mirror of https://github.com/lark-parser/lark.git
Make the JSON parser fast again
This commit is contained in:
parent
dcc9d46eef
commit
f7a6366b6c
|
@ -49,11 +49,21 @@ class TreeToJson(Transformer):
|
|||
false = lambda self, _: False
|
||||
|
||||
|
||||
### Create the JSON parser with Lark, using the Earley algorithm
|
||||
# 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', lexer='standard', transformer=TreeToJson())
|
||||
### Create the JSON parser with Lark, using the LALR algorithm
|
||||
json_parser = Lark(json_grammar, parser='lalr',
|
||||
# Using the standard lexer isn't required, and isn't usually recommended.
|
||||
# But, it's good enough for JSON, and it's slightly faster.
|
||||
lexer='standard',
|
||||
# Disabling propagate_positions and placeholders slightly improves speed
|
||||
propagate_positions=False,
|
||||
maybe_placeholders=False,
|
||||
# Using an internal transformer is faster and more memory efficient
|
||||
transformer=TreeToJson())
|
||||
parse = json_parser.parse
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue