15 #define PARSER_DEBUG 0
18 #define YYERROR_VERBOSE 1
19 #define YYSTACK_USE_ALLOCA 0
34 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
36 #define YYMALLOC(size) rb_parser_malloc(parser, (size))
37 #define YYREALLOC(ptr, size) rb_parser_realloc(parser, (ptr), (size))
38 #define YYCALLOC(nelem, size) rb_parser_calloc(parser, (nelem), (size))
39 #define YYFREE(ptr) rb_parser_free(parser, (ptr))
40 #define malloc YYMALLOC
41 #define realloc YYREALLOC
42 #define calloc YYCALLOC
48 #define REGISTER_SYMID(id, name) register_symid((id), (name), strlen(name), enc)
52 #define is_notop_id(id) ((id)>tLAST_OP_ID)
53 #define is_local_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL)
54 #define is_global_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_GLOBAL)
55 #define is_instance_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_INSTANCE)
56 #define is_attrset_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_ATTRSET)
57 #define is_const_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CONST)
58 #define is_class_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CLASS)
59 #define is_junk_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_JUNK)
60 #define id_type(id) (is_notop_id(id) ? (int)((id)&ID_SCOPE_MASK) : -1)
62 #define is_asgn_or_id(id) ((is_notop_id(id)) && \
63 (((id)&ID_SCOPE_MASK) == ID_GLOBAL || \
64 ((id)&ID_SCOPE_MASK) == ID_INSTANCE || \
65 ((id)&ID_SCOPE_MASK) == ID_CLASS))
83 #define DEF_EXPR(n) EXPR_##n = (1 << EXPR_##n##_bit)
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) {
295 VALUE parsing_thread;
300 #define STR_NEW(p,n) rb_enc_str_new((p),(n),current_enc)
301 #define STR_NEW0() rb_enc_str_new(0,0,current_enc)
302 #define STR_NEW2(p) rb_enc_str_new((p),strlen(p),current_enc)
303 #define STR_NEW3(p,n,e,func) parser_str_new((p),(n),(e),(func),current_enc)
304 #define ENC_SINGLE(cr) ((cr)==ENC_CODERANGE_7BIT)
305 #define TOK_INTERN(mb) rb_intern3(tok(), toklen(), current_enc)
308 #define yyerror(msg) parser_yyerror(parser, (msg))
310 #define lex_strterm (parser->parser_lex_strterm)
311 #define lex_state (parser->parser_lex_state)
312 #define cond_stack (parser->parser_cond_stack)
313 #define cmdarg_stack (parser->parser_cmdarg_stack)
314 #define class_nest (parser->parser_class_nest)
315 #define paren_nest (parser->parser_paren_nest)
316 #define lpar_beg (parser->parser_lpar_beg)
317 #define brace_nest (parser->parser_brace_nest)
318 #define in_single (parser->parser_in_single)
319 #define in_def (parser->parser_in_def)
320 #define compile_for_eval (parser->parser_compile_for_eval)
321 #define cur_mid (parser->parser_cur_mid)
322 #define in_defined (parser->parser_in_defined)
323 #define tokenbuf (parser->parser_tokenbuf)
324 #define tokidx (parser->parser_tokidx)
325 #define toksiz (parser->parser_toksiz)
326 #define tokline (parser->parser_tokline)
327 #define lex_input (parser->parser_lex_input)
328 #define lex_lastline (parser->parser_lex_lastline)
329 #define lex_nextline (parser->parser_lex_nextline)
330 #define lex_pbeg (parser->parser_lex_pbeg)
331 #define lex_p (parser->parser_lex_p)
332 #define lex_pend (parser->parser_lex_pend)
333 #define heredoc_end (parser->parser_heredoc_end)
334 #define command_start (parser->parser_command_start)
335 #define deferred_nodes (parser->parser_deferred_nodes)
336 #define lex_gets_ptr (parser->parser_lex_gets_ptr)
337 #define lex_gets (parser->parser_lex_gets)
338 #define lvtbl (parser->parser_lvtbl)
339 #define ruby__end__seen (parser->parser_ruby__end__seen)
340 #define ruby_sourceline (parser->parser_ruby_sourceline)
341 #define ruby_sourcefile (parser->parser_ruby_sourcefile)
342 #define ruby_sourcefile_string (parser->parser_ruby_sourcefile_string)
343 #define current_enc (parser->enc)
344 #define yydebug (parser->parser_yydebug)
347 #define ruby_eval_tree (parser->parser_eval_tree)
348 #define ruby_eval_tree_begin (parser->parser_eval_tree_begin)
349 #define ruby_debug_lines (parser->debug_lines)
350 #define ruby_coverage (parser->coverage)
354 static int yylex(
void*,
void*);
356 static int yylex(
void*);
360 #define yyparse ruby_yyparse
363 #define rb_node_newnode(type, a1, a2, a3) node_newnode(parser, (type), (a1), (a2), (a3))
366 #define cond(node) cond_gen(parser, (node))
368 #define logop(type,node1,node2) logop_gen(parser, (type), (node1), (node2))
376 #define value_expr(node) value_expr_gen(parser, (node) = remove_begin(node))
377 #define void_expr0(node) void_expr_gen(parser, (node))
378 #define void_expr(node) void_expr0((node) = remove_begin(node))
380 #define void_stmts(node) void_stmts_gen(parser, (node))
382 #define reduce_nodes(n) reduce_nodes_gen(parser,(n))
384 #define block_dup_check(n1,n2) block_dup_check_gen(parser,(n1),(n2))
387 #define block_append(h,t) block_append_gen(parser,(h),(t))
389 #define list_append(l,i) list_append_gen(parser,(l),(i))
391 #define list_concat(h,t) list_concat_gen(parser,(h),(t))
393 #define arg_append(h,t) arg_append_gen(parser,(h),(t))
395 #define arg_concat(h,t) arg_concat_gen(parser,(h),(t))
397 #define literal_concat(h,t) literal_concat_gen(parser,(h),(t))
400 #define new_evstr(n) new_evstr_gen(parser,(n))
402 #define evstr2dstr(n) evstr2dstr_gen(parser,(n))
406 #define call_bin_op(recv,id,arg1) call_bin_op_gen(parser, (recv),(id),(arg1))
408 #define call_uni_op(recv,id) call_uni_op_gen(parser, (recv),(id))
411 #define new_args(f,o,r,p,t) new_args_gen(parser, (f),(o),(r),(p),(t))
413 #define new_args_tail(k,kr,b) new_args_tail_gen(parser, (k),(kr),(b))
417 #define ret_args(node) ret_args_gen(parser, (node))
420 #define new_yield(node) new_yield_gen(parser, (node))
422 #define dsym_node(node) dsym_node_gen(parser, (node))
425 #define gettable(id) gettable_gen(parser,(id))
427 #define assignable(id,node) assignable_gen(parser, (id), (node))
430 #define aryset(node1,node2) aryset_gen(parser, (node1), (node2))
432 #define attrset(node,id) attrset_gen(parser, (node), (id))
435 #define rb_backref_error(n) rb_backref_error_gen(parser,(n))
437 #define node_assign(node1, node2) node_assign_gen(parser, (node1), (node2))
441 #define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (attr), (op), (rhs))
443 #define new_const_op_assign(lhs, op, rhs) new_const_op_assign_gen(parser, (lhs), (op), (rhs))
446 #define match_op(node1,node2) match_op_gen(parser, (node1), (node2))
449 #define local_tbl() local_tbl_gen(parser)
454 #define reg_compile(str,options) reg_compile_gen(parser, (str), (options))
456 #define reg_fragment_setenc(str,options) reg_fragment_setenc_gen(parser, (str), (options))
458 #define reg_fragment_check(str,options) reg_fragment_check_gen(parser, (str), (options))
460 #define reg_named_capture_assign(regexp,match) reg_named_capture_assign_gen(parser,(regexp),(match))
462 #define get_id(id) (id)
463 #define get_value(val) (val)
465 #define value_expr(node) ((void)(node))
466 #define remove_begin(node) (node)
467 #define rb_dvar_defined(id) 0
468 #define rb_local_defined(id) 0
469 static ID ripper_get_id(
VALUE);
470 #define get_id(id) ripper_get_id(id)
472 #define get_value(val) ripper_get_value(val)
474 #define assignable(lhs,node) assignable_gen(parser, (lhs))
476 #define id_is_var(id) id_is_var_gen(parser, (id))
478 #define node_assign(node1, node2) dispatch2(assign, (node1), (node2))
482 #define new_attr_op_assign(lhs, type, attr, op, rhs) new_attr_op_assign_gen(parser, (lhs), (type), (attr), (op), (rhs))
486 #define new_op_assign(lhs, op, rhs) new_op_assign_gen(parser, (lhs), (op), (rhs))
489 #define formal_argument(id) formal_argument_gen(parser, (id))
491 #define shadowing_lvar(name) shadowing_lvar_gen(parser, (name))
493 #define new_bv(id) new_bv_gen(parser, (id))
496 #define local_push(top) local_push_gen(parser,(top))
498 #define local_pop() local_pop_gen(parser)
500 #define local_var(id) local_var_gen(parser, (id))
502 #define arg_var(id) arg_var_gen(parser, (id))
504 #define local_id(id) local_id_gen(parser, (id))
506 #define internal_id() internal_id_gen(parser)
509 #define dyna_push() dyna_push_gen(parser)
511 #define dyna_pop(node) dyna_pop_gen(parser, (node))
513 #define dyna_in_block() dyna_in_block_gen(parser)
514 #define dyna_var(id) local_var(id)
516 #define dvar_defined(id) dvar_defined_gen(parser, (id), 0)
517 #define dvar_defined_get(id) dvar_defined_gen(parser, (id), 1)
519 #define dvar_curr(id) dvar_curr_gen(parser, (id))
522 #define lvar_defined(id) lvar_defined_gen(parser, (id))
524 #define RE_OPTION_ONCE (1<<16)
525 #define RE_OPTION_ENCODING_SHIFT 8
526 #define RE_OPTION_ENCODING(e) (((e)&0xff)<<RE_OPTION_ENCODING_SHIFT)
527 #define RE_OPTION_ENCODING_IDX(o) (((o)>>RE_OPTION_ENCODING_SHIFT)&0xff)
528 #define RE_OPTION_ENCODING_NONE(o) ((o)&RE_OPTION_ARG_ENCODING_NONE)
529 #define RE_OPTION_MASK 0xff
530 #define RE_OPTION_ARG_ENCODING_NONE 32
532 #define NODE_STRTERM NODE_ZARRAY
533 #define NODE_HEREDOC NODE_ARRAY
534 #define SIGN_EXTEND(x,n) (((1<<(n)-1)^((x)&~(~0<<(n))))-(1<<(n)-1))
535 #define nd_func u1.id
536 #if SIZEOF_SHORT == 2
537 #define nd_term(node) ((signed short)(node)->u2.id)
539 #define nd_term(node) SIGN_EXTEND((node)->u2.id, CHAR_BIT*2)
541 #define nd_paren(node) (char)((node)->u2.id >> CHAR_BIT*2)
542 #define nd_nest u3.cnt
547 #define RIPPER_VERSION "0.1.0"
560 #define dispatch0(n) ripper_dispatch0(parser, TOKEN_PASTE(ripper_id_, n))
561 #define dispatch1(n,a) ripper_dispatch1(parser, TOKEN_PASTE(ripper_id_, n), (a))
562 #define dispatch2(n,a,b) ripper_dispatch2(parser, TOKEN_PASTE(ripper_id_, n), (a), (b))
563 #define dispatch3(n,a,b,c) ripper_dispatch3(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c))
564 #define dispatch4(n,a,b,c,d) ripper_dispatch4(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d))
565 #define dispatch5(n,a,b,c,d,e) ripper_dispatch5(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d), (e))
566 #define dispatch7(n,a,b,c,d,e,f,g) ripper_dispatch7(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d), (e), (f), (g))
568 #define yyparse ripper_yyparse
570 #define ripper_intern(s) ID2SYM(rb_intern(s))
571 static VALUE ripper_id2sym(
ID);
573 #define ripper_id2sym(id) ((id) < 256 && rb_ispunct(id) ? \
574 ID2SYM(id) : ripper_id2sym(id))
577 #define arg_new() dispatch0(args_new)
578 #define arg_add(l,a) dispatch2(args_add, (l), (a))
579 #define arg_add_star(l,a) dispatch2(args_add_star, (l), (a))
580 #define arg_add_block(l,b) dispatch2(args_add_block, (l), (b))
581 #define arg_add_optblock(l,b) ((b)==Qundef? (l) : dispatch2(args_add_block, (l), (b)))
582 #define bare_assoc(v) dispatch1(bare_assoc_hash, (v))
583 #define arg_add_assocs(l,b) arg_add((l), bare_assoc(b))
585 #define args2mrhs(a) dispatch1(mrhs_new_from_args, (a))
586 #define mrhs_new() dispatch0(mrhs_new)
587 #define mrhs_add(l,a) dispatch2(mrhs_add, (l), (a))
588 #define mrhs_add_star(l,a) dispatch2(mrhs_add_star, (l), (a))
590 #define mlhs_new() dispatch0(mlhs_new)
591 #define mlhs_add(l,a) dispatch2(mlhs_add, (l), (a))
592 #define mlhs_add_star(l,a) dispatch2(mlhs_add_star, (l), (a))
594 #define params_new(pars, opts, rest, pars2, kws, kwrest, blk) \
595 dispatch7(params, (pars), (opts), (rest), (pars2), (kws), (kwrest), (blk))
597 #define blockvar_new(p,v) dispatch2(block_var, (p), (v))
598 #define blockvar_add_star(l,a) dispatch2(block_var_add_star, (l), (a))
599 #define blockvar_add_block(l,a) dispatch2(block_var_add_block, (l), (a))
601 #define method_optarg(m,a) ((a)==Qundef ? (m) : dispatch2(method_add_arg,(m),(a)))
602 #define method_arg(m,a) dispatch2(method_add_arg,(m),(a))
603 #define method_add_block(m,b) dispatch2(method_add_block, (m), (b))
605 #define escape_Qundef(x) ((x)==Qundef ? Qnil : (x))
614 #define new_args(f,o,r,p,t) new_args_gen(parser, (f),(o),(r),(p),(t))
621 #define new_args_tail(k,kr,b) new_args_tail_gen(parser, (k),(kr),(b))
629 # define ifndef_ripper(x) (x)
632 # define ifndef_ripper(x)
636 # define rb_warn0(fmt) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt))
637 # define rb_warnI(fmt,a) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt), (a))
638 # define rb_warnS(fmt,a) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt), (a))
639 # define rb_warn4S(file,line,fmt,a) rb_compile_warn((file), (line), (fmt), (a))
640 # define rb_warning0(fmt) rb_compile_warning(ruby_sourcefile, ruby_sourceline, (fmt))
641 # define rb_warningS(fmt,a) rb_compile_warning(ruby_sourcefile, ruby_sourceline, (fmt), (a))
643 # define rb_warn0(fmt) ripper_warn0(parser, (fmt))
644 # define rb_warnI(fmt,a) ripper_warnI(parser, (fmt), (a))
645 # define rb_warnS(fmt,a) ripper_warnS(parser, (fmt), (a))
646 # define rb_warn4S(file,line,fmt,a) ripper_warnS(parser, (fmt), (a))
647 # define rb_warning0(fmt) ripper_warning0(parser, (fmt))
648 # define rb_warningS(fmt,a) ripper_warningS(parser, (fmt), (a))
649 static void ripper_warn0(
struct parser_params*,
const char*);
650 static void ripper_warnI(
struct parser_params*,
const char*,
int);
651 static void ripper_warnS(
struct parser_params*,
const char*,
const char*);
652 static void ripper_warning0(
struct parser_params*,
const char*);
653 static void ripper_warningS(
struct parser_params*,
const char*,
const char*);
657 static void ripper_compile_error(
struct parser_params*,
const char *
fmt, ...);
658 # define rb_compile_error ripper_compile_error
659 # define compile_error ripper_compile_error
660 # define PARSER_ARG parser,
662 # define rb_compile_error rb_compile_error_with_enc
663 # define compile_error parser->nerr++,rb_compile_error_with_enc
664 # define PARSER_ARG ruby_sourcefile, ruby_sourceline, current_enc,
672 #define YYMAXDEPTH 10000
679 #define token_info_push(token) (RTEST(ruby_verbose) ? token_info_push(parser, (token)) : (void)0)
680 #define token_info_pop(token) (RTEST(ruby_verbose) ? token_info_pop(parser, (token)) : (void)0)
682 #define token_info_push(token)
683 #define token_info_pop(token)
696 const struct vtable *vars;
759 %type <node> singleton strings
string string1 xstring regexp
760 %type <node> string_contents xstring_contents regexp_contents string_content
761 %type <node> words
symbols symbol_list qwords qsymbols word_list qword_list qsym_list word
762 %type <node> literal numeric dsym cpath
763 %type <node> top_compstmt top_stmts
top_stmt
765 %type <node> expr_value arg_value primary_value fcall
766 %type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
768 %type <node> paren_args opt_paren_args args_tail opt_args_tail block_args_tail opt_block_args_tail
769 %type <node>
command_args aref_args opt_block_arg block_arg var_ref var_lhs
770 %type <node> command_asgn mrhs superclass block_call block_command
771 %type <node> f_block_optarg f_block_opt
772 %type <node> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
773 %type <node> assoc_list assocs
assoc undef_list backref string_dvar for_var
774 %type <node> block_param opt_block_param block_param_def f_opt
775 %type <node> f_kwarg f_kw f_block_kwarg f_block_kw
776 %type <node> bv_decls opt_bv_decl bvar
777 %type <node> lambda f_larglist lambda_body
781 %type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
871 while (node->nd_next) {
872 node = node->nd_next;
886 top_compstmt : top_stmts opt_terms
961 rb_warn0(
"else without rescue is useless");
1031 yyerror(
"BEGIN is permitted only at toplevel");
1037 '{' top_compstmt
'}'
1071 buf[1] = (char)$3->
nd_nth;
1080 yyerror(
"can't make alias for the number variables");
1151 rb_warn0(
"END in method; use at_exit");
1241 | mlhs
'=' arg_value
1335 block_command : block_call
1414 $5->nd_iter =
NEW_CALL($1, $3, $4);
1435 $5->nd_iter =
NEW_CALL($1, $3, $4);
1650 | primary_value
'[' opt_call_args rbracket
1686 yyerror(
"dynamic constant assignment");
1698 yyerror(
"dynamic constant assignment");
1734 | primary_value
'[' opt_call_args rbracket
1770 yyerror(
"dynamic constant assignment");
1783 yyerror(
"dynamic constant assignment");
1806 yyerror(
"class/module name must be CONSTANT");
1882 | undef_list
',' {
lex_state = EXPR_FNAME;} fitem
1972 | primary_value
'[' opt_call_args rbracket
tOP_ASGN arg
2352 | args
',' assocs trailer
2370 paren_args :
'(' opt_call_args rparen
2380 opt_paren_args : none
2384 opt_call_args : none
2390 | args
',' assocs
','
2417 | args opt_block_arg
2425 | assocs opt_block_arg
2435 | args
',' assocs opt_block_arg
2465 block_arg :
tAMPER arg_value
2475 opt_block_arg :
',' block_arg
2501 | args
',' arg_value
2515 | args
',' tSTAR arg_value
2531 mrhs : args
',' arg_value
2545 | args
',' tSTAR arg_value
2752 | method_call brace_block
2766 | k_if expr_value then
2778 | k_unless expr_value then
2812 | k_case expr_value opt_terms
2823 | k_case opt_terms case_body k_end
2890 tbl[0] = 1; tbl[1] =
id;
2897 | k_class cpath superclass
2900 yyerror(
"class definition in method body");
2945 yyerror(
"module definition in method body");
2986 | k_def singleton dot_or_colon {
lex_state = EXPR_FNAME;} fname
3041 primary_value : primary
3191 f_marg_list : f_marg
3199 | f_marg_list
',' f_marg
3209 f_margs : f_marg_list
3217 | f_marg_list
',' tSTAR f_norm_arg
3226 | f_marg_list
',' tSTAR f_norm_arg
',' f_marg_list
3235 | f_marg_list
',' tSTAR
3243 | f_marg_list
',' tSTAR ',' f_marg_list
3260 |
tSTAR f_norm_arg
',' f_marg_list
3280 |
tSTAR ',' f_marg_list
3291 block_args_tail : f_block_kwarg
',' f_kwrest opt_f_block_arg
3295 | f_block_kwarg opt_f_block_arg
3299 | f_kwrest opt_f_block_arg
3309 opt_block_args_tail :
',' block_args_tail
3319 block_param : f_arg
',' f_block_optarg
',' f_rest_arg opt_block_args_tail
3323 | f_arg
',' f_block_optarg
',' f_rest_arg
',' f_arg opt_block_args_tail
3327 | f_arg
',' f_block_optarg opt_block_args_tail
3331 | f_arg
',' f_block_optarg
',' f_arg opt_block_args_tail
3335 | f_arg
',' f_rest_arg opt_block_args_tail
3347 | f_arg
',' f_rest_arg
',' f_arg opt_block_args_tail
3351 | f_arg opt_block_args_tail
3355 | f_block_optarg
',' f_rest_arg opt_block_args_tail
3359 | f_block_optarg
',' f_rest_arg
',' f_arg opt_block_args_tail
3363 | f_block_optarg opt_block_args_tail
3367 | f_block_optarg
',' f_arg opt_block_args_tail
3371 | f_rest_arg opt_block_args_tail
3375 | f_rest_arg
',' f_arg opt_block_args_tail
3385 opt_block_param : none
3392 block_param_def :
'|' opt_bv_decl
'|'
3410 |
'|' block_param opt_bv_decl
'|'
3421 opt_bv_decl : opt_nl
3425 | opt_nl
';' bv_decls opt_nl
3489 f_larglist :
'(' f_args opt_bv_decl
')'
3538 block_call : command do_block
3554 | block_call dot_or_colon operation2 opt_paren_args
3563 | block_call dot_or_colon operation2 opt_paren_args brace_block
3567 $5->nd_iter =
NEW_CALL($1, $3, $4);
3575 | block_call dot_or_colon operation2
command_args do_block
3579 $5->nd_iter =
NEW_CALL($1, $3, $4);
3589 method_call : fcall paren_args
3598 | primary_value
'.' operation2
3614 | primary_value
tCOLON2 operation2
3630 | primary_value
tCOLON2 operation3
3688 | primary_value
'[' opt_call_args rbracket
3780 exc_list : arg_value
3923 for (list = (prev = node)->
nd_next;
list; list = list->nd_next) {
3925 VALUE tail = list->nd_head->nd_lit;
3927 VALUE lit = prev == node ? prev->nd_lit : prev->nd_head->nd_lit;
3933 prev->nd_next = list->nd_next;
3946 if (!node->nd_next) {
3987 | word_list word
' '
3997 word : string_content
4005 | word string_content
4042 | symbol_list word
' '
4146 | string_contents string_content
4164 | xstring_contents string_content
4182 | regexp_contents string_content
4350 var_ref : user_variable
4373 var_lhs : user_variable
4424 f_arglist :
'(' f_args rparen
4442 args_tail : f_kwarg
',' f_kwrest opt_f_block_arg
4446 | f_kwarg opt_f_block_arg
4450 | f_kwrest opt_f_block_arg
4460 opt_args_tail :
',' args_tail
4470 f_args : f_arg
',' f_optarg
',' f_rest_arg opt_args_tail
4474 | f_arg
',' f_optarg
',' f_rest_arg
',' f_arg opt_args_tail
4478 | f_arg
',' f_optarg opt_args_tail
4482 | f_arg
',' f_optarg
',' f_arg opt_args_tail
4486 | f_arg
',' f_rest_arg opt_args_tail
4490 | f_arg
',' f_rest_arg
',' f_arg opt_args_tail
4494 | f_arg opt_args_tail
4498 | f_optarg
',' f_rest_arg opt_args_tail
4502 | f_optarg
',' f_rest_arg
',' f_arg opt_args_tail
4506 | f_optarg opt_args_tail
4510 | f_optarg
',' f_arg opt_args_tail
4514 | f_rest_arg opt_args_tail
4518 | f_rest_arg
',' f_arg opt_args_tail
4536 yyerror(
"formal argument cannot be a constant");
4545 yyerror(
"formal argument cannot be an instance variable");
4554 yyerror(
"formal argument cannot be a global variable");
4563 yyerror(
"formal argument cannot be a class variable");
4571 f_norm_arg : f_bad_arg
4579 f_arg_item : f_norm_arg
4614 | f_arg
',' f_arg_item
4639 f_block_kw :
tLABEL primary_value
4651 f_block_kwarg : f_block_kw
4659 | f_block_kwarg
',' f_block_kw
4664 while (kws->nd_next) {
4689 while (kws->nd_next) {
4739 f_block_optarg : f_block_opt
4747 | f_block_optarg
',' f_block_opt
4752 while (opts->nd_next) {
4753 opts = opts->nd_next;
4771 | f_optarg
',' f_opt
4776 while (opts->nd_next) {
4777 opts = opts->nd_next;
4795 yyerror(
"rest argument must be local variable");
4823 yyerror(
"block argument must be local variable");
4825 yyerror(
"duplicated block argument name");
4836 opt_f_block_arg :
',' f_block_arg
4864 yyerror(
"can't define singleton method for ().");
4876 yyerror(
"can't define singleton method for literals");
4984 rbracket : opt_nl
']'
5013 # define yylval (*((YYSTYPE*)(parser->parser_yylval)))
5022 # define nextc() parser_nextc(parser)
5023 # define pushback(c) parser_pushback(parser, (c))
5024 # define newtok() parser_newtok(parser)
5025 # define tokspace(n) parser_tokspace(parser, (n))
5026 # define tokadd(c) parser_tokadd(parser, (c))
5027 # define tok_hex(numlen) parser_tok_hex(parser, (numlen))
5028 # define read_escape(flags,e) parser_read_escape(parser, (flags), (e))
5029 # define tokadd_escape(e) parser_tokadd_escape(parser, (e))
5030 # define regx_options() parser_regx_options(parser)
5031 # define tokadd_string(f,t,p,n,e) parser_tokadd_string(parser,(f),(t),(p),(n),(e))
5032 # define parse_string(n) parser_parse_string(parser,(n))
5033 # define tokaddmbc(c, enc) parser_tokaddmbc(parser, (c), (enc))
5034 # define here_document(n) parser_here_document(parser,(n))
5035 # define heredoc_identifier() parser_heredoc_identifier(parser)
5036 # define heredoc_restore(n) parser_heredoc_restore(parser,(n))
5037 # define whole_match_p(e,l,i) parser_whole_match_p(parser,(e),(l),(i))
5040 # define set_yylval_str(x) (yylval.node = NEW_STR(x))
5041 # define set_yylval_num(x) (yylval.num = (x))
5042 # define set_yylval_id(x) (yylval.id = (x))
5043 # define set_yylval_name(x) (yylval.id = (x))
5044 # define set_yylval_literal(x) (yylval.node = NEW_LIT(x))
5045 # define set_yylval_node(x) (yylval.node = (x))
5046 # define yylval_id() (yylval.id)
5049 ripper_yylval_id(
ID x)
5053 # define set_yylval_str(x) (void)(x)
5054 # define set_yylval_num(x) (void)(x)
5055 # define set_yylval_id(x) (void)(x)
5056 # define set_yylval_name(x) (void)(yylval.val = ripper_yylval_id(x))
5057 # define set_yylval_literal(x) (void)(x)
5058 # define set_yylval_node(x) (void)(x)
5059 # define yylval_id() yylval.id
5063 #define ripper_flush(p) (void)(p)
5065 #define ripper_flush(p) ((p)->tokp = (p)->parser_lex_p)
5067 #define yylval_rval (*(RB_TYPE_P(yylval.val, T_NODE) ? &yylval.node->nd_rval : &yylval.val))
5074 return lex_p > parser->tokp;
5087 ripper_dispatch_scan_event(
struct parser_params *parser,
int t)
5089 if (!ripper_has_scan_event(parser))
return;
5090 yylval_rval = ripper_scan_event_val(parser, t);
5094 ripper_dispatch_ignored_scan_event(
struct parser_params *parser,
int t)
5096 if (!ripper_has_scan_event(parser))
return;
5097 (
void)ripper_scan_event_val(parser, t);
5101 ripper_dispatch_delayed_token(
struct parser_params *parser,
int t)
5104 const char *saved_tokp = parser->tokp;
5107 parser->tokp =
lex_pbeg + parser->delayed_col;
5109 parser->delayed =
Qnil;
5111 parser->tokp = saved_tokp;
5122 #undef SIGN_EXTEND_CHAR
5124 # define SIGN_EXTEND_CHAR(c) ((signed char)(c))
5127 # define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
5130 #define parser_encoding_name() (current_enc->name)
5131 #define parser_mbclen() mbclen((lex_p-1),lex_pend,current_enc)
5132 #define parser_precise_mbclen() rb_enc_precise_mbclen((lex_p-1),lex_pend,current_enc)
5133 #define is_identchar(p,e,enc) (rb_enc_isalnum(*(p),(enc)) || (*(p)) == '_' || !ISASCII(*(p)))
5134 #define parser_is_identchar() (!parser->eofp && is_identchar((lex_p-1),lex_pend,current_enc))
5136 #define parser_isascii() ISASCII(*(lex_p-1))
5144 for (p =
lex_pbeg; p < pend; p++) {
5146 column = (((column - 1) / 8) + 1) * 8;
5157 for (p =
lex_pbeg; p < pend; p++) {
5158 if (*p !=
' ' && *p !=
'\t') {
5165 #undef token_info_push
5182 #undef token_info_pop
5189 if (!ptinfo)
return;
5195 if (linenum == ptinfo->
linenum) {
5203 "mismatched indentations at '%s' with '%s' at %d",
5216 const int max_line_margin = 30;
5225 if (*p ==
'\n')
break;
5232 if (*pe ==
'\n')
break;
5239 const char *pre =
"", *post =
"";
5241 if (len > max_line_margin * 2 + 10) {
5242 if (
lex_p - p > max_line_margin) {
5246 if (pe -
lex_p > max_line_margin) {
5253 MEMCPY(buf, p,
char, len);
5258 p2 =
buf; pe = buf +
len;
5261 if (*p2 !=
'\t') *p2 =
' ';
5269 dispatch1(parse_error,
STR_NEW2(msg));
5281 CONST_ID(script_lines,
"SCRIPT_LINES__");
5300 RBASIC(lines)->klass = 0;
5302 RARRAY(lines)->as.heap.len =
n;
5398 char *beg, *
end, *pend;
5408 while (end < pend) {
5409 if (*end++ ==
'\n')
break;
5419 if (
NIL_P(line))
return line;
5530 #define STR_FUNC_ESCAPE 0x01
5531 #define STR_FUNC_EXPAND 0x02
5532 #define STR_FUNC_REGEXP 0x04
5533 #define STR_FUNC_QWORDS 0x08
5534 #define STR_FUNC_SYMBOL 0x10
5535 #define STR_FUNC_INDENT 0x20
5565 #define lex_goto_eol(parser) ((parser)->parser_lex_p = (parser)->parser_lex_pend)
5566 #define lex_eol_p() (lex_p >= lex_pend)
5567 #define peek(c) peek_n((c), 0)
5568 #define peek_n(c,n) (lex_p+(n) < lex_pend && (c) == (unsigned char)lex_p[n])
5591 if (
NIL_P(parser->delayed)) {
5595 parser->tokp,
lex_pend - parser->tokp);
5597 parser->delayed_col = (
int)(parser->tokp -
lex_pbeg);
5601 parser->tokp,
lex_pend - parser->tokp);
5617 c = (
unsigned char)*
lex_p++;
5618 if (c ==
'\r' &&
peek(
'\n')) {
5629 if (c == -1)
return;
5636 #define was_bol() (lex_p == lex_pbeg + 1)
5638 #define tokfix() (tokenbuf[tokidx]='\0')
5639 #define tok() tokenbuf
5640 #define toklen() tokidx
5641 #define toklast() (tokidx>0?tokenbuf[tokidx-1]:0)
5688 yyerror(
"invalid hex escape");
5695 #define tokcopy(n) memcpy(tokspace(n), lex_p - (n), (n))
5700 int string_literal,
int symbol_literal,
int regexp_literal)
5720 yyerror(
"invalid Unicode escape");
5723 if (codepoint > 0x10ffff) {
5724 yyerror(
"invalid Unicode codepoint (too large)");
5728 if (regexp_literal) {
5731 else if (codepoint >= 0x80) {
5733 if (string_literal)
tokaddmbc(codepoint, *encp);
5735 else if (string_literal) {
5738 }
while (string_literal && (
peek(
' ') ||
peek(
'\t')));
5741 yyerror(
"unterminated Unicode escape");
5745 if (regexp_literal) {
tokadd(
'}'); }
5751 yyerror(
"invalid Unicode escape");
5755 if (regexp_literal) {
5758 else if (codepoint >= 0x80) {
5760 if (string_literal)
tokaddmbc(codepoint, *encp);
5762 else if (string_literal) {
5770 #define ESCAPE_CONTROL 1
5771 #define ESCAPE_META 2
5780 switch (c =
nextc()) {
5805 case '0':
case '1':
case '2':
case '3':
5806 case '4':
case '5':
case '6':
case '7':
5814 if (numlen == 0)
return 0;
5825 if ((c =
nextc()) !=
'-') {
5829 if ((c =
nextc()) ==
'\\') {
5830 if (
peek(
'u'))
goto eof;
5831 return read_escape(flags|ESCAPE_META, encp) | 0x80;
5833 else if (c == -1 || !
ISASCII(c))
goto eof;
5835 return ((c & 0xff) | 0x80);
5839 if ((c =
nextc()) !=
'-') {
5845 if ((c =
nextc())==
'\\') {
5846 if (
peek(
'u'))
goto eof;
5851 else if (c == -1 || !
ISASCII(c))
goto eof;
5856 yyerror(
"Invalid escape character syntax");
5879 switch (c =
nextc()) {
5883 case '0':
case '1':
case '2':
case '3':
5884 case '4':
case '5':
case '6':
case '7':
5887 if (numlen == 0)
goto eof;
5896 if (numlen == 0)
return -1;
5902 if (flags & ESCAPE_META)
goto eof;
5903 if ((c =
nextc()) !=
'-') {
5912 if (flags & ESCAPE_CONTROL)
goto eof;
5913 if ((c =
nextc()) !=
'-') {
5921 if (flags & ESCAPE_CONTROL)
goto eof;
5925 if ((c =
nextc()) ==
'\\') {
5928 else if (c == -1)
goto eof;
5934 yyerror(
"Invalid escape character syntax");
6001 #define tokadd_mbchar(c) parser_tokadd_mbchar(parser, (c))
6007 case '$':
case '*':
case '+':
case '.':
6008 case '?':
case '^':
case '|':
6009 case ')':
case ']':
case '}':
case '>':
6018 int func,
int term,
int paren,
long *nest,
6022 int has_nonascii = 0;
6025 static const char mixed_msg[] =
"%s mixed within %s source";
6027 #define mixed_error(enc1, enc2) if (!errbuf) { \
6028 size_t len = sizeof(mixed_msg) - 4; \
6029 len += strlen(rb_enc_name(enc1)); \
6030 len += strlen(rb_enc_name(enc2)); \
6031 errbuf = ALLOCA_N(char, len); \
6032 snprintf(errbuf, len, mixed_msg, \
6033 rb_enc_name(enc1), \
6034 rb_enc_name(enc2)); \
6037 #define mixed_escape(beg, enc1, enc2) do { \
6038 const char *pos = lex_p; \
6040 mixed_error((enc1), (enc2)); \
6044 while ((c =
nextc()) != -1) {
6045 if (paren && c == paren) {
6048 else if (c == term) {
6049 if (!nest || !*nest) {
6057 if (c2 ==
'$' || c2 ==
'@' || c2 ==
'{') {
6062 else if (c ==
'\\') {
6063 const char *beg =
lex_p - 1;
6068 if (func & STR_FUNC_EXPAND)
continue;
6077 if ((func & STR_FUNC_EXPAND) == 0) {
6083 func & STR_FUNC_REGEXP);
6084 if (has_nonascii && enc != *encp) {
6090 if (c == -1)
return -1;
6092 if ((func & STR_FUNC_EXPAND) == 0)
tokadd(
'\\');
6095 if (func & STR_FUNC_REGEXP) {
6103 if (has_nonascii && enc != *encp) {
6108 else if (func & STR_FUNC_EXPAND) {
6110 if (func & STR_FUNC_ESCAPE)
tokadd(
'\\');
6113 else if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
6116 else if (c != term && !(paren && c == paren)) {
6133 else if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
6150 #define NEW_STRTERM(func, term, paren) \
6151 rb_node_newnode(NODE_STRTERM, (func), (term) | ((paren) << (CHAR_BIT * 2)), 0)
6157 if (!
NIL_P(parser->delayed)) {
6158 ptrdiff_t len =
lex_p - parser->tokp;
6163 parser->tokp =
lex_p;
6167 #define flush_string_content(enc) ripper_flush_string_content(parser, (enc))
6169 #define flush_string_content(enc) ((void)(enc))
6176 #define BIT(c, idx) (((c) / 32 - 1 == idx) ? (1U << ((c) % 32)) : 0)
6177 #define SPECIAL_PUNCT(idx) ( \
6178 BIT('~', idx) | BIT('*', idx) | BIT('$', idx) | BIT('?', idx) | \
6179 BIT('!', idx) | BIT('@', idx) | BIT('/', idx) | BIT('\\', idx) | \
6180 BIT(';', idx) | BIT(',', idx) | BIT('.', idx) | BIT('=', idx) | \
6181 BIT(':', idx) | BIT('<', idx) | BIT('>', idx) | BIT('\"', idx) | \
6182 BIT('&', idx) | BIT('`', idx) | BIT('\'', idx) | BIT('+', idx) | \
6190 #undef SPECIAL_PUNCT
6196 if (c <= 0x20 || 0x7e < c)
return 0;
6197 return (ruby_global_name_punct_bits[(c - 0x20) / 32] >> (c % 32)) & 1;
6204 const char *p =
lex_p;
6210 if ((c = *p) ==
'-') {
6219 if ((c = *p) ==
'@') {
6239 int func = (
int)quote->nd_func;
6247 if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
6251 if (c == term && !quote->nd_nest) {
6252 if (func & STR_FUNC_QWORDS) {
6253 quote->nd_func = -1;
6256 if (!(func & STR_FUNC_REGEXP))
return tSTRING_END;
6265 if ((func & STR_FUNC_EXPAND) && c ==
'#') {
6275 if (func & STR_FUNC_REGEXP) {
6297 int c =
nextc(), term, func = 0;
6315 while ((c =
nextc()) != -1 && c != term) {
6362 line = here->nd_orig;
6366 lex_p = lex_pbeg + here->nd_nth;
6376 const char *eos,
long len,
int indent)
6382 while (*p &&
ISSPACE(*p)) p++;
6385 if (n < 0 || (n > 0 && p[len] !=
'\n' && p[len] !=
'\r'))
return FALSE;
6386 return strncmp(eos, p, len) == 0;
6393 if (!
NIL_P(parser->delayed))
6396 ripper_dispatch_ignored_scan_event(parser,
tHEREDOC_END);
6399 #define dispatch_heredoc_end() ripper_dispatch_heredoc_end(parser)
6401 #define dispatch_heredoc_end() ((void)0)
6407 int c,
func, indent = 0;
6408 const char *eos, *
p, *pend;
6417 if ((c =
nextc()) == -1) {
6421 if (
NIL_P(parser->delayed)) {
6426 ((len =
lex_p - parser->tokp) > 0 &&
6427 (str =
STR_NEW3(parser->tokp, len, enc, func), 1))) {
6445 if (!(func & STR_FUNC_EXPAND)) {
6452 if (--pend == p || pend[-1] !=
'\r') {
6466 if (
nextc() == -1) {
6487 if (parser->
eofp)
goto error;
6497 if ((c =
nextc()) == -1)
goto error;
6514 rb_warning0(
"ambiguous first argument; put parentheses or even spaces");
6519 #define arg_ambiguous() (arg_ambiguous_gen(parser), 1)
6526 yyerror(
"formal argument must be local variable");
6544 if (len > 5 && name[nlen = len - 5] ==
'-') {
6548 if (len > 4 && name[nlen = len - 4] ==
'-') {
6551 if (
rb_memcicmp(name + nlen + 1,
"mac", 3) == 0 &&
6552 !(len == 8 &&
rb_memcicmp(name,
"utf8-mac", len) == 0))
6567 excargs[1] =
rb_sprintf(
"unknown encoding name: %s", name);
6584 for (i = 0; i <
n; ++
i) {
6659 if (str[i-1] ==
'*' && str[i-2] ==
'-') {
6665 if (i + 1 >= len)
return 0;
6666 if (str[i+1] !=
'-') {
6669 else if (str[i-1] !=
'-') {
6687 VALUE name = 0, val = 0;
6688 const char *beg, *
end, *vbeg, *vend;
6689 #define str_copy(_s, _p, _n) ((_s) \
6690 ? (void)(rb_str_resize((_s), (_n)), \
6691 MEMCPY(RSTRING_PTR(_s), (_p), char, (_n)), (_s)) \
6692 : (void)((_s) = STR_NEW((_p), (_n))))
6694 if (len <= 7)
return FALSE;
6698 len = end - beg - 3;
6709 for (; len > 0 && *
str; str++, --
len) {
6711 case '\'':
case '"':
case ':':
case ';':
6716 for (beg = str; len > 0; str++, --
len) {
6718 case '\'':
case '"':
case ':':
case ';':
6726 for (end = str; len > 0 &&
ISSPACE(*str); str++, --
len);
6728 if (*str !=
':')
continue;
6730 do str++;
while (--len > 0 &&
ISSPACE(*str));
6733 for (vbeg = ++str; --len > 0 && *str !=
'"'; str++) {
6746 for (vbeg = str; len > 0 && *str !=
'"' && *str !=
';' && !
ISSPACE(*str); --
len, str++);
6749 while (len > 0 && (*str ==
';' ||
ISSPACE(*str))) --len, str++;
6754 for (i = 0; i <
n; ++
i) {
6755 if (s[i] ==
'-') s[
i] =
'_';
6762 n = (*p->
length)(parser, vbeg, n);
6768 }
while (++p < magic_comments +
numberof(magic_comments));
6782 const char *beg =
str;
6786 if (send - str <= 6)
return;
6788 case 'C':
case 'c': str += 6;
continue;
6789 case 'O':
case 'o': str += 5;
continue;
6790 case 'D':
case 'd': str += 4;
continue;
6791 case 'I':
case 'i': str += 3;
continue;
6792 case 'N':
case 'n': str += 2;
continue;
6793 case 'G':
case 'g': str += 1;
continue;
6807 if (++str >= send)
return;
6810 if (*str !=
'=' && *str !=
':')
return;
6815 while ((*str ==
'-' || *str ==
'_' ||
ISALNUM(*str)) && ++str < send);
6831 (
unsigned char)
lex_p[0] == 0xbb &&
6832 (
unsigned char)
lex_p[1] == 0xbf) {
6846 #define IS_ARG() IS_lex_state(EXPR_ARG_ANY)
6847 #define IS_END() IS_lex_state(EXPR_END_ANY)
6848 #define IS_BEG() IS_lex_state(EXPR_BEG_ANY)
6849 #define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c))
6850 #define IS_LABEL_POSSIBLE() ((IS_lex_state(EXPR_BEG | EXPR_ENDFN) && !cmd_state) || IS_ARG())
6851 #define IS_LABEL_SUFFIX(n) (peek_n(':',(n)) && !peek_n(':', (n)+1))
6852 #define IS_AFTER_OPERATOR() IS_lex_state(EXPR_FNAME | EXPR_DOT)
6855 #define ambiguous_operator(op, syn) ( \
6856 rb_warning0("`"op"' after local variable is interpreted as binary operator"), \
6857 rb_warning0("even though it seems like "syn""))
6859 #define ambiguous_operator(op, syn) dispatch2(operator_ambiguous, ripper_intern(op), rb_str_new_cstr(syn))
6861 #define warn_balanced(op, syn) ((void) \
6862 (!IS_lex_state_for(last_state, EXPR_CLASS|EXPR_DOT|EXPR_FNAME|EXPR_ENDFN|EXPR_ENDARG) && \
6863 space_seen && !ISSPACE(c) && \
6864 (ambiguous_operator(op, syn), 0)))
6876 int fallthru =
FALSE;
6902 switch (c =
nextc()) {
6910 case ' ':
case '\t':
case '\f':
case '\r':
6914 while ((c =
nextc())) {
6916 case ' ':
case '\t':
case '\f':
case '\r':
6925 ripper_dispatch_scan_event(parser,
tSP);
6938 ripper_dispatch_scan_event(parser,
tCOMMENT);
6943 if (
IS_lex_state(EXPR_BEG | EXPR_VALUE | EXPR_CLASS | EXPR_FNAME | EXPR_DOT)) {
6952 while ((c =
nextc())) {
6954 case ' ':
case '\t':
case '\f':
case '\r':
6959 if ((c =
nextc()) !=
'.') {
6972 parser->tokp =
lex_p;
6975 goto normal_newline;
6984 if ((c =
nextc()) ==
'*') {
6985 if ((c =
nextc()) ==
'=') {
6992 rb_warning0(
"`**' interpreted as argument prefix");
7011 rb_warning0(
"`*' interpreted as argument prefix");
7059 ripper_dispatch_scan_event(parser,
tEMBDOC);
7068 if (c !=
'=')
continue;
7069 if (strncmp(
lex_p,
"end", 3) == 0 &&
7083 if ((c =
nextc()) ==
'=') {
7084 if ((c =
nextc()) ==
'=') {
7093 else if (c ==
'>') {
7105 (!
IS_ARG() || space_seen)) {
7107 if (token)
return token;
7118 if ((c =
nextc()) ==
'>') {
7125 if ((c =
nextc()) ==
'=') {
7139 if ((c =
nextc()) ==
'=') {
7143 if ((c =
nextc()) ==
'=') {
7211 rb_warnI(
"invalid character syntax; use ?\\%c", c2);
7228 else if (c ==
'\\') {
7257 if ((c =
nextc()) ==
'&') {
7259 if ((c =
nextc()) ==
'=') {
7267 else if (c ==
'=') {
7274 rb_warning0(
"`&' interpreted as argument prefix");
7288 if ((c =
nextc()) ==
'|') {
7290 if ((c =
nextc()) ==
'=') {
7370 if ((c =
nextc()) ==
'.') {
7371 if ((c =
nextc()) ==
'.') {
7379 yyerror(
"no .<digit> floating literal anymore; put 0 before dot");
7385 case '0':
case '1':
case '2':
case '3':
case '4':
7386 case '5':
case '6':
case '7':
case '8':
case '9':
7388 int is_float, seen_point, seen_e, nondigit;
7390 is_float = seen_point = seen_e = nondigit = 0;
7393 if (c ==
'-' || c ==
'+') {
7398 #define no_digits() do {yyerror("numeric literal without digits"); return 0;} while (0)
7401 if (c ==
'x' || c ==
'X') {
7407 if (nondigit)
break;
7414 }
while ((c =
nextc()) != -1);
7421 else if (nondigit)
goto trailing_uc;
7425 if (c ==
'b' || c ==
'B') {
7428 if (c ==
'0' || c ==
'1') {
7431 if (nondigit)
break;
7435 if (c !=
'0' && c !=
'1')
break;
7438 }
while ((c =
nextc()) != -1);
7445 else if (nondigit)
goto trailing_uc;
7449 if (c ==
'd' || c ==
'D') {
7455 if (nondigit)
break;
7462 }
while ((c =
nextc()) != -1);
7469 else if (nondigit)
goto trailing_uc;
7477 if (c ==
'o' || c ==
'O') {
7480 if (c == -1 || c ==
'_' || !
ISDIGIT(c)) {
7484 if (c >=
'0' && c <=
'7') {
7489 if (nondigit)
break;
7493 if (c < '0' || c >
'9')
break;
7494 if (c >
'7')
goto invalid_octal;
7497 }
while ((c =
nextc()) != -1);
7501 if (nondigit)
goto trailing_uc;
7510 if (c >
'7' && c <=
'9') {
7512 yyerror(
"Invalid octal digit");
7514 else if (c ==
'.' || c ==
'e' || c ==
'E') {
7526 case '0':
case '1':
case '2':
case '3':
case '4':
7527 case '5':
case '6':
case '7':
case '8':
case '9':
7533 if (nondigit)
goto trailing_uc;
7534 if (seen_point || seen_e) {
7539 if (c0 == -1 || !
ISDIGIT(c0)) {
7567 if (c !=
'-' && c !=
'+')
continue;
7573 if (nondigit)
goto decode_num;
7588 snprintf(tmp,
sizeof(tmp),
"trailing `%c' in number", nondigit);
7594 if (
errno == ERANGE) {
7671 if ((c =
nextc()) ==
'=') {
7691 if ((c =
nextc()) !=
'@') {
7718 if ((c =
nextc()) ==
']') {
7719 if ((c =
nextc()) ==
'=') {
7731 else if (
IS_ARG() && space_seen) {
7766 ripper_dispatch_scan_event(parser,
tSP);
7787 yyerror(
"unknown type of %string");
7791 if (c == -1 || term == -1) {
7796 if (term ==
'(') term =
')';
7797 else if (term ==
'[') term =
']';
7798 else if (term ==
'{') term =
'}';
7799 else if (term ==
'<') term =
'>';
7849 yyerror(
"unknown type of %string");
7853 if ((c =
nextc()) ==
'=') {
7930 case '1':
case '2':
case '3':
7931 case '4':
case '5':
case '6':
7932 case '7':
case '8':
case '9':
7937 }
while (c != -1 &&
ISDIGIT(c));
7983 ripper_dispatch_scan_event(parser,
k__END__);
8011 if ((c ==
'!' || c ==
'?') && !
peek(
'=')) {
8031 if (
tok()[1] ==
'@')
8077 if (state == EXPR_FNAME) {
8091 if (
CMDARG_P() && state != EXPR_CMDARG)
8093 if (state & (EXPR_BEG | EXPR_ENDARG))
8097 if (state & (EXPR_BEG | EXPR_VALUE))
8100 if (kw->
id[0] != kw->
id[1])
8137 yylex(
void *lval,
void *p)
8151 if (!
NIL_P(parser->delayed)) {
8152 ripper_dispatch_delayed_token(parser, t);
8156 ripper_dispatch_scan_event(parser, t);
8198 if (orig == (
NODE*)1)
return;
8207 #define parser_warning(node, mesg) parser_warning(parser, (node), (mesg))
8214 #define parser_warn(node, mesg) parser_warn(parser, (node), (mesg))
8221 if (tail == 0)
return head;
8223 if (h == 0)
return tail;
8262 tail->nd_end =
tail;
8264 end->nd_next =
tail;
8265 h->nd_end = tail->nd_end;
8275 if (list == 0)
return NEW_LIST(item);
8276 if (list->nd_next) {
8277 last = list->nd_next->nd_end;
8285 list->nd_next->nd_end = last->nd_next;
8295 if (head->nd_next) {
8296 last = head->nd_next->nd_end;
8302 head->nd_alen += tail->nd_alen;
8303 last->nd_next =
tail;
8304 if (tail->nd_next) {
8305 head->nd_next->nd_end = tail->nd_next->nd_end;
8308 head->nd_next->nd_end =
tail;
8317 if (
NIL_P(tail))
return 1;
8338 if (!head)
return tail;
8339 if (!tail)
return head;
8349 if (htype ==
NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
8352 lit = headlast->nd_lit;
8375 tail->nd_lit = head->nd_lit;
8379 else if (
NIL_P(tail->nd_lit)) {
8381 head->nd_alen += tail->nd_alen - 1;
8382 head->nd_next->nd_end->nd_next = tail->nd_next;
8383 head->nd_next->nd_end = tail->nd_next->nd_end;
8386 else if (htype ==
NODE_DSTR && (headlast = head->nd_next->nd_end->nd_head) &&
8388 lit = headlast->nd_lit;
8391 tail->nd_lit =
Qnil;
8396 tail->nd_head =
NEW_STR(tail->nd_lit);
8545 static const char names[][12] = {
8546 "EXPR_BEG",
"EXPR_END",
"EXPR_ENDARG",
"EXPR_ENDFN",
"EXPR_ARG",
8547 "EXPR_CMDARG",
"EXPR_MID",
"EXPR_FNAME",
"EXPR_DOT",
"EXPR_CLASS",
8552 return names[
ffs(state)];
8567 # define assignable_result(x) get_value(lhs)
8568 # define parser_yyerror(parser, x) dispatch1(assign_error, lhs)
8570 # define assignable_result(x) (x)
8575 yyerror(
"Can't change the value of self");
8578 yyerror(
"Can't assign to nil");
8581 yyerror(
"Can't assign to true");
8584 yyerror(
"Can't assign to false");
8587 yyerror(
"Can't assign to __FILE__");
8590 yyerror(
"Can't assign to __LINE__");
8593 yyerror(
"Can't assign to __ENCODING__");
8627 yyerror(
"dynamic constant assignment");
8636 #undef assignable_result
8637 #undef parser_yyerror
8644 if (name == idUScore)
return 1;
8651 #define LVAR_USED ((ID)1 << (sizeof(ID) * CHAR_BIT - 1))
8659 yyerror(
"duplicated argument name");
8671 yyerror(
"duplicated argument name");
8729 int scope = (
int)(
id & ID_SCOPE_MASK);
8738 id_type_names[scope],
ID2SYM(
id));
8742 id &= ~ID_SCOPE_MASK;
8771 if (!node2)
return node1;
8775 node1->nd_head =
arg_concat(node1->nd_head, node2);
8787 node1->nd_body =
list_concat(node1->nd_body, node2);
8796 if (!node1)
return NEW_LIST(node2);
8801 node1->nd_head =
arg_append(node1->nd_head, node2);
8834 lhs->nd_value = rhs;
8839 lhs->nd_args =
arg_append(lhs->nd_args, rhs);
8870 if (!cond)
yyerror(
"void value expression");
8875 while (node->nd_next) {
8876 node = node->nd_next;
8878 node = node->nd_head;
8882 node = node->nd_body;
8886 if (!node->nd_body) {
8887 node = node->nd_else;
8890 else if (!node->nd_else) {
8891 node = node->nd_body;
8895 node = node->nd_else;
8901 node = node->nd_2nd;
8915 const char *useless = 0;
8922 switch (node->nd_mid) {
8953 useless =
"a variable";
8956 useless =
"a constant";
8963 useless =
"a literal";
8988 useless =
"defined?";
8996 rb_warnS(
"possibly useless use of %s in void context", useless);
9009 if (!node->nd_next)
return;
9011 node = node->nd_next;
9018 NODE **n = &node, *n1 = node;
9020 *n = n1 = n1->nd_body;
9034 #define subnodes(n1, n2) \
9035 ((!node->n1) ? (node->n2 ? (body = &node->n2, 1) : 0) : \
9036 (!node->n2) ? (body = &node->n1, 1) : \
9037 (reduce_nodes(&node->n1), body = &node->n2, 1))
9047 *body = node = node->nd_stts;
9051 *body = node = node->nd_body;
9055 body = &node->nd_end->nd_head;
9061 body = &node->nd_body;
9070 if (node->nd_else) {
9071 body = &node->nd_resq;
9089 if (!node)
return 1;
9092 if (!(node = node->nd_head))
break;
9096 }
while ((node = node->nd_next) != 0);
9115 yyerror(
"multiple assignment in conditional");
9129 if (!node->nd_value)
return 1;
9132 parser_warn(node->nd_value,
"found = in conditional, should be ==");
9154 for (node = *rootnode; node; node = next) {
9158 next = node->nd_next;
9159 head = node->nd_head;
9162 switch (type =
nd_type(head)) {
9165 val =
rb_range_new(head->nd_beg->nd_lit, head->nd_end->nd_lit,
9185 if (node == 0)
return 0;
9193 return cond0(parser, node);
9199 if (!node)
return 1;
9220 if (node == 0)
return 0;
9227 rb_warn0(
"string literal in condition");
9237 node->nd_1st =
cond0(parser, node->nd_1st);
9238 node->nd_2nd =
cond0(parser, node->nd_2nd);
9243 node->nd_beg =
range_op(parser, node->nd_beg);
9244 node->nd_end =
range_op(parser, node->nd_end);
9277 if (node == 0)
return 0;
9278 return cond0(parser, node);
9286 NODE *node = left, *second;
9287 while ((second = node->nd_2nd) != 0 && (
enum node_type)
nd_type(second) == type) {
9290 node->nd_2nd =
NEW_NODE(type, second, right, 0);
9293 return NEW_NODE(type, left, right, 0);
9310 if (node->nd_next == 0) {
9311 node = node->nd_head;
9332 switch (
TYPE(node->nd_lit)) {
9361 node2->nd_head = node1;
9375 args->
pre_init = m ? m->nd_next : 0;
9448 ID vid = lhs->nd_vid;
9450 lhs->nd_value = rhs;
9457 lhs->nd_value = rhs;
9511 return dispatch3(opassign, lhs, op, rhs);
9517 VALUE recv = dispatch3(field, lhs, type, attr);
9518 return dispatch3(opassign, recv, op, rhs);
9528 if (!local->
used)
return;
9532 if (cnt != local->
vars->
pos) {
9533 rb_bug(
"local->used->pos != local->vars->pos");
9535 for (i = 0; i <
cnt; ++
i) {
9536 if (!v[i] || (u[i] &
LVAR_USED))
continue;
9551 local->
used = !(inherit_dvars &&
9580 int cnt = cnt_args + cnt_vars;
9584 if (cnt <= 0)
return 0;
9588 for (i = 0, j = cnt_args+1; i < cnt_vars; ++
i) {
9629 if (used) used = used->
prev;
9645 static const struct vtable *
9661 if ((tmp =
lvtbl->used) != 0) {
9677 while (
lvtbl->args != lvargs) {
9715 if (used) used = used->
prev;
9768 "regexp encoding option '%c' differs from source encoding '%s'",
9797 int back_num,
int *back_refs,
OnigRegex regex,
void *arg0)
9802 long len = name_end -
name;
9803 const char *s = (
const char *)name;
9820 rb_warningS(
"named capture conflicts a local variable - %s",
9903 if (!node)
return node;
9907 node = node->nd_body;
9911 node = node->nd_body;
9918 prelude->nd_body = node;
9919 scope->nd_body = prelude;
9922 scope->nd_body = node;
9935 if (!node)
return node;
9939 node = node->nd_body;
9943 node = node->nd_body;
9959 prelude->nd_body = node;
9960 scope->nd_body = prelude;
9963 scope->nd_body = node;
9969 static const struct {
9994 #define op_tbl_count numberof(op_tbl)
9996 #ifndef ENABLE_SELECTOR_NAMESPACE
9997 #define ENABLE_SELECTOR_NAMESPACE 0
10004 #if ENABLE_SELECTOR_NAMESPACE
10016 #if ENABLE_SELECTOR_NAMESPACE
10023 ivar2_cmp(
struct ivar2_key *key1,
struct ivar2_key *key2)
10025 if (key1->id == key2->id && key1->klass == key2->klass) {
10032 ivar2_hash(
struct ivar2_key *
key)
10034 return (key->id << 8) ^ (key->klass >> 2);
10048 #if ENABLE_SELECTOR_NAMESPACE
10056 (
void)lex_state_name(-1);
10085 if (m >= e)
return 0;
10089 else if (*m ==
'-') {
10103 return m == e ? mb + 1 : 0;
10118 #define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
10119 #define IDSET_ATTRSET_FOR_INTERN (~(~0U<<(1<<ID_SCOPE_SHIFT)) & ~(1U<<ID_ATTRSET))
10124 const char *m =
name;
10125 const char *e = m +
len;
10128 if (!m || len <= 0)
return -1;
10148 case '<': ++
m;
break;
10149 case '=':
if (*++m ==
'>') ++
m;
break;
10156 case '>':
case '=': ++
m;
break;
10162 case '~': ++
m;
break;
10163 case '=':
if (*++m ==
'=') ++
m;
break;
10164 default:
return -1;
10169 if (*++m ==
'*') ++
m;
10172 case '+':
case '-':
10173 if (*++m ==
'@') ++
m;
10176 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
10181 if (*++m !=
']')
return -1;
10182 if (*++m ==
'=') ++
m;
10186 if (len == 1)
return ID_JUNK;
10188 case '=':
case '~': ++
m;
break;
10189 default:
return -1;
10201 case '!':
case '?':
10205 if (m + 1 < e || *m !=
'=')
break;
10208 if (!(allowed_atttset & (1
U << type)))
return -1;
10215 return m == e ? type : -1;
10278 fake_str.as.heap.len =
len;
10279 fake_str.as.heap.ptr = (
char *)name;
10280 fake_str.as.heap.aux.capa =
len;
10281 str = (
VALUE)&fake_str;
10295 const char *
name, *
m, *
e;
10317 if (len < 2)
goto junk;
10326 if (len < 3)
goto junk;
10331 if (len < 2)
goto junk;
10347 if (*
op_tbl[i].name == *m &&
10348 strcmp(
op_tbl[i].name, m) == 0) {
10356 if (name[last] ==
'=') {
10358 if (last > 1 && name[last-1] ==
'=')
10368 else if (
id == 0) {
10440 name[0] = (char)
id;
10449 if (
op_tbl[i].token ==
id) {
10463 if (
RBASIC(str)->klass == 0)
10469 ID id_stem = (
id & ~ID_SCOPE_MASK);
10486 if (
RBASIC(str)->klass == 0)
10499 if (!str)
return 0;
10593 VALUE name = *namep;
10622 fake_str.as.heap.aux.capa = fake_str.as.heap.len;
10643 fake_str.as.heap.len =
len;
10644 fake_str.as.heap.ptr = (
char *)ptr;
10645 fake_str.as.heap.aux.capa =
len;
10654 fake_str.as.heap.len = len - 1;
10753 parser->delayed =
Qnil;
10755 parser->result =
Qnil;
10756 parser->parsing_thread =
Qnil;
10757 parser->toplevel_p =
TRUE;
10766 #define parser_mark ripper_parser_mark
10767 #define parser_free ripper_parser_free
10807 prev = local->
prev;
10818 size_t size =
sizeof(*p);
10820 if (!ptr)
return 0;
10823 size +=
sizeof(*local);
10843 #undef rb_reserved_word
10932 #define HEAPCNT(n, size) ((n) * (size) / sizeof(YYSTYPE))
10933 #define NEWHEAP() rb_node_newnode(NODE_ALLOCA, 0, (VALUE)parser->heap, 0)
10934 #define ADD2HEAP(n, c, p) ((parser->heap = (n))->u1.node = (p), \
10935 (n)->u3.cnt = (c), (p))
10940 size_t cnt =
HEAPCNT(1, size);
10950 size_t cnt =
HEAPCNT(nelem, size);
10952 void *ptr =
xcalloc(nelem, size);
10961 size_t cnt =
HEAPCNT(1, size);
10963 if (ptr && (n = parser->
heap) !=
NULL) {
10965 if (n->
u1.
node == ptr) {
10982 while ((n = *prev) !=
NULL) {
10983 if (n->
u1.
node == ptr) {
10996 #ifdef RIPPER_DEBUG
10997 extern int rb_is_pointer_to_heap(
VALUE);
11003 if (x ==
Qfalse)
return x;
11004 if (x ==
Qtrue)
return x;
11005 if (x ==
Qnil)
return x;
11010 if (!rb_is_pointer_to_heap(x))
11023 return ((
NODE *)x)->nd_rval;
11032 #define validate(x) ((x) = get_value(x))
11044 return rb_funcall(parser->value, mid, 1, a);
11052 return rb_funcall(parser->value, mid, 2, a, b);
11061 return rb_funcall(parser->value, mid, 3, a, b, c);
11071 return rb_funcall(parser->value, mid, 4, a, b, c, d);
11082 return rb_funcall(parser->value, mid, 5, a, b, c, d, e);
11095 return rb_funcall(parser->value, mid, 7, a, b, c, d, e, f, g);
11098 static const struct kw_assoc {
11101 } keyword_to_name[] = {
11154 keyword_id_to_str(
ID id)
11156 const struct kw_assoc *
a;
11158 for (a = keyword_to_name; a->id; a++) {
11165 #undef ripper_id2sym
11167 ripper_id2sym(
ID id)
11177 if ((name = keyword_id_to_str(
id))) {
11190 rb_bug(
"cannot convert ID to string: %ld", (
unsigned long)
id);
11198 ripper_get_id(
VALUE v)
11208 ripper_get_value(
VALUE v)
11215 return nd->nd_rval;
11224 va_start(args, fmt);
11231 ripper_warn0(
struct parser_params *parser,
const char *fmt)
11237 ripper_warnI(
struct parser_params *parser,
const char *fmt,
int a)
11244 ripper_warnS(
struct parser_params *parser,
const char *fmt,
const char *str)
11251 ripper_warning0(
struct parser_params *parser,
const char *fmt)
11257 ripper_warningS(
struct parser_params *parser,
const char *fmt,
const char *str)
11282 #define ripper_initialized_p(r) ((r)->parser_lex_input != 0)
11301 rb_scan_args(argc, argv,
"12", &src, &fname, &lineno);
11311 if (
NIL_P(fname)) {
11326 struct ripper_args {
11333 ripper_parse0(
VALUE parser_v)
11339 ripper_yyparse((
void*)parser);
11340 return parser->result;
11344 ripper_ensure(
VALUE parser_v)
11349 parser->parsing_thread =
Qnil;
11360 ripper_parse(
VALUE self)
11365 if (!ripper_initialized_p(parser)) {
11368 if (!
NIL_P(parser->parsing_thread)) {
11375 rb_ensure(ripper_parse0,
self, ripper_ensure,
self);
11377 return parser->result;
11388 ripper_column(
VALUE self)
11394 if (!ripper_initialized_p(parser)) {
11397 if (
NIL_P(parser->parsing_thread))
return Qnil;
11409 ripper_filename(
VALUE self)
11414 if (!ripper_initialized_p(parser)) {
11428 ripper_lineno(
VALUE self)
11433 if (!ripper_initialized_p(parser)) {
11436 if (
NIL_P(parser->parsing_thread))
return Qnil;
11440 #ifdef RIPPER_DEBUG
11476 InitVM_ripper(
void)
11492 #ifdef RIPPER_DEBUG
#define rb_enc_islower(c, enc)
char * parser_ruby_sourcefile
#define RB_TYPE_P(obj, type)
#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)
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)
#define IS_LABEL_SUFFIX(n)
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)
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 *)
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)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
#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)
#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_append(VALUE, VALUE)
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_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 struct @60 op_tbl[]
static NODE * attrset_gen(struct parser_params *, NODE *, ID)
NODE * rb_compile_string(const char *f, VALUE s, int line)
static int dvar_curr_gen(struct parser_params *, ID)
int rb_ascii8bit_encindex(void)
static int is_global_name_punct(const char c)
#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)
static int rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_atttset)
#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
void rb_gc_mark_symbols(void)
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 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)
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
int rb_dvar_defined(ID id)
static int arg_var_gen(struct parser_params *, ID)
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)
int rb_symname_p(const char *name)
VALUE rb_thread_current(void)
mlhs_head tSTAR mlhs_node
#define token_info_pop(token)
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 rb_node_newnode(type, a1, a2, a3)
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)
static void arg_ambiguous_gen(struct parser_params *parser)
static void parser_prepare(struct parser_params *parser)
#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)
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)
#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
#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 NEW_ATTRASGN(r, m, a)
#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 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)
VALUE rb_ary_new2(long capa)
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)
VALUE rb_str_intern(VALUE)
#define rb_enc_isupper(c, enc)
static int nodeline(NODE *node)
#define new_attr_op_assign(lhs, type, attr, op, rhs)
#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 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 *)
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)
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)
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)
static int rb_str_symname_type(VALUE name, unsigned int allowed_atttset)
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)