Rewrite lexer and parser#146
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #146 +/- ##
======================================
Coverage 0.00% 0.00%
======================================
Files 21 22 +1
Lines 2500 2611 +111
======================================
- Misses 2500 2611 +111
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | test_benchmark_expression_evaluate |
78.6 µs | 127.7 µs | -38.44% |
| ⚡ | test_benchmark_expression_parse |
343.8 µs | 264.2 µs | +30.13% |
| ⚡ | test_benchmark_lexer_and_parser |
15.7 ms | 13 ms | +21.29% |
| ⚡ | test_benchmark_expression_parse_and_evaluate |
389.5 µs | 353.2 µs | +10.26% |
| 🆕 | test_benchmark_parser |
N/A | 10.6 ms | N/A |
| 🆕 | test_benchmark_lexer |
N/A | 2.4 ms | N/A |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing rewrite-parser (c58b76f) with main (91f2347)
|
@sMezaOrellana would be interested in your thoughts on these changes! |
5f43faa to
16e6b8b
Compare
twiggler
left a comment
There was a problem hiding this comment.
Architecure looks ok, found 2 possible issues TBC
Migrated-from: fox-it/dissect.cstruct#146
Migrated-from: fox-it/dissect.cstruct#146
|
This PR has been migrated to the dissect monorepo: twiggler/dissect-monorepo-test#5 The original diff and commit history have been preserved on the |
|
@twiggler I was a bit sad that your message was just this test, as I thought maybe you left more comments 😉. |
Migrated-from: fox-it/dissect.cstruct#146
Migrated-from: fox-it/dissect.cstruct#146
Migrated-from: fox-it/dissect.cstruct#146
Migrated-from: fox-it/dissect.cstruct#146
twiggler
left a comment
There was a problem hiding this comment.
LGTM
Since it is an impactful rewrite I asked @Miauwkeru to QA
|
I did some checking on our other projects to see what goes wrong, and found some regressions regarding to where it crashed unexpectedly.
#define func(x) ( x ? 1 : 0 )Without a ternary it makes it into a string: # define func(x) ( x == 0)
>>> c_struct.func
' ( x ) ( x = = 0)`
flag INODE {
...
};
#define APFS_INODE_PINNED_MASK INODE.PINNED_TO_MAIN | INODE.PINNED_TO_TIER2I'll look through the code now to see whether I can find some additional issues. |
|
@Miauwkeru fixed. |
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Miauwkeru
left a comment
There was a problem hiding this comment.
LGTM, want to release it as 5.0? Then we don't have to update every project immediately.
Otherwise we might need to already have the patch sets ready before it gets merged in.
We can yank/delete the There is also the option to update the publish step to only work when you tag it or disable publishing it in its entirety |
|
Temporarily disabling the publish step is probably the easiest. |
|
@Miauwkeru I had to fix the merge with #140 to work with the removal of lookups so I require a new ack 😄. |
Closes #85, partially #142, and will make #86 and #138 a lot easier to implement. Fixes #149.
This PR will (finally) replace the shoddy C syntax parser I originally wrote many moons ago, when I discovered the existence of
re.Scannerand ran with it. This PR aims to add a somewhat decent lexer and separate parser. I'm still not a compsci 1337coder, so this is just what I came up with (with some help) and definitely not a textbook implementation. All feedback is welcome.sizeofworks in the expression parser, and addedoffsetofThe new parser has made changing parsing behavior a lot easier. As such, this PR already makes the following changes:
The new parser is slightly stricter, requiring proper semicolon endings for example. We'll need to fix this in any dissect code that has this.
An important semantic change is how named nested structures are handled. In my infinite wisdom, I originally figured that named nested structures do not "exist" in the top level scope. That's not true, so now named nested structures get properly registered with the cstruct instance:
struct { ... } name;. We used to parse this first as an anonymous struct, then capturenameas the structure type name. That's not strictly correct,nameis a variable of an anonymous unnamed struct, so we now treat it as such. We don't error on this, but rather we silently ignorenameand skip until we reach a;typedef enum ...is now allowedThis probably warrants a major version bump, so maybe good to pair this with #114, #144 and what we discussed in #142.