Skip to content

blank line causes ParsingError #171

@shindavid

Description

@shindavid

The following code fails with a ParsingError:

from redbaron import RedBaron

text = '''
if True:
    pass
elif True: pass

else:
    pass
'''

RedBaron(text)

The python interpreter parses text without any syntax error.

Deleting the blank line between the elif and the else fixes the ParsingError.

Expand to view traceback
Traceback (most recent call last):
  File ".../site-packages/baron/baron.py", line 20, in _parse
    return parser(tokens)
  File ".../site-packages/baron/grammator.py", line 836, in parse
    return parser.parse(iter(tokens))
  File ".../site-packages/baron/parser.py", line 165, in parse
    raise ParsingError(debug_output)
baron.parser.ParsingError: Error, got an unexpected token ELSE here:

   1
   2 if True:
   3     pass
   4 elif True: pass
   5
   6 else<---- here

The token ELSE should be one of those: $end, ASSERT, AT, BACKQUOTE, BINARY, BINARY_RAW_STRING, BINARY_STRING, BREAK, CLASS, COMMENT, COMPLEX, CONTINUE, DEF, DEL, ELLIPSIS, ENDL, ENDMARKER, EXEC, FLOAT, FLOAT_EXPONANT, FLOAT_EXPONANT_COMPLEX, FOR, FROM, GLOBAL, HEXA, IF, IMPORT, INT, INTERPOLATED_RAW_STRING, INTERPOLATED_STRING, LAMBDA, LEFT_BRACKET, LEFT_PARENTHESIS, LEFT_SQUARE_BRACKET, LONG, MINUS, NAME, NONLOCAL, NOT, OCTA, PASS, PLUS, PRINT, RAISE, RAW_STRING, RETURN, STAR, STRING, TILDE, TRY, UNICODE_RAW_STRING, UNICODE_STRING, WHILE, WITH, YIELD

Baron has failed to parse this input. If this is valid python code (and by that I mean that the python binary successfully parse this code without any syntax error) (also consider that baron does not yet parse python 3 code integrally) it would be kind if you can extract a snippet of your code that make Baron fails and open a bug here: https://github.com/PyCQA/baron/issues

Sorry for the inconvenience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions