Commit f944249f authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

- syntaxtree.py, parser.py: __str__ methods adjusted for history recording

parent 1b046e5e
...@@ -150,6 +150,8 @@ class HistoryRecord: ...@@ -150,6 +150,8 @@ class HistoryRecord:
@property @property
def stack(self) -> str: def stack(self) -> str:
def ptos(p):
return
return "->".join(str(parser) for parser in self.call_stack) return "->".join(str(parser) for parser in self.call_stack)
@property @property
...@@ -627,6 +629,9 @@ class RegExp(Parser): ...@@ -627,6 +629,9 @@ class RegExp(Parser):
def __repr__(self): def __repr__(self):
return '/%s/' % self.regexp.pattern return '/%s/' % self.regexp.pattern
def __str__(self):
return repr(self)
class Whitespace(RegExp): class Whitespace(RegExp):
assert WHITESPACE_PTYPE == ":Whitespace" assert WHITESPACE_PTYPE == ":Whitespace"
...@@ -692,11 +697,8 @@ class RE(Parser): ...@@ -692,11 +697,8 @@ class RE(Parser):
wR = '~' if self.wR else '' wR = '~' if self.wR else ''
return wL + '/%s/' % self.main.regexp.pattern + wR return wL + '/%s/' % self.main.regexp.pattern + wR
# def __str__(self): def __str__(self):
# if self.ptype == TOKEN_PTYPE: return self.name or repr(self)
# return 'Token "%s"' % self.main.regexp.pattern.replace('\\', '')
# return self.name or ('RE ' + ('~' if self.wL else '')
# + '/%s/' % self.main.regexp.pattern + ('~' if self.wR else ''))
def _grammar_assigned_notifier(self): def _grammar_assigned_notifier(self):
if self.grammar: if self.grammar:
......
...@@ -83,11 +83,8 @@ class ParserBase: ...@@ -83,11 +83,8 @@ class ParserBase:
self.name = name # type: str self.name = name # type: str
self._ptype = ':' + self.__class__.__name__ # type: str self._ptype = ':' + self.__class__.__name__ # type: str
def __repr__(self):
self.name + self.ptype
def __str__(self): def __str__(self):
return self.name or repr(self) return self.name or self.ptype
@property @property
def ptype(self) -> str: def ptype(self) -> str:
...@@ -113,9 +110,6 @@ class MockParser(ParserBase): ...@@ -113,9 +110,6 @@ class MockParser(ParserBase):
self.name = name self.name = name
self._ptype = ptype or ':' + self.__class__.__name__ self._ptype = ptype or ':' + self.__class__.__name__
# def __repr__(self):
# return repr_call(self.__init__, (self.name, self.ptype))
class ZombieParser(MockParser): class ZombieParser(MockParser):
""" """
......
...@@ -20,7 +20,7 @@ inlineenv = beginenv { command | block | text }+ endenv ...@@ -20,7 +20,7 @@ inlineenv = beginenv { command | block | text }+ endenv
beginenv = "\begin{" §NAME §"}" beginenv = "\begin{" §NAME §"}"
endenv = "\end{" §::NAME §"}" endenv = "\end{" §::NAME §"}"
command = CMDNAME [ config ] block command = CMDNAME [[ config ] block]
config = "[" cfgtext §"]" config = "[" cfgtext §"]"
block = "{" { text | block } §"}" block = "{" { text | block } §"}"
......
...@@ -20,6 +20,8 @@ See the License for the specific language governing permissions and ...@@ -20,6 +20,8 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
""" """
import cProfile
import functools
import sys import sys
sys.path.extend(['../../', '../', './']) sys.path.extend(['../../', '../', './'])
...@@ -27,6 +29,18 @@ sys.path.extend(['../../', '../', './']) ...@@ -27,6 +29,18 @@ sys.path.extend(['../../', '../', './'])
from DHParser.toolkit import logging from DHParser.toolkit import logging
from DHParser.testing import recompile_grammar from DHParser.testing import recompile_grammar
with logging():
if not recompile_grammar('.', True): def profile(func):
import cProfile
pr = cProfile.Profile()
pr.enable()
ret = func()
pr.disable()
# after your program ends
pr.print_stats(sort="tottime")
return ret
with logging(False):
if not profile(functools.partial(recompile_grammar, ebnf_filename='.', force=True)):
sys.exit(1) sys.exit(1)
...@@ -73,7 +73,6 @@ ARITHMETIC2_EBNF = """ ...@@ -73,7 +73,6 @@ ARITHMETIC2_EBNF = """
# #
# #
# ARITHMETIC_EBNFTransform = partial(traverse, processing_table=ARITHMETIC_EBNF_transformation_table) # ARITHMETIC_EBNFTransform = partial(traverse, processing_table=ARITHMETIC_EBNF_transformation_table)
# ARITHMETIC2_EBNFTransform = partial(traverse, processing_table=ARITHMETIC2_EBNF_transformation_table)
class TestInfiLoopsAndRecursion: class TestInfiLoopsAndRecursion:
...@@ -248,8 +247,8 @@ class TestPopRetrieve: ...@@ -248,8 +247,8 @@ class TestPopRetrieve:
assert not syntax_tree.error_flag, str(syntax_tree.collect_errors()) assert not syntax_tree.error_flag, str(syntax_tree.collect_errors())
def test_cache_neutrality(self): def test_cache_neutrality(self):
"""Test that packrat-caching does not interfere with """Test that packrat-caching does not interfere with the variable-
Capture-Retrieve-Stack.""" changing parsers: Capture and Retrieve."""
lang = """ lang = """
text = opening closing text = opening closing
opening = (unmarked_package | marked_package) opening = (unmarked_package | marked_package)
......
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