Skip to content

Commit 44f86af

Browse files
committed
Process review feedback
1 parent 16e6b8b commit 44f86af

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

dissect/cstruct/expression.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858

5959

6060
def precedence(o1: TokenType, o2: TokenType) -> bool:
61+
# Unary (prefix) operators are right-associative, so use strict greater-than
62+
if o2 in UNARY_OPERATORS:
63+
return PRECEDENCE_LEVELS[o1] > PRECEDENCE_LEVELS[o2]
6164
return PRECEDENCE_LEVELS[o1] >= PRECEDENCE_LEVELS[o2]
6265

6366

dissect/cstruct/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def _parse_include(self) -> None:
211211

212212
def _parse_config_flags(self) -> None:
213213
"""Parse configuration flags from a directive like ``#[flag1, flag2, ...]``."""
214-
self._flags.extend(self._expect(TokenType.PP_FLAGS).value.split(","))
214+
self._flags.extend(flag.strip() for flag in self._expect(TokenType.PP_FLAGS).value.split(","))
215215

216216
def _handle_conditional(self) -> None:
217217
"""Handle conditional directives: ``#ifdef``, ``#ifndef``, ``#else``, ``#endif``."""

tests/test_expression.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def cs_with_consts(cs: cstruct) -> cstruct:
7171
("21 - B", 8),
7272
("A + B", 21),
7373
("~1", -2),
74+
("-~1", 2),
7475
("~(A + 5)", ~13),
7576
("10l", 10),
7677
("10ll", 10),

tests/test_parser.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dissect.cstruct import cstruct
66
from dissect.cstruct.exceptions import ParserError, ResolveError
77
from dissect.cstruct.lexer import tokenize
8+
from dissect.cstruct.parser import CStyleParser
89
from dissect.cstruct.types import BaseArray, Pointer, Structure
910
from tests.utils import verify_compiled
1011

@@ -361,3 +362,14 @@ def test_multiple_declarators(cs: cstruct) -> None:
361362
assert cs.test.fields["c"].type == cs.uint32
362363
assert cs.test.fields["d"].type.__name__ == "__anonymous_0__"
363364
assert cs.test.fields["e"].type is cs.test.fields["d"].type
365+
366+
367+
def test_config_flags(cs: cstruct) -> None:
368+
"""Test that we parse configuration flag directives correctly."""
369+
cdef = """
370+
#[a, b, c]
371+
"""
372+
parser = CStyleParser(cs)
373+
parser.parse(cdef)
374+
375+
assert parser._flags == ["a", "b", "c"]

0 commit comments

Comments
 (0)