Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify the handling of infinite quantification limit across tree codecs #230

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading