From d01e4bdf9d08a68ff4bd0a51504957742d7affe0 Mon Sep 17 00:00:00 2001 From: Renata Hodovan Date: Sun, 3 Dec 2023 03:08:36 +0100 Subject: [PATCH] Add debug message to rules --- grammarinator/runtime/rule.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/grammarinator/runtime/rule.py b/grammarinator/runtime/rule.py index a6a573a..fa531b1 100644 --- a/grammarinator/runtime/rule.py +++ b/grammarinator/runtime/rule.py @@ -311,7 +311,7 @@ def __repr__(self): return f'{self.__class__.__name__}({", ".join(parts)})' def _dbg_(self): - return '{name}\n{children}'.format(name=self.name, children=indent('\n'.join(child._dbg_() for child in self.children), '| ')) + return '{name}\n{children}'.format(name=self.name or self.__class__.__name__, children=indent('\n'.join(child._dbg_() for child in self.children), '| ')) class UnparserRule(ParentRule): @@ -412,6 +412,9 @@ def __repr__(self): def __deepcopy__(self, memo): return UnparserRuleQuantifier(idx=deepcopy(self.idx, memo), start=deepcopy(self.start, memo), stop=deepcopy(self.stop, memo), children=[deepcopy(child, memo) for child in self.children]) + def _dbg_(self): + return '{name}:[{idx}]\n{children}'.format(idx=self.idx, name=self.__class__.__name__, children=indent('\n'.join(child._dbg_() for child in self.children), '| ')) + class UnparserRuleQuantified(ParentRule): """ @@ -455,3 +458,6 @@ def __deepcopy__(self, memo): return UnparserRuleAlternative(alt_idx=deepcopy(self.alt_idx, memo), idx=deepcopy(self.idx, memo), children=[deepcopy(child, memo) for child in self.children]) + + def _dbg_(self): + return '{name}:[{alt_idx}/{idx}]\n{children}'.format(name=self.__class__.__name__, alt_idx=self.alt_idx, idx=self.idx, children=indent('\n'.join(child._dbg_() for child in self.children), '| '))