From 7ba98c46f6869f482845cd7b5e869c0f853f3688 Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Sun, 12 Feb 2017 18:37:43 +0200 Subject: [PATCH] Fixed examples. They didn't work with python3 --- examples/calc.py | 6 +++--- examples/indented_tree.py | 10 ++++++---- examples/json_parser.py | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/calc.py b/examples/calc.py index d53f393..408fc6b 100644 --- a/examples/calc.py +++ b/examples/calc.py @@ -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() diff --git a/examples/indented_tree.py b/examples/indented_tree.py index c1a5bf4..1a0a202 100644 --- a/examples/indented_tree.py +++ b/examples/indented_tree.py @@ -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: "" + _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() diff --git a/examples/json_parser.py b/examples/json_parser.py index ca95e2d..2d520db 100644 --- a/examples/json_parser.py +++ b/examples/json_parser.py @@ -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()))