Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions parser/grammar_data_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -60,6 +60,7 @@ var grammarTestData = []struct {
{"[1,]", "eval", "Expression(body=List(elts=[Num(n=1)], ctx=Load()))", nil, ""},
{"[1,2]", "eval", "Expression(body=List(elts=[Num(n=1), Num(n=2)], ctx=Load()))", nil, ""},
{"[1,2,]", "eval", "Expression(body=List(elts=[Num(n=1), Num(n=2)], ctx=Load()))", nil, ""},
{"[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, ""},
{"( 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, ""},
{"( 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, ""},
{"( 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, ""},
Expand DownExpand Up@@ -260,6 +261,9 @@ var grammarTestData = []struct {
{"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, ""},
{"a = yield a", "exec", "Module(body=[Assign(targets=[Name(id='a', ctx=Store())], value=Yield(value=Name(id='a', ctx=Load())))])", nil, ""},
{"a.b = 1", "exec", "Module(body=[Assign(targets=[Attribute(value=Name(id='a', ctx=Load()), attr='b', ctx=Store())], value=Num(n=1))])", nil, ""},
{"[e for e in [1, 2, 3]] = 3", "exec", "", py.SyntaxError, "can't assign to list comprehension"},
{"{e for e in [1, 2, 3]} = 3", "exec", "", py.SyntaxError, "can't assign to set comprehension"},
{"{e: e**2 for e in [1, 2, 3]} = 3", "exec", "", py.SyntaxError, "can't assign to dict comprehension"},
{"f() = 1", "exec", "", py.SyntaxError, "can't assign to function call"},
{"lambda: x = 1", "exec", "", py.SyntaxError, "can't assign to lambda"},
{"(a + b) = 1", "exec", "", py.SyntaxError, "can't assign to operator"},
Expand Down
2 changes: 1 addition & 1 deletion parser/parser.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,5 +7,5 @@
// % go generate
// % go build

//go:generate go tool yacc -v y.output grammar.y
//go:generate goyacc -v y.output grammar.y
package parser
Loading