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