Allow bareword keys in nested action-arg hashes#78
Open
wshlavacek wants to merge 1 commit intoRuleWorld:mainfrom
Open
Allow bareword keys in nested action-arg hashes#78wshlavacek wants to merge 1 commit intoRuleWorld:mainfrom
wshlavacek wants to merge 1 commit intoRuleWorld:mainfrom
Conversation
BNGL inherits Perl's `=>` fat-comma semantics, so action arguments like
`generate_network({overwrite=>1,max_stoich=>{R=>6}})` are syntactically
valid even though the inner hash key `R` is unquoted. The pyparsing
grammar in `ActionList.define_parser()` required `quote_word` for
nested-curly keys, so any model that relied on bareword keys (notably
`max_stoich=>{<molecule>=><N>}`) failed at parse time before BNG2.pl
was ever invoked.
Accept either bareword or quoted keys inside nested hashes:
curly_arg_token = (base_name ^ quote_word) + "=>" + arg_type_int
The existing dict-handling path in `BNGParser._parse_action_line` rebuilds
the literal substring verbatim, so round-trip via `Action.gen_string()`
is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BNGL inherits Perl's `=>` fat-comma semantics, so action arguments like `generate_network({overwrite=>1,max_stoich=>{R=>6}})` are syntactically valid even though the inner hash key `R` is unquoted (the `=>` auto-quotes its left operand).
The pyparsing grammar in `ActionList.define_parser()` (`bionetgen/core/utils/utils.py`) requires `quote_word` for nested-curly keys, so any model that uses bareword keys — notably `max_stoich=>{=>}` — fails at parse time before BNG2.pl is ever invoked.
Fix
Accept either bareword or quoted keys inside nested hashes:
```python
curly_arg_token = (base_name ^ quote_word) + "=>" + arg_type_int
```
The existing dict-handling path in `BNGParser._parse_action_line` rebuilds the literal substring verbatim, so round-trip via `Action.gen_string()` is unchanged.
Test plan