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)
164 if (
VTBL_DEBUG) printf(
"vtable_alloc: %p\n", (
void *)tbl);
171 if (
VTBL_DEBUG)printf(
"vtable_free: %p\n", (
void *)tbl);
184 rb_bug(
"vtable_add: vtable is not allocated (%p)", (
void *)tbl);
201 for (i = 0; i < tbl->
pos; i++) {
202 if (tbl->
tbl[i] ==
id) {
298 VALUE parsing_thread;
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))
657 static void ripper_warn0(
struct parser_params*,
const char*);
658 static void ripper_warnI(
struct parser_params*,
const char*,
int);
659 static void ripper_warnS(
struct parser_params*,
const char*,
const char*);
660 static void ripper_warning0(
struct parser_params*,
const char*);
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 <node> singleton strings
string string1 xstring regexp
768 %type <node> string_contents xstring_contents regexp_contents string_content
769 %type <node> words
symbols symbol_list qwords qsymbols word_list qword_list qsym_list word
770 %type <node> literal numeric simple_numeric dsym cpath
771 %type <node> top_compstmt top_stmts
top_stmt
773 %type <node> expr_value arg_value primary_value fcall
774 %type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
776 %type <node> paren_args opt_paren_args args_tail opt_args_tail block_args_tail opt_block_args_tail
777 %type <node>
command_args aref_args opt_block_arg block_arg var_ref var_lhs
778 %type <node> command_asgn mrhs mrhs_arg superclass block_call block_command
779 %type <node> f_block_optarg f_block_opt
780 %type <node> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
781 %type <node> assoc_list assocs
assoc undef_list backref string_dvar for_var
782 %type <node> block_param opt_block_param block_param_def f_opt
783 %type <node> f_kwarg f_kw f_block_kwarg f_block_kw
784 %type <node> bv_decls opt_bv_decl bvar
785 %type <node> lambda f_larglist lambda_body
789 %type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
790 %type <id> f_kwrest f_label
879 while (node->nd_next) {
880 node = node->nd_next;
894 top_compstmt : top_stmts opt_terms
969 rb_warn0(
"else without rescue is useless");
1039 yyerror(
"BEGIN is permitted only at toplevel");
1045 '{' top_compstmt
'}'
1079 buf[1] = (char)$3->
nd_nth;
1088 yyerror(
"can't make alias for the number variables");
1159 rb_warn0(
"END in method; use at_exit");
1334 block_command : block_call
1413 $5->nd_iter =
NEW_CALL($1, $3, $4);
1434 $5->nd_iter =
NEW_CALL($1, $3, $4);
1649 | primary_value
'[' opt_call_args rbracket
1685 yyerror(
"dynamic constant assignment");
1697 yyerror(
"dynamic constant assignment");
1733 | primary_value
'[' opt_call_args rbracket
1769 yyerror(
"dynamic constant assignment");
1782 yyerror(
"dynamic constant assignment");
1805 yyerror(
"class/module name must be CONSTANT");
1881 | undef_list
',' {
lex_state = EXPR_FNAME;} fitem
1971 | primary_value
'[' opt_call_args rbracket
tOP_ASGN arg
2342 | args
',' assocs trailer
2360 paren_args :
'(' opt_call_args rparen
2370 opt_paren_args : none
2374 opt_call_args : none
2380 | args
',' assocs
','
2407 | args opt_block_arg
2415 | assocs opt_block_arg
2425 | args
',' assocs opt_block_arg
2455 block_arg :
tAMPER arg_value
2465 opt_block_arg :
',' block_arg
2491 | args
',' arg_value
2505 | args
',' tSTAR arg_value
2525 mrhs : args
',' arg_value
2539 | args
',' tSTAR arg_value
2746 | method_call brace_block
2760 | k_if expr_value then
2772 | k_unless expr_value then
2806 | k_case expr_value opt_terms
2817 | k_case opt_terms case_body k_end
2884 tbl[0] = 1; tbl[1] =
id;
2891 | k_class cpath superclass
2894 yyerror(
"class definition in method body");
2939 yyerror(
"module definition in method body");
2980 | k_def singleton dot_or_colon {
lex_state = EXPR_FNAME;} fname
3035 primary_value : primary
3185 f_marg_list : f_marg
3193 | f_marg_list
',' f_marg
3203 f_margs : f_marg_list
3211 | f_marg_list
',' tSTAR f_norm_arg
3220 | f_marg_list
',' tSTAR f_norm_arg
',' f_marg_list
3229 | f_marg_list
',' tSTAR
3237 | f_marg_list
',' tSTAR ',' f_marg_list
3254 |
tSTAR f_norm_arg
',' f_marg_list
3274 |
tSTAR ',' f_marg_list
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
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
'|'
3404 |
'|' block_param opt_bv_decl
'|'
3415 opt_bv_decl : opt_nl
3419 | opt_nl
';' bv_decls opt_nl
3483 f_larglist :
'(' f_args opt_bv_decl
')'
3528 block_call : command do_block
3544 | block_call dot_or_colon operation2 opt_paren_args
3553 | block_call dot_or_colon operation2 opt_paren_args brace_block
3557 $5->nd_iter =
NEW_CALL($1, $3, $4);
3565 | block_call dot_or_colon operation2
command_args do_block
3569 $5->nd_iter =
NEW_CALL($1, $3, $4);
3579 method_call : fcall paren_args
3588 | primary_value
'.' operation2
3604 | primary_value
tCOLON2 operation2
3620 | primary_value
tCOLON2 operation3
3678 | primary_value
'[' opt_call_args rbracket
3770 exc_list : arg_value
3913 for (list = (prev = node)->
nd_next;
list; list = list->nd_next) {
3915 VALUE tail = list->nd_head->nd_lit;
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) {
3977 | word_list word
' '
3987 word : string_content
3995 | word string_content
4032 | symbol_list word
' '
4130 | string_contents string_content
4148 | xstring_contents string_content
4166 | regexp_contents string_content
4298 numeric : simple_numeric
4331 var_ref : user_variable
4354 var_lhs : user_variable
4405 f_arglist :
'(' f_args rparen
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");
4531 yyerror(
"formal argument cannot be an instance variable");
4540 yyerror(
"formal argument cannot be a global variable");
4549 yyerror(
"formal argument cannot be a class variable");
4557 f_norm_arg : f_bad_arg
4565 f_arg_item : f_norm_arg
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");
4833 yyerror(
"block argument must be local variable");
4835 yyerror(
"duplicated block argument name");
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");
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);
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__");
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
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;
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()) !=
'-') {
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()) !=
'-') {
5936 if (flags & ESCAPE_CONTROL)
goto eof;
5937 if ((c =
nextc()) !=
'-') {
5945 if (flags & ESCAPE_CONTROL)
goto eof;
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) {
6081 if (c2 ==
'$' || c2 ==
'@' || c2 ==
'{') {
6086 else if (c ==
'\\') {
6087 const char *beg =
lex_p - 1;
6092 if (func & STR_FUNC_EXPAND)
continue;
6101 if ((func & STR_FUNC_EXPAND) == 0) {
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) {
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) {
6431 mask &= ~NUM_SUFFIX_I;
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;
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) {
6570 if (parser->
eofp)
goto error;
6580 if ((c =
nextc()) == -1)
goto error;
6597 rb_warning0(
"ambiguous first argument; put parentheses or even spaces");
6602 #define arg_ambiguous() (arg_ambiguous_gen(parser), 1)
6609 yyerror(
"formal argument must be local variable");
6627 if (len > 5 && name[nlen = len - 5] ==
'-') {
6631 if (len > 4 && name[nlen = len - 4] ==
'-') {
6634 if (
rb_memcicmp(name + nlen + 1,
"mac", 3) == 0 &&
6635 !(len == 8 &&
rb_memcicmp(name,
"utf8-mac", len) == 0))
6650 excargs[1] =
rb_sprintf(
"unknown encoding name: %s", name);
6667 for (i = 0; i <
n; ++
i) {
6742 if (str[i-1] ==
'*' && str[i-2] ==
'-') {
6748 if (i + 1 >= len)
return 0;
6749 if (str[i+1] !=
'-') {
6752 else if (str[i-1] !=
'-') {
6770 VALUE name = 0, val = 0;
6771 const char *beg, *
end, *vbeg, *vend;
6772 #define str_copy(_s, _p, _n) ((_s) \
6773 ? (void)(rb_str_resize((_s), (_n)), \
6774 MEMCPY(RSTRING_PTR(_s), (_p), char, (_n)), (_s)) \
6775 : (void)((_s) = STR_NEW((_p), (_n))))
6777 if (len <= 7)
return FALSE;
6781 len = end - beg - 3;
6792 for (; len > 0 && *
str; str++, --
len) {
6794 case '\'':
case '"':
case ':':
case ';':
6799 for (beg = str; len > 0; str++, --
len) {
6801 case '\'':
case '"':
case ':':
case ';':
6809 for (end = str; len > 0 &&
ISSPACE(*str); str++, --
len);
6811 if (*str !=
':')
continue;
6813 do str++;
while (--len > 0 &&
ISSPACE(*str));
6816 for (vbeg = ++str; --len > 0 && *str !=
'"'; str++) {
6829 for (vbeg = str; len > 0 && *str !=
'"' && *str !=
';' && !
ISSPACE(*str); --
len, str++);
6832 while (len > 0 && (*str ==
';' ||
ISSPACE(*str))) --len, str++;
6837 for (i = 0; i <
n; ++
i) {
6838 if (s[i] ==
'-') s[
i] =
'_';
6845 n = (*p->
length)(parser, vbeg, n);
6851 }
while (++p < magic_comments +
numberof(magic_comments));
6865 const char *beg =
str;
6869 if (send - str <= 6)
return;
6871 case 'C':
case 'c': str += 6;
continue;
6872 case 'O':
case 'o': str += 5;
continue;
6873 case 'D':
case 'd': str += 4;
continue;
6874 case 'I':
case 'i': str += 3;
continue;
6875 case 'N':
case 'n': str += 2;
continue;
6876 case 'G':
case 'g': str += 1;
continue;
6890 if (++str >= send)
return;
6893 if (*str !=
'=' && *str !=
':')
return;
6898 while ((*str ==
'-' || *str ==
'_' ||
ISALNUM(*str)) && ++str < send);
6914 (
unsigned char)
lex_p[0] == 0xbb &&
6915 (
unsigned char)
lex_p[1] == 0xbf) {
6929 #define IS_ARG() IS_lex_state(EXPR_ARG_ANY)
6930 #define IS_END() IS_lex_state(EXPR_END_ANY)
6931 #define IS_BEG() IS_lex_state(EXPR_BEG_ANY)
6932 #define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c))
6933 #define IS_LABEL_POSSIBLE() ((IS_lex_state(EXPR_BEG | EXPR_ENDFN) && !cmd_state) || IS_ARG())
6934 #define IS_LABEL_SUFFIX(n) (peek_n(':',(n)) && !peek_n(':', (n)+1))
6935 #define IS_AFTER_OPERATOR() IS_lex_state(EXPR_FNAME | EXPR_DOT)
6938 #define ambiguous_operator(op, syn) ( \
6939 rb_warning0("`"op"' after local variable or literal is interpreted as binary operator"), \
6940 rb_warning0("even though it seems like "syn""))
6942 #define ambiguous_operator(op, syn) dispatch2(operator_ambiguous, ripper_intern(op), rb_str_new_cstr(syn))
6944 #define warn_balanced(op, syn) ((void) \
6945 (!IS_lex_state_for(last_state, EXPR_CLASS|EXPR_DOT|EXPR_FNAME|EXPR_ENDFN|EXPR_ENDARG) && \
6946 space_seen && !ISSPACE(c) && \
6947 (ambiguous_operator(op, syn), 0)))
6959 int fallthru =
FALSE;
6985 switch (c =
nextc()) {
6993 case ' ':
case '\t':
case '\f':
case '\r':
6997 while ((c =
nextc())) {
6999 case ' ':
case '\t':
case '\f':
case '\r':
7008 ripper_dispatch_scan_event(parser,
tSP);
7021 ripper_dispatch_scan_event(parser,
tCOMMENT);
7026 if (
IS_lex_state(EXPR_BEG | EXPR_VALUE | EXPR_CLASS | EXPR_FNAME | EXPR_DOT | EXPR_LABELARG)) {
7034 goto normal_newline;
7038 while ((c =
nextc())) {
7040 case ' ':
case '\t':
case '\f':
case '\r':
7045 if ((c =
nextc()) !=
'.') {
7058 parser->tokp =
lex_p;
7061 goto normal_newline;
7070 if ((c =
nextc()) ==
'*') {
7071 if ((c =
nextc()) ==
'=') {
7078 rb_warning0(
"`**' interpreted as argument prefix");
7097 rb_warning0(
"`*' interpreted as argument prefix");
7145 ripper_dispatch_scan_event(parser,
tEMBDOC);
7154 if (c !=
'=')
continue;
7155 if (strncmp(
lex_p,
"end", 3) == 0 &&
7169 if ((c =
nextc()) ==
'=') {
7170 if ((c =
nextc()) ==
'=') {
7179 else if (c ==
'>') {
7191 (!
IS_ARG() || space_seen)) {
7193 if (token)
return token;
7204 if ((c =
nextc()) ==
'>') {
7211 if ((c =
nextc()) ==
'=') {
7225 if ((c =
nextc()) ==
'=') {
7229 if ((c =
nextc()) ==
'=') {
7297 rb_warnI(
"invalid character syntax; use ?\\%c", c2);
7314 else if (c ==
'\\') {
7343 if ((c =
nextc()) ==
'&') {
7345 if ((c =
nextc()) ==
'=') {
7353 else if (c ==
'=') {
7360 rb_warning0(
"`&' interpreted as argument prefix");
7374 if ((c =
nextc()) ==
'|') {
7376 if ((c =
nextc()) ==
'=') {
7456 if ((c =
nextc()) ==
'.') {
7457 if ((c =
nextc()) ==
'.') {
7465 yyerror(
"no .<digit> floating literal anymore; put 0 before dot");
7471 case '0':
case '1':
case '2':
case '3':
case '4':
7472 case '5':
case '6':
case '7':
case '8':
case '9':
7474 int is_float, seen_point, seen_e, nondigit;
7477 is_float = seen_point = seen_e = nondigit = 0;
7480 if (c ==
'-' || c ==
'+') {
7485 #define no_digits() do {yyerror("numeric literal without digits"); return 0;} while (0)
7488 if (c ==
'x' || c ==
'X') {
7494 if (nondigit)
break;
7501 }
while ((c =
nextc()) != -1);
7508 else if (nondigit)
goto trailing_uc;
7512 if (c ==
'b' || c ==
'B') {
7515 if (c ==
'0' || c ==
'1') {
7518 if (nondigit)
break;
7522 if (c !=
'0' && c !=
'1')
break;
7525 }
while ((c =
nextc()) != -1);
7532 else if (nondigit)
goto trailing_uc;
7536 if (c ==
'd' || c ==
'D') {
7542 if (nondigit)
break;
7549 }
while ((c =
nextc()) != -1);
7556 else if (nondigit)
goto trailing_uc;
7564 if (c ==
'o' || c ==
'O') {
7567 if (c == -1 || c ==
'_' || !
ISDIGIT(c)) {
7571 if (c >=
'0' && c <=
'7') {
7576 if (nondigit)
break;
7580 if (c < '0' || c >
'9')
break;
7581 if (c >
'7')
goto invalid_octal;
7584 }
while ((c =
nextc()) != -1);
7588 if (nondigit)
goto trailing_uc;
7597 if (c >
'7' && c <=
'9') {
7599 yyerror(
"Invalid octal digit");
7601 else if (c ==
'.' || c ==
'e' || c ==
'E') {
7613 case '0':
case '1':
case '2':
case '3':
case '4':
7614 case '5':
case '6':
case '7':
case '8':
case '9':
7620 if (nondigit)
goto trailing_uc;
7621 if (seen_point || seen_e) {
7626 if (c0 == -1 || !
ISDIGIT(c0)) {
7651 if (c !=
'-' && c !=
'+' && !
ISDIGIT(c)) {
7660 nondigit = (c ==
'-' || c ==
'+') ? c : 0;
7664 if (nondigit)
goto decode_num;
7679 snprintf(tmp,
sizeof(tmp),
"trailing `%c' in number", nondigit);
7688 if (suffix & NUM_SUFFIX_R) {
7689 char *point = &
tok()[seen_point];
7690 size_t fraclen =
toklen()-seen_point-1;
7692 memmove(point, point+1, fraclen+1);
7698 if (
errno == ERANGE) {
7776 if ((c =
nextc()) ==
'=') {
7796 if ((c =
nextc()) !=
'@') {
7823 if ((c =
nextc()) ==
']') {
7824 if ((c =
nextc()) ==
'=') {
7836 else if (
IS_ARG() && space_seen) {
7871 ripper_dispatch_scan_event(parser,
tSP);
7892 yyerror(
"unknown type of %string");
7896 if (c == -1 || term == -1) {
7901 if (term ==
'(') term =
')';
7902 else if (term ==
'[') term =
']';
7903 else if (term ==
'{') term =
'}';
7904 else if (term ==
'<') term =
'>';
7954 yyerror(
"unknown type of %string");
7958 if ((c =
nextc()) ==
'=') {
8034 case '1':
case '2':
case '3':
8035 case '4':
case '5':
case '6':
8036 case '7':
case '8':
case '9':
8041 }
while (c != -1 &&
ISDIGIT(c));
8087 ripper_dispatch_scan_event(parser,
k__END__);
8115 if ((c ==
'!' || c ==
'?') && !
peek(
'=')) {
8135 if (
tok()[1] ==
'@')
8204 if (kw->
id[0] != kw->
id[1])
8241 yylex(
void *lval,
void *p)
8255 if (!
NIL_P(parser->delayed)) {
8256 ripper_dispatch_delayed_token(parser, t);
8260 ripper_dispatch_scan_event(parser, t);
8302 if (orig == (
NODE*)1)
return;
8311 #define parser_warning(node, mesg) parser_warning(parser, (node), (mesg))
8318 #define parser_warn(node, mesg) parser_warn(parser, (node), (mesg))
8325 if (tail == 0)
return head;
8327 if (h == 0)
return tail;
8366 tail->nd_end =
tail;
8368 end->nd_next =
tail;
8369 h->nd_end = tail->nd_end;
8379 if (list == 0)
return NEW_LIST(item);
8380 if (list->nd_next) {
8381 last = list->nd_next->nd_end;
8389 list->nd_next->nd_end = last->nd_next;
8399 if (head->nd_next) {
8400 last = head->nd_next->nd_end;
8406 head->nd_alen += tail->nd_alen;
8407 last->nd_next =
tail;
8408 if (tail->nd_next) {
8409 head->nd_next->nd_end = tail->nd_next->nd_end;
8412 head->nd_next->nd_end =
tail;
8421 if (
NIL_P(tail))
return 1;
8442 if (!head)
return tail;
8443 if (!tail)
return head;
8453 if (htype ==
NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
8456 lit = headlast->nd_lit;
8479 tail->nd_lit = head->nd_lit;
8483 else if (
NIL_P(tail->nd_lit)) {
8485 head->nd_alen += tail->nd_alen - 1;
8486 head->nd_next->nd_end->nd_next = tail->nd_next;
8487 head->nd_next->nd_end = tail->nd_next->nd_end;
8490 else if (htype ==
NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
8492 lit = headlast->nd_lit;
8495 tail->nd_lit =
Qnil;
8500 tail->nd_head =
NEW_STR(tail->nd_lit);
8649 static const char names[][12] = {
8650 "EXPR_BEG",
"EXPR_END",
"EXPR_ENDARG",
"EXPR_ENDFN",
"EXPR_ARG",
8651 "EXPR_CMDARG",
"EXPR_MID",
"EXPR_FNAME",
"EXPR_DOT",
"EXPR_CLASS",
8656 return names[
ffs(state)];
8671 # define assignable_result(x) get_value(lhs)
8672 # define parser_yyerror(parser, x) dispatch1(assign_error, lhs)
8674 # define assignable_result(x) (x)
8679 yyerror(
"Can't change the value of self");
8682 yyerror(
"Can't assign to nil");
8685 yyerror(
"Can't assign to true");
8688 yyerror(
"Can't assign to false");
8691 yyerror(
"Can't assign to __FILE__");
8694 yyerror(
"Can't assign to __LINE__");
8697 yyerror(
"Can't assign to __ENCODING__");
8731 yyerror(
"dynamic constant assignment");
8740 #undef assignable_result
8741 #undef parser_yyerror
8748 if (name == idUScore)
return 1;
8755 #define LVAR_USED ((ID)1 << (sizeof(ID) * CHAR_BIT - 1))
8763 yyerror(
"duplicated argument name");
8776 yyerror(
"duplicated argument name");
8841 int scope = (
int)(
id & ID_SCOPE_MASK);
8850 id_type_names[scope],
ID2SYM(
id));
8854 id &= ~ID_SCOPE_MASK;
8883 if (!node2)
return node1;
8887 node1->nd_head =
arg_concat(node1->nd_head, node2);
8899 node1->nd_body =
list_concat(node1->nd_body, node2);
8908 if (!node1)
return NEW_LIST(node2);
8913 node1->nd_head =
arg_append(node1->nd_head, node2);
8946 lhs->nd_value = rhs;
8951 lhs->nd_args =
arg_append(lhs->nd_args, rhs);
8977 if (!cond)
yyerror(
"void value expression");
8982 while (node->nd_next) {
8983 node = node->nd_next;
8985 node = node->nd_head;
8989 node = node->nd_body;
8993 if (!node->nd_body) {
8994 node = node->nd_else;
8997 else if (!node->nd_else) {
8998 node = node->nd_body;
9002 node = node->nd_else;
9008 node = node->nd_2nd;
9022 const char *useless = 0;
9029 switch (node->nd_mid) {
9060 useless =
"a variable";
9063 useless =
"a constant";
9070 useless =
"a literal";
9095 useless =
"defined?";
9103 rb_warnS(
"possibly useless use of %s in void context", useless);
9116 if (!node->nd_next)
return;
9118 node = node->nd_next;
9125 NODE **n = &node, *n1 = node;
9127 *n = n1 = n1->nd_body;
9135 NODE **n = &node, *n1 = node;
9137 *n = n1 = n1->nd_body;
9151 #define subnodes(n1, n2) \
9152 ((!node->n1) ? (node->n2 ? (body = &node->n2, 1) : 0) : \
9153 (!node->n2) ? (body = &node->n1, 1) : \
9154 (reduce_nodes(&node->n1), body = &node->n2, 1))
9164 *body = node = node->nd_stts;
9168 *body = node = node->nd_body;
9172 body = &node->nd_end->nd_head;
9178 body = &node->nd_body;
9187 if (node->nd_else) {
9188 body = &node->nd_resq;
9206 if (!node)
return 1;
9209 if (!(node = node->nd_head))
break;
9213 }
while ((node = node->nd_next) != 0);
9232 yyerror(
"multiple assignment in conditional");
9246 if (!node->nd_value)
return 1;
9249 parser_warn(node->nd_value,
"found = in conditional, should be ==");
9271 for (node = *rootnode; node; node = next) {
9275 next = node->nd_next;
9276 head = node->nd_head;
9279 switch (type =
nd_type(head)) {
9282 val =
rb_range_new(head->nd_beg->nd_lit, head->nd_end->nd_lit,
9302 if (node == 0)
return 0;
9310 return cond0(parser, node);
9316 if (!node)
return 1;
9337 if (node == 0)
return 0;
9344 rb_warn0(
"string literal in condition");
9354 node->nd_1st =
cond0(parser, node->nd_1st);
9355 node->nd_2nd =
cond0(parser, node->nd_2nd);
9360 node->nd_beg =
range_op(parser, node->nd_beg);
9361 node->nd_end =
range_op(parser, node->nd_end);
9394 if (node == 0)
return 0;
9395 return cond0(parser, node);
9403 NODE *node = left, *second;
9404 while ((second = node->nd_2nd) != 0 && (
enum node_type)
nd_type(second) == type) {
9407 node->nd_2nd =
NEW_NODE(type, second, right, 0);
9410 return NEW_NODE(type, left, right, 0);
9427 if (node->nd_next == 0) {
9428 node = node->nd_head;
9449 switch (
TYPE(node->nd_lit)) {
9471 rb_bug(
"unknown literal type passed to negate_lit");
9481 node2->nd_head = node1;
9495 args->
pre_init = m ? m->nd_next : 0;
9532 kw_rest_arg->nd_cflag =
check;
9573 ID vid = lhs->nd_vid;
9575 lhs->nd_value = rhs;
9582 lhs->nd_value = rhs;
9636 return dispatch3(opassign, lhs, op, rhs);
9642 VALUE recv = dispatch3(field, lhs, type, attr);
9643 return dispatch3(opassign, recv, op, rhs);
9653 if (!local->
used)
return;
9657 if (cnt != local->
vars->
pos) {
9658 rb_bug(
"local->used->pos != local->vars->pos");
9660 for (i = 0; i <
cnt; ++
i) {
9661 if (!v[i] || (u[i] &
LVAR_USED))
continue;
9676 local->
used = !(inherit_dvars &&
9705 int cnt = cnt_args + cnt_vars;
9709 if (cnt <= 0)
return 0;
9713 for (i = 0, j = cnt_args+1; i < cnt_vars; ++
i) {
9754 if (used) used = used->
prev;
9770 static const struct vtable *
9786 if ((tmp =
lvtbl->used) != 0) {
9802 while (
lvtbl->args != lvargs) {
9840 if (used) used = used->
prev;
9893 "regexp encoding option '%c' differs from source encoding '%s'",
9921 int back_num,
int *back_refs,
OnigRegex regex,
void *arg0)
9926 long len = name_end -
name;
9927 const char *s = (
const char *)name;
9944 rb_warningS(
"named capture conflicts a local variable - %s",
10024 NODE *scope = node;
10027 if (!node)
return node;
10031 node = node->nd_body;
10035 node = node->nd_body;
10042 prelude->nd_body = node;
10043 scope->nd_body = prelude;
10046 scope->nd_body = node;
10056 NODE *scope = node;
10059 if (!node)
return node;
10063 node = node->nd_body;
10067 node = node->nd_body;
10083 prelude->nd_body = node;
10084 scope->nd_body = prelude;
10087 scope->nd_body = node;
10093 static const struct {
10118 #define op_tbl_count numberof(op_tbl)
10120 #ifndef ENABLE_SELECTOR_NAMESPACE
10121 #define ENABLE_SELECTOR_NAMESPACE 0
10128 #if ENABLE_SELECTOR_NAMESPACE
10141 #if ENABLE_SELECTOR_NAMESPACE
10148 ivar2_cmp(
struct ivar2_key *key1,
struct ivar2_key *key2)
10150 if (key1->id == key2->id && key1->klass == key2->klass) {
10157 ivar2_hash(
struct ivar2_key *
key)
10159 return (key->id << 8) ^ (key->klass >> 2);
10173 #if ENABLE_SELECTOR_NAMESPACE
10181 (
void)lex_state_name(-1);
10214 if (m >= e)
return 0;
10218 else if (*m ==
'-') {
10219 if (++m >= e)
return 0;
10232 return m == e ? mb + 1 : 0;
10247 #define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
10248 #define IDSET_ATTRSET_FOR_INTERN (~(~0U<<ID_SCOPE_MASK) & ~(1U<<ID_ATTRSET))
10253 const char *m =
name;
10254 const char *e = m +
len;
10257 if (!m || len <= 0)
return -1;
10277 case '<': ++
m;
break;
10278 case '=':
if (*++m ==
'>') ++
m;
break;
10285 case '>':
case '=': ++
m;
break;
10291 case '~': ++
m;
break;
10292 case '=':
if (*++m ==
'=') ++
m;
break;
10293 default:
return -1;
10298 if (*++m ==
'*') ++
m;
10301 case '+':
case '-':
10302 if (*++m ==
'@') ++
m;
10305 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
10310 if (*++m !=
']')
return -1;
10311 if (*++m ==
'=') ++
m;
10315 if (len == 1)
return ID_JUNK;
10317 case '=':
case '~': ++
m;
break;
10318 default:
return -1;
10330 case '!':
case '?':
10336 if (!(allowed_attrset & (1
U << type)))
return -1;
10343 return m == e ? type : -1;
10411 fake_str->
as.
heap.ptr = (
char *)name;
10413 return (
VALUE)fake_str;
10435 const char *
name, *
m, *
e;
10457 if (len < 2)
goto junk;
10466 if (len < 3)
goto junk;
10471 if (len < 2)
goto junk;
10487 if (*
op_tbl[i].name == *m &&
10488 strcmp(
op_tbl[i].name, m) == 0) {
10496 if (name[last] ==
'=') {
10498 if (last > 1 && name[last-1] ==
'=')
10508 else if (
id == 0) {
10580 name[0] = (char)
id;
10591 if (
op_tbl[i].token ==
id) {
10607 if (
RBASIC(str)->klass == 0)
10613 ID id_stem = (
id & ~ID_SCOPE_MASK);
10630 if (
RBASIC(str)->klass == 0)
10643 if (!str)
return 0;
10737 VALUE name = *namep;
10788 fake_str.
as.
heap.len = len - 1;
10888 parser->delayed =
Qnil;
10890 parser->result =
Qnil;
10891 parser->parsing_thread =
Qnil;
10892 parser->toplevel_p =
TRUE;
10901 #define parser_mark ripper_parser_mark
10902 #define parser_free ripper_parser_free
10942 prev = local->
prev;
10953 size_t size =
sizeof(*p);
10955 if (!ptr)
return 0;
10958 size +=
sizeof(*local);
10979 #undef rb_reserved_word
11068 #define HEAPCNT(n, size) ((n) * (size) / sizeof(YYSTYPE))
11069 #define NEWHEAP() rb_node_newnode(NODE_ALLOCA, 0, (VALUE)parser->heap, 0)
11070 #define ADD2HEAP(n, c, p) ((parser->heap = (n))->u1.node = (p), \
11071 (n)->u3.cnt = (c), (p))
11076 size_t cnt =
HEAPCNT(1, size);
11086 size_t cnt =
HEAPCNT(nelem, size);
11088 void *ptr =
xcalloc(nelem, size);
11097 size_t cnt =
HEAPCNT(1, size);
11099 if (ptr && (n = parser->
heap) !=
NULL) {
11101 if (n->
u1.
node == ptr) {
11118 while ((n = *prev) !=
NULL) {
11119 if (n->
u1.
node == ptr) {
11132 #ifdef RIPPER_DEBUG
11133 extern int rb_is_pointer_to_heap(
VALUE);
11139 if (x ==
Qfalse)
return x;
11140 if (x ==
Qtrue)
return x;
11141 if (x ==
Qnil)
return x;
11146 if (!rb_is_pointer_to_heap(x))
11161 return ((
NODE *)x)->nd_rval;
11170 #define validate(x) ((x) = get_value(x))
11182 return rb_funcall(parser->value, mid, 1, a);
11190 return rb_funcall(parser->value, mid, 2, a, b);
11199 return rb_funcall(parser->value, mid, 3, a, b, c);
11209 return rb_funcall(parser->value, mid, 4, a, b, c, d);
11220 return rb_funcall(parser->value, mid, 5, a, b, c, d, e);
11233 return rb_funcall(parser->value, mid, 7, a, b, c, d, e, f, g);
11236 static const struct kw_assoc {
11239 } keyword_to_name[] = {
11292 keyword_id_to_str(
ID id)
11294 const struct kw_assoc *
a;
11296 for (a = keyword_to_name; a->id; a++) {
11303 #undef ripper_id2sym
11305 ripper_id2sym(
ID id)
11315 if ((name = keyword_id_to_str(
id))) {
11328 rb_bug(
"cannot convert ID to string: %ld", (
unsigned long)
id);
11336 ripper_get_id(
VALUE v)
11346 ripper_get_value(
VALUE v)
11353 return nd->nd_rval;
11362 va_start(args, fmt);
11369 ripper_warn0(
struct parser_params *parser,
const char *fmt)
11375 ripper_warnI(
struct parser_params *parser,
const char *fmt,
int a)
11382 ripper_warnS(
struct parser_params *parser,
const char *fmt,
const char *str)
11389 ripper_warning0(
struct parser_params *parser,
const char *fmt)
11395 ripper_warningS(
struct parser_params *parser,
const char *fmt,
const char *str)
11420 #define ripper_initialized_p(r) ((r)->parser_lex_input != 0)
11439 rb_scan_args(argc, argv,
"12", &src, &fname, &lineno);
11449 if (
NIL_P(fname)) {
11464 struct ripper_args {
11471 ripper_parse0(
VALUE parser_v)
11477 ripper_yyparse((
void*)parser);
11478 return parser->result;
11482 ripper_ensure(
VALUE parser_v)
11487 parser->parsing_thread =
Qnil;
11498 ripper_parse(
VALUE self)
11503 if (!ripper_initialized_p(parser)) {
11506 if (!
NIL_P(parser->parsing_thread)) {
11513 rb_ensure(ripper_parse0,
self, ripper_ensure,
self);
11515 return parser->result;
11526 ripper_column(
VALUE self)
11532 if (!ripper_initialized_p(parser)) {
11535 if (
NIL_P(parser->parsing_thread))
return Qnil;
11547 ripper_filename(
VALUE self)
11552 if (!ripper_initialized_p(parser)) {
11566 ripper_lineno(
VALUE self)
11571 if (!ripper_initialized_p(parser)) {
11574 if (
NIL_P(parser->parsing_thread))
return Qnil;
11578 #ifdef RIPPER_DEBUG
11614 InitVM_ripper(
void)
11631 #ifdef RIPPER_DEBUG
#define rb_enc_islower(c, enc)
char * parser_ruby_sourcefile
#define RB_TYPE_P(obj, type)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
#define NEW_ARGSCAT(a, b)
VALUE rb_const_get_at(VALUE, ID)
struct local_vars * parser_lvtbl
VALUE rb_ary_unshift(VALUE ary, VALUE item)
static ID ripper_token2eventid(int tok)
#define rb_warn4S(file, line, fmt, a)
static NODE * match_op_gen(struct parser_params *, NODE *, NODE *)
int rb_is_attrset_id(ID id)
int rb_enc_codelen(int c, rb_encoding *enc)
#define RE_OPTION_ENCODING(e)
static struct parser_params * parser_new(void)
int onig_foreach_name(regex_t *reg, int(*func)(const UChar *, const UChar *, int, int *, regex_t *, void *), void *arg)
st_table * st_init_table_with_size(const struct st_hash_type *, st_index_t)
#define NEW_IASGN(v, val)
VALUE rb_get_coverages(void)
#define dvar_defined_get(id)
#define RE_OPTION_ENCODING_IDX(o)
#define IDSET_ATTRSET_FOR_SYNTAX
#define STR_NEW3(p, n, e, func)
void rb_bug(const char *fmt,...)
#define NEW_DASGN_CURR(v, val)
static NODE * reg_named_capture_assign_gen(struct parser_params *parser, VALUE regexp, NODE *match)
#define ADD2HEAP(n, c, p)
void rb_enc_copy(VALUE obj1, VALUE obj2)
#define attrset(node, id)
void rb_mark_tbl(struct st_table *)
int rb_is_class_name(VALUE name)
NODE * rb_parser_compile_file(volatile VALUE vparser, const char *f, VALUE file, int start)
static int comment_at_top(struct parser_params *parser)
#define new_args(f, o, r, p, t)
#define rb_gc_mark_locations(start, end)
size_t strlen(const char *)
static size_t parser_memsize(const void *ptr)
VALUE parser_lex_nextline
VALUE rb_make_exception(int argc, VALUE *argv)
#define whole_match_p(e, l, i)
#define scan_oct(s, l, e)
const char * rb_obj_classname(VALUE)
static void local_push_gen(struct parser_params *, int)
static NODE * node_assign_gen(struct parser_params *, NODE *, NODE *)
#define list_concat(h, t)
int parser_ruby__end__seen
static int local_var_gen(struct parser_params *, ID)
static void fixpos(NODE *, NODE *)
static int parser_yyerror(struct parser_params *, const char *)
#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)
VALUE rb_str_buf_append(VALUE, VALUE)
struct RString::@95::@96 heap
static int parser_tokadd_utf8(struct parser_params *parser, rb_encoding **encp, int string_literal, int symbol_literal, int regexp_literal)
int parser_compile_for_eval
int parser_token_info_enabled
static NODE * node_newnode(struct parser_params *, enum node_type, VALUE, VALUE, VALUE)
#define NEW_OP_CDECL(v, op, val)
VALUE rb_rational_new(VALUE, VALUE)
#define IS_LABEL_SUFFIX(n)
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
SSL_METHOD *(* func)(void)
static void parser_heredoc_restore(struct parser_params *parser, NODE *here)
#define rb_usascii_str_new2
#define call_uni_op(recv, id)
void rb_define_global_const(const char *, VALUE)
void rb_gc_force_recycle(VALUE)
RUBY_EXTERN void * memmove(void *, const void *, size_t)
static struct symbols global_symbols
VALUE rb_parser_end_seen_p(VALUE vparser)
struct token_info token_info
#define literal_concat(h, t)
stack_type parser_cmdarg_stack
static NODE * parser_compile_string(volatile VALUE vparser, VALUE fname, VALUE s, int line)
#define new_op_assign(lhs, op, rhs)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
#define token_info_push(token)
#define rb_enc_isalnum(c, enc)
static int parser_here_document(struct parser_params *, NODE *)
static NODE * arg_append_gen(struct parser_params *, NODE *, NODE *)
#define new_defined(expr)
static NODE * new_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs)
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)
#define rb_enc_prev_char(s, p, e, enc)
VALUE rb_ary_push(VALUE ary, VALUE item)
static int reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end, int back_num, int *back_refs, OnigRegex regex, void *arg0)
static void warn_unused_var(struct parser_params *parser, struct local_vars *local)
#define new_args_tail(k, kr, b)
static NODE * new_args_tail_gen(struct parser_params *, NODE *, ID, ID)
rb_encoding * rb_enc_compatible(VALUE str1, VALUE str2)
#define NEW_MATCH2(n1, n2)
VALUE op_sym[tLAST_OP_ID]
VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
#define warn_balanced(op, syn)
#define parser_precise_mbclen()
#define shadowing_lvar(name)
#define is_identchar(p, e, enc)
static NODE * arg_blk_pass(NODE *, NODE *)
static void reg_fragment_setenc_gen(struct parser_params *, VALUE, int)
#define mixed_error(enc1, enc2)
static void ripper_init_eventids1_table(VALUE self)
void rb_raise(VALUE exc, const char *fmt,...)
#define mixed_escape(beg, enc1, enc2)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
void rb_compile_warn(const char *file, int line, const char *fmt,...)
static NODE * range_op(struct parser_params *parser, NODE *node)
primary_value operation2 command_args prec tLOWEST
#define set_yylval_node(x)
static NODE * new_yield_gen(struct parser_params *, NODE *)
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
static void parser_pushback(struct parser_params *parser, int c)
#define is_attrset_id(id)
#define formal_argument(id)
void(* rb_magic_comment_setter_t)(struct parser_params *parser, const char *name, const char *val)
#define heredoc_restore(n)
static void reduce_nodes_gen(struct parser_params *, NODE **)
#define rb_warningS(fmt, a)
static struct vtable * dyna_push_gen(struct parser_params *)
#define NEW_CVASGN(v, val)
static int parser_whole_match_p(struct parser_params *parser, const char *eos, long len, int indent)
VALUE rb_int_positive_pow(long x, unsigned long y)
#define reg_compile(str, options)
#define NEW_OP_ASGN_OR(i, val)
static void parser_initialize(struct parser_params *parser)
#define ENCODING_IS_ASCII8BIT(obj)
static VALUE parse(int argc, VALUE *argv, VALUE self)
ID rb_check_id(volatile VALUE *namep)
Returns ID for the given name if it is interned already, or 0.
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
rb_encoding * rb_utf8_encoding(void)
static long parser_encode_length(struct parser_params *parser, const char *name, long len)
#define rb_enc_isdigit(c, enc)
static enum node_type nodetype(NODE *node)
#define ENC_CODERANGE_BROKEN
VALUE rb_sym_all_symbols(void)
static VALUE lex_getline(struct parser_params *parser)
static NODE * call_uni_op_gen(struct parser_params *, NODE *, ID)
VALUE rb_str_new_frozen(VALUE)
#define RUBY_DTRACE_PARSE_BEGIN(arg0, arg1)
#define assignable_result(x)
VALUE parser_ruby_sourcefile_string
#define NEW_CLASS(n, b, s)
static int literal_concat0(struct parser_params *, VALUE, VALUE)
static NODE * assignable_gen(struct parser_params *, ID, NODE *)
#define list_append(l, i)
int rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
static NODE * yycompile(struct parser_params *parser, VALUE fname, int line)
VALUE rb_parser_set_yydebug(VALUE self, VALUE flag)
#define NEW_PRELUDE(p, b)
#define block_dup_check(n1, n2)
static NODE * evstr2dstr_gen(struct parser_params *, NODE *)
#define match_op(node1, node2)
#define ENCODING_GET(obj)
#define set_yylval_num(x)
NODE * parser_deferred_nodes
static int simple_re_meta(int c)
void rb_name_error(ID id, const char *fmt,...)
static int e_option_supplied(struct parser_params *parser)
#define nd_set_type(n, t)
static NODE * list_append_gen(struct parser_params *, NODE *, NODE *)
static int assign_in_cond(struct parser_params *parser, NODE *node)
#define MEMZERO(p, type, n)
void rb_exc_raise(VALUE mesg)
#define NEW_UNLESS(c, t, e)
VALUE rb_usascii_str_new(const char *, long)
static rb_encoding * must_be_ascii_compatible(VALUE s)
int rb_is_const_id(ID id)
int rb_is_instance_id(ID id)
#define RUBY_DTRACE_PARSE_END(arg0, arg1)
static int parser_number_literal_suffix(struct parser_params *parser, int mask)
static int parser_tokadd_string(struct parser_params *, int, int, int, long *, rb_encoding **)
static NODE * remove_begin(NODE *)
int rb_is_method_name(VALUE name)
static VALUE coverage(VALUE fname, int n)
#define NEW_OP_ASGN_AND(i, val)
static NODE * gettable_gen(struct parser_params *, ID)
static NODE * dsym_node_gen(struct parser_params *, NODE *)
static int parser_regx_options(struct parser_params *)
enum lex_state_e parser_lex_state
VALUE parser_lex_lastline
static NODE * newline_node(NODE *)
NODE * rb_parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
static int parser_yylex(struct parser_params *parser)
static VALUE parser_str_new(const char *p, long n, rb_encoding *enc, int func, rb_encoding *enc0)
#define scan_hex(s, l, e)
#define rb_intern_str(string)
int rb_char_to_option_kcode(int c, int *option, int *kcode)
static char * parser_tokspace(struct parser_params *parser, int n)
static NODE * cond_gen(struct parser_params *, NODE *)
#define TypedData_Get_Struct(obj, type, data_type, sval)
void rb_compile_error_append(const char *fmt,...)
void rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt,...)
static void parser_free(void *ptr)
#define StringValuePtr(v)
#define parser_warning(node, mesg)
static void vtable_add(struct vtable *tbl, ID id)
static int symbols_i(VALUE sym, ID value, VALUE ary)
const rb_data_type_t * parent
#define NEW_RESCUE(b, res, e)
static int parser_tokadd_escape(struct parser_params *parser, rb_encoding **encp)
VALUE rb_parser_encoding(VALUE vparser)
struct parser_params * parser
#define NEW_NODE(t, a0, a1, a2)
#define NEW_ENSURE(b, en)
RUBY_EXTERN VALUE rb_mKernel
static NODE * attrset_gen(struct parser_params *, NODE *, ID)
NODE * rb_compile_string(const char *f, VALUE s, int line)
#define RARRAY_AREF(a, i)
static int dvar_curr_gen(struct parser_params *, ID)
#define dispatch_heredoc_end()
static char * parser_newtok(struct parser_params *parser)
#define heredoc_identifier()
void rb_define_const(VALUE, const char *, VALUE)
#define SPECIAL_PUNCT(idx)
#define NEW_WHEN(c, t, e)
top_stmt escape_Qundef($1)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static void parser_set_token_info(struct parser_params *parser, const char *name, const char *val)
static struct st_hash_type symhash
#define call_bin_op(recv, id, arg1)
static NODE * call_bin_op_gen(struct parser_params *, NODE *, ID, NODE *)
static void parser_tokadd(struct parser_params *parser, int c)
#define ruby_eval_tree_begin
static void parser_mark(void *ptr)
#define ruby_sourcefile_string
#define MBCLEN_CHARFOUND_P(ret)
NODE * rb_parser_append_print(VALUE vparser, NODE *node)
#define nd_set_line(n, l)
#define RE_OPTION_ENCODING_NONE(o)
static void ripper_init_eventids1(void)
#define NEW_ARGS_AUX(r, b)
#define TypedData_Wrap_Struct(klass, data_type, sval)
static VALUE lex_get_str(struct parser_params *parser, VALUE s)
#define RUBY_FUNC_EXPORTED
unsigned char buf[MIME_BUF_SIZE]
VALUE rb_suppress_tracing(VALUE(*func)(VALUE), VALUE arg)
static NODE * block_append_gen(struct parser_params *, NODE *, NODE *)
VALUE rb_enc_associate_index(VALUE obj, int idx)
int rb_parse_in_main(void)
static int parser_nextc(struct parser_params *parser)
const char * parser_lex_pend
static void block_dup_check_gen(struct parser_params *, NODE *, NODE *)
#define ALLOCA_N(type, n)
static int local_id_gen(struct parser_params *, ID)
#define rb_backref_error(n)
#define ENC_CODERANGE_UNKNOWN
static ID intern_str(VALUE str)
NODE * rb_parser_while_loop(VALUE vparser, NODE *node, int chop, int split)
static void rb_backref_error_gen(struct parser_params *, NODE *)
NODE * rb_compile_cstr(const char *f, const char *s, int len, int line)
token_info * parser_token_info
static int lvar_defined_gen(struct parser_params *, ID)
static void magic_comment_encoding(struct parser_params *parser, const char *name, const char *val)
#define parser_is_identchar()
VALUE rb_str_buf_cat(VALUE, const char *, long)
void * rb_parser_malloc(struct parser_params *parser, size_t size)
static VALUE setup_fake_str(struct RString *fake_str, const char *name, long len)
static NODE * new_attr_op_assign_gen(struct parser_params *parser, NODE *lhs, ID attr, ID op, NODE *rhs)
static int parser_peek_variable_name(struct parser_params *parser)
#define NEW_LASGN(v, val)
static VALUE yycompile0(VALUE arg)
VALUE rb_obj_as_string(VALUE)
#define NEW_OPT_ARG(i, v)
int rb_dvar_defined(ID id)
static int arg_var_gen(struct parser_params *, ID)
static NODE * remove_begin_all(NODE *)
static void dispose_string(VALUE str)
VALUE rb_str_resize(VALUE, long)
static int reg_fragment_check_gen(struct parser_params *, VALUE, int)
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
#define RUBY_DTRACE_PARSE_END_ENABLED()
#define node_assign(node1, node2)
#define set_yylval_name(x)
#define rb_rational_raw1(x)
int rb_symname_p(const char *name)
VALUE rb_thread_current(void)
static int shadowing_lvar_0(struct parser_params *parser, ID name)
mlhs_head tSTAR mlhs_node
#define token_info_pop(token)
#define rb_ascii8bit_encindex()
VALUE rb_range_new(VALUE, VALUE, int)
VALUE rb_sprintf(const char *format,...)
#define rb_enc_mbcput(c, buf, enc)
static ID formal_argument_gen(struct parser_params *, ID)
#define set_integer_literal(v, f)
#define rb_node_newnode(type, a1, a2, a3)
#define RUBY_TYPED_FREE_IMMEDIATELY
keyword_super command_args
static void set_file_encoding(struct parser_params *parser, const char *str, const char *send)
static NODE * ret_args_gen(struct parser_params *, NODE *)
static NODE * new_const_op_assign_gen(struct parser_params *parser, NODE *lhs, ID op, NODE *rhs)
int rb_is_attrset_name(VALUE name)
#define NEW_DASGN(v, val)
#define read_escape(flags, e)
int rb_enc_symname_p(const char *name, rb_encoding *enc)
#define NEW_POSTARG(i, v)
#define CONST_ID(var, str)
static void local_pop_gen(struct parser_params *)
static int parser_parse_string(struct parser_params *, NODE *)
static NODE * literal_concat_gen(struct parser_params *, NODE *, NODE *)
static void void_expr_gen(struct parser_params *, NODE *)
int rb_is_local_id(ID id)
static NODE * negate_lit(NODE *)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static int dyna_in_block_gen(struct parser_params *)
static void fixup_nodes(NODE **)
#define NEW_STRTERM(func, term, paren)
static void Init_id(void)
rb_encoding * rb_usascii_encoding(void)
#define reg_named_capture_assign(regexp, match)
void rb_gc_mark_symbols(int full_mark)
static void arg_ambiguous_gen(struct parser_params *parser)
#define RBASIC_SET_CLASS_RAW(obj, cls)
static void parser_prepare(struct parser_params *parser)
static int rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset)
#define rb_reserved_word(str, len)
#define NEW_UNTIL(c, b, n)
#define NEW_MATCH3(r, n2)
VALUE rb_str_buf_new(long)
stack_type parser_cond_stack
static void ripper_init_eventids2(void)
int rb_const_defined_at(VALUE, ID)
static void dyna_pop_1(struct parser_params *parser)
static int parser_read_escape(struct parser_params *parser, int flags, rb_encoding **encp)
static void new_bv_gen(struct parser_params *, ID)
static int parser_heredoc_identifier(struct parser_params *parser)
#define str_copy(_s, _p, _n)
rb_hash_aset(hash, RARRAY_AREF(key_value_pair, 0), RARRAY_AREF(key_value_pair, 1))
static int rb_str_symname_type(VALUE name, unsigned int allowed_attrset)
int rb_is_global_id(ID id)
VALUE rb_attr_get(VALUE, ID)
#define rb_enc_ispunct(c, enc)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
#define NEW_RESBODY(a, ex, n)
static struct @92 op_tbl[]
#define is_instance_id(id)
#define set_yylval_str(x)
VALUE rb_reg_check_preprocess(VALUE)
expr ripper_intern("and")
static int is_static_content(NODE *node)
static ID shadowing_lvar_gen(struct parser_params *, ID)
static NODE * arg_concat_gen(struct parser_params *, NODE *, NODE *)
RUBY_EXTERN VALUE rb_cString
#define RUBY_DTRACE_PARSE_BEGIN_ENABLED()
mlhs_head tSTAR mlhs_post
static int is_global_name_punct(const int c)
#define reg_fragment_setenc(str, options)
VALUE rb_vsprintf(const char *, va_list)
#define MEMCPY(p1, p2, type, n)
mlhs_node keyword_variable
block_command cmd_brace_block
static void vtable_free(struct vtable *tbl)
#define logop(type, node1, node2)
#define NEW_GASGN(v, val)
static void warning_unless_e_option(struct parser_params *parser, NODE *node, const char *str)
#define NEW_ARGSPUSH(a, b)
int rb_is_const_name(VALUE name)
static void parser_tokaddmbc(struct parser_params *parser, int c, rb_encoding *enc)
int rb_is_local_name(VALUE name)
static NODE * logop_gen(struct parser_params *, enum node_type, NODE *, NODE *)
#define assignable(id, node)
VALUE rb_str_cat(VALUE, const char *, long)
#define ENC_CODERANGE_7BIT
rb_encoding * rb_enc_get(VALUE obj)
#define NEW_WHILE(c, b, n)
#define NEW_DEFS(r, i, a, d)
void rb_gc_mark_parser(void)
static int is_private_local_id(ID name)
#define IS_lex_state_for(x, ls)
static void no_blockarg(struct parser_params *parser, NODE *node)
void rb_parser_free(struct parser_params *parser, void *ptr)
static struct magic_comment magic_comments[]
void rb_set_errinfo(VALUE err)
#define rb_enc_isspace(c, enc)
static ID register_symid_str(ID, VALUE)
NODE * parser_lex_strterm
top_stmts dispatch0(stmts_new)
#define RUBY_DTRACE_SYMBOL_CREATE_ENABLED()
#define NEW_ATTRASGN(r, m, a)
VALUE rb_complex_raw(VALUE x, VALUE y)
#define aryset(node1, node2)
static int token_info_get_column(struct parser_params *parser, const char *token)
#define new_const_op_assign(lhs, op, rhs)
static NODE * new_evstr_gen(struct parser_params *, NODE *)
static int token_info_has_nonspaces(struct parser_params *parser, const char *token)
st_index_t rb_str_hash(VALUE)
#define NEW_OP_ASGN2(r, i, o, val)
static const rb_data_type_t parser_data_type
static int value_expr_gen(struct parser_params *, NODE *)
void rb_compile_warning(const char *file, int line, const char *fmt,...)
RUBY_EXTERN VALUE rb_cObject
static int vtable_included(const struct vtable *tbl, ID id)
static int parser_set_integer_literal(struct parser_params *parser, VALUE v, int suffix)
static VALUE lex_io_gets(struct parser_params *parser, VALUE io)
static NODE * splat_array(NODE *)
struct rb_encoding_entry * list
void * rb_parser_calloc(struct parser_params *parser, size_t nelem, size_t size)
#define STRNCASECMP(s1, s2, n)
VALUE rb_make_backtrace(void)
#define flush_string_content(enc)
static NODE * aryset_gen(struct parser_params *, NODE *, NODE *)
static int dvar_defined_gen(struct parser_params *, ID, int)
#define block_append(h, t)
static const char * magic_comment_marker(const char *str, long len)
#define NEW_OP_ASGN1(p, id, a)
#define is_asgn_or_id(id)
static int parser_magic_comment(struct parser_params *parser, const char *str, long len)
#define RUBY_DTRACE_SYMBOL_CREATE(arg0, arg1, arg2)
static const char id_type_names[][9]
VALUE rb_str_new(const char *, long)
const char * parser_lex_pbeg
int rb_is_class_id(ID id)
VALUE rb_parser_new(void)
struct parser_params * parser
static VALUE reg_compile_gen(struct parser_params *, VALUE, int)
static void parser_set_encode(struct parser_params *parser, const char *name)
#define NEW_CDECL(v, val, path)
static int literal_node(NODE *node)
const char * parser_lex_p
static int parser_tok_hex(struct parser_params *parser, size_t *numlen)
#define rb_enc_asciicompat(enc)
int rb_is_instance_name(VALUE name)
int parser_ruby_sourceline
const char * rb_id2name(ID id)
#define lex_goto_eol(parser)
#define rb_enc_isupper(c, enc)
static int nodeline(NODE *node)
#define new_attr_op_assign(lhs, type, attr, op, rhs)
#define RBASIC_CLEAR_CLASS(obj)
#define rb_enc_isascii(c, enc)
int rb_str_hash_cmp(VALUE, VALUE)
NODE * rb_parser_compile_string_path(volatile VALUE vparser, VALUE f, VALUE s, int line)
#define tokaddmbc(c, enc)
static NODE * cond0(struct parser_params *, NODE *)
rb_encoding * rb_ascii8bit_encoding(void)
int rb_is_junk_name(VALUE name)
int rb_enc_find_index(const char *name)
RUBY_FUNC_EXPORTED const unsigned int ruby_global_name_punct_bits[(0x7e-0x20+31)/32]
#define set_number_literal(v, t, f)
#define RSTRING_GETMEM(str, ptrvar, lenvar)
ID rb_intern3(const char *name, long len, rb_encoding *enc)
expr expr keyword_or expr
static ID register_symid(ID, const char *, long, rb_encoding *)
#define NEW_DEFN(i, a, d, p)
static NODE * new_args_gen(struct parser_params *, NODE *, NODE *, ID, NODE *, NODE *)
#define RARRAY_ASET(a, i, v)
void * rb_parser_realloc(struct parser_params *parser, void *ptr, size_t size)
st_table * st_init_numtable_with_size(st_index_t)
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck)
static int parser_set_number_literal(struct parser_params *parser, VALUE v, int type, int suffix)
int rb_parse_in_eval(void)
#define ENCODING_SET(obj, i)
int rb_memcicmp(const void *, const void *, long)
static NODE * list_concat_gen(struct parser_params *, NODE *, NODE *)
VALUE rb_filesystem_str_new_cstr(const char *)
ID rb_intern2(const char *name, long len)
#define tokadd_string(f, t, p, n, e)
NODE * rb_compile_file(const char *f, VALUE file, int start)
static int is_special_global_name(const char *m, const char *e, rb_encoding *enc)
#define number_literal_suffix(f)
VALUE rb_parser_get_yydebug(VALUE self)
static ID internal_id_gen(struct parser_params *)
VALUE(* parser_lex_gets)(struct parser_params *, VALUE)
#define IS_LABEL_POSSIBLE()
#define rb_enc_isalpha(c, enc)
static VALUE debug_lines(VALUE fname)
NODE * rb_parser_compile_cstr(volatile VALUE vparser, const char *f, const char *s, int len, int line)
VALUE rb_check_string_type(VALUE)
#define REALLOC_N(var, type, n)
static struct kwtable * reserved_word(const char *, unsigned int)
int rb_enc_str_coderange(VALUE)
#define set_yylval_literal(x)
int rb_local_defined(ID id)
NODE * parser_eval_tree_begin
static int match(VALUE str, VALUE pat, VALUE hash, int(*cb)(VALUE, VALUE))
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
static void dyna_pop_gen(struct parser_params *, const struct vtable *)
static void warn_unless_e_option(struct parser_params *parser, NODE *node, const char *str)
NODE * rb_parser_compile_file_path(volatile VALUE vparser, VALUE fname, VALUE file, int start)
static struct vtable * vtable_alloc(struct vtable *prev)
static ID * local_tbl_gen(struct parser_params *)
#define IS_AFTER_OPERATOR()
#define RTYPEDDATA_TYPE(v)
unsigned long ruby_scan_oct(const char *, size_t, size_t *)
#define IDSET_ATTRSET_FOR_INTERN
#define parser_warn(node, mesg)
static void ripper_init_eventids2_table(VALUE self)
#define reg_fragment_check(str, options)
static int vtable_size(const struct vtable *tbl)
#define parser_encoding_name()
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc)
static int sym_check_asciionly(VALUE str)
static void void_stmts_gen(struct parser_params *, NODE *)
rb_encoding * rb_enc_from_index(int index)
#define NEW_BLOCK_PASS(b)
int rb_is_global_name(VALUE name)
static int parser_tokadd_mbchar(struct parser_params *parser, int c)