Skip to content

Commit

Permalink
Add debug message to rules
Browse files Browse the repository at this point in the history
  • Loading branch information
renatahodovan committed Dec 11, 2023
1 parent 4314fed commit d01e4bd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion grammarinator/runtime/rule.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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), '| '))

0 comments on commit d01e4bd

Please sign in to comment.