Skip to content

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

Merged
jrfaeder merged 1 commit into
RuleWorld:mainfrom
wshlavacek:modelapi-b18-comment-line-continuation
May 11, 2026
Merged

Don't collapse \ continuations inside commented BNGL lines#79
jrfaeder merged 1 commit into
RuleWorld:mainfrom
wshlavacek:modelapi-b18-comment-line-continuation

Conversation

@wshlavacek
Copy link
Copy Markdown
Contributor

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.
@jrfaeder jrfaeder merged commit e6588db into RuleWorld:main May 11, 2026
17 checks passed
@wshlavacek wshlavacek deleted the modelapi-b18-comment-line-continuation 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