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.

26 lines
510 B

  1. #
  2. # This example shows how to use Lark's templates to achieve cleaner grammars
  3. #
  4. from lark import Lark
  5. grammar = r"""
  6. start: list | dict
  7. list: "[" _seperated{atom, ","} "]"
  8. dict: "{" _seperated{key_value, ","} "}"
  9. key_value: atom ":" atom
  10. _seperated{x, sep}: x (sep x)* // Define a sequence of 'x sep x sep x ...'
  11. atom: NUMBER | ESCAPED_STRING
  12. %import common (NUMBER, ESCAPED_STRING, WS)
  13. %ignore WS
  14. """
  15. parser = Lark(grammar)
  16. print(parser.parse('[1, "a", 2]'))
  17. print(parser.parse('{"a": 2, "b": 6}'))