summaryrefslogtreecommitdiff
path: root/prism/templates/src/token_type.c.erb
blob: 1aeecd72b24acbb8f6f5785fd806631e6a70a9ed (plain)
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#include <string.h>

#include "prism/ast.h"

/**
 * Returns a string representation of the given token type.
 */
PRISM_EXPORTED_FUNCTION const char *
pm_token_type_name(pm_token_type_t token_type) {
    switch (token_type) {
<%- tokens.each do |token| -%>
        case PM_TOKEN_<%= token.name %>:
            return "<%= token.name %>";
<%- end -%>
        case PM_TOKEN_MAXIMUM:
            assert(false && "unreachable");
            return "";
    }

    // Provide a default, because some compilers can't determine that the above
    // switch is exhaustive.
    assert(false && "unreachable");
    return "";
}

/**
 * Returns the human name of the given token type.
 */
const char *
pm_token_type_human(pm_token_type_t token_type) {
    switch (token_type) {
        case PM_TOKEN_EOF:
            return "end of file";
        case PM_TOKEN_MISSING:
            return "missing token";
        case PM_TOKEN_NOT_PROVIDED:
            return "not provided token";
        case PM_TOKEN_AMPERSAND:
            return "'&'";
        case PM_TOKEN_AMPERSAND_AMPERSAND:
            return "'&&'";
        case PM_TOKEN_AMPERSAND_AMPERSAND_EQUAL:
            return "'&&='";
        case PM_TOKEN_AMPERSAND_DOT:
            return "'&.'";
        case PM_TOKEN_AMPERSAND_EQUAL:
            return "'&='";
        case PM_TOKEN_BACKTICK:
            return "'`'";
        case PM_TOKEN_BACK_REFERENCE:
            return "back reference";
        case PM_TOKEN_BANG:
            return "'!'";
        case PM_TOKEN_BANG_EQUAL:
            return "'!='";
        case PM_TOKEN_BANG_TILDE:
            return "'!~'";
        case PM_TOKEN_BRACE_LEFT:
            return "'{'";
        case PM_TOKEN_BRACE_RIGHT:
            return "'}'";
        case PM_TOKEN_BRACKET_LEFT:
            return "'['";
        case PM_TOKEN_BRACKET_LEFT_ARRAY:
            return "'['";
        case PM_TOKEN_BRACKET_LEFT_RIGHT:
            return "'[]'";
        case PM_TOKEN_BRACKET_LEFT_RIGHT_EQUAL:
            return "'[]='";
        case PM_TOKEN_BRACKET_RIGHT:
            return "']'";
        case PM_TOKEN_CARET:
            return "'^'";
        case PM_TOKEN_CARET_EQUAL:
            return "'^='";
        case PM_TOKEN_CHARACTER_LITERAL:
            return "character literal";
        case PM_TOKEN_CLASS_VARIABLE:
            return "class variable";
        case PM_TOKEN_COLON:
            return "':'";
        case PM_TOKEN_COLON_COLON:
            return "'::'";
        case PM_TOKEN_COMMA:
            return "','";
        case PM_TOKEN_COMMENT:
            return "comment";
        case PM_TOKEN_CONSTANT:
            return "constant";
        case PM_TOKEN_DOT:
            return "'.'";
        case PM_TOKEN_DOT_DOT:
            return "'..'";
        case PM_TOKEN_DOT_DOT_DOT:
            return "'...'";
        case PM_TOKEN_EMBDOC_BEGIN:
            return "'=begin'";
        case PM_TOKEN_EMBDOC_END:
            return "'=end'";
        case PM_TOKEN_EMBDOC_LINE:
            return "embedded documentation line";
        case PM_TOKEN_EMBEXPR_BEGIN:
            return "'#{'";
        case PM_TOKEN_EMBEXPR_END:
            return "'}'";
        case PM_TOKEN_EMBVAR:
            return "'#'";
        case PM_TOKEN_EQUAL:
            return "'='";
        case PM_TOKEN_EQUAL_EQUAL:
            return "'=='";
        case PM_TOKEN_EQUAL_EQUAL_EQUAL:
            return "'==='";
        case PM_TOKEN_EQUAL_GREATER:
            return "'=>'";
        case PM_TOKEN_EQUAL_TILDE:
            return "'=~'";
        case PM_TOKEN_FLOAT:
            return "float";
        case PM_TOKEN_FLOAT_IMAGINARY:
            return "imaginary";
        case PM_TOKEN_FLOAT_RATIONAL:
            return "rational";
        case PM_TOKEN_FLOAT_RATIONAL_IMAGINARY:
            return "imaginary";
        case PM_TOKEN_GLOBAL_VARIABLE:
            return "global variable";
        case PM_TOKEN_GREATER:
            return "'>'";
        case PM_TOKEN_GREATER_EQUAL:
            return "'>='";
        case PM_TOKEN_GREATER_GREATER:
            return "'>>'";
        case PM_TOKEN_GREATER_GREATER_EQUAL:
            return "'>>='";
        case PM_TOKEN_HEREDOC_END:
            return "heredoc ending";
        case PM_TOKEN_HEREDOC_START:
            return "heredoc beginning";
        case PM_TOKEN_IDENTIFIER:
            return "local variable or method";
        case PM_TOKEN_IGNORED_NEWLINE:
            return "ignored newline";
        case PM_TOKEN_INSTANCE_VARIABLE:
            return "instance variable";
        case PM_TOKEN_INTEGER:
            return "integer";
        case PM_TOKEN_INTEGER_IMAGINARY:
            return "imaginary";
        case PM_TOKEN_INTEGER_RATIONAL:
            return "rational";
        case PM_TOKEN_INTEGER_RATIONAL_IMAGINARY:
            return "imaginary";
        case PM_TOKEN_KEYWORD_ALIAS:
            return "'alias'";
        case PM_TOKEN_KEYWORD_AND:
            return "'and'";
        case PM_TOKEN_KEYWORD_BEGIN:
            return "'begin'";
        case PM_TOKEN_KEYWORD_BEGIN_UPCASE:
            return "'BEGIN'";
        case PM_TOKEN_KEYWORD_BREAK:
            return "'break'";
        case PM_TOKEN_KEYWORD_CASE:
            return "'case'";
        case PM_TOKEN_KEYWORD_CLASS:
            return "'class'";
        case PM_TOKEN_KEYWORD_DEF:
            return "'def'";
        case PM_TOKEN_KEYWORD_DEFINED:
            return "'defined?'";
        case PM_TOKEN_KEYWORD_DO:
            return "'do'";
        case PM_TOKEN_KEYWORD_DO_LOOP:
            return "'do'";
        case PM_TOKEN_KEYWORD_ELSE:
            return "'else'";
        case PM_TOKEN_KEYWORD_ELSIF:
            return "'elsif'";
        case PM_TOKEN_KEYWORD_END:
            return "'end'";
        case PM_TOKEN_KEYWORD_END_UPCASE:
            return "'END'";
        case PM_TOKEN_KEYWORD_ENSURE:
            return "'ensure'";
        case PM_TOKEN_KEYWORD_FALSE:
            return "'false'";
        case PM_TOKEN_KEYWORD_FOR:
            return "'for'";
        case PM_TOKEN_KEYWORD_IF:
            return "'if'";
        case PM_TOKEN_KEYWORD_IF_MODIFIER:
            return "'if'";
        case PM_TOKEN_KEYWORD_IN:
            return "'in'";
        case PM_TOKEN_KEYWORD_MODULE:
            return "'module'";
        case PM_TOKEN_KEYWORD_NEXT:
            return "'next'";
        case PM_TOKEN_KEYWORD_NIL:
            return "'nil'";
        case PM_TOKEN_KEYWORD_NOT:
            return "'not'";
        case PM_TOKEN_KEYWORD_OR:
            return "'or'";
        case PM_TOKEN_KEYWORD_REDO:
            return "'redo'";
        case PM_TOKEN_KEYWORD_RESCUE:
            return "'rescue'";
        case PM_TOKEN_KEYWORD_RESCUE_MODIFIER:
            return "'rescue' modifier";
        case PM_TOKEN_KEYWORD_RETRY:
            return "'retry'";
        case PM_TOKEN_KEYWORD_RETURN:
            return "'return'";
        case PM_TOKEN_KEYWORD_SELF:
            return "'self'";
        case PM_TOKEN_KEYWORD_SUPER:
            return "'super'";
        case PM_TOKEN_KEYWORD_THEN:
            return "'then'";
        case PM_TOKEN_KEYWORD_TRUE:
            return "'true'";
        case PM_TOKEN_KEYWORD_UNDEF:
            return "'undef'";
        case PM_TOKEN_KEYWORD_UNLESS:
            return "'unless'";
        case PM_TOKEN_KEYWORD_UNLESS_MODIFIER:
            return "'unless'";
        case PM_TOKEN_KEYWORD_UNTIL:
            return "'until'";
        case PM_TOKEN_KEYWORD_UNTIL_MODIFIER:
            return "'until'";
        case PM_TOKEN_KEYWORD_WHEN:
            return "'when'";
        case PM_TOKEN_KEYWORD_WHILE:
            return "'while'";
        case PM_TOKEN_KEYWORD_WHILE_MODIFIER:
            return "'while'";
        case PM_TOKEN_KEYWORD_YIELD:
            return "'yield'";
        case PM_TOKEN_KEYWORD___ENCODING__:
            return "'__ENCODING__'";
        case PM_TOKEN_KEYWORD___FILE__:
            return "'__FILE__'";
        case PM_TOKEN_KEYWORD___LINE__:
            return "'__LINE__'";
        case PM_TOKEN_LABEL:
            return "label";
        case PM_TOKEN_LABEL_END:
            return "label terminator";
        case PM_TOKEN_LAMBDA_BEGIN:
            return "'{'";
        case PM_TOKEN_LESS:
            return "'<'";
        case PM_TOKEN_LESS_EQUAL:
            return "'<='";
        case PM_TOKEN_LESS_EQUAL_GREATER:
            return "'<=>'";
        case PM_TOKEN_LESS_LESS:
            return "'<<'";
        case PM_TOKEN_LESS_LESS_EQUAL:
            return "'<<='";
        case PM_TOKEN_METHOD_NAME:
            return "method name";
        case PM_TOKEN_MINUS:
            return "'-'";
        case PM_TOKEN_MINUS_EQUAL:
            return "'-='";
        case PM_TOKEN_MINUS_GREATER:
            return "'->'";
        case PM_TOKEN_NEWLINE:
            return "newline";
        case PM_TOKEN_NUMBERED_REFERENCE:
            return "numbered reference";
        case PM_TOKEN_PARENTHESIS_LEFT:
            return "'('";
        case PM_TOKEN_PARENTHESIS_LEFT_PARENTHESES:
            return "'('";
        case PM_TOKEN_PARENTHESIS_RIGHT:
            return "')'";
        case PM_TOKEN_PERCENT:
            return "'%'";
        case PM_TOKEN_PERCENT_EQUAL:
            return "'%='";
        case PM_TOKEN_PERCENT_LOWER_I:
            return "'%i'";
        case PM_TOKEN_PERCENT_LOWER_W:
            return "'%w'";
        case PM_TOKEN_PERCENT_LOWER_X:
            return "'%x'";
        case PM_TOKEN_PERCENT_UPPER_I:
            return "'%I'";
        case PM_TOKEN_PERCENT_UPPER_W:
            return "'%W'";
        case PM_TOKEN_PIPE:
            return "'|'";
        case PM_TOKEN_PIPE_EQUAL:
            return "'|='";
        case PM_TOKEN_PIPE_PIPE:
            return "'||'";
        case PM_TOKEN_PIPE_PIPE_EQUAL:
            return "'||='";
        case PM_TOKEN_PLUS:
            return "'+'";
        case PM_TOKEN_PLUS_EQUAL:
            return "'+='";
        case PM_TOKEN_QUESTION_MARK:
            return "'?'";
        case PM_TOKEN_REGEXP_BEGIN:
            return "regular expression beginning";
        case PM_TOKEN_REGEXP_END:
            return "regular expression ending";
        case PM_TOKEN_SEMICOLON:
            return "';'";
        case PM_TOKEN_SLASH:
            return "'/'";
        case PM_TOKEN_SLASH_EQUAL:
            return "'/='";
        case PM_TOKEN_STAR:
            return "'*'";
        case PM_TOKEN_STAR_EQUAL:
            return "'*='";
        case PM_TOKEN_STAR_STAR:
            return "'**'";
        case PM_TOKEN_STAR_STAR_EQUAL:
            return "'**='";
        case PM_TOKEN_STRING_BEGIN:
            return "string literal";
        case PM_TOKEN_STRING_CONTENT:
            return "string content";
        case PM_TOKEN_STRING_END:
            return "string ending";
        case PM_TOKEN_SYMBOL_BEGIN:
            return "symbol literal";
        case PM_TOKEN_TILDE:
            return "'~'";
        case PM_TOKEN_UAMPERSAND:
            return "'&'";
        case PM_TOKEN_UCOLON_COLON:
            return "'::'";
        case PM_TOKEN_UDOT_DOT:
            return "'..'";
        case PM_TOKEN_UDOT_DOT_DOT:
            return "'...'";
        case PM_TOKEN_UMINUS:
            return "'-'";
        case PM_TOKEN_UMINUS_NUM:
            return "'-'";
        case PM_TOKEN_UPLUS:
            return "'+'";
        case PM_TOKEN_USTAR:
            return "*";
        case PM_TOKEN_USTAR_STAR:
            return "'**'";
        case PM_TOKEN_WORDS_SEP:
            return "string separator";
        case PM_TOKEN___END__:
            return "'__END__'";
        case PM_TOKEN_MAXIMUM:
            assert(false && "unreachable");
            return "";
    }

    // Provide a default, because some compilers can't determine that the above
    // switch is exhaustive.
    assert(false && "unreachable");
    return "";
}