Browse Source

Small fix in Python grammars (misread tuples, issue #68)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.3
Erez Shinan 6 years ago
parent
commit
23875c5590
2 changed files with 5 additions and 3 deletions
  1. +3
    -2
      examples/python2.g
  2. +2
    -1
      examples/python3.g

+ 3
- 2
examples/python2.g View File

@@ -100,13 +100,14 @@ comp_op: "<"|">"|"=="|">="|"<="|"<>"|"!="|"in"|"not" "in"|"is"|"is" "not"
| molecule "[" [subscriptlist] "]" -> getitem | molecule "[" [subscriptlist] "]" -> getitem
| molecule "." NAME -> getattr | molecule "." NAME -> getattr
| atom | atom
?atom: "(" [yield_expr|testlist_comp] ")"
?atom: "(" [yield_expr|testlist_comp] ")" -> tuple
| "[" [listmaker] "]" | "[" [listmaker] "]"
| "{" [dictorsetmaker] "}" | "{" [dictorsetmaker] "}"
| "`" testlist1 "`" | "`" testlist1 "`"
| "(" test ")"
| NAME | number | string+ | NAME | number | string+
listmaker: test ( list_for | ("," test)* [","] ) listmaker: test ( list_for | ("," test)* [","] )
?testlist_comp: test ( comp_for | ("," test)* [","] )
?testlist_comp: test ( comp_for | ("," test)+ [","] | ",")
lambdef: "lambda" [paramlist] ":" test lambdef: "lambda" [paramlist] ":" test
?subscriptlist: subscript ("," subscript)* [","] ?subscriptlist: subscript ("," subscript)* [","]
subscript: "." "." "." | test | [test] ":" [test] [sliceop] subscript: "." "." "." | test | [test] ":" [test] [sliceop]


+ 2
- 1
examples/python3.g View File

@@ -121,12 +121,13 @@ AWAIT: "await"
| "{" [dictorsetmaker] "}" -> dict | "{" [dictorsetmaker] "}" -> dict
| NAME -> var | NAME -> var
| number | string+ | number | string+
| "(" test ")"
| "..." -> ellipsis | "..." -> ellipsis
| "None" -> const_none | "None" -> const_none
| "True" -> const_true | "True" -> const_true
| "False" -> const_false | "False" -> const_false


testlist_comp: (test|star_expr) ( comp_for | ("," (test|star_expr))* [","] )
?testlist_comp: (test|star_expr) ( comp_for | ("," (test|star_expr))+ [","] | ",")
subscriptlist: subscript ("," subscript)* [","] subscriptlist: subscript ("," subscript)* [","]
subscript: test | [test] ":" [test] [sliceop] subscript: test | [test] ":" [test] [sliceop]
sliceop: ":" [test] sliceop: ":" [test]


Loading…
Cancel
Save