m-labs / pythonparser

MIT License
72 stars 23 forks source link

Empty print statement causes parse error #4

Closed trotterdylan closed 7 years ago

trotterdylan commented 7 years ago

An empty print statement should print just a newline:

>>> print

pythonparser doesn't recognize it as valid syntax:

>>> pythonparser.parse('print\n')
<unknown>:1:6-2:1: fatal: unexpected newline: expected (, +, -, >>, [, `, complex, float, ident, int, lambda, not, strbegin, { or ~
print
     ^
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/trotterd/projects/grumpy/build/lib/python2.7/site-packages/pythonparser/__init__.py", line 58, in parse
    mode, flags, version, engine)
  File "/Users/trotterd/projects/grumpy/build/lib/python2.7/site-packages/pythonparser/__init__.py", line 28, in parse_buffer
    return parser.file_input(), lexer.comments
  File "/Users/trotterd/projects/grumpy/build/lib/python2.7/site-packages/pythonparser/parser.py", line 89, in outer_rule
    result = inner_rule(parser)
  File "/Users/trotterd/projects/grumpy/build/lib/python2.7/site-packages/pythonparser/parser.py", line 151, in rule
    parser.diagnostic_engine.process(error)
  File "/Users/trotterd/projects/grumpy/build/lib/python2.7/site-packages/pythonparser/diagnostic.py", line 165, in process
    raise Error(diagnostic)
pythonparser.diagnostic.Error: <unknown>:1:6-2:1: fatal: unexpected newline: expected (, +, -, >>, [, `, complex, float, ident, int, lambda, not, strbegin, { or ~
print
     ^
whitequark commented 7 years ago

Nevermind the previous comment, I've misread a [.