15 #define PARSER_DEBUG 0
18 #define YYERROR_VERBOSE 1
19 #define YYSTACK_USE_ALLOCA 0
34 #define YYMALLOC(size) rb_parser_malloc(parser, (size))
35 #define YYREALLOC(ptr, size) rb_parser_realloc(parser, (ptr), (size))
36 #define YYCALLOC(nelem, size) rb_parser_calloc(parser, (nelem), (size))
37 #define YYFREE(ptr) rb_parser_free(parser, (ptr))
38 #define malloc YYMALLOC
39 #define realloc YYREALLOC
40 #define calloc YYCALLOC
46 #define REGISTER_SYMID(id, name) register_symid((id), (name), strlen(name), enc)
50 #define is_notop_id(id) ((id)>tLAST_OP_ID)
51 #define is_local_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL)
52 #define is_global_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_GLOBAL)
53 #define is_instance_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_INSTANCE)
54 #define is_attrset_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_ATTRSET)
55 #define is_const_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CONST)
56 #define is_class_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CLASS)
57 #define is_junk_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_JUNK)
58 #define id_type(id) (is_notop_id(id) ? (int)((id)&ID_SCOPE_MASK) : -1)
60 #define is_asgn_or_id(id) ((is_notop_id(id)) && \
61 (((id)&ID_SCOPE_MASK) == ID_GLOBAL || \
62 ((id)&ID_SCOPE_MASK) == ID_INSTANCE || \
63 ((id)&ID_SCOPE_MASK) == ID_CLASS))
82 #define DEF_EXPR(n) EXPR_##n = (1 << EXPR_##n##_bit)
95 EXPR_BEG_ANY = (EXPR_BEG | EXPR_VALUE | EXPR_MID | EXPR_CLASS | EXPR_LABELARG),
99 #define IS_lex_state_for(x, ls) ((x) & (ls))
100 #define IS_lex_state(ls) IS_lex_state_for(lex_state, (ls))
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)
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)
184 rb_bug(
"vtable_add: vtable is not allocated (%p)", (
void *)tbl);
201 for (i = 0; i < tbl->
pos; i++) {
303 #define STR_NEW(p,n) rb_enc_str_new((p),(n),current_enc)
304 #define STR_NEW0() rb_enc_str_new(0,0,current_enc)
305 #define STR_NEW2(p) rb_enc_str_new((p),strlen(p),current_enc)
306 #define STR_NEW3(p,n,e,func) parser_str_new((p),(n),(e),(func),current_enc)
307 #define ENC_SINGLE(cr) ((cr)==ENC_CODERANGE_7BIT)
308 #define TOK_INTERN(mb) rb_intern3(tok(), toklen(), current_enc)
311 #define yyerror(msg) parser_yyerror(parser, (msg))
313 #define lex_strterm (parser->parser_lex_strterm)
314 #define lex_state (parser->parser_lex_state)
315 #define cond_stack (parser->parser_cond_stack)
316 #define cmdarg_stack (parser->parser_cmdarg_stack)
317 #define class_nest (parser->parser_class_nest)
318 #define paren_nest (parser->parser_paren_nest)
319 #define lpar_beg (parser->parser_lpar_beg)
320 #define brace_nest (parser->parser_brace_nest)
321 #define in_single (parser->parser_in_single)
322 #define in_def (parser->parser_in_def)
323 #define compile_for_eval (parser->parser_compile_for_eval)
324 #define cur_mid (parser->parser_cur_mid)
325 #define in_defined (parser->parser_in_defined)
326 #define tokenbuf (parser->parser_tokenbuf)
327 #define tokidx (parser->parser_tokidx)
328 #define toksiz (parser->parser_toksiz)
329 #define tokline (parser->parser_tokline)
330 #define lex_input (parser->parser_lex_input)
331 #define lex_lastline (parser->parser_lex_lastline)
332 #define lex_nextline (parser->parser_lex_nextline)
333 #define lex_pbeg (parser->parser_lex_pbeg)
334 #define lex_p (parser->parser_lex_p)
335 #define lex_pend (parser->parser_lex_pend)
336 #define heredoc_end (parser->parser_heredoc_end)
337 #define command_start (parser->parser_command_start)
338 #define deferred_nodes (parser->parser_deferred_nodes)
339 #define lex_gets_ptr (parser->parser_lex_gets_ptr)
340 #define lex_gets (parser->parser_lex_gets)
341 #define lvtbl (parser->parser_lvtbl)
342 #define ruby__end__seen (parser->parser_ruby__end__seen)
343 #define ruby_sourceline (parser->parser_ruby_sourceline)
344 #define ruby_sourcefile (parser->parser_ruby_sourcefile)
345 #define ruby_sourcefile_string (parser->parser_ruby_sourcefile_string)
346 #define current_enc (parser->enc)
347 #define yydebug (parser->parser_yydebug)
350 #define ruby_eval_tree (parser->parser_eval_tree)
351 #define ruby_eval_tree_begin (parser->parser_eval_tree_begin)
352 #define ruby_debug_lines (parser->debug_lines)
353 #define ruby_coverage (parser->coverage)
357 static int yylex(
void*,
void*);
359 static int yylex(
void*);
363 #define yyparse ruby_yyparse
366 #define rb_node_newnode(type, a1, a2, a3) node_newnode(parser, (type), (a1), (a2), (a3))
369 #define cond(node) cond_gen(parser, (node))
371 #define logop(type,node1,node2) logop_gen(parser, (type), (node1), (node2))
380 #define value_expr(node) value_expr_gen(parser, (node) = remove_begin(node))
381 #define void_expr0(node) void_expr_gen(parser, (node))
382 #define void_expr(node) void_expr0((node) = remove_begin(node))
384 #define void_stmts(node) void_stmts_gen(parser, (node))
386 #define reduce_nodes(n) reduce_nodes_gen(parser,(n))
388 #define block_dup_check(n1,n2) block_dup_check_gen(parser,(n1),(n2))
391 #define block_append(h,t) block_append_gen(parser,(h),(t))
393 #define list_append(l,i) list_append_gen(parser,(l),(i))
395 #define list_concat(h,t) list_concat_gen(parser,(h),(t))
397 #define arg_append(h,t) arg_append_gen(parser,(h),(t))
399 #define arg_concat(h,t) arg_concat_gen(parser,(h),(t))
401 #define literal_concat(h,t) literal_concat_gen(parser,(h),(t))
404 #define new_evstr(n) new_evstr_gen(parser,(n))
406 #define evstr2dstr(n) evstr2dstr_gen(parser,(n))
410 #define call_bin_op(recv,id,arg1) call_bin_op_gen(parser, (recv),(id),(arg1))
412 #define call_uni_op(recv,id) call_uni_op_gen(parser, (recv),(id))
415 #define new_args(f,o,r,p,t) new_args_gen(parser, (f),(o),(r),(p),(t))
417 #define new_args_tail(k,kr,b) new_args_tail_gen(parser, (k),(kr),(b))
421 #define ret_args(node) ret_args_gen(parser, (node))
424 #define new_yield(node) new_yield_gen(parser, (node))
426 #define dsym_node(node) dsym_node_gen(parser, (node))
429 #define gettable(id) gettable_gen(parser,(id))
431 #define assignable(id,node) assignable_gen(parser, (id), (node))
434 #define aryset(node1,node2) aryset_gen(parser, (node1), (node2))
436 #define attrset(node,id) attrset_gen(parser, (node), (id))
439 #define rb_backref_error(n) rb_backref_error_gen(parser,(n))
441 #define node_assign(node1, node2) node_assign_gen(parser, (node1), (node2))
445 #define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (attr), (op), (rhs))
447 #define new_const_op_assign(lhs, op, rhs) new_const_op_assign_gen(parser, (lhs), (op), (rhs))
449 #define new_defined(expr) NEW_DEFINED(remove_begin_all(expr))
452 #define match_op(node1,node2) match_op_gen(parser, (node1), (node2))
455 #define local_tbl() local_tbl_gen(parser)
460 #define reg_compile(str,options) reg_compile_gen(parser, (str), (options))
462 #define reg_fragment_setenc(str,options) reg_fragment_setenc_gen(parser, (str), (options))
464 #define reg_fragment_check(str,options) reg_fragment_check_gen(parser, (str), (options))
466 #define reg_named_capture_assign(regexp,match) reg_named_capture_assign_gen(parser,(regexp),(match))
468 #define get_id(id) (id)
469 #define get_value(val) (val)
471 #define value_expr(node) ((void)(node))
472 #define remove_begin(node) (node)
473 #define rb_dvar_defined(id) 0
474 #define rb_local_defined(id) 0
475 static ID ripper_get_id(
VALUE);
476 #define get_id(id) ripper_get_id(id)
478 #define get_value(val) ripper_get_value(val)
480 #define assignable(lhs,node) assignable_gen(parser, (lhs))
482 #define id_is_var(id) id_is_var_gen(parser, (id))
484 #define node_assign(node1, node2) dispatch2(assign, (node1), (node2))
488 #define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs))
492 #define new_op_assign(lhs, op, rhs) new_op_assign_gen(parser, (lhs), (op), (rhs))
495 #define formal_argument(id) formal_argument_gen(parser, (id))
497 #define shadowing_lvar(name) shadowing_lvar_gen(parser, (name))
499 #define new_bv(id) new_bv_gen(parser, (id))
502 #define local_push(top) local_push_gen(parser,(top))
504 #define local_pop() local_pop_gen(parser)
506 #define local_var(id) local_var_gen(parser, (id))
508 #define arg_var(id) arg_var_gen(parser, (id))
510 #define local_id(id) local_id_gen(parser, (id))
512 #define internal_id() internal_id_gen(parser)
515 #define dyna_push() dyna_push_gen(parser)
517 #define dyna_pop(node) dyna_pop_gen(parser, (node))
519 #define dyna_in_block() dyna_in_block_gen(parser)
520 #define dyna_var(id) local_var(id)
522 #define dvar_defined(id) dvar_defined_gen(parser, (id), 0)
523 #define dvar_defined_get(id) dvar_defined_gen(parser, (id), 1)
525 #define dvar_curr(id) dvar_curr_gen(parser, (id))
528 #define lvar_defined(id) lvar_defined_gen(parser, (id))
530 #define RE_OPTION_ONCE (1<<16)
531 #define RE_OPTION_ENCODING_SHIFT 8
532 #define RE_OPTION_ENCODING(e) (((e)&0xff)<<RE_OPTION_ENCODING_SHIFT)
533 #define RE_OPTION_ENCODING_IDX(o) (((o)>>RE_OPTION_ENCODING_SHIFT)&0xff)
534 #define RE_OPTION_ENCODING_NONE(o) ((o)&RE_OPTION_ARG_ENCODING_NONE)
535 #define RE_OPTION_MASK 0xff
536 #define RE_OPTION_ARG_ENCODING_NONE 32
538 #define NODE_STRTERM NODE_ZARRAY
539 #define NODE_HEREDOC NODE_ARRAY
540 #define SIGN_EXTEND(x,n) (((1<<(n)-1)^((x)&~(~0<<(n))))-(1<<(n)-1))
541 #define nd_func u1.id
542 #if SIZEOF_SHORT == 2
543 #define nd_term(node) ((signed short)(node)->u2.id)
545 #define nd_term(node) SIGN_EXTEND((node)->u2.id, CHAR_BIT*2)
547 #define nd_paren(node) (char)((node)->u2.id >> CHAR_BIT*2)
548 #define nd_nest u3.cnt
553 #define RIPPER_VERSION "0.1.0"
566 #define dispatch0(n) ripper_dispatch0(parser, TOKEN_PASTE(ripper_id_, n))
567 #define dispatch1(n,a) ripper_dispatch1(parser, TOKEN_PASTE(ripper_id_, n), (a))
568 #define dispatch2(n,a,b) ripper_dispatch2(parser, TOKEN_PASTE(ripper_id_, n), (a), (b))
569 #define dispatch3(n,a,b,c) ripper_dispatch3(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c))
570 #define dispatch4(n,a,b,c,d) ripper_dispatch4(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d))
571 #define dispatch5(n,a,b,c,d,e) ripper_dispatch5(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d), (e))
572 #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))
574 #define yyparse ripper_yyparse
576 #define ripper_intern(s) ID2SYM(rb_intern(s))
577 static VALUE ripper_id2sym(
ID);
579 #define ripper_id2sym(id) ((id) < 256 && rb_ispunct(id) ? \
580 ID2SYM(id) : ripper_id2sym(id))
583 #define arg_new() dispatch0(args_new)
584 #define arg_add(l,a) dispatch2(args_add, (l), (a))
585 #define arg_add_star(l,a) dispatch2(args_add_star, (l), (a))
586 #define arg_add_block(l,b) dispatch2(args_add_block, (l), (b))
587 #define arg_add_optblock(l,b) ((b)==Qundef? (l) : dispatch2(args_add_block, (l), (b)))
588 #define bare_assoc(v) dispatch1(bare_assoc_hash, (v))
589 #define arg_add_assocs(l,b) arg_add((l), bare_assoc(b))
591 #define args2mrhs(a) dispatch1(mrhs_new_from_args, (a))
592 #define mrhs_new() dispatch0(mrhs_new)
593 #define mrhs_add(l,a) dispatch2(mrhs_add, (l), (a))
594 #define mrhs_add_star(l,a) dispatch2(mrhs_add_star, (l), (a))
596 #define mlhs_new() dispatch0(mlhs_new)
597 #define mlhs_add(l,a) dispatch2(mlhs_add, (l), (a))
598 #define mlhs_add_star(l,a) dispatch2(mlhs_add_star, (l), (a))
600 #define params_new(pars, opts, rest, pars2, kws, kwrest, blk) \
601 dispatch7(params, (pars), (opts), (rest), (pars2), (kws), (kwrest), (blk))
603 #define blockvar_new(p,v) dispatch2(block_var, (p), (v))
604 #define blockvar_add_star(l,a) dispatch2(block_var_add_star, (l), (a))
605 #define blockvar_add_block(l,a) dispatch2(block_var_add_block, (l), (a))
607 #define method_optarg(m,a) ((a)==Qundef ? (m) : dispatch2(method_add_arg,(m),(a)))
608 #define method_arg(m,a) dispatch2(method_add_arg,(m),(a))
609 #define method_add_block(m,b) dispatch2(method_add_block, (m), (b))
611 #define escape_Qundef(x) ((x)==Qundef ? Qnil : (x))
620 #define new_args(f,o,r,p,t) new_args_gen(parser, (f),(o),(r),(p),(t))
627 #define new_args_tail(k,kr,b) new_args_tail_gen(parser, (k),(kr),(b))
629 #define new_defined(expr) dispatch1(defined, (expr))
637 # define ifndef_ripper(x) (x)
640 # define ifndef_ripper(x)
644 # define rb_warn0(fmt) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt))
645 # define rb_warnI(fmt,a) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt), (a))
646 # define rb_warnS(fmt,a) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt), (a))
647 # define rb_warn4S(file,line,fmt,a) rb_compile_warn((file), (line), (fmt), (a))
648 # define rb_warning0(fmt) rb_compile_warning(ruby_sourcefile, ruby_sourceline, (fmt))
649 # define rb_warningS(fmt,a) rb_compile_warning(ruby_sourcefile, ruby_sourceline, (fmt), (a))
651 # define rb_warn0(fmt) ripper_warn0(parser, (fmt))
652 # define rb_warnI(fmt,a) ripper_warnI(parser, (fmt), (a))
653 # define rb_warnS(fmt,a) ripper_warnS(parser, (fmt), (a))
654 # define rb_warn4S(file,line,fmt,a) ripper_warnS(parser, (fmt), (a))
655 # define rb_warning0(fmt) ripper_warning0(parser, (fmt))
656 # define rb_warningS(fmt,a) ripper_warningS(parser, (fmt), (a))
661 static void ripper_warningS(
struct parser_params*,
const char*,
const char*);
665 static void ripper_compile_error(
struct parser_params*,
const char *fmt, ...);
666 # define rb_compile_error ripper_compile_error
667 # define compile_error ripper_compile_error
668 # define PARSER_ARG parser,
670 # define rb_compile_error rb_compile_error_with_enc
671 # define compile_error parser->nerr++,rb_compile_error_with_enc
672 # define PARSER_ARG ruby_sourcefile, ruby_sourceline, current_enc,
680 #define YYMAXDEPTH 10000
687 #define token_info_push(token) (RTEST(ruby_verbose) ? token_info_push(parser, (token)) : (void)0)
688 #define token_info_pop(token) (RTEST(ruby_verbose) ? token_info_pop(parser, (token)) : (void)0)
690 #define token_info_push(token)
691 #define token_info_pop(token)
704 const struct vtable *vars;
767 %type <val> singleton strings
string string1 xstring regexp
768 %type <val> string_contents xstring_contents regexp_contents string_content
769 %type <val> words
symbols symbol_list qwords qsymbols word_list qword_list qsym_list word
770 %type <val> literal numeric simple_numeric dsym cpath
771 %type <val> top_compstmt top_stmts
top_stmt
773 %type <val> expr_value arg_value primary_value fcall
774 %type <val> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
776 %type <val> paren_args opt_paren_args args_tail opt_args_tail block_args_tail opt_block_args_tail
777 %type <val>
command_args aref_args opt_block_arg block_arg var_ref var_lhs
778 %type <val> command_asgn mrhs mrhs_arg superclass block_call block_command
779 %type <val> f_block_optarg f_block_opt
780 %type <val> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
781 %type <val> assoc_list assocs assoc undef_list backref string_dvar for_var
782 %type <val> block_param opt_block_param block_param_def f_opt
783 %type <val> f_kwarg f_kw f_block_kwarg f_block_kw
784 %type <val> bv_decls opt_bv_decl bvar
785 %type <val> lambda f_larglist lambda_body
789 %type <val> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
790 %type <val> f_kwrest f_label
793 %type <val> program reswords then
do dot_or_colon
879 while (node->nd_next) {
880 node = node->nd_next;
888 parser->result = dispatch1(program, $$);
894 top_compstmt : top_stmts opt_terms
919 $$ = dispatch2(stmts_add,
dispatch0(stmts_new), $1);
927 $$ = dispatch2(stmts_add, $1, $3);
953 $$ = dispatch1(BEGIN, $4);
1007 $$ = dispatch2(stmts_add,
dispatch0(stmts_new),
1016 $$ = dispatch2(stmts_add,
dispatch0(stmts_new), $1);
1024 $$ = dispatch2(stmts_add, $1, $3);
1039 yyerror(
"BEGIN is permitted only at toplevel");
1045 '{' top_compstmt
'}'
1054 $$ = dispatch1(BEGIN, $4);
1063 $$ = dispatch2(
alias, $2, $4);
1071 $$ = dispatch2(var_alias, $2, $3);
1079 buf[1] = (char)$3->nd_nth;
1082 $$ = dispatch2(var_alias, $2, $3);
1088 yyerror(
"can't make alias for the number variables");
1091 $$ = dispatch2(var_alias, $2, $3);
1092 $$ = dispatch1(alias_error, $$);
1100 $$ = dispatch1(undef, $2);
1109 $$ = dispatch2(if_mod, $3, $1);
1118 $$ = dispatch2(unless_mod, $3, $1);
1131 $$ = dispatch2(while_mod, $3, $1);
1144 $$ = dispatch2(until_mod, $3, $1);
1153 $$ = dispatch2(rescue_mod, $1, $3);
1159 rb_warn0(
"END in method; use at_exit");
1165 $$ = dispatch1(
END, $3);
1176 $$ = dispatch2(massign, $1, $3);
1202 $$ = dispatch3(opassign, $$, $5, $6);
1221 $$ = dispatch2(const_path_field, $1, $3);
1222 $$ = dispatch3(opassign, $$, $4, $5);
1236 $$ = dispatch2(assign, dispatch1(var_field, $1), $3);
1237 $$ = dispatch1(assign_error, $$);
1246 $$ = dispatch2(assign, $1, $3);
1255 $$ = dispatch2(massign, $1, $3);
1267 $$ = dispatch2(assign, $1, $3);
1276 $$ = dispatch2(assign, $1, $3);
1312 $$ = dispatch2(unary, ripper_id2sym(
'!'), $2);
1334 block_command : block_call
1340 $$ = dispatch3(call, $1, $2, $3);
1341 $$ = method_arg($$, $4);
1384 $$ = dispatch2(command, $1, $2);
1396 $$ = dispatch2(command, $1, $2);
1397 $$ = method_add_block($$, $3);
1406 $$ = dispatch4(
command_call, $1, ripper_id2sym(
'.'), $3, $4);
1413 $5->nd_iter =
NEW_CALL($1, $3, $4);
1417 $$ = dispatch4(
command_call, $1, ripper_id2sym(
'.'), $3, $4);
1418 $$ = method_add_block($$, $5);
1434 $5->nd_iter =
NEW_CALL($1, $3, $4);
1439 $$ = method_add_block($$, $5);
1448 $$ = dispatch1(super, $2);
1457 $$ = dispatch1(yield, $2);
1465 $$ = dispatch1(
return, $2);
1473 $$ = dispatch1(
break, $2);
1481 $$ = dispatch1(next, $2);
1492 $$ = dispatch1(mlhs_paren, $2);
1503 $$ = dispatch1(mlhs_paren, $2);
1521 $$ = mlhs_add($1, $2);
1529 $$ = mlhs_add_star($1, $3);
1537 $1 = mlhs_add_star($1, $3);
1538 $$ = mlhs_add($1, $5);
1546 $$ = mlhs_add_star($1, Qnil);
1554 $1 = mlhs_add_star($1, Qnil);
1555 $$ = mlhs_add($1, $4);
1563 $$ = mlhs_add_star(mlhs_new(), $2);
1571 $2 = mlhs_add_star(mlhs_new(), $2);
1572 $$ = mlhs_add($2, $4);
1580 $$ = mlhs_add_star(mlhs_new(), Qnil);
1588 $$ = mlhs_add_star(mlhs_new(), Qnil);
1589 $$ = mlhs_add($$, $3);
1600 $$ = dispatch1(mlhs_paren, $2);
1610 $$ = mlhs_add(mlhs_new(), $1);
1618 $$ = mlhs_add($1, $2);
1628 $$ = mlhs_add(mlhs_new(), $1);
1636 $$ = mlhs_add($1, $3);
1649 | primary_value
'[' opt_call_args rbracket
1662 $$ = dispatch3(field, $1, ripper_id2sym(
'.'), $3);
1670 $$ = dispatch2(const_path_field, $1, $3);
1678 $$ = dispatch3(field, $1, ripper_id2sym(
'.'), $3);
1685 yyerror(
"dynamic constant assignment");
1689 yyerror(
"dynamic constant assignment");
1690 $$ = dispatch2(const_path_field, $1, $3);
1697 yyerror(
"dynamic constant assignment");
1700 $$ = dispatch1(top_const_field, $2);
1709 $$ = dispatch1(var_field, $1);
1710 $$ = dispatch1(assign_error, $$);
1721 $$ = dispatch1(var_field, $$);
1730 $$ = dispatch1(var_field, $$);
1733 | primary_value
'[' opt_call_args rbracket
1746 $$ = dispatch3(field, $1, ripper_id2sym(
'.'), $3);
1762 $$ = dispatch3(field, $1, ripper_id2sym(
'.'), $3);
1769 yyerror(
"dynamic constant assignment");
1772 $$ = dispatch2(const_path_field, $1, $3);
1774 $$ = dispatch1(assign_error, $$);
1782 yyerror(
"dynamic constant assignment");
1785 $$ = dispatch1(top_const_field, $2);
1787 $$ = dispatch1(assign_error, $$);
1797 $$ = dispatch1(assign_error, $1);
1805 yyerror(
"class/module name must be CONSTANT");
1807 $$ = dispatch1(class_name_error, $1);
1818 $$ = dispatch1(top_const_ref, $2);
1826 $$ = dispatch1(const_ref, $1);
1834 $$ = dispatch2(const_path_ref, $1, $3);
1867 $$ = dispatch1(symbol_literal, $1);
1881 | undef_list
',' {
lex_state = EXPR_FNAME;} fitem
1943 $$ = dispatch2(assign, $1, $3);
1953 $$ = dispatch2(assign, $1, dispatch2(rescue_mod, $3, $5));
1967 $3 = dispatch2(rescue_mod, $3, $5);
1971 | primary_value
'[' opt_call_args rbracket
tOP_ASGN arg
1994 $$ = dispatch3(opassign, $1, $5, $6);
2018 $$ = dispatch2(const_path_field, $1, $3);
2019 $$ = dispatch3(opassign, $$, $4, $5);
2028 $$ = dispatch1(top_const_field, $2);
2029 $$ = dispatch3(opassign, $$, $3, $4);
2038 $$ = dispatch1(var_field, $1);
2039 $$ = dispatch3(opassign, $$, $2, $3);
2040 $$ = dispatch1(assign_error, $$);
2054 $$ = dispatch2(dot2, $1, $3);
2068 $$ = dispatch2(dot3, $1, $3);
2076 $$ = dispatch3(binary, $1,
ID2SYM(
'+'), $3);
2084 $$ = dispatch3(binary, $1,
ID2SYM(
'-'), $3);
2092 $$ = dispatch3(binary, $1,
ID2SYM(
'*'), $3);
2100 $$ = dispatch3(binary, $1,
ID2SYM(
'/'), $3);
2108 $$ = dispatch3(binary, $1,
ID2SYM(
'%'), $3);
2149 $$ = dispatch3(binary, $1,
ID2SYM(
'|'), $3);
2157 $$ = dispatch3(binary, $1,
ID2SYM(
'^'), $3);
2165 $$ = dispatch3(binary, $1,
ID2SYM(
'&'), $3);
2181 $$ = dispatch3(binary, $1,
ID2SYM(
'>'), $3);
2197 $$ = dispatch3(binary, $1,
ID2SYM(
'<'), $3);
2256 $$ = dispatch2(unary,
ID2SYM(
'!'), $2);
2264 $$ = dispatch2(unary,
ID2SYM(
'~'), $2);
2306 $$ = dispatch1(defined, $4);
2316 $$ = dispatch3(ifop, $1, $3, $6);
2342 | args
',' assocs trailer
2347 $$ = arg_add_assocs($1, $3);
2355 $$ = arg_add_assocs(arg_new(), $1);
2360 paren_args :
'(' opt_call_args rparen
2370 opt_paren_args : none
2374 opt_call_args : none
2380 | args
',' assocs
','
2385 $$ = arg_add_assocs($1, $3);
2393 $$ = arg_add_assocs(arg_new(), $1);
2404 $$ = arg_add(arg_new(), $1);
2407 | args opt_block_arg
2412 $$ = arg_add_optblock($1, $2);
2415 | assocs opt_block_arg
2421 $$ = arg_add_assocs(arg_new(), $1);
2422 $$ = arg_add_optblock($$, $2);
2425 | args
',' assocs opt_block_arg
2431 $$ = arg_add_optblock(arg_add_assocs($1, $3), $4);
2438 $$ = arg_add_block(arg_new(), $1);
2455 block_arg :
tAMPER arg_value
2465 opt_block_arg :
',' block_arg
2480 $$ = arg_add(arg_new(), $1);
2488 $$ = arg_add_star(arg_new(), $2);
2491 | args
',' arg_value
2502 $$ = arg_add($1, $3);
2505 | args
',' tSTAR arg_value
2516 $$ = arg_add_star($1, $4);
2525 mrhs : args
',' arg_value
2536 $$ = mrhs_add(args2mrhs($1), $3);
2539 | args
',' tSTAR arg_value
2551 $$ = mrhs_add_star(args2mrhs($1), $4);
2559 $$ = mrhs_add_star(mrhs_new(), $2);
2579 $$ = method_arg(dispatch1(fcall, $1), arg_new());
2607 $$ = dispatch1(begin, $3);
2615 $$ = dispatch1(paren, 0);
2629 $$ = dispatch1(paren, $3);
2637 $$ = dispatch1(paren, $2);
2645 $$ = dispatch2(const_path_ref, $1, $3);
2653 $$ = dispatch1(top_const_ref, $2);
2690 $$ = dispatch1(yield, dispatch1(paren, $3));
2698 $$ = dispatch1(yield, dispatch1(paren, arg_new()));
2716 $$ = dispatch1(defined, $5);
2741 $$ = method_arg(dispatch1(fcall, $1), arg_new());
2742 $$ = method_add_block($$, $2);
2746 | method_call brace_block
2753 $$ = method_add_block($1, $2);
2760 | k_if expr_value then
2772 | k_unless expr_value then
2792 $$ = dispatch2(
while, $3, $6);
2803 $$ = dispatch2(until, $3, $6);
2806 | k_case expr_value opt_terms
2814 $$ = dispatch2(
case, $2, $4);
2817 | k_case opt_terms case_body k_end
2822 $$ = dispatch2(
case, Qnil, $3);
2884 tbl[0] = 1; tbl[1] =
id;
2888 $$ = dispatch3(
for, $2, $5, $8);
2891 | k_class cpath superclass
2894 yyerror(
"class definition in method body");
2908 $$ = dispatch3(
class, $2, $3, $5);
2930 $$ = dispatch2(sclass, $3, $7);
2939 yyerror(
"module definition in method body");
2953 $$ = dispatch2(module, $2, $4);
2974 $$ = dispatch3(def, $2, $4, $5);
2980 | k_def singleton dot_or_colon {
lex_state = EXPR_FNAME;} fname
2996 $$ = dispatch5(defs, $2, $3, $5, $7, $8);
3006 $$ = dispatch1(
break, arg_new());
3014 $$ = dispatch1(next, arg_new());
3035 primary_value : primary
3158 $$ = dispatch1(
else, $2);
3172 $$ = dispatch1(mlhs_paren, $$);
3180 $$ = dispatch1(mlhs_paren, $2);
3185 f_marg_list : f_marg
3190 $$ = mlhs_add(mlhs_new(), $1);
3193 | f_marg_list
',' f_marg
3198 $$ = mlhs_add($1, $3);
3203 f_margs : f_marg_list
3211 | f_marg_list
',' tSTAR f_norm_arg
3217 $$ = mlhs_add_star($1, $$);
3220 | f_marg_list
',' tSTAR f_norm_arg
',' f_marg_list
3226 $$ = mlhs_add_star($1, $$);
3229 | f_marg_list
',' tSTAR
3234 $$ = mlhs_add_star($1, Qnil);
3237 | f_marg_list
',' tSTAR ',' f_marg_list
3242 $$ = mlhs_add_star($1, $5);
3251 $$ = mlhs_add_star(mlhs_new(), $$);
3254 |
tSTAR f_norm_arg
',' f_marg_list
3263 $$ = mlhs_add_star($$, $4);
3271 $$ = mlhs_add_star(mlhs_new(), Qnil);
3274 |
tSTAR ',' f_marg_list
3279 $$ = mlhs_add_star(mlhs_new(), Qnil);
3285 block_args_tail : f_block_kwarg
',' f_kwrest opt_f_block_arg
3289 | f_block_kwarg opt_f_block_arg
3293 | f_kwrest opt_f_block_arg
3303 opt_block_args_tail :
',' block_args_tail
3313 block_param : f_arg
',' f_block_optarg
',' f_rest_arg opt_block_args_tail
3317 | f_arg
',' f_block_optarg
',' f_rest_arg
',' f_arg opt_block_args_tail
3321 | f_arg
',' f_block_optarg opt_block_args_tail
3325 | f_arg
',' f_block_optarg
',' f_arg opt_block_args_tail
3329 | f_arg
',' f_rest_arg opt_block_args_tail
3338 dispatch1(excessed_comma, $$);
3341 | f_arg
',' f_rest_arg
',' f_arg opt_block_args_tail
3345 | f_arg opt_block_args_tail
3349 | f_block_optarg
',' f_rest_arg opt_block_args_tail
3353 | f_block_optarg
',' f_rest_arg
',' f_arg opt_block_args_tail
3357 | f_block_optarg opt_block_args_tail
3361 | f_block_optarg
',' f_arg opt_block_args_tail
3365 | f_rest_arg opt_block_args_tail
3369 | f_rest_arg
',' f_arg opt_block_args_tail
3379 opt_block_param : none
3386 block_param_def :
'|' opt_bv_decl
'|'
3391 $$ = blockvar_new(params_new(Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,Qnil),
3400 $$ = blockvar_new(params_new(Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,Qnil),
3404 |
'|' block_param opt_bv_decl
'|'
3415 opt_bv_decl : opt_nl
3419 | opt_nl
';' bv_decls opt_nl
3477 $$ = dispatch2(lambda, $3, $5);
3483 f_larglist :
'(' f_args opt_bv_decl
')'
3488 $$ = dispatch1(paren, $2);
3528 block_call : command do_block
3541 $$ = method_add_block($1, $2);
3544 | block_call dot_or_colon operation2 opt_paren_args
3549 $$ = dispatch3(call, $1, $2, $3);
3550 $$ = method_optarg($$, $4);
3553 | block_call dot_or_colon operation2 opt_paren_args brace_block
3557 $5->nd_iter =
NEW_CALL($1, $3, $4);
3562 $$ = method_add_block($$, $5);
3565 | block_call dot_or_colon operation2
command_args do_block
3569 $5->nd_iter =
NEW_CALL($1, $3, $4);
3574 $$ = method_add_block($$, $5);
3579 method_call : fcall paren_args
3585 $$ = method_arg(dispatch1(fcall, $1), $2);
3588 | primary_value
'.' operation2
3600 $$ = dispatch3(call, $1, ripper_id2sym(
'.'), $3);
3601 $$ = method_optarg($$, $5);
3604 | primary_value
tCOLON2 operation2
3616 $$ = dispatch3(call, $1, ripper_id2sym(
'.'), $3);
3617 $$ = method_optarg($$, $5);
3620 | primary_value
tCOLON2 operation3
3640 $$ = dispatch3(call, $1, ripper_id2sym(
'.'),
3642 $$ = method_optarg($$, $4);
3659 $$ = method_optarg($$, $4);
3667 $$ = dispatch1(super, $2);
3678 | primary_value
'[' opt_call_args rbracket
3760 $$ = dispatch4(rescue,
3770 exc_list : arg_value
3801 $$ = dispatch1(ensure, $2);
3813 $$ = dispatch1(symbol_literal, $1);
3843 $$ = dispatch2(string_concat, $1, $2);
3853 $$ = dispatch1(string_literal, $2);
3880 $$ = dispatch1(xstring_literal, $2);
3897 VALUE src = node->nd_lit;
3913 for (list = (prev = node)->nd_next;
list; list = list->nd_next) {
3917 VALUE lit = prev == node ? prev->nd_lit : prev->nd_head->nd_lit;
3923 prev->nd_next = list->nd_next;
3936 if (!node->nd_next) {
3937 VALUE src = node->nd_lit;
3945 $$ = dispatch2(regexp_literal, $2, $3);
3956 $$ = dispatch1(array, $$);
3964 $$ = dispatch1(array, $2);
3977 | word_list word
' '
3982 $$ = dispatch2(words_add, $1, $2);
3987 word : string_content
3992 $$ = dispatch2(word_add, $$, $1);
3995 | word string_content
4000 $$ = dispatch2(word_add, $1, $2);
4011 $$ = dispatch1(array, $$);
4019 $$ = dispatch1(array, $2);
4032 | symbol_list word
' '
4039 $$ = dispatch2(symbols_add, $1, $2);
4050 $$ = dispatch1(array, $$);
4058 $$ = dispatch1(array, $2);
4069 $$ = dispatch1(array, $$);
4077 $$ = dispatch1(array, $2);
4095 $$ = dispatch2(qwords_add, $1, $2);
4117 $$ = dispatch2(qsymbols_add, $1, $2);
4130 | string_contents string_content
4135 $$ = dispatch2(string_add, $1, $2);
4148 | xstring_contents string_content
4153 $$ = dispatch2(xstring_add, $1, $2);
4166 | regexp_contents string_content
4190 $$ = dispatch2(regexp_add, $1, $2);
4209 $$ = dispatch1(string_dvar, $3);
4238 $$ = dispatch1(string_embexpr, $5);
4248 $$ = dispatch1(var_ref, $1);
4256 $$ = dispatch1(var_ref, $1);
4264 $$ = dispatch1(var_ref, $1);
4276 $$ = dispatch1(symbol, $2);
4293 $$ = dispatch1(dyna_symbol, $2);
4298 numeric : simple_numeric
4331 var_ref : user_variable
4336 if (id_is_var(
get_id($1))) {
4337 $$ = dispatch1(var_ref, $1);
4340 $$ = dispatch1(vcall, $1);
4349 $$ = dispatch1(var_ref, $1);
4354 var_lhs : user_variable
4359 $$ = dispatch1(var_field, $$);
4367 $$ = dispatch1(var_field, $$);
4405 f_arglist :
'(' f_args rparen
4410 $$ = dispatch1(paren, $2);
4416 $<num>$ = parser->parser_in_kwarg;
4417 parser->parser_in_kwarg = 1;
4421 parser->parser_in_kwarg = $<num>1;
4428 args_tail : f_kwarg
',' f_kwrest opt_f_block_arg
4432 | f_kwarg opt_f_block_arg
4436 | f_kwrest opt_f_block_arg
4446 opt_args_tail :
',' args_tail
4456 f_args : f_arg
',' f_optarg
',' f_rest_arg opt_args_tail
4460 | f_arg
',' f_optarg
',' f_rest_arg
',' f_arg opt_args_tail
4464 | f_arg
',' f_optarg opt_args_tail
4468 | f_arg
',' f_optarg
',' f_arg opt_args_tail
4472 | f_arg
',' f_rest_arg opt_args_tail
4476 | f_arg
',' f_rest_arg
',' f_arg opt_args_tail
4480 | f_arg opt_args_tail
4484 | f_optarg
',' f_rest_arg opt_args_tail
4488 | f_optarg
',' f_rest_arg
',' f_arg opt_args_tail
4492 | f_optarg opt_args_tail
4496 | f_optarg
',' f_arg opt_args_tail
4500 | f_rest_arg opt_args_tail
4504 | f_rest_arg
',' f_arg opt_args_tail
4522 yyerror(
"formal argument cannot be a constant");
4525 $$ = dispatch1(param_error, $1);
4531 yyerror(
"formal argument cannot be an instance variable");
4534 $$ = dispatch1(param_error, $1);
4540 yyerror(
"formal argument cannot be a global variable");
4543 $$ = dispatch1(param_error, $1);
4549 yyerror(
"formal argument cannot be a class variable");
4552 $$ = dispatch1(param_error, $1);
4557 f_norm_arg : f_bad_arg
4565 f_arg_item : f_norm_arg
4588 $$ = dispatch1(mlhs_paren, $2);
4600 | f_arg
',' f_arg_item
4621 f_kw : f_label arg_value
4641 f_block_kw : f_label primary_value
4661 f_block_kwarg : f_block_kw
4669 | f_block_kwarg
',' f_block_kw
4674 while (kws->nd_next) {
4699 while (kws->nd_next) {
4725 f_opt : f_norm_arg
'=' arg_value
4737 f_block_opt : f_norm_arg
'=' primary_value
4749 f_block_optarg : f_block_opt
4757 | f_block_optarg
',' f_block_opt
4762 while (opts->nd_next) {
4763 opts = opts->nd_next;
4781 | f_optarg
',' f_opt
4786 while (opts->nd_next) {
4787 opts = opts->nd_next;
4805 yyerror(
"rest argument must be local variable");
4811 $$ = dispatch1(rest_param, $2);
4820 $$ = dispatch1(rest_param, Qnil);
4833 yyerror(
"block argument must be local variable");
4835 yyerror(
"duplicated block argument name");
4841 $$ = dispatch1(blockarg, $2);
4846 opt_f_block_arg :
',' f_block_arg
4874 yyerror(
"can't define singleton method for ().");
4886 yyerror(
"can't define singleton method for literals");
4894 $$ = dispatch1(paren, $3);
4905 $$ = dispatch1(assoclist_from_args, $1);
4927 assoc : arg_value
tASSOC arg_value
4936 $$ = dispatch2(assoc_new, $1, $3);
4944 $$ = dispatch2(assoc_new, $1, $2);
4952 $$ = dispatch1(assoc_splat, $2);
4998 rbracket : opt_nl
']'
5027 # define yylval (*((YYSTYPE*)(parser->parser_yylval)))
5036 # define nextc() parser_nextc(parser)
5037 # define pushback(c) parser_pushback(parser, (c))
5038 # define newtok() parser_newtok(parser)
5039 # define tokspace(n) parser_tokspace(parser, (n))
5040 # define tokadd(c) parser_tokadd(parser, (c))
5041 # define tok_hex(numlen) parser_tok_hex(parser, (numlen))
5042 # define read_escape(flags,e) parser_read_escape(parser, (flags), (e))
5043 # define tokadd_escape(e) parser_tokadd_escape(parser, (e))
5044 # define regx_options() parser_regx_options(parser)
5045 # define tokadd_string(f,t,p,n,e) parser_tokadd_string(parser,(f),(t),(p),(n),(e))
5046 # define parse_string(n) parser_parse_string(parser,(n))
5047 # define tokaddmbc(c, enc) parser_tokaddmbc(parser, (c), (enc))
5048 # define here_document(n) parser_here_document(parser,(n))
5049 # define heredoc_identifier() parser_heredoc_identifier(parser)
5050 # define heredoc_restore(n) parser_heredoc_restore(parser,(n))
5051 # define whole_match_p(e,l,i) parser_whole_match_p(parser,(e),(l),(i))
5052 # define number_literal_suffix(f) parser_number_literal_suffix(parser, (f))
5053 # define set_number_literal(v, t, f) parser_set_number_literal(parser, (v), (t), (f))
5054 # define set_integer_literal(v, f) parser_set_integer_literal(parser, (v), (f))
5057 # define set_yylval_str(x) (yylval.node = NEW_STR(x))
5058 # define set_yylval_num(x) (yylval.num = (x))
5059 # define set_yylval_id(x) (yylval.id = (x))
5060 # define set_yylval_name(x) (yylval.id = (x))
5061 # define set_yylval_literal(x) (yylval.node = NEW_LIT(x))
5062 # define set_yylval_node(x) (yylval.node = (x))
5063 # define yylval_id() (yylval.id)
5066 ripper_yylval_id(
ID x)
5070 # define set_yylval_str(x) (void)(x)
5071 # define set_yylval_num(x) (void)(x)
5072 # define set_yylval_id(x) (void)(x)
5073 # define set_yylval_name(x) (void)(yylval.val = ripper_yylval_id(x))
5074 # define set_yylval_literal(x) (void)(x)
5075 # define set_yylval_node(x) (void)(x)
5076 # define yylval_id() yylval.id
5080 #define ripper_flush(p) (void)(p)
5082 #define ripper_flush(p) ((p)->tokp = (p)->parser_lex_p)
5084 #define yylval_rval (*(RB_TYPE_P(yylval.val, T_NODE) ? &yylval.node->nd_rval : &yylval.val))
5091 return lex_p > parser->tokp;
5104 ripper_dispatch_scan_event(
struct parser_params *parser,
int t)
5106 if (!ripper_has_scan_event(parser))
return;
5107 yylval_rval = ripper_scan_event_val(parser, t);
5111 ripper_dispatch_ignored_scan_event(
struct parser_params *parser,
int t)
5113 if (!ripper_has_scan_event(parser))
return;
5114 (void)ripper_scan_event_val(parser, t);
5118 ripper_dispatch_delayed_token(
struct parser_params *parser,
int t)
5121 const char *saved_tokp = parser->tokp;
5124 parser->tokp =
lex_pbeg + parser->delayed_col;
5126 parser->delayed =
Qnil;
5128 parser->tokp = saved_tokp;
5139 #undef SIGN_EXTEND_CHAR
5141 # define SIGN_EXTEND_CHAR(c) ((signed char)(c))
5144 # define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
5147 #define parser_encoding_name() (current_enc->name)
5148 #define parser_mbclen() mbclen((lex_p-1),lex_pend,current_enc)
5149 #define parser_precise_mbclen() rb_enc_precise_mbclen((lex_p-1),lex_pend,current_enc)
5150 #define is_identchar(p,e,enc) (rb_enc_isalnum((unsigned char)(*(p)),(enc)) || (*(p)) == '_' || !ISASCII(*(p)))
5151 #define parser_is_identchar() (!parser->eofp && is_identchar((lex_p-1),lex_pend,current_enc))
5153 #define parser_isascii() ISASCII(*(lex_p-1))
5161 for (p =
lex_pbeg; p < pend; p++) {
5163 column = (((column - 1) / 8) + 1) * 8;
5174 for (p =
lex_pbeg; p < pend; p++) {
5175 if (*p !=
' ' && *p !=
'\t') {
5182 #undef token_info_push
5199 #undef token_info_pop
5206 if (!ptinfo)
return;
5212 if (linenum == ptinfo->
linenum) {
5220 "mismatched indentations at '%s' with '%s' at %d",
5233 const int max_line_margin = 30;
5242 if (*p ==
'\n')
break;
5249 if (*pe ==
'\n')
break;
5256 const char *pre =
"", *post =
"";
5258 if (len > max_line_margin * 2 + 10) {
5259 if (
lex_p - p > max_line_margin) {
5263 if (pe -
lex_p > max_line_margin) {
5270 MEMCPY(buf, p,
char, len);
5274 i = (int)(
lex_p - p);
5275 p2 =
buf; pe = buf + len;
5278 if (*p2 !=
'\t') *p2 =
' ';
5286 dispatch1(parse_error,
STR_NEW2(msg));
5298 CONST_ID(script_lines,
"SCRIPT_LINES__");
5314 if (
RTEST(coverages) &&
RBASIC(coverages)->klass == 0) {
5318 for (i = 0; i < n; i++)
RARRAY_ASET(lines, i, Qnil);
5319 RARRAY(lines)->as.heap.len = n;
5416 char *beg, *end, *pend;
5426 while (end < pend) {
5427 if (*end++ ==
'\n')
break;
5437 if (
NIL_P(line))
return line;
5548 #define STR_FUNC_ESCAPE 0x01
5549 #define STR_FUNC_EXPAND 0x02
5550 #define STR_FUNC_REGEXP 0x04
5551 #define STR_FUNC_QWORDS 0x08
5552 #define STR_FUNC_SYMBOL 0x10
5553 #define STR_FUNC_INDENT 0x20
5559 str_regexp = (STR_FUNC_REGEXP|STR_FUNC_ESCAPE|STR_FUNC_EXPAND),
5561 str_dword = (STR_FUNC_QWORDS|STR_FUNC_EXPAND),
5563 str_dsym = (STR_FUNC_SYMBOL|STR_FUNC_EXPAND)
5583 #define lex_goto_eol(parser) ((parser)->parser_lex_p = (parser)->parser_lex_pend)
5584 #define lex_eol_p() (lex_p >= lex_pend)
5585 #define peek(c) peek_n((c), 0)
5586 #define peek_n(c,n) (lex_p+(n) < lex_pend && (c) == (unsigned char)lex_p[n])
5609 if (
NIL_P(parser->delayed)) {
5613 parser->tokp,
lex_pend - parser->tokp);
5615 parser->delayed_col = (int)(parser->tokp -
lex_pbeg);
5619 parser->tokp,
lex_pend - parser->tokp);
5635 c = (
unsigned char)*
lex_p++;
5653 if (c == -1)
return;
5660 #define was_bol() (lex_p == lex_pbeg + 1)
5662 #define tokfix() (tokenbuf[tokidx]='\0')
5663 #define tok() tokenbuf
5664 #define toklen() tokidx
5665 #define toklast() (tokidx>0?tokenbuf[tokidx-1]:0)
5712 yyerror(
"invalid hex escape");
5719 #define tokcopy(n) memcpy(tokspace(n), lex_p - (n), (n))
5724 int string_literal,
int symbol_literal,
int regexp_literal)
5744 yyerror(
"invalid Unicode escape");
5747 if (codepoint > 0x10ffff) {
5748 yyerror(
"invalid Unicode codepoint (too large)");
5752 if (regexp_literal) {
5755 else if (codepoint >= 0x80) {
5757 if (string_literal)
tokaddmbc(codepoint, *encp);
5759 else if (string_literal) {
5762 }
while (string_literal && (
peek(
' ') ||
peek(
'\t')));
5765 yyerror(
"unterminated Unicode escape");
5769 if (regexp_literal) {
tokadd(
'}'); }
5775 yyerror(
"invalid Unicode escape");
5779 if (regexp_literal) {
5782 else if (codepoint >= 0x80) {
5784 if (string_literal)
tokaddmbc(codepoint, *encp);
5786 else if (string_literal) {
5794 #define ESCAPE_CONTROL 1
5795 #define ESCAPE_META 2
5804 switch (c =
nextc()) {
5829 case '0':
case '1':
case '2':
case '3':
5830 case '4':
case '5':
case '6':
case '7':
5838 if (numlen == 0)
return 0;
5848 if (flags & ESCAPE_META)
goto eof;
5849 if ((c =
nextc()) !=
'-') {
5853 if ((c =
nextc()) ==
'\\') {
5854 if (
peek(
'u'))
goto eof;
5855 return read_escape(flags|ESCAPE_META, encp) | 0x80;
5857 else if (c == -1 || !
ISASCII(c))
goto eof;
5859 return ((c & 0xff) | 0x80);
5863 if ((c =
nextc()) !=
'-') {
5868 if (flags & ESCAPE_CONTROL)
goto eof;
5869 if ((c =
nextc())==
'\\') {
5870 if (
peek(
'u'))
goto eof;
5875 else if (c == -1 || !
ISASCII(c))
goto eof;
5880 yyerror(
"Invalid escape character syntax");
5903 switch (c =
nextc()) {
5907 case '0':
case '1':
case '2':
case '3':
5908 case '4':
case '5':
case '6':
case '7':
5911 if (numlen == 0)
goto eof;
5920 if (numlen == 0)
return -1;
5926 if (flags & ESCAPE_META)
goto eof;
5927 if ((c =
nextc()) !=
'-') {
5932 flags |= ESCAPE_META;
5936 if (flags & ESCAPE_CONTROL)
goto eof;
5937 if ((c =
nextc()) !=
'-') {
5945 if (flags & ESCAPE_CONTROL)
goto eof;
5947 flags |= ESCAPE_CONTROL;
5949 if ((c =
nextc()) ==
'\\') {
5952 else if (c == -1)
goto eof;
5958 yyerror(
"Invalid escape character syntax");
6025 #define tokadd_mbchar(c) parser_tokadd_mbchar(parser, (c))
6031 case '$':
case '*':
case '+':
case '.':
6032 case '?':
case '^':
case '|':
6033 case ')':
case ']':
case '}':
case '>':
6042 int func,
int term,
int paren,
long *nest,
6046 int has_nonascii = 0;
6049 static const char mixed_msg[] =
"%s mixed within %s source";
6051 #define mixed_error(enc1, enc2) if (!errbuf) { \
6052 size_t len = sizeof(mixed_msg) - 4; \
6053 len += strlen(rb_enc_name(enc1)); \
6054 len += strlen(rb_enc_name(enc2)); \
6055 errbuf = ALLOCA_N(char, len); \
6056 snprintf(errbuf, len, mixed_msg, \
6057 rb_enc_name(enc1), \
6058 rb_enc_name(enc2)); \
6061 #define mixed_escape(beg, enc1, enc2) do { \
6062 const char *pos = lex_p; \
6064 mixed_error((enc1), (enc2)); \
6068 while ((c =
nextc()) != -1) {
6069 if (paren && c == paren) {
6072 else if (c == term) {
6073 if (!nest || !*nest) {
6079 else if ((func & STR_FUNC_EXPAND) && c ==
'#' &&
lex_p <
lex_pend) {
6081 if (c2 ==
'$' || c2 ==
'@' || c2 ==
'{') {
6086 else if (c ==
'\\') {
6087 const char *beg =
lex_p - 1;
6091 if (func & STR_FUNC_QWORDS)
break;
6092 if (func & STR_FUNC_EXPAND)
continue;
6097 if (func & STR_FUNC_ESCAPE)
tokadd(c);
6101 if ((func & STR_FUNC_EXPAND) == 0) {
6106 func & STR_FUNC_SYMBOL,
6107 func & STR_FUNC_REGEXP);
6108 if (has_nonascii && enc != *encp) {
6114 if (c == -1)
return -1;
6116 if ((func & STR_FUNC_EXPAND) == 0)
tokadd(
'\\');
6119 if (func & STR_FUNC_REGEXP) {
6127 if (has_nonascii && enc != *encp) {
6132 else if (func & STR_FUNC_EXPAND) {
6134 if (func & STR_FUNC_ESCAPE)
tokadd(
'\\');
6137 else if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
6140 else if (c != term && !(paren && c == paren)) {
6157 else if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
6174 #define NEW_STRTERM(func, term, paren) \
6175 rb_node_newnode(NODE_STRTERM, (func), (term) | ((paren) << (CHAR_BIT * 2)), 0)
6181 if (!
NIL_P(parser->delayed)) {
6182 ptrdiff_t len =
lex_p - parser->tokp;
6187 parser->tokp =
lex_p;
6191 #define flush_string_content(enc) ripper_flush_string_content(parser, (enc))
6193 #define flush_string_content(enc) ((void)(enc))
6200 #define BIT(c, idx) (((c) / 32 - 1 == idx) ? (1U << ((c) % 32)) : 0)
6201 #define SPECIAL_PUNCT(idx) ( \
6202 BIT('~', idx) | BIT('*', idx) | BIT('$', idx) | BIT('?', idx) | \
6203 BIT('!', idx) | BIT('@', idx) | BIT('/', idx) | BIT('\\', idx) | \
6204 BIT(';', idx) | BIT(',', idx) | BIT('.', idx) | BIT('=', idx) | \
6205 BIT(':', idx) | BIT('<', idx) | BIT('>', idx) | BIT('\"', idx) | \
6206 BIT('&', idx) | BIT('`', idx) | BIT('\'', idx) | BIT('+', idx) | \
6214 #undef SPECIAL_PUNCT
6220 if (c <= 0x20 || 0x7e < c)
return 0;
6221 return (ruby_global_name_punct_bits[(c - 0x20) / 32] >> (c % 32)) & 1;
6228 const char *p =
lex_p;
6234 if ((c = *p) ==
'-') {
6243 if ((c = *p) ==
'@') {
6263 int func = (int)quote->nd_func;
6271 if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
6275 if (c == term && !quote->nd_nest) {
6276 if (func & STR_FUNC_QWORDS) {
6277 quote->nd_func = -1;
6280 if (!(func & STR_FUNC_REGEXP))
return tSTRING_END;
6289 if ((func & STR_FUNC_EXPAND) && c ==
'#') {
6299 if (func & STR_FUNC_REGEXP) {
6321 int c =
nextc(), term, func = 0;
6339 while ((c =
nextc()) != -1 && c != term) {
6351 if (func & STR_FUNC_INDENT) {
6387 line = here->nd_orig;
6391 lex_p = lex_pbeg + here->nd_nth;
6401 const char *eos,
long len,
int indent)
6407 while (*p &&
ISSPACE(*p)) p++;
6410 if (n < 0)
return FALSE;
6411 if (n > 0 && p[len] !=
'\n') {
6412 if (p[len] !=
'\r')
return FALSE;
6413 if (n <= 1 || p[len+1] !=
'\n')
return FALSE;
6415 return strncmp(eos, p, len) == 0;
6418 #define NUM_SUFFIX_R (1<<0)
6419 #define NUM_SUFFIX_I (1<<1)
6420 #define NUM_SUFFIX_ALL 3
6426 const char *lastp =
lex_p;
6428 while ((c =
nextc()) != -1) {
6429 if ((mask & NUM_SUFFIX_I) && c ==
'i') {
6430 result |= (mask & NUM_SUFFIX_I);
6431 mask &= ~NUM_SUFFIX_I;
6436 if ((mask & NUM_SUFFIX_R) && c ==
'r') {
6437 result |= (mask & NUM_SUFFIX_R);
6438 mask &= ~NUM_SUFFIX_R;
6454 if (suffix & NUM_SUFFIX_I) {
6466 if (suffix & NUM_SUFFIX_R) {
6477 if (!
NIL_P(parser->delayed))
6480 ripper_dispatch_ignored_scan_event(parser,
tHEREDOC_END);
6483 #define dispatch_heredoc_end() ripper_dispatch_heredoc_end(parser)
6485 #define dispatch_heredoc_end() ((void)0)
6491 int c,
func, indent = 0;
6492 const char *eos, *p, *pend;
6499 indent = (func = *eos++) & STR_FUNC_INDENT;
6501 if ((c =
nextc()) == -1) {
6505 if (
NIL_P(parser->delayed)) {
6510 ((len =
lex_p - parser->tokp) > 0 &&
6511 (str =
STR_NEW3(parser->tokp, len, enc, func), 1))) {
6528 if (!(func & STR_FUNC_EXPAND)) {
6535 if (--pend == p || pend[-1] !=
'\r') {
6549 if (
nextc() == -1) {
6567 if (parser->
eofp)
goto error;
6577 if ((c =
nextc()) == -1)
goto error;
6594 rb_warning0(
"ambiguous first argument; put parentheses or even spaces");
6599 #define arg_ambiguous() (arg_ambiguous_gen(parser), 1)
6606 yyerror(
"formal argument must be local variable");
6624 if (len > 5 && name[nlen = len - 5] ==
'-') {
6628 if (len > 4 && name[nlen = len - 4] ==
'-') {
6631 if (
rb_memcicmp(name + nlen + 1,
"mac", 3) == 0 &&
6632 !(len == 8 &&
rb_memcicmp(name,
"utf8-mac", len) == 0))
6647 excargs[1] =
rb_sprintf(
"unknown encoding name: %s", name);
6664 for (i = 0; i < n; ++i) {
6739 if (str[i-1] ==
'*' && str[i-2] ==
'-') {
6745 if (i + 1 >= len)
return 0;
6746 if (str[i+1] !=
'-') {
6749 else if (str[i-1] !=
'-') {
6767 VALUE name = 0, val = 0;
6768 const char *beg, *end, *vbeg, *vend;
6769 #define str_copy(_s, _p, _n) ((_s) \
6770 ? (void)(rb_str_resize((_s), (_n)), \
6771 MEMCPY(RSTRING_PTR(_s), (_p), char, (_n)), (_s)) \
6772 : (void)((_s) = STR_NEW((_p), (_n))))
6774 if (len <= 7)
return FALSE;
6778 len = end - beg - 3;
6789 for (; len > 0 && *str; str++, --len) {
6791 case '\'':
case '"':
case ':':
case ';':
6796 for (beg = str; len > 0; str++, --len) {
6798 case '\'':
case '"':
case ':':
case ';':
6806 for (end = str; len > 0 &&
ISSPACE(*str); str++, --len);
6808 if (*str !=
':')
continue;
6810 do str++;
while (--len > 0 &&
ISSPACE(*str));
6813 for (vbeg = ++str; --len > 0 && *str !=
'"'; str++) {
6826 for (vbeg = str; len > 0 && *str !=
'"' && *str !=
';' && !
ISSPACE(*str); --len, str++);
6829 while (len > 0 && (*str ==
';' ||
ISSPACE(*str))) --len, str++;
6834 for (i = 0; i < n; ++i) {
6835 if (s[i] ==
'-') s[i] =
'_';
6842 n = (*p->
length)(parser, vbeg, n);
6848 }
while (++p < magic_comments +
numberof(magic_comments));
6862 const char *beg = str;
6866 if (send - str <= 6)
return;
6868 case 'C':
case 'c': str += 6;
continue;
6869 case 'O':
case 'o': str += 5;
continue;
6870 case 'D':
case 'd': str += 4;
continue;
6871 case 'I':
case 'i': str += 3;
continue;
6872 case 'N':
case 'n': str += 2;
continue;
6873 case 'G':
case 'g': str += 1;
continue;
6887 if (++str >= send)
return;
6890 if (*str !=
'=' && *str !=
':')
return;
6895 while ((*str ==
'-' || *str ==
'_' ||
ISALNUM(*str)) && ++str < send);
6911 (
unsigned char)
lex_p[0] == 0xbb &&
6912 (
unsigned char)
lex_p[1] == 0xbf) {
6926 #define IS_ARG() IS_lex_state(EXPR_ARG_ANY)
6927 #define IS_END() IS_lex_state(EXPR_END_ANY)
6928 #define IS_BEG() IS_lex_state(EXPR_BEG_ANY)
6929 #define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c))
6930 #define IS_LABEL_POSSIBLE() ((IS_lex_state(EXPR_BEG | EXPR_ENDFN) && !cmd_state) || IS_ARG())
6931 #define IS_LABEL_SUFFIX(n) (peek_n(':',(n)) && !peek_n(':', (n)+1))
6932 #define IS_AFTER_OPERATOR() IS_lex_state(EXPR_FNAME | EXPR_DOT)
6935 #define ambiguous_operator(op, syn) ( \
6936 rb_warning0("`"op"' after local variable or literal is interpreted as binary operator"), \
6937 rb_warning0("even though it seems like "syn""))
6939 #define ambiguous_operator(op, syn) dispatch2(operator_ambiguous, ripper_intern(op), rb_str_new_cstr(syn))
6941 #define warn_balanced(op, syn) ((void) \
6942 (!IS_lex_state_for(last_state, EXPR_CLASS|EXPR_DOT|EXPR_FNAME|EXPR_ENDFN|EXPR_ENDARG) && \
6943 space_seen && !ISSPACE(c) && \
6944 (ambiguous_operator(op, syn), 0)))
6956 int fallthru =
FALSE;
6982 switch (c =
nextc()) {
6990 case ' ':
case '\t':
case '\f':
case '\r':
6994 while ((c =
nextc())) {
6996 case ' ':
case '\t':
case '\f':
case '\r':
7005 ripper_dispatch_scan_event(parser,
tSP);
7018 ripper_dispatch_scan_event(parser,
tCOMMENT);
7023 if (
IS_lex_state(EXPR_BEG | EXPR_VALUE | EXPR_CLASS | EXPR_FNAME | EXPR_DOT | EXPR_LABELARG)) {
7031 goto normal_newline;
7035 while ((c =
nextc())) {
7037 case ' ':
case '\t':
case '\f':
case '\r':
7042 if ((c =
nextc()) !=
'.') {
7055 parser->tokp =
lex_p;
7058 goto normal_newline;
7067 if ((c =
nextc()) ==
'*') {
7068 if ((c =
nextc()) ==
'=') {
7075 rb_warning0(
"`**' interpreted as argument prefix");
7094 rb_warning0(
"`*' interpreted as argument prefix");
7142 ripper_dispatch_scan_event(parser,
tEMBDOC);
7151 if (c !=
'=')
continue;
7152 if (strncmp(
lex_p,
"end", 3) == 0 &&
7166 if ((c =
nextc()) ==
'=') {
7167 if ((c =
nextc()) ==
'=') {
7176 else if (c ==
'>') {
7188 (!
IS_ARG() || space_seen)) {
7190 if (token)
return token;
7201 if ((c =
nextc()) ==
'>') {
7208 if ((c =
nextc()) ==
'=') {
7222 if ((c =
nextc()) ==
'=') {
7226 if ((c =
nextc()) ==
'=') {
7294 rb_warnI(
"invalid character syntax; use ?\\%c", c2);
7311 else if (c ==
'\\') {
7340 if ((c =
nextc()) ==
'&') {
7342 if ((c =
nextc()) ==
'=') {
7350 else if (c ==
'=') {
7357 rb_warning0(
"`&' interpreted as argument prefix");
7371 if ((c =
nextc()) ==
'|') {
7373 if ((c =
nextc()) ==
'=') {
7453 if ((c =
nextc()) ==
'.') {
7454 if ((c =
nextc()) ==
'.') {
7462 yyerror(
"no .<digit> floating literal anymore; put 0 before dot");
7468 case '0':
case '1':
case '2':
case '3':
case '4':
7469 case '5':
case '6':
case '7':
case '8':
case '9':
7471 int is_float, seen_point, seen_e, nondigit;
7474 is_float = seen_point = seen_e = nondigit = 0;
7477 if (c ==
'-' || c ==
'+') {
7482 #define no_digits() do {yyerror("numeric literal without digits"); return 0;} while (0)
7485 if (c ==
'x' || c ==
'X') {
7491 if (nondigit)
break;
7498 }
while ((c =
nextc()) != -1);
7505 else if (nondigit)
goto trailing_uc;
7509 if (c ==
'b' || c ==
'B') {
7512 if (c ==
'0' || c ==
'1') {
7515 if (nondigit)
break;
7519 if (c !=
'0' && c !=
'1')
break;
7522 }
while ((c =
nextc()) != -1);
7529 else if (nondigit)
goto trailing_uc;
7533 if (c ==
'd' || c ==
'D') {
7539 if (nondigit)
break;
7546 }
while ((c =
nextc()) != -1);
7553 else if (nondigit)
goto trailing_uc;
7561 if (c ==
'o' || c ==
'O') {
7564 if (c == -1 || c ==
'_' || !
ISDIGIT(c)) {
7568 if (c >=
'0' && c <=
'7') {
7573 if (nondigit)
break;
7577 if (c < '0' || c >
'9')
break;
7578 if (c >
'7')
goto invalid_octal;
7581 }
while ((c =
nextc()) != -1);
7585 if (nondigit)
goto trailing_uc;
7594 if (c >
'7' && c <=
'9') {
7596 yyerror(
"Invalid octal digit");
7598 else if (c ==
'.' || c ==
'e' || c ==
'E') {
7610 case '0':
case '1':
case '2':
case '3':
case '4':
7611 case '5':
case '6':
case '7':
case '8':
case '9':
7617 if (nondigit)
goto trailing_uc;
7618 if (seen_point || seen_e) {
7623 if (c0 == -1 || !
ISDIGIT(c0)) {
7648 if (c !=
'-' && c !=
'+' && !
ISDIGIT(c)) {
7657 nondigit = (c ==
'-' || c ==
'+') ? c : 0;
7661 if (nondigit)
goto decode_num;
7676 snprintf(tmp,
sizeof(tmp),
"trailing `%c' in number", nondigit);
7685 if (suffix & NUM_SUFFIX_R) {
7686 char *point = &
tok()[seen_point];
7687 size_t fraclen =
toklen()-seen_point-1;
7689 memmove(point, point+1, fraclen+1);
7695 if (errno == ERANGE) {
7773 if ((c =
nextc()) ==
'=') {
7793 if ((c =
nextc()) !=
'@') {
7820 if ((c =
nextc()) ==
']') {
7821 if ((c =
nextc()) ==
'=') {
7833 else if (
IS_ARG() && space_seen) {
7868 ripper_dispatch_scan_event(parser,
tSP);
7889 yyerror(
"unknown type of %string");
7893 if (c == -1 || term == -1) {
7898 if (term ==
'(') term =
')';
7899 else if (term ==
'[') term =
']';
7900 else if (term ==
'{') term =
'}';
7901 else if (term ==
'<') term =
'>';
7951 yyerror(
"unknown type of %string");
7955 if ((c =
nextc()) ==
'=') {
8031 case '1':
case '2':
case '3':
8032 case '4':
case '5':
case '6':
8033 case '7':
case '8':
case '9':
8038 }
while (c != -1 &&
ISDIGIT(c));
8084 ripper_dispatch_scan_event(parser,
k__END__);
8112 if ((c ==
'!' || c ==
'?') && !
peek(
'=')) {
8132 if (
tok()[1] ==
'@')
8170 if (mb == ENC_CODERANGE_7BIT && !
IS_lex_state(EXPR_DOT)) {
8201 if (kw->
id[0] != kw->
id[1])
8238 yylex(
void *lval,
void *p)
8252 if (!
NIL_P(parser->delayed)) {
8253 ripper_dispatch_delayed_token(parser, t);
8257 ripper_dispatch_scan_event(parser, t);
8299 if (orig == (
NODE*)1)
return;
8308 #define parser_warning(node, mesg) parser_warning(parser, (node), (mesg))
8315 #define parser_warn(node, mesg) parser_warn(parser, (node), (mesg))
8322 if (tail == 0)
return head;
8324 if (h == 0)
return tail;
8352 if (
RTEST(ruby_verbose)) {
8363 tail->nd_end =
tail;
8365 end->nd_next =
tail;
8366 h->nd_end = tail->nd_end;
8376 if (list == 0)
return NEW_LIST(item);
8377 if (list->nd_next) {
8378 last = list->nd_next->nd_end;
8386 list->nd_next->nd_end = last->nd_next;
8396 if (head->nd_next) {
8397 last = head->nd_next->nd_end;
8403 head->nd_alen += tail->nd_alen;
8404 last->nd_next =
tail;
8405 if (tail->nd_next) {
8406 head->nd_next->nd_end = tail->nd_next->nd_end;
8409 head->nd_next->nd_end =
tail;
8418 if (
NIL_P(tail))
return 1;
8439 if (!head)
return tail;
8440 if (!tail)
return head;
8450 if (htype ==
NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
8453 lit = headlast->nd_lit;
8476 tail->nd_lit = head->nd_lit;
8480 else if (
NIL_P(tail->nd_lit)) {
8482 head->nd_alen += tail->nd_alen - 1;
8483 head->nd_next->nd_end->nd_next = tail->nd_next;
8484 head->nd_next->nd_end = tail->nd_next->nd_end;
8487 else if (htype ==
NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
8489 lit = headlast->nd_lit;
8492 tail->nd_lit =
Qnil;
8497 tail->nd_head =
NEW_STR(tail->nd_lit);
8563 if (
RB_TYPE_P(node1->nd_lit, T_REGEXP)) {
8576 if (
RB_TYPE_P(node2->nd_lit, T_REGEXP)) {
8627 switch (
id & ID_SCOPE_MASK) {
8646 static const char names[][12] = {
8647 "EXPR_BEG",
"EXPR_END",
"EXPR_ENDARG",
"EXPR_ENDFN",
"EXPR_ARG",
8648 "EXPR_CMDARG",
"EXPR_MID",
"EXPR_FNAME",
"EXPR_DOT",
"EXPR_CLASS",
8653 return names[
ffs(state)];
8668 # define assignable_result(x) get_value(lhs)
8669 # define parser_yyerror(parser, x) dispatch1(assign_error, lhs)
8671 # define assignable_result(x) (x)
8676 yyerror(
"Can't change the value of self");
8679 yyerror(
"Can't assign to nil");
8682 yyerror(
"Can't assign to true");
8685 yyerror(
"Can't assign to false");
8688 yyerror(
"Can't assign to __FILE__");
8691 yyerror(
"Can't assign to __LINE__");
8694 yyerror(
"Can't assign to __ENCODING__");
8728 yyerror(
"dynamic constant assignment");
8737 #undef assignable_result
8738 #undef parser_yyerror
8745 if (name == idUScore)
return 1;
8752 #define LVAR_USED ((ID)1 << (sizeof(ID) * CHAR_BIT - 1))
8760 yyerror(
"duplicated argument name");
8773 yyerror(
"duplicated argument name");
8838 int scope = (int)(
id & ID_SCOPE_MASK);
8846 rb_name_error(
id,
"cannot make %s ID %+"PRIsVALUE
" attrset",
8847 id_type_names[scope],
ID2SYM(
id));
8851 id &= ~ID_SCOPE_MASK;
8880 if (!node2)
return node1;
8884 node1->nd_head =
arg_concat(node1->nd_head, node2);
8896 node1->nd_body =
list_concat(node1->nd_body, node2);
8905 if (!node1)
return NEW_LIST(node2);
8910 node1->nd_head =
arg_append(node1->nd_head, node2);
8943 lhs->nd_value = rhs;
8948 lhs->nd_args =
arg_append(lhs->nd_args, rhs);
8974 if (!cond)
yyerror(
"void value expression");
8979 while (node->nd_next) {
8980 node = node->nd_next;
8982 node = node->nd_head;
8986 node = node->nd_body;
8990 if (!node->nd_body) {
8991 node = node->nd_else;
8994 else if (!node->nd_else) {
8995 node = node->nd_body;
8999 node = node->nd_else;
9005 node = node->nd_2nd;
9019 const char *useless = 0;
9021 if (!
RTEST(ruby_verbose))
return;
9026 switch (node->nd_mid) {
9057 useless =
"a variable";
9060 useless =
"a constant";
9067 useless =
"a literal";
9092 useless =
"defined?";
9100 rb_warnS(
"possibly useless use of %s in void context", useless);
9108 if (!
RTEST(ruby_verbose))
return;
9113 if (!node->nd_next)
return;
9115 node = node->nd_next;
9122 NODE **n = &node, *n1 = node;
9124 *n = n1 = n1->nd_body;
9132 NODE **n = &node, *n1 = node;
9134 *n = n1 = n1->nd_body;
9148 #define subnodes(n1, n2) \
9149 ((!node->n1) ? (node->n2 ? (body = &node->n2, 1) : 0) : \
9150 (!node->n2) ? (body = &node->n1, 1) : \
9151 (reduce_nodes(&node->n1), body = &node->n2, 1))
9154 int newline = (int)(node->
flags & NODE_FL_NEWLINE);
9161 *body = node = node->nd_stts;
9165 *body = node = node->nd_body;
9169 body = &node->nd_end->nd_head;
9172 if (
subnodes(nd_body, nd_else))
break;
9175 body = &node->nd_body;
9178 if (!
subnodes(nd_body, nd_next))
goto end;
9181 if (!
subnodes(nd_head, nd_resq))
goto end;
9184 if (node->nd_else) {
9185 body = &node->nd_resq;
9188 if (!
subnodes(nd_head, nd_resq))
goto end;
9203 if (!node)
return 1;
9206 if (!(node = node->nd_head))
break;
9210 }
while ((node = node->nd_next) != 0);
9229 yyerror(
"multiple assignment in conditional");
9243 if (!node->nd_value)
return 1;
9246 parser_warn(node->nd_value,
"found = in conditional, should be ==");
9268 for (node = *rootnode; node; node = next) {
9272 next = node->nd_next;
9273 head = node->nd_head;
9276 switch (type =
nd_type(head)) {
9279 val =
rb_range_new(head->nd_beg->nd_lit, head->nd_end->nd_lit,
9299 if (node == 0)
return 0;
9307 return cond0(parser, node);
9313 if (!node)
return 1;
9334 if (node == 0)
return 0;
9341 rb_warn0(
"string literal in condition");
9351 node->nd_1st =
cond0(parser, node->nd_1st);
9352 node->nd_2nd =
cond0(parser, node->nd_2nd);
9357 node->nd_beg =
range_op(parser, node->nd_beg);
9358 node->nd_end =
range_op(parser, node->nd_end);
9364 if ((b == 1 && e == 1) || (b + e >= 2 &&
RTEST(ruby_verbose))) {
9375 if (
RB_TYPE_P(node->nd_lit, T_REGEXP)) {
9391 if (node == 0)
return 0;
9392 return cond0(parser, node);
9400 NODE *node = left, *second;
9401 while ((second = node->nd_2nd) != 0 && (
enum node_type)
nd_type(second) == type) {
9404 node->nd_2nd =
NEW_NODE(type, second, right, 0);
9407 return NEW_NODE(type, left, right, 0);
9424 if (node->nd_next == 0) {
9425 node = node->nd_head;
9446 switch (
TYPE(node->nd_lit)) {
9468 rb_bug(
"unknown literal type passed to negate_lit");
9478 node2->nd_head = node1;
9492 args->
pre_init = m ? m->nd_next : 0;
9529 kw_rest_arg->nd_cflag = check;
9570 ID vid = lhs->nd_vid;
9572 lhs->nd_value = rhs;
9579 lhs->nd_value = rhs;
9633 return dispatch3(opassign, lhs, op, rhs);
9639 VALUE recv = dispatch3(field, lhs, type, attr);
9640 return dispatch3(opassign, recv, op, rhs);
9650 if (!local->
used)
return;
9654 if (cnt != local->
vars->
pos) {
9655 rb_bug(
"local->used->pos != local->vars->pos");
9657 for (i = 0; i <
cnt; ++i) {
9658 if (!v[i] || (u[i] & LVAR_USED))
continue;
9673 local->
used = !(inherit_dvars &&
9702 int cnt = cnt_args + cnt_vars;
9706 if (cnt <= 0)
return 0;
9710 for (i = 0, j = cnt_args+1; i < cnt_vars; ++i) {
9742 struct vtable *vars, *args, *used;
9751 if (used) used = used->
prev;
9762 if (i && used) used->
tbl[i-1] |= LVAR_USED;
9767 static const struct vtable *
9783 if ((tmp =
lvtbl->used) != 0) {
9799 while (
lvtbl->args != lvargs) {
9819 struct vtable *vars, *args, *used;
9831 if (used) used->
tbl[i-1] |= LVAR_USED;
9837 if (used) used = used->
prev;
9890 "regexp encoding option '%c' differs from source encoding '%s'",
9918 int back_num,
int *back_refs,
OnigRegex regex,
void *arg0)
9923 long len = name_end -
name;
9924 const char *s = (
const char *)name;
9941 rb_warningS(
"named capture conflicts a local variable - %s",
10021 NODE *scope = node;
10024 if (!node)
return node;
10028 node = node->nd_body;
10032 node = node->nd_body;
10039 prelude->nd_body = node;
10040 scope->nd_body = prelude;
10043 scope->nd_body = node;
10053 NODE *scope = node;
10056 if (!node)
return node;
10060 node = node->nd_body;
10064 node = node->nd_body;
10080 prelude->nd_body = node;
10081 scope->nd_body = prelude;
10084 scope->nd_body = node;
10090 static const struct {
10115 #define op_tbl_count numberof(op_tbl)
10117 #ifndef ENABLE_SELECTOR_NAMESPACE
10118 #define ENABLE_SELECTOR_NAMESPACE 0
10125 #if ENABLE_SELECTOR_NAMESPACE
10138 #if ENABLE_SELECTOR_NAMESPACE
10145 ivar2_cmp(
struct ivar2_key *key1,
struct ivar2_key *key2)
10147 if (key1->id == key2->id && key1->klass == key2->klass) {
10154 ivar2_hash(
struct ivar2_key *
key)
10156 return (key->id << 8) ^ (key->klass >> 2);
10170 #if ENABLE_SELECTOR_NAMESPACE
10178 (void)lex_state_name(-1);
10211 if (m >= e)
return 0;
10215 else if (*m ==
'-') {
10216 if (++m >= e)
return 0;
10229 return m == e ? mb + 1 : 0;
10244 #define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
10245 #define IDSET_ATTRSET_FOR_INTERN (~(~0U<<ID_SCOPE_MASK) & ~(1U<<ID_ATTRSET))
10250 const char *m =
name;
10251 const char *e = m + len;
10254 if (!m || len <= 0)
return -1;
10274 case '<': ++m;
break;
10275 case '=':
if (*++m ==
'>') ++m;
break;
10282 case '>':
case '=': ++m;
break;
10288 case '~': ++m;
break;
10289 case '=':
if (*++m ==
'=') ++m;
break;
10290 default:
return -1;
10295 if (*++m ==
'*') ++m;
10298 case '+':
case '-':
10299 if (*++m ==
'@') ++m;
10302 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
10307 if (*++m !=
']')
return -1;
10308 if (*++m ==
'=') ++m;
10312 if (len == 1)
return ID_JUNK;
10314 case '=':
case '~': ++m;
break;
10315 default:
return -1;
10327 case '!':
case '?':
10328 if (type == ID_GLOBAL || type == ID_CLASS || type == ID_INSTANCE)
return -1;
10333 if (!(allowed_attrset & (1
U << type)))
return -1;
10340 return m == e ? type : -1;
10407 fake_str->
as.
heap.len = len;
10408 fake_str->
as.
heap.ptr = (
char *)name;
10409 fake_str->
as.
heap.aux.capa = len;
10410 return (
VALUE)fake_str;
10432 const char *
name, *m, *e;
10454 if (len < 2)
goto junk;
10463 if (len < 3)
goto junk;
10468 if (len < 2)
goto junk;
10484 if (*
op_tbl[i].name == *m &&
10485 strcmp(
op_tbl[i].name, m) == 0) {
10493 if (name[last] ==
'=') {
10495 if (last > 1 && name[last-1] ==
'=')
10505 else if (
id == 0) {
10523 if (
id != ID_ATTRSET && m - name < len)
id =
ID_JUNK;
10577 name[0] = (char)
id;
10587 for (i = 0; i < op_tbl_count; i++) {
10588 if (
op_tbl[i].token ==
id) {
10604 if (
RBASIC(str)->klass == 0)
10610 ID id_stem = (
id & ~ID_SCOPE_MASK);
10614 if (!!(str =
rb_id2str(id_stem | ID_LOCAL)))
break;
10615 if (!!(str =
rb_id2str(id_stem | ID_CONST)))
break;
10616 if (!!(str =
rb_id2str(id_stem | ID_INSTANCE)))
break;
10617 if (!!(str =
rb_id2str(id_stem | ID_GLOBAL)))
break;
10618 if (!!(str =
rb_id2str(id_stem | ID_CLASS)))
break;
10619 if (!!(str =
rb_id2str(id_stem | ID_JUNK)))
break;
10627 if (
RBASIC(str)->klass == 0)
10640 if (!str)
return 0;
10734 VALUE name = *namep;
10785 fake_str.
as.
heap.len = len - 1;
10885 parser->delayed =
Qnil;
10887 parser->result =
Qnil;
10888 parser->parsing_thread =
Qnil;
10889 parser->toplevel_p =
TRUE;
10898 #define parser_mark ripper_parser_mark
10899 #define parser_free ripper_parser_free
10939 prev = local->
prev;
10950 size_t size =
sizeof(*p);
10952 if (!ptr)
return 0;
10955 size +=
sizeof(*local);
10976 #undef rb_reserved_word
11065 #define HEAPCNT(n, size) ((n) * (size) / sizeof(YYSTYPE))
11066 #define NEWHEAP() rb_node_newnode(NODE_ALLOCA, 0, (VALUE)parser->heap, 0)
11067 #define ADD2HEAP(n, c, p) ((parser->heap = (n))->u1.node = (p), \
11068 (n)->u3.cnt = (c), (p))
11073 size_t cnt =
HEAPCNT(1, size);
11083 size_t cnt =
HEAPCNT(nelem, size);
11085 void *ptr =
xcalloc(nelem, size);
11094 size_t cnt =
HEAPCNT(1, size);
11096 if (ptr && (n = parser->
heap) !=
NULL) {
11098 if (n->
u1.
node == ptr) {
11115 while ((n = *prev) !=
NULL) {
11116 if (n->
u1.
node == ptr) {
11129 #ifdef RIPPER_DEBUG
11130 extern int rb_is_pointer_to_heap(
VALUE);
11136 if (x == Qfalse)
return x;
11137 if (x == Qtrue)
return x;
11138 if (x == Qnil)
return x;
11143 if (!rb_is_pointer_to_heap(x))
11158 return ((
NODE *)x)->nd_rval;
11167 #define validate(x) ((x) = get_value(x))
11179 return rb_funcall(parser->value, mid, 1, a);
11187 return rb_funcall(parser->value, mid, 2, a, b);
11196 return rb_funcall(parser->value, mid, 3, a, b, c);
11206 return rb_funcall(parser->value, mid, 4, a, b, c, d);
11217 return rb_funcall(parser->value, mid, 5, a, b, c, d, e);
11230 return rb_funcall(parser->value, mid, 7, a, b, c, d, e, f, g);
11233 static const struct kw_assoc {
11236 } keyword_to_name[] = {
11289 keyword_id_to_str(
ID id)
11291 const struct kw_assoc *a;
11293 for (a = keyword_to_name; a->id; a++) {
11300 #undef ripper_id2sym
11302 ripper_id2sym(
ID id)
11312 if ((name = keyword_id_to_str(
id))) {
11325 rb_bug(
"cannot convert ID to string: %ld", (
unsigned long)
id);
11333 ripper_get_id(
VALUE v)
11343 ripper_get_value(
VALUE v)
11346 if (v == Qundef)
return Qnil;
11350 return nd->nd_rval;
11354 ripper_compile_error(
struct parser_params *parser,
const char *fmt, ...)
11359 va_start(args, fmt);
11366 ripper_warn0(
struct parser_params *parser,
const char *fmt)
11372 ripper_warnI(
struct parser_params *parser,
const char *fmt,
int a)
11379 ripper_warnS(
struct parser_params *parser,
const char *fmt,
const char *str)
11386 ripper_warning0(
struct parser_params *parser,
const char *fmt)
11392 ripper_warningS(
struct parser_params *parser,
const char *fmt,
const char *str)
11405 ripper_s_allocate(
VALUE klass)
11417 #define ripper_initialized_p(r) ((r)->parser_lex_input != 0)
11433 VALUE src, fname, lineno;
11436 rb_scan_args(argc, argv,
"12", &src, &fname, &lineno);
11446 if (
NIL_P(fname)) {
11461 struct ripper_args {
11468 ripper_parse0(
VALUE parser_v)
11474 ripper_yyparse((
void*)parser);
11475 return parser->result;
11479 ripper_ensure(
VALUE parser_v)
11484 parser->parsing_thread =
Qnil;
11495 ripper_parse(
VALUE self)
11500 if (!ripper_initialized_p(parser)) {
11503 if (!
NIL_P(parser->parsing_thread)) {
11510 rb_ensure(ripper_parse0,
self, ripper_ensure,
self);
11512 return parser->result;
11523 ripper_column(
VALUE self)
11529 if (!ripper_initialized_p(parser)) {
11532 if (
NIL_P(parser->parsing_thread))
return Qnil;
11544 ripper_filename(
VALUE self)
11549 if (!ripper_initialized_p(parser)) {
11563 ripper_lineno(
VALUE self)
11568 if (!ripper_initialized_p(parser)) {
11571 if (
NIL_P(parser->parsing_thread))
return Qnil;
11575 #ifdef RIPPER_DEBUG
11581 if (obj == Qundef) {
11611 InitVM_ripper(
void)
11628 #ifdef RIPPER_DEBUG