-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathType.g4
221 lines (186 loc) · 3.52 KB
/
Type.g4
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
grammar Type;
UNION: 'union';
ENUM: 'enum';
STRUCT: 'struct';
CLS: 'class';
LPAREN: '(';
RPAREN: ')';
LBRACKET: '[';
RBRACKET: ']';
ASTERISK: '*';
REF: '&';
COMMA: ',';
DOUBLECOLON: '::';
COLON: ':';
ANONYMOUS: 'anonymous';
LAMBDA: 'lambda';
AT: 'at';
CONST: 'const';
RESTRICT: 'restrict';
RESTRICT_: '__restrict';
VOLATILE: 'volatile';
REGISTER: 'register';
EXTERN: 'extern';
AUTO: 'auto';
UNALIGNED_: '__unaligned';
STATIC: 'static';
UNSIGNED: 'unsigned';
SIGNED: 'signed';
VARARG: '...';
LEFT_ANGLE: '<';
RIGHT_ANGLE:'>';
ATOMIC: '_Atomic';
NS_DELIMITER: '`';
NOEXCEPT_: 'noexcept';
LONG: 'long';
COMPLEX: '_Complex';
ATTRIBUTE: '__attribute__';
QUOTE: '"';
SPECIAL_SYMBOL
: '/'
| '-'
| '\\'
| '.'
| '_'
| '+'
;
WS
: [ \n\t\r]+ -> channel(HIDDEN)
;
fragment
IdentifierNondigit
: Nondigit
| UniversalCharacterName
;
fragment
Nondigit
: [a-zA-Z_-]
;
fragment
Digit
: [0-9]
;
fragment
UniversalCharacterName
: '\\u' HexQuad
| '\\U' HexQuad HexQuad
;
fragment
HexQuad
: HexadecimalDigit HexadecimalDigit HexadecimalDigit HexadecimalDigit
;
fragment
HexadecimalDigit
: [0-9a-fA-F]
;
Identifier
: IdentifierNondigit
( IdentifierNondigit
| Digit
)*
;
Size
: Digit+
;
kind_decoration
: UNION
| ENUM
| STRUCT
| CLS
;
modifier
: STATIC
| EXTERN
| AUTO
| REGISTER
;
complex_name
: LONG
| COMPLEX
| Identifier
;
qualifier
: CONST
| RESTRICT
| RESTRICT_
| VOLATILE
| UNALIGNED_
| ATOMIC
;
const_qualifier
: CONST
;
pre_qualifier
: qualifier
;
post_qualifier
: CONST
| RESTRICT_
;
type_qualifier
: UNSIGNED
| SIGNED
;
pointer_const
: ASTERISK+ const_qualifier
| ASTERISK+
| REF+ const_qualifier
| REF+
| const_qualifier
;
param_list
: LPAREN (type_name (COMMA type_name)*)? RPAREN
;
anonymous_location_specification
: LPAREN (ANONYMOUS | LAMBDA) kind_decoration? (AT .*?)? RPAREN
;
template_param
: type_name
| (.*?)
;
angled_expression
: LEFT_ANGLE RIGHT_ANGLE
| LEFT_ANGLE template_param (COMMA template_param)* RIGHT_ANGLE
;
complete_identifier
: NS_DELIMITER complete_identifier NS_DELIMITER DOUBLECOLON complete_identifier
| complete_identifier DOUBLECOLON complete_identifier
| kind_decoration? (complex_name+ angled_expression? | anonymous_location_specification)
;
pre_type
: modifier* (pre_qualifier *) kind_decoration? type_qualifier?
;
probably_quoted
: QUOTE
| (.*?)
;
attribute
: NOEXCEPT_
| ATTRIBUTE LPAREN LPAREN probably_quoted RPAREN RPAREN
;
post_type
: post_qualifier* pointer_const* post_qualifier* size_specification* attribute*
;
size_specification
: LBRACKET (Size? | complete_identifier) RBRACKET
;
template_type
: angled_expression
;
class_spec
: type_name DOUBLECOLON
;
pre_simple_type
: pre_type complete_identifier pointer_const* post_type
;
inner
: class_spec? pointer_const* Identifier? (template_type? | LPAREN inner RPAREN) post_type param_list? attribute*
;
type_name
: pre_simple_type (template_type? | param_list | Identifier? (LPAREN inner RPAREN)? param_list?) post_type
| ATOMIC LPAREN type_name RPAREN
| VARARG
;
entire_input
: type_name EOF
;