ソースを参照

Added more information in UnexpectedInput exception (Issue #78)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.4
Erez Shinan 6年前
コミット
710cb6d20b
3個のファイルの変更4行の追加2行の削除
  1. +2
    -0
      lark/lexer.py
  2. +1
    -1
      lark/load_grammar.py
  3. +1
    -1
      lark/parsers/xearley.py

+ 2
- 0
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)



+ 1
- 1
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)])



+ 1
- 1
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



読み込み中…
キャンセル
保存