This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

66 рядки
1.9 KiB

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