diff --git a/parser/lexer/lexer.go b/parser/lexer/lexer.go index 19e84fd7b..6e4848a83 100644 --- a/parser/lexer/lexer.go +++ b/parser/lexer/lexer.go @@ -133,6 +133,11 @@ func (l *lexer) acceptWord(word string) bool { return false } } + if r = l.peek(); r != ' ' && r != eof { + l.end, l.loc, l.prev = pos, loc, prev + return false + } + return true } diff --git a/parser/lexer/lexer_test.go b/parser/lexer/lexer_test.go index 72bd35fdb..755891b4d 100644 --- a/parser/lexer/lexer_test.go +++ b/parser/lexer/lexer_test.go @@ -97,6 +97,21 @@ var lexTests = []lexTest{ {Kind: EOF}, }, }, + { + "not in_var", + []Token{ + {Kind: Operator, Value: "not"}, + {Kind: Identifier, Value: "in_var"}, + {Kind: EOF}, + }, + }, + { + "not in", + []Token{ + {Kind: Operator, Value: "not in"}, + {Kind: EOF}, + }, + }, { `1..5`, []Token{ diff --git a/parser/parser_test.go b/parser/parser_test.go index 78828ee9c..989829b37 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -65,9 +65,12 @@ func TestParse(t *testing.T) { }, { "(1 - 2) * 3", - &ast.BinaryNode{Operator: "*", - Left: &ast.BinaryNode{Operator: "-", Left: &ast.IntegerNode{Value: 1}, - Right: &ast.IntegerNode{Value: 2}}, Right: &ast.IntegerNode{Value: 3}, + &ast.BinaryNode{ + Operator: "*", + Left: &ast.BinaryNode{ + Operator: "-", Left: &ast.IntegerNode{Value: 1}, + Right: &ast.IntegerNode{Value: 2}, + }, Right: &ast.IntegerNode{Value: 3}, }, }, { @@ -126,7 +129,8 @@ func TestParse(t *testing.T) { "foo.bar().foo().baz[33]", &ast.IndexNode{ Node: &ast.PropertyNode{Node: &ast.MethodNode{Node: &ast.MethodNode{ - Node: &ast.IdentifierNode{Value: "foo"}, Method: "bar", Arguments: []ast.Node{}}, Method: "foo", Arguments: []ast.Node{}}, Property: "baz"}, + Node: &ast.IdentifierNode{Value: "foo"}, Method: "bar", Arguments: []ast.Node{}, + }, Method: "foo", Arguments: []ast.Node{}}, Property: "baz"}, Index: &ast.IntegerNode{Value: 33}, }, }, @@ -194,6 +198,10 @@ func TestParse(t *testing.T) { "0 in []", &ast.BinaryNode{Operator: "in", Left: &ast.IntegerNode{}, Right: &ast.ArrayNode{Nodes: []ast.Node{}}}, }, + { + "not in_var", + &ast.UnaryNode{Operator: "not", Node: &ast.IdentifierNode{Value: "in_var"}}, + }, { "all(Tickets, {.Price > 0})", &ast.BuiltinNode{Name: "all", Arguments: []ast.Node{&ast.IdentifierNode{Value: "Tickets"}, &ast.ClosureNode{Node: &ast.BinaryNode{Operator: ">", Left: &ast.PropertyNode{Node: &ast.PointerNode{}, Property: "Price"}, Right: &ast.IntegerNode{Value: 0}}}}},