Skip to content

Allow bareword keys in nested action-arg hashes#78

Merged
jrfaeder merged 1 commit into
RuleWorld:mainfrom
wshlavacek:modelapi-bareword-nested-hash-keys
May 11, 2026
Merged

Allow bareword keys in nested action-arg hashes#78
jrfaeder merged 1 commit into
RuleWorld:mainfrom
wshlavacek:modelapi-bareword-nested-hash-keys

Conversation

@wshlavacek
Copy link
Copy Markdown
Contributor

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

  • Existing CI passes
  • Round-trip a model with `generate_network({max_stoich=>{R=>6}})` parses cleanly
  • Round-trip a model with `generate_network({max_stoich=>{"R"=>6}})` (quoted form) still parses cleanly

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.
@jrfaeder jrfaeder merged commit 1859739 into RuleWorld:main May 11, 2026
17 checks passed
@wshlavacek wshlavacek deleted the modelapi-bareword-nested-hash-keys branch May 11, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants