Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf2d78d

Browse files
committed
parser: Update from go tool yacc into goyacc
Since Go 1.8 removed the go tool yacc command, we should update it to use goyacc
1 parent ed3c651 commit cf2d78d

File tree

4 files changed

+1438
-1015
lines changed

4 files changed

+1438
-1015
lines changed

parser/grammar_data_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ var grammarTestData = []struct {
6060
{"[1,]", "eval", "Expression(body=List(elts=[Num(n=1)], ctx=Load()))", nil, ""},
6161
{"[1,2]", "eval", "Expression(body=List(elts=[Num(n=1), Num(n=2)], ctx=Load()))", nil, ""},
6262
{"[1,2,]", "eval", "Expression(body=List(elts=[Num(n=1), Num(n=2)], ctx=Load()))", nil, ""},
63+
{"[e for e in (1,2,3)]", "eval", "Expression(body=ListComp(elt=Name(id='e', ctx=Load()), generators=[comprehension(target=Name(id='e', ctx=Store()), iter=Tuple(elts=[Num(n=1), Num(n=2), Num(n=3)], ctx=Load()), ifs=[])]))", nil, ""},
6364
{"( a for a in ab )", "eval", "Expression(body=GeneratorExp(elt=Name(id='a', ctx=Load()), generators=[comprehension(target=Name(id='a', ctx=Store()), iter=Name(id='ab', ctx=Load()), ifs=[])]))", nil, ""},
6465
{"( a for a, in ab )", "eval", "Expression(body=GeneratorExp(elt=Name(id='a', ctx=Load()), generators=[comprehension(target=Tuple(elts=[Name(id='a', ctx=Store())], ctx=Store()), iter=Name(id='ab', ctx=Load()), ifs=[])]))", nil, ""},
6566
{"( a for a, b in ab )", "eval", "Expression(body=GeneratorExp(elt=Name(id='a', ctx=Load()), generators=[comprehension(target=Tuple(elts=[Name(id='a', ctx=Store()), Name(id='b', ctx=Store())], ctx=Store()), iter=Name(id='ab', ctx=Load()), ifs=[])]))", nil, ""},
@@ -260,6 +261,9 @@ var grammarTestData = []struct {
260261
{"a, b = *a", "exec", "Module(body=[Assign(targets=[Tuple(elts=[Name(id='a', ctx=Store()), Name(id='b', ctx=Store())], ctx=Store())], value=Starred(value=Name(id='a', ctx=Load()), ctx=Load()))])", nil, ""},
261262
{"a = yield a", "exec", "Module(body=[Assign(targets=[Name(id='a', ctx=Store())], value=Yield(value=Name(id='a', ctx=Load())))])", nil, ""},
262263
{"a.b = 1", "exec", "Module(body=[Assign(targets=[Attribute(value=Name(id='a', ctx=Load()), attr='b', ctx=Store())], value=Num(n=1))])", nil, ""},
264+
{"[e for e in [1, 2, 3]] = 3", "exec", "", py.SyntaxError, "can't assign to list comprehension"},
265+
{"{e for e in [1, 2, 3]} = 3", "exec", "", py.SyntaxError, "can't assign to set comprehension"},
266+
{"{e: e**2 for e in [1, 2, 3]} = 3", "exec", "", py.SyntaxError, "can't assign to dict comprehension"},
263267
{"f() = 1", "exec", "", py.SyntaxError, "can't assign to function call"},
264268
{"lambda: x = 1", "exec", "", py.SyntaxError, "can't assign to lambda"},
265269
{"(a + b) = 1", "exec", "", py.SyntaxError, "can't assign to operator"},

parser/parser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
// % go generate
88
// % go build
99

10-
//go:generate go tool yacc -v y.output grammar.y
10+
//go:generate goyacc -v y.output grammar.y
1111
package parser

0 commit comments

Comments
 (0)