This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
668 B

  1. #
  2. # This example shows how to use get explicit ambiguity from Lark's Earley parser.
  3. #
  4. from lark import Lark
  5. g = """
  6. sentence: noun verb noun -> simple
  7. | noun verb "like" noun -> comparative
  8. noun: ADJ? NOUN
  9. verb: VERB
  10. NOUN: "flies" | "bananas" | "fruit"
  11. VERB: "like" | "flies"
  12. ADJ: "fruit"
  13. %import common.WS
  14. %ignore WS
  15. """
  16. lark = Lark(g, start='sentence', ambiguity='explicit')
  17. print(lark.parse('fruit flies like bananas').pretty())
  18. # Outputs:
  19. #
  20. # _ambig
  21. # comparative
  22. # noun fruit
  23. # verb flies
  24. # noun bananas
  25. # simple
  26. # noun
  27. # fruit
  28. # flies
  29. # verb like
  30. # noun bananas