Skip to content

Commit 7678a8f

Browse files
authored
Rewrite lexer and parser (#146)
1 parent 91f2347 commit 7678a8f

16 files changed

Lines changed: 1921 additions & 976 deletions

.github/workflows/dissect-ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ jobs:
1515
with:
1616
run-benchmarks: true
1717

18-
1918
publish:
20-
if: ${{ github.ref_name == 'main' || github.ref_type == 'tag' }}
19+
if: ${{ github.ref_type == 'tag' }}
2120
needs: [ci]
2221
runs-on: ubuntu-latest
2322
environment: dissect_publish

dissect/cstruct/cstruct.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from dissect.cstruct.exceptions import ResolveError
1212
from dissect.cstruct.expression import Expression
13-
from dissect.cstruct.parser import CStyleParser, TokenParser
13+
from dissect.cstruct.parser import CStyleParser
1414
from dissect.cstruct.types import (
1515
LEB128,
1616
BaseArray,
@@ -56,7 +56,6 @@ def __init__(self, load: str = "", *, endian: str = "<", pointer: str | None = N
5656
self.endian = endian
5757

5858
self.consts = {}
59-
self.lookups = {}
6059
self.includes = []
6160
# fmt: off
6261
self.typedefs = {
@@ -212,7 +211,6 @@ def __copy__(self) -> cstruct:
212211
cs = cstruct(endian=self.endian, pointer=self.pointer.__name__)
213212
cs._anonymous_count = self._anonymous_count
214213
cs.consts = self.consts.copy()
215-
cs.lookups = self.lookups.copy()
216214
cs.includes = self.includes.copy()
217215

218216
# Update typedefs to point to the new cstruct instance
@@ -274,11 +272,7 @@ def load(self, definition: str, deftype: int | None = None, **kwargs) -> cstruct
274272
Definitions can be parsed using different parsers. Currently, there's
275273
only one supported parser - DEF_CSTYLE. Parsers can add types and
276274
modify this cstruct instance. Arguments can be passed to parsers
277-
using kwargs.
278-
279-
The CSTYLE parser was recently replaced with token based parser,
280-
instead of a strictly regex based one. The old parser is still available
281-
by using DEF_LEGACY.
275+
using ``kwargs``.
282276
283277
Args:
284278
definition: The definition to parse.
@@ -288,9 +282,9 @@ def load(self, definition: str, deftype: int | None = None, **kwargs) -> cstruct
288282
deftype = deftype or cstruct.DEF_CSTYLE
289283

290284
if deftype == cstruct.DEF_CSTYLE:
291-
TokenParser(self, **kwargs).parse(definition)
292-
elif deftype == cstruct.DEF_LEGACY:
293285
CStyleParser(self, **kwargs).parse(definition)
286+
else:
287+
raise ValueError(f"Unknown definition type: {deftype}")
294288

295289
return self
296290

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)