Decode && / || boolean operators when re-emitting from BNG-XML#76
Open
wshlavacek wants to merge 1 commit intoRuleWorld:mainfrom
Open
Decode && / || boolean operators when re-emitting from BNG-XML#76wshlavacek wants to merge 1 commit intoRuleWorld:mainfrom
&& / || boolean operators when re-emitting from BNG-XML#76wshlavacek wants to merge 1 commit intoRuleWorld:mainfrom
Conversation
BNG2.pl's <Expression> serializer rewrites the binary operators ``&&`` and ``||`` as the function-call-shaped strings ``(L)and(R)`` and ``(L)or(R)`` (see Perl2/Expression.pm: '&&' => 'and'). Reading <Expression> verbatim and re-emitting it into a regenerated .bngl file confuses BNG2.pl's BNGL parser, which sees ``and(...)`` as a function call and aborts with "Missing end parentheses ... at and(...)". Fix: in xmlparsers, run a regex pass that maps ``)and(`` → ``) && (`` and ``)or(`` → ``) || (`` before storing the function expression. The match is anchored on the close-paren of the left operand because BNG2.pl always wraps both operands in parens for these forms — so ``)and(`` / ``)or(`` only ever appear as the boolean-operator encoding and never as the suffix of a user identifier or a literal function call.
4 tasks
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
BNG2.pl's
<Expression>serializer rewrites the binary operators&&and||as the function-call-shaped strings(L)and(R)and(L)or(R)(seePerl2/Expression.pm:'&&' => 'and'). Whenbionetgen.modelapireads<Expression>verbatim and re-emits the function body into a regenerated.bngl, BNG2.pl's BNGL parser seesand(...)as a function call and aborts:This breaks any round-trip workflow (parse a BNGL → regenerate it → re-run with BNG2.pl) for models that use boolean operators inside function bodies. Smallest repro is a function like:
After XML round-trip this becomes
if((plusBafA1==1)and(t>=0), 0, 1)which BNG2.pl rejects.Fix
In
bionetgen/modelapi/xmlparsers.py, add a regex pass that maps)and(→) && (and)or(→) || (before storing the function expression. The match is intentionally anchored on the close-paren of the left operand because BNG2.pl always wraps both operands in parens for these forms — so)and(/)or(only ever appear as the boolean-operator encoding and never as the tail of a user-defined identifier (e.g.random(x)) or a literal function call.Test plan
&&/||in a function body: parse → write_model → BNG2.pl simulaterandom(x) + myop(y)is preserved verbatim (no spurious rewrites of)and(-shaped substrings that aren't actually boolean ops — there shouldn't be any, but worth checking)