Ruby  2.5.0dev(2017-10-22revision60238)
eventids2.c
Go to the documentation of this file.
1 #define tIGNORED_NL (tLAST_TOKEN + 1)
2 #define tCOMMENT (tLAST_TOKEN + 2)
3 #define tEMBDOC_BEG (tLAST_TOKEN + 3)
4 #define tEMBDOC (tLAST_TOKEN + 4)
5 #define tEMBDOC_END (tLAST_TOKEN + 5)
6 #define tSP (tLAST_TOKEN + 6)
7 #define tHEREDOC_BEG (tLAST_TOKEN + 7)
8 #define tHEREDOC_END (tLAST_TOKEN + 8)
9 #define k__END__ (tLAST_TOKEN + 9)
10 
11 typedef struct {
53 
65 
66 static ripper_scanner_ids_t ripper_scanner_ids;
67 
68 #include "eventids2table.c"
69 
70 static void
71 ripper_init_eventids2(void)
72 {
73 #define set_id2(name) ripper_scanner_ids.ripper_id_##name = rb_intern_const("on_"#name)
74  set_id2(backref);
75  set_id2(backtick);
76  set_id2(comma);
77  set_id2(const);
78  set_id2(cvar);
79  set_id2(embexpr_beg);
80  set_id2(embexpr_end);
81  set_id2(embvar);
82  set_id2(float);
83  set_id2(gvar);
84  set_id2(ident);
85  set_id2(imaginary);
86  set_id2(int);
87  set_id2(ivar);
88  set_id2(kw);
89  set_id2(lbrace);
90  set_id2(lbracket);
91  set_id2(lparen);
92  set_id2(nl);
93  set_id2(op);
94  set_id2(period);
95  set_id2(rbrace);
96  set_id2(rbracket);
97  set_id2(rparen);
98  set_id2(semicolon);
99  set_id2(symbeg);
100  set_id2(tstring_beg);
101  set_id2(tstring_content);
102  set_id2(tstring_end);
103  set_id2(words_beg);
104  set_id2(qwords_beg);
105  set_id2(qsymbols_beg);
106  set_id2(symbols_beg);
107  set_id2(words_sep);
108  set_id2(rational);
109  set_id2(regexp_beg);
110  set_id2(regexp_end);
111  set_id2(label);
112  set_id2(label_end);
113  set_id2(tlambda);
114  set_id2(tlambeg);
115 
116  set_id2(ignored_nl);
117  set_id2(comment);
118  set_id2(embdoc_beg);
119  set_id2(embdoc);
120  set_id2(embdoc_end);
121  set_id2(sp);
122  set_id2(heredoc_beg);
124  set_id2(__end__);
125  set_id2(CHAR);
126 }
127 
128 STATIC_ASSERT(k__END___range, k__END__ < SHRT_MAX);
129 STATIC_ASSERT(ripper_scanner_ids_size, sizeof(ripper_scanner_ids) < SHRT_MAX);
130 #define O(member) (int)offsetof(ripper_scanner_ids_t, ripper_id_##member)
131 
132 static const struct token_assoc {
133  unsigned short token;
134  unsigned short id_offset;
135 } token_to_eventid[] = {
136  {' ', O(words_sep)},
137  {'!', O(op)},
138  {'%', O(op)},
139  {'&', O(op)},
140  {'*', O(op)},
141  {'+', O(op)},
142  {'-', O(op)},
143  {'/', O(op)},
144  {'<', O(op)},
145  {'=', O(op)},
146  {'>', O(op)},
147  {'?', O(op)},
148  {'^', O(op)},
149  {'|', O(op)},
150  {'~', O(op)},
151  {':', O(op)},
152  {',', O(comma)},
153  {'.', O(period)},
154  {';', O(semicolon)},
155  {'`', O(backtick)},
156  {'\n', O(nl)},
157  {keyword_alias, O(kw)},
158  {keyword_and, O(kw)},
159  {keyword_begin, O(kw)},
160  {keyword_break, O(kw)},
161  {keyword_case, O(kw)},
162  {keyword_class, O(kw)},
163  {keyword_def, O(kw)},
164  {keyword_defined, O(kw)},
165  {keyword_do, O(kw)},
166  {keyword_do_block, O(kw)},
167  {keyword_do_cond, O(kw)},
168  {keyword_else, O(kw)},
169  {keyword_elsif, O(kw)},
170  {keyword_end, O(kw)},
171  {keyword_ensure, O(kw)},
172  {keyword_false, O(kw)},
173  {keyword_for, O(kw)},
174  {keyword_if, O(kw)},
175  {modifier_if, O(kw)},
176  {keyword_in, O(kw)},
177  {keyword_module, O(kw)},
178  {keyword_next, O(kw)},
179  {keyword_nil, O(kw)},
180  {keyword_not, O(kw)},
181  {keyword_or, O(kw)},
182  {keyword_redo, O(kw)},
183  {keyword_rescue, O(kw)},
184  {modifier_rescue, O(kw)},
185  {keyword_retry, O(kw)},
186  {keyword_return, O(kw)},
187  {keyword_self, O(kw)},
188  {keyword_super, O(kw)},
189  {keyword_then, O(kw)},
190  {keyword_true, O(kw)},
191  {keyword_undef, O(kw)},
192  {keyword_unless, O(kw)},
193  {modifier_unless, O(kw)},
194  {keyword_until, O(kw)},
195  {modifier_until, O(kw)},
196  {keyword_when, O(kw)},
197  {keyword_while, O(kw)},
198  {modifier_while, O(kw)},
199  {keyword_yield, O(kw)},
200  {keyword__FILE__, O(kw)},
201  {keyword__LINE__, O(kw)},
202  {keyword__ENCODING__, O(kw)},
203  {keyword_BEGIN, O(kw)},
204  {keyword_END, O(kw)},
205  {keyword_do_LAMBDA, O(kw)},
206  {tAMPER, O(op)},
207  {tANDOP, O(op)},
208  {tAREF, O(op)},
209  {tASET, O(op)},
210  {tASSOC, O(op)},
211  {tBACK_REF, O(backref)},
212  {tCHAR, O(CHAR)},
213  {tCMP, O(op)},
214  {tCOLON2, O(op)},
215  {tCOLON3, O(op)},
216  {tCONSTANT, O(const)},
217  {tCVAR, O(cvar)},
218  {tDOT2, O(op)},
219  {tDOT3, O(op)},
220  {tEQ, O(op)},
221  {tEQQ, O(op)},
222  {tFID, O(ident)},
223  {tFLOAT, O(float)},
224  {tGEQ, O(op)},
225  {tGVAR, O(gvar)},
226  {tIDENTIFIER, O(ident)},
227  {tIMAGINARY, O(imaginary)},
228  {tINTEGER, O(int)},
229  {tIVAR, O(ivar)},
230  {tLBRACE, O(lbrace)},
231  {tLBRACE_ARG, O(lbrace)},
232  {'{', O(lbrace)},
233  {'}', O(rbrace)},
234  {tLBRACK, O(lbracket)},
235  {'[', O(lbracket)},
236  {']', O(rbracket)},
237  {tLEQ, O(op)},
238  {tLPAREN, O(lparen)},
239  {tLPAREN_ARG, O(lparen)},
240  {'(', O(lparen)},
241  {')', O(rparen)},
242  {tLSHFT, O(op)},
243  {tMATCH, O(op)},
244  {tNEQ, O(op)},
245  {tNMATCH, O(op)},
246  {tNTH_REF, O(backref)},
247  {tOP_ASGN, O(op)},
248  {tOROP, O(op)},
249  {tPOW, O(op)},
250  {tQWORDS_BEG, O(qwords_beg)},
251  {tQSYMBOLS_BEG, O(qsymbols_beg)},
252  {tSYMBOLS_BEG, O(symbols_beg)},
253  {tRATIONAL, O(rational)},
254  {tREGEXP_BEG, O(regexp_beg)},
255  {tREGEXP_END, O(regexp_end)},
256  {tRPAREN, O(rparen)},
257  {tRSHFT, O(op)},
258  {tSTAR, O(op)},
259  {tDSTAR, O(op)},
260  {tANDDOT, O(op)},
261  {tSTRING_BEG, O(tstring_beg)},
262  {tSTRING_CONTENT, O(tstring_content)},
263  {tSTRING_DBEG, O(embexpr_beg)},
264  {tSTRING_DEND, O(embexpr_end)},
265  {tSTRING_DVAR, O(embvar)},
266  {tSTRING_END, O(tstring_end)},
267  {tSYMBEG, O(symbeg)},
268  {tUMINUS, O(op)},
269  {tUMINUS_NUM, O(op)},
270  {tUPLUS, O(op)},
271  {tWORDS_BEG, O(words_beg)},
272  {tXSTRING_BEG, O(backtick)},
273  {tLABEL, O(label)},
274  {tLABEL_END, O(label_end)},
275  {tLAMBDA, O(tlambda)},
276  {tLAMBEG, O(tlambeg)},
277 
278  /* ripper specific tokens */
279  {tIGNORED_NL, O(ignored_nl)},
280  {tCOMMENT, O(comment)},
281  {tEMBDOC_BEG, O(embdoc_beg)},
282  {tEMBDOC, O(embdoc)},
283  {tEMBDOC_END, O(embdoc_end)},
284  {tSP, O(sp)},
285  {tHEREDOC_BEG, O(heredoc_beg)},
287  {k__END__, O(__end__)},
288 };
289 
290 static ID
291 ripper_token2eventid(int tok)
292 {
293  int i;
294 
295  for (i = 0; i < numberof(token_to_eventid); i++) {
296  const struct token_assoc *const a = &token_to_eventid[i];
297  if (a->token == tok)
298  return *(const ID *)((const char *)&ripper_scanner_ids + a->id_offset);
299  }
300  if (tok < 256) {
301  return ripper_scanner_ids.ripper_id_CHAR;
302  }
303  rb_raise(rb_eRuntimeError, "[Ripper FATAL] unknown token %d", tok);
304 
305  UNREACHABLE;
306 }
#define keyword_when
Definition: ripper.c:204
#define tLBRACE
Definition: ripper.c:283
#define modifier_if
Definition: ripper.c:227
#define tHEREDOC_BEG
Definition: eventids2.c:7
#define keyword_unless
Definition: ripper.c:199
#define keyword_do_LAMBDA
Definition: ripper.c:216
#define tEMBDOC_BEG
Definition: eventids2.c:3
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2284
#define keyword_yield
Definition: ripper.c:218
#define tEQ
Definition: ripper.c:259
#define keyword__ENCODING__
Definition: ripper.c:238
#define tRPAREN
Definition: ripper.c:281
#define keyword_return
Definition: ripper.c:217
#define tAMPER
Definition: ripper.c:287
#define UNREACHABLE
Definition: ruby.h:46
#define keyword_do_block
Definition: ripper.c:215
#define tEQQ
Definition: ripper.c:260
#define tok()
Definition: ripper.c:11734
#define tSYMBOLS_BEG
Definition: ripper.c:295
#define keyword__FILE__
Definition: ripper.c:237
#define tASSOC
Definition: ripper.c:278
#define tSTRING_DVAR
Definition: ripper.c:299
#define keyword_nil
Definition: ripper.c:221
unsigned short token
Definition: id.c:36
#define keyword_END
Definition: ripper.c:235
#define keyword_class
Definition: ripper.c:190
#define keyword_next
Definition: ripper.c:209
#define tLPAREN_ARG
Definition: ripper.c:280
#define tMATCH
Definition: ripper.c:266
#define tLAMBEG
Definition: ripper.c:301
#define tSTRING_CONTENT
Definition: ripper.c:250
#define tBACK_REF
Definition: ripper.c:253
#define keyword_begin
Definition: ripper.c:194
#define modifier_rescue
Definition: ripper.c:231
#define keyword_not
Definition: ripper.c:226
#define tCMP
Definition: ripper.c:258
#define tLBRACK
Definition: ripper.c:282
#define tGEQ
Definition: ripper.c:262
#define tANDDOT
Definition: ripper.c:274
#define tRSHFT
Definition: ripper.c:273
#define tNMATCH
Definition: ripper.c:267
#define tDOT2
Definition: ripper.c:268
#define tSTAR
Definition: ripper.c:285
#define keyword_def
Definition: ripper.c:192
#define tCHAR
Definition: ripper.c:251
STATIC_ASSERT(k__END___range, k__END__< SHRT_MAX)
#define tFLOAT
Definition: ripper.c:247
#define tCVAR
Definition: ripper.c:244
#define keyword_rescue
Definition: ripper.c:195
#define keyword_end
Definition: ripper.c:197
#define keyword_super
Definition: ripper.c:219
#define O(member)
Definition: eventids2.c:130
#define keyword_if
Definition: ripper.c:198
#define tLEQ
Definition: ripper.c:263
#define tSYMBEG
Definition: ripper.c:289
#define k__END__
Definition: eventids2.c:9
#define keyword_defined
Definition: ripper.c:233
#define tSTRING_DBEG
Definition: ripper.c:297
#define keyword_undef
Definition: ripper.c:193
#define tCONSTANT
Definition: ripper.c:243
#define tXSTRING_BEG
Definition: ripper.c:291
#define tSTRING_DEND
Definition: ripper.c:298
#define numberof(array)
Definition: etc.c:618
#define tREGEXP_BEG
Definition: ripper.c:292
#define keyword_self
Definition: ripper.c:220
#define tHEREDOC_END
Definition: eventids2.c:8
#define tCOLON3
Definition: ripper.c:276
#define tWORDS_BEG
Definition: ripper.c:293
#define modifier_until
Definition: ripper.c:230
#define tOP_ASGN
Definition: ripper.c:277
#define set_id2(name)
#define keyword_false
Definition: ripper.c:223
#define keyword_or
Definition: ripper.c:225
unsigned long ID
Definition: ruby.h:86
#define keyword_until
Definition: ripper.c:206
#define tPOW
Definition: ripper.c:257
#define tANDOP
Definition: ripper.c:264
#define tLABEL_END
Definition: ripper.c:302
#define modifier_while
Definition: ripper.c:229
#define tQSYMBOLS_BEG
Definition: ripper.c:296
#define tOROP
Definition: ripper.c:265
#define tIVAR
Definition: ripper.c:242
#define tFID
Definition: ripper.c:240
#define keyword_in
Definition: ripper.c:212
#define tNTH_REF
Definition: ripper.c:252
#define tIDENTIFIER
Definition: ripper.c:239
#define keyword_then
Definition: ripper.c:200
#define keyword_break
Definition: ripper.c:208
#define tIMAGINARY
Definition: ripper.c:249
#define keyword_do_cond
Definition: ripper.c:214
#define tLBRACE_ARG
Definition: ripper.c:284
#define tAREF
Definition: ripper.c:270
VALUE rb_eRuntimeError
Definition: error.c:800
#define tSP
Definition: eventids2.c:6
#define tGVAR
Definition: ripper.c:241
#define tDOT3
Definition: ripper.c:269
#define tLABEL
Definition: ripper.c:245
#define keyword_while
Definition: ripper.c:205
#define tSTRING_END
Definition: ripper.c:300
#define keyword_BEGIN
Definition: ripper.c:234
#define keyword_for
Definition: ripper.c:207
#define tEMBDOC
Definition: eventids2.c:4
#define keyword_do
Definition: ripper.c:213
#define keyword_true
Definition: ripper.c:222
#define tUPLUS
Definition: ripper.c:255
#define keyword_else
Definition: ripper.c:202
#define tASET
Definition: ripper.c:271
#define tNEQ
Definition: ripper.c:261
#define tLPAREN
Definition: ripper.c:279
#define keyword__LINE__
Definition: ripper.c:236
#define modifier_unless
Definition: ripper.c:228
#define keyword_module
Definition: ripper.c:191
#define keyword_and
Definition: ripper.c:224
#define keyword_retry
Definition: ripper.c:211
#define tCOLON2
Definition: ripper.c:275
#define tLSHFT
Definition: ripper.c:272
#define tUMINUS_NUM
Definition: ripper.c:304
#define tUMINUS
Definition: ripper.c:256
#define keyword_ensure
Definition: ripper.c:196
#define tCOMMENT
Definition: eventids2.c:2
#define tREGEXP_END
Definition: ripper.c:254
#define keyword_redo
Definition: ripper.c:210
#define tRATIONAL
Definition: ripper.c:248
#define tQWORDS_BEG
Definition: ripper.c:294
#define tIGNORED_NL
Definition: eventids2.c:1
#define keyword_alias
Definition: ripper.c:232
#define tINTEGER
Definition: ripper.c:246
#define tDSTAR
Definition: ripper.c:286
#define tSTRING_BEG
Definition: ripper.c:290
#define keyword_case
Definition: ripper.c:203
#define heredoc_end
Definition: ripper.c:594
#define tLAMBDA
Definition: ripper.c:288
#define keyword_elsif
Definition: ripper.c:201
#define tEMBDOC_END
Definition: eventids2.c:5