Ver a proveniência

Example JSON parser is now LALR

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan há 6 anos
ascendente
cometimento
84791b1534
1 ficheiros alterados com 6 adições e 6 eliminações
  1. +6
    -6
      examples/json_parser.py

+ 6
- 6
examples/json_parser.py Ver ficheiro

@@ -1,7 +1,7 @@
#
# This example shows how to write a basic JSON parser
#
# The code is short and clear, but has good performance.
# The code is short and clear, and outperforms every other parser (that's written in Python).
# For an explanation, check out the JSON parser tutorial at /docs/json_tutorial.md
#

@@ -47,12 +47,12 @@ class TreeToJson(Transformer):
true = lambda self, _: True
false = lambda self, _: False

json_parser = Lark(json_grammar, parser='earley', lexer='standard')
def parse(x):
return TreeToJson().transform(json_parser.parse(x))
# json_parser = Lark(json_grammar, parser='earley', lexer='standard')
# def parse(x):
# return TreeToJson().transform(json_parser.parse(x))

# json_parser = Lark(json_grammar, parser='lalr', transformer=TreeToJson())
# parse = json_parser.parse
json_parser = Lark(json_grammar, parser='lalr', transformer=TreeToJson())
parse = json_parser.parse

def test():
test_json = '''


Carregando…
Cancelar
Guardar