Skip to content

Commit

Permalink
Added more information in UnexpectedInput exception (Issue #78)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Feb 2, 2018
1 parent 22e525f commit 710cb6d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lark/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class UnexpectedInput(LexError):
def __init__(self, seq, lex_pos, line, column, allowed=None):
context = seq[lex_pos:lex_pos+5]
message = "No token defined for: '%s' in %r at line %d col %d" % (seq[lex_pos], context, line, column)
if allowed:
message += '\n\nExpecting: %s\n' % allowed

super(UnexpectedInput, self).__init__(message)

Expand Down
2 changes: 1 addition & 1 deletion lark/load_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def range(self, start, end):
assert start.type == end.type == 'STRING'
start = start.value[1:-1]
end = end.value[1:-1]
assert len(start) == len(end) == 1
assert len(start) == len(end) == 1, (start, end, len(start), len(end))
regexp = '[%s-%s]' % (start, end)
return T('pattern', [PatternRE(regexp)])

Expand Down
2 changes: 1 addition & 1 deletion lark/parsers/xearley.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def scan(i, token, column):
del delayed_matches[i+1] # No longer needed, so unburden memory

if not next_set and not delayed_matches:
raise UnexpectedInput(stream, i, text_line, text_column, to_scan)
raise UnexpectedInput(stream, i, text_line, text_column, {item.expect for item in to_scan})

return next_set

Expand Down

0 comments on commit 710cb6d

Please sign in to comment.