Ruby  1.9.3p551(2014-11-13revision48407)
parse.y
Go to the documentation of this file.
1 /**********************************************************************
2 
3  parse.y -
4 
5  $Author: usa $
6  created at: Fri May 28 18:02:42 JST 1993
7 
8  Copyright (C) 1993-2007 Yukihiro Matsumoto
9 
10 **********************************************************************/
11 
12 %{
13 
14 #define YYDEBUG 1
15 #define YYERROR_VERBOSE 1
16 #define YYSTACK_USE_ALLOCA 0
17 
18 #include "ruby/ruby.h"
19 #include "ruby/st.h"
20 #include "ruby/encoding.h"
21 #include "internal.h"
22 #include "node.h"
23 #include "parse.h"
24 #include "id.h"
25 #include "regenc.h"
26 #include <stdio.h>
27 #include <errno.h>
28 #include <ctype.h>
29 
30 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
31 
32 #define YYMALLOC(size) rb_parser_malloc(parser, (size))
33 #define YYREALLOC(ptr, size) rb_parser_realloc(parser, (ptr), (size))
34 #define YYCALLOC(nelem, size) rb_parser_calloc(parser, (nelem), (size))
35 #define YYFREE(ptr) rb_parser_free(parser, (ptr))
36 #define malloc YYMALLOC
37 #define realloc YYREALLOC
38 #define calloc YYCALLOC
39 #define free YYFREE
40 
41 #ifndef RIPPER
42 static ID register_symid(ID, const char *, long, rb_encoding *);
43 #define REGISTER_SYMID(id, name) register_symid((id), (name), strlen(name), enc)
44 #include "id.c"
45 #endif
46 
47 #define is_notop_id(id) ((id)>tLAST_TOKEN)
48 #define is_local_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL)
49 #define is_global_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_GLOBAL)
50 #define is_instance_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_INSTANCE)
51 #define is_attrset_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_ATTRSET)
52 #define is_const_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CONST)
53 #define is_class_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CLASS)
54 #define is_junk_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_JUNK)
55 
56 #define is_asgn_or_id(id) ((is_notop_id(id)) && \
57  (((id)&ID_SCOPE_MASK) == ID_GLOBAL || \
58  ((id)&ID_SCOPE_MASK) == ID_INSTANCE || \
59  ((id)&ID_SCOPE_MASK) == ID_CLASS))
60 
62  EXPR_BEG, /* ignore newline, +/- is a sign. */
63  EXPR_END, /* newline significant, +/- is an operator. */
64  EXPR_ENDARG, /* ditto, and unbound braces. */
65  EXPR_ENDFN, /* ditto, and unbound braces. */
66  EXPR_ARG, /* newline significant, +/- is an operator. */
67  EXPR_CMDARG, /* newline significant, +/- is an operator. */
68  EXPR_MID, /* newline significant, +/- is an operator. */
69  EXPR_FNAME, /* ignore newline, no reserved words. */
70  EXPR_DOT, /* right after `.' or `::', no reserved words. */
71  EXPR_CLASS, /* immediate after `class', no here document. */
72  EXPR_VALUE, /* alike EXPR_BEG but label is disallowed. */
74 };
75 
76 typedef VALUE stack_type;
77 
78 # define BITSTACK_PUSH(stack, n) ((stack) = ((stack)<<1)|((n)&1))
79 # define BITSTACK_POP(stack) ((stack) = (stack) >> 1)
80 # define BITSTACK_LEXPOP(stack) ((stack) = ((stack) >> 1) | ((stack) & 1))
81 # define BITSTACK_SET_P(stack) ((stack)&1)
82 
83 #define COND_PUSH(n) BITSTACK_PUSH(cond_stack, (n))
84 #define COND_POP() BITSTACK_POP(cond_stack)
85 #define COND_LEXPOP() BITSTACK_LEXPOP(cond_stack)
86 #define COND_P() BITSTACK_SET_P(cond_stack)
87 
88 #define CMDARG_PUSH(n) BITSTACK_PUSH(cmdarg_stack, (n))
89 #define CMDARG_POP() BITSTACK_POP(cmdarg_stack)
90 #define CMDARG_LEXPOP() BITSTACK_LEXPOP(cmdarg_stack)
91 #define CMDARG_P() BITSTACK_SET_P(cmdarg_stack)
92 
93 struct vtable {
94  ID *tbl;
95  int pos;
96  int capa;
97  struct vtable *prev;
98 };
99 
100 struct local_vars {
101  struct vtable *args;
102  struct vtable *vars;
103  struct vtable *used;
104  struct local_vars *prev;
105  stack_type cmdargs;
106 };
107 
108 #define DVARS_INHERIT ((void*)1)
109 #define DVARS_TOPSCOPE NULL
110 #define DVARS_SPECIAL_P(tbl) (!POINTER_P(tbl))
111 #define POINTER_P(val) ((VALUE)(val) & ~(VALUE)3)
112 
113 static int
114 vtable_size(const struct vtable *tbl)
115 {
116  if (POINTER_P(tbl)) {
117  return tbl->pos;
118  }
119  else {
120  return 0;
121  }
122 }
123 
124 #define VTBL_DEBUG 0
125 
126 static struct vtable *
128 {
129  struct vtable *tbl = ALLOC(struct vtable);
130  tbl->pos = 0;
131  tbl->capa = 8;
132  tbl->tbl = ALLOC_N(ID, tbl->capa);
133  tbl->prev = prev;
134  if (VTBL_DEBUG) printf("vtable_alloc: %p\n", (void *)tbl);
135  return tbl;
136 }
137 
138 static void
140 {
141  if (VTBL_DEBUG)printf("vtable_free: %p\n", (void *)tbl);
142  if (POINTER_P(tbl)) {
143  if (tbl->tbl) {
144  xfree(tbl->tbl);
145  }
146  xfree(tbl);
147  }
148 }
149 
150 static void
151 vtable_add(struct vtable *tbl, ID id)
152 {
153  if (!POINTER_P(tbl)) {
154  rb_bug("vtable_add: vtable is not allocated (%p)", (void *)tbl);
155  }
156  if (VTBL_DEBUG) printf("vtable_add: %p, %s\n", (void *)tbl, rb_id2name(id));
157 
158  if (tbl->pos == tbl->capa) {
159  tbl->capa = tbl->capa * 2;
160  REALLOC_N(tbl->tbl, ID, tbl->capa);
161  }
162  tbl->tbl[tbl->pos++] = id;
163 }
164 
165 static int
166 vtable_included(const struct vtable * tbl, ID id)
167 {
168  int i;
169 
170  if (POINTER_P(tbl)) {
171  for (i = 0; i < tbl->pos; i++) {
172  if (tbl->tbl[i] == id) {
173  return i+1;
174  }
175  }
176  }
177  return 0;
178 }
179 
180 
181 #ifndef RIPPER
182 typedef struct token_info {
183  const char *token;
184  int linenum;
185  int column;
186  int nonspc;
187  struct token_info *next;
188 } token_info;
189 #endif
190 
191 /*
192  Structure of Lexer Buffer:
193 
194  lex_pbeg tokp lex_p lex_pend
195  | | | |
196  |-----------+--------------+------------|
197  |<------------>|
198  token
199 */
200 struct parser_params {
201  int is_ripper;
202  NODE *heap;
203 
205  VALUE eofp;
206 
209  stack_type parser_cond_stack;
210  stack_type parser_cmdarg_stack;
211  int parser_class_nest;
212  int parser_paren_nest;
213  int parser_lpar_beg;
214  int parser_in_single;
215  int parser_in_def;
218  int parser_in_defined;
219  char *parser_tokenbuf;
220  int parser_tokidx;
221  int parser_toksiz;
225  const char *parser_lex_pbeg;
226  const char *parser_lex_p;
227  const char *parser_lex_pend;
228  int parser_heredoc_end;
231  long parser_lex_gets_ptr;
233  struct local_vars *parser_lvtbl;
235  int line_count;
236  int has_shebang;
237  char *parser_ruby_sourcefile; /* current source file */
238  int parser_ruby_sourceline; /* current line no. */
239  rb_encoding *enc;
240  rb_encoding *utf8;
241 
242  int parser_yydebug;
243 
244 #ifndef RIPPER
245  /* Ruby core only */
249  VALUE coverage;
250  int nerr;
251 
254 #else
255  /* Ripper only */
256  VALUE parser_ruby_sourcefile_string;
257  const char *tokp;
258  VALUE delayed;
259  int delayed_line;
260  int delayed_col;
261 
262  VALUE value;
263  VALUE result;
264  VALUE parsing_thread;
265  int toplevel_p;
266 #endif
267 };
268 
269 #define UTF8_ENC() (parser->utf8 ? parser->utf8 : \
270  (parser->utf8 = rb_utf8_encoding()))
271 #define STR_NEW(p,n) rb_enc_str_new((p),(n),parser->enc)
272 #define STR_NEW0() rb_enc_str_new(0,0,parser->enc)
273 #define STR_NEW2(p) rb_enc_str_new((p),strlen(p),parser->enc)
274 #define STR_NEW3(p,n,e,func) parser_str_new((p),(n),(e),(func),parser->enc)
275 #define ENC_SINGLE(cr) ((cr)==ENC_CODERANGE_7BIT)
276 #define TOK_INTERN(mb) rb_intern3(tok(), toklen(), parser->enc)
277 
278 static int parser_yyerror(struct parser_params*, const char*);
279 #define yyerror(msg) parser_yyerror(parser, (msg))
280 
281 #define lex_strterm (parser->parser_lex_strterm)
282 #define lex_state (parser->parser_lex_state)
283 #define cond_stack (parser->parser_cond_stack)
284 #define cmdarg_stack (parser->parser_cmdarg_stack)
285 #define class_nest (parser->parser_class_nest)
286 #define paren_nest (parser->parser_paren_nest)
287 #define lpar_beg (parser->parser_lpar_beg)
288 #define in_single (parser->parser_in_single)
289 #define in_def (parser->parser_in_def)
290 #define compile_for_eval (parser->parser_compile_for_eval)
291 #define cur_mid (parser->parser_cur_mid)
292 #define in_defined (parser->parser_in_defined)
293 #define tokenbuf (parser->parser_tokenbuf)
294 #define tokidx (parser->parser_tokidx)
295 #define toksiz (parser->parser_toksiz)
296 #define lex_input (parser->parser_lex_input)
297 #define lex_lastline (parser->parser_lex_lastline)
298 #define lex_nextline (parser->parser_lex_nextline)
299 #define lex_pbeg (parser->parser_lex_pbeg)
300 #define lex_p (parser->parser_lex_p)
301 #define lex_pend (parser->parser_lex_pend)
302 #define heredoc_end (parser->parser_heredoc_end)
303 #define command_start (parser->parser_command_start)
304 #define deferred_nodes (parser->parser_deferred_nodes)
305 #define lex_gets_ptr (parser->parser_lex_gets_ptr)
306 #define lex_gets (parser->parser_lex_gets)
307 #define lvtbl (parser->parser_lvtbl)
308 #define ruby__end__seen (parser->parser_ruby__end__seen)
309 #define ruby_sourceline (parser->parser_ruby_sourceline)
310 #define ruby_sourcefile (parser->parser_ruby_sourcefile)
311 #define current_enc (parser->enc)
312 #define yydebug (parser->parser_yydebug)
313 #ifdef RIPPER
314 #else
315 #define ruby_eval_tree (parser->parser_eval_tree)
316 #define ruby_eval_tree_begin (parser->parser_eval_tree_begin)
317 #define ruby_debug_lines (parser->debug_lines)
318 #define ruby_coverage (parser->coverage)
319 #endif
320 
321 #if YYPURE
322 static int yylex(void*, void*);
323 #else
324 static int yylex(void*);
325 #endif
326 
327 #ifndef RIPPER
328 #define yyparse ruby_yyparse
329 
330 static NODE* node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE);
331 #define rb_node_newnode(type, a1, a2, a3) node_newnode(parser, (type), (a1), (a2), (a3))
332 
333 static NODE *cond_gen(struct parser_params*,NODE*);
334 #define cond(node) cond_gen(parser, (node))
335 static NODE *logop_gen(struct parser_params*,enum node_type,NODE*,NODE*);
336 #define logop(type,node1,node2) logop_gen(parser, (type), (node1), (node2))
337 
338 static NODE *newline_node(NODE*);
339 static void fixpos(NODE*,NODE*);
340 
341 static int value_expr_gen(struct parser_params*,NODE*);
342 static void void_expr_gen(struct parser_params*,NODE*);
343 static NODE *remove_begin(NODE*);
344 #define value_expr(node) value_expr_gen(parser, (node) = remove_begin(node))
345 #define void_expr0(node) void_expr_gen(parser, (node))
346 #define void_expr(node) void_expr0((node) = remove_begin(node))
347 static void void_stmts_gen(struct parser_params*,NODE*);
348 #define void_stmts(node) void_stmts_gen(parser, (node))
349 static void reduce_nodes_gen(struct parser_params*,NODE**);
350 #define reduce_nodes(n) reduce_nodes_gen(parser,(n))
351 static void block_dup_check_gen(struct parser_params*,NODE*,NODE*);
352 #define block_dup_check(n1,n2) block_dup_check_gen(parser,(n1),(n2))
353 
354 static NODE *block_append_gen(struct parser_params*,NODE*,NODE*);
355 #define block_append(h,t) block_append_gen(parser,(h),(t))
356 static NODE *list_append_gen(struct parser_params*,NODE*,NODE*);
357 #define list_append(l,i) list_append_gen(parser,(l),(i))
358 static NODE *list_concat_gen(struct parser_params*,NODE*,NODE*);
359 #define list_concat(h,t) list_concat_gen(parser,(h),(t))
360 static NODE *arg_append_gen(struct parser_params*,NODE*,NODE*);
361 #define arg_append(h,t) arg_append_gen(parser,(h),(t))
362 static NODE *arg_concat_gen(struct parser_params*,NODE*,NODE*);
363 #define arg_concat(h,t) arg_concat_gen(parser,(h),(t))
364 static NODE *literal_concat_gen(struct parser_params*,NODE*,NODE*);
365 #define literal_concat(h,t) literal_concat_gen(parser,(h),(t))
366 static int literal_concat0(struct parser_params *, VALUE, VALUE);
367 static NODE *new_evstr_gen(struct parser_params*,NODE*);
368 #define new_evstr(n) new_evstr_gen(parser,(n))
369 static NODE *evstr2dstr_gen(struct parser_params*,NODE*);
370 #define evstr2dstr(n) evstr2dstr_gen(parser,(n))
371 static NODE *splat_array(NODE*);
372 
373 static NODE *call_bin_op_gen(struct parser_params*,NODE*,ID,NODE*);
374 #define call_bin_op(recv,id,arg1) call_bin_op_gen(parser, (recv),(id),(arg1))
375 static NODE *call_uni_op_gen(struct parser_params*,NODE*,ID);
376 #define call_uni_op(recv,id) call_uni_op_gen(parser, (recv),(id))
377 
378 static NODE *new_args_gen(struct parser_params*,NODE*,NODE*,ID,NODE*,ID);
379 #define new_args(f,o,r,p,b) new_args_gen(parser, (f),(o),(r),(p),(b))
380 
381 static NODE *negate_lit(NODE*);
382 static NODE *ret_args_gen(struct parser_params*,NODE*);
383 #define ret_args(node) ret_args_gen(parser, (node))
384 static NODE *arg_blk_pass(NODE*,NODE*);
385 static NODE *new_yield_gen(struct parser_params*,NODE*);
386 #define new_yield(node) new_yield_gen(parser, (node))
387 
388 static NODE *gettable_gen(struct parser_params*,ID);
389 #define gettable(id) gettable_gen(parser,(id))
390 static NODE *assignable_gen(struct parser_params*,ID,NODE*);
391 #define assignable(id,node) assignable_gen(parser, (id), (node))
392 
393 static NODE *aryset_gen(struct parser_params*,NODE*,NODE*);
394 #define aryset(node1,node2) aryset_gen(parser, (node1), (node2))
395 static NODE *attrset_gen(struct parser_params*,NODE*,ID);
396 #define attrset(node,id) attrset_gen(parser, (node), (id))
397 
398 static void rb_backref_error_gen(struct parser_params*,NODE*);
399 #define rb_backref_error(n) rb_backref_error_gen(parser,(n))
400 static NODE *node_assign_gen(struct parser_params*,NODE*,NODE*);
401 #define node_assign(node1, node2) node_assign_gen(parser, (node1), (node2))
402 
403 static NODE *match_op_gen(struct parser_params*,NODE*,NODE*);
404 #define match_op(node1,node2) match_op_gen(parser, (node1), (node2))
405 
406 static ID *local_tbl_gen(struct parser_params*);
407 #define local_tbl() local_tbl_gen(parser)
408 
409 static void fixup_nodes(NODE **);
410 
411 static VALUE reg_compile_gen(struct parser_params*, VALUE, int);
412 #define reg_compile(str,options) reg_compile_gen(parser, (str), (options))
413 static void reg_fragment_setenc_gen(struct parser_params*, VALUE, int);
414 #define reg_fragment_setenc(str,options) reg_fragment_setenc_gen(parser, (str), (options))
415 static int reg_fragment_check_gen(struct parser_params*, VALUE, int);
416 #define reg_fragment_check(str,options) reg_fragment_check_gen(parser, (str), (options))
418 #define reg_named_capture_assign(regexp,match) reg_named_capture_assign_gen(parser,(regexp),(match))
419 
420 #define get_id(id) (id)
421 #define get_value(val) (val)
422 #else
423 #define remove_begin(node) (node)
424 #define rb_dvar_defined(id) 0
425 #define rb_local_defined(id) 0
426 static ID ripper_get_id(VALUE);
427 #define get_id(id) ripper_get_id(id)
428 static VALUE ripper_get_value(VALUE);
429 #define get_value(val) ripper_get_value(val)
430 static VALUE assignable_gen(struct parser_params*,VALUE);
431 #define assignable(lhs,node) assignable_gen(parser, (lhs))
432 static int id_is_var_gen(struct parser_params *parser, ID id);
433 #define id_is_var(id) id_is_var_gen(parser, (id))
434 #endif /* !RIPPER */
435 
436 static ID formal_argument_gen(struct parser_params*, ID);
437 #define formal_argument(id) formal_argument_gen(parser, (id))
438 static ID shadowing_lvar_gen(struct parser_params*,ID);
439 #define shadowing_lvar(name) shadowing_lvar_gen(parser, (name))
440 static void new_bv_gen(struct parser_params*,ID);
441 #define new_bv(id) new_bv_gen(parser, (id))
442 
443 static void local_push_gen(struct parser_params*,int);
444 #define local_push(top) local_push_gen(parser,(top))
445 static void local_pop_gen(struct parser_params*);
446 #define local_pop() local_pop_gen(parser)
447 static int local_var_gen(struct parser_params*, ID);
448 #define local_var(id) local_var_gen(parser, (id));
449 static int arg_var_gen(struct parser_params*, ID);
450 #define arg_var(id) arg_var_gen(parser, (id))
451 static int local_id_gen(struct parser_params*, ID);
452 #define local_id(id) local_id_gen(parser, (id))
453 static ID internal_id_gen(struct parser_params*);
454 #define internal_id() internal_id_gen(parser)
455 
456 static const struct vtable *dyna_push_gen(struct parser_params *);
457 #define dyna_push() dyna_push_gen(parser)
458 static void dyna_pop_gen(struct parser_params*, const struct vtable *);
459 #define dyna_pop(node) dyna_pop_gen(parser, (node))
460 static int dyna_in_block_gen(struct parser_params*);
461 #define dyna_in_block() dyna_in_block_gen(parser)
462 #define dyna_var(id) local_var(id)
463 static int dvar_defined_gen(struct parser_params*,ID,int);
464 #define dvar_defined(id) dvar_defined_gen(parser, (id), 0)
465 #define dvar_defined_get(id) dvar_defined_gen(parser, (id), 1)
466 static int dvar_curr_gen(struct parser_params*,ID);
467 #define dvar_curr(id) dvar_curr_gen(parser, (id))
468 
469 static int lvar_defined_gen(struct parser_params*, ID);
470 #define lvar_defined(id) lvar_defined_gen(parser, (id))
471 
472 #define RE_OPTION_ONCE (1<<16)
473 #define RE_OPTION_ENCODING_SHIFT 8
474 #define RE_OPTION_ENCODING(e) (((e)&0xff)<<RE_OPTION_ENCODING_SHIFT)
475 #define RE_OPTION_ENCODING_IDX(o) (((o)>>RE_OPTION_ENCODING_SHIFT)&0xff)
476 #define RE_OPTION_ENCODING_NONE(o) ((o)&RE_OPTION_ARG_ENCODING_NONE)
477 #define RE_OPTION_MASK 0xff
478 #define RE_OPTION_ARG_ENCODING_NONE 32
479 
480 #define NODE_STRTERM NODE_ZARRAY /* nothing to gc */
481 #define NODE_HEREDOC NODE_ARRAY /* 1, 3 to gc */
482 #define SIGN_EXTEND(x,n) (((1<<(n)-1)^((x)&~(~0<<(n))))-(1<<(n)-1))
483 #define nd_func u1.id
484 #if SIZEOF_SHORT == 2
485 #define nd_term(node) ((signed short)(node)->u2.id)
486 #else
487 #define nd_term(node) SIGN_EXTEND((node)->u2.id, CHAR_BIT*2)
488 #endif
489 #define nd_paren(node) (char)((node)->u2.id >> CHAR_BIT*2)
490 #define nd_nest u3.cnt
491 
492 /****** Ripper *******/
493 
494 #ifdef RIPPER
495 #define RIPPER_VERSION "0.1.0"
496 
497 #include "eventids1.c"
498 #include "eventids2.c"
499 static ID ripper_id_gets;
500 
501 static VALUE ripper_dispatch0(struct parser_params*,ID);
502 static VALUE ripper_dispatch1(struct parser_params*,ID,VALUE);
503 static VALUE ripper_dispatch2(struct parser_params*,ID,VALUE,VALUE);
504 static VALUE ripper_dispatch3(struct parser_params*,ID,VALUE,VALUE,VALUE);
505 static VALUE ripper_dispatch4(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE);
506 static VALUE ripper_dispatch5(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,VALUE);
507 
508 #define dispatch0(n) ripper_dispatch0(parser, TOKEN_PASTE(ripper_id_, n))
509 #define dispatch1(n,a) ripper_dispatch1(parser, TOKEN_PASTE(ripper_id_, n), (a))
510 #define dispatch2(n,a,b) ripper_dispatch2(parser, TOKEN_PASTE(ripper_id_, n), (a), (b))
511 #define dispatch3(n,a,b,c) ripper_dispatch3(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c))
512 #define dispatch4(n,a,b,c,d) ripper_dispatch4(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d))
513 #define dispatch5(n,a,b,c,d,e) ripper_dispatch5(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d), (e))
514 
515 #define yyparse ripper_yyparse
516 
517 #define ripper_intern(s) ID2SYM(rb_intern(s))
518 static VALUE ripper_id2sym(ID);
519 #ifdef __GNUC__
520 #define ripper_id2sym(id) ((id) < 256 && rb_ispunct(id) ? \
521  ID2SYM(id) : ripper_id2sym(id))
522 #endif
523 
524 #define arg_new() dispatch0(args_new)
525 #define arg_add(l,a) dispatch2(args_add, (l), (a))
526 #define arg_add_star(l,a) dispatch2(args_add_star, (l), (a))
527 #define arg_add_block(l,b) dispatch2(args_add_block, (l), (b))
528 #define arg_add_optblock(l,b) ((b)==Qundef? (l) : dispatch2(args_add_block, (l), (b)))
529 #define bare_assoc(v) dispatch1(bare_assoc_hash, (v))
530 #define arg_add_assocs(l,b) arg_add((l), bare_assoc(b))
531 
532 #define args2mrhs(a) dispatch1(mrhs_new_from_args, (a))
533 #define mrhs_new() dispatch0(mrhs_new)
534 #define mrhs_add(l,a) dispatch2(mrhs_add, (l), (a))
535 #define mrhs_add_star(l,a) dispatch2(mrhs_add_star, (l), (a))
536 
537 #define mlhs_new() dispatch0(mlhs_new)
538 #define mlhs_add(l,a) dispatch2(mlhs_add, (l), (a))
539 #define mlhs_add_star(l,a) dispatch2(mlhs_add_star, (l), (a))
540 
541 #define params_new(pars, opts, rest, pars2, blk) \
542  dispatch5(params, (pars), (opts), (rest), (pars2), (blk))
543 
544 #define blockvar_new(p,v) dispatch2(block_var, (p), (v))
545 #define blockvar_add_star(l,a) dispatch2(block_var_add_star, (l), (a))
546 #define blockvar_add_block(l,a) dispatch2(block_var_add_block, (l), (a))
547 
548 #define method_optarg(m,a) ((a)==Qundef ? (m) : dispatch2(method_add_arg,(m),(a)))
549 #define method_arg(m,a) dispatch2(method_add_arg,(m),(a))
550 #define method_add_block(m,b) dispatch2(method_add_block, (m), (b))
551 
552 #define escape_Qundef(x) ((x)==Qundef ? Qnil : (x))
553 
554 #define FIXME 0
555 
556 #endif /* RIPPER */
557 
558 #ifndef RIPPER
559 # define ifndef_ripper(x) (x)
560 #else
561 # define ifndef_ripper(x)
562 #endif
563 
564 #ifndef RIPPER
565 # define rb_warn0(fmt) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt))
566 # define rb_warnI(fmt,a) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt), (a))
567 # define rb_warnS(fmt,a) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt), (a))
568 # define rb_warning0(fmt) rb_compile_warning(ruby_sourcefile, ruby_sourceline, (fmt))
569 # define rb_warningS(fmt,a) rb_compile_warning(ruby_sourcefile, ruby_sourceline, (fmt), (a))
570 #else
571 # define rb_warn0(fmt) ripper_warn0(parser, (fmt))
572 # define rb_warnI(fmt,a) ripper_warnI(parser, (fmt), (a))
573 # define rb_warnS(fmt,a) ripper_warnS(parser, (fmt), (a))
574 # define rb_warning0(fmt) ripper_warning0(parser, (fmt))
575 # define rb_warningS(fmt,a) ripper_warningS(parser, (fmt), (a))
576 static void ripper_warn0(struct parser_params*, const char*);
577 static void ripper_warnI(struct parser_params*, const char*, int);
578 #if 0
579 static void ripper_warnS(struct parser_params*, const char*, const char*);
580 #endif
581 static void ripper_warning0(struct parser_params*, const char*);
582 static void ripper_warningS(struct parser_params*, const char*, const char*);
583 #endif
584 
585 #ifdef RIPPER
586 static void ripper_compile_error(struct parser_params*, const char *fmt, ...);
587 # define rb_compile_error ripper_compile_error
588 # define compile_error ripper_compile_error
589 # define PARSER_ARG parser,
590 #else
591 # define rb_compile_error rb_compile_error_with_enc
592 # define compile_error parser->nerr++,rb_compile_error_with_enc
593 # define PARSER_ARG ruby_sourcefile, ruby_sourceline, current_enc,
594 #endif
595 
596 /* Older versions of Yacc set YYMAXDEPTH to a very low value by default (150,
597  for instance). This is too low for Ruby to parse some files, such as
598  date/format.rb, therefore bump the value up to at least Bison's default. */
599 #ifdef OLD_YACC
600 #ifndef YYMAXDEPTH
601 #define YYMAXDEPTH 10000
602 #endif
603 #endif
604 
605 #ifndef RIPPER
606 static void token_info_push(struct parser_params*, const char *token);
607 static void token_info_pop(struct parser_params*, const char *token);
608 #define token_info_push(token) (RTEST(ruby_verbose) ? token_info_push(parser, (token)) : (void)0)
609 #define token_info_pop(token) (RTEST(ruby_verbose) ? token_info_pop(parser, (token)) : (void)0)
610 #else
611 #define token_info_push(token) /* nothing */
612 #define token_info_pop(token) /* nothing */
613 #endif
614 %}
615 
616 %pure-parser
617 %lex-param {struct parser_params *parser}
618 %parse-param {struct parser_params *parser}
619 
620 %union {
621  VALUE val;
622  NODE *node;
623  ID id;
624  int num;
625  const struct vtable *vars;
626 }
627 
628 /*%%%*/
629 %token
630 /*%
631 %token <val>
632 %*/
641  keyword_if
655  keyword_in
656  keyword_do
668  keyword_or
682 
684 %token <node> tINTEGER tFLOAT tSTRING_CONTENT tCHAR
685 %token <node> tNTH_REF tBACK_REF
686 %token <num> tREGEXP_END
687 
688 %type <node> singleton strings string string1 xstring regexp
689 %type <node> string_contents xstring_contents regexp_contents string_content
690 %type <node> words qwords word_list qword_list word
691 %type <node> literal numeric dsym cpath
692 %type <node> top_compstmt top_stmts top_stmt
693 %type <node> bodystmt compstmt stmts stmt expr arg primary command command_call method_call
694 %type <node> expr_value arg_value primary_value
695 %type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
696 %type <node> args call_args opt_call_args
697 %type <node> paren_args opt_paren_args
698 %type <node> command_args aref_args opt_block_arg block_arg var_ref var_lhs
699 %type <node> command_asgn mrhs superclass block_call block_command
700 %type <node> f_block_optarg f_block_opt
701 %type <node> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
702 %type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
703 %type <node> block_param opt_block_param block_param_def f_opt
704 %type <node> bv_decls opt_bv_decl bvar
705 %type <node> lambda f_larglist lambda_body
706 %type <node> brace_block cmd_brace_block do_block lhs none fitem
708 %type <id> fsym keyword_variable user_variable sym symbol operation operation2 operation3
709 %type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
710 /*%%%*/
711 /*%
712 %type <val> program reswords then do dot_or_colon
713 %*/
714 %token tUPLUS /* unary+ */
715 %token tUMINUS /* unary- */
716 %token tPOW /* ** */
717 %token tCMP /* <=> */
718 %token tEQ /* == */
719 %token tEQQ /* === */
720 %token tNEQ /* != */
721 %token tGEQ /* >= */
722 %token tLEQ /* <= */
723 %token tANDOP tOROP /* && and || */
724 %token tMATCH tNMATCH /* =~ and !~ */
725 %token tDOT2 tDOT3 /* .. and ... */
726 %token tAREF tASET /* [] and []= */
727 %token tLSHFT tRSHFT /* << and >> */
728 %token tCOLON2 /* :: */
729 %token tCOLON3 /* :: at EXPR_BEG */
730 %token <id> tOP_ASGN /* +=, -= etc. */
731 %token tASSOC /* => */
732 %token tLPAREN /* ( */
733 %token tLPAREN_ARG /* ( */
734 %token tRPAREN /* ) */
735 %token tLBRACK /* [ */
736 %token tLBRACE /* { */
737 %token tLBRACE_ARG /* { */
738 %token tSTAR /* * */
739 %token tAMPER /* & */
740 %token tLAMBDA /* -> */
743 
744 /*
745  * precedence table
746  */
747 
748 %nonassoc tLOWEST
749 %nonassoc tLBRACE_ARG
750 
753 %right keyword_not
754 %nonassoc keyword_defined
755 %right '=' tOP_ASGN
756 %left modifier_rescue
757 %right '?' ':'
758 %nonassoc tDOT2 tDOT3
759 %left tOROP
760 %left tANDOP
761 %nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
762 %left '>' tGEQ '<' tLEQ
763 %left '|' '^'
764 %left '&'
765 %left tLSHFT tRSHFT
766 %left '+' '-'
767 %left '*' '/' '%'
768 %right tUMINUS_NUM tUMINUS
769 %right tPOW
770 %right '!' '~' tUPLUS
771 
772 %nonassoc idNULL
773 %nonassoc idRespond_to
774 %nonassoc idIFUNC
775 %nonassoc idCFUNC
776 %nonassoc id_core_set_method_alias
778 %nonassoc id_core_undef_method
779 %nonassoc id_core_define_method
781 %nonassoc id_core_set_postexe
782 
784 
785 %%
786 program : {
788  /*%%%*/
790  /*%
791  local_push(0);
792  %*/
793  }
794  top_compstmt
795  {
796  /*%%%*/
797  if ($2 && !compile_for_eval) {
798  /* last expression should not be void */
799  if (nd_type($2) != NODE_BLOCK) void_expr($2);
800  else {
801  NODE *node = $2;
802  while (node->nd_next) {
803  node = node->nd_next;
804  }
805  void_expr(node->nd_head);
806  }
807  }
809  /*%
810  $$ = $2;
811  parser->result = dispatch1(program, $$);
812  %*/
813  local_pop();
814  }
815  ;
816 
817 top_compstmt : top_stmts opt_terms
818  {
819  /*%%%*/
822  /*%
823  %*/
824  $$ = $1;
825  }
826  ;
827 
828 top_stmts : none
829  {
830  /*%%%*/
831  $$ = NEW_BEGIN(0);
832  /*%
833  $$ = dispatch2(stmts_add, dispatch0(stmts_new),
834  dispatch0(void_stmt));
835  %*/
836  }
837  | top_stmt
838  {
839  /*%%%*/
840  $$ = newline_node($1);
841  /*%
842  $$ = dispatch2(stmts_add, dispatch0(stmts_new), $1);
843  %*/
844  }
845  | top_stmts terms top_stmt
846  {
847  /*%%%*/
848  $$ = block_append($1, newline_node($3));
849  /*%
850  $$ = dispatch2(stmts_add, $1, $3);
851  %*/
852  }
853  | error top_stmt
854  {
855  $$ = remove_begin($2);
856  }
857  ;
858 
859 top_stmt : stmt
860  | keyword_BEGIN
861  {
862  if (in_def || in_single) {
863  yyerror("BEGIN in method");
864  }
865  /*%%%*/
866  /* local_push(0); */
867  /*%
868  %*/
869  }
870  '{' top_compstmt '}'
871  {
872  /*%%%*/
874  $4);
875  /* NEW_PREEXE($4)); */
876  /* local_pop(); */
877  $$ = NEW_BEGIN(0);
878  /*%
879  $$ = dispatch1(BEGIN, $4);
880  %*/
881  }
882  ;
883 
884 bodystmt : compstmt
885  opt_rescue
886  opt_else
887  opt_ensure
888  {
889  /*%%%*/
890  $$ = $1;
891  if ($2) {
892  $$ = NEW_RESCUE($1, $2, $3);
893  }
894  else if ($3) {
895  rb_warn0("else without rescue is useless");
896  $$ = block_append($$, $3);
897  }
898  if ($4) {
899  if ($$) {
900  $$ = NEW_ENSURE($$, $4);
901  }
902  else {
903  $$ = block_append($4, NEW_NIL());
904  }
905  }
906  fixpos($$, $1);
907  /*%
908  $$ = dispatch4(bodystmt,
909  escape_Qundef($1),
910  escape_Qundef($2),
911  escape_Qundef($3),
912  escape_Qundef($4));
913  %*/
914  }
915  ;
916 
917 compstmt : stmts opt_terms
918  {
919  /*%%%*/
920  void_stmts($1);
922  /*%
923  %*/
924  $$ = $1;
925  }
926  ;
927 
928 stmts : none
929  {
930  /*%%%*/
931  $$ = NEW_BEGIN(0);
932  /*%
933  $$ = dispatch2(stmts_add, dispatch0(stmts_new),
934  dispatch0(void_stmt));
935  %*/
936  }
937  | stmt
938  {
939  /*%%%*/
940  $$ = newline_node($1);
941  /*%
942  $$ = dispatch2(stmts_add, dispatch0(stmts_new), $1);
943  %*/
944  }
945  | stmts terms stmt
946  {
947  /*%%%*/
948  $$ = block_append($1, newline_node($3));
949  /*%
950  $$ = dispatch2(stmts_add, $1, $3);
951  %*/
952  }
953  | error stmt
954  {
955  $$ = remove_begin($2);
956  }
957  ;
958 
960  {
961  /*%%%*/
962  $$ = NEW_ALIAS($2, $4);
963  /*%
964  $$ = dispatch2(alias, $2, $4);
965  %*/
966  }
968  {
969  /*%%%*/
970  $$ = NEW_VALIAS($2, $3);
971  /*%
972  $$ = dispatch2(var_alias, $2, $3);
973  %*/
974  }
976  {
977  /*%%%*/
978  char buf[2];
979  buf[0] = '$';
980  buf[1] = (char)$3->nd_nth;
981  $$ = NEW_VALIAS($2, rb_intern2(buf, 2));
982  /*%
983  $$ = dispatch2(var_alias, $2, $3);
984  %*/
985  }
987  {
988  /*%%%*/
989  yyerror("can't make alias for the number variables");
990  $$ = NEW_BEGIN(0);
991  /*%
992  $$ = dispatch2(var_alias, $2, $3);
993  $$ = dispatch1(alias_error, $$);
994  %*/
995  }
997  {
998  /*%%%*/
999  $$ = $2;
1000  /*%
1001  $$ = dispatch1(undef, $2);
1002  %*/
1003  }
1005  {
1006  /*%%%*/
1007  $$ = NEW_IF(cond($3), remove_begin($1), 0);
1008  fixpos($$, $3);
1009  /*%
1010  $$ = dispatch2(if_mod, $3, $1);
1011  %*/
1012  }
1014  {
1015  /*%%%*/
1016  $$ = NEW_UNLESS(cond($3), remove_begin($1), 0);
1017  fixpos($$, $3);
1018  /*%
1019  $$ = dispatch2(unless_mod, $3, $1);
1020  %*/
1021  }
1023  {
1024  /*%%%*/
1025  if ($1 && nd_type($1) == NODE_BEGIN) {
1026  $$ = NEW_WHILE(cond($3), $1->nd_body, 0);
1027  }
1028  else {
1029  $$ = NEW_WHILE(cond($3), $1, 1);
1030  }
1031  /*%
1032  $$ = dispatch2(while_mod, $3, $1);
1033  %*/
1034  }
1036  {
1037  /*%%%*/
1038  if ($1 && nd_type($1) == NODE_BEGIN) {
1039  $$ = NEW_UNTIL(cond($3), $1->nd_body, 0);
1040  }
1041  else {
1042  $$ = NEW_UNTIL(cond($3), $1, 1);
1043  }
1044  /*%
1045  $$ = dispatch2(until_mod, $3, $1);
1046  %*/
1047  }
1049  {
1050  /*%%%*/
1051  NODE *resq = NEW_RESBODY(0, remove_begin($3), 0);
1052  $$ = NEW_RESCUE(remove_begin($1), resq, 0);
1053  /*%
1054  $$ = dispatch2(rescue_mod, $1, $3);
1055  %*/
1056  }
1057  | keyword_END '{' compstmt '}'
1058  {
1059  if (in_def || in_single) {
1060  rb_warn0("END in method; use at_exit");
1061  }
1062  /*%%%*/
1063  $$ = NEW_POSTEXE(NEW_NODE(
1064  NODE_SCOPE, 0 /* tbl */, $3 /* body */, 0 /* args */));
1065  /*%
1066  $$ = dispatch1(END, $3);
1067  %*/
1068  }
1069  | command_asgn
1070  | mlhs '=' command_call
1071  {
1072  /*%%%*/
1073  value_expr($3);
1074  $1->nd_value = $3;
1075  $$ = $1;
1076  /*%
1077  $$ = dispatch2(massign, $1, $3);
1078  %*/
1079  }
1080  | var_lhs tOP_ASGN command_call
1081  {
1082  /*%%%*/
1083  value_expr($3);
1084  if ($1) {
1085  ID vid = $1->nd_vid;
1086  if ($2 == tOROP) {
1087  $1->nd_value = $3;
1088  $$ = NEW_OP_ASGN_OR(gettable(vid), $1);
1089  if (is_asgn_or_id(vid)) {
1090  $$->nd_aid = vid;
1091  }
1092  }
1093  else if ($2 == tANDOP) {
1094  $1->nd_value = $3;
1095  $$ = NEW_OP_ASGN_AND(gettable(vid), $1);
1096  }
1097  else {
1098  $$ = $1;
1099  $$->nd_value = NEW_CALL(gettable(vid), $2, NEW_LIST($3));
1100  }
1101  }
1102  else {
1103  $$ = NEW_BEGIN(0);
1104  }
1105  /*%
1106  $$ = dispatch3(opassign, $1, $2, $3);
1107  %*/
1108  }
1109  | primary_value '[' opt_call_args rbracket tOP_ASGN command_call
1110  {
1111  /*%%%*/
1112  NODE *args;
1113 
1114  value_expr($6);
1115  if (!$3) $3 = NEW_ZARRAY();
1116  args = arg_concat($3, $6);
1117  if ($5 == tOROP) {
1118  $5 = 0;
1119  }
1120  else if ($5 == tANDOP) {
1121  $5 = 1;
1122  }
1123  $$ = NEW_OP_ASGN1($1, $5, args);
1124  fixpos($$, $1);
1125  /*%
1126  $$ = dispatch2(aref_field, $1, escape_Qundef($3));
1127  $$ = dispatch3(opassign, $$, $5, $6);
1128  %*/
1129  }
1130  | primary_value '.' tIDENTIFIER tOP_ASGN command_call
1131  {
1132  /*%%%*/
1133  value_expr($5);
1134  if ($4 == tOROP) {
1135  $4 = 0;
1136  }
1137  else if ($4 == tANDOP) {
1138  $4 = 1;
1139  }
1140  $$ = NEW_OP_ASGN2($1, $3, $4, $5);
1141  fixpos($$, $1);
1142  /*%
1143  $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
1144  $$ = dispatch3(opassign, $$, $4, $5);
1145  %*/
1146  }
1147  | primary_value '.' tCONSTANT tOP_ASGN command_call
1148  {
1149  /*%%%*/
1150  value_expr($5);
1151  if ($4 == tOROP) {
1152  $4 = 0;
1153  }
1154  else if ($4 == tANDOP) {
1155  $4 = 1;
1156  }
1157  $$ = NEW_OP_ASGN2($1, $3, $4, $5);
1158  fixpos($$, $1);
1159  /*%
1160  $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
1161  $$ = dispatch3(opassign, $$, $4, $5);
1162  %*/
1163  }
1164  | primary_value tCOLON2 tCONSTANT tOP_ASGN command_call
1165  {
1166  /*%%%*/
1167  yyerror("constant re-assignment");
1168  $$ = 0;
1169  /*%
1170  $$ = dispatch2(const_path_field, $1, $3);
1171  $$ = dispatch3(opassign, $$, $4, $5);
1172  $$ = dispatch1(assign_error, $$);
1173  %*/
1174  }
1175  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN command_call
1176  {
1177  /*%%%*/
1178  value_expr($5);
1179  if ($4 == tOROP) {
1180  $4 = 0;
1181  }
1182  else if ($4 == tANDOP) {
1183  $4 = 1;
1184  }
1185  $$ = NEW_OP_ASGN2($1, $3, $4, $5);
1186  fixpos($$, $1);
1187  /*%
1188  $$ = dispatch3(field, $1, ripper_intern("::"), $3);
1189  $$ = dispatch3(opassign, $$, $4, $5);
1190  %*/
1191  }
1192  | backref tOP_ASGN command_call
1193  {
1194  /*%%%*/
1195  rb_backref_error($1);
1196  $$ = NEW_BEGIN(0);
1197  /*%
1198  $$ = dispatch2(assign, dispatch1(var_field, $1), $3);
1199  $$ = dispatch1(assign_error, $$);
1200  %*/
1201  }
1202  | lhs '=' mrhs
1203  {
1204  /*%%%*/
1205  value_expr($3);
1206  $$ = node_assign($1, $3);
1207  /*%
1208  $$ = dispatch2(assign, $1, $3);
1209  %*/
1210  }
1211  | mlhs '=' arg_value
1212  {
1213  /*%%%*/
1214  $1->nd_value = $3;
1215  $$ = $1;
1216  /*%
1217  $$ = dispatch2(massign, $1, $3);
1218  %*/
1219  }
1220  | mlhs '=' mrhs
1221  {
1222  /*%%%*/
1223  $1->nd_value = $3;
1224  $$ = $1;
1225  /*%
1226  $$ = dispatch2(massign, $1, $3);
1227  %*/
1228  }
1229  | expr
1230  ;
1231 
1232 command_asgn : lhs '=' command_call
1233  {
1234  /*%%%*/
1236  $$ = node_assign($1, $3);
1237  /*%
1238  $$ = dispatch2(assign, $1, $3);
1239  %*/
1240  }
1241  | lhs '=' command_asgn
1242  {
1243  /*%%%*/
1244  value_expr($3);
1245  $$ = node_assign($1, $3);
1246  /*%
1247  $$ = dispatch2(assign, $1, $3);
1248  %*/
1249  }
1250  ;
1251 
1252 
1255  {
1256  /*%%%*/
1257  $$ = logop(NODE_AND, $1, $3);
1258  /*%
1259  $$ = dispatch3(binary, $1, ripper_intern("and"), $3);
1260  %*/
1261  }
1262  | expr keyword_or expr
1263  {
1264  /*%%%*/
1265  $$ = logop(NODE_OR, $1, $3);
1266  /*%
1267  $$ = dispatch3(binary, $1, ripper_intern("or"), $3);
1268  %*/
1269  }
1270  | keyword_not opt_nl expr
1271  {
1272  /*%%%*/
1273  $$ = call_uni_op(cond($3), '!');
1274  /*%
1275  $$ = dispatch2(unary, ripper_intern("not"), $3);
1276  %*/
1277  }
1278  | '!' command_call
1279  {
1280  /*%%%*/
1281  $$ = call_uni_op(cond($2), '!');
1282  /*%
1283  $$ = dispatch2(unary, ripper_id2sym('!'), $2);
1284  %*/
1285  }
1286  | arg
1287  ;
1288 
1289 expr_value : expr
1290  {
1291  /*%%%*/
1293  $$ = $1;
1294  if (!$$) $$ = NEW_NIL();
1295  /*%
1296  $$ = $1;
1297  %*/
1298  }
1299  ;
1300 
1301 command_call : command
1302  | block_command
1303  ;
1304 
1305 block_command : block_call
1306  | block_call '.' operation2 command_args
1307  {
1308  /*%%%*/
1309  $$ = NEW_CALL($1, $3, $4);
1310  /*%
1311  $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
1312  $$ = method_arg($$, $4);
1313  %*/
1314  }
1315  | block_call tCOLON2 operation2 command_args
1316  {
1317  /*%%%*/
1318  $$ = NEW_CALL($1, $3, $4);
1319  /*%
1320  $$ = dispatch3(call, $1, ripper_intern("::"), $3);
1321  $$ = method_arg($$, $4);
1322  %*/
1323  }
1324  ;
1325 
1327  {
1328  $<vars>1 = dyna_push();
1329  /*%%%*/
1330  $<num>$ = ruby_sourceline;
1331  /*%
1332  %*/
1333  }
1334  opt_block_param
1335  compstmt
1336  '}'
1337  {
1338  /*%%%*/
1339  $$ = NEW_ITER($3,$4);
1340  nd_set_line($$, $<num>2);
1341  /*%
1342  $$ = dispatch2(brace_block, escape_Qundef($3), $4);
1343  %*/
1344  dyna_pop($<vars>1);
1345  }
1346  ;
1347 
1348 command : operation command_args %prec tLOWEST
1349  {
1350  /*%%%*/
1351  $$ = NEW_FCALL($1, $2);
1352  fixpos($$, $2);
1353  /*%
1354  $$ = dispatch2(command, $1, $2);
1355  %*/
1356  }
1357  | operation command_args cmd_brace_block
1358  {
1359  /*%%%*/
1360  block_dup_check($2,$3);
1361  $3->nd_iter = NEW_FCALL($1, $2);
1362  $$ = $3;
1363  fixpos($$, $2);
1364  /*%
1365  $$ = dispatch2(command, $1, $2);
1366  $$ = method_add_block($$, $3);
1367  %*/
1368  }
1369  | primary_value '.' operation2 command_args %prec tLOWEST
1370  {
1371  /*%%%*/
1372  $$ = NEW_CALL($1, $3, $4);
1373  fixpos($$, $1);
1374  /*%
1375  $$ = dispatch4(command_call, $1, ripper_id2sym('.'), $3, $4);
1376  %*/
1377  }
1378  | primary_value '.' operation2 command_args cmd_brace_block
1379  {
1380  /*%%%*/
1381  block_dup_check($4,$5);
1382  $5->nd_iter = NEW_CALL($1, $3, $4);
1383  $$ = $5;
1384  fixpos($$, $1);
1385  /*%
1386  $$ = dispatch4(command_call, $1, ripper_id2sym('.'), $3, $4);
1387  $$ = method_add_block($$, $5);
1388  %*/
1389  }
1390  | primary_value tCOLON2 operation2 command_args %prec tLOWEST
1391  {
1392  /*%%%*/
1393  $$ = NEW_CALL($1, $3, $4);
1394  fixpos($$, $1);
1395  /*%
1396  $$ = dispatch4(command_call, $1, ripper_intern("::"), $3, $4);
1397  %*/
1398  }
1399  | primary_value tCOLON2 operation2 command_args cmd_brace_block
1400  {
1401  /*%%%*/
1402  block_dup_check($4,$5);
1403  $5->nd_iter = NEW_CALL($1, $3, $4);
1404  $$ = $5;
1405  fixpos($$, $1);
1406  /*%
1407  $$ = dispatch4(command_call, $1, ripper_intern("::"), $3, $4);
1408  $$ = method_add_block($$, $5);
1409  %*/
1410  }
1412  {
1413  /*%%%*/
1414  $$ = NEW_SUPER($2);
1415  fixpos($$, $2);
1416  /*%
1417  $$ = dispatch1(super, $2);
1418  %*/
1419  }
1421  {
1422  /*%%%*/
1423  $$ = new_yield($2);
1424  fixpos($$, $2);
1425  /*%
1426  $$ = dispatch1(yield, $2);
1427  %*/
1428  }
1430  {
1431  /*%%%*/
1432  $$ = NEW_RETURN(ret_args($2));
1433  /*%
1434  $$ = dispatch1(return, $2);
1435  %*/
1436  }
1438  {
1439  /*%%%*/
1440  $$ = NEW_BREAK(ret_args($2));
1441  /*%
1442  $$ = dispatch1(break, $2);
1443  %*/
1444  }
1446  {
1447  /*%%%*/
1448  $$ = NEW_NEXT(ret_args($2));
1449  /*%
1450  $$ = dispatch1(next, $2);
1451  %*/
1452  }
1453  ;
1454 
1455 mlhs : mlhs_basic
1456  | tLPAREN mlhs_inner rparen
1457  {
1458  /*%%%*/
1459  $$ = $2;
1460  /*%
1461  $$ = dispatch1(mlhs_paren, $2);
1462  %*/
1463  }
1464  ;
1465 
1467  | tLPAREN mlhs_inner rparen
1468  {
1469  /*%%%*/
1470  $$ = NEW_MASGN(NEW_LIST($2), 0);
1471  /*%
1472  $$ = dispatch1(mlhs_paren, $2);
1473  %*/
1474  }
1475  ;
1476 
1478  {
1479  /*%%%*/
1480  $$ = NEW_MASGN($1, 0);
1481  /*%
1482  $$ = $1;
1483  %*/
1484  }
1486  {
1487  /*%%%*/
1488  $$ = NEW_MASGN(list_append($1,$2), 0);
1489  /*%
1490  $$ = mlhs_add($1, $2);
1491  %*/
1492  }
1494  {
1495  /*%%%*/
1496  $$ = NEW_MASGN($1, $3);
1497  /*%
1498  $$ = mlhs_add_star($1, $3);
1499  %*/
1500  }
1502  {
1503  /*%%%*/
1504  $$ = NEW_MASGN($1, NEW_POSTARG($3,$5));
1505  /*%
1506  $1 = mlhs_add_star($1, $3);
1507  $$ = mlhs_add($1, $5);
1508  %*/
1509  }
1510  | mlhs_head tSTAR
1511  {
1512  /*%%%*/
1513  $$ = NEW_MASGN($1, -1);
1514  /*%
1515  $$ = mlhs_add_star($1, Qnil);
1516  %*/
1517  }
1518  | mlhs_head tSTAR ',' mlhs_post
1519  {
1520  /*%%%*/
1521  $$ = NEW_MASGN($1, NEW_POSTARG(-1, $4));
1522  /*%
1523  $1 = mlhs_add_star($1, Qnil);
1524  $$ = mlhs_add($1, $4);
1525  %*/
1526  }
1527  | tSTAR mlhs_node
1528  {
1529  /*%%%*/
1530  $$ = NEW_MASGN(0, $2);
1531  /*%
1532  $$ = mlhs_add_star(mlhs_new(), $2);
1533  %*/
1534  }
1535  | tSTAR mlhs_node ',' mlhs_post
1536  {
1537  /*%%%*/
1538  $$ = NEW_MASGN(0, NEW_POSTARG($2,$4));
1539  /*%
1540  $2 = mlhs_add_star(mlhs_new(), $2);
1541  $$ = mlhs_add($2, $4);
1542  %*/
1543  }
1544  | tSTAR
1545  {
1546  /*%%%*/
1547  $$ = NEW_MASGN(0, -1);
1548  /*%
1549  $$ = mlhs_add_star(mlhs_new(), Qnil);
1550  %*/
1551  }
1552  | tSTAR ',' mlhs_post
1553  {
1554  /*%%%*/
1555  $$ = NEW_MASGN(0, NEW_POSTARG(-1, $3));
1556  /*%
1557  $$ = mlhs_add_star(mlhs_new(), Qnil);
1558  $$ = mlhs_add($$, $3);
1559  %*/
1560  }
1561  ;
1562 
1564  | tLPAREN mlhs_inner rparen
1565  {
1566  /*%%%*/
1567  $$ = $2;
1568  /*%
1569  $$ = dispatch1(mlhs_paren, $2);
1570  %*/
1571  }
1572  ;
1573 
1574 mlhs_head : mlhs_item ','
1575  {
1576  /*%%%*/
1577  $$ = NEW_LIST($1);
1578  /*%
1579  $$ = mlhs_add(mlhs_new(), $1);
1580  %*/
1581  }
1582  | mlhs_head mlhs_item ','
1583  {
1584  /*%%%*/
1585  $$ = list_append($1, $2);
1586  /*%
1587  $$ = mlhs_add($1, $2);
1588  %*/
1589  }
1590  ;
1591 
1593  {
1594  /*%%%*/
1595  $$ = NEW_LIST($1);
1596  /*%
1597  $$ = mlhs_add(mlhs_new(), $1);
1598  %*/
1599  }
1600  | mlhs_post ',' mlhs_item
1601  {
1602  /*%%%*/
1603  $$ = list_append($1, $3);
1604  /*%
1605  $$ = mlhs_add($1, $3);
1606  %*/
1607  }
1608  ;
1609 
1610 mlhs_node : user_variable
1611  {
1612  $$ = assignable($1, 0);
1613  }
1615  {
1616  $$ = assignable($1, 0);
1617  }
1618  | primary_value '[' opt_call_args rbracket
1619  {
1620  /*%%%*/
1621  $$ = aryset($1, $3);
1622  /*%
1623  $$ = dispatch2(aref_field, $1, escape_Qundef($3));
1624  %*/
1625  }
1626  | primary_value '.' tIDENTIFIER
1627  {
1628  /*%%%*/
1629  $$ = attrset($1, $3);
1630  /*%
1631  $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
1632  %*/
1633  }
1634  | primary_value tCOLON2 tIDENTIFIER
1635  {
1636  /*%%%*/
1637  $$ = attrset($1, $3);
1638  /*%
1639  $$ = dispatch2(const_path_field, $1, $3);
1640  %*/
1641  }
1642  | primary_value '.' tCONSTANT
1643  {
1644  /*%%%*/
1645  $$ = attrset($1, $3);
1646  /*%
1647  $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
1648  %*/
1649  }
1650  | primary_value tCOLON2 tCONSTANT
1651  {
1652  /*%%%*/
1653  if (in_def || in_single)
1654  yyerror("dynamic constant assignment");
1655  $$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
1656  /*%
1657  if (in_def || in_single)
1658  yyerror("dynamic constant assignment");
1659  $$ = dispatch2(const_path_field, $1, $3);
1660  %*/
1661  }
1662  | tCOLON3 tCONSTANT
1663  {
1664  /*%%%*/
1665  if (in_def || in_single)
1666  yyerror("dynamic constant assignment");
1667  $$ = NEW_CDECL(0, 0, NEW_COLON3($2));
1668  /*%
1669  $$ = dispatch1(top_const_field, $2);
1670  %*/
1671  }
1672  | backref
1673  {
1674  /*%%%*/
1675  rb_backref_error($1);
1676  $$ = NEW_BEGIN(0);
1677  /*%
1678  $$ = dispatch1(var_field, $1);
1679  $$ = dispatch1(assign_error, $$);
1680  %*/
1681  }
1682  ;
1683 
1684 lhs : user_variable
1685  {
1686  $$ = assignable($1, 0);
1687  /*%%%*/
1688  if (!$$) $$ = NEW_BEGIN(0);
1689  /*%
1690  $$ = dispatch1(var_field, $$);
1691  %*/
1692  }
1694  {
1695  $$ = assignable($1, 0);
1696  /*%%%*/
1697  if (!$$) $$ = NEW_BEGIN(0);
1698  /*%
1699  $$ = dispatch1(var_field, $$);
1700  %*/
1701  }
1702  | primary_value '[' opt_call_args rbracket
1703  {
1704  /*%%%*/
1705  $$ = aryset($1, $3);
1706  /*%
1707  $$ = dispatch2(aref_field, $1, escape_Qundef($3));
1708  %*/
1709  }
1710  | primary_value '.' tIDENTIFIER
1711  {
1712  /*%%%*/
1713  $$ = attrset($1, $3);
1714  /*%
1715  $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
1716  %*/
1717  }
1718  | primary_value tCOLON2 tIDENTIFIER
1719  {
1720  /*%%%*/
1721  $$ = attrset($1, $3);
1722  /*%
1723  $$ = dispatch3(field, $1, ripper_intern("::"), $3);
1724  %*/
1725  }
1726  | primary_value '.' tCONSTANT
1727  {
1728  /*%%%*/
1729  $$ = attrset($1, $3);
1730  /*%
1731  $$ = dispatch3(field, $1, ripper_id2sym('.'), $3);
1732  %*/
1733  }
1734  | primary_value tCOLON2 tCONSTANT
1735  {
1736  /*%%%*/
1737  if (in_def || in_single)
1738  yyerror("dynamic constant assignment");
1739  $$ = NEW_CDECL(0, 0, NEW_COLON2($1, $3));
1740  /*%
1741  $$ = dispatch2(const_path_field, $1, $3);
1742  if (in_def || in_single) {
1743  $$ = dispatch1(assign_error, $$);
1744  }
1745  %*/
1746  }
1747  | tCOLON3 tCONSTANT
1748  {
1749  /*%%%*/
1750  if (in_def || in_single)
1751  yyerror("dynamic constant assignment");
1752  $$ = NEW_CDECL(0, 0, NEW_COLON3($2));
1753  /*%
1754  $$ = dispatch1(top_const_field, $2);
1755  if (in_def || in_single) {
1756  $$ = dispatch1(assign_error, $$);
1757  }
1758  %*/
1759  }
1760  | backref
1761  {
1762  /*%%%*/
1763  rb_backref_error($1);
1764  $$ = NEW_BEGIN(0);
1765  /*%
1766  $$ = dispatch1(assign_error, $1);
1767  %*/
1768  }
1769  ;
1770 
1771 cname : tIDENTIFIER
1772  {
1773  /*%%%*/
1774  yyerror("class/module name must be CONSTANT");
1775  /*%
1776  $$ = dispatch1(class_name_error, $1);
1777  %*/
1778  }
1779  | tCONSTANT
1780  ;
1781 
1782 cpath : tCOLON3 cname
1783  {
1784  /*%%%*/
1785  $$ = NEW_COLON3($2);
1786  /*%
1787  $$ = dispatch1(top_const_ref, $2);
1788  %*/
1789  }
1790  | cname
1791  {
1792  /*%%%*/
1793  $$ = NEW_COLON2(0, $$);
1794  /*%
1795  $$ = dispatch1(const_ref, $1);
1796  %*/
1797  }
1798  | primary_value tCOLON2 cname
1799  {
1800  /*%%%*/
1801  $$ = NEW_COLON2($1, $3);
1802  /*%
1803  $$ = dispatch2(const_path_ref, $1, $3);
1804  %*/
1805  }
1806  ;
1807 
1808 fname : tIDENTIFIER
1809  | tCONSTANT
1810  | tFID
1811  | op
1812  {
1814  $$ = $1;
1815  }
1816  | reswords
1817  {
1819  /*%%%*/
1820  $$ = $<id>1;
1821  /*%
1822  $$ = $1;
1823  %*/
1824  }
1825  ;
1826 
1827 fsym : fname
1828  | symbol
1829  ;
1830 
1831 fitem : fsym
1832  {
1833  /*%%%*/
1834  $$ = NEW_LIT(ID2SYM($1));
1835  /*%
1836  $$ = dispatch1(symbol_literal, $1);
1837  %*/
1838  }
1839  | dsym
1840  ;
1841 
1842 undef_list : fitem
1843  {
1844  /*%%%*/
1845  $$ = NEW_UNDEF($1);
1846  /*%
1847  $$ = rb_ary_new3(1, $1);
1848  %*/
1849  }
1851  {
1852  /*%%%*/
1853  $$ = block_append($1, NEW_UNDEF($4));
1854  /*%
1855  rb_ary_push($1, $4);
1856  %*/
1857  }
1858  ;
1859 
1860 op : '|' { ifndef_ripper($$ = '|'); }
1861  | '^' { ifndef_ripper($$ = '^'); }
1862  | '&' { ifndef_ripper($$ = '&'); }
1863  | tCMP { ifndef_ripper($$ = tCMP); }
1864  | tEQ { ifndef_ripper($$ = tEQ); }
1865  | tEQQ { ifndef_ripper($$ = tEQQ); }
1866  | tMATCH { ifndef_ripper($$ = tMATCH); }
1867  | tNMATCH { ifndef_ripper($$ = tNMATCH); }
1868  | '>' { ifndef_ripper($$ = '>'); }
1869  | tGEQ { ifndef_ripper($$ = tGEQ); }
1870  | '<' { ifndef_ripper($$ = '<'); }
1871  | tLEQ { ifndef_ripper($$ = tLEQ); }
1872  | tNEQ { ifndef_ripper($$ = tNEQ); }
1873  | tLSHFT { ifndef_ripper($$ = tLSHFT); }
1874  | tRSHFT { ifndef_ripper($$ = tRSHFT); }
1875  | '+' { ifndef_ripper($$ = '+'); }
1876  | '-' { ifndef_ripper($$ = '-'); }
1877  | '*' { ifndef_ripper($$ = '*'); }
1878  | tSTAR { ifndef_ripper($$ = '*'); }
1879  | '/' { ifndef_ripper($$ = '/'); }
1880  | '%' { ifndef_ripper($$ = '%'); }
1881  | tPOW { ifndef_ripper($$ = tPOW); }
1882  | '!' { ifndef_ripper($$ = '!'); }
1883  | '~' { ifndef_ripper($$ = '~'); }
1884  | tUPLUS { ifndef_ripper($$ = tUPLUS); }
1885  | tUMINUS { ifndef_ripper($$ = tUMINUS); }
1886  | tAREF { ifndef_ripper($$ = tAREF); }
1887  | tASET { ifndef_ripper($$ = tASET); }
1888  | '`' { ifndef_ripper($$ = '`'); }
1889  ;
1890 
1903  ;
1904 
1905 arg : lhs '=' arg
1906  {
1907  /*%%%*/
1908  value_expr($3);
1909  $$ = node_assign($1, $3);
1910  /*%
1911  $$ = dispatch2(assign, $1, $3);
1912  %*/
1913  }
1914  | lhs '=' arg modifier_rescue arg
1915  {
1916  /*%%%*/
1917  value_expr($3);
1918  $3 = NEW_RESCUE($3, NEW_RESBODY(0,$5,0), 0);
1919  $$ = node_assign($1, $3);
1920  /*%
1921  $$ = dispatch2(assign, $1, dispatch2(rescue_mod, $3, $5));
1922  %*/
1923  }
1924  | var_lhs tOP_ASGN arg
1925  {
1926  /*%%%*/
1927  value_expr($3);
1928  if ($1) {
1929  ID vid = $1->nd_vid;
1930  if ($2 == tOROP) {
1931  $1->nd_value = $3;
1932  $$ = NEW_OP_ASGN_OR(gettable(vid), $1);
1933  if (is_asgn_or_id(vid)) {
1934  $$->nd_aid = vid;
1935  }
1936  }
1937  else if ($2 == tANDOP) {
1938  $1->nd_value = $3;
1939  $$ = NEW_OP_ASGN_AND(gettable(vid), $1);
1940  }
1941  else {
1942  $$ = $1;
1943  $$->nd_value = NEW_CALL(gettable(vid), $2, NEW_LIST($3));
1944  }
1945  }
1946  else {
1947  $$ = NEW_BEGIN(0);
1948  }
1949  /*%
1950  $$ = dispatch3(opassign, $1, $2, $3);
1951  %*/
1952  }
1953  | var_lhs tOP_ASGN arg modifier_rescue arg
1954  {
1955  /*%%%*/
1956  value_expr($3);
1957  $3 = NEW_RESCUE($3, NEW_RESBODY(0,$5,0), 0);
1958  if ($1) {
1959  ID vid = $1->nd_vid;
1960  if ($2 == tOROP) {
1961  $1->nd_value = $3;
1962  $$ = NEW_OP_ASGN_OR(gettable(vid), $1);
1963  if (is_asgn_or_id(vid)) {
1964  $$->nd_aid = vid;
1965  }
1966  }
1967  else if ($2 == tANDOP) {
1968  $1->nd_value = $3;
1969  $$ = NEW_OP_ASGN_AND(gettable(vid), $1);
1970  }
1971  else {
1972  $$ = $1;
1973  $$->nd_value = NEW_CALL(gettable(vid), $2, NEW_LIST($3));
1974  }
1975  }
1976  else {
1977  $$ = NEW_BEGIN(0);
1978  }
1979  /*%
1980  $3 = dispatch2(rescue_mod, $3, $5);
1981  $$ = dispatch3(opassign, $1, $2, $3);
1982  %*/
1983  }
1984  | primary_value '[' opt_call_args rbracket tOP_ASGN arg
1985  {
1986  /*%%%*/
1987  NODE *args;
1988 
1989  value_expr($6);
1990  if (!$3) $3 = NEW_ZARRAY();
1991  if (nd_type($3) == NODE_BLOCK_PASS) {
1992  args = NEW_ARGSCAT($3, $6);
1993  }
1994  else {
1995  args = arg_concat($3, $6);
1996  }
1997  if ($5 == tOROP) {
1998  $5 = 0;
1999  }
2000  else if ($5 == tANDOP) {
2001  $5 = 1;
2002  }
2003  $$ = NEW_OP_ASGN1($1, $5, args);
2004  fixpos($$, $1);
2005  /*%
2006  $1 = dispatch2(aref_field, $1, escape_Qundef($3));
2007  $$ = dispatch3(opassign, $1, $5, $6);
2008  %*/
2009  }
2010  | primary_value '.' tIDENTIFIER tOP_ASGN arg
2011  {
2012  /*%%%*/
2013  value_expr($5);
2014  if ($4 == tOROP) {
2015  $4 = 0;
2016  }
2017  else if ($4 == tANDOP) {
2018  $4 = 1;
2019  }
2020  $$ = NEW_OP_ASGN2($1, $3, $4, $5);
2021  fixpos($$, $1);
2022  /*%
2023  $1 = dispatch3(field, $1, ripper_id2sym('.'), $3);
2024  $$ = dispatch3(opassign, $1, $4, $5);
2025  %*/
2026  }
2027  | primary_value '.' tCONSTANT tOP_ASGN arg
2028  {
2029  /*%%%*/
2030  value_expr($5);
2031  if ($4 == tOROP) {
2032  $4 = 0;
2033  }
2034  else if ($4 == tANDOP) {
2035  $4 = 1;
2036  }
2037  $$ = NEW_OP_ASGN2($1, $3, $4, $5);
2038  fixpos($$, $1);
2039  /*%
2040  $1 = dispatch3(field, $1, ripper_id2sym('.'), $3);
2041  $$ = dispatch3(opassign, $1, $4, $5);
2042  %*/
2043  }
2044  | primary_value tCOLON2 tIDENTIFIER tOP_ASGN arg
2045  {
2046  /*%%%*/
2047  value_expr($5);
2048  if ($4 == tOROP) {
2049  $4 = 0;
2050  }
2051  else if ($4 == tANDOP) {
2052  $4 = 1;
2053  }
2054  $$ = NEW_OP_ASGN2($1, $3, $4, $5);
2055  fixpos($$, $1);
2056  /*%
2057  $1 = dispatch3(field, $1, ripper_intern("::"), $3);
2058  $$ = dispatch3(opassign, $1, $4, $5);
2059  %*/
2060  }
2061  | primary_value tCOLON2 tCONSTANT tOP_ASGN arg
2062  {
2063  /*%%%*/
2064  yyerror("constant re-assignment");
2065  $$ = NEW_BEGIN(0);
2066  /*%
2067  $$ = dispatch2(const_path_field, $1, $3);
2068  $$ = dispatch3(opassign, $$, $4, $5);
2069  $$ = dispatch1(assign_error, $$);
2070  %*/
2071  }
2073  {
2074  /*%%%*/
2075  yyerror("constant re-assignment");
2076  $$ = NEW_BEGIN(0);
2077  /*%
2078  $$ = dispatch1(top_const_field, $2);
2079  $$ = dispatch3(opassign, $$, $3, $4);
2080  $$ = dispatch1(assign_error, $$);
2081  %*/
2082  }
2083  | backref tOP_ASGN arg
2084  {
2085  /*%%%*/
2086  rb_backref_error($1);
2087  $$ = NEW_BEGIN(0);
2088  /*%
2089  $$ = dispatch1(var_field, $1);
2090  $$ = dispatch3(opassign, $$, $2, $3);
2091  $$ = dispatch1(assign_error, $$);
2092  %*/
2093  }
2094  | arg tDOT2 arg
2095  {
2096  /*%%%*/
2097  value_expr($1);
2098  value_expr($3);
2099  $$ = NEW_DOT2($1, $3);
2100  if (nd_type($1) == NODE_LIT && FIXNUM_P($1->nd_lit) &&
2101  nd_type($3) == NODE_LIT && FIXNUM_P($3->nd_lit)) {
2103  }
2104  /*%
2105  $$ = dispatch2(dot2, $1, $3);
2106  %*/
2107  }
2108  | arg tDOT3 arg
2109  {
2110  /*%%%*/
2111  value_expr($1);
2112  value_expr($3);
2113  $$ = NEW_DOT3($1, $3);
2114  if (nd_type($1) == NODE_LIT && FIXNUM_P($1->nd_lit) &&
2115  nd_type($3) == NODE_LIT && FIXNUM_P($3->nd_lit)) {
2117  }
2118  /*%
2119  $$ = dispatch2(dot3, $1, $3);
2120  %*/
2121  }
2122  | arg '+' arg
2123  {
2124  /*%%%*/
2125  $$ = call_bin_op($1, '+', $3);
2126  /*%
2127  $$ = dispatch3(binary, $1, ID2SYM('+'), $3);
2128  %*/
2129  }
2130  | arg '-' arg
2131  {
2132  /*%%%*/
2133  $$ = call_bin_op($1, '-', $3);
2134  /*%
2135  $$ = dispatch3(binary, $1, ID2SYM('-'), $3);
2136  %*/
2137  }
2138  | arg '*' arg
2139  {
2140  /*%%%*/
2141  $$ = call_bin_op($1, '*', $3);
2142  /*%
2143  $$ = dispatch3(binary, $1, ID2SYM('*'), $3);
2144  %*/
2145  }
2146  | arg '/' arg
2147  {
2148  /*%%%*/
2149  $$ = call_bin_op($1, '/', $3);
2150  /*%
2151  $$ = dispatch3(binary, $1, ID2SYM('/'), $3);
2152  %*/
2153  }
2154  | arg '%' arg
2155  {
2156  /*%%%*/
2157  $$ = call_bin_op($1, '%', $3);
2158  /*%
2159  $$ = dispatch3(binary, $1, ID2SYM('%'), $3);
2160  %*/
2161  }
2162  | arg tPOW arg
2163  {
2164  /*%%%*/
2165  $$ = call_bin_op($1, tPOW, $3);
2166  /*%
2167  $$ = dispatch3(binary, $1, ripper_intern("**"), $3);
2168  %*/
2169  }
2171  {
2172  /*%%%*/
2173  $$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0);
2174  /*%
2175  $$ = dispatch3(binary, $2, ripper_intern("**"), $4);
2176  $$ = dispatch2(unary, ripper_intern("-@"), $$);
2177  %*/
2178  }
2180  {
2181  /*%%%*/
2182  $$ = NEW_CALL(call_bin_op($2, tPOW, $4), tUMINUS, 0);
2183  /*%
2184  $$ = dispatch3(binary, $2, ripper_intern("**"), $4);
2185  $$ = dispatch2(unary, ripper_intern("-@"), $$);
2186  %*/
2187  }
2188  | tUPLUS arg
2189  {
2190  /*%%%*/
2191  $$ = call_uni_op($2, tUPLUS);
2192  /*%
2193  $$ = dispatch2(unary, ripper_intern("+@"), $2);
2194  %*/
2195  }
2196  | tUMINUS arg
2197  {
2198  /*%%%*/
2199  $$ = call_uni_op($2, tUMINUS);
2200  /*%
2201  $$ = dispatch2(unary, ripper_intern("-@"), $2);
2202  %*/
2203  }
2204  | arg '|' arg
2205  {
2206  /*%%%*/
2207  $$ = call_bin_op($1, '|', $3);
2208  /*%
2209  $$ = dispatch3(binary, $1, ID2SYM('|'), $3);
2210  %*/
2211  }
2212  | arg '^' arg
2213  {
2214  /*%%%*/
2215  $$ = call_bin_op($1, '^', $3);
2216  /*%
2217  $$ = dispatch3(binary, $1, ID2SYM('^'), $3);
2218  %*/
2219  }
2220  | arg '&' arg
2221  {
2222  /*%%%*/
2223  $$ = call_bin_op($1, '&', $3);
2224  /*%
2225  $$ = dispatch3(binary, $1, ID2SYM('&'), $3);
2226  %*/
2227  }
2228  | arg tCMP arg
2229  {
2230  /*%%%*/
2231  $$ = call_bin_op($1, tCMP, $3);
2232  /*%
2233  $$ = dispatch3(binary, $1, ripper_intern("<=>"), $3);
2234  %*/
2235  }
2236  | arg '>' arg
2237  {
2238  /*%%%*/
2239  $$ = call_bin_op($1, '>', $3);
2240  /*%
2241  $$ = dispatch3(binary, $1, ID2SYM('>'), $3);
2242  %*/
2243  }
2244  | arg tGEQ arg
2245  {
2246  /*%%%*/
2247  $$ = call_bin_op($1, tGEQ, $3);
2248  /*%
2249  $$ = dispatch3(binary, $1, ripper_intern(">="), $3);
2250  %*/
2251  }
2252  | arg '<' arg
2253  {
2254  /*%%%*/
2255  $$ = call_bin_op($1, '<', $3);
2256  /*%
2257  $$ = dispatch3(binary, $1, ID2SYM('<'), $3);
2258  %*/
2259  }
2260  | arg tLEQ arg
2261  {
2262  /*%%%*/
2263  $$ = call_bin_op($1, tLEQ, $3);
2264  /*%
2265  $$ = dispatch3(binary, $1, ripper_intern("<="), $3);
2266  %*/
2267  }
2268  | arg tEQ arg
2269  {
2270  /*%%%*/
2271  $$ = call_bin_op($1, tEQ, $3);
2272  /*%
2273  $$ = dispatch3(binary, $1, ripper_intern("=="), $3);
2274  %*/
2275  }
2276  | arg tEQQ arg
2277  {
2278  /*%%%*/
2279  $$ = call_bin_op($1, tEQQ, $3);
2280  /*%
2281  $$ = dispatch3(binary, $1, ripper_intern("==="), $3);
2282  %*/
2283  }
2284  | arg tNEQ arg
2285  {
2286  /*%%%*/
2287  $$ = call_bin_op($1, tNEQ, $3);
2288  /*%
2289  $$ = dispatch3(binary, $1, ripper_intern("!="), $3);
2290  %*/
2291  }
2292  | arg tMATCH arg
2293  {
2294  /*%%%*/
2295  $$ = match_op($1, $3);
2296  if (nd_type($1) == NODE_LIT && TYPE($1->nd_lit) == T_REGEXP) {
2297  $$ = reg_named_capture_assign($1->nd_lit, $$);
2298  }
2299  /*%
2300  $$ = dispatch3(binary, $1, ripper_intern("=~"), $3);
2301  %*/
2302  }
2303  | arg tNMATCH arg
2304  {
2305  /*%%%*/
2306  $$ = call_bin_op($1, tNMATCH, $3);
2307  /*%
2308  $$ = dispatch3(binary, $1, ripper_intern("!~"), $3);
2309  %*/
2310  }
2311  | '!' arg
2312  {
2313  /*%%%*/
2314  $$ = call_uni_op(cond($2), '!');
2315  /*%
2316  $$ = dispatch2(unary, ID2SYM('!'), $2);
2317  %*/
2318  }
2319  | '~' arg
2320  {
2321  /*%%%*/
2322  $$ = call_uni_op($2, '~');
2323  /*%
2324  $$ = dispatch2(unary, ID2SYM('~'), $2);
2325  %*/
2326  }
2327  | arg tLSHFT arg
2328  {
2329  /*%%%*/
2330  $$ = call_bin_op($1, tLSHFT, $3);
2331  /*%
2332  $$ = dispatch3(binary, $1, ripper_intern("<<"), $3);
2333  %*/
2334  }
2335  | arg tRSHFT arg
2336  {
2337  /*%%%*/
2338  $$ = call_bin_op($1, tRSHFT, $3);
2339  /*%
2340  $$ = dispatch3(binary, $1, ripper_intern(">>"), $3);
2341  %*/
2342  }
2343  | arg tANDOP arg
2344  {
2345  /*%%%*/
2346  $$ = logop(NODE_AND, $1, $3);
2347  /*%
2348  $$ = dispatch3(binary, $1, ripper_intern("&&"), $3);
2349  %*/
2350  }
2351  | arg tOROP arg
2352  {
2353  /*%%%*/
2354  $$ = logop(NODE_OR, $1, $3);
2355  /*%
2356  $$ = dispatch3(binary, $1, ripper_intern("||"), $3);
2357  %*/
2358  }
2359  | keyword_defined opt_nl {in_defined = 1;} arg
2360  {
2361  /*%%%*/
2362  in_defined = 0;
2363  $$ = NEW_DEFINED($4);
2364  /*%
2365  in_defined = 0;
2366  $$ = dispatch1(defined, $4);
2367  %*/
2368  }
2369  | arg '?' arg opt_nl ':' arg
2370  {
2371  /*%%%*/
2372  value_expr($1);
2373  $$ = NEW_IF(cond($1), $3, $6);
2374  fixpos($$, $1);
2375  /*%
2376  $$ = dispatch3(ifop, $1, $3, $6);
2377  %*/
2378  }
2379  | primary
2380  {
2381  $$ = $1;
2382  }
2383  ;
2384 
2385 arg_value : arg
2386  {
2387  /*%%%*/
2388  value_expr($1);
2389  $$ = $1;
2390  if (!$$) $$ = NEW_NIL();
2391  /*%
2392  $$ = $1;
2393  %*/
2394  }
2395  ;
2396 
2397 aref_args : none
2398  | args trailer
2399  {
2400  $$ = $1;
2401  }
2402  | args ',' assocs trailer
2403  {
2404  /*%%%*/
2405  $$ = arg_append($1, NEW_HASH($3));
2406  /*%
2407  $$ = arg_add_assocs($1, $3);
2408  %*/
2409  }
2410  | assocs trailer
2411  {
2412  /*%%%*/
2413  $$ = NEW_LIST(NEW_HASH($1));
2414  /*%
2415  $$ = arg_add_assocs(arg_new(), $1);
2416  %*/
2417  }
2418  ;
2419 
2420 paren_args : '(' opt_call_args rparen
2421  {
2422  /*%%%*/
2423  $$ = $2;
2424  /*%
2425  $$ = dispatch1(arg_paren, escape_Qundef($2));
2426  %*/
2427  }
2428  ;
2429 
2430 opt_paren_args : none
2431  | paren_args
2432  ;
2433 
2434 opt_call_args : none
2435  | call_args
2436  | args ','
2437  {
2438  $$ = $1;
2439  }
2440  | args ',' assocs ','
2441  {
2442  /*%%%*/
2443  $$ = arg_append($1, NEW_HASH($3));
2444  /*%
2445  $$ = arg_add_assocs($1, $3);
2446  %*/
2447  }
2448  | assocs ','
2449  {
2450  /*%%%*/
2451  $$ = NEW_LIST(NEW_HASH($1));
2452  /*%
2453  $$ = arg_add_assocs(arg_new(), $1);
2454  %*/
2455  }
2456  ;
2457 
2458 call_args : command
2459  {
2460  /*%%%*/
2461  value_expr($1);
2462  $$ = NEW_LIST($1);
2463  /*%
2464  $$ = arg_add(arg_new(), $1);
2465  %*/
2466  }
2467  | args opt_block_arg
2468  {
2469  /*%%%*/
2470  $$ = arg_blk_pass($1, $2);
2471  /*%
2472  $$ = arg_add_optblock($1, $2);
2473  %*/
2474  }
2475  | assocs opt_block_arg
2476  {
2477  /*%%%*/
2478  $$ = NEW_LIST(NEW_HASH($1));
2479  $$ = arg_blk_pass($$, $2);
2480  /*%
2481  $$ = arg_add_assocs(arg_new(), $1);
2482  $$ = arg_add_optblock($$, $2);
2483  %*/
2484  }
2485  | args ',' assocs opt_block_arg
2486  {
2487  /*%%%*/
2488  $$ = arg_append($1, NEW_HASH($3));
2489  $$ = arg_blk_pass($$, $4);
2490  /*%
2491  $$ = arg_add_optblock(arg_add_assocs($1, $3), $4);
2492  %*/
2493  }
2494  | block_arg
2495  /*%c%*/
2496  /*%c
2497  {
2498  $$ = arg_add_block(arg_new(), $1);
2499  }
2500  %*/
2501  ;
2502 
2503 command_args : {
2504  $<val>$ = cmdarg_stack;
2505  CMDARG_PUSH(1);
2506  }
2507  call_args
2508  {
2509  /* CMDARG_POP() */
2510  cmdarg_stack = $<val>1;
2511  $$ = $2;
2512  }
2513  ;
2514 
2515 block_arg : tAMPER arg_value
2516  {
2517  /*%%%*/
2518  $$ = NEW_BLOCK_PASS($2);
2519  /*%
2520  $$ = $2;
2521  %*/
2522  }
2523  ;
2524 
2525 opt_block_arg : ',' block_arg
2526  {
2527  $$ = $2;
2528  }
2529  | none
2530  {
2531  $$ = 0;
2532  }
2533  ;
2534 
2535 args : arg_value
2536  {
2537  /*%%%*/
2538  $$ = NEW_LIST($1);
2539  /*%
2540  $$ = arg_add(arg_new(), $1);
2541  %*/
2542  }
2543  | tSTAR arg_value
2544  {
2545  /*%%%*/
2546  $$ = NEW_SPLAT($2);
2547  /*%
2548  $$ = arg_add_star(arg_new(), $2);
2549  %*/
2550  }
2551  | args ',' arg_value
2552  {
2553  /*%%%*/
2554  NODE *n1;
2555  if ((n1 = splat_array($1)) != 0) {
2556  $$ = list_append(n1, $3);
2557  }
2558  else {
2559  $$ = arg_append($1, $3);
2560  }
2561  /*%
2562  $$ = arg_add($1, $3);
2563  %*/
2564  }
2565  | args ',' tSTAR arg_value
2566  {
2567  /*%%%*/
2568  NODE *n1;
2569  if ((nd_type($4) == NODE_ARRAY) && (n1 = splat_array($1)) != 0) {
2570  $$ = list_concat(n1, $4);
2571  }
2572  else {
2573  $$ = arg_concat($1, $4);
2574  }
2575  /*%
2576  $$ = arg_add_star($1, $4);
2577  %*/
2578  }
2579  ;
2580 
2581 mrhs : args ',' arg_value
2582  {
2583  /*%%%*/
2584  NODE *n1;
2585  if ((n1 = splat_array($1)) != 0) {
2586  $$ = list_append(n1, $3);
2587  }
2588  else {
2589  $$ = arg_append($1, $3);
2590  }
2591  /*%
2592  $$ = mrhs_add(args2mrhs($1), $3);
2593  %*/
2594  }
2595  | args ',' tSTAR arg_value
2596  {
2597  /*%%%*/
2598  NODE *n1;
2599  if (nd_type($4) == NODE_ARRAY &&
2600  (n1 = splat_array($1)) != 0) {
2601  $$ = list_concat(n1, $4);
2602  }
2603  else {
2604  $$ = arg_concat($1, $4);
2605  }
2606  /*%
2607  $$ = mrhs_add_star(args2mrhs($1), $4);
2608  %*/
2609  }
2610  | tSTAR arg_value
2611  {
2612  /*%%%*/
2613  $$ = NEW_SPLAT($2);
2614  /*%
2615  $$ = mrhs_add_star(mrhs_new(), $2);
2616  %*/
2617  }
2618  ;
2619 
2620 primary : literal
2621  | strings
2622  | xstring
2623  | regexp
2624  | words
2625  | qwords
2626  | var_ref
2627  | backref
2628  | tFID
2629  {
2630  /*%%%*/
2631  $$ = NEW_FCALL($1, 0);
2632  /*%
2633  $$ = method_arg(dispatch1(fcall, $1), arg_new());
2634  %*/
2635  }
2636  | k_begin
2637  {
2638  /*%%%*/
2639  $<num>$ = ruby_sourceline;
2640  /*%
2641  %*/
2642  }
2643  bodystmt
2644  k_end
2645  {
2646  /*%%%*/
2647  if ($3 == NULL) {
2648  $$ = NEW_NIL();
2649  }
2650  else {
2651  if (nd_type($3) == NODE_RESCUE ||
2652  nd_type($3) == NODE_ENSURE)
2653  nd_set_line($3, $<num>2);
2654  $$ = NEW_BEGIN($3);
2655  }
2656  nd_set_line($$, $<num>2);
2657  /*%
2658  $$ = dispatch1(begin, $3);
2659  %*/
2660  }
2661  | tLPAREN_ARG expr {lex_state = EXPR_ENDARG;} rparen
2662  {
2663  rb_warning0("(...) interpreted as grouped expression");
2664  /*%%%*/
2665  $$ = $2;
2666  /*%
2667  $$ = dispatch1(paren, $2);
2668  %*/
2669  }
2670  | tLPAREN compstmt ')'
2671  {
2672  /*%%%*/
2673  $$ = $2;
2674  /*%
2675  $$ = dispatch1(paren, $2);
2676  %*/
2677  }
2678  | primary_value tCOLON2 tCONSTANT
2679  {
2680  /*%%%*/
2681  $$ = NEW_COLON2($1, $3);
2682  /*%
2683  $$ = dispatch2(const_path_ref, $1, $3);
2684  %*/
2685  }
2686  | tCOLON3 tCONSTANT
2687  {
2688  /*%%%*/
2689  $$ = NEW_COLON3($2);
2690  /*%
2691  $$ = dispatch1(top_const_ref, $2);
2692  %*/
2693  }
2694  | tLBRACK aref_args ']'
2695  {
2696  /*%%%*/
2697  if ($2 == 0) {
2698  $$ = NEW_ZARRAY(); /* zero length array*/
2699  }
2700  else {
2701  $$ = $2;
2702  }
2703  /*%
2704  $$ = dispatch1(array, escape_Qundef($2));
2705  %*/
2706  }
2707  | tLBRACE assoc_list '}'
2708  {
2709  /*%%%*/
2710  $$ = NEW_HASH($2);
2711  /*%
2712  $$ = dispatch1(hash, escape_Qundef($2));
2713  %*/
2714  }
2715  | keyword_return
2716  {
2717  /*%%%*/
2718  $$ = NEW_RETURN(0);
2719  /*%
2720  $$ = dispatch0(return0);
2721  %*/
2722  }
2723  | keyword_yield '(' call_args rparen
2724  {
2725  /*%%%*/
2726  $$ = new_yield($3);
2727  /*%
2728  $$ = dispatch1(yield, dispatch1(paren, $3));
2729  %*/
2730  }
2731  | keyword_yield '(' rparen
2732  {
2733  /*%%%*/
2734  $$ = NEW_YIELD(0, Qfalse);
2735  /*%
2736  $$ = dispatch1(yield, dispatch1(paren, arg_new()));
2737  %*/
2738  }
2739  | keyword_yield
2740  {
2741  /*%%%*/
2742  $$ = NEW_YIELD(0, Qfalse);
2743  /*%
2744  $$ = dispatch0(yield0);
2745  %*/
2746  }
2747  | keyword_defined opt_nl '(' {in_defined = 1;} expr rparen
2748  {
2749  /*%%%*/
2750  in_defined = 0;
2751  $$ = NEW_DEFINED($5);
2752  /*%
2753  in_defined = 0;
2754  $$ = dispatch1(defined, $5);
2755  %*/
2756  }
2757  | keyword_not '(' expr rparen
2758  {
2759  /*%%%*/
2760  $$ = call_uni_op(cond($3), '!');
2761  /*%
2762  $$ = dispatch2(unary, ripper_intern("not"), $3);
2763  %*/
2764  }
2765  | keyword_not '(' rparen
2766  {
2767  /*%%%*/
2768  $$ = call_uni_op(cond(NEW_NIL()), '!');
2769  /*%
2770  $$ = dispatch2(unary, ripper_intern("not"), Qnil);
2771  %*/
2772  }
2773  | operation brace_block
2774  {
2775  /*%%%*/
2776  $2->nd_iter = NEW_FCALL($1, 0);
2777  $$ = $2;
2778  fixpos($2->nd_iter, $2);
2779  /*%
2780  $$ = method_arg(dispatch1(fcall, $1), arg_new());
2781  $$ = method_add_block($$, $2);
2782  %*/
2783  }
2784  | method_call
2785  | method_call brace_block
2786  {
2787  /*%%%*/
2788  block_dup_check($1->nd_args, $2);
2789  $2->nd_iter = $1;
2790  $$ = $2;
2791  fixpos($$, $1);
2792  /*%
2793  $$ = method_add_block($1, $2);
2794  %*/
2795  }
2796  | tLAMBDA lambda
2797  {
2798  $$ = $2;
2799  }
2800  | k_if expr_value then
2801  compstmt
2802  if_tail
2803  k_end
2804  {
2805  /*%%%*/
2806  $$ = NEW_IF(cond($2), $4, $5);
2807  fixpos($$, $2);
2808  /*%
2809  $$ = dispatch3(if, $2, $4, escape_Qundef($5));
2810  %*/
2811  }
2812  | k_unless expr_value then
2813  compstmt
2814  opt_else
2815  k_end
2816  {
2817  /*%%%*/
2818  $$ = NEW_UNLESS(cond($2), $4, $5);
2819  fixpos($$, $2);
2820  /*%
2821  $$ = dispatch3(unless, $2, $4, escape_Qundef($5));
2822  %*/
2823  }
2824  | k_while {COND_PUSH(1);} expr_value do {COND_POP();}
2825  compstmt
2826  k_end
2827  {
2828  /*%%%*/
2829  $$ = NEW_WHILE(cond($3), $6, 1);
2830  fixpos($$, $3);
2831  /*%
2832  $$ = dispatch2(while, $3, $6);
2833  %*/
2834  }
2835  | k_until {COND_PUSH(1);} expr_value do {COND_POP();}
2836  compstmt
2837  k_end
2838  {
2839  /*%%%*/
2840  $$ = NEW_UNTIL(cond($3), $6, 1);
2841  fixpos($$, $3);
2842  /*%
2843  $$ = dispatch2(until, $3, $6);
2844  %*/
2845  }
2846  | k_case expr_value opt_terms
2847  case_body
2848  k_end
2849  {
2850  /*%%%*/
2851  $$ = NEW_CASE($2, $4);
2852  fixpos($$, $2);
2853  /*%
2854  $$ = dispatch2(case, $2, $4);
2855  %*/
2856  }
2857  | k_case opt_terms case_body k_end
2858  {
2859  /*%%%*/
2860  $$ = NEW_CASE(0, $3);
2861  /*%
2862  $$ = dispatch2(case, Qnil, $3);
2863  %*/
2864  }
2865  | k_for for_var keyword_in
2866  {COND_PUSH(1);}
2867  expr_value do
2868  {COND_POP();}
2869  compstmt
2870  k_end
2871  {
2872  /*%%%*/
2873  /*
2874  * for a, b, c in e
2875  * #=>
2876  * e.each{|*x| a, b, c = x
2877  *
2878  * for a in e
2879  * #=>
2880  * e.each{|x| a, = x}
2881  */
2882  ID id = internal_id();
2883  ID *tbl = ALLOC_N(ID, 2);
2884  NODE *m = NEW_ARGS_AUX(0, 0);
2885  NODE *args, *scope;
2886 
2887  if (nd_type($2) == NODE_MASGN) {
2888  /* if args.length == 1 && args[0].kind_of?(Array)
2889  * args = args[0]
2890  * end
2891  */
2892  NODE *one = NEW_LIST(NEW_LIT(INT2FIX(1)));
2893  NODE *zero = NEW_LIST(NEW_LIT(INT2FIX(0)));
2894  m->nd_next = block_append(
2895  NEW_IF(
2897  NEW_CALL(NEW_CALL(NEW_DVAR(id), rb_intern("length"), 0),
2898  rb_intern("=="), one),
2899  NEW_CALL(NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero),
2900  rb_intern("kind_of?"), NEW_LIST(NEW_LIT(rb_cArray))),
2901  0),
2902  NEW_DASGN_CURR(id,
2903  NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero)),
2904  0),
2905  node_assign($2, NEW_DVAR(id)));
2906 
2907  args = new_args(m, 0, id, 0, 0);
2908  }
2909  else {
2910  if (nd_type($2) == NODE_LASGN ||
2911  nd_type($2) == NODE_DASGN ||
2912  nd_type($2) == NODE_DASGN_CURR) {
2913  $2->nd_value = NEW_DVAR(id);
2914  m->nd_plen = 1;
2915  m->nd_next = $2;
2916  args = new_args(m, 0, 0, 0, 0);
2917  }
2918  else {
2919  m->nd_next = node_assign(NEW_MASGN(NEW_LIST($2), 0), NEW_DVAR(id));
2920  args = new_args(m, 0, id, 0, 0);
2921  }
2922  }
2923  scope = NEW_NODE(NODE_SCOPE, tbl, $8, args);
2924  tbl[0] = 1; tbl[1] = id;
2925  $$ = NEW_FOR(0, $5, scope);
2926  fixpos($$, $2);
2927  /*%
2928  $$ = dispatch3(for, $2, $5, $8);
2929  %*/
2930  }
2931  | k_class cpath superclass
2932  {
2933  if (in_def || in_single)
2934  yyerror("class definition in method body");
2935  local_push(0);
2936  /*%%%*/
2937  $<num>$ = ruby_sourceline;
2938  /*%
2939  %*/
2940  }
2941  bodystmt
2942  k_end
2943  {
2944  /*%%%*/
2945  $$ = NEW_CLASS($2, $5, $3);
2946  nd_set_line($$, $<num>4);
2947  /*%
2948  $$ = dispatch3(class, $2, $3, $5);
2949  %*/
2950  local_pop();
2951  }
2952  | k_class tLSHFT expr
2953  {
2954  $<num>$ = in_def;
2955  in_def = 0;
2956  }
2957  term
2958  {
2959  $<num>$ = in_single;
2960  in_single = 0;
2961  local_push(0);
2962  }
2963  bodystmt
2964  k_end
2965  {
2966  /*%%%*/
2967  $$ = NEW_SCLASS($3, $7);
2968  fixpos($$, $3);
2969  /*%
2970  $$ = dispatch2(sclass, $3, $7);
2971  %*/
2972  local_pop();
2973  in_def = $<num>4;
2974  in_single = $<num>6;
2975  }
2976  | k_module cpath
2977  {
2978  if (in_def || in_single)
2979  yyerror("module definition in method body");
2980  local_push(0);
2981  /*%%%*/
2982  $<num>$ = ruby_sourceline;
2983  /*%
2984  %*/
2985  }
2986  bodystmt
2987  k_end
2988  {
2989  /*%%%*/
2990  $$ = NEW_MODULE($2, $4);
2991  nd_set_line($$, $<num>3);
2992  /*%
2993  $$ = dispatch2(module, $2, $4);
2994  %*/
2995  local_pop();
2996  }
2997  | k_def fname
2998  {
2999  $<id>$ = cur_mid;
3000  cur_mid = $2;
3001  in_def++;
3002  local_push(0);
3003  }
3004  f_arglist
3005  bodystmt
3006  k_end
3007  {
3008  /*%%%*/
3009  NODE *body = remove_begin($5);
3010  reduce_nodes(&body);
3011  $$ = NEW_DEFN($2, $4, body, NOEX_PRIVATE);
3012  nd_set_line($$, $<num>1);
3013  /*%
3014  $$ = dispatch3(def, $2, $4, $5);
3015  %*/
3016  local_pop();
3017  in_def--;
3018  cur_mid = $<id>3;
3019  }
3020  | k_def singleton dot_or_colon {lex_state = EXPR_FNAME;} fname
3021  {
3022  in_single++;
3023  lex_state = EXPR_ENDFN; /* force for args */
3024  local_push(0);
3025  }
3026  f_arglist
3027  bodystmt
3028  k_end
3029  {
3030  /*%%%*/
3031  NODE *body = remove_begin($8);
3032  reduce_nodes(&body);
3033  $$ = NEW_DEFS($2, $5, $7, body);
3034  nd_set_line($$, $<num>1);
3035  /*%
3036  $$ = dispatch5(defs, $2, $3, $5, $7, $8);
3037  %*/
3038  local_pop();
3039  in_single--;
3040  }
3041  | keyword_break
3042  {
3043  /*%%%*/
3044  $$ = NEW_BREAK(0);
3045  /*%
3046  $$ = dispatch1(break, arg_new());
3047  %*/
3048  }
3049  | keyword_next
3050  {
3051  /*%%%*/
3052  $$ = NEW_NEXT(0);
3053  /*%
3054  $$ = dispatch1(next, arg_new());
3055  %*/
3056  }
3057  | keyword_redo
3058  {
3059  /*%%%*/
3060  $$ = NEW_REDO();
3061  /*%
3062  $$ = dispatch0(redo);
3063  %*/
3064  }
3065  | keyword_retry
3066  {
3067  /*%%%*/
3068  $$ = NEW_RETRY();
3069  /*%
3070  $$ = dispatch0(retry);
3071  %*/
3072  }
3073  ;
3074 
3075 primary_value : primary
3076  {
3077  /*%%%*/
3078  value_expr($1);
3079  $$ = $1;
3080  if (!$$) $$ = NEW_NIL();
3081  /*%
3082  $$ = $1;
3083  %*/
3084  }
3085  ;
3086 
3087 k_begin : keyword_begin
3088  {
3089  token_info_push("begin");
3090  }
3091  ;
3092 
3093 k_if : keyword_if
3094  {
3095  token_info_push("if");
3096  }
3097  ;
3098 
3099 k_unless : keyword_unless
3100  {
3101  token_info_push("unless");
3102  }
3103  ;
3104 
3105 k_while : keyword_while
3106  {
3107  token_info_push("while");
3108  }
3109  ;
3110 
3111 k_until : keyword_until
3112  {
3113  token_info_push("until");
3114  }
3115  ;
3116 
3117 k_case : keyword_case
3118  {
3119  token_info_push("case");
3120  }
3121  ;
3122 
3123 k_for : keyword_for
3124  {
3125  token_info_push("for");
3126  }
3127  ;
3128 
3129 k_class : keyword_class
3130  {
3131  token_info_push("class");
3132  }
3133  ;
3134 
3135 k_module : keyword_module
3136  {
3137  token_info_push("module");
3138  }
3139  ;
3140 
3141 k_def : keyword_def
3142  {
3143  token_info_push("def");
3144  /*%%%*/
3145  $<num>$ = ruby_sourceline;
3146  /*%
3147  %*/
3148  }
3149  ;
3150 
3151 k_end : keyword_end
3152  {
3153  token_info_pop("end");
3154  }
3155  ;
3156 
3157 then : term
3158  /*%c%*/
3159  /*%c
3160  { $$ = Qnil; }
3161  %*/
3162  | keyword_then
3163  | term keyword_then
3164  /*%c%*/
3165  /*%c
3166  { $$ = $2; }
3167  %*/
3168  ;
3169 
3170 do : term
3171  /*%c%*/
3172  /*%c
3173  { $$ = Qnil; }
3174  %*/
3175  | keyword_do_cond
3176  ;
3177 
3178 if_tail : opt_else
3179  | keyword_elsif expr_value then
3180  compstmt
3181  if_tail
3182  {
3183  /*%%%*/
3184  $$ = NEW_IF(cond($2), $4, $5);
3185  fixpos($$, $2);
3186  /*%
3187  $$ = dispatch3(elsif, $2, $4, escape_Qundef($5));
3188  %*/
3189  }
3190  ;
3191 
3192 opt_else : none
3194  {
3195  /*%%%*/
3196  $$ = $2;
3197  /*%
3198  $$ = dispatch1(else, $2);
3199  %*/
3200  }
3201  ;
3202 
3203 for_var : lhs
3204  | mlhs
3205  ;
3206 
3207 f_marg : f_norm_arg
3208  {
3209  $$ = assignable($1, 0);
3210  /*%%%*/
3211  /*%
3212  $$ = dispatch1(mlhs_paren, $$);
3213  %*/
3214  }
3215  | tLPAREN f_margs rparen
3216  {
3217  /*%%%*/
3218  $$ = $2;
3219  /*%
3220  $$ = dispatch1(mlhs_paren, $2);
3221  %*/
3222  }
3223  ;
3224 
3225 f_marg_list : f_marg
3226  {
3227  /*%%%*/
3228  $$ = NEW_LIST($1);
3229  /*%
3230  $$ = mlhs_add(mlhs_new(), $1);
3231  %*/
3232  }
3233  | f_marg_list ',' f_marg
3234  {
3235  /*%%%*/
3236  $$ = list_append($1, $3);
3237  /*%
3238  $$ = mlhs_add($1, $3);
3239  %*/
3240  }
3241  ;
3242 
3243 f_margs : f_marg_list
3244  {
3245  /*%%%*/
3246  $$ = NEW_MASGN($1, 0);
3247  /*%
3248  $$ = $1;
3249  %*/
3250  }
3251  | f_marg_list ',' tSTAR f_norm_arg
3252  {
3253  $$ = assignable($4, 0);
3254  /*%%%*/
3255  $$ = NEW_MASGN($1, $$);
3256  /*%
3257  $$ = mlhs_add_star($1, $$);
3258  %*/
3259  }
3260  | f_marg_list ',' tSTAR f_norm_arg ',' f_marg_list
3261  {
3262  $$ = assignable($4, 0);
3263  /*%%%*/
3264  $$ = NEW_MASGN($1, NEW_POSTARG($$, $6));
3265  /*%
3266  $$ = mlhs_add_star($1, $$);
3267  %*/
3268  }
3269  | f_marg_list ',' tSTAR
3270  {
3271  /*%%%*/
3272  $$ = NEW_MASGN($1, -1);
3273  /*%
3274  $$ = mlhs_add_star($1, Qnil);
3275  %*/
3276  }
3277  | f_marg_list ',' tSTAR ',' f_marg_list
3278  {
3279  /*%%%*/
3280  $$ = NEW_MASGN($1, NEW_POSTARG(-1, $5));
3281  /*%
3282  $$ = mlhs_add_star($1, $5);
3283  %*/
3284  }
3285  | tSTAR f_norm_arg
3286  {
3287  $$ = assignable($2, 0);
3288  /*%%%*/
3289  $$ = NEW_MASGN(0, $$);
3290  /*%
3291  $$ = mlhs_add_star(mlhs_new(), $$);
3292  %*/
3293  }
3294  | tSTAR f_norm_arg ',' f_marg_list
3295  {
3296  $$ = assignable($2, 0);
3297  /*%%%*/
3298  $$ = NEW_MASGN(0, NEW_POSTARG($$, $4));
3299  /*%
3300  #if 0
3301  TODO: Check me
3302  #endif
3303  $$ = mlhs_add_star($$, $4);
3304  %*/
3305  }
3306  | tSTAR
3307  {
3308  /*%%%*/
3309  $$ = NEW_MASGN(0, -1);
3310  /*%
3311  $$ = mlhs_add_star(mlhs_new(), Qnil);
3312  %*/
3313  }
3314  | tSTAR ',' f_marg_list
3315  {
3316  /*%%%*/
3317  $$ = NEW_MASGN(0, NEW_POSTARG(-1, $3));
3318  /*%
3319  $$ = mlhs_add_star(mlhs_new(), Qnil);
3320  %*/
3321  }
3322  ;
3323 
3324 block_param : f_arg ',' f_block_optarg ',' f_rest_arg opt_f_block_arg
3325  {
3326  /*%%%*/
3327  $$ = new_args($1, $3, $5, 0, $6);
3328  /*%
3329  $$ = params_new($1, $3, $5, Qnil, escape_Qundef($6));
3330  %*/
3331  }
3332  | f_arg ',' f_block_optarg ',' f_rest_arg ',' f_arg opt_f_block_arg
3333  {
3334  /*%%%*/
3335  $$ = new_args($1, $3, $5, $7, $8);
3336  /*%
3337  $$ = params_new($1, $3, $5, $7, escape_Qundef($8));
3338  %*/
3339  }
3340  | f_arg ',' f_block_optarg opt_f_block_arg
3341  {
3342  /*%%%*/
3343  $$ = new_args($1, $3, 0, 0, $4);
3344  /*%
3345  $$ = params_new($1, $3, Qnil, Qnil, escape_Qundef($4));
3346  %*/
3347  }
3348  | f_arg ',' f_block_optarg ',' f_arg opt_f_block_arg
3349  {
3350  /*%%%*/
3351  $$ = new_args($1, $3, 0, $5, $6);
3352  /*%
3353  $$ = params_new($1, $3, Qnil, $5, escape_Qundef($6));
3354  %*/
3355  }
3356  | f_arg ',' f_rest_arg opt_f_block_arg
3357  {
3358  /*%%%*/
3359  $$ = new_args($1, 0, $3, 0, $4);
3360  /*%
3361  $$ = params_new($1, Qnil, $3, Qnil, escape_Qundef($4));
3362  %*/
3363  }
3364  | f_arg ','
3365  {
3366  /*%%%*/
3367  $$ = new_args($1, 0, 1, 0, 0);
3368  /*%
3369  $$ = params_new($1, Qnil, Qnil, Qnil, Qnil);
3370  dispatch1(excessed_comma, $$);
3371  %*/
3372  }
3373  | f_arg ',' f_rest_arg ',' f_arg opt_f_block_arg
3374  {
3375  /*%%%*/
3376  $$ = new_args($1, 0, $3, $5, $6);
3377  /*%
3378  $$ = params_new($1, Qnil, $3, $5, escape_Qundef($6));
3379  %*/
3380  }
3381  | f_arg opt_f_block_arg
3382  {
3383  /*%%%*/
3384  $$ = new_args($1, 0, 0, 0, $2);
3385  /*%
3386  $$ = params_new($1, Qnil,Qnil, Qnil, escape_Qundef($2));
3387  %*/
3388  }
3389  | f_block_optarg ',' f_rest_arg opt_f_block_arg
3390  {
3391  /*%%%*/
3392  $$ = new_args(0, $1, $3, 0, $4);
3393  /*%
3394  $$ = params_new(Qnil, $1, $3, Qnil, escape_Qundef($4));
3395  %*/
3396  }
3397  | f_block_optarg ',' f_rest_arg ',' f_arg opt_f_block_arg
3398  {
3399  /*%%%*/
3400  $$ = new_args(0, $1, $3, $5, $6);
3401  /*%
3402  $$ = params_new(Qnil, $1, $3, $5, escape_Qundef($6));
3403  %*/
3404  }
3405  | f_block_optarg opt_f_block_arg
3406  {
3407  /*%%%*/
3408  $$ = new_args(0, $1, 0, 0, $2);
3409  /*%
3410  $$ = params_new(Qnil, $1, Qnil, Qnil,escape_Qundef($2));
3411  %*/
3412  }
3413  | f_block_optarg ',' f_arg opt_f_block_arg
3414  {
3415  /*%%%*/
3416  $$ = new_args(0, $1, 0, $3, $4);
3417  /*%
3418  $$ = params_new(Qnil, $1, Qnil, $3, escape_Qundef($4));
3419  %*/
3420  }
3421  | f_rest_arg opt_f_block_arg
3422  {
3423  /*%%%*/
3424  $$ = new_args(0, 0, $1, 0, $2);
3425  /*%
3426  $$ = params_new(Qnil, Qnil, $1, Qnil, escape_Qundef($2));
3427  %*/
3428  }
3429  | f_rest_arg ',' f_arg opt_f_block_arg
3430  {
3431  /*%%%*/
3432  $$ = new_args(0, 0, $1, $3, $4);
3433  /*%
3434  $$ = params_new(Qnil, Qnil, $1, $3, escape_Qundef($4));
3435  %*/
3436  }
3437  | f_block_arg
3438  {
3439  /*%%%*/
3440  $$ = new_args(0, 0, 0, 0, $1);
3441  /*%
3442  $$ = params_new(Qnil, Qnil, Qnil, Qnil, $1);
3443  %*/
3444  }
3445  ;
3446 
3447 opt_block_param : none
3448  | block_param_def
3449  {
3450  command_start = TRUE;
3451  }
3452  ;
3453 
3454 block_param_def : '|' opt_bv_decl '|'
3455  {
3456  /*%%%*/
3457  $$ = 0;
3458  /*%
3459  $$ = blockvar_new(params_new(Qnil,Qnil,Qnil,Qnil,Qnil),
3460  escape_Qundef($2));
3461  %*/
3462  }
3463  | tOROP
3464  {
3465  /*%%%*/
3466  $$ = 0;
3467  /*%
3468  $$ = blockvar_new(params_new(Qnil,Qnil,Qnil,Qnil,Qnil),
3469  Qnil);
3470  %*/
3471  }
3472  | '|' block_param opt_bv_decl '|'
3473  {
3474  /*%%%*/
3475  $$ = $2;
3476  /*%
3477  $$ = blockvar_new(escape_Qundef($2), escape_Qundef($3));
3478  %*/
3479  }
3480  ;
3481 
3482 
3483 opt_bv_decl : none
3484  | ';' bv_decls
3485  {
3486  /*%%%*/
3487  $$ = 0;
3488  /*%
3489  $$ = $2;
3490  %*/
3491  }
3492  ;
3493 
3494 bv_decls : bvar
3495  /*%c%*/
3496  /*%c
3497  {
3498  $$ = rb_ary_new3(1, $1);
3499  }
3500  %*/
3501  | bv_decls ',' bvar
3502  /*%c%*/
3503  /*%c
3504  {
3505  rb_ary_push($$, $3);
3506  }
3507  %*/
3508  ;
3509 
3510 bvar : tIDENTIFIER
3511  {
3512  new_bv(get_id($1));
3513  /*%%%*/
3514  /*%
3515  $$ = get_value($1);
3516  %*/
3517  }
3518  | f_bad_arg
3519  {
3520  $$ = 0;
3521  }
3522  ;
3523 
3524 lambda : {
3525  $<vars>$ = dyna_push();
3526  }
3527  {
3528  $<num>$ = lpar_beg;
3529  lpar_beg = ++paren_nest;
3530  }
3531  f_larglist
3532  lambda_body
3533  {
3534  lpar_beg = $<num>2;
3535  /*%%%*/
3536  $$ = $3;
3537  $$->nd_body = NEW_SCOPE($3->nd_head, $4);
3538  /*%
3539  $$ = dispatch2(lambda, $3, $4);
3540  %*/
3541  dyna_pop($<vars>1);
3542  }
3543  ;
3544 
3545 f_larglist : '(' f_args opt_bv_decl rparen
3546  {
3547  /*%%%*/
3548  $$ = NEW_LAMBDA($2);
3549  /*%
3550  $$ = dispatch1(paren, $2);
3551  %*/
3552  }
3553  | f_args
3554  {
3555  /*%%%*/
3556  $$ = NEW_LAMBDA($1);
3557  /*%
3558  $$ = $1;
3559  %*/
3560  }
3561  ;
3562 
3563 lambda_body : tLAMBEG compstmt '}'
3564  {
3565  $$ = $2;
3566  }
3568  {
3569  $$ = $2;
3570  }
3571  ;
3572 
3573 do_block : keyword_do_block
3574  {
3575  $<vars>1 = dyna_push();
3576  /*%%%*/
3577  $<num>$ = ruby_sourceline;
3578  /*% %*/
3579  }
3580  opt_block_param
3581  compstmt
3582  keyword_end
3583  {
3584  /*%%%*/
3585  $$ = NEW_ITER($3,$4);
3586  nd_set_line($$, $<num>2);
3587  /*%
3588  $$ = dispatch2(do_block, escape_Qundef($3), $4);
3589  %*/
3590  dyna_pop($<vars>1);
3591  }
3592  ;
3593 
3594 block_call : command do_block
3595  {
3596  /*%%%*/
3597  if (nd_type($1) == NODE_YIELD) {
3598  compile_error(PARSER_ARG "block given to yield");
3599  }
3600  else {
3601  block_dup_check($1->nd_args, $2);
3602  }
3603  $2->nd_iter = $1;
3604  $$ = $2;
3605  fixpos($$, $1);
3606  /*%
3607  $$ = method_add_block($1, $2);
3608  %*/
3609  }
3610  | block_call '.' operation2 opt_paren_args
3611  {
3612  /*%%%*/
3613  $$ = NEW_CALL($1, $3, $4);
3614  /*%
3615  $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
3616  $$ = method_optarg($$, $4);
3617  %*/
3618  }
3619  | block_call tCOLON2 operation2 opt_paren_args
3620  {
3621  /*%%%*/
3622  $$ = NEW_CALL($1, $3, $4);
3623  /*%
3624  $$ = dispatch3(call, $1, ripper_intern("::"), $3);
3625  $$ = method_optarg($$, $4);
3626  %*/
3627  }
3628  ;
3629 
3630 method_call : operation paren_args
3631  {
3632  /*%%%*/
3633  $$ = NEW_FCALL($1, $2);
3634  fixpos($$, $2);
3635  /*%
3636  $$ = method_arg(dispatch1(fcall, $1), $2);
3637  %*/
3638  }
3639  | primary_value '.' operation2 opt_paren_args
3640  {
3641  /*%%%*/
3642  $$ = NEW_CALL($1, $3, $4);
3643  fixpos($$, $1);
3644  /*%
3645  $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
3646  $$ = method_optarg($$, $4);
3647  %*/
3648  }
3649  | primary_value tCOLON2 operation2 paren_args
3650  {
3651  /*%%%*/
3652  $$ = NEW_CALL($1, $3, $4);
3653  fixpos($$, $1);
3654  /*%
3655  $$ = dispatch3(call, $1, ripper_id2sym('.'), $3);
3656  $$ = method_optarg($$, $4);
3657  %*/
3658  }
3659  | primary_value tCOLON2 operation3
3660  {
3661  /*%%%*/
3662  $$ = NEW_CALL($1, $3, 0);
3663  /*%
3664  $$ = dispatch3(call, $1, ripper_intern("::"), $3);
3665  %*/
3666  }
3667  | primary_value '.' paren_args
3668  {
3669  /*%%%*/
3670  $$ = NEW_CALL($1, rb_intern("call"), $3);
3671  fixpos($$, $1);
3672  /*%
3673  $$ = dispatch3(call, $1, ripper_id2sym('.'),
3674  ripper_intern("call"));
3675  $$ = method_optarg($$, $3);
3676  %*/
3677  }
3678  | primary_value tCOLON2 paren_args
3679  {
3680  /*%%%*/
3681  $$ = NEW_CALL($1, rb_intern("call"), $3);
3682  fixpos($$, $1);
3683  /*%
3684  $$ = dispatch3(call, $1, ripper_intern("::"),
3685  ripper_intern("call"));
3686  $$ = method_optarg($$, $3);
3687  %*/
3688  }
3689  | keyword_super paren_args
3690  {
3691  /*%%%*/
3692  $$ = NEW_SUPER($2);
3693  /*%
3694  $$ = dispatch1(super, $2);
3695  %*/
3696  }
3697  | keyword_super
3698  {
3699  /*%%%*/
3700  $$ = NEW_ZSUPER();
3701  /*%
3702  $$ = dispatch0(zsuper);
3703  %*/
3704  }
3705  | primary_value '[' opt_call_args rbracket
3706  {
3707  /*%%%*/
3708  if ($1 && nd_type($1) == NODE_SELF)
3709  $$ = NEW_FCALL(tAREF, $3);
3710  else
3711  $$ = NEW_CALL($1, tAREF, $3);
3712  fixpos($$, $1);
3713  /*%
3714  $$ = dispatch2(aref, $1, escape_Qundef($3));
3715  %*/
3716  }
3717  ;
3718 
3719 brace_block : '{'
3720  {
3721  $<vars>1 = dyna_push();
3722  /*%%%*/
3723  $<num>$ = ruby_sourceline;
3724  /*%
3725  %*/
3726  }
3727  opt_block_param
3728  compstmt '}'
3729  {
3730  /*%%%*/
3731  $$ = NEW_ITER($3,$4);
3732  nd_set_line($$, $<num>2);
3733  /*%
3734  $$ = dispatch2(brace_block, escape_Qundef($3), $4);
3735  %*/
3736  dyna_pop($<vars>1);
3737  }
3738  | keyword_do
3739  {
3740  $<vars>1 = dyna_push();
3741  /*%%%*/
3742  $<num>$ = ruby_sourceline;
3743  /*%
3744  %*/
3745  }
3746  opt_block_param
3748  {
3749  /*%%%*/
3750  $$ = NEW_ITER($3,$4);
3751  nd_set_line($$, $<num>2);
3752  /*%
3753  $$ = dispatch2(do_block, escape_Qundef($3), $4);
3754  %*/
3755  dyna_pop($<vars>1);
3756  }
3757  ;
3758 
3759 case_body : keyword_when args then
3760  compstmt
3761  cases
3762  {
3763  /*%%%*/
3764  $$ = NEW_WHEN($2, $4, $5);
3765  /*%
3766  $$ = dispatch3(when, $2, $4, escape_Qundef($5));
3767  %*/
3768  }
3769  ;
3770 
3771 cases : opt_else
3772  | case_body
3773  ;
3774 
3775 opt_rescue : keyword_rescue exc_list exc_var then
3776  compstmt
3777  opt_rescue
3778  {
3779  /*%%%*/
3780  if ($3) {
3781  $3 = node_assign($3, NEW_ERRINFO());
3782  $5 = block_append($3, $5);
3783  }
3784  $$ = NEW_RESBODY($2, $5, $6);
3785  fixpos($$, $2?$2:$5);
3786  /*%
3787  $$ = dispatch4(rescue,
3788  escape_Qundef($2),
3789  escape_Qundef($3),
3790  escape_Qundef($5),
3791  escape_Qundef($6));
3792  %*/
3793  }
3794  | none
3795  ;
3796 
3797 exc_list : arg_value
3798  {
3799  /*%%%*/
3800  $$ = NEW_LIST($1);
3801  /*%
3802  $$ = rb_ary_new3(1, $1);
3803  %*/
3804  }
3805  | mrhs
3806  {
3807  /*%%%*/
3808  if (!($$ = splat_array($1))) $$ = $1;
3809  /*%
3810  $$ = $1;
3811  %*/
3812  }
3813  | none
3814  ;
3815 
3816 exc_var : tASSOC lhs
3817  {
3818  $$ = $2;
3819  }
3820  | none
3821  ;
3822 
3823 opt_ensure : keyword_ensure compstmt
3824  {
3825  /*%%%*/
3826  $$ = $2;
3827  /*%
3828  $$ = dispatch1(ensure, $2);
3829  %*/
3830  }
3831  | none
3832  ;
3833 
3834 literal : numeric
3835  | symbol
3836  {
3837  /*%%%*/
3838  $$ = NEW_LIT(ID2SYM($1));
3839  /*%
3840  $$ = dispatch1(symbol_literal, $1);
3841  %*/
3842  }
3843  | dsym
3844  ;
3845 
3846 strings : string
3847  {
3848  /*%%%*/
3849  NODE *node = $1;
3850  if (!node) {
3851  node = NEW_STR(STR_NEW0());
3852  }
3853  else {
3854  node = evstr2dstr(node);
3855  }
3856  $$ = node;
3857  /*%
3858  $$ = $1;
3859  %*/
3860  }
3861  ;
3862 
3863 string : tCHAR
3864  | string1
3865  | string string1
3866  {
3867  /*%%%*/
3868  $$ = literal_concat($1, $2);
3869  /*%
3870  $$ = dispatch2(string_concat, $1, $2);
3871  %*/
3872  }
3873  ;
3874 
3875 string1 : tSTRING_BEG string_contents tSTRING_END
3876  {
3877  /*%%%*/
3878  $$ = $2;
3879  /*%
3880  $$ = dispatch1(string_literal, $2);
3881  %*/
3882  }
3883  ;
3884 
3885 xstring : tXSTRING_BEG xstring_contents tSTRING_END
3886  {
3887  /*%%%*/
3888  NODE *node = $2;
3889  if (!node) {
3890  node = NEW_XSTR(STR_NEW0());
3891  }
3892  else {
3893  switch (nd_type(node)) {
3894  case NODE_STR:
3895  nd_set_type(node, NODE_XSTR);
3896  break;
3897  case NODE_DSTR:
3898  nd_set_type(node, NODE_DXSTR);
3899  break;
3900  default:
3901  node = NEW_NODE(NODE_DXSTR, Qnil, 1, NEW_LIST(node));
3902  break;
3903  }
3904  }
3905  $$ = node;
3906  /*%
3907  $$ = dispatch1(xstring_literal, $2);
3908  %*/
3909  }
3910  ;
3911 
3912 regexp : tREGEXP_BEG regexp_contents tREGEXP_END
3913  {
3914  /*%%%*/
3915  int options = $3;
3916  NODE *node = $2;
3917  NODE *list, *prev;
3918  if (!node) {
3919  node = NEW_LIT(reg_compile(STR_NEW0(), options));
3920  }
3921  else switch (nd_type(node)) {
3922  case NODE_STR:
3923  {
3924  VALUE src = node->nd_lit;
3925  nd_set_type(node, NODE_LIT);
3926  node->nd_lit = reg_compile(src, options);
3927  }
3928  break;
3929  default:
3930  node = NEW_NODE(NODE_DSTR, STR_NEW0(), 1, NEW_LIST(node));
3931  case NODE_DSTR:
3932  if (options & RE_OPTION_ONCE) {
3934  }
3935  else {
3936  nd_set_type(node, NODE_DREGX);
3937  }
3938  node->nd_cflag = options & RE_OPTION_MASK;
3939  if (!NIL_P(node->nd_lit)) reg_fragment_check(node->nd_lit, options);
3940  for (list = (prev = node)->nd_next; list; list = list->nd_next) {
3941  if (nd_type(list->nd_head) == NODE_STR) {
3942  VALUE tail = list->nd_head->nd_lit;
3943  if (reg_fragment_check(tail, options) && prev && !NIL_P(prev->nd_lit)) {
3944  VALUE lit = prev == node ? prev->nd_lit : prev->nd_head->nd_lit;
3945  if (!literal_concat0(parser, lit, tail)) {
3946  node = 0;
3947  break;
3948  }
3949  rb_str_resize(tail, 0);
3950  prev->nd_next = list->nd_next;
3951  rb_gc_force_recycle((VALUE)list->nd_head);
3952  rb_gc_force_recycle((VALUE)list);
3953  list = prev;
3954  }
3955  else {
3956  prev = list;
3957  }
3958  }
3959  else {
3960  prev = 0;
3961  }
3962  }
3963  if (!node->nd_next) {
3964  VALUE src = node->nd_lit;
3965  nd_set_type(node, NODE_LIT);
3966  node->nd_lit = reg_compile(src, options);
3967  }
3968  break;
3969  }
3970  $$ = node;
3971  /*%
3972  $$ = dispatch2(regexp_literal, $2, $3);
3973  %*/
3974  }
3975  ;
3976 
3977 words : tWORDS_BEG ' ' tSTRING_END
3978  {
3979  /*%%%*/
3980  $$ = NEW_ZARRAY();
3981  /*%
3982  $$ = dispatch0(words_new);
3983  $$ = dispatch1(array, $$);
3984  %*/
3985  }
3986  | tWORDS_BEG word_list tSTRING_END
3987  {
3988  /*%%%*/
3989  $$ = $2;
3990  /*%
3991  $$ = dispatch1(array, $2);
3992  %*/
3993  }
3994  ;
3995 
3996 word_list : /* none */
3997  {
3998  /*%%%*/
3999  $$ = 0;
4000  /*%
4001  $$ = dispatch0(words_new);
4002  %*/
4003  }
4004  | word_list word ' '
4005  {
4006  /*%%%*/
4007  $$ = list_append($1, evstr2dstr($2));
4008  /*%
4009  $$ = dispatch2(words_add, $1, $2);
4010  %*/
4011  }
4012  ;
4013 
4014 word : string_content
4015  /*%c%*/
4016  /*%c
4017  {
4018  $$ = dispatch0(word_new);
4019  $$ = dispatch2(word_add, $$, $1);
4020  }
4021  %*/
4022  | word string_content
4023  {
4024  /*%%%*/
4025  $$ = literal_concat($1, $2);
4026  /*%
4027  $$ = dispatch2(word_add, $1, $2);
4028  %*/
4029  }
4030  ;
4031 
4032 qwords : tQWORDS_BEG ' ' tSTRING_END
4033  {
4034  /*%%%*/
4035  $$ = NEW_ZARRAY();
4036  /*%
4037  $$ = dispatch0(qwords_new);
4038  $$ = dispatch1(array, $$);
4039  %*/
4040  }
4041  | tQWORDS_BEG qword_list tSTRING_END
4042  {
4043  /*%%%*/
4044  $$ = $2;
4045  /*%
4046  $$ = dispatch1(array, $2);
4047  %*/
4048  }
4049  ;
4050 
4051 qword_list : /* none */
4052  {
4053  /*%%%*/
4054  $$ = 0;
4055  /*%
4056  $$ = dispatch0(qwords_new);
4057  %*/
4058  }
4059  | qword_list tSTRING_CONTENT ' '
4060  {
4061  /*%%%*/
4062  $$ = list_append($1, $2);
4063  /*%
4064  $$ = dispatch2(qwords_add, $1, $2);
4065  %*/
4066  }
4067  ;
4068 
4069 string_contents : /* none */
4070  {
4071  /*%%%*/
4072  $$ = 0;
4073  /*%
4074  $$ = dispatch0(string_content);
4075  %*/
4076  }
4077  | string_contents string_content
4078  {
4079  /*%%%*/
4080  $$ = literal_concat($1, $2);
4081  /*%
4082  $$ = dispatch2(string_add, $1, $2);
4083  %*/
4084  }
4085  ;
4086 
4087 xstring_contents: /* none */
4088  {
4089  /*%%%*/
4090  $$ = 0;
4091  /*%
4092  $$ = dispatch0(xstring_new);
4093  %*/
4094  }
4095  | xstring_contents string_content
4096  {
4097  /*%%%*/
4098  $$ = literal_concat($1, $2);
4099  /*%
4100  $$ = dispatch2(xstring_add, $1, $2);
4101  %*/
4102  }
4103  ;
4104 
4105 regexp_contents: /* none */
4106  {
4107  /*%%%*/
4108  $$ = 0;
4109  /*%
4110  $$ = dispatch0(regexp_new);
4111  %*/
4112  }
4113  | regexp_contents string_content
4114  {
4115  /*%%%*/
4116  NODE *head = $1, *tail = $2;
4117  if (!head) {
4118  $$ = tail;
4119  }
4120  else if (!tail) {
4121  $$ = head;
4122  }
4123  else {
4124  switch (nd_type(head)) {
4125  case NODE_STR:
4126  nd_set_type(head, NODE_DSTR);
4127  break;
4128  case NODE_DSTR:
4129  break;
4130  default:
4131  head = list_append(NEW_DSTR(Qnil), head);
4132  break;
4133  }
4134  $$ = list_append(head, tail);
4135  }
4136  /*%
4137  $$ = dispatch2(regexp_add, $1, $2);
4138  %*/
4139  }
4140  ;
4141 
4142 string_content : tSTRING_CONTENT
4143  | tSTRING_DVAR
4144  {
4145  $<node>$ = lex_strterm;
4146  lex_strterm = 0;
4147  lex_state = EXPR_BEG;
4148  }
4149  string_dvar
4150  {
4151  /*%%%*/
4152  lex_strterm = $<node>2;
4153  $$ = NEW_EVSTR($3);
4154  /*%
4155  lex_strterm = $<node>2;
4156  $$ = dispatch1(string_dvar, $3);
4157  %*/
4158  }
4159  | tSTRING_DBEG
4160  {
4161  $<val>1 = cond_stack;
4162  $<val>$ = cmdarg_stack;
4163  cond_stack = 0;
4164  cmdarg_stack = 0;
4165  }
4166  {
4167  $<node>$ = lex_strterm;
4168  lex_strterm = 0;
4169  lex_state = EXPR_BEG;
4170  }
4171  compstmt '}'
4172  {
4173  cond_stack = $<val>1;
4174  cmdarg_stack = $<val>2;
4175  lex_strterm = $<node>3;
4176  /*%%%*/
4177  if ($4) $4->flags &= ~NODE_FL_NEWLINE;
4178  $$ = new_evstr($4);
4179  /*%
4180  $$ = dispatch1(string_embexpr, $4);
4181  %*/
4182  }
4183  ;
4184 
4185 string_dvar : tGVAR
4186  {
4187  /*%%%*/
4188  $$ = NEW_GVAR($1);
4189  /*%
4190  $$ = dispatch1(var_ref, $1);
4191  %*/
4192  }
4193  | tIVAR
4194  {
4195  /*%%%*/
4196  $$ = NEW_IVAR($1);
4197  /*%
4198  $$ = dispatch1(var_ref, $1);
4199  %*/
4200  }
4201  | tCVAR
4202  {
4203  /*%%%*/
4204  $$ = NEW_CVAR($1);
4205  /*%
4206  $$ = dispatch1(var_ref, $1);
4207  %*/
4208  }
4209  | backref
4210  ;
4211 
4212 symbol : tSYMBEG sym
4213  {
4214  lex_state = EXPR_END;
4215  /*%%%*/
4216  $$ = $2;
4217  /*%
4218  $$ = dispatch1(symbol, $2);
4219  %*/
4220  }
4221  ;
4222 
4223 sym : fname
4224  | tIVAR
4225  | tGVAR
4226  | tCVAR
4227  ;
4228 
4229 dsym : tSYMBEG xstring_contents tSTRING_END
4230  {
4231  lex_state = EXPR_END;
4232  /*%%%*/
4233  if (!($$ = $2)) {
4234  $$ = NEW_LIT(ID2SYM(rb_intern("")));
4235  }
4236  else {
4237  VALUE lit;
4238 
4239  switch (nd_type($$)) {
4240  case NODE_DSTR:
4241  nd_set_type($$, NODE_DSYM);
4242  break;
4243  case NODE_STR:
4244  lit = $$->nd_lit;
4245  $$->nd_lit = ID2SYM(rb_intern_str(lit));
4246  nd_set_type($$, NODE_LIT);
4247  break;
4248  default:
4249  $$ = NEW_NODE(NODE_DSYM, Qnil, 1, NEW_LIST($$));
4250  break;
4251  }
4252  }
4253  /*%
4254  $$ = dispatch1(dyna_symbol, $2);
4255  %*/
4256  }
4257  ;
4258 
4259 numeric : tINTEGER
4260  | tFLOAT
4261  | tUMINUS_NUM tINTEGER %prec tLOWEST
4262  {
4263  /*%%%*/
4264  $$ = negate_lit($2);
4265  /*%
4266  $$ = dispatch2(unary, ripper_intern("-@"), $2);
4267  %*/
4268  }
4269  | tUMINUS_NUM tFLOAT %prec tLOWEST
4270  {
4271  /*%%%*/
4272  $$ = negate_lit($2);
4273  /*%
4274  $$ = dispatch2(unary, ripper_intern("-@"), $2);
4275  %*/
4276  }
4277  ;
4278 
4279 user_variable : tIDENTIFIER
4280  | tIVAR
4281  | tGVAR
4282  | tCONSTANT
4283  | tCVAR
4284  ;
4285 
4293  ;
4294 
4295 var_ref : user_variable
4296  {
4297  /*%%%*/
4298  if (!($$ = gettable($1))) $$ = NEW_BEGIN(0);
4299  /*%
4300  if (id_is_var(get_id($1))) {
4301  $$ = dispatch1(var_ref, $1);
4302  }
4303  else {
4304  $$ = dispatch1(vcall, $1);
4305  }
4306  %*/
4307  }
4309  {
4310  /*%%%*/
4311  if (!($$ = gettable($1))) $$ = NEW_BEGIN(0);
4312  /*%
4313  $$ = dispatch1(var_ref, $1);
4314  %*/
4315  }
4316  ;
4317 
4318 var_lhs : user_variable
4319  {
4320  $$ = assignable($1, 0);
4321  /*%%%*/
4322  /*%
4323  $$ = dispatch1(var_field, $$);
4324  %*/
4325  }
4327  {
4328  $$ = assignable($1, 0);
4329  /*%%%*/
4330  /*%
4331  $$ = dispatch1(var_field, $$);
4332  %*/
4333  }
4334  ;
4335 
4336 backref : tNTH_REF
4337  | tBACK_REF
4338  ;
4339 
4340 superclass : term
4341  {
4342  /*%%%*/
4343  $$ = 0;
4344  /*%
4345  $$ = Qnil;
4346  %*/
4347  }
4348  | '<'
4349  {
4350  lex_state = EXPR_BEG;
4351  }
4352  expr_value term
4353  {
4354  $$ = $3;
4355  }
4356  | error term
4357  {
4358  /*%%%*/
4359  yyerrok;
4360  $$ = 0;
4361  /*%
4362  yyerrok;
4363  $$ = Qnil;
4364  %*/
4365  }
4366  ;
4367 
4368 f_arglist : '(' f_args rparen
4369  {
4370  /*%%%*/
4371  $$ = $2;
4372  /*%
4373  $$ = dispatch1(paren, $2);
4374  %*/
4375  lex_state = EXPR_BEG;
4376  command_start = TRUE;
4377  }
4378  | f_args term
4379  {
4380  $$ = $1;
4381  lex_state = EXPR_BEG;
4382  command_start = TRUE;
4383  }
4384  ;
4385 
4386 f_args : f_arg ',' f_optarg ',' f_rest_arg opt_f_block_arg
4387  {
4388  /*%%%*/
4389  $$ = new_args($1, $3, $5, 0, $6);
4390  /*%
4391  $$ = params_new($1, $3, $5, Qnil, escape_Qundef($6));
4392  %*/
4393  }
4394  | f_arg ',' f_optarg ',' f_rest_arg ',' f_arg opt_f_block_arg
4395  {
4396  /*%%%*/
4397  $$ = new_args($1, $3, $5, $7, $8);
4398  /*%
4399  $$ = params_new($1, $3, $5, $7, escape_Qundef($8));
4400  %*/
4401  }
4402  | f_arg ',' f_optarg opt_f_block_arg
4403  {
4404  /*%%%*/
4405  $$ = new_args($1, $3, 0, 0, $4);
4406  /*%
4407  $$ = params_new($1, $3, Qnil, Qnil, escape_Qundef($4));
4408  %*/
4409  }
4410  | f_arg ',' f_optarg ',' f_arg opt_f_block_arg
4411  {
4412  /*%%%*/
4413  $$ = new_args($1, $3, 0, $5, $6);
4414  /*%
4415  $$ = params_new($1, $3, Qnil, $5, escape_Qundef($6));
4416  %*/
4417  }
4418  | f_arg ',' f_rest_arg opt_f_block_arg
4419  {
4420  /*%%%*/
4421  $$ = new_args($1, 0, $3, 0, $4);
4422  /*%
4423  $$ = params_new($1, Qnil, $3, Qnil, escape_Qundef($4));
4424  %*/
4425  }
4426  | f_arg ',' f_rest_arg ',' f_arg opt_f_block_arg
4427  {
4428  /*%%%*/
4429  $$ = new_args($1, 0, $3, $5, $6);
4430  /*%
4431  $$ = params_new($1, Qnil, $3, $5, escape_Qundef($6));
4432  %*/
4433  }
4434  | f_arg opt_f_block_arg
4435  {
4436  /*%%%*/
4437  $$ = new_args($1, 0, 0, 0, $2);
4438  /*%
4439  $$ = params_new($1, Qnil, Qnil, Qnil,escape_Qundef($2));
4440  %*/
4441  }
4442  | f_optarg ',' f_rest_arg opt_f_block_arg
4443  {
4444  /*%%%*/
4445  $$ = new_args(0, $1, $3, 0, $4);
4446  /*%
4447  $$ = params_new(Qnil, $1, $3, Qnil, escape_Qundef($4));
4448  %*/
4449  }
4450  | f_optarg ',' f_rest_arg ',' f_arg opt_f_block_arg
4451  {
4452  /*%%%*/
4453  $$ = new_args(0, $1, $3, $5, $6);
4454  /*%
4455  $$ = params_new(Qnil, $1, $3, $5, escape_Qundef($6));
4456  %*/
4457  }
4458  | f_optarg opt_f_block_arg
4459  {
4460  /*%%%*/
4461  $$ = new_args(0, $1, 0, 0, $2);
4462  /*%
4463  $$ = params_new(Qnil, $1, Qnil, Qnil,escape_Qundef($2));
4464  %*/
4465  }
4466  | f_optarg ',' f_arg opt_f_block_arg
4467  {
4468  /*%%%*/
4469  $$ = new_args(0, $1, 0, $3, $4);
4470  /*%
4471  $$ = params_new(Qnil, $1, Qnil, $3, escape_Qundef($4));
4472  %*/
4473  }
4474  | f_rest_arg opt_f_block_arg
4475  {
4476  /*%%%*/
4477  $$ = new_args(0, 0, $1, 0, $2);
4478  /*%
4479  $$ = params_new(Qnil, Qnil, $1, Qnil,escape_Qundef($2));
4480  %*/
4481  }
4482  | f_rest_arg ',' f_arg opt_f_block_arg
4483  {
4484  /*%%%*/
4485  $$ = new_args(0, 0, $1, $3, $4);
4486  /*%
4487  $$ = params_new(Qnil, Qnil, $1, $3, escape_Qundef($4));
4488  %*/
4489  }
4490  | f_block_arg
4491  {
4492  /*%%%*/
4493  $$ = new_args(0, 0, 0, 0, $1);
4494  /*%
4495  $$ = params_new(Qnil, Qnil, Qnil, Qnil, $1);
4496  %*/
4497  }
4498  | /* none */
4499  {
4500  /*%%%*/
4501  $$ = new_args(0, 0, 0, 0, 0);
4502  /*%
4503  $$ = params_new(Qnil, Qnil, Qnil, Qnil, Qnil);
4504  %*/
4505  }
4506  ;
4507 
4508 f_bad_arg : tCONSTANT
4509  {
4510  /*%%%*/
4511  yyerror("formal argument cannot be a constant");
4512  $$ = 0;
4513  /*%
4514  $$ = dispatch1(param_error, $1);
4515  %*/
4516  }
4517  | tIVAR
4518  {
4519  /*%%%*/
4520  yyerror("formal argument cannot be an instance variable");
4521  $$ = 0;
4522  /*%
4523  $$ = dispatch1(param_error, $1);
4524  %*/
4525  }
4526  | tGVAR
4527  {
4528  /*%%%*/
4529  yyerror("formal argument cannot be a global variable");
4530  $$ = 0;
4531  /*%
4532  $$ = dispatch1(param_error, $1);
4533  %*/
4534  }
4535  | tCVAR
4536  {
4537  /*%%%*/
4538  yyerror("formal argument cannot be a class variable");
4539  $$ = 0;
4540  /*%
4541  $$ = dispatch1(param_error, $1);
4542  %*/
4543  }
4544  ;
4545 
4546 f_norm_arg : f_bad_arg
4547  | tIDENTIFIER
4548  {
4549  formal_argument(get_id($1));
4550  $$ = $1;
4551  }
4552  ;
4553 
4554 f_arg_item : f_norm_arg
4555  {
4556  arg_var(get_id($1));
4557  /*%%%*/
4558  $$ = NEW_ARGS_AUX($1, 1);
4559  /*%
4560  $$ = get_value($1);
4561  %*/
4562  }
4563  | tLPAREN f_margs rparen
4564  {
4565  ID tid = internal_id();
4566  arg_var(tid);
4567  /*%%%*/
4568  if (dyna_in_block()) {
4569  $2->nd_value = NEW_DVAR(tid);
4570  }
4571  else {
4572  $2->nd_value = NEW_LVAR(tid);
4573  }
4574  $$ = NEW_ARGS_AUX(tid, 1);
4575  $$->nd_next = $2;
4576  /*%
4577  $$ = dispatch1(mlhs_paren, $2);
4578  %*/
4579  }
4580  ;
4581 
4582 f_arg : f_arg_item
4583  /*%c%*/
4584  /*%c
4585  {
4586  $$ = rb_ary_new3(1, $1);
4587  }
4588  c%*/
4589  | f_arg ',' f_arg_item
4590  {
4591  /*%%%*/
4592  $$ = $1;
4593  $$->nd_plen++;
4594  $$->nd_next = block_append($$->nd_next, $3->nd_next);
4596  /*%
4597  $$ = rb_ary_push($1, $3);
4598  %*/
4599  }
4600  ;
4601 
4602 f_opt : tIDENTIFIER '=' arg_value
4603  {
4605  $$ = assignable($1, $3);
4606  /*%%%*/
4607  $$ = NEW_OPT_ARG(0, $$);
4608  /*%
4609  $$ = rb_assoc_new($$, $3);
4610  %*/
4611  }
4612  ;
4613 
4614 f_block_opt : tIDENTIFIER '=' primary_value
4615  {
4617  $$ = assignable($1, $3);
4618  /*%%%*/
4619  $$ = NEW_OPT_ARG(0, $$);
4620  /*%
4621  $$ = rb_assoc_new($$, $3);
4622  %*/
4623  }
4624  ;
4625 
4626 f_block_optarg : f_block_opt
4627  {
4628  /*%%%*/
4629  $$ = $1;
4630  /*%
4631  $$ = rb_ary_new3(1, $1);
4632  %*/
4633  }
4634  | f_block_optarg ',' f_block_opt
4635  {
4636  /*%%%*/
4637  NODE *opts = $1;
4638 
4639  while (opts->nd_next) {
4640  opts = opts->nd_next;
4641  }
4642  opts->nd_next = $3;
4643  $$ = $1;
4644  /*%
4645  $$ = rb_ary_push($1, $3);
4646  %*/
4647  }
4648  ;
4649 
4650 f_optarg : f_opt
4651  {
4652  /*%%%*/
4653  $$ = $1;
4654  /*%
4655  $$ = rb_ary_new3(1, $1);
4656  %*/
4657  }
4658  | f_optarg ',' f_opt
4659  {
4660  /*%%%*/
4661  NODE *opts = $1;
4662 
4663  while (opts->nd_next) {
4664  opts = opts->nd_next;
4665  }
4666  opts->nd_next = $3;
4667  $$ = $1;
4668  /*%
4669  $$ = rb_ary_push($1, $3);
4670  %*/
4671  }
4672  ;
4673 
4674 restarg_mark : '*'
4675  | tSTAR
4676  ;
4677 
4678 f_rest_arg : restarg_mark tIDENTIFIER
4679  {
4680  /*%%%*/
4681  if (!is_local_id($2))
4682  yyerror("rest argument must be local variable");
4683  /*% %*/
4685  /*%%%*/
4686  $$ = $2;
4687  /*%
4688  $$ = dispatch1(rest_param, $2);
4689  %*/
4690  }
4691  | restarg_mark
4692  {
4693  /*%%%*/
4694  $$ = internal_id();
4695  arg_var($$);
4696  /*%
4697  $$ = dispatch1(rest_param, Qnil);
4698  %*/
4699  }
4700  ;
4701 
4702 blkarg_mark : '&'
4703  | tAMPER
4704  ;
4705 
4706 f_block_arg : blkarg_mark tIDENTIFIER
4707  {
4708  /*%%%*/
4709  if (!is_local_id($2))
4710  yyerror("block argument must be local variable");
4711  else if (!dyna_in_block() && local_id($2))
4712  yyerror("duplicated block argument name");
4713  /*% %*/
4715  /*%%%*/
4716  $$ = $2;
4717  /*%
4718  $$ = dispatch1(blockarg, $2);
4719  %*/
4720  }
4721  ;
4722 
4723 opt_f_block_arg : ',' f_block_arg
4724  {
4725  $$ = $2;
4726  }
4727  | none
4728  {
4729  /*%%%*/
4730  $$ = 0;
4731  /*%
4732  $$ = Qundef;
4733  %*/
4734  }
4735  ;
4736 
4737 singleton : var_ref
4738  {
4739  /*%%%*/
4740  value_expr($1);
4741  $$ = $1;
4742  if (!$$) $$ = NEW_NIL();
4743  /*%
4744  $$ = $1;
4745  %*/
4746  }
4747  | '(' {lex_state = EXPR_BEG;} expr rparen
4748  {
4749  /*%%%*/
4750  if ($3 == 0) {
4751  yyerror("can't define singleton method for ().");
4752  }
4753  else {
4754  switch (nd_type($3)) {
4755  case NODE_STR:
4756  case NODE_DSTR:
4757  case NODE_XSTR:
4758  case NODE_DXSTR:
4759  case NODE_DREGX:
4760  case NODE_LIT:
4761  case NODE_ARRAY:
4762  case NODE_ZARRAY:
4763  yyerror("can't define singleton method for literals");
4764  default:
4765  value_expr($3);
4766  break;
4767  }
4768  }
4769  $$ = $3;
4770  /*%
4771  $$ = dispatch1(paren, $3);
4772  %*/
4773  }
4774  ;
4775 
4776 assoc_list : none
4777  | assocs trailer
4778  {
4779  /*%%%*/
4780  $$ = $1;
4781  /*%
4782  $$ = dispatch1(assoclist_from_args, $1);
4783  %*/
4784  }
4785  ;
4786 
4787 assocs : assoc
4788  /*%c%*/
4789  /*%c
4790  {
4791  $$ = rb_ary_new3(1, $1);
4792  }
4793  %*/
4794  | assocs ',' assoc
4795  {
4796  /*%%%*/
4797  $$ = list_concat($1, $3);
4798  /*%
4799  $$ = rb_ary_push($1, $3);
4800  %*/
4801  }
4802  ;
4803 
4804 assoc : arg_value tASSOC arg_value
4805  {
4806  /*%%%*/
4807  $$ = list_append(NEW_LIST($1), $3);
4808  /*%
4809  $$ = dispatch2(assoc_new, $1, $3);
4810  %*/
4811  }
4812  | tLABEL arg_value
4813  {
4814  /*%%%*/
4815  $$ = list_append(NEW_LIST(NEW_LIT(ID2SYM($1))), $2);
4816  /*%
4817  $$ = dispatch2(assoc_new, $1, $2);
4818  %*/
4819  }
4820  ;
4821 
4822 operation : tIDENTIFIER
4823  | tCONSTANT
4824  | tFID
4825  ;
4826 
4827 operation2 : tIDENTIFIER
4828  | tCONSTANT
4829  | tFID
4830  | op
4831  ;
4832 
4833 operation3 : tIDENTIFIER
4834  | tFID
4835  | op
4836  ;
4837 
4838 dot_or_colon : '.'
4839  /*%c%*/
4840  /*%c
4841  { $$ = $<val>1; }
4842  %*/
4843  | tCOLON2
4844  /*%c%*/
4845  /*%c
4846  { $$ = $<val>1; }
4847  %*/
4848  ;
4849 
4850 opt_terms : /* none */
4851  | terms
4852  ;
4853 
4854 opt_nl : /* none */
4855  | '\n'
4856  ;
4857 
4858 rparen : opt_nl ')'
4859  ;
4860 
4861 rbracket : opt_nl ']'
4862  ;
4863 
4864 trailer : /* none */
4865  | '\n'
4866  | ','
4867  ;
4868 
4869 term : ';' {yyerrok;}
4870  | '\n'
4871  ;
4872 
4873 terms : term
4874  | terms ';' {yyerrok;}
4875  ;
4876 
4877 none : /* none */
4878  {
4879  /*%%%*/
4880  $$ = 0;
4881  /*%
4882  $$ = Qundef;
4883  %*/
4884  }
4885  ;
4886 %%
4887 # undef parser
4888 # undef yylex
4889 # undef yylval
4890 # define yylval (*((YYSTYPE*)(parser->parser_yylval)))
4891 
4892 static int parser_regx_options(struct parser_params*);
4893 static int parser_tokadd_string(struct parser_params*,int,int,int,long*,rb_encoding**);
4894 static void parser_tokaddmbc(struct parser_params *parser, int c, rb_encoding *enc);
4895 static int parser_parse_string(struct parser_params*,NODE*);
4896 static int parser_here_document(struct parser_params*,NODE*);
4897 
4898 
4899 # define nextc() parser_nextc(parser)
4900 # define pushback(c) parser_pushback(parser, (c))
4901 # define newtok() parser_newtok(parser)
4902 # define tokspace(n) parser_tokspace(parser, (n))
4903 # define tokadd(c) parser_tokadd(parser, (c))
4904 # define tok_hex(numlen) parser_tok_hex(parser, (numlen))
4905 # define read_escape(flags,e) parser_read_escape(parser, (flags), (e))
4906 # define tokadd_escape(e) parser_tokadd_escape(parser, (e))
4907 # define regx_options() parser_regx_options(parser)
4908 # define tokadd_string(f,t,p,n,e) parser_tokadd_string(parser,(f),(t),(p),(n),(e))
4909 # define parse_string(n) parser_parse_string(parser,(n))
4910 # define tokaddmbc(c, enc) parser_tokaddmbc(parser, (c), (enc))
4911 # define here_document(n) parser_here_document(parser,(n))
4912 # define heredoc_identifier() parser_heredoc_identifier(parser)
4913 # define heredoc_restore(n) parser_heredoc_restore(parser,(n))
4914 # define whole_match_p(e,l,i) parser_whole_match_p(parser,(e),(l),(i))
4915 
4916 #ifndef RIPPER
4917 # define set_yylval_str(x) (yylval.node = NEW_STR(x))
4918 # define set_yylval_num(x) (yylval.num = (x))
4919 # define set_yylval_id(x) (yylval.id = (x))
4920 # define set_yylval_name(x) (yylval.id = (x))
4921 # define set_yylval_literal(x) (yylval.node = NEW_LIT(x))
4922 # define set_yylval_node(x) (yylval.node = (x))
4923 # define yylval_id() (yylval.id)
4924 #else
4925 static inline VALUE
4926 ripper_yylval_id(ID x)
4927 {
4928  return (VALUE)NEW_LASGN(x, ID2SYM(x));
4929 }
4930 # define set_yylval_str(x) (void)(x)
4931 # define set_yylval_num(x) (void)(x)
4932 # define set_yylval_id(x) (void)(x)
4933 # define set_yylval_name(x) (void)(yylval.val = ripper_yylval_id(x))
4934 # define set_yylval_literal(x) (void)(x)
4935 # define set_yylval_node(x) (void)(x)
4936 # define yylval_id() yylval.id
4937 #endif
4938 
4939 #ifndef RIPPER
4940 #define ripper_flush(p) (void)(p)
4941 #else
4942 #define ripper_flush(p) ((p)->tokp = (p)->parser_lex_p)
4943 
4944 #define yylval_rval (*(RB_TYPE_P(yylval.val, T_NODE) ? &yylval.node->nd_rval : &yylval.val))
4945 
4946 static int
4947 ripper_has_scan_event(struct parser_params *parser)
4948 {
4949 
4950  if (lex_p < parser->tokp) rb_raise(rb_eRuntimeError, "lex_p < tokp");
4951  return lex_p > parser->tokp;
4952 }
4953 
4954 static VALUE
4955 ripper_scan_event_val(struct parser_params *parser, int t)
4956 {
4957  VALUE str = STR_NEW(parser->tokp, lex_p - parser->tokp);
4958  VALUE rval = ripper_dispatch1(parser, ripper_token2eventid(t), str);
4959  ripper_flush(parser);
4960  return rval;
4961 }
4962 
4963 static void
4964 ripper_dispatch_scan_event(struct parser_params *parser, int t)
4965 {
4966  if (!ripper_has_scan_event(parser)) return;
4967  yylval_rval = ripper_scan_event_val(parser, t);
4968 }
4969 
4970 static void
4971 ripper_dispatch_ignored_scan_event(struct parser_params *parser, int t)
4972 {
4973  if (!ripper_has_scan_event(parser)) return;
4974  (void)ripper_scan_event_val(parser, t);
4975 }
4976 
4977 static void
4978 ripper_dispatch_delayed_token(struct parser_params *parser, int t)
4979 {
4980  int saved_line = ruby_sourceline;
4981  const char *saved_tokp = parser->tokp;
4982 
4983  ruby_sourceline = parser->delayed_line;
4984  parser->tokp = lex_pbeg + parser->delayed_col;
4985  yylval_rval = ripper_dispatch1(parser, ripper_token2eventid(t), parser->delayed);
4986  parser->delayed = Qnil;
4987  ruby_sourceline = saved_line;
4988  parser->tokp = saved_tokp;
4989 }
4990 #endif /* RIPPER */
4991 
4992 #include "ruby/regex.h"
4993 #include "ruby/util.h"
4994 
4995 /* We remove any previous definition of `SIGN_EXTEND_CHAR',
4996  since ours (we hope) works properly with all combinations of
4997  machines, compilers, `char' and `unsigned char' argument types.
4998  (Per Bothner suggested the basic approach.) */
4999 #undef SIGN_EXTEND_CHAR
5000 #if __STDC__
5001 # define SIGN_EXTEND_CHAR(c) ((signed char)(c))
5002 #else /* not __STDC__ */
5003 /* As in Harbison and Steele. */
5004 # define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
5005 #endif
5006 
5007 #define parser_encoding_name() (parser->enc->name)
5008 #define parser_mbclen() mbclen((lex_p-1),lex_pend,parser->enc)
5009 #define parser_precise_mbclen() rb_enc_precise_mbclen((lex_p-1),lex_pend,parser->enc)
5010 #define is_identchar(p,e,enc) (rb_enc_isalnum(*(p),(enc)) || (*(p)) == '_' || !ISASCII(*(p)))
5011 #define parser_is_identchar() (!parser->eofp && is_identchar((lex_p-1),lex_pend,parser->enc))
5012 
5013 #define parser_isascii() ISASCII(*(lex_p-1))
5014 
5015 #ifndef RIPPER
5016 static int
5017 token_info_get_column(struct parser_params *parser, const char *token)
5018 {
5019  int column = 1;
5020  const char *p, *pend = lex_p - strlen(token);
5021  for (p = lex_pbeg; p < pend; p++) {
5022  if (*p == '\t') {
5023  column = (((column - 1) / 8) + 1) * 8;
5024  }
5025  column++;
5026  }
5027  return column;
5028 }
5029 
5030 static int
5031 token_info_has_nonspaces(struct parser_params *parser, const char *token)
5032 {
5033  const char *p, *pend = lex_p - strlen(token);
5034  for (p = lex_pbeg; p < pend; p++) {
5035  if (*p != ' ' && *p != '\t') {
5036  return 1;
5037  }
5038  }
5039  return 0;
5040 }
5041 
5042 #undef token_info_push
5043 static void
5044 token_info_push(struct parser_params *parser, const char *token)
5045 {
5046  token_info *ptinfo;
5047 
5048  if (!parser->parser_token_info_enabled) return;
5049  ptinfo = ALLOC(token_info);
5050  ptinfo->token = token;
5051  ptinfo->linenum = ruby_sourceline;
5052  ptinfo->column = token_info_get_column(parser, token);
5053  ptinfo->nonspc = token_info_has_nonspaces(parser, token);
5054  ptinfo->next = parser->parser_token_info;
5055 
5056  parser->parser_token_info = ptinfo;
5057 }
5058 
5059 #undef token_info_pop
5060 static void
5061 token_info_pop(struct parser_params *parser, const char *token)
5062 {
5063  int linenum;
5064  token_info *ptinfo = parser->parser_token_info;
5065 
5066  if (!ptinfo) return;
5067  parser->parser_token_info = ptinfo->next;
5068  if (token_info_get_column(parser, token) == ptinfo->column) { /* OK */
5069  goto finish;
5070  }
5071  linenum = ruby_sourceline;
5072  if (linenum == ptinfo->linenum) { /* SKIP */
5073  goto finish;
5074  }
5075  if (token_info_has_nonspaces(parser, token) || ptinfo->nonspc) { /* SKIP */
5076  goto finish;
5077  }
5078  if (parser->parser_token_info_enabled) {
5080  "mismatched indentations at '%s' with '%s' at %d",
5081  token, ptinfo->token, ptinfo->linenum);
5082  }
5083 
5084  finish:
5085  xfree(ptinfo);
5086 }
5087 #endif /* RIPPER */
5088 
5089 static int
5090 parser_yyerror(struct parser_params *parser, const char *msg)
5091 {
5092 #ifndef RIPPER
5093  const int max_line_margin = 30;
5094  const char *p, *pe;
5095  char *buf;
5096  long len;
5097  int i;
5098 
5099  compile_error(PARSER_ARG "%s", msg);
5100  p = lex_p;
5101  while (lex_pbeg <= p) {
5102  if (*p == '\n') break;
5103  p--;
5104  }
5105  p++;
5106 
5107  pe = lex_p;
5108  while (pe < lex_pend) {
5109  if (*pe == '\n') break;
5110  pe++;
5111  }
5112 
5113  len = pe - p;
5114  if (len > 4) {
5115  char *p2;
5116  const char *pre = "", *post = "";
5117 
5118  if (len > max_line_margin * 2 + 10) {
5119  if (lex_p - p > max_line_margin) {
5120  p = rb_enc_prev_char(p, lex_p - max_line_margin, pe, rb_enc_get(lex_lastline));
5121  pre = "...";
5122  }
5123  if (pe - lex_p > max_line_margin) {
5124  pe = rb_enc_prev_char(lex_p, lex_p + max_line_margin, pe, rb_enc_get(lex_lastline));
5125  post = "...";
5126  }
5127  len = pe - p;
5128  }
5129  buf = ALLOCA_N(char, len+2);
5130  MEMCPY(buf, p, char, len);
5131  buf[len] = '\0';
5132  rb_compile_error_append("%s%s%s", pre, buf, post);
5133 
5134  i = (int)(lex_p - p);
5135  p2 = buf; pe = buf + len;
5136 
5137  while (p2 < pe) {
5138  if (*p2 != '\t') *p2 = ' ';
5139  p2++;
5140  }
5141  buf[i] = '^';
5142  buf[i+1] = '\0';
5143  rb_compile_error_append("%s%s", pre, buf);
5144  }
5145 #else
5146  dispatch1(parse_error, STR_NEW2(msg));
5147 #endif /* !RIPPER */
5148  return 0;
5149 }
5150 
5151 static void parser_prepare(struct parser_params *parser);
5152 
5153 #ifndef RIPPER
5154 static VALUE
5155 debug_lines(const char *f)
5156 {
5157  ID script_lines;
5158  CONST_ID(script_lines, "SCRIPT_LINES__");
5159  if (rb_const_defined_at(rb_cObject, script_lines)) {
5160  VALUE hash = rb_const_get_at(rb_cObject, script_lines);
5161  if (TYPE(hash) == T_HASH) {
5163  VALUE lines = rb_ary_new();
5164  rb_hash_aset(hash, fname, lines);
5165  return lines;
5166  }
5167  }
5168  return 0;
5169 }
5170 
5171 static VALUE
5172 coverage(const char *f, int n)
5173 {
5174  VALUE coverages = rb_get_coverages();
5175  if (RTEST(coverages) && RBASIC(coverages)->klass == 0) {
5177  VALUE lines = rb_ary_new2(n);
5178  int i;
5179  RBASIC(lines)->klass = 0;
5180  for (i = 0; i < n; i++) RARRAY_PTR(lines)[i] = Qnil;
5181  RARRAY(lines)->as.heap.len = n;
5182  rb_hash_aset(coverages, fname, lines);
5183  return lines;
5184  }
5185  return 0;
5186 }
5187 
5188 static int
5189 e_option_supplied(struct parser_params *parser)
5190 {
5191  return strcmp(ruby_sourcefile, "-e") == 0;
5192 }
5193 
5194 static VALUE
5195 yycompile0(VALUE arg, int tracing)
5196 {
5197  int n;
5198  NODE *tree;
5199  struct parser_params *parser = (struct parser_params *)arg;
5200 
5201  if (!compile_for_eval && rb_safe_level() == 0) {
5203  if (ruby_debug_lines && ruby_sourceline > 0) {
5204  VALUE str = STR_NEW0();
5205  n = ruby_sourceline;
5206  do {
5208  } while (--n);
5209  }
5210 
5211  if (!e_option_supplied(parser)) {
5213  }
5214  }
5215 
5216  parser_prepare(parser);
5217  deferred_nodes = 0;
5218 #ifndef RIPPER
5220 #endif
5221  n = yyparse((void*)parser);
5222  ruby_debug_lines = 0;
5223  ruby_coverage = 0;
5224  compile_for_eval = 0;
5225 
5226  lex_strterm = 0;
5227  lex_p = lex_pbeg = lex_pend = 0;
5228  lex_lastline = lex_nextline = 0;
5229  if (parser->nerr) {
5230  return 0;
5231  }
5232  tree = ruby_eval_tree;
5233  if (!tree) {
5234  tree = NEW_NIL();
5235  }
5236  else if (ruby_eval_tree_begin) {
5237  tree->nd_body = NEW_PRELUDE(ruby_eval_tree_begin, tree->nd_body);
5238  }
5239  return (VALUE)tree;
5240 }
5241 
5242 static NODE*
5243 yycompile(struct parser_params *parser, const char *f, int line)
5244 {
5246  ruby_sourceline = line - 1;
5247  return (NODE *)ruby_suppress_tracing(yycompile0, (VALUE)parser, TRUE);
5248 }
5249 #endif /* !RIPPER */
5250 
5251 static rb_encoding *
5253 {
5254  rb_encoding *enc = rb_enc_get(s);
5255  if (!rb_enc_asciicompat(enc)) {
5256  rb_raise(rb_eArgError, "invalid source encoding");
5257  }
5258  return enc;
5259 }
5260 
5261 static VALUE
5262 lex_get_str(struct parser_params *parser, VALUE s)
5263 {
5264  char *beg, *end, *pend;
5266 
5267  beg = RSTRING_PTR(s);
5268  if (lex_gets_ptr) {
5269  if (RSTRING_LEN(s) == lex_gets_ptr) return Qnil;
5270  beg += lex_gets_ptr;
5271  }
5272  pend = RSTRING_PTR(s) + RSTRING_LEN(s);
5273  end = beg;
5274  while (end < pend) {
5275  if (*end++ == '\n') break;
5276  }
5277  lex_gets_ptr = end - RSTRING_PTR(s);
5278  return rb_enc_str_new(beg, end - beg, enc);
5279 }
5280 
5281 static VALUE
5282 lex_getline(struct parser_params *parser)
5283 {
5284  VALUE line = (*parser->parser_lex_gets)(parser, parser->parser_lex_input);
5285  if (NIL_P(line)) return line;
5287 #ifndef RIPPER
5288  if (ruby_debug_lines) {
5289  rb_enc_associate(line, parser->enc);
5291  }
5292  if (ruby_coverage) {
5294  }
5295 #endif
5296  return line;
5297 }
5298 
5299 #ifdef RIPPER
5301 #else
5302 static const rb_data_type_t parser_data_type;
5303 
5304 static NODE*
5305 parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
5306 {
5307  struct parser_params *parser;
5308  NODE *node;
5309  volatile VALUE tmp;
5310 
5311  TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser);
5313  lex_gets_ptr = 0;
5314  lex_input = s;
5315  lex_pbeg = lex_p = lex_pend = 0;
5317 
5318  node = yycompile(parser, f, line);
5319  tmp = vparser; /* prohibit tail call optimization */
5320 
5321  return node;
5322 }
5323 
5324 NODE*
5325 rb_compile_string(const char *f, VALUE s, int line)
5326 {
5328  return parser_compile_string(rb_parser_new(), f, s, line);
5329 }
5330 
5331 NODE*
5332 rb_parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
5333 {
5335  return parser_compile_string(vparser, f, s, line);
5336 }
5337 
5338 NODE*
5339 rb_compile_cstr(const char *f, const char *s, int len, int line)
5340 {
5341  VALUE str = rb_str_new(s, len);
5342  return parser_compile_string(rb_parser_new(), f, str, line);
5343 }
5344 
5345 NODE*
5346 rb_parser_compile_cstr(volatile VALUE vparser, const char *f, const char *s, int len, int line)
5347 {
5348  VALUE str = rb_str_new(s, len);
5349  return parser_compile_string(vparser, f, str, line);
5350 }
5351 
5352 static VALUE
5353 lex_io_gets(struct parser_params *parser, VALUE io)
5354 {
5355  return rb_io_gets(io);
5356 }
5357 
5358 NODE*
5359 rb_compile_file(const char *f, VALUE file, int start)
5360 {
5361  VALUE volatile vparser = rb_parser_new();
5362 
5363  return rb_parser_compile_file(vparser, f, file, start);
5364 }
5365 
5366 NODE*
5367 rb_parser_compile_file(volatile VALUE vparser, const char *f, VALUE file, int start)
5368 {
5369  struct parser_params *parser;
5370  volatile VALUE tmp;
5371  NODE *node;
5372 
5373  TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser);
5375  lex_input = file;
5376  lex_pbeg = lex_p = lex_pend = 0;
5378 
5379  node = yycompile(parser, f, start);
5380  tmp = vparser; /* prohibit tail call optimization */
5381 
5382  return node;
5383 }
5384 #endif /* !RIPPER */
5385 
5386 #define STR_FUNC_ESCAPE 0x01
5387 #define STR_FUNC_EXPAND 0x02
5388 #define STR_FUNC_REGEXP 0x04
5389 #define STR_FUNC_QWORDS 0x08
5390 #define STR_FUNC_SYMBOL 0x10
5391 #define STR_FUNC_INDENT 0x20
5392 
5393 enum string_type {
5394  str_squote = (0),
5402 };
5403 
5404 static VALUE
5405 parser_str_new(const char *p, long n, rb_encoding *enc, int func, rb_encoding *enc0)
5406 {
5407  VALUE str;
5408 
5409  str = rb_enc_str_new(p, n, enc);
5410  if (!(func & STR_FUNC_REGEXP) && rb_enc_asciicompat(enc)) {
5412  }
5413  else if (enc0 == rb_usascii_encoding() && enc != rb_utf8_encoding()) {
5415  }
5416  }
5417 
5418  return str;
5419 }
5420 
5421 #define lex_goto_eol(parser) ((parser)->parser_lex_p = (parser)->parser_lex_pend)
5422 #define lex_eol_p() (lex_p >= lex_pend)
5423 #define peek(c) peek_n((c), 0)
5424 #define peek_n(c,n) (lex_p+(n) < lex_pend && (c) == (unsigned char)lex_p[n])
5425 
5426 static inline int
5427 parser_nextc(struct parser_params *parser)
5428 {
5429  int c;
5430 
5431  if (lex_p == lex_pend) {
5432  VALUE v = lex_nextline;
5433  lex_nextline = 0;
5434  if (!v) {
5435  if (parser->eofp)
5436  return -1;
5437 
5438  if (!lex_input || NIL_P(v = lex_getline(parser))) {
5439  parser->eofp = Qtrue;
5440  lex_goto_eol(parser);
5441  return -1;
5442  }
5443  }
5444  {
5445 #ifdef RIPPER
5446  if (parser->tokp < lex_pend) {
5447  if (NIL_P(parser->delayed)) {
5448  parser->delayed = rb_str_buf_new(1024);
5449  rb_enc_associate(parser->delayed, parser->enc);
5450  rb_str_buf_cat(parser->delayed,
5451  parser->tokp, lex_pend - parser->tokp);
5452  parser->delayed_line = ruby_sourceline;
5453  parser->delayed_col = (int)(parser->tokp - lex_pbeg);
5454  }
5455  else {
5456  rb_str_buf_cat(parser->delayed,
5457  parser->tokp, lex_pend - parser->tokp);
5458  }
5459  }
5460 #endif
5461  if (heredoc_end > 0) {
5463  heredoc_end = 0;
5464  }
5465  ruby_sourceline++;
5466  parser->line_count++;
5467  lex_pbeg = lex_p = RSTRING_PTR(v);
5468  lex_pend = lex_p + RSTRING_LEN(v);
5469  ripper_flush(parser);
5470  lex_lastline = v;
5471  }
5472  }
5473  c = (unsigned char)*lex_p++;
5474  if (c == '\r' && peek('\n')) {
5475  lex_p++;
5476  c = '\n';
5477  }
5478 
5479  return c;
5480 }
5481 
5482 static void
5483 parser_pushback(struct parser_params *parser, int c)
5484 {
5485  if (c == -1) return;
5486  lex_p--;
5487  if (lex_p > lex_pbeg && lex_p[0] == '\n' && lex_p[-1] == '\r') {
5488  lex_p--;
5489  }
5490 }
5491 
5492 #define was_bol() (lex_p == lex_pbeg + 1)
5493 
5494 #define tokfix() (tokenbuf[tokidx]='\0')
5495 #define tok() tokenbuf
5496 #define toklen() tokidx
5497 #define toklast() (tokidx>0?tokenbuf[tokidx-1]:0)
5498 
5499 static char*
5500 parser_newtok(struct parser_params *parser)
5501 {
5502  tokidx = 0;
5503  if (!tokenbuf) {
5504  toksiz = 60;
5505  tokenbuf = ALLOC_N(char, 60);
5506  }
5507  if (toksiz > 4096) {
5508  toksiz = 60;
5509  REALLOC_N(tokenbuf, char, 60);
5510  }
5511  return tokenbuf;
5512 }
5513 
5514 static char *
5515 parser_tokspace(struct parser_params *parser, int n)
5516 {
5517  tokidx += n;
5518 
5519  if (tokidx >= toksiz) {
5520  do {toksiz *= 2;} while (toksiz < tokidx);
5521  REALLOC_N(tokenbuf, char, toksiz);
5522  }
5523  return &tokenbuf[tokidx-n];
5524 }
5525 
5526 static void
5527 parser_tokadd(struct parser_params *parser, int c)
5528 {
5529  tokenbuf[tokidx++] = (char)c;
5530  if (tokidx >= toksiz) {
5531  toksiz *= 2;
5532  REALLOC_N(tokenbuf, char, toksiz);
5533  }
5534 }
5535 
5536 static int
5537 parser_tok_hex(struct parser_params *parser, size_t *numlen)
5538 {
5539  int c;
5540 
5541  c = scan_hex(lex_p, 2, numlen);
5542  if (!*numlen) {
5543  yyerror("invalid hex escape");
5544  return 0;
5545  }
5546  lex_p += *numlen;
5547  return c;
5548 }
5549 
5550 #define tokcopy(n) memcpy(tokspace(n), lex_p - (n), (n))
5551 
5552 static int
5554  int string_literal, int symbol_literal, int regexp_literal)
5555 {
5556  /*
5557  * If string_literal is true, then we allow multiple codepoints
5558  * in \u{}, and add the codepoints to the current token.
5559  * Otherwise we're parsing a character literal and return a single
5560  * codepoint without adding it
5561  */
5562 
5563  int codepoint;
5564  size_t numlen;
5565 
5566  if (regexp_literal) { tokadd('\\'); tokadd('u'); }
5567 
5568  if (peek('{')) { /* handle \u{...} form */
5569  do {
5570  if (regexp_literal) { tokadd(*lex_p); }
5571  nextc();
5572  codepoint = scan_hex(lex_p, 6, &numlen);
5573  if (numlen == 0) {
5574  yyerror("invalid Unicode escape");
5575  return 0;
5576  }
5577  if (codepoint > 0x10ffff) {
5578  yyerror("invalid Unicode codepoint (too large)");
5579  return 0;
5580  }
5581  lex_p += numlen;
5582  if (regexp_literal) {
5583  tokcopy((int)numlen);
5584  }
5585  else if (codepoint >= 0x80) {
5586  *encp = UTF8_ENC();
5587  if (string_literal) tokaddmbc(codepoint, *encp);
5588  }
5589  else if (string_literal) {
5590  tokadd(codepoint);
5591  }
5592  } while (string_literal && (peek(' ') || peek('\t')));
5593 
5594  if (!peek('}')) {
5595  yyerror("unterminated Unicode escape");
5596  return 0;
5597  }
5598 
5599  if (regexp_literal) { tokadd('}'); }
5600  nextc();
5601  }
5602  else { /* handle \uxxxx form */
5603  codepoint = scan_hex(lex_p, 4, &numlen);
5604  if (numlen < 4) {
5605  yyerror("invalid Unicode escape");
5606  return 0;
5607  }
5608  lex_p += 4;
5609  if (regexp_literal) {
5610  tokcopy(4);
5611  }
5612  else if (codepoint >= 0x80) {
5613  *encp = UTF8_ENC();
5614  if (string_literal) tokaddmbc(codepoint, *encp);
5615  }
5616  else if (string_literal) {
5617  tokadd(codepoint);
5618  }
5619  }
5620 
5621  return codepoint;
5622 }
5623 
5624 #define ESCAPE_CONTROL 1
5625 #define ESCAPE_META 2
5626 
5627 static int
5628 parser_read_escape(struct parser_params *parser, int flags,
5629  rb_encoding **encp)
5630 {
5631  int c;
5632  size_t numlen;
5633 
5634  switch (c = nextc()) {
5635  case '\\': /* Backslash */
5636  return c;
5637 
5638  case 'n': /* newline */
5639  return '\n';
5640 
5641  case 't': /* horizontal tab */
5642  return '\t';
5643 
5644  case 'r': /* carriage-return */
5645  return '\r';
5646 
5647  case 'f': /* form-feed */
5648  return '\f';
5649 
5650  case 'v': /* vertical tab */
5651  return '\13';
5652 
5653  case 'a': /* alarm(bell) */
5654  return '\007';
5655 
5656  case 'e': /* escape */
5657  return 033;
5658 
5659  case '0': case '1': case '2': case '3': /* octal constant */
5660  case '4': case '5': case '6': case '7':
5661  pushback(c);
5662  c = scan_oct(lex_p, 3, &numlen);
5663  lex_p += numlen;
5664  return c;
5665 
5666  case 'x': /* hex constant */
5667  c = tok_hex(&numlen);
5668  if (numlen == 0) return 0;
5669  return c;
5670 
5671  case 'b': /* backspace */
5672  return '\010';
5673 
5674  case 's': /* space */
5675  return ' ';
5676 
5677  case 'M':
5678  if (flags & ESCAPE_META) goto eof;
5679  if ((c = nextc()) != '-') {
5680  pushback(c);
5681  goto eof;
5682  }
5683  if ((c = nextc()) == '\\') {
5684  if (peek('u')) goto eof;
5685  return read_escape(flags|ESCAPE_META, encp) | 0x80;
5686  }
5687  else if (c == -1 || !ISASCII(c)) goto eof;
5688  else {
5689  return ((c & 0xff) | 0x80);
5690  }
5691 
5692  case 'C':
5693  if ((c = nextc()) != '-') {
5694  pushback(c);
5695  goto eof;
5696  }
5697  case 'c':
5698  if (flags & ESCAPE_CONTROL) goto eof;
5699  if ((c = nextc())== '\\') {
5700  if (peek('u')) goto eof;
5701  c = read_escape(flags|ESCAPE_CONTROL, encp);
5702  }
5703  else if (c == '?')
5704  return 0177;
5705  else if (c == -1 || !ISASCII(c)) goto eof;
5706  return c & 0x9f;
5707 
5708  eof:
5709  case -1:
5710  yyerror("Invalid escape character syntax");
5711  return '\0';
5712 
5713  default:
5714  return c;
5715  }
5716 }
5717 
5718 static void
5719 parser_tokaddmbc(struct parser_params *parser, int c, rb_encoding *enc)
5720 {
5721  int len = rb_enc_codelen(c, enc);
5722  rb_enc_mbcput(c, tokspace(len), enc);
5723 }
5724 
5725 static int
5726 parser_tokadd_escape(struct parser_params *parser, rb_encoding **encp)
5727 {
5728  int c;
5729  int flags = 0;
5730  size_t numlen;
5731 
5732  first:
5733  switch (c = nextc()) {
5734  case '\n':
5735  return 0; /* just ignore */
5736 
5737  case '0': case '1': case '2': case '3': /* octal constant */
5738  case '4': case '5': case '6': case '7':
5739  {
5740  ruby_scan_oct(--lex_p, 3, &numlen);
5741  if (numlen == 0) goto eof;
5742  lex_p += numlen;
5743  tokcopy((int)numlen + 1);
5744  }
5745  return 0;
5746 
5747  case 'x': /* hex constant */
5748  {
5749  tok_hex(&numlen);
5750  if (numlen == 0) return -1;
5751  tokcopy((int)numlen + 2);
5752  }
5753  return 0;
5754 
5755  case 'M':
5756  if (flags & ESCAPE_META) goto eof;
5757  if ((c = nextc()) != '-') {
5758  pushback(c);
5759  goto eof;
5760  }
5761  tokcopy(3);
5762  flags |= ESCAPE_META;
5763  goto escaped;
5764 
5765  case 'C':
5766  if (flags & ESCAPE_CONTROL) goto eof;
5767  if ((c = nextc()) != '-') {
5768  pushback(c);
5769  goto eof;
5770  }
5771  tokcopy(3);
5772  goto escaped;
5773 
5774  case 'c':
5775  if (flags & ESCAPE_CONTROL) goto eof;
5776  tokcopy(2);
5777  flags |= ESCAPE_CONTROL;
5778  escaped:
5779  if ((c = nextc()) == '\\') {
5780  goto first;
5781  }
5782  else if (c == -1) goto eof;
5783  tokadd(c);
5784  return 0;
5785 
5786  eof:
5787  case -1:
5788  yyerror("Invalid escape character syntax");
5789  return -1;
5790 
5791  default:
5792  tokadd('\\');
5793  tokadd(c);
5794  }
5795  return 0;
5796 }
5797 
5798 static int
5799 parser_regx_options(struct parser_params *parser)
5800 {
5801  int kcode = 0;
5802  int kopt = 0;
5803  int options = 0;
5804  int c, opt, kc;
5805 
5806  newtok();
5807  while (c = nextc(), ISALPHA(c)) {
5808  if (c == 'o') {
5809  options |= RE_OPTION_ONCE;
5810  }
5811  else if (rb_char_to_option_kcode(c, &opt, &kc)) {
5812  if (kc >= 0) {
5813  if (kc != rb_ascii8bit_encindex()) kcode = c;
5814  kopt = opt;
5815  }
5816  else {
5817  options |= opt;
5818  }
5819  }
5820  else {
5821  tokadd(c);
5822  }
5823  }
5824  options |= kopt;
5825  pushback(c);
5826  if (toklen()) {
5827  tokfix();
5828  compile_error(PARSER_ARG "unknown regexp option%s - %s",
5829  toklen() > 1 ? "s" : "", tok());
5830  }
5831  return options | RE_OPTION_ENCODING(kcode);
5832 }
5833 
5834 static void
5835 dispose_string(VALUE str)
5836 {
5837  /* TODO: should use another API? */
5838  if (RBASIC(str)->flags & RSTRING_NOEMBED)
5839  xfree(RSTRING_PTR(str));
5840  rb_gc_force_recycle(str);
5841 }
5842 
5843 static int
5844 parser_tokadd_mbchar(struct parser_params *parser, int c)
5845 {
5846  int len = parser_precise_mbclen();
5847  if (!MBCLEN_CHARFOUND_P(len)) {
5848  compile_error(PARSER_ARG "invalid multibyte char (%s)", parser_encoding_name());
5849  return -1;
5850  }
5851  tokadd(c);
5852  lex_p += --len;
5853  if (len > 0) tokcopy(len);
5854  return c;
5855 }
5856 
5857 #define tokadd_mbchar(c) parser_tokadd_mbchar(parser, (c))
5858 
5859 static int
5860 parser_tokadd_string(struct parser_params *parser,
5861  int func, int term, int paren, long *nest,
5862  rb_encoding **encp)
5863 {
5864  int c;
5865  int has_nonascii = 0;
5866  rb_encoding *enc = *encp;
5867  char *errbuf = 0;
5868  static const char mixed_msg[] = "%s mixed within %s source";
5869 
5870 #define mixed_error(enc1, enc2) if (!errbuf) { \
5871  size_t len = sizeof(mixed_msg) - 4; \
5872  len += strlen(rb_enc_name(enc1)); \
5873  len += strlen(rb_enc_name(enc2)); \
5874  errbuf = ALLOCA_N(char, len); \
5875  snprintf(errbuf, len, mixed_msg, \
5876  rb_enc_name(enc1), \
5877  rb_enc_name(enc2)); \
5878  yyerror(errbuf); \
5879  }
5880 #define mixed_escape(beg, enc1, enc2) do { \
5881  const char *pos = lex_p; \
5882  lex_p = (beg); \
5883  mixed_error((enc1), (enc2)); \
5884  lex_p = pos; \
5885  } while (0)
5886 
5887  while ((c = nextc()) != -1) {
5888  if (paren && c == paren) {
5889  ++*nest;
5890  }
5891  else if (c == term) {
5892  if (!nest || !*nest) {
5893  pushback(c);
5894  break;
5895  }
5896  --*nest;
5897  }
5898  else if ((func & STR_FUNC_EXPAND) && c == '#' && lex_p < lex_pend) {
5899  int c2 = *lex_p;
5900  if (c2 == '$' || c2 == '@' || c2 == '{') {
5901  pushback(c);
5902  break;
5903  }
5904  }
5905  else if (c == '\\') {
5906  const char *beg = lex_p - 1;
5907  c = nextc();
5908  switch (c) {
5909  case '\n':
5910  if (func & STR_FUNC_QWORDS) break;
5911  if (func & STR_FUNC_EXPAND) continue;
5912  tokadd('\\');
5913  break;
5914 
5915  case '\\':
5916  if (func & STR_FUNC_ESCAPE) tokadd(c);
5917  break;
5918 
5919  case 'u':
5920  if ((func & STR_FUNC_EXPAND) == 0) {
5921  tokadd('\\');
5922  break;
5923  }
5924  parser_tokadd_utf8(parser, &enc, 1,
5925  func & STR_FUNC_SYMBOL,
5926  func & STR_FUNC_REGEXP);
5927  if (has_nonascii && enc != *encp) {
5928  mixed_escape(beg, enc, *encp);
5929  }
5930  continue;
5931 
5932  default:
5933  if (c == -1) return -1;
5934  if (!ISASCII(c)) {
5935  if ((func & STR_FUNC_EXPAND) == 0) tokadd('\\');
5936  goto non_ascii;
5937  }
5938  if (func & STR_FUNC_REGEXP) {
5939  pushback(c);
5940  if ((c = tokadd_escape(&enc)) < 0)
5941  return -1;
5942  if (has_nonascii && enc != *encp) {
5943  mixed_escape(beg, enc, *encp);
5944  }
5945  continue;
5946  }
5947  else if (func & STR_FUNC_EXPAND) {
5948  pushback(c);
5949  if (func & STR_FUNC_ESCAPE) tokadd('\\');
5950  c = read_escape(0, &enc);
5951  }
5952  else if ((func & STR_FUNC_QWORDS) && ISSPACE(c)) {
5953  /* ignore backslashed spaces in %w */
5954  }
5955  else if (c != term && !(paren && c == paren)) {
5956  tokadd('\\');
5957  pushback(c);
5958  continue;
5959  }
5960  }
5961  }
5962  else if (!parser_isascii()) {
5963  non_ascii:
5964  has_nonascii = 1;
5965  if (enc != *encp) {
5966  mixed_error(enc, *encp);
5967  continue;
5968  }
5969  if (tokadd_mbchar(c) == -1) return -1;
5970  continue;
5971  }
5972  else if ((func & STR_FUNC_QWORDS) && ISSPACE(c)) {
5973  pushback(c);
5974  break;
5975  }
5976  if (c & 0x80) {
5977  has_nonascii = 1;
5978  if (enc != *encp) {
5979  mixed_error(enc, *encp);
5980  continue;
5981  }
5982  }
5983  tokadd(c);
5984  }
5985  *encp = enc;
5986  return c;
5987 }
5988 
5989 #define NEW_STRTERM(func, term, paren) \
5990  rb_node_newnode(NODE_STRTERM, (func), (term) | ((paren) << (CHAR_BIT * 2)), 0)
5991 
5992 #ifdef RIPPER
5993 static void
5994 ripper_flush_string_content(struct parser_params *parser, rb_encoding *enc)
5995 {
5996  if (!NIL_P(parser->delayed)) {
5997  ptrdiff_t len = lex_p - parser->tokp;
5998  if (len > 0) {
5999  rb_enc_str_buf_cat(parser->delayed, parser->tokp, len, enc);
6000  }
6001  ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
6002  parser->tokp = lex_p;
6003  }
6004 }
6005 
6006 #define flush_string_content(enc) ripper_flush_string_content(parser, (enc))
6007 #else
6008 #define flush_string_content(enc) ((void)(enc))
6009 #endif
6010 
6011 RUBY_FUNC_EXPORTED const unsigned int ruby_global_name_punct_bits[(0x7e - 0x20 + 31) / 32];
6012 /* this can be shared with ripper, since it's independent from struct
6013  * parser_params. */
6014 #ifndef RIPPER
6015 #define BIT(c, idx) (((c) / 32 - 1 == idx) ? (1U << ((c) % 32)) : 0)
6016 #define SPECIAL_PUNCT(idx) ( \
6017  BIT('~', idx) | BIT('*', idx) | BIT('$', idx) | BIT('?', idx) | \
6018  BIT('!', idx) | BIT('@', idx) | BIT('/', idx) | BIT('\\', idx) | \
6019  BIT(';', idx) | BIT(',', idx) | BIT('.', idx) | BIT('=', idx) | \
6020  BIT(':', idx) | BIT('<', idx) | BIT('>', idx) | BIT('\"', idx) | \
6021  BIT('&', idx) | BIT('`', idx) | BIT('\'', idx) | BIT('+', idx) | \
6022  BIT('0', idx))
6023 const unsigned int ruby_global_name_punct_bits[] = {
6024  SPECIAL_PUNCT(0),
6025  SPECIAL_PUNCT(1),
6026  SPECIAL_PUNCT(2),
6027 };
6028 #undef BIT
6029 #undef SPECIAL_PUNCT
6030 #endif
6031 
6032 static inline int
6033 is_global_name_punct(const char c)
6034 {
6035  if (c <= 0x20 || 0x7e < c) return 0;
6036  return (ruby_global_name_punct_bits[(c - 0x20) / 32] >> (c % 32)) & 1;
6037 }
6038 
6039 static int
6041 {
6042  int c;
6043  const char *p = lex_p;
6044 
6045  if (p + 1 >= lex_pend) return 0;
6046  c = *p++;
6047  switch (c) {
6048  case '$':
6049  if ((c = *p) == '-') {
6050  if (++p >= lex_pend) return 0;
6051  c = *p;
6052  }
6053  else if (is_global_name_punct(c) || ISDIGIT(c)) {
6054  return tSTRING_DVAR;
6055  }
6056  break;
6057  case '@':
6058  if ((c = *p) == '@') {
6059  if (++p >= lex_pend) return 0;
6060  c = *p;
6061  }
6062  break;
6063  case '{':
6064  lex_p = p;
6065  command_start = TRUE;
6066  return tSTRING_DBEG;
6067  default:
6068  return 0;
6069  }
6070  if (!ISASCII(c) || c == '_' || ISALPHA(c))
6071  return tSTRING_DVAR;
6072  return 0;
6073 }
6074 
6075 static int
6076 parser_parse_string(struct parser_params *parser, NODE *quote)
6077 {
6078  int func = (int)quote->nd_func;
6079  int term = nd_term(quote);
6080  int paren = nd_paren(quote);
6081  int c, space = 0;
6082  rb_encoding *enc = parser->enc;
6083 
6084  if (func == -1) return tSTRING_END;
6085  c = nextc();
6086  if ((func & STR_FUNC_QWORDS) && ISSPACE(c)) {
6087  do {c = nextc();} while (ISSPACE(c));
6088  space = 1;
6089  }
6090  if (c == term && !quote->nd_nest) {
6091  if (func & STR_FUNC_QWORDS) {
6092  quote->nd_func = -1;
6093  return ' ';
6094  }
6095  if (!(func & STR_FUNC_REGEXP)) return tSTRING_END;
6097  return tREGEXP_END;
6098  }
6099  if (space) {
6100  pushback(c);
6101  return ' ';
6102  }
6103  newtok();
6104  if ((func & STR_FUNC_EXPAND) && c == '#') {
6105  int t = parser_peek_variable_name(parser);
6106  if (t) return t;
6107  tokadd('#');
6108  c = nextc();
6109  }
6110  pushback(c);
6111  if (tokadd_string(func, term, paren, &quote->nd_nest,
6112  &enc) == -1) {
6113  ruby_sourceline = nd_line(quote);
6114  if (func & STR_FUNC_REGEXP) {
6115  if (parser->eofp)
6116  compile_error(PARSER_ARG "unterminated regexp meets end of file");
6117  return tREGEXP_END;
6118  }
6119  else {
6120  if (parser->eofp)
6121  compile_error(PARSER_ARG "unterminated string meets end of file");
6122  return tSTRING_END;
6123  }
6124  }
6125 
6126  tokfix();
6127  set_yylval_str(STR_NEW3(tok(), toklen(), enc, func));
6128  flush_string_content(enc);
6129 
6130  return tSTRING_CONTENT;
6131 }
6132 
6133 static int
6135 {
6136  int c = nextc(), term, func = 0;
6137  long len;
6138 
6139  if (c == '-') {
6140  c = nextc();
6141  func = STR_FUNC_INDENT;
6142  }
6143  switch (c) {
6144  case '\'':
6145  func |= str_squote; goto quoted;
6146  case '"':
6147  func |= str_dquote; goto quoted;
6148  case '`':
6149  func |= str_xquote;
6150  quoted:
6151  newtok();
6152  tokadd(func);
6153  term = c;
6154  while ((c = nextc()) != -1 && c != term) {
6155  if (tokadd_mbchar(c) == -1) return 0;
6156  }
6157  if (c == -1) {
6158  compile_error(PARSER_ARG "unterminated here document identifier");
6159  return 0;
6160  }
6161  break;
6162 
6163  default:
6164  if (!parser_is_identchar()) {
6165  pushback(c);
6166  if (func & STR_FUNC_INDENT) {
6167  pushback('-');
6168  }
6169  return 0;
6170  }
6171  newtok();
6172  term = '"';
6173  tokadd(func |= str_dquote);
6174  do {
6175  if (tokadd_mbchar(c) == -1) return 0;
6176  } while ((c = nextc()) != -1 && parser_is_identchar());
6177  pushback(c);
6178  break;
6179  }
6180 
6181  tokfix();
6182 #ifdef RIPPER
6183  ripper_dispatch_scan_event(parser, tHEREDOC_BEG);
6184 #endif
6185  len = lex_p - lex_pbeg;
6186  lex_goto_eol(parser);
6188  STR_NEW(tok(), toklen()), /* nd_lit */
6189  len, /* nd_nth */
6190  lex_lastline); /* nd_orig */
6192  ripper_flush(parser);
6193  return term == '`' ? tXSTRING_BEG : tSTRING_BEG;
6194 }
6195 
6196 static void
6197 parser_heredoc_restore(struct parser_params *parser, NODE *here)
6198 {
6199  VALUE line;
6200 
6201  line = here->nd_orig;
6202  lex_lastline = line;
6203  lex_pbeg = RSTRING_PTR(line);
6204  lex_pend = lex_pbeg + RSTRING_LEN(line);
6205  lex_p = lex_pbeg + here->nd_nth;
6207  ruby_sourceline = nd_line(here);
6208  dispose_string(here->nd_lit);
6209  rb_gc_force_recycle((VALUE)here);
6210  ripper_flush(parser);
6211 }
6212 
6213 static int
6214 parser_whole_match_p(struct parser_params *parser,
6215  const char *eos, long len, int indent)
6216 {
6217  const char *p = lex_pbeg;
6218  long n;
6219 
6220  if (indent) {
6221  while (*p && ISSPACE(*p)) p++;
6222  }
6223  n = lex_pend - (p + len);
6224  if (n < 0 || (n > 0 && p[len] != '\n' && p[len] != '\r')) return FALSE;
6225  return strncmp(eos, p, len) == 0;
6226 }
6227 
6228 #ifdef RIPPER
6229 static void
6230 ripper_dispatch_heredoc_end(struct parser_params *parser)
6231 {
6232  if (!NIL_P(parser->delayed))
6233  ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
6234  lex_goto_eol(parser);
6235  ripper_dispatch_ignored_scan_event(parser, tHEREDOC_END);
6236 }
6237 
6238 #define dispatch_heredoc_end() ripper_dispatch_heredoc_end(parser)
6239 #else
6240 #define dispatch_heredoc_end() ((void)0)
6241 #endif
6242 
6243 static int
6244 parser_here_document(struct parser_params *parser, NODE *here)
6245 {
6246  int c, func, indent = 0;
6247  const char *eos, *p, *pend;
6248  long len;
6249  VALUE str = 0;
6250  rb_encoding *enc = parser->enc;
6251 
6252  eos = RSTRING_PTR(here->nd_lit);
6253  len = RSTRING_LEN(here->nd_lit) - 1;
6254  indent = (func = *eos++) & STR_FUNC_INDENT;
6255 
6256  if ((c = nextc()) == -1) {
6257  error:
6258  compile_error(PARSER_ARG "can't find string \"%s\" anywhere before EOF", eos);
6259 #ifdef RIPPER
6260  if (NIL_P(parser->delayed)) {
6261  ripper_dispatch_scan_event(parser, tSTRING_CONTENT);
6262  }
6263  else {
6264  if (str ||
6265  ((len = lex_p - parser->tokp) > 0 &&
6266  (str = STR_NEW3(parser->tokp, len, enc, func), 1))) {
6267  rb_str_append(parser->delayed, str);
6268  }
6269  ripper_dispatch_delayed_token(parser, tSTRING_CONTENT);
6270  }
6271  lex_goto_eol(parser);
6272 #endif
6273  restore:
6275  lex_strterm = 0;
6276  return 0;
6277  }
6278  if (was_bol() && whole_match_p(eos, len, indent)) {
6281  return tSTRING_END;
6282  }
6283 
6284  if (!(func & STR_FUNC_EXPAND)) {
6285  do {
6287  pend = lex_pend;
6288  if (pend > p) {
6289  switch (pend[-1]) {
6290  case '\n':
6291  if (--pend == p || pend[-1] != '\r') {
6292  pend++;
6293  break;
6294  }
6295  case '\r':
6296  --pend;
6297  }
6298  }
6299  if (str)
6300  rb_str_cat(str, p, pend - p);
6301  else
6302  str = STR_NEW(p, pend - p);
6303  if (pend < lex_pend) rb_str_cat(str, "\n", 1);
6304  lex_goto_eol(parser);
6305  if (nextc() == -1) {
6306  if (str) dispose_string(str);
6307  goto error;
6308  }
6309  } while (!whole_match_p(eos, len, indent));
6310  }
6311  else {
6312  /* int mb = ENC_CODERANGE_7BIT, *mbp = &mb;*/
6313  newtok();
6314  if (c == '#') {
6315  int t = parser_peek_variable_name(parser);
6316  if (t) return t;
6317  tokadd('#');
6318  c = nextc();
6319  }
6320  do {
6321  pushback(c);
6322  if ((c = tokadd_string(func, '\n', 0, NULL, &enc)) == -1) {
6323  if (parser->eofp) goto error;
6324  goto restore;
6325  }
6326  if (c != '\n') {
6327  set_yylval_str(STR_NEW3(tok(), toklen(), enc, func));
6328  flush_string_content(enc);
6329  return tSTRING_CONTENT;
6330  }
6331  tokadd(nextc());
6332  /* if (mbp && mb == ENC_CODERANGE_UNKNOWN) mbp = 0;*/
6333  if ((c = nextc()) == -1) goto error;
6334  } while (!whole_match_p(eos, len, indent));
6335  str = STR_NEW3(tok(), toklen(), enc, func);
6336  }
6339  lex_strterm = NEW_STRTERM(-1, 0, 0);
6340  set_yylval_str(str);
6341  return tSTRING_CONTENT;
6342 }
6343 
6344 #include "lex.c"
6345 
6346 static void
6347 arg_ambiguous_gen(struct parser_params *parser)
6348 {
6349 #ifndef RIPPER
6350  rb_warning0("ambiguous first argument; put parentheses or even spaces");
6351 #else
6353 #endif
6354 }
6355 #define arg_ambiguous() (arg_ambiguous_gen(parser), 1)
6356 
6357 static ID
6358 formal_argument_gen(struct parser_params *parser, ID lhs)
6359 {
6360 #ifndef RIPPER
6361  if (!is_local_id(lhs))
6362  yyerror("formal argument must be local variable");
6363 #endif
6364  shadowing_lvar(lhs);
6365  return lhs;
6366 }
6367 
6368 static int
6369 lvar_defined_gen(struct parser_params *parser, ID id)
6370 {
6371  return (dyna_in_block() && dvar_defined_get(id)) || local_id(id);
6372 }
6373 
6374 /* emacsen -*- hack */
6375 static long
6376 parser_encode_length(struct parser_params *parser, const char *name, long len)
6377 {
6378  long nlen;
6379 
6380  if (len > 5 && name[nlen = len - 5] == '-') {
6381  if (rb_memcicmp(name + nlen + 1, "unix", 4) == 0)
6382  return nlen;
6383  }
6384  if (len > 4 && name[nlen = len - 4] == '-') {
6385  if (rb_memcicmp(name + nlen + 1, "dos", 3) == 0)
6386  return nlen;
6387  if (rb_memcicmp(name + nlen + 1, "mac", 3) == 0 &&
6388  !(len == 8 && rb_memcicmp(name, "utf8-mac", len) == 0))
6389  /* exclude UTF8-MAC because the encoding named "UTF8" doesn't exist in Ruby */
6390  return nlen;
6391  }
6392  return len;
6393 }
6394 
6395 static void
6396 parser_set_encode(struct parser_params *parser, const char *name)
6397 {
6398  int idx = rb_enc_find_index(name);
6399  rb_encoding *enc;
6400  VALUE excargs[3];
6401 
6402  if (idx < 0) {
6403  excargs[1] = rb_sprintf("unknown encoding name: %s", name);
6404  error:
6405  excargs[0] = rb_eArgError;
6406  excargs[2] = rb_make_backtrace();
6407  rb_ary_unshift(excargs[2], rb_sprintf("%s:%d", ruby_sourcefile, ruby_sourceline));
6408  rb_exc_raise(rb_make_exception(3, excargs));
6409  }
6410  enc = rb_enc_from_index(idx);
6411  if (!rb_enc_asciicompat(enc)) {
6412  excargs[1] = rb_sprintf("%s is not ASCII compatible", rb_enc_name(enc));
6413  goto error;
6414  }
6415  parser->enc = enc;
6416 #ifndef RIPPER
6417  if (ruby_debug_lines) {
6418  long i, n = RARRAY_LEN(ruby_debug_lines);
6419  const VALUE *p = RARRAY_PTR(ruby_debug_lines);
6420  for (i = 0; i < n; ++i) {
6421  rb_enc_associate_index(*p, idx);
6422  }
6423  }
6424 #endif
6425 }
6426 
6427 static int
6428 comment_at_top(struct parser_params *parser)
6429 {
6430  const char *p = lex_pbeg, *pend = lex_p - 1;
6431  if (parser->line_count != (parser->has_shebang ? 2 : 1)) return 0;
6432  while (p < pend) {
6433  if (!ISSPACE(*p)) return 0;
6434  p++;
6435  }
6436  return 1;
6437 }
6438 
6439 #ifndef RIPPER
6440 typedef long (*rb_magic_comment_length_t)(struct parser_params *parser, const char *name, long len);
6441 typedef void (*rb_magic_comment_setter_t)(struct parser_params *parser, const char *name, const char *val);
6442 
6443 static void
6444 magic_comment_encoding(struct parser_params *parser, const char *name, const char *val)
6445 {
6446  if (!comment_at_top(parser)) {
6447  return;
6448  }
6449  parser_set_encode(parser, val);
6450 }
6451 
6452 static void
6453 parser_set_token_info(struct parser_params *parser, const char *name, const char *val)
6454 {
6455  int *p = &parser->parser_token_info_enabled;
6456 
6457  switch (*val) {
6458  case 't': case 'T':
6459  if (strcasecmp(val, "true") == 0) {
6460  *p = TRUE;
6461  return;
6462  }
6463  break;
6464  case 'f': case 'F':
6465  if (strcasecmp(val, "false") == 0) {
6466  *p = FALSE;
6467  return;
6468  }
6469  break;
6470  }
6471  rb_compile_warning(ruby_sourcefile, ruby_sourceline, "invalid value for %s: %s", name, val);
6472 }
6473 
6474 struct magic_comment {
6475  const char *name;
6478 };
6479 
6480 static const struct magic_comment magic_comments[] = {
6483  {"warn_indent", parser_set_token_info},
6484 };
6485 #endif
6486 
6487 static const char *
6488 magic_comment_marker(const char *str, long len)
6489 {
6490  long i = 2;
6491 
6492  while (i < len) {
6493  switch (str[i]) {
6494  case '-':
6495  if (str[i-1] == '*' && str[i-2] == '-') {
6496  return str + i + 1;
6497  }
6498  i += 2;
6499  break;
6500  case '*':
6501  if (i + 1 >= len) return 0;
6502  if (str[i+1] != '-') {
6503  i += 4;
6504  }
6505  else if (str[i-1] != '-') {
6506  i += 2;
6507  }
6508  else {
6509  return str + i + 2;
6510  }
6511  break;
6512  default:
6513  i += 3;
6514  break;
6515  }
6516  }
6517  return 0;
6518 }
6519 
6520 static int
6521 parser_magic_comment(struct parser_params *parser, const char *str, long len)
6522 {
6523  VALUE name = 0, val = 0;
6524  const char *beg, *end, *vbeg, *vend;
6525 #define str_copy(_s, _p, _n) ((_s) \
6526  ? (void)(rb_str_resize((_s), (_n)), \
6527  MEMCPY(RSTRING_PTR(_s), (_p), char, (_n)), (_s)) \
6528  : (void)((_s) = STR_NEW((_p), (_n))))
6529 
6530  if (len <= 7) return FALSE;
6531  if (!(beg = magic_comment_marker(str, len))) return FALSE;
6532  if (!(end = magic_comment_marker(beg, str + len - beg))) return FALSE;
6533  str = beg;
6534  len = end - beg - 3;
6535 
6536  /* %r"([^\\s\'\":;]+)\\s*:\\s*(\"(?:\\\\.|[^\"])*\"|[^\"\\s;]+)[\\s;]*" */
6537  while (len > 0) {
6538 #ifndef RIPPER
6539  const struct magic_comment *p = magic_comments;
6540 #endif
6541  char *s;
6542  int i;
6543  long n = 0;
6544 
6545  for (; len > 0 && *str; str++, --len) {
6546  switch (*str) {
6547  case '\'': case '"': case ':': case ';':
6548  continue;
6549  }
6550  if (!ISSPACE(*str)) break;
6551  }
6552  for (beg = str; len > 0; str++, --len) {
6553  switch (*str) {
6554  case '\'': case '"': case ':': case ';':
6555  break;
6556  default:
6557  if (ISSPACE(*str)) break;
6558  continue;
6559  }
6560  break;
6561  }
6562  for (end = str; len > 0 && ISSPACE(*str); str++, --len);
6563  if (!len) break;
6564  if (*str != ':') continue;
6565 
6566  do str++; while (--len > 0 && ISSPACE(*str));
6567  if (!len) break;
6568  if (*str == '"') {
6569  for (vbeg = ++str; --len > 0 && *str != '"'; str++) {
6570  if (*str == '\\') {
6571  --len;
6572  ++str;
6573  }
6574  }
6575  vend = str;
6576  if (len) {
6577  --len;
6578  ++str;
6579  }
6580  }
6581  else {
6582  for (vbeg = str; len > 0 && *str != '"' && *str != ';' && !ISSPACE(*str); --len, str++);
6583  vend = str;
6584  }
6585  while (len > 0 && (*str == ';' || ISSPACE(*str))) --len, str++;
6586 
6587  n = end - beg;
6588  str_copy(name, beg, n);
6589  s = RSTRING_PTR(name);
6590  for (i = 0; i < n; ++i) {
6591  if (s[i] == '-') s[i] = '_';
6592  }
6593 #ifndef RIPPER
6594  do {
6595  if (STRNCASECMP(p->name, s, n) == 0) {
6596  n = vend - vbeg;
6597  if (p->length) {
6598  n = (*p->length)(parser, vbeg, n);
6599  }
6600  str_copy(val, vbeg, n);
6601  (*p->func)(parser, s, RSTRING_PTR(val));
6602  break;
6603  }
6604  } while (++p < magic_comments + numberof(magic_comments));
6605 #else
6606  str_copy(val, vbeg, vend - vbeg);
6607  dispatch2(magic_comment, name, val);
6608 #endif
6609  }
6610 
6611  return TRUE;
6612 }
6613 
6614 static void
6615 set_file_encoding(struct parser_params *parser, const char *str, const char *send)
6616 {
6617  int sep = 0;
6618  const char *beg = str;
6619  VALUE s;
6620 
6621  for (;;) {
6622  if (send - str <= 6) return;
6623  switch (str[6]) {
6624  case 'C': case 'c': str += 6; continue;
6625  case 'O': case 'o': str += 5; continue;
6626  case 'D': case 'd': str += 4; continue;
6627  case 'I': case 'i': str += 3; continue;
6628  case 'N': case 'n': str += 2; continue;
6629  case 'G': case 'g': str += 1; continue;
6630  case '=': case ':':
6631  sep = 1;
6632  str += 6;
6633  break;
6634  default:
6635  str += 6;
6636  if (ISSPACE(*str)) break;
6637  continue;
6638  }
6639  if (STRNCASECMP(str-6, "coding", 6) == 0) break;
6640  }
6641  for (;;) {
6642  do {
6643  if (++str >= send) return;
6644  } while (ISSPACE(*str));
6645  if (sep) break;
6646  if (*str != '=' && *str != ':') return;
6647  sep = 1;
6648  str++;
6649  }
6650  beg = str;
6651  while ((*str == '-' || *str == '_' || ISALNUM(*str)) && ++str < send);
6652  s = rb_str_new(beg, parser_encode_length(parser, beg, str - beg));
6653  parser_set_encode(parser, RSTRING_PTR(s));
6654  rb_str_resize(s, 0);
6655 }
6656 
6657 static void
6658 parser_prepare(struct parser_params *parser)
6659 {
6660  int c = nextc();
6661  switch (c) {
6662  case '#':
6663  if (peek('!')) parser->has_shebang = 1;
6664  break;
6665  case 0xef: /* UTF-8 BOM marker */
6666  if (lex_pend - lex_p >= 2 &&
6667  (unsigned char)lex_p[0] == 0xbb &&
6668  (unsigned char)lex_p[1] == 0xbf) {
6669  parser->enc = rb_utf8_encoding();
6670  lex_p += 2;
6671  lex_pbeg = lex_p;
6672  return;
6673  }
6674  break;
6675  case EOF:
6676  return;
6677  }
6678  pushback(c);
6679  parser->enc = rb_enc_get(lex_lastline);
6680 }
6681 
6682 #define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG)
6683 #define IS_END() (lex_state == EXPR_END || lex_state == EXPR_ENDARG || lex_state == EXPR_ENDFN)
6684 #define IS_BEG() (lex_state == EXPR_BEG || lex_state == EXPR_MID || lex_state == EXPR_VALUE || lex_state == EXPR_CLASS)
6685 #define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c))
6686 #define IS_LABEL_POSSIBLE() ((lex_state == EXPR_BEG && !cmd_state) || IS_ARG())
6687 #define IS_LABEL_SUFFIX(n) (peek_n(':',(n)) && !peek_n(':', (n)+1))
6688 
6689 #ifndef RIPPER
6690 #define ambiguous_operator(op, syn) ( \
6691  rb_warning0("`"op"' after local variable is interpreted as binary operator"), \
6692  rb_warning0("even though it seems like "syn""))
6693 #else
6694 #define ambiguous_operator(op, syn) dispatch2(operator_ambiguous, ripper_intern(op), rb_str_new_cstr(syn))
6695 #endif
6696 #define warn_balanced(op, syn) ((void) \
6697  (last_state != EXPR_CLASS && last_state != EXPR_DOT && \
6698  last_state != EXPR_FNAME && last_state != EXPR_ENDFN && \
6699  last_state != EXPR_ENDARG && \
6700  space_seen && !ISSPACE(c) && \
6701  (ambiguous_operator(op, syn), 0)))
6702 
6703 static int
6704 parser_yylex(struct parser_params *parser)
6705 {
6706  register int c;
6707  int space_seen = 0;
6708  int cmd_state;
6709  enum lex_state_e last_state;
6710  rb_encoding *enc;
6711  int mb;
6712 #ifdef RIPPER
6713  int fallthru = FALSE;
6714 #endif
6715 
6716  if (lex_strterm) {
6717  int token;
6718  if (nd_type(lex_strterm) == NODE_HEREDOC) {
6719  token = here_document(lex_strterm);
6720  if (token == tSTRING_END) {
6721  lex_strterm = 0;
6722  lex_state = EXPR_END;
6723  }
6724  }
6725  else {
6726  token = parse_string(lex_strterm);
6727  if (token == tSTRING_END || token == tREGEXP_END) {
6729  lex_strterm = 0;
6730  lex_state = EXPR_END;
6731  }
6732  }
6733  return token;
6734  }
6735  cmd_state = command_start;
6736  command_start = FALSE;
6737  retry:
6738  last_state = lex_state;
6739  switch (c = nextc()) {
6740  case '\0': /* NUL */
6741  case '\004': /* ^D */
6742  case '\032': /* ^Z */
6743  case -1: /* end of script. */
6744  return 0;
6745 
6746  /* white spaces */
6747  case ' ': case '\t': case '\f': case '\r':
6748  case '\13': /* '\v' */
6749  space_seen = 1;
6750 #ifdef RIPPER
6751  while ((c = nextc())) {
6752  switch (c) {
6753  case ' ': case '\t': case '\f': case '\r':
6754  case '\13': /* '\v' */
6755  break;
6756  default:
6757  goto outofloop;
6758  }
6759  }
6760  outofloop:
6761  pushback(c);
6762  ripper_dispatch_scan_event(parser, tSP);
6763 #endif
6764  goto retry;
6765 
6766  case '#': /* it's a comment */
6767  /* no magic_comment in shebang line */
6768  if (!parser_magic_comment(parser, lex_p, lex_pend - lex_p)) {
6769  if (comment_at_top(parser)) {
6770  set_file_encoding(parser, lex_p, lex_pend);
6771  }
6772  }
6773  lex_p = lex_pend;
6774 #ifdef RIPPER
6775  ripper_dispatch_scan_event(parser, tCOMMENT);
6776  fallthru = TRUE;
6777 #endif
6778  /* fall through */
6779  case '\n':
6780  switch (lex_state) {
6781  case EXPR_BEG:
6782  case EXPR_FNAME:
6783  case EXPR_DOT:
6784  case EXPR_CLASS:
6785  case EXPR_VALUE:
6786 #ifdef RIPPER
6787  if (!fallthru) {
6788  ripper_dispatch_scan_event(parser, tIGNORED_NL);
6789  }
6790  fallthru = FALSE;
6791 #endif
6792  goto retry;
6793  default:
6794  break;
6795  }
6796  while ((c = nextc())) {
6797  switch (c) {
6798  case ' ': case '\t': case '\f': case '\r':
6799  case '\13': /* '\v' */
6800  space_seen = 1;
6801  break;
6802  case '.': {
6803  if ((c = nextc()) != '.') {
6804  pushback(c);
6805  pushback('.');
6806  goto retry;
6807  }
6808  }
6809  default:
6810  --ruby_sourceline;
6812  case -1: /* EOF no decrement*/
6813  lex_goto_eol(parser);
6814 #ifdef RIPPER
6815  if (c != -1) {
6816  parser->tokp = lex_p;
6817  }
6818 #endif
6819  goto normal_newline;
6820  }
6821  }
6822  normal_newline:
6823  command_start = TRUE;
6824  lex_state = EXPR_BEG;
6825  return '\n';
6826 
6827  case '*':
6828  if ((c = nextc()) == '*') {
6829  if ((c = nextc()) == '=') {
6831  lex_state = EXPR_BEG;
6832  return tOP_ASGN;
6833  }
6834  pushback(c);
6835  c = tPOW;
6836  }
6837  else {
6838  if (c == '=') {
6839  set_yylval_id('*');
6840  lex_state = EXPR_BEG;
6841  return tOP_ASGN;
6842  }
6843  pushback(c);
6844  if (IS_SPCARG(c)) {
6845  rb_warning0("`*' interpreted as argument prefix");
6846  c = tSTAR;
6847  }
6848  else if (IS_BEG()) {
6849  c = tSTAR;
6850  }
6851  else {
6852  warn_balanced("*", "argument prefix");
6853  c = '*';
6854  }
6855  }
6856  switch (lex_state) {
6857  case EXPR_FNAME: case EXPR_DOT:
6858  lex_state = EXPR_ARG; break;
6859  default:
6860  lex_state = EXPR_BEG; break;
6861  }
6862  return c;
6863 
6864  case '!':
6865  c = nextc();
6866  if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
6867  lex_state = EXPR_ARG;
6868  if (c == '@') {
6869  return '!';
6870  }
6871  }
6872  else {
6873  lex_state = EXPR_BEG;
6874  }
6875  if (c == '=') {
6876  return tNEQ;
6877  }
6878  if (c == '~') {
6879  return tNMATCH;
6880  }
6881  pushback(c);
6882  return '!';
6883 
6884  case '=':
6885  if (was_bol()) {
6886  /* skip embedded rd document */
6887  if (strncmp(lex_p, "begin", 5) == 0 && ISSPACE(lex_p[5])) {
6888 #ifdef RIPPER
6889  int first_p = TRUE;
6890 
6891  lex_goto_eol(parser);
6892  ripper_dispatch_scan_event(parser, tEMBDOC_BEG);
6893 #endif
6894  for (;;) {
6895  lex_goto_eol(parser);
6896 #ifdef RIPPER
6897  if (!first_p) {
6898  ripper_dispatch_scan_event(parser, tEMBDOC);
6899  }
6900  first_p = FALSE;
6901 #endif
6902  c = nextc();
6903  if (c == -1) {
6904  compile_error(PARSER_ARG "embedded document meets end of file");
6905  return 0;
6906  }
6907  if (c != '=') continue;
6908  if (strncmp(lex_p, "end", 3) == 0 &&
6909  (lex_p + 3 == lex_pend || ISSPACE(lex_p[3]))) {
6910  break;
6911  }
6912  }
6913  lex_goto_eol(parser);
6914 #ifdef RIPPER
6915  ripper_dispatch_scan_event(parser, tEMBDOC_END);
6916 #endif
6917  goto retry;
6918  }
6919  }
6920 
6921  switch (lex_state) {
6922  case EXPR_FNAME: case EXPR_DOT:
6923  lex_state = EXPR_ARG; break;
6924  default:
6925  lex_state = EXPR_BEG; break;
6926  }
6927  if ((c = nextc()) == '=') {
6928  if ((c = nextc()) == '=') {
6929  return tEQQ;
6930  }
6931  pushback(c);
6932  return tEQ;
6933  }
6934  if (c == '~') {
6935  return tMATCH;
6936  }
6937  else if (c == '>') {
6938  return tASSOC;
6939  }
6940  pushback(c);
6941  return '=';
6942 
6943  case '<':
6944  last_state = lex_state;
6945  c = nextc();
6946  if (c == '<' &&
6947  lex_state != EXPR_DOT &&
6948  lex_state != EXPR_CLASS &&
6949  !IS_END() &&
6950  (!IS_ARG() || space_seen)) {
6951  int token = heredoc_identifier();
6952  if (token) return token;
6953  }
6954  switch (lex_state) {
6955  case EXPR_FNAME: case EXPR_DOT:
6956  lex_state = EXPR_ARG; break;
6957  default:
6958  lex_state = EXPR_BEG; break;
6959  }
6960  if (c == '=') {
6961  if ((c = nextc()) == '>') {
6962  return tCMP;
6963  }
6964  pushback(c);
6965  return tLEQ;
6966  }
6967  if (c == '<') {
6968  if ((c = nextc()) == '=') {
6970  lex_state = EXPR_BEG;
6971  return tOP_ASGN;
6972  }
6973  pushback(c);
6974  warn_balanced("<<", "here document");
6975  return tLSHFT;
6976  }
6977  pushback(c);
6978  return '<';
6979 
6980  case '>':
6981  switch (lex_state) {
6982  case EXPR_FNAME: case EXPR_DOT:
6983  lex_state = EXPR_ARG; break;
6984  default:
6985  lex_state = EXPR_BEG; break;
6986  }
6987  if ((c = nextc()) == '=') {
6988  return tGEQ;
6989  }
6990  if (c == '>') {
6991  if ((c = nextc()) == '=') {
6993  lex_state = EXPR_BEG;
6994  return tOP_ASGN;
6995  }
6996  pushback(c);
6997  return tRSHFT;
6998  }
6999  pushback(c);
7000  return '>';
7001 
7002  case '"':
7003  lex_strterm = NEW_STRTERM(str_dquote, '"', 0);
7004  return tSTRING_BEG;
7005 
7006  case '`':
7007  if (lex_state == EXPR_FNAME) {
7009  return c;
7010  }
7011  if (lex_state == EXPR_DOT) {
7012  if (cmd_state)
7014  else
7015  lex_state = EXPR_ARG;
7016  return c;
7017  }
7018  lex_strterm = NEW_STRTERM(str_xquote, '`', 0);
7019  return tXSTRING_BEG;
7020 
7021  case '\'':
7022  lex_strterm = NEW_STRTERM(str_squote, '\'', 0);
7023  return tSTRING_BEG;
7024 
7025  case '?':
7026  if (IS_END()) {
7028  return '?';
7029  }
7030  c = nextc();
7031  if (c == -1) {
7032  compile_error(PARSER_ARG "incomplete character syntax");
7033  return 0;
7034  }
7035  if (rb_enc_isspace(c, parser->enc)) {
7036  if (!IS_ARG()) {
7037  int c2 = 0;
7038  switch (c) {
7039  case ' ':
7040  c2 = 's';
7041  break;
7042  case '\n':
7043  c2 = 'n';
7044  break;
7045  case '\t':
7046  c2 = 't';
7047  break;
7048  case '\v':
7049  c2 = 'v';
7050  break;
7051  case '\r':
7052  c2 = 'r';
7053  break;
7054  case '\f':
7055  c2 = 'f';
7056  break;
7057  }
7058  if (c2) {
7059  rb_warnI("invalid character syntax; use ?\\%c", c2);
7060  }
7061  }
7062  ternary:
7063  pushback(c);
7065  return '?';
7066  }
7067  newtok();
7068  enc = parser->enc;
7069  if (!parser_isascii()) {
7070  if (tokadd_mbchar(c) == -1) return 0;
7071  }
7072  else if ((rb_enc_isalnum(c, parser->enc) || c == '_') &&
7073  lex_p < lex_pend && is_identchar(lex_p, lex_pend, parser->enc)) {
7074  goto ternary;
7075  }
7076  else if (c == '\\') {
7077  if (peek('u')) {
7078  nextc();
7079  c = parser_tokadd_utf8(parser, &enc, 0, 0, 0);
7080  if (0x80 <= c) {
7081  tokaddmbc(c, enc);
7082  }
7083  else {
7084  tokadd(c);
7085  }
7086  }
7087  else if (!lex_eol_p() && !(c = *lex_p, ISASCII(c))) {
7088  nextc();
7089  if (tokadd_mbchar(c) == -1) return 0;
7090  }
7091  else {
7092  c = read_escape(0, &enc);
7093  tokadd(c);
7094  }
7095  }
7096  else {
7097  tokadd(c);
7098  }
7099  tokfix();
7100  set_yylval_str(STR_NEW3(tok(), toklen(), enc, 0));
7101  lex_state = EXPR_END;
7102  return tCHAR;
7103 
7104  case '&':
7105  if ((c = nextc()) == '&') {
7106  lex_state = EXPR_BEG;
7107  if ((c = nextc()) == '=') {
7109  lex_state = EXPR_BEG;
7110  return tOP_ASGN;
7111  }
7112  pushback(c);
7113  return tANDOP;
7114  }
7115  else if (c == '=') {
7116  set_yylval_id('&');
7117  lex_state = EXPR_BEG;
7118  return tOP_ASGN;
7119  }
7120  pushback(c);
7121  if (IS_SPCARG(c)) {
7122  rb_warning0("`&' interpreted as argument prefix");
7123  c = tAMPER;
7124  }
7125  else if (IS_BEG()) {
7126  c = tAMPER;
7127  }
7128  else {
7129  warn_balanced("&", "argument prefix");
7130  c = '&';
7131  }
7132  switch (lex_state) {
7133  case EXPR_FNAME: case EXPR_DOT:
7134  lex_state = EXPR_ARG; break;
7135  default:
7136  lex_state = EXPR_BEG;
7137  }
7138  return c;
7139 
7140  case '|':
7141  if ((c = nextc()) == '|') {
7142  lex_state = EXPR_BEG;
7143  if ((c = nextc()) == '=') {
7145  lex_state = EXPR_BEG;
7146  return tOP_ASGN;
7147  }
7148  pushback(c);
7149  return tOROP;
7150  }
7151  if (c == '=') {
7152  set_yylval_id('|');
7153  lex_state = EXPR_BEG;
7154  return tOP_ASGN;
7155  }
7156  if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
7157  lex_state = EXPR_ARG;
7158  }
7159  else {
7160  lex_state = EXPR_BEG;
7161  }
7162  pushback(c);
7163  return '|';
7164 
7165  case '+':
7166  c = nextc();
7167  if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
7168  lex_state = EXPR_ARG;
7169  if (c == '@') {
7170  return tUPLUS;
7171  }
7172  pushback(c);
7173  return '+';
7174  }
7175  if (c == '=') {
7176  set_yylval_id('+');
7177  lex_state = EXPR_BEG;
7178  return tOP_ASGN;
7179  }
7180  if (IS_BEG() || (IS_SPCARG(c) && arg_ambiguous())) {
7181  lex_state = EXPR_BEG;
7182  pushback(c);
7183  if (c != -1 && ISDIGIT(c)) {
7184  c = '+';
7185  goto start_num;
7186  }
7187  return tUPLUS;
7188  }
7189  lex_state = EXPR_BEG;
7190  pushback(c);
7191  warn_balanced("+", "unary operator");
7192  return '+';
7193 
7194  case '-':
7195  c = nextc();
7196  if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
7197  lex_state = EXPR_ARG;
7198  if (c == '@') {
7199  return tUMINUS;
7200  }
7201  pushback(c);
7202  return '-';
7203  }
7204  if (c == '=') {
7205  set_yylval_id('-');
7206  lex_state = EXPR_BEG;
7207  return tOP_ASGN;
7208  }
7209  if (c == '>') {
7210  lex_state = EXPR_ARG;
7211  return tLAMBDA;
7212  }
7213  if (IS_BEG() || (IS_SPCARG(c) && arg_ambiguous())) {
7214  lex_state = EXPR_BEG;
7215  pushback(c);
7216  if (c != -1 && ISDIGIT(c)) {
7217  return tUMINUS_NUM;
7218  }
7219  return tUMINUS;
7220  }
7221  lex_state = EXPR_BEG;
7222  pushback(c);
7223  warn_balanced("-", "unary operator");
7224  return '-';
7225 
7226  case '.':
7227  lex_state = EXPR_BEG;
7228  if ((c = nextc()) == '.') {
7229  if ((c = nextc()) == '.') {
7230  return tDOT3;
7231  }
7232  pushback(c);
7233  return tDOT2;
7234  }
7235  pushback(c);
7236  if (c != -1 && ISDIGIT(c)) {
7237  yyerror("no .<digit> floating literal anymore; put 0 before dot");
7238  }
7239  lex_state = EXPR_DOT;
7240  return '.';
7241 
7242  start_num:
7243  case '0': case '1': case '2': case '3': case '4':
7244  case '5': case '6': case '7': case '8': case '9':
7245  {
7246  int is_float, seen_point, seen_e, nondigit;
7247 
7248  is_float = seen_point = seen_e = nondigit = 0;
7249  lex_state = EXPR_END;
7250  newtok();
7251  if (c == '-' || c == '+') {
7252  tokadd(c);
7253  c = nextc();
7254  }
7255  if (c == '0') {
7256 #define no_digits() do {yyerror("numeric literal without digits"); return 0;} while (0)
7257  int start = toklen();
7258  c = nextc();
7259  if (c == 'x' || c == 'X') {
7260  /* hexadecimal */
7261  c = nextc();
7262  if (c != -1 && ISXDIGIT(c)) {
7263  do {
7264  if (c == '_') {
7265  if (nondigit) break;
7266  nondigit = c;
7267  continue;
7268  }
7269  if (!ISXDIGIT(c)) break;
7270  nondigit = 0;
7271  tokadd(c);
7272  } while ((c = nextc()) != -1);
7273  }
7274  pushback(c);
7275  tokfix();
7276  if (toklen() == start) {
7277  no_digits();
7278  }
7279  else if (nondigit) goto trailing_uc;
7281  return tINTEGER;
7282  }
7283  if (c == 'b' || c == 'B') {
7284  /* binary */
7285  c = nextc();
7286  if (c == '0' || c == '1') {
7287  do {
7288  if (c == '_') {
7289  if (nondigit) break;
7290  nondigit = c;
7291  continue;
7292  }
7293  if (c != '0' && c != '1') break;
7294  nondigit = 0;
7295  tokadd(c);
7296  } while ((c = nextc()) != -1);
7297  }
7298  pushback(c);
7299  tokfix();
7300  if (toklen() == start) {
7301  no_digits();
7302  }
7303  else if (nondigit) goto trailing_uc;
7305  return tINTEGER;
7306  }
7307  if (c == 'd' || c == 'D') {
7308  /* decimal */
7309  c = nextc();
7310  if (c != -1 && ISDIGIT(c)) {
7311  do {
7312  if (c == '_') {
7313  if (nondigit) break;
7314  nondigit = c;
7315  continue;
7316  }
7317  if (!ISDIGIT(c)) break;
7318  nondigit = 0;
7319  tokadd(c);
7320  } while ((c = nextc()) != -1);
7321  }
7322  pushback(c);
7323  tokfix();
7324  if (toklen() == start) {
7325  no_digits();
7326  }
7327  else if (nondigit) goto trailing_uc;
7329  return tINTEGER;
7330  }
7331  if (c == '_') {
7332  /* 0_0 */
7333  goto octal_number;
7334  }
7335  if (c == 'o' || c == 'O') {
7336  /* prefixed octal */
7337  c = nextc();
7338  if (c == -1 || c == '_' || !ISDIGIT(c)) {
7339  no_digits();
7340  }
7341  }
7342  if (c >= '0' && c <= '7') {
7343  /* octal */
7344  octal_number:
7345  do {
7346  if (c == '_') {
7347  if (nondigit) break;
7348  nondigit = c;
7349  continue;
7350  }
7351  if (c < '0' || c > '9') break;
7352  if (c > '7') goto invalid_octal;
7353  nondigit = 0;
7354  tokadd(c);
7355  } while ((c = nextc()) != -1);
7356  if (toklen() > start) {
7357  pushback(c);
7358  tokfix();
7359  if (nondigit) goto trailing_uc;
7361  return tINTEGER;
7362  }
7363  if (nondigit) {
7364  pushback(c);
7365  goto trailing_uc;
7366  }
7367  }
7368  if (c > '7' && c <= '9') {
7369  invalid_octal:
7370  yyerror("Invalid octal digit");
7371  }
7372  else if (c == '.' || c == 'e' || c == 'E') {
7373  tokadd('0');
7374  }
7375  else {
7376  pushback(c);
7378  return tINTEGER;
7379  }
7380  }
7381 
7382  for (;;) {
7383  switch (c) {
7384  case '0': case '1': case '2': case '3': case '4':
7385  case '5': case '6': case '7': case '8': case '9':
7386  nondigit = 0;
7387  tokadd(c);
7388  break;
7389 
7390  case '.':
7391  if (nondigit) goto trailing_uc;
7392  if (seen_point || seen_e) {
7393  goto decode_num;
7394  }
7395  else {
7396  int c0 = nextc();
7397  if (c0 == -1 || !ISDIGIT(c0)) {
7398  pushback(c0);
7399  goto decode_num;
7400  }
7401  c = c0;
7402  }
7403  tokadd('.');
7404  tokadd(c);
7405  is_float++;
7406  seen_point++;
7407  nondigit = 0;
7408  break;
7409 
7410  case 'e':
7411  case 'E':
7412  if (nondigit) {
7413  pushback(c);
7414  c = nondigit;
7415  goto decode_num;
7416  }
7417  if (seen_e) {
7418  goto decode_num;
7419  }
7420  tokadd(c);
7421  seen_e++;
7422  is_float++;
7423  nondigit = c;
7424  c = nextc();
7425  if (c != '-' && c != '+') continue;
7426  tokadd(c);
7427  nondigit = c;
7428  break;
7429 
7430  case '_': /* `_' in number just ignored */
7431  if (nondigit) goto decode_num;
7432  nondigit = c;
7433  break;
7434 
7435  default:
7436  goto decode_num;
7437  }
7438  c = nextc();
7439  }
7440 
7441  decode_num:
7442  pushback(c);
7443  if (nondigit) {
7444  char tmp[30];
7445  trailing_uc:
7446  snprintf(tmp, sizeof(tmp), "trailing `%c' in number", nondigit);
7447  yyerror(tmp);
7448  }
7449  tokfix();
7450  if (is_float) {
7451  double d = strtod(tok(), 0);
7452  if (errno == ERANGE) {
7453  rb_warningS("Float %s out of range", tok());
7454  errno = 0;
7455  }
7457  return tFLOAT;
7458  }
7460  return tINTEGER;
7461  }
7462 
7463  case ')':
7464  case ']':
7465  paren_nest--;
7466  case '}':
7467  COND_LEXPOP();
7468  CMDARG_LEXPOP();
7469  if (c == ')')
7471  else
7473  return c;
7474 
7475  case ':':
7476  c = nextc();
7477  if (c == ':') {
7478  if (IS_BEG() || lex_state == EXPR_CLASS || IS_SPCARG(-1)) {
7479  lex_state = EXPR_BEG;
7480  return tCOLON3;
7481  }
7482  lex_state = EXPR_DOT;
7483  return tCOLON2;
7484  }
7485  if (IS_END() || ISSPACE(c)) {
7486  pushback(c);
7487  warn_balanced(":", "symbol literal");
7488  lex_state = EXPR_BEG;
7489  return ':';
7490  }
7491  switch (c) {
7492  case '\'':
7493  lex_strterm = NEW_STRTERM(str_ssym, c, 0);
7494  break;
7495  case '"':
7496  lex_strterm = NEW_STRTERM(str_dsym, c, 0);
7497  break;
7498  default:
7499  pushback(c);
7500  break;
7501  }
7503  return tSYMBEG;
7504 
7505  case '/':
7506  if (IS_BEG()) {
7507  lex_strterm = NEW_STRTERM(str_regexp, '/', 0);
7508  return tREGEXP_BEG;
7509  }
7510  if ((c = nextc()) == '=') {
7511  set_yylval_id('/');
7512  lex_state = EXPR_BEG;
7513  return tOP_ASGN;
7514  }
7515  pushback(c);
7516  if (IS_SPCARG(c)) {
7517  (void)arg_ambiguous();
7518  lex_strterm = NEW_STRTERM(str_regexp, '/', 0);
7519  return tREGEXP_BEG;
7520  }
7521  switch (lex_state) {
7522  case EXPR_FNAME: case EXPR_DOT:
7523  lex_state = EXPR_ARG; break;
7524  default:
7525  lex_state = EXPR_BEG; break;
7526  }
7527  warn_balanced("/", "regexp literal");
7528  return '/';
7529 
7530  case '^':
7531  if ((c = nextc()) == '=') {
7532  set_yylval_id('^');
7533  lex_state = EXPR_BEG;
7534  return tOP_ASGN;
7535  }
7536  switch (lex_state) {
7537  case EXPR_FNAME: case EXPR_DOT:
7538  lex_state = EXPR_ARG; break;
7539  default:
7540  lex_state = EXPR_BEG; break;
7541  }
7542  pushback(c);
7543  return '^';
7544 
7545  case ';':
7546  lex_state = EXPR_BEG;
7547  command_start = TRUE;
7548  return ';';
7549 
7550  case ',':
7551  lex_state = EXPR_BEG;
7552  return ',';
7553 
7554  case '~':
7555  if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
7556  if ((c = nextc()) != '@') {
7557  pushback(c);
7558  }
7559  lex_state = EXPR_ARG;
7560  }
7561  else {
7562  lex_state = EXPR_BEG;
7563  }
7564  return '~';
7565 
7566  case '(':
7567  if (IS_BEG()) {
7568  c = tLPAREN;
7569  }
7570  else if (IS_SPCARG(-1)) {
7571  c = tLPAREN_ARG;
7572  }
7573  paren_nest++;
7574  COND_PUSH(0);
7575  CMDARG_PUSH(0);
7576  lex_state = EXPR_BEG;
7577  return c;
7578 
7579  case '[':
7580  paren_nest++;
7581  if (lex_state == EXPR_FNAME || lex_state == EXPR_DOT) {
7582  lex_state = EXPR_ARG;
7583  if ((c = nextc()) == ']') {
7584  if ((c = nextc()) == '=') {
7585  return tASET;
7586  }
7587  pushback(c);
7588  return tAREF;
7589  }
7590  pushback(c);
7591  return '[';
7592  }
7593  else if (IS_BEG()) {
7594  c = tLBRACK;
7595  }
7596  else if (IS_ARG() && space_seen) {
7597  c = tLBRACK;
7598  }
7599  lex_state = EXPR_BEG;
7600  COND_PUSH(0);
7601  CMDARG_PUSH(0);
7602  return c;
7603 
7604  case '{':
7605  if (lpar_beg && lpar_beg == paren_nest) {
7606  lex_state = EXPR_BEG;
7607  lpar_beg = 0;
7608  --paren_nest;
7609  COND_PUSH(0);
7610  CMDARG_PUSH(0);
7611  return tLAMBEG;
7612  }
7613  if (IS_ARG() || lex_state == EXPR_END || lex_state == EXPR_ENDFN)
7614  c = '{'; /* block (primary) */
7615  else if (lex_state == EXPR_ENDARG)
7616  c = tLBRACE_ARG; /* block (expr) */
7617  else
7618  c = tLBRACE; /* hash */
7619  COND_PUSH(0);
7620  CMDARG_PUSH(0);
7621  lex_state = EXPR_BEG;
7622  if (c != tLBRACE) command_start = TRUE;
7623  return c;
7624 
7625  case '\\':
7626  c = nextc();
7627  if (c == '\n') {
7628  space_seen = 1;
7629 #ifdef RIPPER
7630  ripper_dispatch_scan_event(parser, tSP);
7631 #endif
7632  goto retry; /* skip \\n */
7633  }
7634  pushback(c);
7635  return '\\';
7636 
7637  case '%':
7638  if (IS_BEG()) {
7639  int term;
7640  int paren;
7641 
7642  c = nextc();
7643  quotation:
7644  if (c == -1 || !ISALNUM(c)) {
7645  term = c;
7646  c = 'Q';
7647  }
7648  else {
7649  term = nextc();
7650  if (rb_enc_isalnum(term, parser->enc) || !parser_isascii()) {
7651  yyerror("unknown type of %string");
7652  return 0;
7653  }
7654  }
7655  if (c == -1 || term == -1) {
7656  compile_error(PARSER_ARG "unterminated quoted string meets end of file");
7657  return 0;
7658  }
7659  paren = term;
7660  if (term == '(') term = ')';
7661  else if (term == '[') term = ']';
7662  else if (term == '{') term = '}';
7663  else if (term == '<') term = '>';
7664  else paren = 0;
7665 
7666  switch (c) {
7667  case 'Q':
7668  lex_strterm = NEW_STRTERM(str_dquote, term, paren);
7669  return tSTRING_BEG;
7670 
7671  case 'q':
7672  lex_strterm = NEW_STRTERM(str_squote, term, paren);
7673  return tSTRING_BEG;
7674 
7675  case 'W':
7676  lex_strterm = NEW_STRTERM(str_dword, term, paren);
7677  do {c = nextc();} while (ISSPACE(c));
7678  pushback(c);
7679  return tWORDS_BEG;
7680 
7681  case 'w':
7682  lex_strterm = NEW_STRTERM(str_sword, term, paren);
7683  do {c = nextc();} while (ISSPACE(c));
7684  pushback(c);
7685  return tQWORDS_BEG;
7686 
7687  case 'x':
7688  lex_strterm = NEW_STRTERM(str_xquote, term, paren);
7689  return tXSTRING_BEG;
7690 
7691  case 'r':
7692  lex_strterm = NEW_STRTERM(str_regexp, term, paren);
7693  return tREGEXP_BEG;
7694 
7695  case 's':
7696  lex_strterm = NEW_STRTERM(str_ssym, term, paren);
7698  return tSYMBEG;
7699 
7700  default:
7701  yyerror("unknown type of %string");
7702  return 0;
7703  }
7704  }
7705  if ((c = nextc()) == '=') {
7706  set_yylval_id('%');
7707  lex_state = EXPR_BEG;
7708  return tOP_ASGN;
7709  }
7710  if (IS_SPCARG(c)) {
7711  goto quotation;
7712  }
7713  switch (lex_state) {
7714  case EXPR_FNAME: case EXPR_DOT:
7715  lex_state = EXPR_ARG; break;
7716  default:
7717  lex_state = EXPR_BEG; break;
7718  }
7719  pushback(c);
7720  warn_balanced("%%", "string literal");
7721  return '%';
7722 
7723  case '$':
7724  lex_state = EXPR_END;
7725  newtok();
7726  c = nextc();
7727  switch (c) {
7728  case '_': /* $_: last read line string */
7729  c = nextc();
7730  if (parser_is_identchar()) {
7731  tokadd('$');
7732  tokadd('_');
7733  break;
7734  }
7735  pushback(c);
7736  c = '_';
7737  /* fall through */
7738  case '~': /* $~: match-data */
7739  case '*': /* $*: argv */
7740  case '$': /* $$: pid */
7741  case '?': /* $?: last status */
7742  case '!': /* $!: error string */
7743  case '@': /* $@: error position */
7744  case '/': /* $/: input record separator */
7745  case '\\': /* $\: output record separator */
7746  case ';': /* $;: field separator */
7747  case ',': /* $,: output field separator */
7748  case '.': /* $.: last read line number */
7749  case '=': /* $=: ignorecase */
7750  case ':': /* $:: load path */
7751  case '<': /* $<: reading filename */
7752  case '>': /* $>: default output handle */
7753  case '\"': /* $": already loaded files */
7754  tokadd('$');
7755  tokadd(c);
7756  tokfix();
7758  return tGVAR;
7759 
7760  case '-':
7761  tokadd('$');
7762  tokadd(c);
7763  c = nextc();
7764  if (parser_is_identchar()) {
7765  if (tokadd_mbchar(c) == -1) return 0;
7766  }
7767  else {
7768  pushback(c);
7769  }
7770  gvar:
7771  tokfix();
7773  return tGVAR;
7774 
7775  case '&': /* $&: last match */
7776  case '`': /* $`: string before last match */
7777  case '\'': /* $': string after last match */
7778  case '+': /* $+: string matches last paren. */
7779  if (last_state == EXPR_FNAME) {
7780  tokadd('$');
7781  tokadd(c);
7782  goto gvar;
7783  }
7785  return tBACK_REF;
7786 
7787  case '1': case '2': case '3':
7788  case '4': case '5': case '6':
7789  case '7': case '8': case '9':
7790  tokadd('$');
7791  do {
7792  tokadd(c);
7793  c = nextc();
7794  } while (c != -1 && ISDIGIT(c));
7795  pushback(c);
7796  if (last_state == EXPR_FNAME) goto gvar;
7797  tokfix();
7798  set_yylval_node(NEW_NTH_REF(atoi(tok()+1)));
7799  return tNTH_REF;
7800 
7801  default:
7802  if (!parser_is_identchar()) {
7803  pushback(c);
7804  compile_error(PARSER_ARG "`$%c' is not allowed as a global variable name", c);
7805  return 0;
7806  }
7807  case '0':
7808  tokadd('$');
7809  }
7810  break;
7811 
7812  case '@':
7813  c = nextc();
7814  newtok();
7815  tokadd('@');
7816  if (c == '@') {
7817  tokadd('@');
7818  c = nextc();
7819  }
7820  if (c != -1 && (ISDIGIT(c) || !parser_is_identchar())) {
7821  pushback(c);
7822  if (tokidx == 1) {
7823  compile_error(PARSER_ARG "`@%c' is not allowed as an instance variable name", c);
7824  }
7825  else {
7826  compile_error(PARSER_ARG "`@@%c' is not allowed as a class variable name", c);
7827  }
7828  return 0;
7829  }
7830  break;
7831 
7832  case '_':
7833  if (was_bol() && whole_match_p("__END__", 7, 0)) {
7834  ruby__end__seen = 1;
7835  parser->eofp = Qtrue;
7836 #ifndef RIPPER
7837  return -1;
7838 #else
7839  lex_goto_eol(parser);
7840  ripper_dispatch_scan_event(parser, k__END__);
7841  return 0;
7842 #endif
7843  }
7844  newtok();
7845  break;
7846 
7847  default:
7848  if (!parser_is_identchar()) {
7849  rb_compile_error(PARSER_ARG "Invalid char `\\x%02X' in expression", c);
7850  goto retry;
7851  }
7852 
7853  newtok();
7854  break;
7855  }
7856 
7857  mb = ENC_CODERANGE_7BIT;
7858  do {
7859  if (!ISASCII(c)) mb = ENC_CODERANGE_UNKNOWN;
7860  if (tokadd_mbchar(c) == -1) return 0;
7861  c = nextc();
7862  } while (parser_is_identchar());
7863  switch (tok()[0]) {
7864  case '@': case '$':
7865  pushback(c);
7866  break;
7867  default:
7868  if ((c == '!' || c == '?') && !peek('=')) {
7869  tokadd(c);
7870  }
7871  else {
7872  pushback(c);
7873  }
7874  }
7875  tokfix();
7876 
7877  {
7878  int result = 0;
7879 
7880  last_state = lex_state;
7881  switch (tok()[0]) {
7882  case '$':
7883  lex_state = EXPR_END;
7884  result = tGVAR;
7885  break;
7886  case '@':
7887  lex_state = EXPR_END;
7888  if (tok()[1] == '@')
7889  result = tCVAR;
7890  else
7891  result = tIVAR;
7892  break;
7893 
7894  default:
7895  if (toklast() == '!' || toklast() == '?') {
7896  result = tFID;
7897  }
7898  else {
7899  if (lex_state == EXPR_FNAME) {
7900  if ((c = nextc()) == '=' && !peek('~') && !peek('>') &&
7901  (!peek('=') || (peek_n('>', 1)))) {
7902  result = tIDENTIFIER;
7903  tokadd(c);
7904  tokfix();
7905  }
7906  else {
7907  pushback(c);
7908  }
7909  }
7910  if (result == 0 && ISUPPER(tok()[0])) {
7911  result = tCONSTANT;
7912  }
7913  else {
7914  result = tIDENTIFIER;
7915  }
7916  }
7917 
7918  if (IS_LABEL_POSSIBLE()) {
7919  if (IS_LABEL_SUFFIX(0)) {
7920  lex_state = EXPR_BEG;
7921  nextc();
7923  return tLABEL;
7924  }
7925  }
7926  if (mb == ENC_CODERANGE_7BIT && lex_state != EXPR_DOT) {
7927  const struct kwtable *kw;
7928 
7929  /* See if it is a reserved word. */
7930  kw = rb_reserved_word(tok(), toklen());
7931  if (kw) {
7932  enum lex_state_e state = lex_state;
7933  lex_state = kw->state;
7934  if (state == EXPR_FNAME) {
7936  return kw->id[0];
7937  }
7938  if (kw->id[0] == keyword_do) {
7939  command_start = TRUE;
7940  if (lpar_beg && lpar_beg == paren_nest) {
7941  lpar_beg = 0;
7942  --paren_nest;
7943  return keyword_do_LAMBDA;
7944  }
7945  if (COND_P()) return keyword_do_cond;
7946  if (CMDARG_P() && state != EXPR_CMDARG)
7947  return keyword_do_block;
7948  if (state == EXPR_ENDARG || state == EXPR_BEG)
7949  return keyword_do_block;
7950  return keyword_do;
7951  }
7952  if (state == EXPR_BEG || state == EXPR_VALUE)
7953  return kw->id[0];
7954  else {
7955  if (kw->id[0] != kw->id[1])
7956  lex_state = EXPR_BEG;
7957  return kw->id[1];
7958  }
7959  }
7960  }
7961 
7962  if (IS_BEG() ||
7963  lex_state == EXPR_DOT ||
7964  IS_ARG()) {
7965  if (cmd_state) {
7967  }
7968  else {
7969  lex_state = EXPR_ARG;
7970  }
7971  }
7972  else if (lex_state == EXPR_FNAME) {
7974  }
7975  else {
7976  lex_state = EXPR_END;
7977  }
7978  }
7979  {
7980  ID ident = TOK_INTERN(!ENC_SINGLE(mb));
7981 
7982  set_yylval_name(ident);
7983  if (last_state != EXPR_DOT && last_state != EXPR_FNAME &&
7984  is_local_id(ident) && lvar_defined(ident)) {
7985  lex_state = EXPR_END;
7986  }
7987  }
7988  return result;
7989  }
7990 }
7991 
7992 #if YYPURE
7993 static int
7994 yylex(void *lval, void *p)
7995 #else
7996 yylex(void *p)
7997 #endif
7998 {
7999  struct parser_params *parser = (struct parser_params*)p;
8000  int t;
8001 
8002 #if YYPURE
8003  parser->parser_yylval = lval;
8004  parser->parser_yylval->val = Qundef;
8005 #endif
8006  t = parser_yylex(parser);
8007 #ifdef RIPPER
8008  if (!NIL_P(parser->delayed)) {
8009  ripper_dispatch_delayed_token(parser, t);
8010  return t;
8011  }
8012  if (t != 0)
8013  ripper_dispatch_scan_event(parser, t);
8014 #endif
8015 
8016  return t;
8017 }
8018 
8019 #ifndef RIPPER
8020 static NODE*
8021 node_newnode(struct parser_params *parser, enum node_type type, VALUE a0, VALUE a1, VALUE a2)
8022 {
8023  NODE *n = (rb_node_newnode)(type, a0, a1, a2);
8025  return n;
8026 }
8027 
8028 enum node_type
8029 nodetype(NODE *node) /* for debug */
8030 {
8031  return (enum node_type)nd_type(node);
8032 }
8033 
8034 int
8035 nodeline(NODE *node)
8036 {
8037  return nd_line(node);
8038 }
8039 
8040 static NODE*
8041 newline_node(NODE *node)
8042 {
8043  if (node) {
8044  node = remove_begin(node);
8045  node->flags |= NODE_FL_NEWLINE;
8046  }
8047  return node;
8048 }
8049 
8050 static void
8051 fixpos(NODE *node, NODE *orig)
8052 {
8053  if (!node) return;
8054  if (!orig) return;
8055  if (orig == (NODE*)1) return;
8056  nd_set_line(node, nd_line(orig));
8057 }
8058 
8059 static void
8060 parser_warning(struct parser_params *parser, NODE *node, const char *mesg)
8061 {
8062  rb_compile_warning(ruby_sourcefile, nd_line(node), "%s", mesg);
8063 }
8064 #define parser_warning(node, mesg) parser_warning(parser, (node), (mesg))
8065 
8066 static void
8067 parser_warn(struct parser_params *parser, NODE *node, const char *mesg)
8068 {
8069  rb_compile_warn(ruby_sourcefile, nd_line(node), "%s", mesg);
8070 }
8071 #define parser_warn(node, mesg) parser_warn(parser, (node), (mesg))
8072 
8073 static NODE*
8074 block_append_gen(struct parser_params *parser, NODE *head, NODE *tail)
8075 {
8076  NODE *end, *h = head, *nd;
8077 
8078  if (tail == 0) return head;
8079 
8080  if (h == 0) return tail;
8081  switch (nd_type(h)) {
8082  case NODE_LIT:
8083  case NODE_STR:
8084  case NODE_SELF:
8085  case NODE_TRUE:
8086  case NODE_FALSE:
8087  case NODE_NIL:
8088  parser_warning(h, "unused literal ignored");
8089  return tail;
8090  default:
8091  h = end = NEW_BLOCK(head);
8092  end->nd_end = end;
8093  fixpos(end, head);
8094  head = end;
8095  break;
8096  case NODE_BLOCK:
8097  end = h->nd_end;
8098  break;
8099  }
8100 
8101  nd = end->nd_head;
8102  switch (nd_type(nd)) {
8103  case NODE_RETURN:
8104  case NODE_BREAK:
8105  case NODE_NEXT:
8106  case NODE_REDO:
8107  case NODE_RETRY:
8108  if (RTEST(ruby_verbose)) {
8109  parser_warning(nd, "statement not reached");
8110  }
8111  break;
8112 
8113  default:
8114  break;
8115  }
8116 
8117  if (nd_type(tail) != NODE_BLOCK) {
8118  tail = NEW_BLOCK(tail);
8119  tail->nd_end = tail;
8120  }
8121  end->nd_next = tail;
8122  h->nd_end = tail->nd_end;
8123  return head;
8124 }
8125 
8126 /* append item to the list */
8127 static NODE*
8128 list_append_gen(struct parser_params *parser, NODE *list, NODE *item)
8129 {
8130  NODE *last;
8131 
8132  if (list == 0) return NEW_LIST(item);
8133  if (list->nd_next) {
8134  last = list->nd_next->nd_end;
8135  }
8136  else {
8137  last = list;
8138  }
8139 
8140  list->nd_alen += 1;
8141  last->nd_next = NEW_LIST(item);
8142  list->nd_next->nd_end = last->nd_next;
8143  return list;
8144 }
8145 
8146 /* concat two lists */
8147 static NODE*
8148 list_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
8149 {
8150  NODE *last;
8151 
8152  if (head->nd_next) {
8153  last = head->nd_next->nd_end;
8154  }
8155  else {
8156  last = head;
8157  }
8158 
8159  head->nd_alen += tail->nd_alen;
8160  last->nd_next = tail;
8161  if (tail->nd_next) {
8162  head->nd_next->nd_end = tail->nd_next->nd_end;
8163  }
8164  else {
8165  head->nd_next->nd_end = tail;
8166  }
8167 
8168  return head;
8169 }
8170 
8171 static int
8172 literal_concat0(struct parser_params *parser, VALUE head, VALUE tail)
8173 {
8174  if (NIL_P(tail)) return 1;
8175  if (!rb_enc_compatible(head, tail)) {
8176  compile_error(PARSER_ARG "string literal encodings differ (%s / %s)",
8177  rb_enc_name(rb_enc_get(head)),
8178  rb_enc_name(rb_enc_get(tail)));
8179  rb_str_resize(head, 0);
8180  rb_str_resize(tail, 0);
8181  return 0;
8182  }
8183  rb_str_buf_append(head, tail);
8184  return 1;
8185 }
8186 
8187 /* concat two string literals */
8188 static NODE *
8189 literal_concat_gen(struct parser_params *parser, NODE *head, NODE *tail)
8190 {
8191  enum node_type htype;
8192 
8193  if (!head) return tail;
8194  if (!tail) return head;
8195 
8196  htype = nd_type(head);
8197  if (htype == NODE_EVSTR) {
8198  NODE *node = NEW_DSTR(Qnil);
8199  head = list_append(node, head);
8200  }
8201  switch (nd_type(tail)) {
8202  case NODE_STR:
8203  if (htype == NODE_STR) {
8204  if (!literal_concat0(parser, head->nd_lit, tail->nd_lit)) {
8205  error:
8206  rb_gc_force_recycle((VALUE)head);
8207  rb_gc_force_recycle((VALUE)tail);
8208  return 0;
8209  }
8210  rb_gc_force_recycle((VALUE)tail);
8211  }
8212  else {
8213  list_append(head, tail);
8214  }
8215  break;
8216 
8217  case NODE_DSTR:
8218  if (htype == NODE_STR) {
8219  if (!literal_concat0(parser, head->nd_lit, tail->nd_lit))
8220  goto error;
8221  tail->nd_lit = head->nd_lit;
8222  rb_gc_force_recycle((VALUE)head);
8223  head = tail;
8224  }
8225  else if (NIL_P(tail->nd_lit)) {
8226  head->nd_alen += tail->nd_alen - 1;
8227  head->nd_next->nd_end->nd_next = tail->nd_next;
8228  head->nd_next->nd_end = tail->nd_next->nd_end;
8229  rb_gc_force_recycle((VALUE)tail);
8230  }
8231  else {
8232  nd_set_type(tail, NODE_ARRAY);
8233  tail->nd_head = NEW_STR(tail->nd_lit);
8234  list_concat(head, tail);
8235  }
8236  break;
8237 
8238  case NODE_EVSTR:
8239  if (htype == NODE_STR) {
8240  nd_set_type(head, NODE_DSTR);
8241  head->nd_alen = 1;
8242  }
8243  list_append(head, tail);
8244  break;
8245  }
8246  return head;
8247 }
8248 
8249 static NODE *
8250 evstr2dstr_gen(struct parser_params *parser, NODE *node)
8251 {
8252  if (nd_type(node) == NODE_EVSTR) {
8253  node = list_append(NEW_DSTR(Qnil), node);
8254  }
8255  return node;
8256 }
8257 
8258 static NODE *
8259 new_evstr_gen(struct parser_params *parser, NODE *node)
8260 {
8261  NODE *head = node;
8262 
8263  if (node) {
8264  switch (nd_type(node)) {
8265  case NODE_STR: case NODE_DSTR: case NODE_EVSTR:
8266  return node;
8267  }
8268  }
8269  return NEW_EVSTR(head);
8270 }
8271 
8272 static NODE *
8273 call_bin_op_gen(struct parser_params *parser, NODE *recv, ID id, NODE *arg1)
8274 {
8275  value_expr(recv);
8276  value_expr(arg1);
8277  return NEW_CALL(recv, id, NEW_LIST(arg1));
8278 }
8279 
8280 static NODE *
8281 call_uni_op_gen(struct parser_params *parser, NODE *recv, ID id)
8282 {
8283  value_expr(recv);
8284  return NEW_CALL(recv, id, 0);
8285 }
8286 
8287 static NODE*
8288 match_op_gen(struct parser_params *parser, NODE *node1, NODE *node2)
8289 {
8290  value_expr(node1);
8291  value_expr(node2);
8292  if (node1) {
8293  switch (nd_type(node1)) {
8294  case NODE_DREGX:
8295  case NODE_DREGX_ONCE:
8296  return NEW_MATCH2(node1, node2);
8297 
8298  case NODE_LIT:
8299  if (TYPE(node1->nd_lit) == T_REGEXP) {
8300  return NEW_MATCH2(node1, node2);
8301  }
8302  }
8303  }
8304 
8305  if (node2) {
8306  switch (nd_type(node2)) {
8307  case NODE_DREGX:
8308  case NODE_DREGX_ONCE:
8309  return NEW_MATCH3(node2, node1);
8310 
8311  case NODE_LIT:
8312  if (TYPE(node2->nd_lit) == T_REGEXP) {
8313  return NEW_MATCH3(node2, node1);
8314  }
8315  }
8316  }
8317 
8318  return NEW_CALL(node1, tMATCH, NEW_LIST(node2));
8319 }
8320 
8321 static NODE*
8322 gettable_gen(struct parser_params *parser, ID id)
8323 {
8324  if (id == keyword_self) {
8325  return NEW_SELF();
8326  }
8327  else if (id == keyword_nil) {
8328  return NEW_NIL();
8329  }
8330  else if (id == keyword_true) {
8331  return NEW_TRUE();
8332  }
8333  else if (id == keyword_false) {
8334  return NEW_FALSE();
8335  }
8336  else if (id == keyword__FILE__) {
8339  }
8340  else if (id == keyword__LINE__) {
8341  return NEW_LIT(INT2FIX(ruby_sourceline));
8342  }
8343  else if (id == keyword__ENCODING__) {
8344  return NEW_LIT(rb_enc_from_encoding(parser->enc));
8345  }
8346  else if (is_local_id(id)) {
8347  if (dyna_in_block() && dvar_defined(id)) return NEW_DVAR(id);
8348  if (local_id(id)) return NEW_LVAR(id);
8349  /* method call without arguments */
8350  return NEW_VCALL(id);
8351  }
8352  else if (is_global_id(id)) {
8353  return NEW_GVAR(id);
8354  }
8355  else if (is_instance_id(id)) {
8356  return NEW_IVAR(id);
8357  }
8358  else if (is_const_id(id)) {
8359  return NEW_CONST(id);
8360  }
8361  else if (is_class_id(id)) {
8362  return NEW_CVAR(id);
8363  }
8364  compile_error(PARSER_ARG "identifier %s is not valid to get", rb_id2name(id));
8365  return 0;
8366 }
8367 #else /* !RIPPER */
8368 static int
8369 id_is_var_gen(struct parser_params *parser, ID id)
8370 {
8371  if (is_notop_id(id)) {
8372  switch (id & ID_SCOPE_MASK) {
8373  case ID_GLOBAL: case ID_INSTANCE: case ID_CONST: case ID_CLASS:
8374  return 1;
8375  case ID_LOCAL:
8376  if (dyna_in_block() && dvar_defined(id)) return 1;
8377  if (local_id(id)) return 1;
8378  /* method call without arguments */
8379  return 0;
8380  }
8381  }
8382  compile_error(PARSER_ARG "identifier %s is not valid to get", rb_id2name(id));
8383  return 0;
8384 }
8385 #endif /* !RIPPER */
8386 
8387 #ifdef RIPPER
8388 static VALUE
8389 assignable_gen(struct parser_params *parser, VALUE lhs)
8390 #else
8391 static NODE*
8392 assignable_gen(struct parser_params *parser, ID id, NODE *val)
8393 #endif
8394 {
8395 #ifdef RIPPER
8396  ID id = get_id(lhs);
8397 # define assignable_result(x) get_value(lhs)
8398 # define parser_yyerror(parser, x) dispatch1(assign_error, lhs)
8399 #else
8400 # define assignable_result(x) (x)
8401 #endif
8402  if (!id) return assignable_result(0);
8403  if (id == keyword_self) {
8404  yyerror("Can't change the value of self");
8405  }
8406  else if (id == keyword_nil) {
8407  yyerror("Can't assign to nil");
8408  }
8409  else if (id == keyword_true) {
8410  yyerror("Can't assign to true");
8411  }
8412  else if (id == keyword_false) {
8413  yyerror("Can't assign to false");
8414  }
8415  else if (id == keyword__FILE__) {
8416  yyerror("Can't assign to __FILE__");
8417  }
8418  else if (id == keyword__LINE__) {
8419  yyerror("Can't assign to __LINE__");
8420  }
8421  else if (id == keyword__ENCODING__) {
8422  yyerror("Can't assign to __ENCODING__");
8423  }
8424  else if (is_local_id(id)) {
8425  if (dyna_in_block()) {
8426  if (dvar_curr(id)) {
8427  return assignable_result(NEW_DASGN_CURR(id, val));
8428  }
8429  else if (dvar_defined(id)) {
8430  return assignable_result(NEW_DASGN(id, val));
8431  }
8432  else if (local_id(id)) {
8433  return assignable_result(NEW_LASGN(id, val));
8434  }
8435  else {
8436  dyna_var(id);
8437  return assignable_result(NEW_DASGN_CURR(id, val));
8438  }
8439  }
8440  else {
8441  if (!local_id(id)) {
8442  local_var(id);
8443  }
8444  return assignable_result(NEW_LASGN(id, val));
8445  }
8446  }
8447  else if (is_global_id(id)) {
8448  return assignable_result(NEW_GASGN(id, val));
8449  }
8450  else if (is_instance_id(id)) {
8451  return assignable_result(NEW_IASGN(id, val));
8452  }
8453  else if (is_const_id(id)) {
8454  if (!in_def && !in_single)
8455  return assignable_result(NEW_CDECL(id, val, 0));
8456  yyerror("dynamic constant assignment");
8457  }
8458  else if (is_class_id(id)) {
8459  return assignable_result(NEW_CVASGN(id, val));
8460  }
8461  else {
8462  compile_error(PARSER_ARG "identifier %s is not valid to set", rb_id2name(id));
8463  }
8464  return assignable_result(0);
8465 #undef assignable_result
8466 #undef parser_yyerror
8467 }
8468 
8469 #define LVAR_USED ((int)1 << (sizeof(int) * CHAR_BIT - 1))
8470 
8471 static ID
8472 shadowing_lvar_gen(struct parser_params *parser, ID name)
8473 {
8474  if (idUScore == name) return name;
8475  if (dyna_in_block()) {
8476  if (dvar_curr(name)) {
8477  yyerror("duplicated argument name");
8478  }
8479  else if (dvar_defined_get(name) || local_id(name)) {
8480  rb_warningS("shadowing outer local variable - %s", rb_id2name(name));
8481  vtable_add(lvtbl->vars, name);
8482  if (lvtbl->used) {
8484  }
8485  }
8486  }
8487  else {
8488  if (local_id(name)) {
8489  yyerror("duplicated argument name");
8490  }
8491  }
8492  return name;
8493 }
8494 
8495 static void
8496 new_bv_gen(struct parser_params *parser, ID name)
8497 {
8498  if (!name) return;
8499  if (!is_local_id(name)) {
8500  compile_error(PARSER_ARG "invalid local variable - %s",
8501  rb_id2name(name));
8502  return;
8503  }
8504  shadowing_lvar(name);
8505  dyna_var(name);
8506 }
8507 
8508 #ifndef RIPPER
8509 static NODE *
8510 aryset_gen(struct parser_params *parser, NODE *recv, NODE *idx)
8511 {
8512  if (recv && nd_type(recv) == NODE_SELF)
8513  recv = (NODE *)1;
8514  return NEW_ATTRASGN(recv, tASET, idx);
8515 }
8516 
8517 static void
8518 block_dup_check_gen(struct parser_params *parser, NODE *node1, NODE *node2)
8519 {
8520  if (node2 && node1 && nd_type(node1) == NODE_BLOCK_PASS) {
8521  compile_error(PARSER_ARG "both block arg and actual block given");
8522  }
8523 }
8524 
8525 ID
8526 rb_id_attrset(ID id)
8527 {
8528  id &= ~ID_SCOPE_MASK;
8529  id |= ID_ATTRSET;
8530  return id;
8531 }
8532 
8533 static NODE *
8534 attrset_gen(struct parser_params *parser, NODE *recv, ID id)
8535 {
8536  if (recv && nd_type(recv) == NODE_SELF)
8537  recv = (NODE *)1;
8538  return NEW_ATTRASGN(recv, rb_id_attrset(id), 0);
8539 }
8540 
8541 static void
8542 rb_backref_error_gen(struct parser_params *parser, NODE *node)
8543 {
8544  switch (nd_type(node)) {
8545  case NODE_NTH_REF:
8546  compile_error(PARSER_ARG "Can't set variable $%ld", node->nd_nth);
8547  break;
8548  case NODE_BACK_REF:
8549  compile_error(PARSER_ARG "Can't set variable $%c", (int)node->nd_nth);
8550  break;
8551  }
8552 }
8553 
8554 static NODE *
8555 arg_concat_gen(struct parser_params *parser, NODE *node1, NODE *node2)
8556 {
8557  if (!node2) return node1;
8558  switch (nd_type(node1)) {
8559  case NODE_BLOCK_PASS:
8560  if (node1->nd_head)
8561  node1->nd_head = arg_concat(node1->nd_head, node2);
8562  else
8563  node1->nd_head = NEW_LIST(node2);
8564  return node1;
8565  case NODE_ARGSPUSH:
8566  if (nd_type(node2) != NODE_ARRAY) break;
8567  node1->nd_body = list_concat(NEW_LIST(node1->nd_body), node2);
8568  nd_set_type(node1, NODE_ARGSCAT);
8569  return node1;
8570  case NODE_ARGSCAT:
8571  if (nd_type(node2) != NODE_ARRAY ||
8572  nd_type(node1->nd_body) != NODE_ARRAY) break;
8573  node1->nd_body = list_concat(node1->nd_body, node2);
8574  return node1;
8575  }
8576  return NEW_ARGSCAT(node1, node2);
8577 }
8578 
8579 static NODE *
8580 arg_append_gen(struct parser_params *parser, NODE *node1, NODE *node2)
8581 {
8582  if (!node1) return NEW_LIST(node2);
8583  switch (nd_type(node1)) {
8584  case NODE_ARRAY:
8585  return list_append(node1, node2);
8586  case NODE_BLOCK_PASS:
8587  node1->nd_head = arg_append(node1->nd_head, node2);
8588  return node1;
8589  case NODE_ARGSPUSH:
8590  node1->nd_body = list_append(NEW_LIST(node1->nd_body), node2);
8591  nd_set_type(node1, NODE_ARGSCAT);
8592  return node1;
8593  }
8594  return NEW_ARGSPUSH(node1, node2);
8595 }
8596 
8597 static NODE *
8598 splat_array(NODE* node)
8599 {
8600  if (nd_type(node) == NODE_SPLAT) node = node->nd_head;
8601  if (nd_type(node) == NODE_ARRAY) return node;
8602  return 0;
8603 }
8604 
8605 static NODE *
8606 node_assign_gen(struct parser_params *parser, NODE *lhs, NODE *rhs)
8607 {
8608  if (!lhs) return 0;
8609 
8610  switch (nd_type(lhs)) {
8611  case NODE_GASGN:
8612  case NODE_IASGN:
8613  case NODE_IASGN2:
8614  case NODE_LASGN:
8615  case NODE_DASGN:
8616  case NODE_DASGN_CURR:
8617  case NODE_MASGN:
8618  case NODE_CDECL:
8619  case NODE_CVASGN:
8620  lhs->nd_value = rhs;
8621  break;
8622 
8623  case NODE_ATTRASGN:
8624  case NODE_CALL:
8625  lhs->nd_args = arg_append(lhs->nd_args, rhs);
8626  break;
8627 
8628  default:
8629  /* should not happen */
8630  break;
8631  }
8632 
8633  return lhs;
8634 }
8635 
8636 static int
8637 value_expr_gen(struct parser_params *parser, NODE *node)
8638 {
8639  int cond = 0;
8640 
8641  if (!node) {
8642  rb_warning0("empty expression");
8643  }
8644  while (node) {
8645  switch (nd_type(node)) {
8646  case NODE_DEFN:
8647  case NODE_DEFS:
8648  parser_warning(node, "void value expression");
8649  return FALSE;
8650 
8651  case NODE_RETURN:
8652  case NODE_BREAK:
8653  case NODE_NEXT:
8654  case NODE_REDO:
8655  case NODE_RETRY:
8656  if (!cond) yyerror("void value expression");
8657  /* or "control never reach"? */
8658  return FALSE;
8659 
8660  case NODE_BLOCK:
8661  while (node->nd_next) {
8662  node = node->nd_next;
8663  }
8664  node = node->nd_head;
8665  break;
8666 
8667  case NODE_BEGIN:
8668  node = node->nd_body;
8669  break;
8670 
8671  case NODE_IF:
8672  if (!node->nd_body) {
8673  node = node->nd_else;
8674  break;
8675  }
8676  else if (!node->nd_else) {
8677  node = node->nd_body;
8678  break;
8679  }
8680  if (!value_expr(node->nd_body)) return FALSE;
8681  node = node->nd_else;
8682  break;
8683 
8684  case NODE_AND:
8685  case NODE_OR:
8686  cond = 1;
8687  node = node->nd_2nd;
8688  break;
8689 
8690  default:
8691  return TRUE;
8692  }
8693  }
8694 
8695  return TRUE;
8696 }
8697 
8698 static void
8699 void_expr_gen(struct parser_params *parser, NODE *node)
8700 {
8701  const char *useless = 0;
8702 
8703  if (!RTEST(ruby_verbose)) return;
8704 
8705  if (!node) return;
8706  switch (nd_type(node)) {
8707  case NODE_CALL:
8708  switch (node->nd_mid) {
8709  case '+':
8710  case '-':
8711  case '*':
8712  case '/':
8713  case '%':
8714  case tPOW:
8715  case tUPLUS:
8716  case tUMINUS:
8717  case '|':
8718  case '^':
8719  case '&':
8720  case tCMP:
8721  case '>':
8722  case tGEQ:
8723  case '<':
8724  case tLEQ:
8725  case tEQ:
8726  case tNEQ:
8727  useless = rb_id2name(node->nd_mid);
8728  break;
8729  }
8730  break;
8731 
8732  case NODE_LVAR:
8733  case NODE_DVAR:
8734  case NODE_GVAR:
8735  case NODE_IVAR:
8736  case NODE_CVAR:
8737  case NODE_NTH_REF:
8738  case NODE_BACK_REF:
8739  useless = "a variable";
8740  break;
8741  case NODE_CONST:
8742  useless = "a constant";
8743  break;
8744  case NODE_LIT:
8745  case NODE_STR:
8746  case NODE_DSTR:
8747  case NODE_DREGX:
8748  case NODE_DREGX_ONCE:
8749  useless = "a literal";
8750  break;
8751  case NODE_COLON2:
8752  case NODE_COLON3:
8753  useless = "::";
8754  break;
8755  case NODE_DOT2:
8756  useless = "..";
8757  break;
8758  case NODE_DOT3:
8759  useless = "...";
8760  break;
8761  case NODE_SELF:
8762  useless = "self";
8763  break;
8764  case NODE_NIL:
8765  useless = "nil";
8766  break;
8767  case NODE_TRUE:
8768  useless = "true";
8769  break;
8770  case NODE_FALSE:
8771  useless = "false";
8772  break;
8773  case NODE_DEFINED:
8774  useless = "defined?";
8775  break;
8776  }
8777 
8778  if (useless) {
8779  int line = ruby_sourceline;
8780 
8781  ruby_sourceline = nd_line(node);
8782  rb_warnS("possibly useless use of %s in void context", useless);
8783  ruby_sourceline = line;
8784  }
8785 }
8786 
8787 static void
8788 void_stmts_gen(struct parser_params *parser, NODE *node)
8789 {
8790  if (!RTEST(ruby_verbose)) return;
8791  if (!node) return;
8792  if (nd_type(node) != NODE_BLOCK) return;
8793 
8794  for (;;) {
8795  if (!node->nd_next) return;
8796  void_expr0(node->nd_head);
8797  node = node->nd_next;
8798  }
8799 }
8800 
8801 static NODE *
8802 remove_begin(NODE *node)
8803 {
8804  NODE **n = &node, *n1 = node;
8805  while (n1 && nd_type(n1) == NODE_BEGIN && n1->nd_body) {
8806  *n = n1 = n1->nd_body;
8807  }
8808  return node;
8809 }
8810 
8811 static void
8812 reduce_nodes_gen(struct parser_params *parser, NODE **body)
8813 {
8814  NODE *node = *body;
8815 
8816  if (!node) {
8817  *body = NEW_NIL();
8818  return;
8819  }
8820 #define subnodes(n1, n2) \
8821  ((!node->n1) ? (node->n2 ? (body = &node->n2, 1) : 0) : \
8822  (!node->n2) ? (body = &node->n1, 1) : \
8823  (reduce_nodes(&node->n1), body = &node->n2, 1))
8824 
8825  while (node) {
8826  int newline = (int)(node->flags & NODE_FL_NEWLINE);
8827  switch (nd_type(node)) {
8828  end:
8829  case NODE_NIL:
8830  *body = 0;
8831  return;
8832  case NODE_RETURN:
8833  *body = node = node->nd_stts;
8834  if (newline && node) node->flags |= NODE_FL_NEWLINE;
8835  continue;
8836  case NODE_BEGIN:
8837  *body = node = node->nd_body;
8838  if (newline && node) node->flags |= NODE_FL_NEWLINE;
8839  continue;
8840  case NODE_BLOCK:
8841  body = &node->nd_end->nd_head;
8842  break;
8843  case NODE_IF:
8844  if (subnodes(nd_body, nd_else)) break;
8845  return;
8846  case NODE_CASE:
8847  body = &node->nd_body;
8848  break;
8849  case NODE_WHEN:
8850  if (!subnodes(nd_body, nd_next)) goto end;
8851  break;
8852  case NODE_ENSURE:
8853  if (!subnodes(nd_head, nd_resq)) goto end;
8854  break;
8855  case NODE_RESCUE:
8856  if (node->nd_else) {
8857  body = &node->nd_resq;
8858  break;
8859  }
8860  if (!subnodes(nd_head, nd_resq)) goto end;
8861  break;
8862  default:
8863  return;
8864  }
8865  node = *body;
8866  if (newline && node) node->flags |= NODE_FL_NEWLINE;
8867  }
8868 
8869 #undef subnodes
8870 }
8871 
8872 static int
8873 assign_in_cond(struct parser_params *parser, NODE *node)
8874 {
8875  switch (nd_type(node)) {
8876  case NODE_MASGN:
8877  yyerror("multiple assignment in conditional");
8878  return 1;
8879 
8880  case NODE_LASGN:
8881  case NODE_DASGN:
8882  case NODE_DASGN_CURR:
8883  case NODE_GASGN:
8884  case NODE_IASGN:
8885  break;
8886 
8887  default:
8888  return 0;
8889  }
8890 
8891  if (!node->nd_value) return 1;
8892  switch (nd_type(node->nd_value)) {
8893  case NODE_LIT:
8894  case NODE_STR:
8895  case NODE_NIL:
8896  case NODE_TRUE:
8897  case NODE_FALSE:
8898  /* reports always */
8899  parser_warn(node->nd_value, "found = in conditional, should be ==");
8900  return 1;
8901 
8902  case NODE_DSTR:
8903  case NODE_XSTR:
8904  case NODE_DXSTR:
8905  case NODE_EVSTR:
8906  case NODE_DREGX:
8907  default:
8908  break;
8909  }
8910  return 1;
8911 }
8912 
8913 static void
8914 warn_unless_e_option(struct parser_params *parser, NODE *node, const char *str)
8915 {
8916  if (!e_option_supplied(parser)) parser_warn(node, str);
8917 }
8918 
8919 static void
8920 warning_unless_e_option(struct parser_params *parser, NODE *node, const char *str)
8921 {
8922  if (!e_option_supplied(parser)) parser_warning(node, str);
8923 }
8924 
8925 static void
8926 fixup_nodes(NODE **rootnode)
8927 {
8928  NODE *node, *next, *head;
8929 
8930  for (node = *rootnode; node; node = next) {
8931  enum node_type type;
8932  VALUE val;
8933 
8934  next = node->nd_next;
8935  head = node->nd_head;
8936  rb_gc_force_recycle((VALUE)node);
8937  *rootnode = next;
8938  switch (type = nd_type(head)) {
8939  case NODE_DOT2:
8940  case NODE_DOT3:
8941  val = rb_range_new(head->nd_beg->nd_lit, head->nd_end->nd_lit,
8942  type == NODE_DOT3);
8943  rb_gc_force_recycle((VALUE)head->nd_beg);
8944  rb_gc_force_recycle((VALUE)head->nd_end);
8945  nd_set_type(head, NODE_LIT);
8946  head->nd_lit = val;
8947  break;
8948  default:
8949  break;
8950  }
8951  }
8952 }
8953 
8954 static NODE *cond0(struct parser_params*,NODE*);
8955 
8956 static NODE*
8957 range_op(struct parser_params *parser, NODE *node)
8958 {
8959  enum node_type type;
8960 
8961  if (node == 0) return 0;
8962 
8963  type = nd_type(node);
8964  value_expr(node);
8965  if (type == NODE_LIT && FIXNUM_P(node->nd_lit)) {
8966  warn_unless_e_option(parser, node, "integer literal in conditional range");
8967  return NEW_CALL(node, tEQ, NEW_LIST(NEW_GVAR(rb_intern("$."))));
8968  }
8969  return cond0(parser, node);
8970 }
8971 
8972 static int
8973 literal_node(NODE *node)
8974 {
8975  if (!node) return 1; /* same as NODE_NIL */
8976  switch (nd_type(node)) {
8977  case NODE_LIT:
8978  case NODE_STR:
8979  case NODE_DSTR:
8980  case NODE_EVSTR:
8981  case NODE_DREGX:
8982  case NODE_DREGX_ONCE:
8983  case NODE_DSYM:
8984  return 2;
8985  case NODE_TRUE:
8986  case NODE_FALSE:
8987  case NODE_NIL:
8988  return 1;
8989  }
8990  return 0;
8991 }
8992 
8993 static NODE*
8994 cond0(struct parser_params *parser, NODE *node)
8995 {
8996  if (node == 0) return 0;
8997  assign_in_cond(parser, node);
8998 
8999  switch (nd_type(node)) {
9000  case NODE_DSTR:
9001  case NODE_EVSTR:
9002  case NODE_STR:
9003  rb_warn0("string literal in condition");
9004  break;
9005 
9006  case NODE_DREGX:
9007  case NODE_DREGX_ONCE:
9008  warning_unless_e_option(parser, node, "regex literal in condition");
9009  return NEW_MATCH2(node, NEW_GVAR(rb_intern("$_")));
9010 
9011  case NODE_AND:
9012  case NODE_OR:
9013  node->nd_1st = cond0(parser, node->nd_1st);
9014  node->nd_2nd = cond0(parser, node->nd_2nd);
9015  break;
9016 
9017  case NODE_DOT2:
9018  case NODE_DOT3:
9019  node->nd_beg = range_op(parser, node->nd_beg);
9020  node->nd_end = range_op(parser, node->nd_end);
9021  if (nd_type(node) == NODE_DOT2) nd_set_type(node,NODE_FLIP2);
9022  else if (nd_type(node) == NODE_DOT3) nd_set_type(node, NODE_FLIP3);
9023  if (!e_option_supplied(parser)) {
9024  int b = literal_node(node->nd_beg);
9025  int e = literal_node(node->nd_end);
9026  if ((b == 1 && e == 1) || (b + e >= 2 && RTEST(ruby_verbose))) {
9027  parser_warn(node, "range literal in condition");
9028  }
9029  }
9030  break;
9031 
9032  case NODE_DSYM:
9033  parser_warning(node, "literal in condition");
9034  break;
9035 
9036  case NODE_LIT:
9037  if (TYPE(node->nd_lit) == T_REGEXP) {
9038  warn_unless_e_option(parser, node, "regex literal in condition");
9039  nd_set_type(node, NODE_MATCH);
9040  }
9041  else {
9042  parser_warning(node, "literal in condition");
9043  }
9044  default:
9045  break;
9046  }
9047  return node;
9048 }
9049 
9050 static NODE*
9051 cond_gen(struct parser_params *parser, NODE *node)
9052 {
9053  if (node == 0) return 0;
9054  return cond0(parser, node);
9055 }
9056 
9057 static NODE*
9058 logop_gen(struct parser_params *parser, enum node_type type, NODE *left, NODE *right)
9059 {
9060  value_expr(left);
9061  if (left && (enum node_type)nd_type(left) == type) {
9062  NODE *node = left, *second;
9063  while ((second = node->nd_2nd) != 0 && (enum node_type)nd_type(second) == type) {
9064  node = second;
9065  }
9066  node->nd_2nd = NEW_NODE(type, second, right, 0);
9067  return left;
9068  }
9069  return NEW_NODE(type, left, right, 0);
9070 }
9071 
9072 static void
9073 no_blockarg(struct parser_params *parser, NODE *node)
9074 {
9075  if (node && nd_type(node) == NODE_BLOCK_PASS) {
9076  compile_error(PARSER_ARG "block argument should not be given");
9077  }
9078 }
9079 
9080 static NODE *
9081 ret_args_gen(struct parser_params *parser, NODE *node)
9082 {
9083  if (node) {
9084  no_blockarg(parser, node);
9085  if (nd_type(node) == NODE_ARRAY) {
9086  if (node->nd_next == 0) {
9087  node = node->nd_head;
9088  }
9089  else {
9090  nd_set_type(node, NODE_VALUES);
9091  }
9092  }
9093  }
9094  return node;
9095 }
9096 
9097 static NODE *
9098 new_yield_gen(struct parser_params *parser, NODE *node)
9099 {
9100  long state = Qtrue;
9101 
9102  if (node) {
9103  no_blockarg(parser, node);
9104  if (node && nd_type(node) == NODE_SPLAT) {
9105  state = Qtrue;
9106  }
9107  }
9108  else {
9109  state = Qfalse;
9110  }
9111  return NEW_YIELD(node, state);
9112 }
9113 
9114 static NODE*
9115 negate_lit(NODE *node)
9116 {
9117  switch (TYPE(node->nd_lit)) {
9118  case T_FIXNUM:
9119  node->nd_lit = LONG2FIX(-FIX2LONG(node->nd_lit));
9120  break;
9121  case T_BIGNUM:
9122  node->nd_lit = rb_funcall(node->nd_lit,tUMINUS,0,0);
9123  break;
9124  case T_FLOAT:
9125  RFLOAT(node->nd_lit)->float_value = -RFLOAT_VALUE(node->nd_lit);
9126  break;
9127  default:
9128  break;
9129  }
9130  return node;
9131 }
9132 
9133 static NODE *
9134 arg_blk_pass(NODE *node1, NODE *node2)
9135 {
9136  if (node2) {
9137  node2->nd_head = node1;
9138  return node2;
9139  }
9140  return node1;
9141 }
9142 
9143 static NODE*
9144 new_args_gen(struct parser_params *parser, NODE *m, NODE *o, ID r, NODE *p, ID b)
9145 {
9146  int saved_line = ruby_sourceline;
9147  NODE *node;
9148  NODE *i1, *i2 = 0;
9149 
9150  node = NEW_ARGS(m ? m->nd_plen : 0, o);
9151  i1 = m ? m->nd_next : 0;
9152  node->nd_next = NEW_ARGS_AUX(r, b);
9153 
9154  if (p) {
9155  i2 = p->nd_next;
9156  node->nd_next->nd_next = NEW_ARGS_AUX(p->nd_pid, p->nd_plen);
9157  }
9158  else if (i1) {
9159  node->nd_next->nd_next = NEW_ARGS_AUX(0, 0);
9160  }
9161  if (i1 || i2) {
9162  node->nd_next->nd_next->nd_next = NEW_NODE(NODE_AND, i1, i2, 0);
9163  }
9164  ruby_sourceline = saved_line;
9165  return node;
9166 }
9167 #endif /* !RIPPER */
9168 
9169 static void
9170 warn_unused_var(struct parser_params *parser, struct local_vars *local)
9171 {
9172  int i, cnt;
9173  ID *v, *u;
9174 
9175  if (!local->used) return;
9176  v = local->vars->tbl;
9177  u = local->used->tbl;
9178  cnt = local->used->pos;
9179  if (cnt != local->vars->pos) {
9180  rb_bug("local->used->pos != local->vars->pos");
9181  }
9182  for (i = 0; i < cnt; ++i) {
9183  if (!v[i] || (u[i] & LVAR_USED)) continue;
9184  if (idUScore == v[i]) continue;
9185  rb_compile_warn(ruby_sourcefile, (int)u[i], "assigned but unused variable - %s", rb_id2name(v[i]));
9186  }
9187 }
9188 
9189 static void
9190 local_push_gen(struct parser_params *parser, int inherit_dvars)
9191 {
9192  struct local_vars *local;
9193 
9194  local = ALLOC(struct local_vars);
9195  local->prev = lvtbl;
9196  local->args = vtable_alloc(0);
9197  local->vars = vtable_alloc(inherit_dvars ? DVARS_INHERIT : DVARS_TOPSCOPE);
9198  local->used = !inherit_dvars && RTEST(ruby_verbose) ? vtable_alloc(0) : 0;
9199  local->cmdargs = cmdarg_stack;
9200  cmdarg_stack = 0;
9201  lvtbl = local;
9202 }
9203 
9204 static void
9205 local_pop_gen(struct parser_params *parser)
9206 {
9207  struct local_vars *local = lvtbl->prev;
9208  if (lvtbl->used) {
9209  warn_unused_var(parser, lvtbl);
9210  vtable_free(lvtbl->used);
9211  }
9212  vtable_free(lvtbl->args);
9213  vtable_free(lvtbl->vars);
9214  cmdarg_stack = lvtbl->cmdargs;
9215  xfree(lvtbl);
9216  lvtbl = local;
9217 }
9218 
9219 #ifndef RIPPER
9220 static ID*
9221 vtable_tblcpy(ID *buf, const struct vtable *src)
9222 {
9223  int i, cnt = vtable_size(src);
9224 
9225  if (cnt > 0) {
9226  buf[0] = cnt;
9227  for (i = 0; i < cnt; i++) {
9228  buf[i] = src->tbl[i];
9229  }
9230  return buf;
9231  }
9232  return 0;
9233 }
9234 
9235 static ID*
9236 local_tbl_gen(struct parser_params *parser)
9237 {
9238  int cnt = vtable_size(lvtbl->args) + vtable_size(lvtbl->vars);
9239  ID *buf;
9240 
9241  if (cnt <= 0) return 0;
9242  buf = ALLOC_N(ID, cnt + 1);
9243  vtable_tblcpy(buf+1, lvtbl->args);
9244  vtable_tblcpy(buf+vtable_size(lvtbl->args)+1, lvtbl->vars);
9245  buf[0] = cnt;
9246  return buf;
9247 }
9248 #endif
9249 
9250 static int
9251 arg_var_gen(struct parser_params *parser, ID id)
9252 {
9253  vtable_add(lvtbl->args, id);
9254  return vtable_size(lvtbl->args) - 1;
9255 }
9256 
9257 static int
9258 local_var_gen(struct parser_params *parser, ID id)
9259 {
9260  vtable_add(lvtbl->vars, id);
9261  if (lvtbl->used) {
9263  }
9264  return vtable_size(lvtbl->vars) - 1;
9265 }
9266 
9267 static int
9268 local_id_gen(struct parser_params *parser, ID id)
9269 {
9270  struct vtable *vars, *args, *used;
9271 
9272  vars = lvtbl->vars;
9273  args = lvtbl->args;
9274  used = lvtbl->used;
9275 
9276  while (vars && POINTER_P(vars->prev)) {
9277  vars = vars->prev;
9278  args = args->prev;
9279  if (used) used = used->prev;
9280  }
9281 
9282  if (vars && vars->prev == DVARS_INHERIT) {
9283  return rb_local_defined(id);
9284  }
9285  else if (vtable_included(args, id)) {
9286  return 1;
9287  }
9288  else {
9289  int i = vtable_included(vars, id);
9290  if (i && used) used->tbl[i-1] |= LVAR_USED;
9291  return i != 0;
9292  }
9293 }
9294 
9295 static const struct vtable *
9296 dyna_push_gen(struct parser_params *parser)
9297 {
9298  lvtbl->args = vtable_alloc(lvtbl->args);
9299  lvtbl->vars = vtable_alloc(lvtbl->vars);
9300  if (lvtbl->used) {
9301  lvtbl->used = vtable_alloc(lvtbl->used);
9302  }
9303  return lvtbl->args;
9304 }
9305 
9306 static void
9307 dyna_pop_1(struct parser_params *parser)
9308 {
9309  struct vtable *tmp;
9310 
9311  if ((tmp = lvtbl->used) != 0) {
9312  warn_unused_var(parser, lvtbl);
9313  lvtbl->used = lvtbl->used->prev;
9314  vtable_free(tmp);
9315  }
9316  tmp = lvtbl->args;
9317  lvtbl->args = lvtbl->args->prev;
9318  vtable_free(tmp);
9319  tmp = lvtbl->vars;
9320  lvtbl->vars = lvtbl->vars->prev;
9321  vtable_free(tmp);
9322 }
9323 
9324 static void
9325 dyna_pop_gen(struct parser_params *parser, const struct vtable *lvargs)
9326 {
9327  while (lvtbl->args != lvargs) {
9328  dyna_pop_1(parser);
9329  if (!lvtbl->args) {
9330  struct local_vars *local = lvtbl->prev;
9331  xfree(lvtbl);
9332  lvtbl = local;
9333  }
9334  }
9335  dyna_pop_1(parser);
9336 }
9337 
9338 static int
9339 dyna_in_block_gen(struct parser_params *parser)
9340 {
9341  return POINTER_P(lvtbl->vars) && lvtbl->vars->prev != DVARS_TOPSCOPE;
9342 }
9343 
9344 static int
9345 dvar_defined_gen(struct parser_params *parser, ID id, int get)
9346 {
9347  struct vtable *vars, *args, *used;
9348  int i;
9349 
9350  args = lvtbl->args;
9351  vars = lvtbl->vars;
9352  used = lvtbl->used;
9353 
9354  while (POINTER_P(vars)) {
9355  if (vtable_included(args, id)) {
9356  return 1;
9357  }
9358  if ((i = vtable_included(vars, id)) != 0) {
9359  if (used) used->tbl[i-1] |= LVAR_USED;
9360  return 1;
9361  }
9362  args = args->prev;
9363  vars = vars->prev;
9364  if (get) used = 0;
9365  if (used) used = used->prev;
9366  }
9367 
9368  if (vars == DVARS_INHERIT) {
9369  return rb_dvar_defined(id);
9370  }
9371 
9372  return 0;
9373 }
9374 
9375 static int
9376 dvar_curr_gen(struct parser_params *parser, ID id)
9377 {
9378  return (vtable_included(lvtbl->args, id) ||
9379  vtable_included(lvtbl->vars, id));
9380 }
9381 
9382 #ifndef RIPPER
9383 static void
9384 reg_fragment_setenc_gen(struct parser_params* parser, VALUE str, int options)
9385 {
9386  int c = RE_OPTION_ENCODING_IDX(options);
9387 
9388  if (c) {
9389  int opt, idx;
9390  rb_char_to_option_kcode(c, &opt, &idx);
9391  if (idx != ENCODING_GET(str) &&
9393  goto error;
9394  }
9395  ENCODING_SET(str, idx);
9396  }
9397  else if (RE_OPTION_ENCODING_NONE(options)) {
9398  if (!ENCODING_IS_ASCII8BIT(str) &&
9400  c = 'n';
9401  goto error;
9402  }
9404  }
9405  else if (parser->enc == rb_usascii_encoding()) {
9407  /* raise in re.c */
9409  }
9410  else {
9412  }
9413  }
9414  return;
9415 
9416  error:
9418  "regexp encoding option '%c' differs from source encoding '%s'",
9419  c, rb_enc_name(rb_enc_get(str)));
9420 }
9421 
9422 static int
9423 reg_fragment_check_gen(struct parser_params* parser, VALUE str, int options)
9424 {
9425  VALUE err;
9426  reg_fragment_setenc(str, options);
9427  err = rb_reg_check_preprocess(str);
9428  if (err != Qnil) {
9429  err = rb_obj_as_string(err);
9430  compile_error(PARSER_ARG "%s", RSTRING_PTR(err));
9431  RB_GC_GUARD(err);
9432  return 0;
9433  }
9434  return 1;
9435 }
9436 
9437 typedef struct {
9438  struct parser_params* parser;
9439  rb_encoding *enc;
9440  NODE *succ_block;
9441  NODE *fail_block;
9442  int num;
9444 
9445 static int
9446 reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end,
9447  int back_num, int *back_refs, OnigRegex regex, void *arg0)
9448 {
9450  struct parser_params* parser = arg->parser;
9451  rb_encoding *enc = arg->enc;
9452  long len = name_end - name;
9453  const char *s = (const char *)name;
9454  ID var;
9455 
9456  arg->num++;
9457 
9458  if (arg->succ_block == 0) {
9459  arg->succ_block = NEW_BEGIN(0);
9460  arg->fail_block = NEW_BEGIN(0);
9461  }
9462 
9463  if (!len || (*name != '_' && ISASCII(*name) && !rb_enc_islower(*name, enc)) ||
9464  (len < MAX_WORD_LENGTH && rb_reserved_word(s, (int)len)) ||
9465  !rb_enc_symname2_p(s, len, enc)) {
9466  return ST_CONTINUE;
9467  }
9468  var = rb_intern3(s, len, enc);
9469  if (dvar_defined(var) || local_id(var)) {
9470  rb_warningS("named capture conflicts a local variable - %s",
9471  rb_id2name(var));
9472  }
9473  arg->succ_block = block_append(arg->succ_block,
9475  NEW_CALL(
9476  gettable(rb_intern("$~")),
9477  idAREF,
9478  NEW_LIST(NEW_LIT(ID2SYM(var))))
9479  )));
9480  arg->fail_block = block_append(arg->fail_block,
9482  return ST_CONTINUE;
9483 }
9484 
9485 static NODE *
9486 reg_named_capture_assign_gen(struct parser_params* parser, VALUE regexp, NODE *match)
9487 {
9489 
9490  arg.parser = parser;
9491  arg.enc = rb_enc_get(regexp);
9492  arg.succ_block = 0;
9493  arg.fail_block = 0;
9494  arg.num = 0;
9496 
9497  if (arg.num == 0)
9498  return match;
9499 
9500  return
9501  block_append(
9502  newline_node(match),
9503  NEW_IF(gettable(rb_intern("$~")),
9504  block_append(
9505  newline_node(arg.succ_block),
9506  newline_node(
9507  NEW_CALL(
9508  gettable(rb_intern("$~")),
9509  rb_intern("begin"),
9510  NEW_LIST(NEW_LIT(INT2FIX(0)))))),
9511  block_append(
9512  newline_node(arg.fail_block),
9513  newline_node(
9514  NEW_LIT(Qnil)))));
9515 }
9516 
9517 static VALUE
9518 reg_compile_gen(struct parser_params* parser, VALUE str, int options)
9519 {
9520  VALUE re;
9521  VALUE err;
9522 
9523  reg_fragment_setenc(str, options);
9524  err = rb_errinfo();
9525  re = rb_reg_compile(str, options & RE_OPTION_MASK, ruby_sourcefile, ruby_sourceline);
9526  if (NIL_P(re)) {
9527  ID mesg = rb_intern("mesg");
9528  VALUE m = rb_attr_get(rb_errinfo(), mesg);
9529  rb_set_errinfo(err);
9530  if (!NIL_P(err)) {
9531  rb_str_append(rb_str_cat(rb_attr_get(err, mesg), "\n", 1), m);
9532  }
9533  else {
9535  }
9536  return Qnil;
9537  }
9538  return re;
9539 }
9540 
9541 void
9542 rb_gc_mark_parser(void)
9543 {
9544 }
9545 
9546 NODE*
9547 rb_parser_append_print(VALUE vparser, NODE *node)
9548 {
9549  NODE *prelude = 0;
9550  NODE *scope = node;
9551  struct parser_params *parser;
9552 
9553  if (!node) return node;
9554 
9555  TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser);
9556 
9557  node = node->nd_body;
9558 
9559  if (nd_type(node) == NODE_PRELUDE) {
9560  prelude = node;
9561  node = node->nd_body;
9562  }
9563 
9564  node = block_append(node,
9565  NEW_FCALL(rb_intern("print"),
9566  NEW_ARRAY(NEW_GVAR(rb_intern("$_")))));
9567  if (prelude) {
9568  prelude->nd_body = node;
9569  scope->nd_body = prelude;
9570  }
9571  else {
9572  scope->nd_body = node;
9573  }
9574 
9575  return scope;
9576 }
9577 
9578 NODE *
9579 rb_parser_while_loop(VALUE vparser, NODE *node, int chop, int split)
9580 {
9581  NODE *prelude = 0;
9582  NODE *scope = node;
9583  struct parser_params *parser;
9584 
9585  if (!node) return node;
9586 
9587  TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser);
9588 
9589  node = node->nd_body;
9590 
9591  if (nd_type(node) == NODE_PRELUDE) {
9592  prelude = node;
9593  node = node->nd_body;
9594  }
9595  if (split) {
9596  node = block_append(NEW_GASGN(rb_intern("$F"),
9597  NEW_CALL(NEW_GVAR(rb_intern("$_")),
9598  rb_intern("split"), 0)),
9599  node);
9600  }
9601  if (chop) {
9602  node = block_append(NEW_CALL(NEW_GVAR(rb_intern("$_")),
9603  rb_intern("chop!"), 0), node);
9604  }
9605 
9606  node = NEW_OPT_N(node);
9607 
9608  if (prelude) {
9609  prelude->nd_body = node;
9610  scope->nd_body = prelude;
9611  }
9612  else {
9613  scope->nd_body = node;
9614  }
9615 
9616  return scope;
9617 }
9618 
9619 static const struct {
9620  ID token;
9621  const char *name;
9622 } op_tbl[] = {
9623  {tDOT2, ".."},
9624  {tDOT3, "..."},
9625  {tPOW, "**"},
9626  {tUPLUS, "+@"},
9627  {tUMINUS, "-@"},
9628  {tCMP, "<=>"},
9629  {tGEQ, ">="},
9630  {tLEQ, "<="},
9631  {tEQ, "=="},
9632  {tEQQ, "==="},
9633  {tNEQ, "!="},
9634  {tMATCH, "=~"},
9635  {tNMATCH, "!~"},
9636  {tAREF, "[]"},
9637  {tASET, "[]="},
9638  {tLSHFT, "<<"},
9639  {tRSHFT, ">>"},
9640  {tCOLON2, "::"},
9641 };
9642 
9643 #define op_tbl_count numberof(op_tbl)
9644 
9645 #ifndef ENABLE_SELECTOR_NAMESPACE
9646 #define ENABLE_SELECTOR_NAMESPACE 0
9647 #endif
9648 
9649 static struct symbols {
9650  ID last_id;
9651  st_table *sym_id;
9652  st_table *id_str;
9653 #if ENABLE_SELECTOR_NAMESPACE
9654  st_table *ivar2_id;
9655  st_table *id_ivar2;
9656 #endif
9658 } global_symbols = {tLAST_ID};
9659 
9660 static const struct st_hash_type symhash = {
9662  rb_str_hash,
9663 };
9664 
9665 #if ENABLE_SELECTOR_NAMESPACE
9666 struct ivar2_key {
9667  ID id;
9668  VALUE klass;
9669 };
9670 
9671 static int
9672 ivar2_cmp(struct ivar2_key *key1, struct ivar2_key *key2)
9673 {
9674  if (key1->id == key2->id && key1->klass == key2->klass) {
9675  return 0;
9676  }
9677  return 1;
9678 }
9679 
9680 static int
9681 ivar2_hash(struct ivar2_key *key)
9682 {
9683  return (key->id << 8) ^ (key->klass >> 2);
9684 }
9685 
9686 static const struct st_hash_type ivar2_hash_type = {
9687  ivar2_cmp,
9688  ivar2_hash,
9689 };
9690 #endif
9691 
9692 void
9693 Init_sym(void)
9694 {
9695  global_symbols.sym_id = st_init_table_with_size(&symhash, 1000);
9697 #if ENABLE_SELECTOR_NAMESPACE
9698  global_symbols.ivar2_id = st_init_table_with_size(&ivar2_hash_type, 1000);
9699  global_symbols.id_ivar2 = st_init_numtable_with_size(1000);
9700 #endif
9701 
9702  Init_id();
9703 }
9704 
9705 void
9706 rb_gc_mark_symbols(void)
9707 {
9711 }
9712 #endif /* !RIPPER */
9713 
9714 static ID
9715 internal_id_gen(struct parser_params *parser)
9716 {
9717  ID id = (ID)vtable_size(lvtbl->args) + (ID)vtable_size(lvtbl->vars);
9718  id += ((tLAST_TOKEN - ID_INTERNAL) >> ID_SCOPE_SHIFT) + 1;
9719  return ID_INTERNAL | (id << ID_SCOPE_SHIFT);
9720 }
9721 
9722 #ifndef RIPPER
9723 static int
9724 is_special_global_name(const char *m, const char *e, rb_encoding *enc)
9725 {
9726  int mb = 0;
9727 
9728  if (m >= e) return 0;
9729  if (is_global_name_punct(*m)) {
9730  ++m;
9731  }
9732  else if (*m == '-') {
9733  ++m;
9734  if (m < e && is_identchar(m, e, enc)) {
9735  if (!ISASCII(*m)) mb = 1;
9736  m += rb_enc_mbclen(m, e, enc);
9737  }
9738  }
9739  else {
9740  if (!rb_enc_isdigit(*m, enc)) return 0;
9741  do {
9742  if (!ISASCII(*m)) mb = 1;
9743  ++m;
9744  } while (m < e && rb_enc_isdigit(*m, enc));
9745  }
9746  return m == e ? mb + 1 : 0;
9747 }
9748 
9749 int
9750 rb_symname_p(const char *name)
9751 {
9752  return rb_enc_symname_p(name, rb_ascii8bit_encoding());
9753 }
9754 
9755 int
9756 rb_enc_symname_p(const char *name, rb_encoding *enc)
9757 {
9758  return rb_enc_symname2_p(name, strlen(name), enc);
9759 }
9760 
9761 int
9762 rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
9763 {
9764  const char *m = name;
9765  const char *e = m + len;
9766  int localid = FALSE;
9767 
9768  if (!m || len <= 0) return FALSE;
9769  switch (*m) {
9770  case '\0':
9771  return FALSE;
9772 
9773  case '$':
9774  if (is_special_global_name(++m, e, enc)) return TRUE;
9775  goto id;
9776 
9777  case '@':
9778  if (*++m == '@') ++m;
9779  goto id;
9780 
9781  case '<':
9782  switch (*++m) {
9783  case '<': ++m; break;
9784  case '=': if (*++m == '>') ++m; break;
9785  default: break;
9786  }
9787  break;
9788 
9789  case '>':
9790  switch (*++m) {
9791  case '>': case '=': ++m; break;
9792  }
9793  break;
9794 
9795  case '=':
9796  switch (*++m) {
9797  case '~': ++m; break;
9798  case '=': if (*++m == '=') ++m; break;
9799  default: return FALSE;
9800  }
9801  break;
9802 
9803  case '*':
9804  if (*++m == '*') ++m;
9805  break;
9806 
9807  case '+': case '-':
9808  if (*++m == '@') ++m;
9809  break;
9810 
9811  case '|': case '^': case '&': case '/': case '%': case '~': case '`':
9812  ++m;
9813  break;
9814 
9815  case '[':
9816  if (*++m != ']') return FALSE;
9817  if (*++m == '=') ++m;
9818  break;
9819 
9820  case '!':
9821  if (len == 1) return TRUE;
9822  switch (*++m) {
9823  case '=': case '~': ++m; break;
9824  default: return FALSE;
9825  }
9826  break;
9827 
9828  default:
9829  localid = !rb_enc_isupper(*m, enc);
9830  id:
9831  if (m >= e || (*m != '_' && !rb_enc_isalpha(*m, enc) && ISASCII(*m)))
9832  return FALSE;
9833  while (m < e && is_identchar(m, e, enc)) m += rb_enc_mbclen(m, e, enc);
9834  if (localid) {
9835  switch (*m) {
9836  case '!': case '?': case '=': ++m;
9837  }
9838  }
9839  break;
9840  }
9841  return m == e;
9842 }
9843 
9844 static ID
9845 register_symid(ID id, const char *name, long len, rb_encoding *enc)
9846 {
9847  VALUE str = rb_enc_str_new(name, len, enc);
9848  OBJ_FREEZE(str);
9851  return id;
9852 }
9853 
9854 ID
9855 rb_intern3(const char *name, long len, rb_encoding *enc)
9856 {
9857  const char *m = name;
9858  const char *e = m + len;
9859  unsigned char c;
9860  VALUE str;
9861  ID id;
9862  long last;
9863  int mb;
9864  st_data_t data;
9865  struct RString fake_str;
9866  fake_str.basic.flags = T_STRING|RSTRING_NOEMBED;
9867  fake_str.basic.klass = rb_cString;
9868  fake_str.as.heap.len = len;
9869  fake_str.as.heap.ptr = (char *)name;
9870  fake_str.as.heap.aux.capa = len;
9871  str = (VALUE)&fake_str;
9872  rb_enc_associate(str, enc);
9873  OBJ_FREEZE(str);
9874 
9876  rb_raise(rb_eEncodingError, "invalid encoding symbol");
9877  }
9878 
9879  if (st_lookup(global_symbols.sym_id, str, &data))
9880  return (ID)data;
9881 
9882  if (rb_cString && !rb_enc_asciicompat(enc)) {
9883  id = ID_JUNK;
9884  goto new_id;
9885  }
9886  last = len-1;
9887  id = 0;
9888  switch (*m) {
9889  case '$':
9890  id |= ID_GLOBAL;
9891  if ((mb = is_special_global_name(++m, e, enc)) != 0) {
9892  if (!--mb) enc = rb_ascii8bit_encoding();
9893  goto new_id;
9894  }
9895  break;
9896  case '@':
9897  if (m[1] == '@') {
9898  m++;
9899  id |= ID_CLASS;
9900  }
9901  else {
9902  id |= ID_INSTANCE;
9903  }
9904  m++;
9905  break;
9906  default:
9907  c = m[0];
9908  if (c != '_' && rb_enc_isascii(c, enc) && rb_enc_ispunct(c, enc)) {
9909  /* operators */
9910  int i;
9911 
9912  if (len == 1) {
9913  id = c;
9914  goto id_register;
9915  }
9916  for (i = 0; i < op_tbl_count; i++) {
9917  if (*op_tbl[i].name == *m &&
9918  strcmp(op_tbl[i].name, m) == 0) {
9919  id = op_tbl[i].token;
9920  goto id_register;
9921  }
9922  }
9923  }
9924 
9925  if (m[last] == '=') {
9926  /* attribute assignment */
9927  id = rb_intern3(name, last, enc);
9928  if (id > tLAST_TOKEN && !is_attrset_id(id)) {
9929  enc = rb_enc_get(rb_id2str(id));
9930  id = rb_id_attrset(id);
9931  goto id_register;
9932  }
9933  id = ID_ATTRSET;
9934  }
9935  else if (rb_enc_isupper(m[0], enc)) {
9936  id = ID_CONST;
9937  }
9938  else {
9939  id = ID_LOCAL;
9940  }
9941  break;
9942  }
9943  mb = 0;
9944  if (!rb_enc_isdigit(*m, enc)) {
9945  while (m <= name + last && is_identchar(m, e, enc)) {
9946  if (ISASCII(*m)) {
9947  m++;
9948  }
9949  else {
9950  mb = 1;
9951  m += rb_enc_mbclen(m, e, enc);
9952  }
9953  }
9954  }
9955  if (m - name < len) id = ID_JUNK;
9956  if (enc != rb_usascii_encoding()) {
9957  /*
9958  * this clause makes sense only when called from other than
9959  * rb_intern_str() taking care of code-range.
9960  */
9961  if (!mb) {
9962  for (; m <= name + len; ++m) {
9963  if (!ISASCII(*m)) goto mbstr;
9964  }
9965  enc = rb_usascii_encoding();
9966  }
9967  mbstr:;
9968  }
9969  new_id:
9971  if (len > 20) {
9972  rb_raise(rb_eRuntimeError, "symbol table overflow (symbol %.20s...)",
9973  name);
9974  }
9975  else {
9976  rb_raise(rb_eRuntimeError, "symbol table overflow (symbol %.*s)",
9977  (int)len, name);
9978  }
9979  }
9981  id_register:
9982  return register_symid(id, name, len, enc);
9983 }
9984 
9985 ID
9986 rb_intern2(const char *name, long len)
9987 {
9988  return rb_intern3(name, len, rb_usascii_encoding());
9989 }
9990 
9991 #undef rb_intern
9992 ID
9993 rb_intern(const char *name)
9994 {
9995  return rb_intern2(name, strlen(name));
9996 }
9997 
9998 ID
9999 rb_intern_str(VALUE str)
10000 {
10001  rb_encoding *enc;
10002  ID id;
10003 
10005  enc = rb_usascii_encoding();
10006  }
10007  else {
10008  enc = rb_enc_get(str);
10009  }
10010  id = rb_intern3(RSTRING_PTR(str), RSTRING_LEN(str), enc);
10011  RB_GC_GUARD(str);
10012  return id;
10013 }
10014 
10015 VALUE
10016 rb_id2str(ID id)
10017 {
10018  st_data_t data;
10019 
10020  if (id < tLAST_TOKEN) {
10021  int i = 0;
10022 
10023  if (id < INT_MAX && rb_ispunct((int)id)) {
10024  VALUE str = global_symbols.op_sym[i = (int)id];
10025  if (!str) {
10026  char name[2];
10027  name[0] = (char)id;
10028  name[1] = 0;
10029  str = rb_usascii_str_new(name, 1);
10030  OBJ_FREEZE(str);
10032  }
10033  return str;
10034  }
10035  for (i = 0; i < op_tbl_count; i++) {
10036  if (op_tbl[i].token == id) {
10037  VALUE str = global_symbols.op_sym[i];
10038  if (!str) {
10039  str = rb_usascii_str_new2(op_tbl[i].name);
10040  OBJ_FREEZE(str);
10042  }
10043  return str;
10044  }
10045  }
10046  }
10047 
10048  if (st_lookup(global_symbols.id_str, id, &data)) {
10049  VALUE str = (VALUE)data;
10050  if (RBASIC(str)->klass == 0)
10051  RBASIC(str)->klass = rb_cString;
10052  return str;
10053  }
10054 
10055  if (is_attrset_id(id)) {
10056  ID id2 = (id & ~ID_SCOPE_MASK) | ID_LOCAL;
10057  VALUE str;
10058 
10059  while (!(str = rb_id2str(id2))) {
10060  if (!is_local_id(id2)) return 0;
10061  id2 = (id & ~ID_SCOPE_MASK) | ID_CONST;
10062  }
10063  str = rb_str_dup(str);
10064  rb_str_cat(str, "=", 1);
10065  rb_intern_str(str);
10066  if (st_lookup(global_symbols.id_str, id, &data)) {
10067  VALUE str = (VALUE)data;
10068  if (RBASIC(str)->klass == 0)
10069  RBASIC(str)->klass = rb_cString;
10070  return str;
10071  }
10072  }
10073  return 0;
10074 }
10075 
10076 const char *
10077 rb_id2name(ID id)
10078 {
10079  VALUE str = rb_id2str(id);
10080 
10081  if (!str) return 0;
10082  return RSTRING_PTR(str);
10083 }
10084 
10085 static int
10087 {
10088  rb_ary_push(ary, ID2SYM(value));
10089  return ST_CONTINUE;
10090 }
10091 
10092 /*
10093  * call-seq:
10094  * Symbol.all_symbols => array
10095  *
10096  * Returns an array of all the symbols currently in Ruby's symbol
10097  * table.
10098  *
10099  * Symbol.all_symbols.size #=> 903
10100  * Symbol.all_symbols[1,20] #=> [:floor, :ARGV, :Binding, :symlink,
10101  * :chown, :EOFError, :$;, :String,
10102  * :LOCK_SH, :"setuid?", :$<,
10103  * :default_proc, :compact, :extend,
10104  * :Tms, :getwd, :$=, :ThreadGroup,
10105  * :wait2, :$>]
10106  */
10107 
10108 VALUE
10109 rb_sym_all_symbols(void)
10110 {
10112 
10114  return ary;
10115 }
10116 
10117 int
10118 rb_is_const_id(ID id)
10119 {
10120  return is_const_id(id);
10121 }
10122 
10123 int
10124 rb_is_class_id(ID id)
10125 {
10126  return is_class_id(id);
10127 }
10128 
10129 int
10131 {
10132  return is_instance_id(id);
10133 }
10134 
10135 int
10136 rb_is_local_id(ID id)
10137 {
10138  return is_local_id(id);
10139 }
10140 
10141 int
10142 rb_is_junk_id(ID id)
10143 {
10144  return is_junk_id(id);
10145 }
10146 
10147 #endif /* !RIPPER */
10148 
10149 static void
10150 parser_initialize(struct parser_params *parser)
10151 {
10152  parser->eofp = Qfalse;
10153 
10154  parser->parser_lex_strterm = 0;
10155  parser->parser_cond_stack = 0;
10156  parser->parser_cmdarg_stack = 0;
10157  parser->parser_class_nest = 0;
10158  parser->parser_paren_nest = 0;
10159  parser->parser_lpar_beg = 0;
10160  parser->parser_in_single = 0;
10161  parser->parser_in_def = 0;
10162  parser->parser_in_defined = 0;
10163  parser->parser_compile_for_eval = 0;
10164  parser->parser_cur_mid = 0;
10165  parser->parser_tokenbuf = NULL;
10166  parser->parser_tokidx = 0;
10167  parser->parser_toksiz = 0;
10168  parser->parser_heredoc_end = 0;
10169  parser->parser_command_start = TRUE;
10170  parser->parser_deferred_nodes = 0;
10171  parser->parser_lex_pbeg = 0;
10172  parser->parser_lex_p = 0;
10173  parser->parser_lex_pend = 0;
10174  parser->parser_lvtbl = 0;
10175  parser->parser_ruby__end__seen = 0;
10176  parser->parser_ruby_sourcefile = 0;
10177 #ifndef RIPPER
10178  parser->is_ripper = 0;
10179  parser->parser_eval_tree_begin = 0;
10180  parser->parser_eval_tree = 0;
10181 #else
10182  parser->is_ripper = 1;
10183  parser->parser_ruby_sourcefile_string = Qnil;
10184  parser->delayed = Qnil;
10185 
10186  parser->result = Qnil;
10187  parser->parsing_thread = Qnil;
10188  parser->toplevel_p = TRUE;
10189 #endif
10190 #ifdef YYMALLOC
10191  parser->heap = NULL;
10192 #endif
10193  parser->enc = rb_usascii_encoding();
10194 }
10195 
10196 #ifdef RIPPER
10197 #define parser_mark ripper_parser_mark
10198 #define parser_free ripper_parser_free
10199 #endif
10200 
10201 static void
10202 parser_mark(void *ptr)
10203 {
10204  struct parser_params *p = (struct parser_params*)ptr;
10205 
10211 #ifndef RIPPER
10214  rb_gc_mark(p->debug_lines);
10215 #else
10216  rb_gc_mark(p->parser_ruby_sourcefile_string);
10217  rb_gc_mark(p->delayed);
10218  rb_gc_mark(p->value);
10219  rb_gc_mark(p->result);
10220  rb_gc_mark(p->parsing_thread);
10221 #endif
10222 #ifdef YYMALLOC
10223  rb_gc_mark((VALUE)p->heap);
10224 #endif
10225 }
10226 
10227 static void
10228 parser_free(void *ptr)
10229 {
10230  struct parser_params *p = (struct parser_params*)ptr;
10231  struct local_vars *local, *prev;
10232 
10233  if (p->parser_tokenbuf) {
10234  xfree(p->parser_tokenbuf);
10235  }
10236  for (local = p->parser_lvtbl; local; local = prev) {
10237  if (local->vars) xfree(local->vars);
10238  prev = local->prev;
10239  xfree(local);
10240  }
10241 #ifndef RIPPER
10243 #endif
10244  xfree(p);
10245 }
10246 
10247 static size_t
10248 parser_memsize(const void *ptr)
10249 {
10250  struct parser_params *p = (struct parser_params*)ptr;
10251  struct local_vars *local;
10252  size_t size = sizeof(*p);
10253 
10254  if (!ptr) return 0;
10255  size += p->parser_toksiz;
10256  for (local = p->parser_lvtbl; local; local = local->prev) {
10257  size += sizeof(*local);
10258  if (local->vars) size += local->vars->capa * sizeof(ID);
10259  }
10260 #ifndef RIPPER
10261  if (p->parser_ruby_sourcefile) {
10262  size += strlen(p->parser_ruby_sourcefile) + 1;
10263  }
10264 #endif
10265  return size;
10266 }
10267 
10268 static
10269 #ifndef RIPPER
10270 const
10271 #endif
10272 rb_data_type_t parser_data_type = {
10273  "parser",
10274  {
10275  parser_mark,
10276  parser_free,
10278  },
10279 };
10280 
10281 #ifndef RIPPER
10282 #undef rb_reserved_word
10283 
10284 const struct kwtable *
10285 rb_reserved_word(const char *str, unsigned int len)
10286 {
10287  return reserved_word(str, len);
10288 }
10289 
10290 static struct parser_params *
10291 parser_new(void)
10292 {
10293  struct parser_params *p;
10294 
10295  p = ALLOC_N(struct parser_params, 1);
10296  MEMZERO(p, struct parser_params, 1);
10297  parser_initialize(p);
10298  return p;
10299 }
10300 
10301 VALUE
10302 rb_parser_new(void)
10303 {
10304  struct parser_params *p = parser_new();
10305 
10306  return TypedData_Wrap_Struct(0, &parser_data_type, p);
10307 }
10308 
10309 /*
10310  * call-seq:
10311  * ripper#end_seen? -> Boolean
10312  *
10313  * Return true if parsed source ended by +\_\_END\_\_+.
10314  */
10315 VALUE
10316 rb_parser_end_seen_p(VALUE vparser)
10317 {
10318  struct parser_params *parser;
10319 
10320  TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser);
10321  return ruby__end__seen ? Qtrue : Qfalse;
10322 }
10323 
10324 /*
10325  * call-seq:
10326  * ripper#encoding -> encoding
10327  *
10328  * Return encoding of the source.
10329  */
10330 VALUE
10331 rb_parser_encoding(VALUE vparser)
10332 {
10333  struct parser_params *parser;
10334 
10335  TypedData_Get_Struct(vparser, struct parser_params, &parser_data_type, parser);
10336  return rb_enc_from_encoding(parser->enc);
10337 }
10338 
10339 /*
10340  * call-seq:
10341  * ripper.yydebug -> true or false
10342  *
10343  * Get yydebug.
10344  */
10345 VALUE
10347 {
10348  struct parser_params *parser;
10349 
10350  TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
10351  return yydebug ? Qtrue : Qfalse;
10352 }
10353 
10354 /*
10355  * call-seq:
10356  * ripper.yydebug = flag
10357  *
10358  * Set yydebug.
10359  */
10360 VALUE
10362 {
10363  struct parser_params *parser;
10364 
10365  TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
10366  yydebug = RTEST(flag);
10367  return flag;
10368 }
10369 
10370 #ifdef YYMALLOC
10371 #define HEAPCNT(n, size) ((n) * (size) / sizeof(YYSTYPE))
10372 #define NEWHEAP() rb_node_newnode(NODE_ALLOCA, 0, (VALUE)parser->heap, 0)
10373 #define ADD2HEAP(n, c, p) ((parser->heap = (n))->u1.node = (p), \
10374  (n)->u3.cnt = (c), (p))
10375 
10376 void *
10377 rb_parser_malloc(struct parser_params *parser, size_t size)
10378 {
10379  size_t cnt = HEAPCNT(1, size);
10380  NODE *n = NEWHEAP();
10381  void *ptr = xmalloc(size);
10382 
10383  return ADD2HEAP(n, cnt, ptr);
10384 }
10385 
10386 void *
10387 rb_parser_calloc(struct parser_params *parser, size_t nelem, size_t size)
10388 {
10389  size_t cnt = HEAPCNT(nelem, size);
10390  NODE *n = NEWHEAP();
10391  void *ptr = xcalloc(nelem, size);
10392 
10393  return ADD2HEAP(n, cnt, ptr);
10394 }
10395 
10396 void *
10397 rb_parser_realloc(struct parser_params *parser, void *ptr, size_t size)
10398 {
10399  NODE *n;
10400  size_t cnt = HEAPCNT(1, size);
10401 
10402  if (ptr && (n = parser->heap) != NULL) {
10403  do {
10404  if (n->u1.node == ptr) {
10405  n->u1.node = ptr = xrealloc(ptr, size);
10406  if (n->u3.cnt) n->u3.cnt = cnt;
10407  return ptr;
10408  }
10409  } while ((n = n->u2.node) != NULL);
10410  }
10411  n = NEWHEAP();
10412  ptr = xrealloc(ptr, size);
10413  return ADD2HEAP(n, cnt, ptr);
10414 }
10415 
10416 void
10417 rb_parser_free(struct parser_params *parser, void *ptr)
10418 {
10419  NODE **prev = &parser->heap, *n;
10420 
10421  while ((n = *prev) != NULL) {
10422  if (n->u1.node == ptr) {
10423  *prev = n->u2.node;
10425  break;
10426  }
10427  prev = &n->u2.node;
10428  }
10429  xfree(ptr);
10430 }
10431 #endif
10432 #endif
10433 
10434 #ifdef RIPPER
10435 #ifdef RIPPER_DEBUG
10436 extern int rb_is_pointer_to_heap(VALUE);
10437 
10438 /* :nodoc: */
10439 static VALUE
10440 ripper_validate_object(VALUE self, VALUE x)
10441 {
10442  if (x == Qfalse) return x;
10443  if (x == Qtrue) return x;
10444  if (x == Qnil) return x;
10445  if (x == Qundef)
10446  rb_raise(rb_eArgError, "Qundef given");
10447  if (FIXNUM_P(x)) return x;
10448  if (SYMBOL_P(x)) return x;
10449  if (!rb_is_pointer_to_heap(x))
10450  rb_raise(rb_eArgError, "invalid pointer: %p", x);
10451  switch (TYPE(x)) {
10452  case T_STRING:
10453  case T_OBJECT:
10454  case T_ARRAY:
10455  case T_BIGNUM:
10456  case T_FLOAT:
10457  return x;
10458  case T_NODE:
10459  if (nd_type(x) != NODE_LASGN) {
10460  rb_raise(rb_eArgError, "NODE given: %p", x);
10461  }
10462  return ((NODE *)x)->nd_rval;
10463  default:
10464  rb_raise(rb_eArgError, "wrong type of ruby object: %p (%s)",
10465  x, rb_obj_classname(x));
10466  }
10467  return x;
10468 }
10469 #endif
10470 
10471 #define validate(x) ((x) = get_value(x))
10472 
10473 static VALUE
10474 ripper_dispatch0(struct parser_params *parser, ID mid)
10475 {
10476  return rb_funcall(parser->value, mid, 0);
10477 }
10478 
10479 static VALUE
10480 ripper_dispatch1(struct parser_params *parser, ID mid, VALUE a)
10481 {
10482  validate(a);
10483  return rb_funcall(parser->value, mid, 1, a);
10484 }
10485 
10486 static VALUE
10487 ripper_dispatch2(struct parser_params *parser, ID mid, VALUE a, VALUE b)
10488 {
10489  validate(a);
10490  validate(b);
10491  return rb_funcall(parser->value, mid, 2, a, b);
10492 }
10493 
10494 static VALUE
10495 ripper_dispatch3(struct parser_params *parser, ID mid, VALUE a, VALUE b, VALUE c)
10496 {
10497  validate(a);
10498  validate(b);
10499  validate(c);
10500  return rb_funcall(parser->value, mid, 3, a, b, c);
10501 }
10502 
10503 static VALUE
10504 ripper_dispatch4(struct parser_params *parser, ID mid, VALUE a, VALUE b, VALUE c, VALUE d)
10505 {
10506  validate(a);
10507  validate(b);
10508  validate(c);
10509  validate(d);
10510  return rb_funcall(parser->value, mid, 4, a, b, c, d);
10511 }
10512 
10513 static VALUE
10514 ripper_dispatch5(struct parser_params *parser, ID mid, VALUE a, VALUE b, VALUE c, VALUE d, VALUE e)
10515 {
10516  validate(a);
10517  validate(b);
10518  validate(c);
10519  validate(d);
10520  validate(e);
10521  return rb_funcall(parser->value, mid, 5, a, b, c, d, e);
10522 }
10523 
10524 static const struct kw_assoc {
10525  ID id;
10526  const char *name;
10527 } keyword_to_name[] = {
10528  {keyword_class, "class"},
10529  {keyword_module, "module"},
10530  {keyword_def, "def"},
10531  {keyword_undef, "undef"},
10532  {keyword_begin, "begin"},
10533  {keyword_rescue, "rescue"},
10534  {keyword_ensure, "ensure"},
10535  {keyword_end, "end"},
10536  {keyword_if, "if"},
10537  {keyword_unless, "unless"},
10538  {keyword_then, "then"},
10539  {keyword_elsif, "elsif"},
10540  {keyword_else, "else"},
10541  {keyword_case, "case"},
10542  {keyword_when, "when"},
10543  {keyword_while, "while"},
10544  {keyword_until, "until"},
10545  {keyword_for, "for"},
10546  {keyword_break, "break"},
10547  {keyword_next, "next"},
10548  {keyword_redo, "redo"},
10549  {keyword_retry, "retry"},
10550  {keyword_in, "in"},
10551  {keyword_do, "do"},
10552  {keyword_do_cond, "do"},
10553  {keyword_do_block, "do"},
10554  {keyword_return, "return"},
10555  {keyword_yield, "yield"},
10556  {keyword_super, "super"},
10557  {keyword_self, "self"},
10558  {keyword_nil, "nil"},
10559  {keyword_true, "true"},
10560  {keyword_false, "false"},
10561  {keyword_and, "and"},
10562  {keyword_or, "or"},
10563  {keyword_not, "not"},
10564  {modifier_if, "if"},
10565  {modifier_unless, "unless"},
10566  {modifier_while, "while"},
10567  {modifier_until, "until"},
10568  {modifier_rescue, "rescue"},
10569  {keyword_alias, "alias"},
10570  {keyword_defined, "defined?"},
10571  {keyword_BEGIN, "BEGIN"},
10572  {keyword_END, "END"},
10573  {keyword__LINE__, "__LINE__"},
10574  {keyword__FILE__, "__FILE__"},
10575  {keyword__ENCODING__, "__ENCODING__"},
10576  {0, NULL}
10577 };
10578 
10579 static const char*
10580 keyword_id_to_str(ID id)
10581 {
10582  const struct kw_assoc *a;
10583 
10584  for (a = keyword_to_name; a->id; a++) {
10585  if (a->id == id)
10586  return a->name;
10587  }
10588  return NULL;
10589 }
10590 
10591 #undef ripper_id2sym
10592 static VALUE
10593 ripper_id2sym(ID id)
10594 {
10595  const char *name;
10596  char buf[8];
10597 
10598  if (id <= 256) {
10599  buf[0] = (char)id;
10600  buf[1] = '\0';
10601  return ID2SYM(rb_intern2(buf, 1));
10602  }
10603  if ((name = keyword_id_to_str(id))) {
10604  return ID2SYM(rb_intern(name));
10605  }
10606  switch (id) {
10607  case tOROP:
10608  name = "||";
10609  break;
10610  case tANDOP:
10611  name = "&&";
10612  break;
10613  default:
10614  name = rb_id2name(id);
10615  if (!name) {
10616  rb_bug("cannot convert ID to string: %ld", (unsigned long)id);
10617  }
10618  return ID2SYM(id);
10619  }
10620  return ID2SYM(rb_intern(name));
10621 }
10622 
10623 static ID
10624 ripper_get_id(VALUE v)
10625 {
10626  NODE *nd;
10627  if (!RB_TYPE_P(v, T_NODE)) return 0;
10628  nd = (NODE *)v;
10629  if (nd_type(nd) != NODE_LASGN) return 0;
10630  return nd->nd_vid;
10631 }
10632 
10633 static VALUE
10634 ripper_get_value(VALUE v)
10635 {
10636  NODE *nd;
10637  if (v == Qundef) return Qnil;
10638  if (!RB_TYPE_P(v, T_NODE)) return v;
10639  nd = (NODE *)v;
10640  if (nd_type(nd) != NODE_LASGN) return Qnil;
10641  return nd->nd_rval;
10642 }
10643 
10644 static void
10645 ripper_compile_error(struct parser_params *parser, const char *fmt, ...)
10646 {
10647  VALUE str;
10648  va_list args;
10649 
10650  va_start(args, fmt);
10651  str = rb_vsprintf(fmt, args);
10652  va_end(args);
10653  rb_funcall(parser->value, rb_intern("compile_error"), 1, str);
10654 }
10655 
10656 static void
10657 ripper_warn0(struct parser_params *parser, const char *fmt)
10658 {
10659  rb_funcall(parser->value, rb_intern("warn"), 1, STR_NEW2(fmt));
10660 }
10661 
10662 static void
10663 ripper_warnI(struct parser_params *parser, const char *fmt, int a)
10664 {
10665  rb_funcall(parser->value, rb_intern("warn"), 2,
10666  STR_NEW2(fmt), INT2NUM(a));
10667 }
10668 
10669 #if 0
10670 static void
10671 ripper_warnS(struct parser_params *parser, const char *fmt, const char *str)
10672 {
10673  rb_funcall(parser->value, rb_intern("warn"), 2,
10674  STR_NEW2(fmt), STR_NEW2(str));
10675 }
10676 #endif
10677 
10678 static void
10679 ripper_warning0(struct parser_params *parser, const char *fmt)
10680 {
10681  rb_funcall(parser->value, rb_intern("warning"), 1, STR_NEW2(fmt));
10682 }
10683 
10684 static void
10685 ripper_warningS(struct parser_params *parser, const char *fmt, const char *str)
10686 {
10687  rb_funcall(parser->value, rb_intern("warning"), 2,
10688  STR_NEW2(fmt), STR_NEW2(str));
10689 }
10690 
10691 static VALUE
10692 ripper_lex_get_generic(struct parser_params *parser, VALUE src)
10693 {
10694  return rb_funcall(src, ripper_id_gets, 0);
10695 }
10696 
10697 static VALUE
10698 ripper_s_allocate(VALUE klass)
10699 {
10700  struct parser_params *p;
10701  VALUE self;
10702 
10703  p = ALLOC_N(struct parser_params, 1);
10704  MEMZERO(p, struct parser_params, 1);
10705  self = TypedData_Wrap_Struct(klass, &parser_data_type, p);
10706  p->value = self;
10707  return self;
10708 }
10709 
10710 #define ripper_initialized_p(r) ((r)->parser_lex_input != 0)
10711 
10712 /*
10713  * call-seq:
10714  * Ripper.new(src, filename="(ripper)", lineno=1) -> ripper
10715  *
10716  * Create a new Ripper object.
10717  * _src_ must be a String, an IO, or an Object which has #gets method.
10718  *
10719  * This method does not starts parsing.
10720  * See also Ripper#parse and Ripper.parse.
10721  */
10722 static VALUE
10723 ripper_initialize(int argc, VALUE *argv, VALUE self)
10724 {
10725  struct parser_params *parser;
10726  VALUE src, fname, lineno;
10727 
10728  TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
10729  rb_scan_args(argc, argv, "12", &src, &fname, &lineno);
10730  if (rb_obj_respond_to(src, ripper_id_gets, 0)) {
10731  parser->parser_lex_gets = ripper_lex_get_generic;
10732  }
10733  else {
10734  StringValue(src);
10735  parser->parser_lex_gets = lex_get_str;
10736  }
10737  parser->parser_lex_input = src;
10738  parser->eofp = Qfalse;
10739  if (NIL_P(fname)) {
10740  fname = STR_NEW2("(ripper)");
10741  }
10742  else {
10743  StringValue(fname);
10744  }
10745  parser_initialize(parser);
10746 
10747  parser->parser_ruby_sourcefile_string = fname;
10748  parser->parser_ruby_sourcefile = RSTRING_PTR(fname);
10749  parser->parser_ruby_sourceline = NIL_P(lineno) ? 0 : NUM2INT(lineno) - 1;
10750 
10751  return Qnil;
10752 }
10753 
10754 struct ripper_args {
10755  struct parser_params *parser;
10756  int argc;
10757  VALUE *argv;
10758 };
10759 
10760 static VALUE
10761 ripper_parse0(VALUE parser_v)
10762 {
10763  struct parser_params *parser;
10764 
10765  TypedData_Get_Struct(parser_v, struct parser_params, &parser_data_type, parser);
10766  parser_prepare(parser);
10767  ripper_yyparse((void*)parser);
10768  return parser->result;
10769 }
10770 
10771 static VALUE
10772 ripper_ensure(VALUE parser_v)
10773 {
10774  struct parser_params *parser;
10775 
10776  TypedData_Get_Struct(parser_v, struct parser_params, &parser_data_type, parser);
10777  parser->parsing_thread = Qnil;
10778  return Qnil;
10779 }
10780 
10781 /*
10782  * call-seq:
10783  * ripper#parse
10784  *
10785  * Start parsing and returns the value of the root action.
10786  */
10787 static VALUE
10788 ripper_parse(VALUE self)
10789 {
10790  struct parser_params *parser;
10791 
10792  TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
10793  if (!ripper_initialized_p(parser)) {
10794  rb_raise(rb_eArgError, "method called for uninitialized object");
10795  }
10796  if (!NIL_P(parser->parsing_thread)) {
10797  if (parser->parsing_thread == rb_thread_current())
10798  rb_raise(rb_eArgError, "Ripper#parse is not reentrant");
10799  else
10800  rb_raise(rb_eArgError, "Ripper#parse is not multithread-safe");
10801  }
10802  parser->parsing_thread = rb_thread_current();
10803  rb_ensure(ripper_parse0, self, ripper_ensure, self);
10804 
10805  return parser->result;
10806 }
10807 
10808 /*
10809  * call-seq:
10810  * ripper#column -> Integer
10811  *
10812  * Return column number of current parsing line.
10813  * This number starts from 0.
10814  */
10815 static VALUE
10816 ripper_column(VALUE self)
10817 {
10818  struct parser_params *parser;
10819  long col;
10820 
10821  TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
10822  if (!ripper_initialized_p(parser)) {
10823  rb_raise(rb_eArgError, "method called for uninitialized object");
10824  }
10825  if (NIL_P(parser->parsing_thread)) return Qnil;
10826  col = parser->tokp - parser->parser_lex_pbeg;
10827  return LONG2NUM(col);
10828 }
10829 
10830 /*
10831  * call-seq:
10832  * ripper#filename -> String
10833  *
10834  * Return current parsing filename.
10835  */
10836 static VALUE
10837 ripper_filename(VALUE self)
10838 {
10839  struct parser_params *parser;
10840 
10841  TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
10842  if (!ripper_initialized_p(parser)) {
10843  rb_raise(rb_eArgError, "method called for uninitialized object");
10844  }
10845  return parser->parser_ruby_sourcefile_string;
10846 }
10847 
10848 /*
10849  * call-seq:
10850  * ripper#lineno -> Integer
10851  *
10852  * Return line number of current parsing line.
10853  * This number starts from 1.
10854  */
10855 static VALUE
10856 ripper_lineno(VALUE self)
10857 {
10858  struct parser_params *parser;
10859 
10860  TypedData_Get_Struct(self, struct parser_params, &parser_data_type, parser);
10861  if (!ripper_initialized_p(parser)) {
10862  rb_raise(rb_eArgError, "method called for uninitialized object");
10863  }
10864  if (NIL_P(parser->parsing_thread)) return Qnil;
10865  return INT2NUM(parser->parser_ruby_sourceline);
10866 }
10867 
10868 #ifdef RIPPER_DEBUG
10869 /* :nodoc: */
10870 static VALUE
10871 ripper_assert_Qundef(VALUE self, VALUE obj, VALUE msg)
10872 {
10873  StringValue(msg);
10874  if (obj == Qundef) {
10875  rb_raise(rb_eArgError, "%s", RSTRING_PTR(msg));
10876  }
10877  return Qnil;
10878 }
10879 
10880 /* :nodoc: */
10881 static VALUE
10882 ripper_value(VALUE self, VALUE obj)
10883 {
10884  return ULONG2NUM(obj);
10885 }
10886 #endif
10887 
10888 
10889 void
10890 InitVM_ripper(void)
10891 {
10892  parser_data_type.parent = RTYPEDDATA_TYPE(rb_parser_new());
10893 }
10894 
10895 void
10896 Init_ripper(void)
10897 {
10898  VALUE Ripper;
10899 
10900  InitVM(ripper);
10901  Ripper = rb_define_class("Ripper", rb_cObject);
10902  rb_define_const(Ripper, "Version", rb_usascii_str_new2(RIPPER_VERSION));
10903  rb_define_alloc_func(Ripper, ripper_s_allocate);
10904  rb_define_method(Ripper, "initialize", ripper_initialize, -1);
10905  rb_define_method(Ripper, "parse", ripper_parse, 0);
10906  rb_define_method(Ripper, "column", ripper_column, 0);
10907  rb_define_method(Ripper, "filename", ripper_filename, 0);
10908  rb_define_method(Ripper, "lineno", ripper_lineno, 0);
10909  rb_define_method(Ripper, "end_seen?", rb_parser_end_seen_p, 0);
10910  rb_define_method(Ripper, "encoding", rb_parser_encoding, 0);
10911  rb_define_method(Ripper, "yydebug", rb_parser_get_yydebug, 0);
10912  rb_define_method(Ripper, "yydebug=", rb_parser_set_yydebug, 1);
10913 #ifdef RIPPER_DEBUG
10914  rb_define_method(rb_mKernel, "assert_Qundef", ripper_assert_Qundef, 2);
10915  rb_define_method(rb_mKernel, "rawVALUE", ripper_value, 1);
10916  rb_define_method(rb_mKernel, "validate_object", ripper_validate_object, 1);
10917 #endif
10918 
10919  ripper_id_gets = rb_intern("gets");
10920  ripper_init_eventids1(Ripper);
10921  ripper_init_eventids2(Ripper);
10922  /* ensure existing in symbol table */
10923  (void)rb_intern("||");
10924  (void)rb_intern("&&");
10925 
10926 # if 0
10927  /* Hack to let RDoc document SCRIPT_LINES__ */
10928 
10929  /*
10930  * When a Hash is assigned to +SCRIPT_LINES__+ the contents of files loaded
10931  * after the assignment will be added as an Array of lines with the file
10932  * name as the key.
10933  */
10934  rb_define_global_const("SCRIPT_LINES__", Qnil);
10935 #endif
10936 
10937 }
10938 #endif /* RIPPER */
#define STRNCASECMP(s1, s2, n)
Definition: ruby.h:1467
RUBY_EXTERN VALUE rb_cString
Definition: ruby.h:1276
void rb_define_global_const(const char *, VALUE)
Definition: variable.c:1937
static int yylex(void *)
char * parser_ruby_sourcefile
Definition: ripper.c:295
VALUE val
Definition: ripper.y:170
#define RSTRING_LEN(string)
Definition: generator.h:45
#define NEW_YIELD(a, s)
#define deferred_nodes
Definition: ripper.c:362
#define nd_next
#define command_start
Definition: parse.y:303
#define nd_type(n)
#define NEW_ARGSCAT(a, b)
RARRAY_PTR(q->result)[0]
#define NODE_DREGX_ONCE
#define yyparse
Definition: ripper.c:386
#define T_OBJECT
Definition: ruby.h:413
#define lex_eol_p()
stack_type cmdargs
Definition: ripper.c:163
#define NEW_FALSE()
#define COND_PUSH(n)
Definition: parse.y:83
enum lex_state_e state
Definition: lex.c:33
struct local_vars * parser_lvtbl
Definition: ripper.c:291
#define NODE_IF
#define lex_p
Definition: parse.y:300
VALUE rb_ary_unshift(VALUE ary, VALUE item)
Definition: array.c:939
static ID ripper_token2eventid(int tok)
Definition: eventids2.c:267
#define NODE_RESCUE
Definition: lex.c:33
static NODE * match_op_gen(struct parser_params *, NODE *, NODE *)
int rb_enc_codelen(int c, rb_encoding *enc)
Definition: encoding.c:916
#define NODE_RETRY
Definition: ripper.y:118
#define NODE_DEFN
static double zero(void)
Definition: isinf.c:51
ssize_t n
Definition: bigdecimal.c:5519
#define gettable(id)
Definition: parse.y:389
#define MBCLEN_CHARFOUND_P(ret)
Definition: encoding.h:135
VALUE sym
Definition: tkutil.c:1298
#define RE_OPTION_ENCODING(e)
Definition: parse.y:474
volatile VALUE ary
Definition: tcltklib.c:9700
#define NODE_FALSE
#define NEW_DOT3(b, e)
static struct parser_params * parser_new(void)
Definition: ripper.c:16576
#define DVARS_TOPSCOPE
Definition: parse.y:109
VP_EXPORT int
Definition: bigdecimal.c:4911
#define NODE_OR
int onig_foreach_name(regex_t *reg, int(*func)(const UChar *, const UChar *, int, int *, regex_t *, void *), void *arg)
Definition: regparse.c:530
#define NEW_IASGN(v, val)
VALUE rb_get_coverages(void)
Definition: thread.c:4886
#define yydebug
Definition: ripper.c:370
#define dvar_defined_get(id)
Definition: parse.y:465
#define RE_OPTION_ENCODING_IDX(o)
Definition: parse.y:475
#define NEW_NTH_REF(n)
Definition: ripper.y:114
#define STR_NEW3(p, n, e, func)
Definition: parse.y:274
void rb_bug(const char *fmt,...)
Definition: error.c:265
#define NEW_DASGN_CURR(v, val)
static NODE * reg_named_capture_assign_gen(struct parser_params *parser, VALUE regexp, NODE *match)
#define IS_BEG()
#define ADD2HEAP(n, c, p)
struct token_info * next
Definition: ripper.c:245
#define FALSE
Definition: nkf.h:185
#define attrset(node, id)
Definition: parse.y:396
Definition: ripper.y:107
struct vtable * used
Definition: ripper.c:161
int idx
Definition: tcltklib.c:9703
#define tHEREDOC_BEG
Definition: eventids2.c:7
NODE * rb_parser_compile_file(volatile VALUE vparser, const char *f, VALUE file, int start)
Definition: ripper.c:11652
static int comment_at_top(struct parser_params *parser)
Definition: ripper.c:12713
#define rb_gc_mark_locations(start, end)
Definition: gc.c:1571
size_t strlen(const char *)
static size_t parser_memsize(const void *ptr)
Definition: ripper.c:16533
VALUE parser_lex_nextline
Definition: ripper.c:282
VALUE rb_make_exception(int argc, VALUE *argv)
Definition: eval.c:574
#define whole_match_p(e, l, i)
keyword_alias tGVAR tBACK_REF
Definition: ripper.y:976
#define scan_oct(s, l, e)
Definition: util.h:52
#define is_class_id(id)
Definition: parse.y:53
#define T_FIXNUM
Definition: ruby.h:425
Definition: st.h:77
VALUE stack_type
Definition: ripper.c:134
#define HEAPCNT(n, size)
#define cond_stack
Definition: parse.y:283
static void local_push_gen(struct parser_params *, int)
static NODE * node_assign_gen(struct parser_params *, NODE *, NODE *)
VALUE rb_id2str(ID id)
Definition: ripper.c:16301
#define new_yield(node)
Definition: parse.y:386
#define list_concat(h, t)
Definition: parse.y:359
int parser_ruby__end__seen
Definition: ripper.c:292
static void ripper_init_eventids2(VALUE self)
Definition: eventids2.c:62
#define NODE_DSYM
int parser_command_start
Definition: ripper.c:287
#define dyna_var(id)
Definition: parse.y:462
static int local_var_gen(struct parser_params *, ID)
static void fixpos(NODE *, NODE *)
Definition: ripper.c:14336
VALUE rb_range_new(VALUE, VALUE, int)
Definition: range.c:61
#define NODE_DEFS
#define lvar_defined(id)
Definition: parse.y:470
#define NUM2INT(x)
Definition: ruby.h:536
static int parser_yyerror(struct parser_params *, const char *)
#define NEW_CALL(r, m, a)
#define nd_body
#define COND_LEXPOP()
Definition: parse.y:85
parser parser_yylval val
Definition: ripper.c:14289
#define get_id(id)
Definition: parse.y:420
#define TOK_INTERN(mb)
Definition: parse.y:276
#define NODE_DOT3
#define local_var(id)
Definition: parse.y:448
const char * name
Definition: lex.c:33
#define tEMBDOC_BEG
Definition: eventids2.c:3
Definition: ripper.y:117
static int parser_tokadd_utf8(struct parser_params *parser, rb_encoding **encp, int string_literal, int symbol_literal, int regexp_literal)
Definition: ripper.c:11838
int parser_compile_for_eval
Definition: ripper.c:274
int parser_token_info_enabled
Definition: ripper.c:310
#define NEW_ALIAS(n, o)
static NODE * node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE)
VALUE op_sym[tLAST_TOKEN]
Definition: ripper.c:15942
#define IS_LABEL_SUFFIX(n)
VALUE rb_str_cat(VALUE, const char *, long)
Definition: string.c:1889
Definition: ripper.y:104
#define st_foreach
Definition: regint.h:150
mlhs_head mlhs_item
Definition: ripper.y:1486
#define paren_nest
Definition: parse.y:286
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
static void parser_heredoc_restore(struct parser_params *parser, NODE *here)
Definition: ripper.c:12482
#define LONG2NUM(i)
Definition: cparse.c:72
char * finish
Definition: yaml2byte.c:128
#define NEW_TRUE()
rb_hash_aset(CALLBACK_TABLE, id_num, cmd)
#define call_uni_op(recv, id)
Definition: parse.y:376
#define nd_resq
#define NODE_NTH_REF
#define RFLOAT_VALUE(val)
Definition: generator.h:32
#define NODE_TRUE
#define TypedData_Wrap_Struct(klass, data_type, sval)
Definition: ruby.h:826
static struct symbols global_symbols
VALUE rb_parser_end_seen_p(VALUE vparser)
Definition: ripper.c:16601
#define lex_lastline
Definition: parse.y:297
#define TypedData_Get_Struct(obj, type, data_type, sval)
Definition: ruby.h:840
int line_count
Definition: ripper.c:293
#define NEW_EVSTR(n)
#define NEW_NEXT(s)
struct token_info token_info
#define literal_concat(h, t)
Definition: parse.y:365
stack_type parser_cmdarg_stack
Definition: ripper.c:268
#define IS_END()
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *)
Definition: string.c:534
#define tokspace(n)
#define strcasecmp
Definition: win32.h:208
SYMID SyckParser * p
Definition: yaml2byte.c:119
#define is_const_id(id)
Definition: parse.y:52
VALUE rb_enc_from_encoding(rb_encoding *encoding)
Definition: encoding.c:102
#define NEW_NIL()
#define token_info_push(token)
Definition: ripper.c:666
return ST_CONTINUE
Definition: tkutil.c:1273
static VALUE debug_lines(const char *f)
Definition: ripper.c:11440
#define NODE_ENSURE
static int parser_here_document(struct parser_params *, NODE *)
Definition: ripper.c:12529
static NODE * arg_append_gen(struct parser_params *, NODE *, NODE *)
Definition: ripper.y:119
long(* rb_magic_comment_length_t)(struct parser_params *parser, const char *name, long len)
Definition: ripper.c:12725
#define NEW_ZARRAY()
#define lex_pbeg
Definition: parse.y:299
unsigned long VALUE
Definition: ruby.h:88
VALUE enc
Definition: tcltklib.c:10402
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:740
Definition: ripper.y:98
#define subnodes(n1, n2)
#define local_pop()
Definition: parse.y:446
VALUE rb_eEncodingError
Definition: error.c:473
static int reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end, int back_num, int *back_refs, OnigRegex regex, void *arg0)
Definition: ripper.c:15731
static void warn_unused_var(struct parser_params *parser, struct local_vars *local)
Definition: ripper.c:15455
struct RBasic basic
Definition: ruby.h:653
#define nd_else
rb_encoding * rb_enc_compatible(VALUE str1, VALUE str2)
Definition: encoding.c:750
#define newtok()
#define NODE_PRELUDE
#define nd_term(node)
Definition: parse.y:487
static VALUE INT2NUM(int v)
Definition: ruby.h:981
rb_encoding * utf8
Definition: ripper.c:298
#define void_stmts(node)
Definition: parse.y:348
#define NEW_MATCH2(n1, n2)
VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline)
Definition: re.c:2516
#define CMDARG_LEXPOP()
Definition: parse.y:90
VALUE debug_lines
Definition: ripper.c:306
#define parser_precise_mbclen()
#define shadowing_lvar(name)
Definition: parse.y:439
#define is_identchar(p, e, enc)
static NODE * arg_blk_pass(NODE *, NODE *)
static void VALUE * p2
Definition: array.c:1848
#define NEW_POSTEXE(b)
#define NEW_STR(s)
VALUE var
Definition: tcltklib.c:5506
keyword_alias tGVAR tNTH_REF
Definition: ripper.y:987
#define yyerrok
Definition: ripper.c:4193
#define NODE_EVSTR
#define RSTRING_PTR(string)
Definition: generator.h:42
static VALUE parse(int argc, VALUE *argv, VALUE self)
Definition: parser.c:229
static void reg_fragment_setenc_gen(struct parser_params *, VALUE, int)
int rb_enc_str_coderange(VALUE)
Definition: string.c:324
#define mixed_error(enc1, enc2)
#define NODE_DXSTR
#define NODE_CASE
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1574
#define STR_FUNC_INDENT
Definition: ripper.y:108
#define mixed_escape(beg, enc1, enc2)
return Qtrue
Definition: tcltklib.c:9597
Definition: ripper.y:148
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
Definition: encoding.c:727
ID * tbl
Definition: ripper.c:152
#define MAX_WORD_LENGTH
Definition: name2ctype.h:22187
const rb_data_type_t * parent
Definition: ruby.h:779
#define warn_balanced(op, syn)
void rb_compile_warn(const char *file, int line, const char *fmt,...)
Definition: error.c:153
#define peek_n(c, n)
static NODE * range_op(struct parser_params *parser, NODE *node)
Definition: ripper.c:15242
primary_value operation2 command_args prec tLOWEST
Definition: ripper.y:1370
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
#define T_HASH
Definition: ruby.h:421
#define NEW_CONST(v)
int parser_toksiz
Definition: ripper.c:279
#define set_yylval_node(x)
static NODE * new_yield_gen(struct parser_params *, NODE *)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
Definition: encoding.c:847
st_index_t rb_str_hash(VALUE)
Definition: string.c:2170
#define RARRAY_LEN(ARRAY)
Definition: generator.h:39
static void parser_pushback(struct parser_params *parser, int c)
Definition: ripper.c:11768
return str
Definition: ruby.c:1183
#define NODE_STR
ID last_id
Definition: ripper.c:15935
nd_set_line($$,$< num >2)
#define NODE_REDO
#define is_attrset_id(id)
Definition: parse.y:51
#define NODE_NEXT
#define formal_argument(id)
Definition: parse.y:437
Definition: ripper.y:111
#define NEW_DVAR(v)
void(* rb_magic_comment_setter_t)(struct parser_params *parser, const char *name, const char *val)
Definition: ripper.c:12726
#define T_ARRAY
Definition: ruby.h:420
r
Definition: bigdecimal.c:1154
#define heredoc_restore(n)
static void reduce_nodes_gen(struct parser_params *, NODE **)
#define st_lookup
Definition: regint.h:149
#define rb_enc_islower(c, enc)
Definition: encoding.h:173
#define rb_warningS(fmt, a)
Definition: parse.y:569
static struct vtable * dyna_push_gen(struct parser_params *)
#define ID_LOCAL
#define ruby_sourcefile
Definition: compile.c:426
#define NODE_XSTR
#define cmdarg_stack
Definition: parse.y:284
Definition: ripper.y:106
#define NEW_CVASGN(v, val)
static int parser_whole_match_p(struct parser_params *parser, const char *eos, long len, int indent)
Definition: ripper.c:12499
#define NODE_BLOCK_PASS
#define ISDIGIT(c)
mlhs_item mlhs_head
Definition: ripper.y:1558
#define reg_compile(str, options)
Definition: parse.y:412
#define NEW_BREAK(s)
unsigned int last
Definition: nkf.c:3915
#define NEW_OP_ASGN_OR(i, val)
static void parser_initialize(struct parser_params *parser)
Definition: ripper.c:16435
#define NEW_MASGN(l, r)
static NODE * yycompile(struct parser_params *parser, const char *f, int line)
Definition: ripper.c:11528
struct RNode * node
Definition: ripper.y:240
#define ruby_debug_lines
Definition: parse.y:317
static ID * vtable_tblcpy(ID *buf, const struct vtable *src)
Definition: ripper.c:15506
#define FIXNUM_P(f)
Definition: ruby.h:338
rb_encoding * rb_utf8_encoding(void)
Definition: encoding.c:1125
VALUE parser_lex_input
Definition: ripper.c:280
static long parser_encode_length(struct parser_params *parser, const char *name, long len)
Definition: ripper.c:12661
VALUE tbl
Definition: tkutil.c:1279
#define NEW_LVAR(v)
VALUE VALUE args
Definition: tcltklib.c:2550
#define STR_FUNC_REGEXP
VALUE rb_str_buf_append(VALUE, VALUE)
Definition: string.c:2031
VALUE rb_sym_all_symbols(void)
Definition: ripper.c:16394
static VALUE lex_getline(struct parser_params *parser)
Definition: ripper.c:11567
static NODE * call_uni_op_gen(struct parser_params *, NODE *, ID)
stmt
Definition: ripper.y:938
#define ID2SYM(i)
Definition: cparse.c:63
Definition: ripper.y:113
#define ID_INTERNAL
Definition: ripper.y:95
int pos
Definition: ripper.c:153
#define NEW_FOR(v, i, b)
#define NEW_CLASS(n, b, s)
static int literal_concat0(struct parser_params *, VALUE, VALUE)
static ID register_symid(ID, const char *, long, rb_encoding *)
static NODE * assignable_gen(struct parser_params *, ID, NODE *)
#define tokidx
Definition: parse.y:294
#define NODE_GASGN
#define LVAR_USED
#define list_append(l, i)
Definition: parse.y:357
int rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
Definition: ripper.c:16047
#define NEW_SPLAT(a)
#define ID_SCOPE_SHIFT
flag
Definition: tcltklib.c:2039
#define st_init_numtable_with_size
Definition: regint.h:143
VALUE rb_parser_set_yydebug(VALUE self, VALUE flag)
Definition: ripper.c:16646
#define ENC_CODERANGE_7BIT
Definition: encoding.h:58
#define NEW_PRELUDE(p, b)
#define block_dup_check(n1, n2)
Definition: parse.y:352
const char * rb_obj_classname(VALUE)
Definition: variable.c:318
d
Definition: strlcat.c:58
void rb_gc_force_recycle(VALUE p)
Definition: gc.c:2345
gz lineno
Definition: zlib.c:2031
static NODE * evstr2dstr_gen(struct parser_params *, NODE *)
#define NEW_ITER(a, b)
#define match_op(node1, node2)
Definition: parse.y:404
const char * fmt
Definition: tcltklib.c:837
unsigned char OnigUChar
Definition: oniguruma.h:110
int parser_yydebug
Definition: ripper.c:300
st_table * id_str
Definition: ripper.c:15937
NODE * parser_eval_tree
Definition: ripper.c:305
#define set_yylval_num(x)
NODE * parser_deferred_nodes
Definition: ripper.c:288
#define NEW_GVAR(v)
VALUE rb_str_buf_cat(VALUE, const char *, long)
Definition: string.c:1873
#define tLAST_TOKEN
Definition: ripper.y:37
command_asgn lhs
Definition: ripper.y:1241
Definition: ripper.y:236
static int e_option_supplied(struct parser_params *parser)
Definition: ripper.c:11474
int has_shebang
Definition: ripper.c:294
#define NEW_DSTR(s)
#define nd_set_type(n, t)
Real * b
Definition: bigdecimal.c:1140
static NODE * list_append_gen(struct parser_params *, NODE *, NODE *)
#define toklen()
static int assign_in_cond(struct parser_params *parser, NODE *node)
Definition: ripper.c:15158
#define ISALPHA(c)
Definition: ruby.h:1457
void rb_exc_raise(VALUE mesg)
Definition: eval.c:460
#define NEWHEAP()
#define NEW_UNLESS(c, t, e)
block_command ripper_id2sym('.')
#define NEW_MODULE(n, b)
#define Qnil
Definition: ruby.h:367
#define strtod(s, e)
Definition: util.h:76
static rb_encoding * must_be_ascii_compatible(VALUE s)
Definition: ripper.c:11537
struct vtable * prev
Definition: ripper.c:155
int rb_is_const_id(ID id)
Definition: ripper.c:16403
int rb_is_instance_id(ID id)
Definition: ripper.c:16415
#define RB_TYPE_P(obj, type)
Definition: ruby.h:1353
return rb_str_append(rb_str_new2(cmd_id_head), id_num)
static int parser_tokadd_string(struct parser_params *, int, int, int, long *, rb_encoding **)
Definition: ripper.c:12145
static NODE * remove_begin(NODE *)
#define nd_paren(node)
Definition: parse.y:489
VALUE hash
Definition: tkutil.c:267
#define assignable_result(x)
#define MEMZERO(p, type, n)
Definition: ruby.h:1052
Definition: ripper.y:109
Definition: ruby.h:652
Definition: ripper.y:96
#define NEW_OP_ASGN_AND(i, val)
rb_encoding * enc
Definition: ripper.c:297
static NODE * gettable_gen(struct parser_params *, ID)
#define nd_args
#define NODE_LVAR
static int parser_regx_options(struct parser_params *)
Definition: ripper.c:12084
n NULL
Definition: yaml2byte.c:134
enum lex_state_e parser_lex_state
Definition: ripper.c:266
#define NODE_LASGN
int capa
Definition: ripper.c:154
VALUE parser_lex_lastline
Definition: ripper.c:281
#define NEW_OPT_N(b)
Definition: ripper.y:112
void * data
Definition: yaml2byte.c:131
static NODE * newline_node(NODE *)
NODE * rb_parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
Definition: ripper.c:11617
BDIGIT m
Definition: bigdecimal.c:4946
static int parser_yylex(struct parser_params *parser)
Definition: ripper.c:12989
static VALUE parser_str_new(const char *p, long n, rb_encoding *enc, int func, rb_encoding *enc0)
Definition: ripper.c:11690
#define scan_hex(s, l, e)
Definition: util.h:54
return Qfalse
Definition: tcltklib.c:6768
static char * parser_tokspace(struct parser_params *parser, int n)
Definition: ripper.c:11800
static NODE * cond_gen(struct parser_params *, NODE *)
#define arg_append(h, t)
Definition: parse.y:361
#define RARRAY(obj)
Definition: ruby.h:911
#define local_id(id)
Definition: parse.y:452
#define ALLOC_N(type, n)
Definition: ruby.h:1034
#define op_tbl_count
void rb_compile_error_append(const char *fmt,...)
Definition: error.c:129
static void parser_free(void *ptr)
Definition: ripper.c:16513
#define nextc()
#define NODE_WHEN
#define parser_warning(node, mesg)
#define RE_OPTION_ONCE
Definition: parse.y:472
int rb_ispunct(int c)
Definition: encoding.c:1646
static void vtable_add(struct vtable *tbl, ID id)
Definition: parse.y:151
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1246
VALUE rb_eRuntimeError
Definition: error.c:466
static int symbols_i(VALUE sym, ID value, VALUE ary)
Definition: ripper.c:16371
#define NEW_RESCUE(b, res, e)
static int parser_tokadd_escape(struct parser_params *parser, rb_encoding **encp)
Definition: ripper.c:12011
#define rb_enc_isascii(c, enc)
Definition: encoding.h:171
VALUE rb_parser_encoding(VALUE vparser)
Definition: ripper.c:16616
#define st_init_table_with_size
Definition: regint.h:141
struct parser_params * parser
Definition: ripper.c:15723
#define NODE_YIELD
#define NEW_NODE(t, a0, a1, a2)
#define NEW_LIST(a)
#define NEW_ENSURE(b, en)
#define NODE_FLIP2
char * ruby_strdup(const char *)
Definition: util.c:425
#define NODE_BLOCK
#define ID_INSTANCE
static NODE * attrset_gen(struct parser_params *, NODE *, ID)
NODE * rb_compile_string(const char *f, VALUE s, int line)
Definition: ripper.c:11610
#define NEW_BLOCK(a)
VALUE rb_obj_as_string(VALUE)
Definition: string.c:854
#define NODE_DASGN_CURR
#define NODE_HEREDOC
Definition: parse.y:481
int parser_paren_nest
Definition: ripper.c:270
static int dvar_curr_gen(struct parser_params *, ID)
VALUE rb_ary_new(void)
Definition: array.c:339
#define NODE_AND
#define local_push(top)
Definition: parse.y:444
#define new_args(f, o, r, p, b)
Definition: parse.y:379
int rb_ascii8bit_encindex(void)
Definition: encoding.c:1119
int flags
Definition: tcltklib.c:3012
static int is_global_name_punct(const char c)
Definition: ripper.c:12318
#define NEW_UNDEF(i)
#define ID_JUNK
#define dispatch_heredoc_end()
va_end(args)
#define ID_GLOBAL
static char * parser_newtok(struct parser_params *parser)
Definition: ripper.c:11785
RUBY_EXTERN VALUE rb_mKernel
Definition: ruby.h:1234
#define lex_pend
Definition: parse.y:301
#define snprintf
Definition: subst.h:6
VALUE rb_thread_current(void)
Definition: thread.c:1742
#define heredoc_identifier()
#define SPECIAL_PUNCT(idx)
#define NIL_P(v)
Definition: ruby.h:374
#define NEW_WHEN(c, t, e)
#define ISASCII(c)
Definition: ruby.h:1450
#define IS_ARG()
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:469
static VALUE VALUE obj
Definition: tcltklib.c:3147
static void parser_set_token_info(struct parser_params *parser, const char *name, const char *val)
Definition: ripper.c:12738
static struct st_hash_type symhash
Definition: ripper.c:15945
#define toksiz
Definition: parse.y:295
#define call_bin_op(recv, id, arg1)
Definition: parse.y:374
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:1923
static NODE * call_bin_op_gen(struct parser_params *, NODE *, ID, NODE *)
static void parser_tokadd(struct parser_params *parser, int c)
Definition: ripper.c:11812
#define k__END__
Definition: eventids2.c:9
#define ruby_eval_tree_begin
Definition: parse.y:316
static void parser_mark(void *ptr)
Definition: ripper.c:16487
#define ISALNUM(c)
Definition: ruby.h:1456
#define RFLOAT(obj)
Definition: ruby.h:908
static double one(void)
Definition: isinf.c:52
enum node_type nodetype(NODE *node)
Definition: ripper.c:14314
#define evstr2dstr(n)
Definition: parse.y:370
#define NODE_ARGSCAT
#define NODE_COLON2
#define T_FLOAT
Definition: ruby.h:417
NODE * rb_parser_append_print(VALUE vparser, NODE *node)
Definition: ripper.c:15832
pure parser lex param
Definition: ripper.y:617
#define RE_OPTION_ENCODING_NONE(o)
Definition: parse.y:476
#define TYPE(x)
Definition: ruby.h:441
static NODE * parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
Definition: ripper.c:11590
#define ALLOCA_N(type, n)
Definition: ruby.h:1038
#define NEW_ARGS_AUX(r, b)
#define T_BIGNUM
Definition: ruby.h:423
static struct @13 op_tbl[]
static VALUE coverage(const char *f, int n)
Definition: ripper.c:11457
#define ENC_CODERANGE_UNKNOWN
Definition: encoding.h:57
keyword_END
Definition: ripper.y:1057
static VALUE lex_get_str(struct parser_params *parser, VALUE s)
Definition: ripper.c:11547
#define ISUPPER(c)
Definition: ruby.h:1454
#define RUBY_FUNC_EXPORTED
Definition: defines.h:254
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1053
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:3913
#define rb_warn0(fmt)
Definition: parse.y:565
static NODE * block_append_gen(struct parser_params *, NODE *, NODE *)
#define T_NODE
Definition: ruby.h:434
#define ENC_CODERANGE_BROKEN
Definition: encoding.h:60
#define rb_enc_isupper(c, enc)
Definition: encoding.h:174
VALUE rb_enc_associate_index(VALUE obj, int idx)
Definition: encoding.c:709
int rb_parse_in_main(void)
Definition: compile.c:5576
static int parser_nextc(struct parser_params *parser)
Definition: ripper.c:11712
#define NEW_ARGS(m, o)
int err
Definition: win32.c:78
#define dyna_pop(node)
Definition: ripper.c:517
#define OBJ_FREEZE(x)
Definition: ruby.h:970
#define ESCAPE_CONTROL
#define dyna_in_block()
Definition: parse.y:461
static VALUE VALUE assoc
Definition: tkutil.c:544
const char * parser_lex_pend
Definition: ripper.c:285
#define NEW_DEFINED(e)
#define RE_OPTION_MASK
Definition: parse.y:477
#define in_defined
Definition: parse.y:292
static void block_dup_check_gen(struct parser_params *, NODE *, NODE *)
static int local_id_gen(struct parser_params *, ID)
#define rb_backref_error(n)
Definition: parse.y:399
void rb_gc_mark_symbols(void)
Definition: ripper.c:15991
long cnt
Definition: ripper.y:257
ID token
Definition: ripper.c:15905
static int VALUE key
Definition: tkutil.c:265
Definition: ripper.y:115
NODE * rb_parser_while_loop(VALUE vparser, NODE *node, int chop, int split)
Definition: ripper.c:15864
static void rb_backref_error_gen(struct parser_params *, NODE *)
NODE * rb_compile_cstr(const char *f, const char *s, int len, int line)
Definition: ripper.c:11624
token_info * parser_token_info
Definition: ripper.c:311
Definition: ripper.y:122
static int lvar_defined_gen(struct parser_params *, ID)
static void magic_comment_encoding(struct parser_params *parser, const char *name, const char *val)
Definition: ripper.c:12729
int column
Definition: ripper.c:243
#define parser_is_identchar()
VALUE rb_make_backtrace(void)
Definition: vm_eval.c:1657
#define ALLOC(type)
Definition: ruby.h:1035
#define lex_state
Definition: parse.y:282
#define EOF
Definition: vsnprintf.c:206
void * rb_parser_malloc(struct parser_params *parser, size_t size)
Definition: ripper.c:16662
VALUE rb_str_resize(VALUE, long)
Definition: string.c:1779
#define tHEREDOC_END
Definition: eventids2.c:8
#define ID_CLASS
static int parser_peek_variable_name(struct parser_params *parser)
Definition: ripper.c:12325
#define NEW_LAMBDA(a)
#define NEW_LASGN(v, val)
node_type
Definition: ripper.y:23
int rb_str_hash_cmp(VALUE, VALUE)
Definition: string.c:2180
VALUE * argv
Definition: tcltklib.c:1962
#define NEW_OPT_ARG(i, v)
string_type
Definition: ripper.c:11678
int rb_dvar_defined(ID id)
Definition: compile.c:5526
#define lex_gets
Definition: parse.y:306
static int arg_var_gen(struct parser_params *, ID)
static void dispose_string(VALUE str)
Definition: ripper.c:12120
#define IS_SPCARG(c)
#define arg_ambiguous()
static int reg_fragment_check_gen(struct parser_params *, VALUE, int)
int parser_in_single
Definition: ripper.c:272
const int id
Definition: nkf.c:209
#define NEW_SCLASS(r, b)
#define void_expr(node)
Definition: parse.y:346
#define node_assign(node1, node2)
Definition: parse.y:401
#define ret_args(node)
Definition: parse.y:383
#define REALLOC_N(var, type, n)
Definition: ruby.h:1036
#define set_yylval_name(x)
int errno
#define TRUE
Definition: nkf.h:186
int rb_symname_p(const char *name)
Definition: ripper.c:16035
q result
Definition: tcltklib.c:7059
#define NODE_NIL
VALUE rb_io_gets(VALUE)
Definition: io.c:2892
mlhs_head tSTAR mlhs_node
Definition: ripper.y:1494
#define tok()
#define NODE_ATTRASGN
#define token_info_pop(token)
Definition: ripper.c:667
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1203
volatile VALUE value
Definition: tcltklib.c:9429
#define NODE_COLON3
#define NODE_DEFINED
#define in_def
Definition: parse.y:289
static ID formal_argument_gen(struct parser_params *, ID)
#define rb_enc_isspace(c, enc)
Definition: encoding.h:178
#define rb_node_newnode(type, a1, a2, a3)
Definition: ripper.c:389
stmt modifier_if expr_value
Definition: ripper.y:1005
#define lex_strterm
Definition: parse.y:281
int rb_obj_respond_to(VALUE, ID, int)
Definition: vm_method.c:1218
union RNode::@15 u2
block_command block_call tCOLON2 operation2 command_args
Definition: ripper.y:1316
static void set_file_encoding(struct parser_params *parser, const char *str, const char *send)
Definition: ripper.c:12900
#define NEW_DOT2(b, e)
static NODE * ret_args_gen(struct parser_params *, NODE *)
#define NODE_MASGN
#define RB_GC_GUARD(object)
Definition: generator.h:50
#define nd_nth
#define rb_enc_name(enc)
Definition: encoding.h:121
#define rb_warnS(fmt, a)
Definition: parse.y:567
#define NEW_DASGN(v, val)
register char * s
Definition: os2.c:56
#define NEW_VALIAS(n, o)
#define read_escape(flags, e)
#define parser_isascii()
int rb_enc_symname_p(const char *name, rb_encoding *enc)
Definition: ripper.c:16041
#define NEW_POSTARG(i, v)
#define here_document(n)
#define NEW_ERRINFO()
#define tok_hex(numlen)
void Init_sym(void)
Definition: ripper.c:15978
static void local_pop_gen(struct parser_params *)
#define NODE_CONST
static int parser_parse_string(struct parser_params *, NODE *)
Definition: ripper.c:12361
#define heredoc_end
Definition: parse.y:302
static NODE * literal_concat_gen(struct parser_params *, NODE *, NODE *)
VP_EXPORT void
Definition: bigdecimal.c:4944
static void void_expr_gen(struct parser_params *, NODE *)
int rb_is_local_id(ID id)
Definition: ripper.c:16421
rb_magic_comment_length_t length
Definition: ripper.c:12762
int parser_in_def
Definition: ripper.c:273
static NODE * negate_lit(NODE *)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1416
#define NEW_SUPER(a)
#define no_digits()
mlhs mlhs_inner
Definition: ripper.y:1453
#define NEW_COLON2(c, i)
static int dyna_in_block_gen(struct parser_params *)
static void fixup_nodes(NODE **)
VALUE parser_cur_mid
Definition: ripper.c:275
#define NEW_STRTERM(func, term, paren)
static void Init_id(void)
Definition: ripper.y:17
#define is_junk_id(id)
Definition: parse.y:54
long parser_lex_gets_ptr
Definition: ripper.c:289
unsigned long ID
Definition: ruby.h:89
#define NODE_GVAR
#define NODE_CDECL
#define CMDARG_PUSH(n)
Definition: parse.y:88
rb_encoding * rb_usascii_encoding(void)
Definition: encoding.c:1140
#define NEW_HASH(a)
#define rb_enc_isalnum(c, enc)
Definition: encoding.h:176
#define reg_named_capture_assign(regexp, match)
Definition: parse.y:418
#define rb_enc_isdigit(c, enc)
Definition: encoding.h:179
#define arg_concat(h, t)
Definition: parse.y:363
Definition: ripper.y:93
static VALUE yycompile0(VALUE arg, int tracing)
Definition: ripper.c:11480
static void arg_ambiguous_gen(struct parser_params *parser)
Definition: ripper.c:12632
static void parser_prepare(struct parser_params *parser)
Definition: ripper.c:12943
#define set_yylval_id(x)
#define NODE_LIT
#define rb_reserved_word(str, len)
Definition: lex.c:37
int type
Definition: tcltklib.c:107
int id[2]
Definition: lex.c:33
#define NEW_UNTIL(c, b, n)
#define NEW_MATCH3(r, n2)
int argc
Definition: tcltklib.c:1961
stack_type parser_cond_stack
Definition: ripper.c:267
#define ESCAPE_META
#define RBASIC(obj)
Definition: ruby.h:904
int rb_is_junk_id(ID id)
Definition: ripper.c:16427
static void dyna_pop_1(struct parser_params *parser)
Definition: ripper.c:15592
static int parser_read_escape(struct parser_params *parser, int flags, rb_encoding **encp)
Definition: ripper.c:11913
int parser_heredoc_end
Definition: ripper.c:286
#define ruby_sourceline
Definition: ripper.c:367
static void new_bv_gen(struct parser_params *, ID)
static int parser_heredoc_identifier(struct parser_params *parser)
Definition: ripper.c:12419
Definition: ripper.y:100
#define rb_enc_ispunct(c, enc)
Definition: encoding.h:175
static void ripper_init_eventids1(VALUE self)
Definition: eventids1.c:129
#define str_copy(_s, _p, _n)
ID rb_id_attrset(ID id)
Definition: ripper.c:14811
void rb_mark_tbl(st_table *tbl)
Definition: gc.c:1735
mlhs_head tSTAR
Definition: ripper.y:1511
#define regx_options()
register unsigned int len
Definition: name2ctype.h:22210
#define NEW_SELF()
#define xfree
Definition: defines.h:69
#define rb_enc_asciicompat(enc)
Definition: encoding.h:181
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
Definition: eval.c:737
VALUE flags
Definition: ruby.h:597
#define NEW_RESBODY(a, ex, n)
#define NEW_RETURN(s)
#define NODE_ARGSPUSH
#define NODE_BACK_REF
int rb_char_to_option_kcode(int c, int *option, int *kcode)
Definition: re.c:285
#define NODE_MATCH
#define is_instance_id(id)
Definition: parse.y:50
#define tokadd(c)
#define set_yylval_str(x)
VALUE rb_reg_check_preprocess(VALUE)
Definition: re.c:2289
#define lvtbl
Definition: parse.y:307
VALUE flags
Definition: ripper.y:237
static ID shadowing_lvar_gen(struct parser_params *, ID)
const char * token
Definition: ripper.c:241
static NODE * arg_concat_gen(struct parser_params *, NODE *, NODE *)
ruby_verbose
Definition: tcltklib.c:5807
#define ENCODING_IS_ASCII8BIT(obj)
Definition: encoding.h:52
#define NEW_COLON3(i)
VALUE rb_str_dup(VALUE)
Definition: string.c:905
#define NEW_CASE(h, b)
return ptr
Definition: tcltklib.c:780
#define rb_enc_isalpha(c, enc)
Definition: encoding.h:172
VpDivd * c
Definition: bigdecimal.c:1163
mlhs_head tSTAR mlhs_post
Definition: ripper.y:1502
long st_data_t
Definition: syck.h:69
#define value_expr(node)
Definition: parse.y:344
state
Definition: gb18030.c:213
#define NODE_DASGN
int parser_in_defined
Definition: ripper.c:276
VALUE msg
Definition: tcltklib.c:842
#define reg_fragment_setenc(str, options)
Definition: parse.y:414
#define NEW_BACK_REF(n)
#define new_bv(id)
Definition: parse.y:441
int parser_class_nest
Definition: ripper.c:269
#define DVARS_INHERIT
Definition: parse.y:108
#define ruby_eval_tree
Definition: parse.y:315
#define ruby__end__seen
Definition: parse.y:308
#define dvar_curr(id)
Definition: parse.y:467
mlhs_node keyword_variable
Definition: ripper.y:1615
Definition: ripper.y:121
command operation command_args cmd_brace_block
Definition: ripper.y:1358
static void vtable_free(struct vtable *tbl)
Definition: parse.y:139
gz end
Definition: zlib.c:2033
#define NEW_IF(c, t, e)
nd_iter
Definition: parse.y:1361
#define logop(type, node1, node2)
Definition: parse.y:336
#define NEW_GASGN(v, val)
#define PARSER_ARG
Definition: parse.y:593
static void warning_unless_e_option(struct parser_params *parser, NODE *node, const char *str)
Definition: ripper.c:15205
#define NEW_ARGSPUSH(a, b)
static void parser_tokaddmbc(struct parser_params *parser, int c, rb_encoding *enc)
Definition: ripper.c:12004
#define SYMBOL_P(v)
Definition: cparse.c:69
arg
Definition: ripper.y:1287
static NODE * logop_gen(struct parser_params *, enum node_type, NODE *, NODE *)
VALUE rb_usascii_str_new2(const char *)
VALUE src
Definition: tcltklib.c:7940
#define assignable(id, node)
Definition: parse.y:391
int rb_const_defined_at(VALUE, ID)
Definition: variable.c:1853
#define NEW_XSTR(s)
fitem
Definition: ripper.y:960
#define ENCODING_GET(obj)
Definition: encoding.h:47
Definition: ripper.y:110
rb_encoding * rb_enc_get(VALUE obj)
Definition: encoding.c:733
#define NEW_WHILE(c, b, n)
#define NEW_DEFS(r, i, a, d)
void rb_gc_mark_parser(void)
Definition: ripper.c:15827
keyword_undef undef_list
Definition: ripper.y:997
int nonspc
Definition: ripper.c:244
int size
Definition: encoding.c:51
#define INT2FIX(i)
Definition: ruby.h:225
static void no_blockarg(struct parser_params *parser, NODE *node)
Definition: ripper.c:15358
top_stmt
Definition: ripper.y:838
#define NODE_FLIP3
opt_block_param compstmt
Definition: ripper.y:1337
#define POINTER_P(val)
Definition: parse.y:111
void rb_parser_free(struct parser_params *parser, void *ptr)
Definition: ripper.c:16702
int parser_tokidx
Definition: ripper.c:278
#define ruby_coverage
Definition: parse.y:318
#define NODE_DVAR
static VALUE ULONG2NUM(unsigned long v)
Definition: ruby.h:1015
static struct magic_comment magic_comments[]
Definition: ripper.c:12765
#define is_local_id(id)
Definition: parse.y:48
#define xmalloc
Definition: defines.h:64
#define rb_compile_error
Definition: ripper.c:649
ID rb_intern_str(VALUE str)
Definition: ripper.c:16284
static NODE * new_args_gen(struct parser_params *, NODE *, NODE *, ID, NODE *, ID)
Definition: ripper.y:91
Definition: ripper.y:126
VALUE coverage
Definition: ripper.c:307
#define COND_POP()
Definition: parse.y:84
command_call
Definition: ripper.y:1279
int t
Definition: ripper.c:14285
void rb_set_errinfo(VALUE err)
Definition: eval.c:1065
NODE * parser_lex_strterm
Definition: ripper.c:265
const char * name
Definition: ripper.c:12760
#define NEW_IVAR(v)
top_stmts dispatch0(stmts_new)
#define tSP
Definition: eventids2.c:6
#define COND_P()
Definition: parse.y:86
#define NEW_ATTRASGN(r, m, a)
#define aryset(node1, node2)
Definition: parse.y:394
#define NODE_ZARRAY
static int token_info_get_column(struct parser_params *parser, const char *token)
Definition: ripper.c:11302
static NODE * new_evstr_gen(struct parser_params *, NODE *)
char * start
Definition: yaml2byte.c:126
#define arg_var(id)
Definition: parse.y:450
#define STR_FUNC_SYMBOL
#define NEW_BEGIN(b)
#define NEW_FCALL(m, a)
#define NODE_CVAR
#define NEW_SCOPE(a, b)
static int token_info_has_nonspaces(struct parser_params *parser, const char *token)
Definition: ripper.c:11316
#define NEW_OP_ASGN2(r, i, o, val)
#define NODE_BREAK
static const rb_data_type_t parser_data_type
Definition: ripper.c:11587
rb_magic_comment_setter_t func
Definition: ripper.c:12761
static int value_expr_gen(struct parser_params *, NODE *)
int parser_lpar_beg
Definition: ripper.c:271
void rb_compile_warning(const char *file, int line, const char *fmt,...)
Definition: error.c:169
#define STR_FUNC_QWORDS
st_table * sym_id
Definition: ripper.c:15936
#define cur_mid
Definition: parse.y:291
#define NODE_FL_NEWLINE
#define dvar_defined(id)
Definition: parse.y:464
#define CMDARG_P()
Definition: parse.y:91
struct local_vars * prev
Definition: ripper.c:162
#define NEW_VCALL(m)
#define ifndef_ripper(x)
Definition: parse.y:559
#define LONG2FIX(i)
Definition: ruby.h:226
static int vtable_included(const struct vtable *tbl, ID id)
Definition: parse.y:166
struct vtable * vars
Definition: ripper.c:160
#define RTEST(v)
Definition: ruby.h:373
#define T_STRING
Definition: ruby.h:418
static VALUE lex_io_gets(struct parser_params *parser, VALUE io)
Definition: ripper.c:11638
static NODE * splat_array(NODE *)
klass
Definition: tcltklib.c:3493
#define RREGEXP(obj)
Definition: ruby.h:910
#define NODE_DSTR
#define STR_NEW0()
Definition: parse.y:272
struct rb_encoding_entry * list
Definition: encoding.c:49
#define NEW_RETRY()
void * rb_parser_calloc(struct parser_params *parser, size_t nelem, size_t size)
Definition: ripper.c:16672
rb_encoding * rb_filesystem_encoding(void)
Definition: encoding.c:1205
#define st_add_direct
Definition: regint.h:151
#define STR_FUNC_EXPAND
#define flush_string_content(enc)
#define STR_FUNC_ESCAPE
int linenum
Definition: ripper.c:242
#define NEW_CVAR(v)
static NODE * aryset_gen(struct parser_params *, NODE *, NODE *)
#define tEMBDOC
Definition: eventids2.c:4
Definition: ripper.y:120
#define NODE_BEGIN
gz io
Definition: zlib.c:2024
static int dvar_defined_gen(struct parser_params *, ID, int)
#define block_append(h, t)
Definition: parse.y:355
char * parser_tokenbuf
Definition: ripper.c:277
VALUE rb_cArray
Definition: array.c:27
static const char * magic_comment_marker(const char *str, long len)
Definition: ripper.c:12773
#define NEW_OP_ASGN1(p, id, a)
union RNode::@14 u1
keyword_alias tGVAR tGVAR
Definition: ripper.y:968
#define tokadd_mbchar(c)
#define is_asgn_or_id(id)
Definition: parse.y:56
static int parser_magic_comment(struct parser_params *parser, const char *str, long len)
Definition: ripper.c:12806
Definition: ripper.y:97
#define ripper_flush(p)
VALUE rb_ary_new2(long capa)
Definition: array.c:332
#define lpar_beg
Definition: parse.y:287
const char * parser_lex_pbeg
Definition: ripper.c:283
int rb_is_class_id(ID id)
Definition: ripper.c:16409
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
Definition: string.c:424
#define cond(node)
Definition: parse.y:334
#define rb_safe_level()
Definition: tcltklib.c:90
VALUE rb_parser_new(void)
Definition: ripper.c:16587
struct parser_params * parser
Definition: ripper.c:4323
#define NODE_CVASGN
Definition: ripper.c:151
VALUE rb_const_get_at(VALUE, ID)
Definition: variable.c:1641
static VALUE reg_compile_gen(struct parser_params *, VALUE, int)
static void parser_set_encode(struct parser_params *parser, const char *name)
Definition: ripper.c:12681
#define NEW_CDECL(v, val, path)
static int literal_node(NODE *node)
Definition: ripper.c:15258
union RNode::@16 u3
#define lex_gets_ptr
Definition: parse.y:305
const char * parser_lex_p
Definition: ripper.c:284
#define tokenbuf
Definition: parse.y:293
#define nd_lit
static int parser_tok_hex(struct parser_params *parser, size_t *numlen)
Definition: ripper.c:11822
#define xrealloc
Definition: defines.h:67
#define is_global_id(id)
Definition: parse.y:49
lex_state_e
Definition: ripper.c:119
#define nd_head
int parser_ruby_sourceline
Definition: ripper.c:296
const char * rb_id2name(ID id)
Definition: ripper.c:16362
#define NODE_CALL
#define lex_goto_eol(parser)
#define rb_errinfo()
Definition: tcltklib.c:85
return rb_funcall(q->proc, ID_call, 0)
int cnt
Definition: tcltklib.c:6138
YYSTYPE * parser_yylval
Definition: ripper.c:262
BDIGIT e
Definition: bigdecimal.c:4946
#define lex_input
Definition: parse.y:296
keyword_return call_args
Definition: ripper.y:1430
#define NEW_LIT(l)
#define tokaddmbc(c, enc)
#define dyna_push()
Definition: parse.y:457
#define in_single
Definition: parse.y:288
VALUE opts
Definition: tcltklib.c:6135
int is_ripper
Definition: ripper.c:259
static NODE * cond0(struct parser_params *, NODE *)
Definition: ripper.c:15279
options
Definition: tcltklib.c:4470
rb_encoding * rb_ascii8bit_encoding(void)
Definition: encoding.c:1110
#define NODE_IVAR
int rb_enc_find_index(const char *name)
Definition: encoding.c:596
VALUE eofp
Definition: ripper.c:263
RUBY_FUNC_EXPORTED const unsigned int ruby_global_name_punct_bits[(0x7e-0x20+31)/32]
Definition: ripper.c:12296
#define reduce_nodes(n)
Definition: parse.y:350
#define pushback(c)
#define CONST_ID(var, str)
Definition: ruby.h:1127
NODE * heap
Definition: ripper.c:260
#define STR_NEW(p, n)
Definition: parse.y:271
ID rb_intern3(const char *name, long len, rb_encoding *enc)
Definition: ripper.c:16140
#define NODE_DOT2
encp
Definition: crypt.c:564
#define compile_error
Definition: parse.y:592
expr expr keyword_or expr
Definition: ripper.y:1263
#define tokfix()
#define void_expr0(node)
Definition: parse.y:345
#define rb_warnI(fmt, a)
Definition: parse.y:566
#define ID_SCOPE_MASK
#define peek(c)
int nodeline(NODE *node)
Definition: ripper.c:14320
#define NODE_DREGX
#define NODE_IASGN
#define NEW_DEFN(i, a, d, p)
#define ENC_SINGLE(cr)
Definition: parse.y:275
#define NODE_RETURN
#define long
Definition: name2ctype.h:37
ssize_t i
Definition: bigdecimal.c:5519
#define toklast()
void * rb_parser_realloc(struct parser_params *parser, void *ptr, size_t size)
Definition: ripper.c:16682
#define NEW_REDO()
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck)
Definition: bignum.c:567
#define new_evstr(n)
Definition: parse.y:368
#define NODE_ARRAY
#define NODE_SPLAT
#define rb_enc_mbcput(c, buf, enc)
Definition: encoding.h:158
#define rb_intern(str)
int rb_parse_in_eval(void)
Definition: compile.c:5570
BDIGIT v
Definition: bigdecimal.c:5520
VALUE rb_str_buf_new(long)
Definition: string.c:736
VALUE rb_usascii_str_new(const char *, long)
Definition: string.c:416
#define internal_id()
Definition: parse.y:454
static NODE * list_concat_gen(struct parser_params *, NODE *, NODE *)
#define tCOMMENT
Definition: eventids2.c:2
#define NEW_ZSUPER()
ID rb_intern2(const char *name, long len)
Definition: ripper.c:16271
rb_gc_mark(ptr->aliases)
VALUE rb_vsprintf(const char *, va_list)
Definition: sprintf.c:1197
#define tokadd_string(f, t, p, n, e)
NODE * rb_compile_file(const char *f, VALUE file, int start)
Definition: ripper.c:11644
static int is_special_global_name(const char *m, const char *e, rb_encoding *enc)
Definition: ripper.c:16009
#define lex_nextline
Definition: parse.y:298
#define nd_line(n)
VALUE rb_parser_get_yydebug(VALUE self)
Definition: ripper.c:16631
static ID internal_id_gen(struct parser_params *)
VALUE(* parser_lex_gets)(struct parser_params *, VALUE)
Definition: ripper.c:290
const char * name
Definition: nkf.c:208
#define IS_LABEL_POSSIBLE()
#define RTYPEDDATA_TYPE(v)
Definition: ruby.h:798
#define FIX2LONG(x)
Definition: ruby.h:336
#define Qundef
Definition: ruby.h:368
#define tIGNORED_NL
Definition: eventids2.c:1
NODE * rb_parser_compile_cstr(volatile VALUE vparser, const char *f, const char *s, int len, int line)
Definition: ripper.c:11631
#define compile_for_eval
Definition: parse.y:290
#define NODE_SCOPE
static struct kwtable * reserved_word(const char *, unsigned int)
#define ISXDIGIT(c)
Definition: ruby.h:1459
#define ENCODING_SET(obj, i)
Definition: encoding.h:37
#define set_yylval_literal(x)
int rb_local_defined(ID id)
Definition: compile.c:5551
st_index_t num_entries
Definition: st.h:93
NODE * parser_eval_tree_begin
Definition: ripper.c:304
Real * a
Definition: bigdecimal.c:1140
static int match(VALUE str, VALUE pat, VALUE hash, int(*cb)(VALUE, VALUE))
Definition: date_parse.c:245
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1210
static void dyna_pop_gen(struct parser_params *, const struct vtable *)
static void warn_unless_e_option(struct parser_params *parser, NODE *node, const char *str)
Definition: ripper.c:15199
#define NODE_IASGN2
#define NODE_SELF
#define rb_warning0(fmt)
Definition: parse.y:568
#define RSTRING_NOEMBED
Definition: ruby.h:666
int rb_memcicmp(const void *, const void *, long)
Definition: re.c:80
#define ID_CONST
#define tokadd_escape(e)
VALUE rb_eArgError
Definition: error.c:468
mlhs mlhs_basic
Definition: ripper.y:1453
static struct vtable * vtable_alloc(struct vtable *prev)
Definition: parse.y:127
#define rb_enc_prev_char(s, p, e, enc)
Definition: encoding.h:161
#define NEW_ARRAY(a)
#define T_REGEXP
Definition: ruby.h:419
static ID * local_tbl_gen(struct parser_params *)
#define VTBL_DEBUG
Definition: parse.y:124
#define UTF8_ENC()
Definition: parse.y:269
unsigned long ruby_scan_oct(const char *, size_t, size_t *)
Definition: util.c:28
#define NODE_VALUES
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1032
#define ID_ATTRSET
struct vtable * args
Definition: ripper.c:159
#define was_bol()
VALUE ruby_suppress_tracing(VALUE(*func)(VALUE, int), VALUE arg, int always)
Definition: thread.c:4603
Definition: ripper.y:134
#define parser_warn(node, mesg)
#define tEMBDOC_END
Definition: eventids2.c:5
#define STR_NEW2(p)
Definition: parse.y:273
#define DBL2NUM(dbl)
Definition: ruby.h:647
#define reg_fragment_check(str, options)
Definition: parse.y:416
static int vtable_size(const struct vtable *tbl)
Definition: parse.y:114
#define ISSPACE(c)
Definition: ruby.h:1453
#define StringValue(v)
Definition: ruby.h:466
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc)
Definition: string.c:2000
#define parser_encoding_name()
static void void_stmts_gen(struct parser_params *, NODE *)
#define is_notop_id(id)
Definition: parse.y:47
rb_encoding * rb_enc_from_index(int index)
Definition: encoding.c:512
#define InitVM(ext)
Definition: console.c:89
VALUE rb_str_new(const char *, long)
Definition: string.c:410
#define yyerror(msg)
Definition: parse.y:279
#define NEW_BLOCK_PASS(b)
#define xcalloc
Definition: defines.h:66
#define tokcopy(n)
#define numberof(array)
Definition: parse.y:30
#define parse_string(n)
static int parser_tokadd_mbchar(struct parser_params *parser, int c)
Definition: ripper.c:12129