aboutsummaryrefslogtreecommitdiff
path: root/expr.go
diff options
context:
space:
mode:
authorFumitoshi Ukai <fumitoshi.ukai@gmail.com>2015-06-11 17:15:49 +0900
committerFumitoshi Ukai <fumitoshi.ukai@gmail.com>2015-06-11 17:34:10 +0900
commit4a708512624fe1bec939fd41661665c27bd0ebcb (patch)
treebb862740ee8aeeec2a5ecbb7503293effa2585d9 /expr.go
parent72598e7aba34804477c8fd6a32dee0216d32ad98 (diff)
downloadkati-4a708512624fe1bec939fd41661665c27bd0ebcb.tar.gz
refactor sh builtins
add -use_shell_builtins flag to disable the feature (when some builtin is broken)
Diffstat (limited to 'expr.go')
-rw-r--r--expr.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/expr.go b/expr.go
index 6af75f1..6af8d6e 100644
--- a/expr.go
+++ b/expr.go
@@ -584,3 +584,32 @@ func (f funcstats) Eval(w io.Writer, ev *Evaluator) {
// TODO(ukai): per functype?
traceEvent.end(te)
}
+
+type matchVarref struct{}
+
+func (m matchVarref) String() string { return "$(match-any)" }
+func (m matchVarref) Eval(w io.Writer, ev *Evaluator) { panic("not implemented") }
+func (m matchVarref) Serialize() SerializableVar { panic("not implemented") }
+func (m matchVarref) Dump(w io.Writer) { panic("not implemented") }
+
+func matchExpr(expr, pat Expr) ([]Value, bool) {
+ if len(expr) != len(pat) {
+ return nil, false
+ }
+ var mv matchVarref
+ var matches []Value
+ for i := range expr {
+ if pat[i] == mv {
+ switch expr[i].(type) {
+ case paramref, varref:
+ matches = append(matches, expr[i])
+ continue
+ }
+ return nil, false
+ }
+ if expr[i] != pat[i] {
+ return nil, false
+ }
+ }
+ return matches, true
+}