Skip to content

Commit

Permalink
Unify the handling of infinite quantification limit across tree codecs (
Browse files Browse the repository at this point in the history
#230)

From now, not only the flatbuffers but also the json tree codec represents
the infinite quantification limit with the value of -1.
  • Loading branch information
renatahodovan authored Jun 5, 2024
1 parent 240ce2b commit 7bb9556
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions grammarinator/tool/tree_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def _rule_to_dict(node):
if isinstance(node, UnparserRuleQuantified):
return {'t': 'qd', 'c': node.children}
if isinstance(node, UnparserRuleQuantifier):
return {'t': 'q', 'i': node.idx, 'b': node.start, 'e': node.stop, 'c': node.children}
return {'t': 'q', 'i': node.idx, 'b': node.start, 'e': node.stop if node.stop != inf else -1, 'c': node.children}
raise AssertionError
return json.dumps(root, default=_rule_to_dict).encode(encoding=self._encoding, errors=self._encoding_errors)

Expand All @@ -152,7 +152,7 @@ def _dict_to_rule(dct):
if dct['t'] == 'qd':
return UnparserRuleQuantified(children=dct['c'])
if dct['t'] == 'q':
return UnparserRuleQuantifier(idx=dct['i'], start=dct['b'], stop=dct['e'], children=dct['c'])
return UnparserRuleQuantifier(idx=dct['i'], start=dct['b'], stop=dct['e'] if dct['e'] != -1 else inf, children=dct['c'])
raise json.JSONDecodeError

try:
Expand Down

0 comments on commit 7bb9556

Please sign in to comment.