@@ -12,7 +12,8 @@ Uses reconstruct_python.py for generating the final Python 2 code. | |||||
from lark import Lark | from lark import Lark | ||||
from lark.tree_templates import TemplateConf, TemplateTranslator | from lark.tree_templates import TemplateConf, TemplateTranslator | ||||
from reconstruct_python import PythonIndenter, PythonReconstructor | |||||
from lark.indenter import PythonIndenter | |||||
from reconstruct_python import PythonReconstructor | |||||
# | # | ||||
@@ -12,17 +12,9 @@ from io import open | |||||
import glob, time | import glob, time | ||||
from lark import Lark | 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') | kwargs = dict(postlex=PythonIndenter(), start='file_input') | ||||
# Official Python grammar by Lark | # Official Python grammar by Lark | ||||
@@ -10,13 +10,11 @@ a small formatter. | |||||
from lark import Lark, Token | from lark import Lark, Token | ||||
from lark.reconstruct import Reconstructor | from lark.reconstruct import Reconstructor | ||||
from python_parser import PythonIndenter | |||||
from lark.indenter import PythonIndenter | |||||
# Official Python grammar by Lark | # 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(',+-*/~@<>="|:') | SPACE_AFTER = set(',+-*/~@<>="|:') | ||||
@@ -101,3 +101,12 @@ class Indenter(PostLex, ABC): | |||||
raise NotImplementedError() | 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 |