diff --git a/lark/lexer.py b/lark/lexer.py index bd22a20..2fdc6b9 100644 --- a/lark/lexer.py +++ b/lark/lexer.py @@ -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) diff --git a/lark/load_grammar.py b/lark/load_grammar.py index 2d01277..85738de 100644 --- a/lark/load_grammar.py +++ b/lark/load_grammar.py @@ -347,7 +347,7 @@ class PrepareLiterals(InlineTransformer): 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)]) diff --git a/lark/parsers/xearley.py b/lark/parsers/xearley.py index 420c469..d9234ab 100644 --- a/lark/parsers/xearley.py +++ b/lark/parsers/xearley.py @@ -112,7 +112,7 @@ class Parser: 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