Problem:
# 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=" " )
Specific Error:
- AttributeError: type object 'Lark' has no attribute 'pretty'
Setup:
Python version = 3.8.1
In Miniconda 3 on Mac Bug Sur
conda install lark-parser
Installed 0.11.2-pyh44b312d_0
conda upgrade lark-parser
Installed 0.11.3-pyhd8ed1ab_0
Edit: Note about my Goal:
The goal here is NOT just to parse JSON; I just happen to be using a JSON example to try and learn. I want to write my own grammar for some data that I'm dealing with at work.
Edit: Why I Believe Pretty Print Should Exist:
Here's an example that uses the .pretty() function, and even includes output. But I can't seem to find anything (via conda at least) that includes .pretty(): http://github.com/lark-parser/lark/blob/master/docs/json_tutorial.md