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