Skip to content

Commit da4c23e

Browse files
authored
acceptWord checks the rune after word (#184)
1 parent baae791 commit da4c23e

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

parser/lexer/lexer.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ func (l *lexer) acceptWord(word string) bool {
133133
return false
134134
}
135135
}
136+
if r = l.peek(); r != ' ' && r != eof {
137+
l.end, l.loc, l.prev = pos, loc, prev
138+
return false
139+
}
140+
136141
return true
137142
}
138143

parser/lexer/lexer_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,21 @@ var lexTests = []lexTest{
9797
{Kind: EOF},
9898
},
9999
},
100+
{
101+
"not in_var",
102+
[]Token{
103+
{Kind: Operator, Value: "not"},
104+
{Kind: Identifier, Value: "in_var"},
105+
{Kind: EOF},
106+
},
107+
},
108+
{
109+
"not in",
110+
[]Token{
111+
{Kind: Operator, Value: "not in"},
112+
{Kind: EOF},
113+
},
114+
},
100115
{
101116
`1..5`,
102117
[]Token{

parser/parser_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ func TestParse(t *testing.T) {
6565
},
6666
{
6767
"(1 - 2) * 3",
68-
&ast.BinaryNode{Operator: "*",
69-
Left: &ast.BinaryNode{Operator: "-", Left: &ast.IntegerNode{Value: 1},
70-
Right: &ast.IntegerNode{Value: 2}}, Right: &ast.IntegerNode{Value: 3},
68+
&ast.BinaryNode{
69+
Operator: "*",
70+
Left: &ast.BinaryNode{
71+
Operator: "-", Left: &ast.IntegerNode{Value: 1},
72+
Right: &ast.IntegerNode{Value: 2},
73+
}, Right: &ast.IntegerNode{Value: 3},
7174
},
7275
},
7376
{
@@ -126,7 +129,8 @@ func TestParse(t *testing.T) {
126129
"foo.bar().foo().baz[33]",
127130
&ast.IndexNode{
128131
Node: &ast.PropertyNode{Node: &ast.MethodNode{Node: &ast.MethodNode{
129-
Node: &ast.IdentifierNode{Value: "foo"}, Method: "bar", Arguments: []ast.Node{}}, Method: "foo", Arguments: []ast.Node{}}, Property: "baz"},
132+
Node: &ast.IdentifierNode{Value: "foo"}, Method: "bar", Arguments: []ast.Node{},
133+
}, Method: "foo", Arguments: []ast.Node{}}, Property: "baz"},
130134
Index: &ast.IntegerNode{Value: 33},
131135
},
132136
},
@@ -194,6 +198,10 @@ func TestParse(t *testing.T) {
194198
"0 in []",
195199
&ast.BinaryNode{Operator: "in", Left: &ast.IntegerNode{}, Right: &ast.ArrayNode{Nodes: []ast.Node{}}},
196200
},
201+
{
202+
"not in_var",
203+
&ast.UnaryNode{Operator: "not", Node: &ast.IdentifierNode{Value: "in_var"}},
204+
},
197205
{
198206
"all(Tickets, {.Price > 0})",
199207
&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}}}}},

0 commit comments

Comments
 (0)