Skip to content

Commit 2fb9631

Browse files
committed
Allow bareword keys in nested action-arg hashes
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.
1 parent f571e3a commit 2fb9631

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

bionetgen/core/utils/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,10 @@ def define_parser(self):
487487
arg_type_list = "[" + pp.delimitedList((quote_word ^ arg_type_float)) + "]"
488488
arg_type_string = quote_word
489489
#
490-
curly_arg_token = quote_word + "=>" + arg_type_int
490+
# BNGL/Perl `=>` auto-quotes its left operand, so dict keys
491+
# may be either bareword (max_stoich=>{R=>6}) or quoted
492+
# (max_stoich=>{"R"=>6}). Accept both.
493+
curly_arg_token = (base_name ^ quote_word) + "=>" + arg_type_int
491494
# TODO: handle 0 case
492495
arg_type_curly = "{" + pp.delimitedList(curly_arg_token) + "}"
493496
arg_types = (

0 commit comments

Comments
 (0)