From 35f2acc8e0a9b97964664bb093f4e63e6c8b79e0 Mon Sep 17 00:00:00 2001 From: Bill Hlavacek Date: Sun, 10 May 2026 17:15:23 -0600 Subject: [PATCH] Anchor BNGL action-name detection to start-of-line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `BNGFile._not_action` does an unanchored substring search of action names against each line, so any line that *contains* an action name as a substring gets pulled out of its block and pushed into the action list. The repeated repro is `conversion()=...` inside a `begin functions` block — the substring `version(` matches the `version` action prefix and the line gets misclassified. Same pitfall exists for `bifurcate` (any identifier ending in `...ifurcate`), `simulate_ssa` / `simulate_nf` / `simulate_pla` / `simulate_ode` (any expression that mentions one of these names), and `readFile` / `writeFile` (any path or function with the substring). Fix: anchor the match to the start of the left-stripped line so user identifiers that look like an action name in the middle of an expression are no longer misclassified. Indentation is allowed before the action name to match the existing behavior. --- bionetgen/modelapi/bngfile.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bionetgen/modelapi/bngfile.py b/bionetgen/modelapi/bngfile.py index a601a374..0411ae62 100644 --- a/bionetgen/modelapi/bngfile.py +++ b/bionetgen/modelapi/bngfile.py @@ -192,8 +192,14 @@ def strip_actions(self, model_path, folder) -> str: return stripped_model def _not_action(self, line) -> bool: + # Anchor the match to the start of the (left-stripped) line so that + # user identifiers containing an action name as a substring — most + # commonly ``conversion()`` (the substring ``version(`` matches the + # ``version`` action) inside a ``begin functions`` block — aren't + # misclassified and pulled out as actions. + stripped = line.lstrip() for action in self._action_list: - if action in line: + if stripped.startswith(action): return False return True