Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

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

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

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