we-like-parsers / pegen

PEG parser generator for Python
https://we-like-parsers.github.io/pegen/
MIT License
150 stars 32 forks source link

parse error #99

Open wiltchamberian opened 7 months ago

wiltchamberian commented 7 months ago
start[ast.Module]: a=expr_stmt* ENDMARKER { ast.Module(body=a or [] }
expr_stmt: a=expr NEWLINE { ast.Expr(value=a, EXTRA) }

expr:
    | l=expr '+' r=term { ast.BinOp(left=l, op=ast.Add(), right=r, EXTRA) }
    | l=expr '-' r=term { ast.BinOp(left=l, op=ast.Sub(), right=r, EXTRA) }
    | term

term:
    | l=term '*' r=factor { ast.BinOp(left=l, op=ast.Mult(), right=r, EXTRA) }
    | l=term '/' r=factor { ast.BinOp(left=l, op=ast.Div(), right=r, EXTRA) }
    | factor

factor:
    | '(' e=expr ')' { e }
    | atom

atom:
    | NAME
    | NUMBER

These codes are copied from : https://we-like-parsers.github.io/pegen/grammar.html and I use python3.10 to parse but it failed, obvisouly, "ast.Module(body=a or [] " here lacks a ')' and there other issues such as

  File "<unknown>", line 1
    ast . Expr ( value = a , EXTRA )
                                   ^
SyntaxError: positional argument follows keyword argument     
For full traceback, use -v
0dminnimda commented 7 months ago

The docs there seems to be a little outdated, it's probably meant to be LOCATIONS