Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/openmc_mcnp_adapter/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_read_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading