Skip to content

Allow bareword keys in nested action-arg hashes#78

Open
wshlavacek wants to merge 1 commit intoRuleWorld:mainfrom
wshlavacek:modelapi-bareword-nested-hash-keys
Open

Allow bareword keys in nested action-arg hashes#78
wshlavacek wants to merge 1 commit intoRuleWorld:mainfrom
wshlavacek:modelapi-bareword-nested-hash-keys

Conversation

@wshlavacek
Copy link
Copy Markdown

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.
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.

1 participant