1API Reference
2=============
3
4Lark
5----
6
7.. autoclass:: lark.Lark
8    :members: open, parse, parse_interactive, lex, save, load, get_terminal, open_from_package
9
10
11Using Unicode character classes with ``regex``
12^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13
14Python's builtin ``re`` module has a few persistent known bugs and also won't parse
15advanced regex features such as character classes.
16With ``pip install lark-parser[regex]``, the ``regex`` module will be
17installed alongside lark and can act as a drop-in replacement to ``re``.
18
19Any instance of Lark instantiated with ``regex=True`` will use the ``regex`` module instead of ``re``.
20
21For example, we can use character classes to match PEP-3131 compliant Python identifiers:
22
23::
24
25    from lark import Lark
26    >>> g = Lark(r"""
27                        ?start: NAME
28                        NAME: ID_START ID_CONTINUE*
29                        ID_START: /[\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}_]+/
30                        ID_CONTINUE: ID_START | /[\p{Mn}\p{Mc}\p{Nd}\p{Pc}·]+/
31                    """, regex=True)
32
33    >>> g.parse('வணக்கம்')
34    'வணக்கம்'
35
36
37Tree
38----
39
40.. autoclass:: lark.Tree
41    :members: pretty, find_pred, find_data, iter_subtrees, scan_values,
42        iter_subtrees_topdown
43
44Token
45-----
46
47.. autoclass:: lark.Token
48
49Transformer, Visitor & Interpreter
50----------------------------------
51
52See :doc:`visitors`.
53
54ForestVisitor, ForestTransformer, & TreeForestTransformer
55-----------------------------------------------------------
56
57See :doc:`forest`.
58
59UnexpectedInput
60---------------
61
62.. autoclass:: lark.exceptions.UnexpectedInput
63    :members: get_context, match_examples
64
65.. autoclass:: lark.exceptions.UnexpectedToken
66
67.. autoclass:: lark.exceptions.UnexpectedCharacters
68
69.. autoclass:: lark.exceptions.UnexpectedEOF
70
71InteractiveParser
72-----------------
73
74.. autoclass:: lark.parsers.lalr_interactive_parser.InteractiveParser
75    :members: choices, feed_token, copy, pretty, resume_parse, exhaust_lexer, accepts, as_immutable
76
77.. autoclass:: lark.parsers.lalr_interactive_parser.ImmutableInteractiveParser
78    :members: choices, feed_token, copy, pretty, resume_parse, exhaust_lexer, accepts, as_mutable
79
80
81ast_utils
82---------
83
84For an example of using ``ast_utils``, see `/examples/advanced/create_ast.py`_
85
86.. autoclass:: lark.ast_utils.Ast
87
88.. autoclass:: lark.ast_utils.AsList
89
90.. autofunction:: lark.ast_utils.create_transformer
91
92.. _/examples/advanced/create_ast.py: examples/advanced/create_ast.html