Skip to content

Commit 566d131

Browse files
author
cabrol
committed
Make the comment parsing more generic, allowing more special chars
Signed-off-by: qcabrol
1 parent 06de786 commit 566d131

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

dissect/cstruct/cstruct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def _parse_fields(self, s):
417417
#parse the comment header
418418
if d['commentBlock'] is not None and d['commentBlock'].startswith('/*'):
419419
commentfields = re.finditer(
420-
r'@(?P<commentType>[a-zA-Z0-9_\-\/,.\°\%]+):[ \t]*(?P<commentVal>[a-zA-Z0-9_\-,.\°\%]+)',
420+
r'@(?P<commentType>[^@,;:\\]+):[ \t]*(?P<commentVal>[^@,;:\s\\]+)',
421421
d['commentBlock'],
422422
)
423423
for cf in commentfields:

tests/test_basic.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -779,13 +779,13 @@ def test_commentfieldparse(capsys):
779779
struct test{
780780
/*
781781
* @scale: 0.001
782-
* @unit: testUnit1
782+
* @unit: µtestUnit1
783783
*/
784784
int testVar1;
785785
int testVar2;
786786
/* dicardedCom2
787787
* @scale: 5
788-
* @unit: testUnit2
788+
* @unit: %testUnit2
789789
*/
790790
int testVar3;
791791
};
@@ -798,9 +798,9 @@ def test_commentfieldparse(capsys):
798798
assert 'testVar2' in c.test.lookup
799799

800800
assert c.test.lookup['testVar1'].commentAttributes['scale'] == '0.001'
801-
assert c.test.lookup['testVar1'].commentAttributes['unit'] == 'testUnit1'
801+
assert c.test.lookup['testVar1'].commentAttributes['unit'] == 'µtestUnit1'
802802

803803
assert c.test.lookup['testVar2'].commentAttributes == {}
804804

805805
assert c.test.lookup['testVar3'].commentAttributes['scale'] == '5'
806-
assert c.test.lookup['testVar3'].commentAttributes['unit'] == 'testUnit2'
806+
assert c.test.lookup['testVar3'].commentAttributes['unit'] == '%testUnit2'

0 commit comments

Comments
 (0)