Commit e4638fde authored by Eckhart Arnold's avatar Eckhart Arnold

- syntaxtree.py, parser.py: yet better string representation of parsers

parent f944249f
......@@ -150,9 +150,8 @@ class HistoryRecord:
@property
def stack(self) -> str:
def ptos(p):
return
return "->".join(str(parser) for parser in self.call_stack)
return "->".join((repr(p) if p.ptype == ':RegExp' else p.name or p.ptype)
for p in self.call_stack)
@property
def status(self) -> str:
......@@ -629,9 +628,6 @@ class RegExp(Parser):
def __repr__(self):
return '/%s/' % self.regexp.pattern
def __str__(self):
return repr(self)
class Whitespace(RegExp):
assert WHITESPACE_PTYPE == ":Whitespace"
......@@ -697,9 +693,6 @@ class RE(Parser):
wR = '~' if self.wR else ''
return wL + '/%s/' % self.main.regexp.pattern + wR
def __str__(self):
return self.name or repr(self)
def _grammar_assigned_notifier(self):
if self.grammar:
# use default whitespace parsers if not otherwise specified
......
......@@ -83,8 +83,11 @@ class ParserBase:
self.name = name # type: str
self._ptype = ':' + self.__class__.__name__ # type: str
def __repr__(self):
return self.name + self.ptype
def __str__(self):
return self.name or self.ptype
return self.name + (' = ' if self.name else '') + repr(self)
@property
def ptype(self) -> str:
......
......@@ -39,7 +39,7 @@ def selftest(file_name):
print("\nAlphabetical List of Parsers:\n")
parser_list = sorted([p for p in parser.all_parsers__ if p.name], key=lambda p: p.name)
for p in parser_list:
print("%s = %s" % (p.name, repr(p)))
print(p)
print('\n\n')
transformer = get_ebnf_transformer()
compiler = get_ebnf_compiler(compiler_name, grammar)
......@@ -86,5 +86,5 @@ if __name__ == "__main__":
else:
# run self test
# selftest('EBNF/EBNF.ebnf')
with logging(False):
with logging(True):
profile(partial(selftest, file_name='EBNF/EBNF.ebnf'))
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