Browse Source

Small fixes

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.10.0
Erez Sh 6 years ago
parent
commit
2c7afed894
1 changed files with 5 additions and 2 deletions
  1. +5
    -2
      lark/exceptions.py

+ 5
- 2
lark/exceptions.py View File

@@ -43,6 +43,8 @@ class UnexpectedInput(LarkError):
""" Given a parser instance and a dictionary mapping some label with """ Given a parser instance and a dictionary mapping some label with
some malformed syntax examples, it'll return the label for the some malformed syntax examples, it'll return the label for the
example that bests matches the current error. example that bests matches the current error.

It's recommended to call this with `use_accepts=True`. The default is False for backwards compatibility.
""" """
assert self.state is not None, "Not supported for this exception" assert self.state is not None, "Not supported for this exception"


@@ -93,10 +95,11 @@ class UnexpectedCharacters(LexError, UnexpectedInput):
self.considered_tokens = considered_tokens self.considered_tokens = considered_tokens


if isinstance(seq, bytes): if isinstance(seq, bytes):
message = "No terminal defined for '%s' at line %d col %d" % (seq[lex_pos:lex_pos+1].decode("ascii", "backslashreplace"), line, column)
_s = seq[lex_pos:lex_pos+1].decode("ascii", "backslashreplace")
else: else:
message = "No terminal defined for '%s' at line %d col %d" % (seq[lex_pos], line, column)
_s = seq[lex_pos]


message = "No terminal defined for '%s' at line %d col %d" % (_s, line, column)
message += '\n\n' + self.get_context(seq) message += '\n\n' + self.get_context(seq)
if allowed: if allowed:
message += '\nExpecting: %s\n' % allowed message += '\nExpecting: %s\n' % allowed


Loading…
Cancel
Save