UnexpectedInput

UnexpectedInput

UnexpectedInput Error.

Used as a base class for the following exceptions:

- ``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.

Constructor

new UnexpectedInput()

Source:

Methods

get_context()

Returns a pretty string pinpointing the error in the text, with span amount of context characters around it.

    Note:
        The parser doesn't hold a copy of the text it has to parse,
        so you have to provide it again
Source:

get_context()

Returns a pretty string pinpointing the error in the text, with span amount of context characters around it.

    Note:
        The parser doesn't hold a copy of the text it has to parse,
        so you have to provide it again
Source:

match_examples()

Allows you to detect what's wrong in the input text by matching against example errors.

    Given a parser instance and a dictionary mapping some label with
    some malformed syntax examples, it'll return the label for the
    example that bests matches the current error. The function will
    iterate the dictionary until it finds a matching error, and
    return the corresponding value.

    For an example usage, see `examples/error_reporting_lalr.py`

    Parameters:
        parse_fn: parse function (usually ``lark_instance.parse``)
        examples: dictionary of ``{'example_string': value}``.
        use_accepts: Recommended to keep this as ``use_accepts=True``.
Source:

match_examples()

Allows you to detect what's wrong in the input text by matching against example errors.

    Given a parser instance and a dictionary mapping some label with
    some malformed syntax examples, it'll return the label for the
    example that bests matches the current error. The function will
    iterate the dictionary until it finds a matching error, and
    return the corresponding value.

    For an example usage, see `examples/error_reporting_lalr.py`

    Parameters:
        parse_fn: parse function (usually ``lark_instance.parse``)
        examples: dictionary of ``{'example_string': value}``.
        use_accepts: Recommended to keep this as ``use_accepts=True``.
Source:

UnexpectedInput

UnexpectedInput Error.

Used as a base class for the following exceptions:

- ``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.

Constructor

new UnexpectedInput()

Source:

Methods

get_context()

Returns a pretty string pinpointing the error in the text, with span amount of context characters around it.

    Note:
        The parser doesn't hold a copy of the text it has to parse,
        so you have to provide it again
Source:

get_context()

Returns a pretty string pinpointing the error in the text, with span amount of context characters around it.

    Note:
        The parser doesn't hold a copy of the text it has to parse,
        so you have to provide it again
Source:

match_examples()

Allows you to detect what's wrong in the input text by matching against example errors.

    Given a parser instance and a dictionary mapping some label with
    some malformed syntax examples, it'll return the label for the
    example that bests matches the current error. The function will
    iterate the dictionary until it finds a matching error, and
    return the corresponding value.

    For an example usage, see `examples/error_reporting_lalr.py`

    Parameters:
        parse_fn: parse function (usually ``lark_instance.parse``)
        examples: dictionary of ``{'example_string': value}``.
        use_accepts: Recommended to keep this as ``use_accepts=True``.
Source:

match_examples()

Allows you to detect what's wrong in the input text by matching against example errors.

    Given a parser instance and a dictionary mapping some label with
    some malformed syntax examples, it'll return the label for the
    example that bests matches the current error. The function will
    iterate the dictionary until it finds a matching error, and
    return the corresponding value.

    For an example usage, see `examples/error_reporting_lalr.py`

    Parameters:
        parse_fn: parse function (usually ``lark_instance.parse``)
        examples: dictionary of ``{'example_string': value}``.
        use_accepts: Recommended to keep this as ``use_accepts=True``.
Source: