mirror of https://github.com/lark-parser/lark.git
Fixed examples. They didn't work with python3
This commit is contained in:
parent
9c1a81b709
commit
7ba98c46f6
|
@ -22,7 +22,7 @@ calc_grammar = """
|
|||
"""
|
||||
|
||||
class CalculateTree(InlineTransformer):
|
||||
from operator import add, sub, mul, div, neg
|
||||
from operator import add, sub, mul, truediv as div, neg
|
||||
number = float
|
||||
|
||||
def __init__(self):
|
||||
|
@ -50,8 +50,8 @@ def main():
|
|||
|
||||
def test():
|
||||
# print calc("a=(1+2)")
|
||||
print calc("a = 1+2")
|
||||
print calc("1+a*-3")
|
||||
print(calc("a = 1+2"))
|
||||
print(calc("1+a*-3"))
|
||||
|
||||
if __name__ == '__main__':
|
||||
test()
|
||||
|
|
|
@ -7,15 +7,17 @@ It is crucial for the indenter that the NL_type matches the spaces (and tabs) af
|
|||
from lark.lark import Lark
|
||||
from lark.indenter import Indenter
|
||||
|
||||
tree_grammar = """
|
||||
tree_grammar = r"""
|
||||
?start: _NL* tree
|
||||
|
||||
tree: /\w+/ _NL [_INDENT tree+ _DEDENT]
|
||||
tree: NAME _NL [_INDENT tree+ _DEDENT]
|
||||
|
||||
NAME: /\w+/
|
||||
|
||||
WS.ignore: /\s+/
|
||||
_NL.newline: /(\r?\n[\t ]*)+/
|
||||
_NL: /(\r?\n[\t ]*)+/
|
||||
_INDENT: "<INDENT>"
|
||||
_DEDENT: "<DEDENT>"
|
||||
"""
|
||||
|
||||
class TreeIndenter(Indenter):
|
||||
|
@ -39,7 +41,7 @@ a
|
|||
"""
|
||||
|
||||
def test():
|
||||
print parser.parse(test_tree).pretty()
|
||||
print(parser.parse(test_tree).pretty())
|
||||
|
||||
if __name__ == '__main__':
|
||||
test()
|
||||
|
|
|
@ -53,12 +53,12 @@ def test():
|
|||
'''
|
||||
|
||||
j = parse(test_json)
|
||||
print j
|
||||
print(j)
|
||||
import json
|
||||
assert j == json.loads(test_json)
|
||||
|
||||
if __name__ == '__main__':
|
||||
test()
|
||||
with open(sys.argv[1]) as f:
|
||||
print parse(f.read())
|
||||
print(parse(f.read()))
|
||||
|
||||
|
|
Loading…
Reference in New Issue