15 #define YYERROR_VERBOSE 1
16 #define YYSTACK_USE_ALLOCA 0
30 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
32 #define YYMALLOC(size) rb_parser_malloc(parser, (size))
33 #define YYREALLOC(ptr, size) rb_parser_realloc(parser, (ptr), (size))
34 #define YYCALLOC(nelem, size) rb_parser_calloc(parser, (nelem), (size))
35 #define YYFREE(ptr) rb_parser_free(parser, (ptr))
36 #define malloc YYMALLOC
37 #define realloc YYREALLOC
38 #define calloc YYCALLOC
43 #define REGISTER_SYMID(id, name) register_symid((id), (name), strlen(name), enc)
47 #define is_notop_id(id) ((id)>tLAST_TOKEN)
48 #define is_local_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_LOCAL)
49 #define is_global_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_GLOBAL)
50 #define is_instance_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_INSTANCE)
51 #define is_attrset_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_ATTRSET)
52 #define is_const_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CONST)
53 #define is_class_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_CLASS)
54 #define is_junk_id(id) (is_notop_id(id)&&((id)&ID_SCOPE_MASK)==ID_JUNK)
56 #define is_asgn_or_id(id) ((is_notop_id(id)) && \
57 (((id)&ID_SCOPE_MASK) == ID_GLOBAL || \
58 ((id)&ID_SCOPE_MASK) == ID_INSTANCE || \
59 ((id)&ID_SCOPE_MASK) == ID_CLASS))
78 # define BITSTACK_PUSH(stack, n) ((stack) = ((stack)<<1)|((n)&1))
79 # define BITSTACK_POP(stack) ((stack) = (stack) >> 1)
80 # define BITSTACK_LEXPOP(stack) ((stack) = ((stack) >> 1) | ((stack) & 1))
81 # define BITSTACK_SET_P(stack) ((stack)&1)
83 #define COND_PUSH(n) BITSTACK_PUSH(cond_stack, (n))
84 #define COND_POP() BITSTACK_POP(cond_stack)
85 #define COND_LEXPOP() BITSTACK_LEXPOP(cond_stack)
86 #define COND_P() BITSTACK_SET_P(cond_stack)
88 #define CMDARG_PUSH(n) BITSTACK_PUSH(cmdarg_stack, (n))
89 #define CMDARG_POP() BITSTACK_POP(cmdarg_stack)
90 #define CMDARG_LEXPOP() BITSTACK_LEXPOP(cmdarg_stack)
91 #define CMDARG_P() BITSTACK_SET_P(cmdarg_stack)
107 #define DVARS_INHERIT ((void*)1)
108 #define DVARS_TOPSCOPE NULL
109 #define DVARS_SPECIAL_P(tbl) (!POINTER_P(tbl))
110 #define POINTER_P(val) ((VALUE)(val) & ~(VALUE)3)
133 if (
VTBL_DEBUG) printf(
"vtable_alloc: %p\n", (
void *)tbl);
140 if (
VTBL_DEBUG)printf(
"vtable_free: %p\n", (
void *)tbl);
153 rb_bug(
"vtable_add: vtable is not allocated (%p)", (
void *)tbl);
170 for (i = 0; i < tbl->
pos; i++) {
171 if (tbl->
tbl[i] ==
id) {
255 VALUE parser_ruby_sourcefile_string;
263 VALUE parsing_thread;
268 #define UTF8_ENC() (parser->utf8 ? parser->utf8 : \
269 (parser->utf8 = rb_utf8_encoding()))
270 #define STR_NEW(p,n) rb_enc_str_new((p),(n),parser->enc)
271 #define STR_NEW0() rb_enc_str_new(0,0,parser->enc)
272 #define STR_NEW2(p) rb_enc_str_new((p),strlen(p),parser->enc)
273 #define STR_NEW3(p,n,e,func) parser_str_new((p),(n),(e),(func),parser->enc)
274 #define ENC_SINGLE(cr) ((cr)==ENC_CODERANGE_7BIT)
275 #define TOK_INTERN(mb) rb_intern3(tok(), toklen(), parser->enc)
278 #define yyerror(msg) parser_yyerror(parser, (msg))
280 #define YYLEX_PARAM parser
282 #define lex_strterm (parser->parser_lex_strterm)
283 #define lex_state (parser->parser_lex_state)
284 #define cond_stack (parser->parser_cond_stack)
285 #define cmdarg_stack (parser->parser_cmdarg_stack)
286 #define class_nest (parser->parser_class_nest)
287 #define paren_nest (parser->parser_paren_nest)
288 #define lpar_beg (parser->parser_lpar_beg)
289 #define in_single (parser->parser_in_single)
290 #define in_def (parser->parser_in_def)
291 #define compile_for_eval (parser->parser_compile_for_eval)
292 #define cur_mid (parser->parser_cur_mid)
293 #define in_defined (parser->parser_in_defined)
294 #define tokenbuf (parser->parser_tokenbuf)
295 #define tokidx (parser->parser_tokidx)
296 #define toksiz (parser->parser_toksiz)
297 #define lex_input (parser->parser_lex_input)
298 #define lex_lastline (parser->parser_lex_lastline)
299 #define lex_nextline (parser->parser_lex_nextline)
300 #define lex_pbeg (parser->parser_lex_pbeg)
301 #define lex_p (parser->parser_lex_p)
302 #define lex_pend (parser->parser_lex_pend)
303 #define heredoc_end (parser->parser_heredoc_end)
304 #define command_start (parser->parser_command_start)
305 #define deferred_nodes (parser->parser_deferred_nodes)
306 #define lex_gets_ptr (parser->parser_lex_gets_ptr)
307 #define lex_gets (parser->parser_lex_gets)
308 #define lvtbl (parser->parser_lvtbl)
309 #define ruby__end__seen (parser->parser_ruby__end__seen)
310 #define ruby_sourceline (parser->parser_ruby_sourceline)
311 #define ruby_sourcefile (parser->parser_ruby_sourcefile)
312 #define current_enc (parser->enc)
313 #define yydebug (parser->parser_yydebug)
316 #define ruby_eval_tree (parser->parser_eval_tree)
317 #define ruby_eval_tree_begin (parser->parser_eval_tree_begin)
318 #define ruby_debug_lines (parser->debug_lines)
319 #define ruby_coverage (parser->coverage)
322 static int yylex(
void*,
void*);
325 #define yyparse ruby_yyparse
328 #define rb_node_newnode(type, a1, a2, a3) node_newnode(parser, (type), (a1), (a2), (a3))
331 #define cond(node) cond_gen(parser, (node))
333 #define logop(type,node1,node2) logop_gen(parser, (type), (node1), (node2))
341 #define value_expr(node) value_expr_gen(parser, (node) = remove_begin(node))
342 #define void_expr0(node) void_expr_gen(parser, (node))
343 #define void_expr(node) void_expr0((node) = remove_begin(node))
345 #define void_stmts(node) void_stmts_gen(parser, (node))
347 #define reduce_nodes(n) reduce_nodes_gen(parser,(n))
349 #define block_dup_check(n1,n2) block_dup_check_gen(parser,(n1),(n2))
352 #define block_append(h,t) block_append_gen(parser,(h),(t))
354 #define list_append(l,i) list_append_gen(parser,(l),(i))
356 #define list_concat(h,t) list_concat_gen(parser,(h),(t))
358 #define arg_append(h,t) arg_append_gen(parser,(h),(t))
360 #define arg_concat(h,t) arg_concat_gen(parser,(h),(t))
362 #define literal_concat(h,t) literal_concat_gen(parser,(h),(t))
365 #define new_evstr(n) new_evstr_gen(parser,(n))
367 #define evstr2dstr(n) evstr2dstr_gen(parser,(n))
371 #define call_bin_op(recv,id,arg1) call_bin_op_gen(parser, (recv),(id),(arg1))
373 #define call_uni_op(recv,id) call_uni_op_gen(parser, (recv),(id))
376 #define new_args(f,o,r,p,b) new_args_gen(parser, (f),(o),(r),(p),(b))
380 #define ret_args(node) ret_args_gen(parser, (node))
383 #define new_yield(node) new_yield_gen(parser, (node))
386 #define gettable(id) gettable_gen(parser,(id))
388 #define assignable(id,node) assignable_gen(parser, (id), (node))
391 #define aryset(node1,node2) aryset_gen(parser, (node1), (node2))
393 #define attrset(node,id) attrset_gen(parser, (node), (id))
396 #define rb_backref_error(n) rb_backref_error_gen(parser,(n))
398 #define node_assign(node1, node2) node_assign_gen(parser, (node1), (node2))
401 #define match_op(node1,node2) match_op_gen(parser, (node1), (node2))
404 #define local_tbl() local_tbl_gen(parser)
409 #define reg_compile(str,options) reg_compile_gen(parser, (str), (options))
411 #define reg_fragment_setenc(str,options) reg_fragment_setenc_gen(parser, (str), (options))
413 #define reg_fragment_check(str,options) reg_fragment_check_gen(parser, (str), (options))
415 #define reg_named_capture_assign(regexp,match) reg_named_capture_assign_gen(parser,(regexp),(match))
417 #define get_id(id) (id)
418 #define get_value(val) (val)
420 #define remove_begin(node) (node)
421 #define rb_dvar_defined(id) 0
422 #define rb_local_defined(id) 0
423 static ID ripper_get_id(
VALUE);
424 #define get_id(id) ripper_get_id(id)
426 #define get_value(val) ripper_get_value(val)
428 #define assignable(lhs,node) assignable_gen(parser, (lhs))
430 #define id_is_var(id) id_is_var_gen(parser, (id))
434 #define formal_argument(id) formal_argument_gen(parser, (id))
436 #define shadowing_lvar(name) shadowing_lvar_gen(parser, (name))
438 #define new_bv(id) new_bv_gen(parser, (id))
441 #define local_push(top) local_push_gen(parser,(top))
443 #define local_pop() local_pop_gen(parser)
445 #define local_var(id) local_var_gen(parser, (id));
447 #define arg_var(id) arg_var_gen(parser, (id))
449 #define local_id(id) local_id_gen(parser, (id))
451 #define internal_id() internal_id_gen(parser)
454 #define dyna_push() dyna_push_gen(parser)
456 #define dyna_pop(node) dyna_pop_gen(parser, (node))
458 #define dyna_in_block() dyna_in_block_gen(parser)
459 #define dyna_var(id) local_var(id)
461 #define dvar_defined(id) dvar_defined_gen(parser, (id), 0)
462 #define dvar_defined_get(id) dvar_defined_gen(parser, (id), 1)
464 #define dvar_curr(id) dvar_curr_gen(parser, (id))
467 #define lvar_defined(id) lvar_defined_gen(parser, (id))
469 #define RE_OPTION_ONCE (1<<16)
470 #define RE_OPTION_ENCODING_SHIFT 8
471 #define RE_OPTION_ENCODING(e) (((e)&0xff)<<RE_OPTION_ENCODING_SHIFT)
472 #define RE_OPTION_ENCODING_IDX(o) (((o)>>RE_OPTION_ENCODING_SHIFT)&0xff)
473 #define RE_OPTION_ENCODING_NONE(o) ((o)&RE_OPTION_ARG_ENCODING_NONE)
474 #define RE_OPTION_MASK 0xff
475 #define RE_OPTION_ARG_ENCODING_NONE 32
477 #define NODE_STRTERM NODE_ZARRAY
478 #define NODE_HEREDOC NODE_ARRAY
479 #define SIGN_EXTEND(x,n) (((1<<(n)-1)^((x)&~(~0<<(n))))-(1<<(n)-1))
480 #define nd_func u1.id
481 #if SIZEOF_SHORT == 2
482 #define nd_term(node) ((signed short)(node)->u2.id)
484 #define nd_term(node) SIGN_EXTEND((node)->u2.id, CHAR_BIT*2)
486 #define nd_paren(node) (char)((node)->u2.id >> CHAR_BIT*2)
487 #define nd_nest u3.cnt
492 #define RIPPER_VERSION "0.1.0"
496 static ID ripper_id_gets;
505 #define dispatch0(n) ripper_dispatch0(parser, TOKEN_PASTE(ripper_id_, n))
506 #define dispatch1(n,a) ripper_dispatch1(parser, TOKEN_PASTE(ripper_id_, n), (a))
507 #define dispatch2(n,a,b) ripper_dispatch2(parser, TOKEN_PASTE(ripper_id_, n), (a), (b))
508 #define dispatch3(n,a,b,c) ripper_dispatch3(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c))
509 #define dispatch4(n,a,b,c,d) ripper_dispatch4(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d))
510 #define dispatch5(n,a,b,c,d,e) ripper_dispatch5(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d), (e))
512 #define yyparse ripper_yyparse
514 #define ripper_intern(s) ID2SYM(rb_intern(s))
517 #define ripper_id2sym(id) ((id) < 256 && rb_ispunct(id) ? \
518 ID2SYM(id) : ripper_id2sym(id))
521 #define arg_new() dispatch0(args_new)
522 #define arg_add(l,a) dispatch2(args_add, (l), (a))
523 #define arg_add_star(l,a) dispatch2(args_add_star, (l), (a))
524 #define arg_add_block(l,b) dispatch2(args_add_block, (l), (b))
525 #define arg_add_optblock(l,b) ((b)==Qundef? (l) : dispatch2(args_add_block, (l), (b)))
526 #define bare_assoc(v) dispatch1(bare_assoc_hash, (v))
527 #define arg_add_assocs(l,b) arg_add((l), bare_assoc(b))
529 #define args2mrhs(a) dispatch1(mrhs_new_from_args, (a))
530 #define mrhs_new() dispatch0(mrhs_new)
531 #define mrhs_add(l,a) dispatch2(mrhs_add, (l), (a))
532 #define mrhs_add_star(l,a) dispatch2(mrhs_add_star, (l), (a))
534 #define mlhs_new() dispatch0(mlhs_new)
535 #define mlhs_add(l,a) dispatch2(mlhs_add, (l), (a))
536 #define mlhs_add_star(l,a) dispatch2(mlhs_add_star, (l), (a))
538 #define params_new(pars, opts, rest, pars2, blk) \
539 dispatch5(params, (pars), (opts), (rest), (pars2), (blk))
541 #define blockvar_new(p,v) dispatch2(block_var, (p), (v))
542 #define blockvar_add_star(l,a) dispatch2(block_var_add_star, (l), (a))
543 #define blockvar_add_block(l,a) dispatch2(block_var_add_block, (l), (a))
545 #define method_optarg(m,a) ((a)==Qundef ? (m) : dispatch2(method_add_arg,(m),(a)))
546 #define method_arg(m,a) dispatch2(method_add_arg,(m),(a))
547 #define method_add_block(m,b) dispatch2(method_add_block, (m), (b))
549 #define escape_Qundef(x) ((x)==Qundef ? Qnil : (x))
556 # define ifndef_ripper(x) (x)
558 # define ifndef_ripper(x)
562 # define rb_warn0(fmt) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt))
563 # define rb_warnI(fmt,a) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt), (a))
564 # define rb_warnS(fmt,a) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt), (a))
565 # define rb_warning0(fmt) rb_compile_warning(ruby_sourcefile, ruby_sourceline, (fmt))
566 # define rb_warningS(fmt,a) rb_compile_warning(ruby_sourcefile, ruby_sourceline, (fmt), (a))
568 # define rb_warn0(fmt) ripper_warn0(parser, (fmt))
569 # define rb_warnI(fmt,a) ripper_warnI(parser, (fmt), (a))
570 # define rb_warnS(fmt,a) ripper_warnS(parser, (fmt), (a))
571 # define rb_warning0(fmt) ripper_warning0(parser, (fmt))
572 # define rb_warningS(fmt,a) ripper_warningS(parser, (fmt), (a))
573 static void ripper_warn0(
struct parser_params*,
const char*);
574 static void ripper_warnI(
struct parser_params*,
const char*,
int);
576 static void ripper_warnS(
struct parser_params*,
const char*,
const char*);
578 static void ripper_warning0(
struct parser_params*,
const char*);
579 static void ripper_warningS(
struct parser_params*,
const char*,
const char*);
583 static void ripper_compile_error(
struct parser_params*,
const char *fmt, ...);
584 # define rb_compile_error ripper_compile_error
585 # define compile_error ripper_compile_error
586 # define PARSER_ARG parser,
588 # define rb_compile_error rb_compile_error_with_enc
589 # define compile_error parser->nerr++,rb_compile_error_with_enc
590 # define PARSER_ARG ruby_sourcefile, ruby_sourceline, current_enc,
598 #define YYMAXDEPTH 10000
605 #define token_info_push(token) (RTEST(ruby_verbose) ? token_info_push(parser, (token)) : (void)0)
606 #define token_info_pop(token) (RTEST(ruby_verbose) ? token_info_pop(parser, (token)) : (void)0)
608 #define token_info_push(token)
609 #define token_info_pop(token)
621 const struct vtable *vars;
684 %type <node> singleton strings
string string1 xstring regexp
685 %type <node> string_contents xstring_contents regexp_contents string_content
686 %type <node> words qwords word_list qword_list word
687 %type <node> literal numeric dsym cpath
688 %type <node> top_compstmt top_stmts
top_stmt
690 %type <node>
expr_value arg_value primary_value
691 %type <node> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
693 %type <node> paren_args opt_paren_args
694 %type <node>
command_args aref_args opt_block_arg block_arg var_ref var_lhs
695 %type <node> command_asgn mrhs superclass block_call block_command
696 %type <node> f_block_optarg f_block_opt
697 %type <node> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
698 %type <node> assoc_list assocs assoc
undef_list backref string_dvar for_var
699 %type <node> block_param opt_block_param block_param_def f_opt
700 %type <node> bv_decls opt_bv_decl bvar
701 %type <node> lambda f_larglist lambda_body
705 %type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
798 while (node->nd_next) {
799 node = node->nd_next;
813 top_compstmt : top_stmts opt_terms
891 rb_warn0(
"else without rescue is useless");
985 yyerror(
"can't make alias for the number variables");
1056 rb_warn0(
"END in method; use at_exit");
1081 ID vid = $1->nd_vid;
1163 yyerror(
"constant re-assignment");
1207 | mlhs
'=' arg_value
1301 block_command : block_call
1378 $5->nd_iter =
NEW_CALL($1, $3, $4);
1399 $5->nd_iter =
NEW_CALL($1, $3, $4);
1614 | primary_value
'[' opt_call_args rbracket
1650 yyerror(
"dynamic constant assignment");
1662 yyerror(
"dynamic constant assignment");
1698 | primary_value
'[' opt_call_args rbracket
1734 yyerror(
"dynamic constant assignment");
1747 yyerror(
"dynamic constant assignment");
1770 yyerror(
"class/module name must be CONSTANT");
1925 ID vid = $1->nd_vid;
1955 ID vid = $1->nd_vid;
1980 | primary_value
'[' opt_call_args rbracket
tOP_ASGN arg
2060 yyerror(
"constant re-assignment");
2071 yyerror(
"constant re-assignment");
2398 | args
',' assocs trailer
2416 paren_args :
'(' opt_call_args rparen
2426 opt_paren_args : none
2430 opt_call_args : none
2436 | args
',' assocs
','
2463 | args opt_block_arg
2471 | assocs opt_block_arg
2481 | args
',' assocs opt_block_arg
2511 block_arg :
tAMPER arg_value
2521 opt_block_arg :
',' block_arg
2547 | args
',' arg_value
2561 | args
',' tSTAR arg_value
2577 mrhs : args
',' arg_value
2591 | args
',' tSTAR arg_value
2659 rb_warning0(
"(...) interpreted as grouped expression");
2769 | operation brace_block
2781 | method_call brace_block
2853 | k_case opt_terms case_body k_end
2920 tbl[0] = 1; tbl[1] =
id;
2927 | k_class cpath superclass
2930 yyerror(
"class definition in method body");
2975 yyerror(
"module definition in method body");
3071 primary_value : primary
3221 f_marg_list : f_marg
3229 | f_marg_list
',' f_marg
3239 f_margs : f_marg_list
3247 | f_marg_list
',' tSTAR f_norm_arg
3256 | f_marg_list
',' tSTAR f_norm_arg
',' f_marg_list
3265 | f_marg_list
',' tSTAR
3273 | f_marg_list
',' tSTAR ',' f_marg_list
3290 |
tSTAR f_norm_arg
',' f_marg_list
3310 |
tSTAR ',' f_marg_list
3320 block_param : f_arg
',' f_block_optarg
',' f_rest_arg opt_f_block_arg
3328 | f_arg
',' f_block_optarg
',' f_rest_arg
',' f_arg opt_f_block_arg
3336 | f_arg
',' f_block_optarg opt_f_block_arg
3344 | f_arg
',' f_block_optarg
',' f_arg opt_f_block_arg
3352 | f_arg
',' f_rest_arg opt_f_block_arg
3369 | f_arg
',' f_rest_arg
',' f_arg opt_f_block_arg
3377 | f_arg opt_f_block_arg
3385 | f_block_optarg
',' f_rest_arg opt_f_block_arg
3393 | f_block_optarg
',' f_rest_arg
',' f_arg opt_f_block_arg
3401 | f_block_optarg opt_f_block_arg
3409 | f_block_optarg
',' f_arg opt_f_block_arg
3417 | f_rest_arg opt_f_block_arg
3425 | f_rest_arg
',' f_arg opt_f_block_arg
3443 opt_block_param : none
3450 block_param_def :
'|' opt_bv_decl
'|'
3468 |
'|' block_param opt_bv_decl
'|'
3541 f_larglist :
'(' f_args opt_bv_decl rparen
3590 block_call : command do_block
3606 | block_call
'.' operation2 opt_paren_args
3615 | block_call
tCOLON2 operation2 opt_paren_args
3626 method_call : operation paren_args
3635 | primary_value
'.' operation2 opt_paren_args
3645 | primary_value
tCOLON2 operation2 paren_args
3655 | primary_value
tCOLON2 operation3
3663 | primary_value
'.' paren_args
3674 | primary_value
tCOLON2 paren_args
3701 | primary_value
'[' opt_call_args rbracket
3793 exc_list : arg_value
3920 VALUE src = node->nd_lit;
3936 for (list = (prev = node)->
nd_next;
list; list = list->nd_next) {
3938 VALUE tail = list->nd_head->nd_lit;
3940 VALUE lit = prev == node ? prev->nd_lit : prev->nd_head->nd_lit;
3946 prev->nd_next = list->nd_next;
3959 if (!node->nd_next) {
3960 VALUE src = node->nd_lit;
4000 | word_list word
' '
4010 word : string_content
4018 | word string_content
4073 | string_contents string_content
4091 | xstring_contents string_content
4109 | regexp_contents string_content
4112 NODE *head = $1, *tail = $2;
4291 var_ref : user_variable
4314 var_lhs : user_variable
4364 f_arglist :
'(' f_args rparen
4382 f_args : f_arg
',' f_optarg
',' f_rest_arg opt_f_block_arg
4390 | f_arg
',' f_optarg
',' f_rest_arg
',' f_arg opt_f_block_arg
4398 | f_arg
',' f_optarg opt_f_block_arg
4406 | f_arg
',' f_optarg
',' f_arg opt_f_block_arg
4414 | f_arg
',' f_rest_arg opt_f_block_arg
4422 | f_arg
',' f_rest_arg
',' f_arg opt_f_block_arg
4430 | f_arg opt_f_block_arg
4438 | f_optarg
',' f_rest_arg opt_f_block_arg
4446 | f_optarg
',' f_rest_arg
',' f_arg opt_f_block_arg
4454 | f_optarg opt_f_block_arg
4462 | f_optarg
',' f_arg opt_f_block_arg
4470 | f_rest_arg opt_f_block_arg
4478 | f_rest_arg
',' f_arg opt_f_block_arg
4507 yyerror(
"formal argument cannot be a constant");
4516 yyerror(
"formal argument cannot be an instance variable");
4525 yyerror(
"formal argument cannot be a global variable");
4534 yyerror(
"formal argument cannot be a class variable");
4542 f_norm_arg : f_bad_arg
4550 f_arg_item : f_norm_arg
4585 | f_arg
',' f_arg_item
4622 f_block_optarg : f_block_opt
4630 | f_block_optarg
',' f_block_opt
4635 while (opts->nd_next) {
4636 opts = opts->nd_next;
4654 | f_optarg
',' f_opt
4659 while (opts->nd_next) {
4660 opts = opts->nd_next;
4678 yyerror(
"rest argument must be local variable");
4706 yyerror(
"block argument must be local variable");
4708 yyerror(
"duplicated block argument name");
4719 opt_f_block_arg :
',' f_block_arg
4747 yyerror(
"can't define singleton method for ().");
4759 yyerror(
"can't define singleton method for literals");
4800 assoc : arg_value
tASSOC arg_value
4857 rbracket : opt_nl
']'
4886 # define yylval (*((YYSTYPE*)(parser->parser_yylval)))
4895 # define nextc() parser_nextc(parser)
4896 # define pushback(c) parser_pushback(parser, (c))
4897 # define newtok() parser_newtok(parser)
4898 # define tokspace(n) parser_tokspace(parser, (n))
4899 # define tokadd(c) parser_tokadd(parser, (c))
4900 # define tok_hex(numlen) parser_tok_hex(parser, (numlen))
4901 # define read_escape(flags,e) parser_read_escape(parser, (flags), (e))
4902 # define tokadd_escape(e) parser_tokadd_escape(parser, (e))
4903 # define regx_options() parser_regx_options(parser)
4904 # define tokadd_string(f,t,p,n,e) parser_tokadd_string(parser,(f),(t),(p),(n),(e))
4905 # define parse_string(n) parser_parse_string(parser,(n))
4906 # define tokaddmbc(c, enc) parser_tokaddmbc(parser, (c), (enc))
4907 # define here_document(n) parser_here_document(parser,(n))
4908 # define heredoc_identifier() parser_heredoc_identifier(parser)
4909 # define heredoc_restore(n) parser_heredoc_restore(parser,(n))
4910 # define whole_match_p(e,l,i) parser_whole_match_p(parser,(e),(l),(i))
4913 # define set_yylval_str(x) (yylval.node = NEW_STR(x))
4914 # define set_yylval_num(x) (yylval.num = (x))
4915 # define set_yylval_id(x) (yylval.id = (x))
4916 # define set_yylval_name(x) (yylval.id = (x))
4917 # define set_yylval_literal(x) (yylval.node = NEW_LIT(x))
4918 # define set_yylval_node(x) (yylval.node = (x))
4919 # define yylval_id() (yylval.id)
4922 ripper_yylval_id(
ID x)
4926 # define set_yylval_str(x) (void)(x)
4927 # define set_yylval_num(x) (void)(x)
4928 # define set_yylval_id(x) (void)(x)
4929 # define set_yylval_name(x) (void)(yylval.val = ripper_yylval_id(x))
4930 # define set_yylval_literal(x) (void)(x)
4931 # define set_yylval_node(x) (void)(x)
4932 # define yylval_id() yylval.id
4936 #define ripper_flush(p) (void)(p)
4938 #define ripper_flush(p) ((p)->tokp = (p)->parser_lex_p)
4940 #define yylval_rval (*(RB_TYPE_P(yylval.val, T_NODE) ? &yylval.node->nd_rval : &yylval.val))
4947 return lex_p > parser->tokp;
4960 ripper_dispatch_scan_event(
struct parser_params *parser,
int t)
4962 if (!ripper_has_scan_event(parser))
return;
4963 yylval_rval = ripper_scan_event_val(parser, t);
4967 ripper_dispatch_ignored_scan_event(
struct parser_params *parser,
int t)
4969 if (!ripper_has_scan_event(parser))
return;
4970 (void)ripper_scan_event_val(parser, t);
4974 ripper_dispatch_delayed_token(
struct parser_params *parser,
int t)
4977 const char *saved_tokp = parser->tokp;
4980 parser->tokp =
lex_pbeg + parser->delayed_col;
4982 parser->delayed =
Qnil;
4984 parser->tokp = saved_tokp;
4995 #undef SIGN_EXTEND_CHAR
4997 # define SIGN_EXTEND_CHAR(c) ((signed char)(c))
5000 # define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
5003 #define parser_encoding_name() (parser->enc->name)
5004 #define parser_mbclen() mbclen((lex_p-1),lex_pend,parser->enc)
5005 #define parser_precise_mbclen() rb_enc_precise_mbclen((lex_p-1),lex_pend,parser->enc)
5006 #define is_identchar(p,e,enc) (rb_enc_isalnum(*(p),(enc)) || (*(p)) == '_' || !ISASCII(*(p)))
5007 #define parser_is_identchar() (!parser->eofp && is_identchar((lex_p-1),lex_pend,parser->enc))
5009 #define parser_isascii() ISASCII(*(lex_p-1))
5017 for (p =
lex_pbeg; p < pend; p++) {
5019 column = (((column - 1) / 8) + 1) * 8;
5030 for (p =
lex_pbeg; p < pend; p++) {
5031 if (*p !=
' ' && *p !=
'\t') {
5038 #undef token_info_push
5055 #undef token_info_pop
5062 if (!ptinfo)
return;
5068 if (linenum == ptinfo->
linenum) {
5076 "mismatched indentations at '%s' with '%s' at %d",
5089 const int max_line_margin = 30;
5098 if (*p ==
'\n')
break;
5105 if (*pe ==
'\n')
break;
5112 const char *pre =
"", *post =
"";
5114 if (len > max_line_margin * 2 + 10) {
5115 if (
lex_p - p > max_line_margin) {
5119 if (pe -
lex_p > max_line_margin) {
5126 MEMCPY(buf, p,
char, len);
5130 i = (int)(
lex_p - p);
5131 p2 =
buf; pe = buf +
len;
5134 if (*p2 !=
'\t') *p2 =
' ';
5142 dispatch1(parse_error,
STR_NEW2(msg));
5154 CONST_ID(script_lines,
"SCRIPT_LINES__");
5171 if (
RTEST(coverages) &&
RBASIC(coverages)->klass == 0) {
5175 RBASIC(lines)->klass = 0;
5177 RARRAY(lines)->as.heap.len = n;
5260 char *beg, *end, *pend;
5270 while (end < pend) {
5271 if (*end++ ==
'\n')
break;
5281 if (
NIL_P(line))
return line;
5382 #define STR_FUNC_ESCAPE 0x01
5383 #define STR_FUNC_EXPAND 0x02
5384 #define STR_FUNC_REGEXP 0x04
5385 #define STR_FUNC_QWORDS 0x08
5386 #define STR_FUNC_SYMBOL 0x10
5387 #define STR_FUNC_INDENT 0x20
5417 #define lex_goto_eol(parser) ((parser)->parser_lex_p = (parser)->parser_lex_pend)
5418 #define lex_eol_p() (lex_p >= lex_pend)
5419 #define peek(c) peek_n((c), 0)
5420 #define peek_n(c,n) (lex_p+(n) < lex_pend && (c) == (unsigned char)lex_p[n])
5443 if (
NIL_P(parser->delayed)) {
5447 parser->tokp,
lex_pend - parser->tokp);
5449 parser->delayed_col = (int)(parser->tokp -
lex_pbeg);
5453 parser->tokp,
lex_pend - parser->tokp);
5469 c = (
unsigned char)*
lex_p++;
5470 if (c ==
'\r' &&
peek(
'\n')) {
5481 if (c == -1)
return;
5488 #define was_bol() (lex_p == lex_pbeg + 1)
5490 #define tokfix() (tokenbuf[tokidx]='\0')
5491 #define tok() tokenbuf
5492 #define toklen() tokidx
5493 #define toklast() (tokidx>0?tokenbuf[tokidx-1]:0)
5539 yyerror(
"invalid hex escape");
5546 #define tokcopy(n) memcpy(tokspace(n), lex_p - (n), (n))
5550 int string_literal,
int symbol_literal,
int regexp_literal)
5570 yyerror(
"invalid Unicode escape");
5573 if (codepoint > 0x10ffff) {
5574 yyerror(
"invalid Unicode codepoint (too large)");
5578 if (regexp_literal) {
5581 else if (codepoint >= 0x80) {
5583 if (string_literal)
tokaddmbc(codepoint, *encp);
5585 else if (string_literal) {
5588 }
while (string_literal && (
peek(
' ') ||
peek(
'\t')));
5591 yyerror(
"unterminated Unicode escape");
5595 if (regexp_literal) {
tokadd(
'}'); }
5601 yyerror(
"invalid Unicode escape");
5605 if (regexp_literal) {
5608 else if (codepoint >= 0x80) {
5610 if (string_literal)
tokaddmbc(codepoint, *encp);
5612 else if (string_literal) {
5620 #define ESCAPE_CONTROL 1
5621 #define ESCAPE_META 2
5630 switch (c =
nextc()) {
5655 case '0':
case '1':
case '2':
case '3':
5656 case '4':
case '5':
case '6':
case '7':
5664 if (numlen == 0)
return 0;
5675 if ((c =
nextc()) !=
'-') {
5679 if ((c =
nextc()) ==
'\\') {
5680 if (
peek(
'u'))
goto eof;
5681 return read_escape(flags|ESCAPE_META, encp) | 0x80;
5683 else if (c == -1 || !
ISASCII(c))
goto eof;
5685 return ((c & 0xff) | 0x80);
5689 if ((c =
nextc()) !=
'-') {
5695 if ((c =
nextc())==
'\\') {
5696 if (
peek(
'u'))
goto eof;
5701 else if (c == -1 || !
ISASCII(c))
goto eof;
5706 yyerror(
"Invalid escape character syntax");
5729 switch (c =
nextc()) {
5733 case '0':
case '1':
case '2':
case '3':
5734 case '4':
case '5':
case '6':
case '7':
5737 if (numlen == 0)
goto eof;
5746 if (numlen == 0)
return -1;
5752 if (flags & ESCAPE_META)
goto eof;
5753 if ((c =
nextc()) !=
'-') {
5762 if (flags & ESCAPE_CONTROL)
goto eof;
5763 if ((c =
nextc()) !=
'-') {
5771 if (flags & ESCAPE_CONTROL)
goto eof;
5775 if ((c =
nextc()) ==
'\\') {
5778 else if (c == -1)
goto eof;
5784 yyerror(
"Invalid escape character syntax");
5853 #define tokadd_mbchar(c) parser_tokadd_mbchar(parser, (c))
5857 int func,
int term,
int paren,
long *nest,
5861 int has_nonascii = 0;
5864 static const char mixed_msg[] =
"%s mixed within %s source";
5866 #define mixed_error(enc1, enc2) if (!errbuf) { \
5867 size_t len = sizeof(mixed_msg) - 4; \
5868 len += strlen(rb_enc_name(enc1)); \
5869 len += strlen(rb_enc_name(enc2)); \
5870 errbuf = ALLOCA_N(char, len); \
5871 snprintf(errbuf, len, mixed_msg, \
5872 rb_enc_name(enc1), \
5873 rb_enc_name(enc2)); \
5876 #define mixed_escape(beg, enc1, enc2) do { \
5877 const char *pos = lex_p; \
5879 mixed_error((enc1), (enc2)); \
5883 while ((c =
nextc()) != -1) {
5884 if (paren && c == paren) {
5887 else if (c == term) {
5888 if (!nest || !*nest) {
5896 if (c2 ==
'$' || c2 ==
'@' || c2 ==
'{') {
5901 else if (c ==
'\\') {
5902 const char *beg =
lex_p - 1;
5907 if (func & STR_FUNC_EXPAND)
continue;
5916 if ((func & STR_FUNC_EXPAND) == 0) {
5922 func & STR_FUNC_REGEXP);
5923 if (has_nonascii && enc != *encp) {
5929 if (c == -1)
return -1;
5931 if ((func & STR_FUNC_EXPAND) == 0)
tokadd(
'\\');
5934 if (func & STR_FUNC_REGEXP) {
5938 if (has_nonascii && enc != *encp) {
5943 else if (func & STR_FUNC_EXPAND) {
5945 if (func & STR_FUNC_ESCAPE)
tokadd(
'\\');
5948 else if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
5951 else if (c != term && !(paren && c == paren)) {
5968 else if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
5985 #define NEW_STRTERM(func, term, paren) \
5986 rb_node_newnode(NODE_STRTERM, (func), (term) | ((paren) << (CHAR_BIT * 2)), 0)
5992 if (!
NIL_P(parser->delayed)) {
5993 ptrdiff_t len =
lex_p - parser->tokp;
5998 parser->tokp =
lex_p;
6002 #define flush_string_content(enc) ripper_flush_string_content(parser, (enc))
6004 #define flush_string_content(enc) ((void)(enc))
6010 int func = (int)quote->nd_func;
6018 if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
6022 if (c == term && !quote->nd_nest) {
6023 if (func & STR_FUNC_QWORDS) {
6024 quote->nd_func = -1;
6027 if (!(func & STR_FUNC_REGEXP))
return tSTRING_END;
6036 if ((func & STR_FUNC_EXPAND) && c ==
'#') {
6037 switch (c =
nextc()) {
6051 if (func & STR_FUNC_REGEXP) {
6073 int c =
nextc(), term, func = 0;
6091 while ((c =
nextc()) != -1 && c != term) {
6138 line = here->nd_orig;
6142 lex_p = lex_pbeg + here->nd_nth;
6152 const char *eos,
long len,
int indent)
6158 while (*p &&
ISSPACE(*p)) p++;
6161 if (n < 0 || (n > 0 && p[len] !=
'\n' && p[len] !=
'\r'))
return FALSE;
6162 return strncmp(eos, p, len) == 0;
6169 if (!
NIL_P(parser->delayed))
6172 ripper_dispatch_ignored_scan_event(parser,
tHEREDOC_END);
6175 #define dispatch_heredoc_end() ripper_dispatch_heredoc_end(parser)
6177 #define dispatch_heredoc_end() ((void)0)
6183 int c,
func, indent = 0;
6184 const char *eos, *
p, *pend;
6193 if ((c =
nextc()) == -1) {
6197 if (
NIL_P(parser->delayed)) {
6202 ((len =
lex_p - parser->tokp) > 0 &&
6203 (str =
STR_NEW3(parser->tokp, len, enc, func), 1))) {
6221 if (!(func & STR_FUNC_EXPAND)) {
6228 if (--pend == p || pend[-1] !=
'\r') {
6242 if (
nextc() == -1) {
6252 switch (c =
nextc()) {
6265 if (parser->
eofp)
goto error;
6275 if ((c =
nextc()) == -1)
goto error;
6292 rb_warning0(
"ambiguous first argument; put parentheses or even spaces");
6297 #define arg_ambiguous() (arg_ambiguous_gen(parser), 1)
6304 yyerror(
"formal argument must be local variable");
6322 if (len > 5 && name[nlen = len - 5] ==
'-') {
6326 if (len > 4 && name[nlen = len - 4] ==
'-') {
6329 if (
rb_memcicmp(name + nlen + 1,
"mac", 3) == 0 &&
6330 !(len == 8 &&
rb_memcicmp(name,
"utf8-mac", len) == 0))
6345 excargs[1] =
rb_sprintf(
"unknown encoding name: %s", name);
6362 for (i = 0; i < n; ++
i) {
6437 if (str[i-1] ==
'*' && str[i-2] ==
'-') {
6443 if (i + 1 >= len)
return 0;
6444 if (str[i+1] !=
'-') {
6447 else if (str[i-1] !=
'-') {
6465 VALUE name = 0, val = 0;
6466 const char *beg, *end, *vbeg, *vend;
6467 #define str_copy(_s, _p, _n) ((_s) \
6468 ? (void)(rb_str_resize((_s), (_n)), \
6469 MEMCPY(RSTRING_PTR(_s), (_p), char, (_n)), (_s)) \
6470 : (void)((_s) = STR_NEW((_p), (_n))))
6472 if (len <= 7)
return FALSE;
6476 len = end - beg - 3;
6487 for (; len > 0 && *str; str++, --
len) {
6489 case '\'':
case '"':
case ':':
case ';':
6494 for (beg = str; len > 0; str++, --
len) {
6496 case '\'':
case '"':
case ':':
case ';':
6504 for (end = str; len > 0 &&
ISSPACE(*str); str++, --
len);
6506 if (*str !=
':')
continue;
6508 do str++;
while (--len > 0 &&
ISSPACE(*str));
6511 for (vbeg = ++str; --len > 0 && *str !=
'"'; str++) {
6524 for (vbeg = str; len > 0 && *str !=
'"' && *str !=
';' && !
ISSPACE(*str); --
len, str++);
6527 while (len > 0 && (*str ==
';' ||
ISSPACE(*str))) --len, str++;
6532 for (i = 0; i < n; ++
i) {
6533 if (s[i] ==
'-') s[
i] =
'_';
6540 n = (*p->
length)(parser, vbeg, n);
6546 }
while (++p < magic_comments +
numberof(magic_comments));
6560 const char *beg = str;
6564 if (send - str <= 6)
return;
6566 case 'C':
case 'c': str += 6;
continue;
6567 case 'O':
case 'o': str += 5;
continue;
6568 case 'D':
case 'd': str += 4;
continue;
6569 case 'I':
case 'i': str += 3;
continue;
6570 case 'N':
case 'n': str += 2;
continue;
6571 case 'G':
case 'g': str += 1;
continue;
6585 if (++str >= send)
return;
6588 if (*str !=
'=' && *str !=
':')
return;
6593 while ((*str ==
'-' || *str ==
'_' ||
ISALNUM(*str)) && ++str < send);
6609 (
unsigned char)
lex_p[0] == 0xbb &&
6610 (
unsigned char)
lex_p[1] == 0xbf) {
6624 #define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG)
6625 #define IS_END() (lex_state == EXPR_END || lex_state == EXPR_ENDARG || lex_state == EXPR_ENDFN)
6626 #define IS_BEG() (lex_state == EXPR_BEG || lex_state == EXPR_MID || lex_state == EXPR_VALUE || lex_state == EXPR_CLASS)
6627 #define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c))
6628 #define IS_LABEL_POSSIBLE() ((lex_state == EXPR_BEG && !cmd_state) || IS_ARG())
6629 #define IS_LABEL_SUFFIX(n) (peek_n(':',(n)) && !peek_n(':', (n)+1))
6632 #define ambiguous_operator(op, syn) ( \
6633 rb_warning0("`"op"' after local variable is interpreted as binary operator"), \
6634 rb_warning0("even though it seems like "syn""))
6636 #define ambiguous_operator(op, syn) dispatch2(operator_ambiguous, ripper_intern(op), rb_str_new_cstr(syn))
6638 #define warn_balanced(op, syn) ((void) \
6639 (last_state != EXPR_CLASS && last_state != EXPR_DOT && \
6640 last_state != EXPR_FNAME && last_state != EXPR_ENDFN && \
6641 last_state != EXPR_ENDARG && \
6642 space_seen && !ISSPACE(c) && \
6643 (ambiguous_operator(op, syn), 0)))
6655 int fallthru =
FALSE;
6681 switch (c =
nextc()) {
6689 case ' ':
case '\t':
case '\f':
case '\r':
6693 while ((c =
nextc())) {
6695 case ' ':
case '\t':
case '\f':
case '\r':
6704 ripper_dispatch_scan_event(parser,
tSP);
6717 ripper_dispatch_scan_event(parser,
tCOMMENT);
6738 while ((c =
nextc())) {
6740 case ' ':
case '\t':
case '\f':
case '\r':
6745 if ((c =
nextc()) !=
'.') {
6758 parser->tokp =
lex_p;
6761 goto normal_newline;
6770 if ((c =
nextc()) ==
'*') {
6771 if ((c =
nextc()) ==
'=') {
6787 rb_warning0(
"`*' interpreted as argument prefix");
6840 ripper_dispatch_scan_event(parser,
tEMBDOC);
6849 if (c !=
'=')
continue;
6850 if (strncmp(
lex_p,
"end", 3) == 0 &&
6869 if ((c =
nextc()) ==
'=') {
6870 if ((c =
nextc()) ==
'=') {
6879 else if (c ==
'>') {
6892 (!
IS_ARG() || space_seen)) {
6894 if (token)
return token;
6903 if ((c =
nextc()) ==
'>') {
6910 if ((c =
nextc()) ==
'=') {
6929 if ((c =
nextc()) ==
'=') {
6933 if ((c =
nextc()) ==
'=') {
7001 rb_warnI(
"invalid character syntax; use ?\\%c", c2);
7018 else if (c ==
'\\') {
7047 if ((c =
nextc()) ==
'&') {
7049 if ((c =
nextc()) ==
'=') {
7057 else if (c ==
'=') {
7064 rb_warning0(
"`&' interpreted as argument prefix");
7083 if ((c =
nextc()) ==
'|') {
7085 if ((c =
nextc()) ==
'=') {
7170 if ((c =
nextc()) ==
'.') {
7171 if ((c =
nextc()) ==
'.') {
7179 yyerror(
"no .<digit> floating literal anymore; put 0 before dot");
7185 case '0':
case '1':
case '2':
case '3':
case '4':
7186 case '5':
case '6':
case '7':
case '8':
case '9':
7188 int is_float, seen_point, seen_e, nondigit;
7190 is_float = seen_point = seen_e = nondigit = 0;
7193 if (c ==
'-' || c ==
'+') {
7198 #define no_digits() do {yyerror("numeric literal without digits"); return 0;} while (0)
7201 if (c ==
'x' || c ==
'X') {
7207 if (nondigit)
break;
7214 }
while ((c =
nextc()) != -1);
7221 else if (nondigit)
goto trailing_uc;
7225 if (c ==
'b' || c ==
'B') {
7228 if (c ==
'0' || c ==
'1') {
7231 if (nondigit)
break;
7235 if (c !=
'0' && c !=
'1')
break;
7238 }
while ((c =
nextc()) != -1);
7245 else if (nondigit)
goto trailing_uc;
7249 if (c ==
'd' || c ==
'D') {
7255 if (nondigit)
break;
7262 }
while ((c =
nextc()) != -1);
7269 else if (nondigit)
goto trailing_uc;
7277 if (c ==
'o' || c ==
'O') {
7280 if (c == -1 || c ==
'_' || !
ISDIGIT(c)) {
7284 if (c >=
'0' && c <=
'7') {
7289 if (nondigit)
break;
7293 if (c < '0' || c >
'9')
break;
7294 if (c >
'7')
goto invalid_octal;
7297 }
while ((c =
nextc()) != -1);
7301 if (nondigit)
goto trailing_uc;
7310 if (c >
'7' && c <=
'9') {
7312 yyerror(
"Invalid octal digit");
7314 else if (c ==
'.' || c ==
'e' || c ==
'E') {
7326 case '0':
case '1':
case '2':
case '3':
case '4':
7327 case '5':
case '6':
case '7':
case '8':
case '9':
7333 if (nondigit)
goto trailing_uc;
7334 if (seen_point || seen_e) {
7339 if (c0 == -1 || !
ISDIGIT(c0)) {
7367 if (c !=
'-' && c !=
'+')
continue;
7373 if (nondigit)
goto decode_num;
7388 snprintf(tmp,
sizeof(tmp),
"trailing `%c' in number", nondigit);
7394 if (
errno == ERANGE) {
7452 if ((c =
nextc()) ==
'=') {
7473 if ((c =
nextc()) ==
'=') {
7498 if ((c =
nextc()) !=
'@') {
7525 if ((c =
nextc()) ==
']') {
7526 if ((c =
nextc()) ==
'=') {
7538 else if (
IS_ARG() && space_seen) {
7572 ripper_dispatch_scan_event(parser,
tSP);
7593 yyerror(
"unknown type of %string");
7597 if (c == -1 || term == -1) {
7602 if (term ==
'(') term =
')';
7603 else if (term ==
'[') term =
']';
7604 else if (term ==
'{') term =
'}';
7605 else if (term ==
'<') term =
'>';
7643 yyerror(
"unknown type of %string");
7647 if ((c =
nextc()) ==
'=') {
7729 case '1':
case '2':
case '3':
7730 case '4':
case '5':
case '6':
7731 case '7':
case '8':
case '9':
7736 }
while (c != -1 &&
ISDIGIT(c));
7784 ripper_dispatch_scan_event(parser,
k__END__);
7812 if ((c ==
'!' || c ==
'?') && !
peek(
'=')) {
7832 if (
tok()[1] ==
'@')
7899 if (kw->
id[0] != kw->
id[1])
7938 yylex(
void *lval,
void *p)
7952 if (!
NIL_P(parser->delayed)) {
7953 ripper_dispatch_delayed_token(parser, t);
7957 ripper_dispatch_scan_event(parser, t);
7999 if (orig == (
NODE*)1)
return;
8008 #define parser_warning(node, mesg) parser_warning(parser, (node), (mesg))
8015 #define parser_warn(node, mesg) parser_warn(parser, (node), (mesg))
8020 NODE *end, *h = head, *nd;
8022 if (tail == 0)
return head;
8024 if (h == 0)
return tail;
8063 tail->nd_end = tail;
8065 end->nd_next = tail;
8066 h->nd_end = tail->nd_end;
8076 if (list == 0)
return NEW_LIST(item);
8077 if (list->nd_next) {
8078 last = list->nd_next->nd_end;
8086 list->nd_next->nd_end = last->nd_next;
8096 if (head->nd_next) {
8097 last = head->nd_next->nd_end;
8103 head->nd_alen += tail->nd_alen;
8104 last->nd_next = tail;
8105 if (tail->nd_next) {
8106 head->nd_next->nd_end = tail->nd_next->nd_end;
8109 head->nd_next->nd_end = tail;
8118 if (
NIL_P(tail))
return 1;
8137 if (!head)
return tail;
8138 if (!tail)
return head;
8165 tail->nd_lit = head->nd_lit;
8169 else if (
NIL_P(tail->nd_lit)) {
8170 head->nd_alen += tail->nd_alen - 1;
8171 head->nd_next->nd_end->nd_next = tail->nd_next;
8172 head->nd_next->nd_end = tail->nd_next->nd_end;
8177 tail->nd_head =
NEW_STR(tail->nd_lit);
8341 # define assignable_result(x) get_value(lhs)
8342 # define parser_yyerror(parser, x) dispatch1(assign_error, lhs)
8344 # define assignable_result(x) (x)
8348 yyerror(
"Can't change the value of self");
8351 yyerror(
"Can't assign to nil");
8354 yyerror(
"Can't assign to true");
8357 yyerror(
"Can't assign to false");
8360 yyerror(
"Can't assign to __FILE__");
8363 yyerror(
"Can't assign to __LINE__");
8366 yyerror(
"Can't assign to __ENCODING__");
8400 yyerror(
"dynamic constant assignment");
8409 #undef assignable_result
8410 #undef parser_yyerror
8413 #define LVAR_USED ((int)1 << (sizeof(int) * CHAR_BIT - 1))
8418 if (idUScore == name)
return name;
8421 yyerror(
"duplicated argument name");
8433 yyerror(
"duplicated argument name");
8472 id &= ~ID_SCOPE_MASK;
8501 if (!node2)
return node1;
8505 node1->nd_head =
arg_concat(node1->nd_head, node2);
8517 node1->nd_body =
list_concat(node1->nd_body, node2);
8526 if (!node1)
return NEW_LIST(node2);
8531 node1->nd_head =
arg_append(node1->nd_head, node2);
8564 lhs->nd_value = rhs;
8569 lhs->nd_args =
arg_append(lhs->nd_args, rhs);
8600 if (!cond)
yyerror(
"void value expression");
8605 while (node->nd_next) {
8606 node = node->nd_next;
8608 node = node->nd_head;
8612 node = node->nd_body;
8616 if (!node->nd_body) {
8617 node = node->nd_else;
8620 else if (!node->nd_else) {
8621 node = node->nd_body;
8625 node = node->nd_else;
8631 node = node->nd_2nd;
8645 const char *useless = 0;
8652 switch (node->nd_mid) {
8683 useless =
"a variable";
8686 useless =
"a constant";
8693 useless =
"a literal";
8718 useless =
"defined?";
8726 rb_warnS(
"possibly useless use of %s in void context", useless);
8739 if (!node->nd_next)
return;
8741 node = node->nd_next;
8748 NODE **n = &node, *n1 = node;
8750 *n = n1 = n1->nd_body;
8764 #define subnodes(n1, n2) \
8765 ((!node->n1) ? (node->n2 ? (body = &node->n2, 1) : 0) : \
8766 (!node->n2) ? (body = &node->n1, 1) : \
8767 (reduce_nodes(&node->n1), body = &node->n2, 1))
8777 *body = node = node->nd_stts;
8781 *body = node = node->nd_body;
8785 body = &node->nd_end->nd_head;
8791 body = &node->nd_body;
8800 if (node->nd_else) {
8801 body = &node->nd_resq;
8821 yyerror(
"multiple assignment in conditional");
8835 if (!node->nd_value)
return 1;
8836 switch (
nd_type(node->nd_value)) {
8843 parser_warn(node->nd_value,
"found = in conditional, should be ==");
8872 NODE *node, *next, *head;
8874 for (node = *rootnode; node; node = next) {
8878 next = node->nd_next;
8879 head = node->nd_head;
8882 switch (type =
nd_type(head)) {
8885 val =
rb_range_new(head->nd_beg->nd_lit, head->nd_end->nd_lit,
8905 if (node == 0)
return 0;
8913 return cond0(parser, node);
8919 if (!node)
return 1;
8940 if (node == 0)
return 0;
8947 rb_warn0(
"string literal in condition");
8957 node->nd_1st =
cond0(parser, node->nd_1st);
8958 node->nd_2nd =
cond0(parser, node->nd_2nd);
8963 node->nd_beg =
range_op(parser, node->nd_beg);
8964 node->nd_end =
range_op(parser, node->nd_end);
8997 if (node == 0)
return 0;
8998 return cond0(parser, node);
9006 NODE *node = left, *second;
9007 while ((second = node->nd_2nd) != 0 && (
enum node_type)
nd_type(second) == type) {
9010 node->nd_2nd =
NEW_NODE(type, second, right, 0);
9013 return NEW_NODE(type, left, right, 0);
9030 if (node->nd_next == 0) {
9031 node = node->nd_head;
9061 switch (
TYPE(node->nd_lit)) {
9081 node2->nd_head = node1;
9094 node =
NEW_ARGS(m ? m->nd_plen : 0, o);
9095 i1 = m ? m->nd_next : 0;
9100 node->nd_next->nd_next =
NEW_ARGS_AUX(p->nd_pid, p->nd_plen);
9119 if (!local->
used)
return;
9123 if (cnt != local->
vars->
pos) {
9124 rb_bug(
"local->used->pos != local->vars->pos");
9126 for (i = 0; i <
cnt; ++
i) {
9127 if (!v[i] || (u[i] &
LVAR_USED))
continue;
9128 if (idUScore == v[i])
continue;
9168 for (i = 0; i <
cnt; i++) {
9169 buf[
i] = src->
tbl[
i];
9182 if (cnt <= 0)
return 0;
9220 if (used) used = used->
prev;
9236 static const struct vtable *
9252 if ((tmp =
lvtbl->used) != 0) {
9268 while (
lvtbl->args != lvargs) {
9306 if (used) used = used->
prev;
9359 "regexp encoding option '%c' differs from source encoding '%s'",
9388 int back_num,
int *back_refs,
OnigRegex regex,
void *arg0)
9393 long len = name_end -
name;
9394 const char *s = (
const char *)name;
9411 rb_warningS(
"named capture conflicts a local variable - %s",
9494 if (!node)
return node;
9498 node = node->nd_body;
9502 node = node->nd_body;
9509 prelude->nd_body = node;
9510 scope->nd_body = prelude;
9513 scope->nd_body = node;
9526 if (!node)
return node;
9530 node = node->nd_body;
9534 node = node->nd_body;
9550 prelude->nd_body = node;
9551 scope->nd_body = prelude;
9554 scope->nd_body = node;
9560 static const struct {
9586 #define op_tbl_count numberof(op_tbl)
9588 #ifndef ENABLE_SELECTOR_NAMESPACE
9589 #define ENABLE_SELECTOR_NAMESPACE 0
9596 #if ENABLE_SELECTOR_NAMESPACE
9608 #if ENABLE_SELECTOR_NAMESPACE
9615 ivar2_cmp(
struct ivar2_key *key1,
struct ivar2_key *key2)
9617 if (key1->id == key2->id && key1->klass == key2->klass) {
9624 ivar2_hash(
struct ivar2_key *
key)
9626 return (key->id << 8) ^ (key->klass >> 2);
9640 #if ENABLE_SELECTOR_NAMESPACE
9671 if (m >= e)
return 0;
9673 case '~':
case '*':
case '$':
case '?':
case '!':
case '@':
9674 case '/':
case '\\':
case ';':
case ',':
case '.':
case '=':
9675 case ':':
case '<':
case '>':
case '\"':
9676 case '&':
case '`':
case '\'':
case '+':
9694 return m == e ? mb + 1 : 0;
9712 const char *m =
name;
9713 const char *e = m +
len;
9714 int localid =
FALSE;
9716 if (!m || len <= 0)
return FALSE;
9726 if (*++m ==
'@') ++m;
9731 case '<': ++m;
break;
9732 case '=':
if (*++m ==
'>') ++m;
break;
9739 case '>':
case '=': ++m;
break;
9745 case '~': ++m;
break;
9746 case '=':
if (*++m ==
'=') ++m;
break;
9747 default:
return FALSE;
9752 if (*++m ==
'*') ++m;
9756 if (*++m ==
'@') ++m;
9759 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
9764 if (*++m !=
']')
return FALSE;
9765 if (*++m ==
'=') ++m;
9769 if (len == 1)
return TRUE;
9771 case '=':
case '~': ++m;
break;
9772 default:
return FALSE;
9784 case '!':
case '?':
case '=': ++m;
9805 const char *m =
name;
9806 const char *e = m +
len;
9816 fake_str.as.heap.len =
len;
9817 fake_str.as.heap.ptr = (
char *)name;
9818 fake_str.as.heap.aux.capa =
len;
9819 str = (
VALUE)&fake_str;
9865 if (*
op_tbl[i].name == *m &&
9866 strcmp(
op_tbl[i].name, m) == 0) {
9873 if (m[last] ==
'=') {
9903 if (m - name < len)
id =
ID_JUNK;
9910 for (; m <= name +
len; ++m) {
9984 if (
op_tbl[i].token ==
id) {
9998 if (
RBASIC(str)->klass == 0)
10009 id2 = (
id & ~ID_SCOPE_MASK) |
ID_CONST;
10016 if (
RBASIC(str)->klass == 0)
10029 if (!str)
return 0;
10131 parser->parser_ruby_sourcefile_string =
Qnil;
10132 parser->delayed =
Qnil;
10134 parser->result =
Qnil;
10135 parser->parsing_thread =
Qnil;
10136 parser->toplevel_p =
TRUE;
10145 #define parser_mark ripper_parser_mark
10146 #define parser_free ripper_parser_free
10164 rb_gc_mark(p->parser_ruby_sourcefile_string);
10186 prev = local->
prev;
10200 size_t size =
sizeof(*p);
10202 if (!ptr)
return 0;
10205 size +=
sizeof(*local);
10230 #undef rb_reserved_word
10319 #define HEAPCNT(n, size) ((n) * (size) / sizeof(YYSTYPE))
10320 #define NEWHEAP() rb_node_newnode(NODE_ALLOCA, 0, (VALUE)parser->heap, 0)
10321 #define ADD2HEAP(n, c, p) ((parser->heap = (n))->u1.node = (p), \
10322 (n)->u3.cnt = (c), (p))
10327 size_t cnt =
HEAPCNT(1, size);
10337 size_t cnt =
HEAPCNT(nelem, size);
10339 void *ptr =
xcalloc(nelem, size);
10348 size_t cnt =
HEAPCNT(1, size);
10350 if (ptr && (n = parser->
heap) !=
NULL) {
10352 if (n->
u1.
node == ptr) {
10369 while ((n = *prev) !=
NULL) {
10370 if (n->
u1.
node == ptr) {
10383 #ifdef RIPPER_DEBUG
10384 extern int rb_is_pointer_to_heap(
VALUE);
10390 if (x ==
Qfalse)
return x;
10391 if (x ==
Qtrue)
return x;
10392 if (x ==
Qnil)
return x;
10397 if (!rb_is_pointer_to_heap(x))
10410 return ((
NODE *)x)->nd_rval;
10419 #define validate(x) ((x) = get_value(x))
10431 return rb_funcall(parser->value, mid, 1, a);
10439 return rb_funcall(parser->value, mid, 2, a, b);
10448 return rb_funcall(parser->value, mid, 3, a, b, c);
10458 return rb_funcall(parser->value, mid, 4, a, b, c, d);
10469 return rb_funcall(parser->value, mid, 5, a, b, c, d, e);
10472 static const struct kw_assoc {
10475 } keyword_to_name[] = {
10528 keyword_id_to_str(
ID id)
10530 const struct kw_assoc *a;
10532 for (a = keyword_to_name; a->id; a++) {
10539 #undef ripper_id2sym
10551 if ((name = keyword_id_to_str(
id))) {
10564 rb_bug(
"cannot convert ID to string: %ld", (
unsigned long)
id);
10572 ripper_get_id(
VALUE v)
10582 ripper_get_value(
VALUE v)
10589 return nd->nd_rval;
10593 ripper_compile_error(
struct parser_params *parser,
const char *fmt, ...)
10598 va_start(args, fmt);
10605 ripper_warn0(
struct parser_params *parser,
const char *fmt)
10611 ripper_warnI(
struct parser_params *parser,
const char *fmt,
int a)
10619 ripper_warnS(
struct parser_params *parser,
const char *fmt,
const char *str)
10627 ripper_warning0(
struct parser_params *parser,
const char *fmt)
10633 ripper_warningS(
struct parser_params *parser,
const char *fmt,
const char *str)
10646 ripper_s_allocate(
VALUE klass)
10658 #define ripper_initialized_p(r) ((r)->parser_lex_input != 0)
10674 VALUE src, fname, lineno;
10677 rb_scan_args(argc, argv,
"12", &src, &fname, &lineno);
10687 if (
NIL_P(fname)) {
10695 parser->parser_ruby_sourcefile_string = fname;
10702 struct ripper_args {
10709 ripper_parse0(
VALUE parser_v)
10715 ripper_yyparse((
void*)parser);
10716 return parser->result;
10720 ripper_ensure(
VALUE parser_v)
10725 parser->parsing_thread =
Qnil;
10736 ripper_parse(
VALUE self)
10741 if (!ripper_initialized_p(parser)) {
10744 if (!
NIL_P(parser->parsing_thread)) {
10751 rb_ensure(ripper_parse0,
self, ripper_ensure,
self);
10753 return parser->result;
10764 ripper_column(
VALUE self)
10770 if (!ripper_initialized_p(parser)) {
10773 if (
NIL_P(parser->parsing_thread))
return Qnil;
10785 ripper_filename(
VALUE self)
10790 if (!ripper_initialized_p(parser)) {
10793 return parser->parser_ruby_sourcefile_string;
10804 ripper_lineno(
VALUE self)
10809 if (!ripper_initialized_p(parser)) {
10812 if (
NIL_P(parser->parsing_thread))
return Qnil;
10816 #ifdef RIPPER_DEBUG
10838 InitVM_ripper(
void)
10861 #ifdef RIPPER_DEBUG
#define STRNCASECMP(s1, s2, n)
RUBY_EXTERN VALUE rb_cString
void rb_define_global_const(const char *, VALUE)
char * parser_ruby_sourcefile
#define RSTRING_LEN(string)
#define NEW_ARGSCAT(a, b)
#define id_core_define_method
struct local_vars * parser_lvtbl
VALUE rb_ary_unshift(VALUE ary, VALUE item)
static ID ripper_token2eventid(int tok)
static NODE * match_op_gen(struct parser_params *, NODE *, NODE *)
int rb_enc_codelen(int c, rb_encoding *enc)
#define MBCLEN_CHARFOUND_P(ret)
#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)
#define NEW_IASGN(v, val)
VALUE rb_get_coverages(void)
#define dvar_defined_get(id)
#define RE_OPTION_ENCODING_IDX(o)
#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)
< num > opt_block_param compstmt
#define attrset(node, id)
static const struct kwtable * reserved_word(const char *, unsigned int)
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 rb_gc_mark_locations(start, end)
size_t strlen(const char *)
static size_t parser_memsize(const void *ptr)
#define keyword__ENCODING__
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)
#define id_core_set_variable_alias
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 void ripper_init_eventids2(VALUE self)
static int local_var_gen(struct parser_params *, ID)
VALUE rb_range_new(VALUE, VALUE, int)
static int parser_yyerror(struct parser_params *, const char *)
#define NEW_CALL(r, m, a)
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)
VALUE op_sym[tLAST_TOKEN]
#define IS_LABEL_SUFFIX(n)
VALUE rb_str_cat(VALUE, const char *, long)
static void parser_heredoc_restore(struct parser_params *parser, NODE *here)
#define call_uni_op(recv, id)
#define RFLOAT_VALUE(val)
#define TypedData_Wrap_Struct(klass, data_type, sval)
static struct symbols global_symbols
VALUE rb_parser_end_seen_p(VALUE vparser)
#define TypedData_Get_Struct(obj, type, data_type, sval)
static void fixpos(NODE *, NODE *)
#define literal_concat(h, t)
stack_type parser_cmdarg_stack
VALUE rb_external_str_new_with_enc(const char *ptr, long len, rb_encoding *)
VALUE rb_enc_from_encoding(rb_encoding *encoding)
static VALUE debug_lines(const char *f)
static int parser_here_document(struct parser_params *, NODE *)
static NODE * arg_append_gen(struct parser_params *, NODE *, NODE *)
long(* rb_magic_comment_length_t)(struct parser_params *parser, const char *name, long len)
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)
rb_encoding * rb_enc_compatible(VALUE str1, VALUE str2)
mlhs_head tSTAR mlhs_node
static VALUE INT2NUM(int v)
#define NEW_MATCH2(n1, n2)
VALUE rb_reg_compile(VALUE str, int options, const char *sourcefile, int sourceline)
mlhs_node keyword_variable
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
#define parser_precise_mbclen()
#define shadowing_lvar(name)
#define is_identchar(p, e, enc)
static NODE * arg_blk_pass(NODE *, NODE *)
#define RSTRING_PTR(string)
static VALUE parse(int argc, VALUE *argv, VALUE self)
static void reg_fragment_setenc_gen(struct parser_params *, VALUE, int)
int rb_enc_str_coderange(VALUE)
#define mixed_error(enc1, enc2)
void rb_raise(VALUE exc, const char *fmt,...)
#define mixed_escape(beg, enc1, enc2)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
const rb_data_type_t * parent
#define warn_balanced(op, syn)
void rb_compile_warn(const char *file, int line, const char *fmt,...)
static NODE * range_op(struct parser_params *parser, NODE *node)
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
#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)
expr expr keyword_or expr
st_index_t rb_str_hash(VALUE)
#define RARRAY_LEN(ARRAY)
static void parser_pushback(struct parser_params *parser, int c)
nd_set_line($$,$< num >2)
#define is_attrset_id(id)
#define formal_argument(id)
void rb_gc_mark(VALUE ptr)
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_enc_islower(c, enc)
#define rb_warningS(fmt, a)
#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)
static NODE * yycompile(struct parser_params *parser, const char *f, int line)
block_command block_call tCOLON2 operation2 command_args
static ID * vtable_tblcpy(ID *buf, const struct vtable *src)
#define token_info_pop(token)
rb_encoding * rb_utf8_encoding(void)
static long parser_encode_length(struct parser_params *parser, const char *name, long len)
VALUE rb_str_buf_append(VALUE, VALUE)
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)
#define assignable_result(x)
#define NEW_CLASS(n, b, s)
static int literal_concat0(struct parser_params *, VALUE, VALUE)
static ID register_symid(ID, const char *, long, rb_encoding *)
static NODE * assignable_gen(struct parser_params *, ID, NODE *)
#define list_append(l, i)
int rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
#define st_init_numtable_with_size
VALUE rb_parser_set_yydebug(VALUE self, VALUE flag)
#define ENC_CODERANGE_7BIT
#define NEW_PRELUDE(p, b)
#define block_dup_check(n1, n2)
const char * rb_obj_classname(VALUE)
void rb_gc_force_recycle(VALUE p)
static NODE * evstr2dstr_gen(struct parser_params *, NODE *)
#define match_op(node1, node2)
#define set_yylval_num(x)
NODE * parser_deferred_nodes
VALUE rb_str_buf_cat(VALUE, const char *, long)
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)
mlhs_head tSTAR mlhs_post
void rb_exc_raise(VALUE mesg)
#define NEW_UNLESS(c, t, e)
block_command ripper_id2sym('.')
static rb_encoding * must_be_ascii_compatible(VALUE s)
int rb_is_const_id(ID id)
int rb_is_instance_id(ID id)
#define RB_TYPE_P(obj, type)
static int parser_tokadd_string(struct parser_params *, int, int, int, long *, rb_encoding **)
static NODE * remove_begin(NODE *)
#define MEMZERO(p, type, n)
#define NEW_OP_ASGN_AND(i, val)
static NODE * gettable_gen(struct parser_params *, ID)
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)
static char * parser_tokspace(struct parser_params *parser, int n)
static NODE * cond_gen(struct parser_params *, NODE *)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
void rb_compile_error_append(const char *fmt,...)
static void parser_free(void *ptr)
#define parser_warning(node, mesg)
#define id_core_define_singleton_method
static void vtable_add(struct vtable *tbl, ID id)
RUBY_EXTERN VALUE rb_cObject
static int symbols_i(VALUE sym, ID value, VALUE ary)
#define NEW_RESCUE(b, res, e)
static int parser_tokadd_escape(struct parser_params *parser, rb_encoding **encp)
#define rb_enc_isascii(c, enc)
VALUE rb_parser_encoding(VALUE vparser)
#define st_init_table_with_size
struct parser_params * parser
#define NEW_NODE(t, a0, a1, a2)
#define NEW_ENSURE(b, en)
char * ruby_strdup(const char *)
static NODE * attrset_gen(struct parser_params *, NODE *, ID)
NODE * rb_compile_string(const char *f, VALUE s, int line)
VALUE rb_obj_as_string(VALUE)
static int dvar_curr_gen(struct parser_params *, ID)
#define new_args(f, o, r, p, b)
int rb_ascii8bit_encindex(void)
#define dispatch_heredoc_end()
static char * parser_newtok(struct parser_params *parser)
RUBY_EXTERN VALUE rb_mKernel
VALUE rb_thread_current(void)
#define heredoc_identifier()
#define NEW_WHEN(c, t, e)
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 const struct @13 op_tbl[]
#define call_bin_op(recv, id, arg1)
void rb_define_const(VALUE, const char *, VALUE)
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)
rb_atomic_t cnt[RUBY_NSIG]
enum node_type nodetype(NODE *node)
NODE * rb_parser_append_print(VALUE vparser, NODE *node)
#define RE_OPTION_ENCODING_NONE(o)
char ary[RSTRING_EMBED_LEN_MAX+1]
static NODE * parser_compile_string(volatile VALUE vparser, const char *f, VALUE s, int line)
#define ALLOCA_N(type, n)
#define NEW_ARGS_AUX(r, b)
static const struct vtable * dyna_push_gen(struct parser_params *)
static VALUE coverage(const char *f, int n)
#define ENC_CODERANGE_UNKNOWN
static VALUE lex_get_str(struct parser_params *parser, VALUE s)
#define MEMCPY(p1, p2, type, n)
static NODE * block_append_gen(struct parser_params *, NODE *, NODE *)
#define ENC_CODERANGE_BROKEN
#define rb_enc_isupper(c, enc)
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 *)
static int local_id_gen(struct parser_params *, ID)
#define rb_backref_error(n)
void rb_gc_mark_symbols(void)
NODE * rb_parser_while_loop(VALUE vparser, NODE *node, int chop, int split)
#define token_info_push(token)
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_make_backtrace(void)
void * rb_parser_malloc(struct parser_params *parser, size_t size)
VALUE rb_str_resize(VALUE, long)
#define NEW_LASGN(v, val)
int rb_str_hash_cmp(VALUE, VALUE)
#define NEW_OPT_ARG(i, v)
int rb_dvar_defined(ID id)
static int arg_var_gen(struct parser_params *, ID)
static void dispose_string(VALUE str)
static int reg_fragment_check_gen(struct parser_params *, VALUE, int)
#define node_assign(node1, node2)
#define REALLOC_N(var, type, n)
SSL_METHOD *(* func)(void)
#define set_yylval_name(x)
stmt modifier_if expr_value
int rb_symname_p(const char *name)
VALUE rb_sprintf(const char *format,...)
static ID formal_argument_gen(struct parser_params *, ID)
#define rb_enc_isspace(c, enc)
int rb_obj_respond_to(VALUE, ID, int)
static void set_file_encoding(struct parser_params *parser, const char *str, const char *send)
static NODE * ret_args_gen(struct parser_params *, NODE *)
#define RB_GC_GUARD(object)
#define id_core_set_method_alias
#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)
static const struct magic_comment magic_comments[]
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 rb_enc_isalnum(c, enc)
#define reg_named_capture_assign(regexp, match)
#define rb_enc_isdigit(c, enc)
static VALUE yycompile0(VALUE arg, int tracing)
static void arg_ambiguous_gen(struct parser_params *parser)
static void parser_prepare(struct parser_params *parser)
#define rb_reserved_word(str, len)
static int options(unsigned char *cp)
#define NEW_UNTIL(c, b, n)
#define NEW_MATCH3(r, n2)
stack_type parser_cond_stack
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 rb_enc_ispunct(c, enc)
static void ripper_init_eventids1(VALUE self)
#define str_copy(_s, _p, _n)
void rb_mark_tbl(st_table *tbl)
register unsigned int len
#define rb_node_newnode(type, a1, a2, a3)
#define RARRAY_PTR(ARRAY)
#define keyword_do_LAMBDA
#define rb_enc_asciicompat(enc)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
#define NEW_RESBODY(a, ex, n)
int rb_char_to_option_kcode(int c, int *option, int *kcode)
#define is_instance_id(id)
#define set_yylval_str(x)
VALUE rb_reg_check_preprocess(VALUE)
static ID shadowing_lvar_gen(struct parser_params *, ID)
static NODE * arg_concat_gen(struct parser_params *, NODE *, NODE *)
#define ENCODING_IS_ASCII8BIT(obj)
#define rb_enc_isalpha(c, enc)
#define reg_fragment_setenc(str, options)
operation command_args 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)
static void parser_tokaddmbc(struct parser_params *parser, int c, rb_encoding *enc)
#define id_core_set_postexe
static NODE * logop_gen(struct parser_params *, enum node_type, NODE *, NODE *)
VALUE rb_usascii_str_new2(const char *)
#define assignable(id, node)
int rb_const_defined_at(VALUE, ID)
#define ENCODING_GET(obj)
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 void no_blockarg(struct parser_params *parser, NODE *node)
void rb_parser_free(struct parser_params *parser, void *ptr)
static VALUE ULONG2NUM(unsigned long v)
ID rb_intern_str(VALUE str)
static NODE * new_args_gen(struct parser_params *, NODE *, NODE *, ID, NODE *, ID)
void rb_set_errinfo(VALUE err)
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)
static const struct st_hash_type symhash
static NODE * new_evstr_gen(struct parser_params *, NODE *)
static int token_info_has_nonspaces(struct parser_params *parser, const char *token)
#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,...)
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)
rb_encoding * rb_filesystem_encoding(void)
mlhs_inner mlhs_head mlhs_item
#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)
static unsigned int hash(const char *str, unsigned int len)
#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)
const char * parser_lex_pbeg
int rb_is_class_id(ID id)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
VALUE rb_parser_new(void)
VALUE rb_const_get_at(VALUE, ID)
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)
int parser_ruby_sourceline
const char * rb_id2name(ID id)
#define lex_goto_eol(parser)
#define tokaddmbc(c, enc)
static NODE * cond0(struct parser_params *, NODE *)
rb_encoding * rb_ascii8bit_encoding(void)
int rb_enc_find_index(const char *name)
#define CONST_ID(var, str)
ID rb_intern3(const char *name, long len, rb_encoding *enc)
#define NEW_DEFN(i, a, d, p)
void * rb_parser_realloc(struct parser_params *parser, void *ptr, size_t size)
VALUE rb_cstr_to_inum(const char *str, int base, int badcheck)
#define rb_enc_mbcput(c, buf, enc)
int rb_parse_in_eval(void)
VALUE rb_str_buf_new(long)
#define id_core_undef_method
VALUE rb_usascii_str_new(const char *, long)
static NODE * list_concat_gen(struct parser_params *, NODE *, NODE *)
ID rb_intern2(const char *name, long len)
VALUE rb_vsprintf(const char *, va_list)
#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 RTYPEDDATA_TYPE(v)
NODE * rb_parser_compile_cstr(volatile VALUE vparser, const char *f, const char *s, int len, int line)
struct token_info token_info
#define ENCODING_SET(obj, i)
#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)
VALUE rb_str_append(VALUE, VALUE)
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)
int rb_memcicmp(const void *, const void *, long)
static struct vtable * vtable_alloc(struct vtable *prev)
#define rb_enc_prev_char(s, p, e, enc)
static ID * local_tbl_gen(struct parser_params *)
unsigned long ruby_scan_oct(const char *, size_t, size_t *)
VALUE rb_attr_get(VALUE, ID)
VALUE ruby_suppress_tracing(VALUE(*func)(VALUE, int), VALUE arg, int always)
#define parser_warn(node, mesg)
static int yylex(void *, void *)
#define reg_fragment_check(str, options)
static int vtable_size(const struct vtable *tbl)
VALUE rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *enc)
#define parser_encoding_name()
static void void_stmts_gen(struct parser_params *, NODE *)
rb_encoding * rb_enc_from_index(int index)
VALUE rb_str_new(const char *, long)
#define NEW_BLOCK_PASS(b)
static int parser_tokadd_mbchar(struct parser_params *parser, int c)