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.

38 lines
768 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, v_args
  10. inline_args = v_args(inline=True)
  11. class TreeToJson(Transformer):
  12. @inline_args
  13. def string(self, s):
  14. return s[1:-1].replace('\\"', '"')
  15. array = list
  16. pair = tuple
  17. object = dict
  18. number = inline_args(float)
  19. null = lambda self, _: None
  20. true = lambda self, _: True
  21. false = lambda self, _: False
  22. parser = Lark_StandAlone(transformer=TreeToJson())
  23. if __name__ == '__main__':
  24. with open(sys.argv[1]) as f:
  25. print(parser.parse(f.read()))