diff --git a/examples/advanced/py3to2.py b/examples/advanced/py3to2.py index 59a6f91..e08967c 100644 --- a/examples/advanced/py3to2.py +++ b/examples/advanced/py3to2.py @@ -12,7 +12,8 @@ Uses reconstruct_python.py for generating the final Python 2 code. from lark import Lark from lark.tree_templates import TemplateConf, TemplateTranslator -from reconstruct_python import PythonIndenter, PythonReconstructor +from lark.indenter import PythonIndenter +from reconstruct_python import PythonReconstructor # diff --git a/examples/advanced/python_parser.py b/examples/advanced/python_parser.py index 40e8605..78f8520 100644 --- a/examples/advanced/python_parser.py +++ b/examples/advanced/python_parser.py @@ -12,17 +12,9 @@ from io import open import glob, time from lark import Lark -from lark.indenter import Indenter +from lark.indenter import PythonIndenter -class PythonIndenter(Indenter): - NL_type = '_NEWLINE' - OPEN_PAREN_types = ['LPAR', 'LSQB', 'LBRACE'] - CLOSE_PAREN_types = ['RPAR', 'RSQB', 'RBRACE'] - INDENT_type = '_INDENT' - DEDENT_type = '_DEDENT' - tab_len = 8 - kwargs = dict(postlex=PythonIndenter(), start='file_input') # Official Python grammar by Lark diff --git a/examples/advanced/reconstruct_python.py b/examples/advanced/reconstruct_python.py index 76dfd9f..1724846 100644 --- a/examples/advanced/reconstruct_python.py +++ b/examples/advanced/reconstruct_python.py @@ -10,13 +10,11 @@ a small formatter. from lark import Lark, Token from lark.reconstruct import Reconstructor - -from python_parser import PythonIndenter +from lark.indenter import PythonIndenter # Official Python grammar by Lark -python_parser3 = Lark.open_from_package('lark', 'python.lark', ['grammars'], - parser='lalr', postlex=PythonIndenter(), - start='file_input', maybe_placeholders=False) +kwargs = dict(parser='lalr', postlex=PythonIndenter(), start='file_input', maybe_placeholders=False) +python_parser3 = Lark.open_from_package('lark', 'python.lark', ['grammars'], **kwargs) SPACE_AFTER = set(',+-*/~@<>="|:') diff --git a/lark/indenter.py b/lark/indenter.py index 1121104..7482923 100644 --- a/lark/indenter.py +++ b/lark/indenter.py @@ -101,3 +101,12 @@ class Indenter(PostLex, ABC): raise NotImplementedError() ###} + + +class PythonIndenter(Indenter): + NL_type = '_NEWLINE' + OPEN_PAREN_types = ['LPAR', 'LSQB', 'LBRACE'] + CLOSE_PAREN_types = ['RPAR', 'RSQB', 'RBRACE'] + INDENT_type = '_INDENT' + DEDENT_type = '_DEDENT' + tab_len = 8 \ No newline at end of file