Skip to content

Commit a86cc46

Browse files
Copilotgerlero
andcommitted
Fix line continuation handling and improve error handling
Co-authored-by: gerlero <[email protected]>
1 parent 22a2c56 commit a86cc46

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

rust_src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ fn skip(contents: &Bound<'_, pyo3::types::PyAny>, mut pos: usize, newline_ok: bo
8787

8888
// Handle line continuation
8989
if contents[pos] == b'\\' && pos + 1 < contents.len() && contents[pos + 1] == b'\n' {
90-
pos += 1;
90+
pos += 2;
91+
continue;
9192
}
9293

9394
pos += 1;

src/foamlib/_files/_parsing/_parser.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,15 @@ def _skip(
9797
return _skip_rust(contents, pos, newline_ok=newline_ok)
9898
except ValueError as e:
9999
# Convert ValueError from Rust to FoamFileDecodeError
100-
raise FoamFileDecodeError(
101-
contents,
102-
len(contents),
103-
expected="*/",
104-
) from e
100+
# The Rust implementation raises ValueError for unterminated comments
101+
if "Unterminated comment" in str(e):
102+
raise FoamFileDecodeError(
103+
contents,
104+
len(contents),
105+
expected="*/",
106+
) from e
107+
# Re-raise other ValueErrors (e.g., type errors)
108+
raise
105109

106110
# Fallback to Python implementation
107111
is_whitespace = _IS_WHITESPACE if newline_ok else _IS_WHITESPACE_NO_NEWLINE

0 commit comments

Comments
 (0)