Skip to content

Commit 16e6b8b

Browse files
committed
Rewrite lexer and parser
1 parent edf9f8e commit 16e6b8b

14 files changed

Lines changed: 1617 additions & 958 deletions

dissect/cstruct/cstruct.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from dissect.cstruct.exceptions import ResolveError
1111
from dissect.cstruct.expression import Expression
12-
from dissect.cstruct.parser import CStyleParser, TokenParser
12+
from dissect.cstruct.parser import CStyleParser
1313
from dissect.cstruct.types import (
1414
LEB128,
1515
BaseArray,
@@ -267,9 +267,9 @@ def load(self, definition: str, deftype: int | None = None, **kwargs) -> cstruct
267267
deftype = deftype or cstruct.DEF_CSTYLE
268268

269269
if deftype == cstruct.DEF_CSTYLE:
270-
TokenParser(self, **kwargs).parse(definition)
271-
elif deftype == cstruct.DEF_LEGACY:
272270
CStyleParser(self, **kwargs).parse(definition)
271+
else:
272+
raise ValueError(f"Unknown definition type: {deftype}")
273273

274274
return self
275275

dissect/cstruct/exceptions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ class Error(Exception):
55
pass
66

77

8+
class LexerError(Error):
9+
pass
10+
11+
812
class ParserError(Error):
913
pass
1014

@@ -23,7 +27,3 @@ class ArraySizeError(Error):
2327

2428
class ExpressionParserError(Error):
2529
pass
26-
27-
28-
class ExpressionTokenizerError(Error):
29-
pass

0 commit comments

Comments
 (0)