Lark

Lark

Main interface for the library.

It's mostly a thin wrapper for the many different parsers, and for the tree constructor.

Parameters:
    grammar: a string or file-object containing the grammar spec (using Lark's ebnf syntax)
    options: a dictionary controlling various aspects of Lark.

Example:
    >>> Lark(r'''start: "foo" ''')
    Lark(...)

Constructor

new Lark()

Source:

Methods

get_terminal()

Get information about a terminal

Source:

get_terminal()

Get information about a terminal

Source:

lex()

Only lex (and postlex) the text, without parsing it. Only relevant when lexer='basic'

    When dont_ignore=True, the lexer will return all tokens, even those marked for %ignore.

    :raises UnexpectedCharacters: In case the lexer cannot find a suitable match.
Source:

lex()

Only lex (and postlex) the text, without parsing it. Only relevant when lexer='basic'

    When dont_ignore=True, the lexer will return all tokens, even those marked for %ignore.

    :raises UnexpectedCharacters: In case the lexer cannot find a suitable match.
Source:

parse()

Parse the given text, according to the options provided.

    Parameters:
        text (str): Text to be parsed.
        start (str, optional): Required if Lark was given multiple possible start symbols (using the start option).
        on_error (function, optional): if provided, will be called on UnexpectedToken error. Return true to resume parsing.
            LALR only. See examples/advanced/error_handling.py for an example of how to use on_error.

    Returns:
        If a transformer is supplied to ``__init__``, returns whatever is the
        result of the transformation. Otherwise, returns a Tree instance.

    :raises UnexpectedInput: On a parse error, one of these sub-exceptions will rise:
            ``UnexpectedCharacters``, ``UnexpectedToken``, or ``UnexpectedEOF``.
            For convenience, these sub-exceptions also inherit from ``ParserError`` and ``LexerError``.
Source:

parse()

Parse the given text, according to the options provided.

    Parameters:
        text (str): Text to be parsed.
        start (str, optional): Required if Lark was given multiple possible start symbols (using the start option).
        on_error (function, optional): if provided, will be called on UnexpectedToken error. Return true to resume parsing.
            LALR only. See examples/advanced/error_handling.py for an example of how to use on_error.

    Returns:
        If a transformer is supplied to ``__init__``, returns whatever is the
        result of the transformation. Otherwise, returns a Tree instance.

    :raises UnexpectedInput: On a parse error, one of these sub-exceptions will rise:
            ``UnexpectedCharacters``, ``UnexpectedToken``, or ``UnexpectedEOF``.
            For convenience, these sub-exceptions also inherit from ``ParserError`` and ``LexerError``.
Source:

parse_interactive()

Start an interactive parsing session.

    Parameters:
        text (str, optional): Text to be parsed. Required for ``resume_parse()``.
        start (str, optional): Start symbol

    Returns:
        A new InteractiveParser instance.

    See Also: ``Lark.parse()``
Source:

parse_interactive()

Start an interactive parsing session.

    Parameters:
        text (str, optional): Text to be parsed. Required for ``resume_parse()``.
        start (str, optional): Start symbol

    Returns:
        A new InteractiveParser instance.

    See Also: ``Lark.parse()``
Source:

repr()

Create an instance of Lark with the grammar loaded from within the package package. This allows grammar loading from zipapps.

    Imports in the grammar will use the `package` and `search_paths` provided, through `FromPackageLoader`

    Example:

        Lark.open_from_package(__name__, "example.lark", ("grammars",), parser=...)
Source:

repr()

Create an instance of Lark with the grammar loaded from within the package package. This allows grammar loading from zipapps.

    Imports in the grammar will use the `package` and `search_paths` provided, through `FromPackageLoader`

    Example:

        Lark.open_from_package(__name__, "example.lark", ("grammars",), parser=...)
Source:

Lark

Main interface for the library.

It's mostly a thin wrapper for the many different parsers, and for the tree constructor.

Parameters:
    grammar: a string or file-object containing the grammar spec (using Lark's ebnf syntax)
    options: a dictionary controlling various aspects of Lark.

Example:
    >>> Lark(r'''start: "foo" ''')
    Lark(...)

Constructor

new Lark()

Source:

Methods

get_terminal()

Get information about a terminal

Source:

get_terminal()

Get information about a terminal

Source:

lex()

Only lex (and postlex) the text, without parsing it. Only relevant when lexer='basic'

    When dont_ignore=True, the lexer will return all tokens, even those marked for %ignore.

    :raises UnexpectedCharacters: In case the lexer cannot find a suitable match.
Source:

lex()

Only lex (and postlex) the text, without parsing it. Only relevant when lexer='basic'

    When dont_ignore=True, the lexer will return all tokens, even those marked for %ignore.

    :raises UnexpectedCharacters: In case the lexer cannot find a suitable match.
Source:

parse()

Parse the given text, according to the options provided.

    Parameters:
        text (str): Text to be parsed.
        start (str, optional): Required if Lark was given multiple possible start symbols (using the start option).
        on_error (function, optional): if provided, will be called on UnexpectedToken error. Return true to resume parsing.
            LALR only. See examples/advanced/error_handling.py for an example of how to use on_error.

    Returns:
        If a transformer is supplied to ``__init__``, returns whatever is the
        result of the transformation. Otherwise, returns a Tree instance.

    :raises UnexpectedInput: On a parse error, one of these sub-exceptions will rise:
            ``UnexpectedCharacters``, ``UnexpectedToken``, or ``UnexpectedEOF``.
            For convenience, these sub-exceptions also inherit from ``ParserError`` and ``LexerError``.
Source:

parse()

Parse the given text, according to the options provided.

    Parameters:
        text (str): Text to be parsed.
        start (str, optional): Required if Lark was given multiple possible start symbols (using the start option).
        on_error (function, optional): if provided, will be called on UnexpectedToken error. Return true to resume parsing.
            LALR only. See examples/advanced/error_handling.py for an example of how to use on_error.

    Returns:
        If a transformer is supplied to ``__init__``, returns whatever is the
        result of the transformation. Otherwise, returns a Tree instance.

    :raises UnexpectedInput: On a parse error, one of these sub-exceptions will rise:
            ``UnexpectedCharacters``, ``UnexpectedToken``, or ``UnexpectedEOF``.
            For convenience, these sub-exceptions also inherit from ``ParserError`` and ``LexerError``.
Source:

parse_interactive()

Start an interactive parsing session.

    Parameters:
        text (str, optional): Text to be parsed. Required for ``resume_parse()``.
        start (str, optional): Start symbol

    Returns:
        A new InteractiveParser instance.

    See Also: ``Lark.parse()``
Source:

parse_interactive()

Start an interactive parsing session.

    Parameters:
        text (str, optional): Text to be parsed. Required for ``resume_parse()``.
        start (str, optional): Start symbol

    Returns:
        A new InteractiveParser instance.

    See Also: ``Lark.parse()``
Source:

repr()

Create an instance of Lark with the grammar loaded from within the package package. This allows grammar loading from zipapps.

    Imports in the grammar will use the `package` and `search_paths` provided, through `FromPackageLoader`

    Example:

        Lark.open_from_package(__name__, "example.lark", ("grammars",), parser=...)
Source:

repr()

Create an instance of Lark with the grammar loaded from within the package package. This allows grammar loading from zipapps.

    Imports in the grammar will use the `package` and `search_paths` provided, through `FromPackageLoader`

    Example:

        Lark.open_from_package(__name__, "example.lark", ("grammars",), parser=...)
Source: