-
Notifications
You must be signed in to change notification settings - Fork 0
/
cstruct.pegjs
53 lines (39 loc) · 881 Bytes
/
cstruct.pegjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
struct
= _ 'struct'_ cident* _ '{' _
d:(declareStmt/macroExp)*
_'}'_ cident? _ ';'?{return d}
declareStmt
= _ (modifier/signtype _)* _ lentype:(lentype/typeExp)? _ ptr:ptrExp? _ name:nameExp _ len:arrayExp? _ ('=' _ value _)? ';' _
{return {'type':ptr?"*":lentype, 'name':name ,'len':len}}
ptrExp
= ("*" _)+
typeExp
= type:(cident _ )
{return type[0]}
arrayExp
= '[' _ value:digest _ ']'
{return value}
/ '[' _ value:hex _ ']'
{return value}
nameExp
= cident
value
= [^;]+
macroExp
= '#' [^\n]* ('\n')
{return null}
signtype
= "unsigned" / "signed"
modifier
= "violate" / "const" / "static"
lentype
= "long long int" / "long long" / "long int" / "short int" / "long" /"short"
_ "whitespace"
= $[ \t\n\r]*
cident
= $[A-Za-z0-9_]+
//{return cident.join("")}
digest
= $[0-9]+
hex
= $('0x'[0-9a-fA-F]+)