소스 검색

Make the JSON parser fast again

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.8.0
Erez Sh 4 년 전
부모
커밋
f7a6366b6c
1개의 변경된 파일11개의 추가작업 그리고 1개의 파일을 삭제
  1. +11
    -1
      examples/json_parser.py

+ 11
- 1
examples/json_parser.py 파일 보기

@@ -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




불러오는 중...
취소
저장