Commit ce75dc7b authored by di68kap's avatar di68kap

- Refactoring: removed syntaxtree.Node.parser

parent c5464ea9
......@@ -431,10 +431,10 @@ class Node: # (collections.abc.Sized): Base class omitted for cython-compatibil
return self._tag_name[0] == ':'
@property
def parser(self) -> MockParser:
name, ptype = (self.tag_name.split(':') + [''])[:2]
return MockParser(name, ':' + ptype)
# @property
# def parser(self) -> MockParser:
# name, ptype = (self.tag_name.split(':') + [''])[:2]
# return MockParser(name, ':' + ptype)
@property
......
......@@ -172,7 +172,7 @@ def get_grammar() -> LaTeXGrammar:
def streamline_whitespace(context):
if context[-2].parser.ptype == ":_Token":
if context[-2].tag_name == TOKEN_PTYPE:
return
node = context[-1]
assert node.tag_name in ['WSPC', ':Whitespace']
......@@ -200,7 +200,7 @@ def is_commandname(context):
"""Returns True, if last node in the content represents a (potentially
unknown) LaTeX-command."""
node = context[-1]
if node.parser.ptype == TOKEN_PTYPE:
if node.tag_name == TOKEN_PTYPE:
parent = context[-2]
if len(parent.children) > 1:
parent_name = parent.tag_name.lower()
......
......@@ -83,6 +83,8 @@ def tst_func():
print('Saving AST')
with open('LOGS/' + file[:-4] + '.ast', 'w', encoding='utf-8') as f:
f.write(result.as_sxpr(compact=True))
with open('LOGS/' + file[:-4] + '.tex', 'w', encoding='utf-8') as f:
f.write(str(result))
print('\nCompiling document: "%s"' % file)
output = compiler(result)
......
......@@ -176,7 +176,7 @@ class TestRegex:
parser = compile_python_object(DHPARSER_IMPORTS + result, '\w+Grammar$')()
node = parser('abc+def', parser.regex)
assert not node.error_flag
assert node.parser.name == "regex"
assert node.tag_name == "regex"
assert str(node) == 'abc+def'
def test_multilineRegex_wo_Comments(self):
......@@ -192,7 +192,7 @@ class TestRegex:
parser = compile_python_object(DHPARSER_IMPORTS + result, '\w+Grammar$')()
node = parser('abc+def', parser.regex)
assert not node.error_flag
assert node.parser.name == "regex"
assert node.tag_name == "regex"
assert str(node) == 'abc+def'
def text_ignore_case(self):
......@@ -209,7 +209,7 @@ class TestRegex:
assert node
assert not node.error_flag
assert rest == ''
assert node.parser.name == "regex"
assert node.tag_name == "regex"
assert str(node) == 'Alpha'
mlregex = r"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment