This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 

38 líneas
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()))