From 9b398bd827030e5283dd6e913f3c952ca4d31393 Mon Sep 17 00:00:00 2001 From: "Travis J. Labossiere-Hickman" Date: Thu, 7 May 2026 13:04:09 -0600 Subject: [PATCH 1/2] Don't expand `read file` in comments. --- src/openmc_mcnp_adapter/parse.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/openmc_mcnp_adapter/parse.py b/src/openmc_mcnp_adapter/parse.py index dcf9a26..8245971 100644 --- a/src/openmc_mcnp_adapter/parse.py +++ b/src/openmc_mcnp_adapter/parse.py @@ -26,12 +26,12 @@ ) _READ_RE = re.compile(r""" - ^ # Beginning of line + ^\s*(?!c\b) # Beginning of line that is not a comment line \s*read # Keyword \s.*?file # Everything up to filename \s*=\s* # = sign (required) with optional spaces - (\S+) # The file name is anything without whitespace - .* # Anything else until end-of-line + ([^$\s]+) # The file name stops at whitespace or $ + [^$\n]* # Anything else until end-of-line or $ """, re.IGNORECASE | re.VERBOSE | re.MULTILINE ) From 20d6ee3f0fc1cafec5f16284f4d597dc3956a4f6 Mon Sep 17 00:00:00 2001 From: "Travis J. Labossiere-Hickman" Date: Thu, 7 May 2026 13:24:33 -0600 Subject: [PATCH 2/2] Verify that 'read file' doesn't actuate in comments. --- tests/test_read_file.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_read_file.py b/tests/test_read_file.py index 1fc94c8..1283e1e 100644 --- a/tests/test_read_file.py +++ b/tests/test_read_file.py @@ -19,6 +19,22 @@ def test_read_not_found(): mcnp_str_to_model(deck) +def test_dont_read_comments(): + deck = textwrap.dedent(""" + title + c The next line would point to an invalid file + c read file=/badfile.path + 1 0 -1 + + c The next line would also point to an invalid file + 1 so 1.0 $ read file=/badfile.path + + c + nps 1 + """) + mcnp_str_to_model(deck) + + def test_read_recursive(): reference = expand_read_cards(INPUT_DIR / "testReadReference.imcnp") trial = expand_read_cards(INPUT_DIR / "testRead.imcnp")