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.

36 lines
738 B

  1. """
  2. Standalone Parser
  3. ===================================
  4. This example demonstrates how to generate and use the standalone parser,
  5. using the JSON example.
  6. See README.md for more details.
  7. """
  8. import sys
  9. from json_parser import Lark_StandAlone, Transformer, inline_args
  10. class TreeToJson(Transformer):
  11. @inline_args
  12. def string(self, s):
  13. return s[1:-1].replace('\\"', '"')
  14. array = list
  15. pair = tuple
  16. object = dict
  17. number = inline_args(float)
  18. null = lambda self, _: None
  19. true = lambda self, _: True
  20. false = lambda self, _: False
  21. parser = Lark_StandAlone(transformer=TreeToJson())
  22. if __name__ == '__main__':
  23. with open(sys.argv[1]) as f:
  24. print(parser.parse(f.read()))