...
|
...
|
@@ -86,7 +86,7 @@ func (a *AST) parseFunCallerOrConst() ExprAST { |
|
|
// call func
|
|
|
if a.currTok.Tok == "(" {
|
|
|
f := FunCallerExprAST{}
|
|
|
if _, ok := defFunc[name]; !ok {
|
|
|
if _, ok := defFunc[strings.ToLower(name)]; !ok {
|
|
|
a.Err = errors.New(
|
|
|
fmt.Sprintf("function `%s` is undefined\n%s",
|
|
|
name,
|
...
|
...
|
@@ -107,7 +107,7 @@ func (a *AST) parseFunCallerOrConst() ExprAST { |
|
|
exprs = append(exprs, a.ParseExpression())
|
|
|
}
|
|
|
}
|
|
|
def := defFunc[name]
|
|
|
def := defFunc[strings.ToLower(name)]
|
|
|
if def.argc >= 0 && len(exprs) != def.argc {
|
|
|
a.Err = errors.New(
|
|
|
fmt.Sprintf("wrong way calling function `%s`, parameters want %d but get %d\n%s",
|
...
|
...
|
@@ -117,8 +117,7 @@ func (a *AST) parseFunCallerOrConst() ExprAST { |
|
|
ErrPos(a.source, a.currTok.Offset)))
|
|
|
}
|
|
|
a.getNextToken()
|
|
|
f.Name = name
|
|
|
f.Args = exprs
|
|
|
f = NewFunCallerExprAST(name, exprs...)
|
|
|
return f
|
|
|
}
|
|
|
// call const
|
...
|
...
|
@@ -129,9 +128,7 @@ func (a *AST) parseFunCallerOrConst() ExprAST { |
|
|
}
|
|
|
} else {
|
|
|
if strings.Contains(name, ".") {
|
|
|
return FieldExprAST{
|
|
|
Str: name,
|
|
|
}
|
|
|
return NewFieldExprAST(name)
|
|
|
}
|
|
|
a.Err = errors.New(
|
|
|
fmt.Sprintf("const `%s` is undefined\n%s",
|
...
|
...
|
@@ -148,9 +145,7 @@ func (a *AST) parsePrimary() ExprAST { |
|
|
case Literal:
|
|
|
return a.parseNumber()
|
|
|
case StringArgs:
|
|
|
e := ValueExprAST{
|
|
|
Str: a.currTok.Tok,
|
|
|
}
|
|
|
e := NewValueExprAST(a.currTok.Tok)
|
|
|
a.getNextToken()
|
|
|
return e
|
|
|
case Operator:
|
...
|
...
|
@@ -182,11 +177,7 @@ func (a *AST) parsePrimary() ExprAST { |
|
|
ErrPos(a.source, a.currTok.Offset)))
|
|
|
return nil
|
|
|
}
|
|
|
bin := BinaryExprAST{
|
|
|
Op: "-",
|
|
|
Lhs: NumberExprAST{},
|
|
|
Rhs: a.parsePrimary(),
|
|
|
}
|
|
|
bin := NewBinaryExprAST("-", NumberExprAST{}, a.parsePrimary())
|
|
|
return bin
|
|
|
} else {
|
|
|
return a.parseNumber()
|
...
|
...
|
@@ -226,10 +217,6 @@ func (a *AST) parseBinOpRHS(execPrec int, lhs ExprAST) ExprAST { |
|
|
return nil
|
|
|
}
|
|
|
}
|
|
|
lhs = BinaryExprAST{
|
|
|
Op: binOp,
|
|
|
Lhs: lhs,
|
|
|
Rhs: rhs,
|
|
|
}
|
|
|
lhs = NewBinaryExprAST(binOp, lhs, rhs)
|
|
|
}
|
|
|
} |
...
|
...
|
|