1Working with the SPPF
2=====================
3
4When parsing with Earley, Lark provides the ``ambiguity='forest'`` option
5to obtain the shared packed parse forest (SPPF) produced by the parser as
6an alternative to it being automatically converted to a tree.
7
8Lark provides a few tools to facilitate working with the SPPF. Here are some
9things to consider when deciding whether or not to use the SPPF.
10
11**Pros**
12
13- Efficient storage of highly ambiguous parses
14- Precise handling of ambiguities
15- Custom rule prioritizers
16- Ability to handle infinite ambiguities
17- Directly transform forest -> object instead of forest -> tree -> object
18
19**Cons**
20
21- More complex than working with a tree
22- SPPF may contain nodes corresponding to rules generated internally
23- Loss of Lark grammar features:
24
25  - Rules starting with '_' are not inlined in the SPPF
26  - Rules starting with '?' are never inlined in the SPPF
27  - All tokens will appear in the SPPF
28
29SymbolNode
30----------
31
32.. autoclass:: lark.parsers.earley_forest.SymbolNode
33   :members: is_ambiguous, children
34
35PackedNode
36----------
37
38.. autoclass:: lark.parsers.earley_forest.PackedNode
39   :members: children
40
41ForestVisitor
42-------------
43
44.. autoclass:: lark.parsers.earley_forest.ForestVisitor
45   :members: visit, visit_symbol_node_in, visit_symbol_node_out,
46             visit_packed_node_in, visit_packed_node_out,
47             visit_token_node, on_cycle, get_cycle_in_path
48
49ForestTransformer
50-----------------
51
52.. autoclass:: lark.parsers.earley_forest.ForestTransformer
53   :members: transform, transform_symbol_node, transform_intermediate_node,
54             transform_packed_node, transform_token_node
55
56TreeForestTransformer
57---------------------
58
59.. autoclass:: lark.parsers.earley_forest.TreeForestTransformer
60   :members: __default__, __default_token__, __default_ambig__
61
62handles_ambiguity
63-----------------
64
65.. autofunction:: lark.parsers.earley_forest.handles_ambiguity
66