问题:
# From example at https://github.com/lark-parser/lark/blob/master/examples/json_parser.py
from lark import Lark, Transformer, v_args
parse = json_parser.parse
json_grammar = r""" ... """
### 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())
with open(sys.argv[1]) as f:
tree = parse(f.read())
print( tree )
# Errors next 2 lines:
# No: tree.pretty( indent_str=" " )
# No: Lark.pretty( indent_str=" " )
具体错误:
- AttributeError:类型对象'Lark'没有属性'pretty'
设置:
Python 版本 = 3.8.1
在 Mac Bug Sur 上的 Miniconda 3 中
conda install lark-parser
安装 0.11.2-pyh44b312d_0
conda upgrade lark-parser
安装 0.11.3-pyhd8ed1ab_0
编辑:注意我的目标:
这里的目标不仅仅是解析 JSON;我只是碰巧正在使用一个 JSON 示例来尝试和学习。我想为我在工作中处理的一些数据编写自己的语法。
编辑:为什么我相信漂亮的印刷品应该存在:
这是一个使用 .pretty() 函数的示例,甚至包括输出。但我似乎找不到任何包含 .pretty() 的内容(至少通过 conda):http: //github.com/lark-parser/lark/blob/master/docs/json_tutorial.md