Skip to content

Don't collapse \ continuations inside commented BNGL lines#79

Open
wshlavacek wants to merge 1 commit intoRuleWorld:mainfrom
wshlavacek:modelapi-b18-comment-line-continuation
Open

Don't collapse \ continuations inside commented BNGL lines#79
wshlavacek wants to merge 1 commit intoRuleWorld:mainfrom
wshlavacek:modelapi-b18-comment-line-continuation

Conversation

@wshlavacek
Copy link
Copy Markdown

Summary

`BNGFile.strip_actions` folds trailing-backslash line continuations before the action parser sees them, but the regex doesn't currently respect comments. A commented-out

```

foo()=if(t<42,0,\


immediately above a live

\`\`\`
foo()=if(t<42,9.899,\

glues both into the comment, and the live definition silently disappears from the rendered `.bngl` (and from any `.net` BNG2.pl generates downstream).

Fix

Anchor the regex to start-of-line and require no `#` between that and the trailing `\` — comment lines keep their continuation markers as part of the comment body, which is what BNG2.pl itself does.

```python
mstr = re.sub(r"^([^#\n]*)\\n", r"\1", mstr, flags=re.MULTILINE)


## Test plan

- [ ] Existing CI passes
- [ ] A model with a commented-out \`\\\`-continuation immediately above a live function definition preserves the live definition through round-trip

`BNGFile.strip_actions` folds trailing-backslash line continuations before
the action parser sees them, but the previous regex didn't respect
comments: a commented-out

    # foo()=if(t<42,0,\

immediately above a live

    foo()=if(t<42,9.899,\

glued both into the comment, and the live definition silently
disappeared from the rendered `.bngl` (and from any `.net` BNG2.pl
generated downstream).

Fix: anchor the regex to start-of-line and require no `#` between that
and the trailing `\` — comment lines keep their continuation markers as
part of the comment body, which is what BNG2.pl itself does.
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