Read a define value untill the end of the line or when it encounters a comment - #170
Read a define value untill the end of the line or when it encounters a comment#170Miauwkeru wants to merge 2 commits into
Conversation
…a comment - Keeps track of the whitespece between the value and the comment - Will keep track of a single qouted character
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #170 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 22 22
Lines 2798 2881 +83
=====================================
- Misses 2798 2881 +83
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:
|
|
This was the first one that got through all the tests, I will think of a better solution for the quoted string as it will break if you add a single quote somewhere between double quotes |
|
I can replace it with dissect.cstruct/tests/test_parser.py Line 254 in 3032ad7 oterwise |
|
What about multiline defines with quotes at the end of each (or some) line? Note that I'm not sure how that'd work in C, just a thought. Worth a test. |
Do you mean something like this: #define HELP " \
#define NLD "it won't work without the backslash according to some tests with godbolt |
|
I mean something like this: |
it will error in that case in c: main.c:4:13: error: expected identifier or ‘(’ before string constant
4 | "zomg" \ // and here
| ^~~~~~
main.c:4:20: error: stray ‘\’ in program
4 | "zomg" \ // and here
| ^
main.c:3:19: error: stray ‘\’ in program
3 | #define foo "bar" \ // comment here
| ^
main.c:8:12: note: in expansion of macro ‘foo’
8 | printf(foo);and in cstruct it creates a lexer error for an unexpected |
|
This is valid C though: #define foo "bar" /* comment */ \
"zomg"Might be nice to at least put something like this in the unit test. |
I'll add it and see whether I can make that work :) |
|
In def test_preprocessor_define_substitute_define(cs: cstruct) -> None:
"""Test whether we can concatinate defines with other strings."""
c_def = """
#define DATA1 "world"
#define CONCAT "hello" \\
DATA1
"""
cs.load(c_def)
assert cs.consts["CONCAT"] == "helloworld" |
fixes #169