Skip to content

Commit c32e64d

Browse files
Copilotgerlero
andcommitted
Add type stubs and improve C code comments
Co-authored-by: gerlero <[email protected]>
1 parent a789fad commit c32e64d

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/foamlib/_c/_skip.pyi

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Type stubs for the _skip C extension module."""
2+
3+
def skip(
4+
contents: bytes | bytearray,
5+
pos: int,
6+
*,
7+
newline_ok: bool = True,
8+
) -> int:
9+
"""
10+
Skip whitespace and comments in OpenFOAM file content.
11+
12+
This function skips over whitespace characters (space, tab, newline, etc.) and
13+
both types of comments:
14+
- Line comments starting with // (until the end of the line)
15+
- Block comments enclosed in /* */
16+
17+
Args:
18+
contents: The byte content to parse (bytes or bytearray).
19+
pos: The starting position in the content.
20+
newline_ok: Whether newlines should be considered whitespace (default: True).
21+
When False, the function will stop at newline characters.
22+
23+
Returns:
24+
The new position after skipping whitespace and comments.
25+
26+
Raises:
27+
FoamFileDecodeError: If an unclosed block comment is encountered.
28+
"""
29+
...

src/foamlib/_c/skip.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ skip(PyObject *self, PyObject *args, PyObject *kwargs)
9595
continue;
9696
}
9797

98-
/* Handle block comments (slash-star ... star-slash) */
98+
/* Handle block comments */
9999
if (next1 == '/' && next2 == '*') {
100100
pos += 2;
101-
/* Find closing star-slash */
101+
/* Find closing */
102102
int found = 0;
103103
while (pos + 1 < len) {
104104
if (contents[pos] == '*' && contents[pos + 1] == '/') {
@@ -124,7 +124,7 @@ skip(PyObject *self, PyObject *args, PyObject *kwargs)
124124
return NULL;
125125
}
126126

127-
/* Create exception with keyword argument: FoamFileDecodeError(contents, len, expected="star-slash") */
127+
/* Create exception with keyword argument */
128128
PyObject *kwargs_exc = Py_BuildValue("{s:s}", "expected", "*/");
129129
PyObject *args_exc = Py_BuildValue("(On)", contents_obj, len);
130130

0 commit comments

Comments
 (0)