|
@@ -36,8 +36,9 @@ class UnexpectedInput(LarkError): |
|
|
|
|
|
|
|
|
Used as a base class for the following exceptions: |
|
|
Used as a base class for the following exceptions: |
|
|
|
|
|
|
|
|
- ``UnexpectedToken``: The parser received an unexpected token |
|
|
|
|
|
- ``UnexpectedCharacters``: The lexer encountered an unexpected string |
|
|
- ``UnexpectedCharacters``: The lexer encountered an unexpected string |
|
|
|
|
|
- ``UnexpectedToken``: The parser received an unexpected token |
|
|
|
|
|
- ``UnexpectedEOF``: The parser expected a token, but the input ended |
|
|
|
|
|
|
|
|
After catching one of these exceptions, you may call the following helper methods to create a nicer error message. |
|
|
After catching one of these exceptions, you may call the following helper methods to create a nicer error message. |
|
|
""" |
|
|
""" |
|
@@ -128,6 +129,9 @@ class UnexpectedInput(LarkError): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UnexpectedEOF(ParseError, UnexpectedInput): |
|
|
class UnexpectedEOF(ParseError, UnexpectedInput): |
|
|
|
|
|
"""An exception that is raised by the parser, when the input ends while it still expects a token. |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
def __init__(self, expected, state=None, terminals_by_name=None): |
|
|
def __init__(self, expected, state=None, terminals_by_name=None): |
|
|
super(UnexpectedEOF, self).__init__() |
|
|
super(UnexpectedEOF, self).__init__() |
|
|
|
|
|
|
|
@@ -148,6 +152,10 @@ class UnexpectedEOF(ParseError, UnexpectedInput): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UnexpectedCharacters(LexError, UnexpectedInput): |
|
|
class UnexpectedCharacters(LexError, UnexpectedInput): |
|
|
|
|
|
"""An exception that is raised by the lexer, when it cannot match the next |
|
|
|
|
|
string of characters to any of its terminals. |
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
def __init__(self, seq, lex_pos, line, column, allowed=None, considered_tokens=None, state=None, token_history=None, |
|
|
def __init__(self, seq, lex_pos, line, column, allowed=None, considered_tokens=None, state=None, token_history=None, |
|
|
terminals_by_name=None, considered_rules=None): |
|
|
terminals_by_name=None, considered_rules=None): |
|
|
super(UnexpectedCharacters, self).__init__() |
|
|
super(UnexpectedCharacters, self).__init__() |
|
@@ -185,10 +193,15 @@ class UnexpectedToken(ParseError, UnexpectedInput): |
|
|
"""An exception that is raised by the parser, when the token it received |
|
|
"""An exception that is raised by the parser, when the token it received |
|
|
doesn't match any valid step forward. |
|
|
doesn't match any valid step forward. |
|
|
|
|
|
|
|
|
The parser provides an interactive instance through `interactive_parser`, |
|
|
|
|
|
which is initialized to the point of failture, and can be used for debugging and error handling. |
|
|
|
|
|
|
|
|
Parameters: |
|
|
|
|
|
token: The mismatched token |
|
|
|
|
|
expected: The set of expected tokens |
|
|
|
|
|
considered_rules: Which rules were considered, to deduce the expected tokens |
|
|
|
|
|
state: A value representing the parser state. Do not rely on its value or type. |
|
|
|
|
|
interactive_parser: An instance of ``InteractiveParser``, that is initialized to the point of failture, |
|
|
|
|
|
and can be used for debugging and error handling. |
|
|
|
|
|
|
|
|
see: ``InteractiveParser``. |
|
|
|
|
|
|
|
|
Note: These parameters are available as attributes of the instance. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
def __init__(self, token, expected, considered_rules=None, state=None, interactive_parser=None, terminals_by_name=None, token_history=None): |
|
|
def __init__(self, token, expected, considered_rules=None, state=None, interactive_parser=None, terminals_by_name=None, token_history=None): |
|
@@ -234,14 +247,20 @@ class VisitError(LarkError): |
|
|
"""VisitError is raised when visitors are interrupted by an exception |
|
|
"""VisitError is raised when visitors are interrupted by an exception |
|
|
|
|
|
|
|
|
It provides the following attributes for inspection: |
|
|
It provides the following attributes for inspection: |
|
|
- obj: the tree node or token it was processing when the exception was raised |
|
|
|
|
|
- orig_exc: the exception that cause it to fail |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parameters: |
|
|
|
|
|
rule: the name of the visit rule that failed |
|
|
|
|
|
obj: the tree-node or token that was being processed |
|
|
|
|
|
orig_exc: the exception that cause it to fail |
|
|
|
|
|
|
|
|
|
|
|
Note: These parameters are available as attributes |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
def __init__(self, rule, obj, orig_exc): |
|
|
def __init__(self, rule, obj, orig_exc): |
|
|
message = 'Error trying to process rule "%s":\n\n%s' % (rule, orig_exc) |
|
|
message = 'Error trying to process rule "%s":\n\n%s' % (rule, orig_exc) |
|
|
super(VisitError, self).__init__(message) |
|
|
super(VisitError, self).__init__(message) |
|
|
|
|
|
|
|
|
|
|
|
self.rule = rule |
|
|
self.obj = obj |
|
|
self.obj = obj |
|
|
self.orig_exc = orig_exc |
|
|
self.orig_exc = orig_exc |
|
|
|
|
|
|
|
|