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)
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 <val> singleton strings
string string1 xstring regexp
685 %type <val> string_contents xstring_contents regexp_contents string_content
686 %type <val> words qwords word_list qword_list word
687 %type <val> literal numeric dsym cpath
688 %type <val> top_compstmt top_stmts
top_stmt
690 %type <val>
expr_value arg_value primary_value
691 %type <val> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
693 %type <val> paren_args opt_paren_args
694 %type <val>
command_args aref_args opt_block_arg block_arg var_ref var_lhs
695 %type <val> command_asgn mrhs superclass block_call block_command
696 %type <val> f_block_optarg f_block_opt
697 %type <val> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
698 %type <val> assoc_list assocs assoc
undef_list backref string_dvar for_var
699 %type <val> block_param opt_block_param block_param_def f_opt
700 %type <val> bv_decls opt_bv_decl bvar
701 %type <val> lambda f_larglist lambda_body
705 %type <val> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
708 %type <val> program reswords then
do dot_or_colon
798 while (node->nd_next) {
799 node = node->nd_next;
807 parser->result = dispatch1(program, $$);
813 top_compstmt : top_stmts opt_terms
829 $$ = dispatch2(stmts_add,
dispatch0(stmts_new),
838 $$ = dispatch2(stmts_add,
dispatch0(stmts_new), $1);
846 $$ = dispatch2(stmts_add, $1, $3);
875 $$ = dispatch1(BEGIN, $4);
891 rb_warn0(
"else without rescue is useless");
904 $$ = dispatch4(bodystmt,
929 $$ = dispatch2(stmts_add,
dispatch0(stmts_new),
938 $$ = dispatch2(stmts_add,
dispatch0(stmts_new), $1);
946 $$ = dispatch2(stmts_add, $1, $3);
960 $$ = dispatch2(
alias, $2, $4);
968 $$ = dispatch2(var_alias, $2, $3);
976 buf[1] = (char)$3->
nd_nth;
979 $$ = dispatch2(var_alias, $2, $3);
985 yyerror(
"can't make alias for the number variables");
988 $$ = dispatch2(var_alias, $2, $3);
989 $$ = dispatch1(alias_error, $$);
997 $$ = dispatch1(undef, $2);
1006 $$ = dispatch2(if_mod, $3, $1);
1015 $$ = dispatch2(unless_mod, $3, $1);
1028 $$ = dispatch2(while_mod, $3, $1);
1041 $$ = dispatch2(until_mod, $3, $1);
1050 $$ = dispatch2(rescue_mod, $1, $3);
1056 rb_warn0(
"END in method; use at_exit");
1062 $$ = dispatch1(
END, $3);
1073 $$ = dispatch2(massign, $1, $3);
1081 ID vid = $1->nd_vid;
1102 $$ = dispatch3(opassign, $1, $2, $3);
1123 $$ = dispatch3(opassign, $$, $5, $6);
1140 $$ = dispatch3(opassign, $$, $4, $5);
1157 $$ = dispatch3(opassign, $$, $4, $5);
1163 yyerror(
"constant re-assignment");
1166 $$ = dispatch2(const_path_field, $1, $3);
1167 $$ = dispatch3(opassign, $$, $4, $5);
1168 $$ = dispatch1(assign_error, $$);
1185 $$ = dispatch3(opassign, $$, $4, $5);
1194 $$ = dispatch2(assign, dispatch1(var_field, $1), $3);
1195 $$ = dispatch1(assign_error, $$);
1204 $$ = dispatch2(assign, $1, $3);
1207 | mlhs
'=' arg_value
1213 $$ = dispatch2(massign, $1, $3);
1222 $$ = dispatch2(massign, $1, $3);
1234 $$ = dispatch2(assign, $1, $3);
1243 $$ = dispatch2(assign, $1, $3);
1301 block_command : block_call
1308 $$ = method_arg($$, $4);
1317 $$ = method_arg($$, $4);
1350 $$ = dispatch2(command, $1, $2);
1361 $$ = dispatch2(command, $1, $2);
1362 $$ = method_add_block($$, $3);
1378 $5->nd_iter =
NEW_CALL($1, $3, $4);
1383 $$ = method_add_block($$, $5);
1399 $5->nd_iter =
NEW_CALL($1, $3, $4);
1404 $$ = method_add_block($$, $5);
1413 $$ = dispatch1(super, $2);
1422 $$ = dispatch1(yield, $2);
1430 $$ = dispatch1(
return, $2);
1438 $$ = dispatch1(
break, $2);
1446 $$ = dispatch1(next, $2);
1457 $$ = dispatch1(mlhs_paren, $2);
1468 $$ = dispatch1(mlhs_paren, $2);
1486 $$ = mlhs_add($1, $2);
1494 $$ = mlhs_add_star($1, $3);
1502 $1 = mlhs_add_star($1, $3);
1503 $$ = mlhs_add($1, $5);
1511 $$ = mlhs_add_star($1,
Qnil);
1519 $1 = mlhs_add_star($1,
Qnil);
1520 $$ = mlhs_add($1, $4);
1528 $$ = mlhs_add_star(mlhs_new(), $2);
1536 $2 = mlhs_add_star(mlhs_new(), $2);
1537 $$ = mlhs_add($2, $4);
1545 $$ = mlhs_add_star(mlhs_new(),
Qnil);
1553 $$ = mlhs_add_star(mlhs_new(),
Qnil);
1554 $$ = mlhs_add($$, $3);
1565 $$ = dispatch1(mlhs_paren, $2);
1575 $$ = mlhs_add(mlhs_new(), $1);
1583 $$ = mlhs_add($1, $2);
1593 $$ = mlhs_add(mlhs_new(), $1);
1601 $$ = mlhs_add($1, $3);
1614 | primary_value
'[' opt_call_args rbracket
1635 $$ = dispatch2(const_path_field, $1, $3);
1650 yyerror(
"dynamic constant assignment");
1654 yyerror(
"dynamic constant assignment");
1655 $$ = dispatch2(const_path_field, $1, $3);
1662 yyerror(
"dynamic constant assignment");
1665 $$ = dispatch1(top_const_field, $2);
1674 $$ = dispatch1(var_field, $1);
1675 $$ = dispatch1(assign_error, $$);
1686 $$ = dispatch1(var_field, $$);
1695 $$ = dispatch1(var_field, $$);
1698 | primary_value
'[' opt_call_args rbracket
1734 yyerror(
"dynamic constant assignment");
1737 $$ = dispatch2(const_path_field, $1, $3);
1739 $$ = dispatch1(assign_error, $$);
1747 yyerror(
"dynamic constant assignment");
1750 $$ = dispatch1(top_const_field, $2);
1752 $$ = dispatch1(assign_error, $$);
1762 $$ = dispatch1(assign_error, $1);
1770 yyerror(
"class/module name must be CONSTANT");
1772 $$ = dispatch1(class_name_error, $1);
1783 $$ = dispatch1(top_const_ref, $2);
1791 $$ = dispatch1(const_ref, $1);
1799 $$ = dispatch2(const_path_ref, $1, $3);
1832 $$ = dispatch1(symbol_literal, $1);
1907 $$ = dispatch2(assign, $1, $3);
1917 $$ = dispatch2(assign, $1, dispatch2(rescue_mod, $3, $5));
1925 ID vid = $1->nd_vid;
1946 $$ = dispatch3(opassign, $1, $2, $3);
1955 ID vid = $1->nd_vid;
1976 $3 = dispatch2(rescue_mod, $3, $5);
1977 $$ = dispatch3(opassign, $1, $2, $3);
1980 | primary_value
'[' opt_call_args rbracket
tOP_ASGN arg
2003 $$ = dispatch3(opassign, $1, $5, $6);
2020 $$ = dispatch3(opassign, $1, $4, $5);
2037 $$ = dispatch3(opassign, $1, $4, $5);
2054 $$ = dispatch3(opassign, $1, $4, $5);
2060 yyerror(
"constant re-assignment");
2063 $$ = dispatch2(const_path_field, $1, $3);
2064 $$ = dispatch3(opassign, $$, $4, $5);
2065 $$ = dispatch1(assign_error, $$);
2071 yyerror(
"constant re-assignment");
2074 $$ = dispatch1(top_const_field, $2);
2075 $$ = dispatch3(opassign, $$, $3, $4);
2076 $$ = dispatch1(assign_error, $$);
2085 $$ = dispatch1(var_field, $1);
2086 $$ = dispatch3(opassign, $$, $2, $3);
2087 $$ = dispatch1(assign_error, $$);
2101 $$ = dispatch2(dot2, $1, $3);
2115 $$ = dispatch2(dot3, $1, $3);
2123 $$ = dispatch3(binary, $1,
ID2SYM(
'+'), $3);
2131 $$ = dispatch3(binary, $1,
ID2SYM(
'-'), $3);
2139 $$ = dispatch3(binary, $1,
ID2SYM(
'*'), $3);
2147 $$ = dispatch3(binary, $1,
ID2SYM(
'/'), $3);
2155 $$ = dispatch3(binary, $1,
ID2SYM(
'%'), $3);
2205 $$ = dispatch3(binary, $1,
ID2SYM(
'|'), $3);
2213 $$ = dispatch3(binary, $1,
ID2SYM(
'^'), $3);
2221 $$ = dispatch3(binary, $1,
ID2SYM(
'&'), $3);
2237 $$ = dispatch3(binary, $1,
ID2SYM(
'>'), $3);
2253 $$ = dispatch3(binary, $1,
ID2SYM(
'<'), $3);
2312 $$ = dispatch2(unary,
ID2SYM(
'!'), $2);
2320 $$ = dispatch2(unary,
ID2SYM(
'~'), $2);
2362 $$ = dispatch1(defined, $4);
2372 $$ = dispatch3(ifop, $1, $3, $6);
2398 | args
',' assocs trailer
2403 $$ = arg_add_assocs($1, $3);
2411 $$ = arg_add_assocs(arg_new(), $1);
2416 paren_args :
'(' opt_call_args rparen
2426 opt_paren_args : none
2430 opt_call_args : none
2436 | args
',' assocs
','
2441 $$ = arg_add_assocs($1, $3);
2449 $$ = arg_add_assocs(arg_new(), $1);
2460 $$ = arg_add(arg_new(), $1);
2463 | args opt_block_arg
2468 $$ = arg_add_optblock($1, $2);
2471 | assocs opt_block_arg
2477 $$ = arg_add_assocs(arg_new(), $1);
2478 $$ = arg_add_optblock($$, $2);
2481 | args
',' assocs opt_block_arg
2487 $$ = arg_add_optblock(arg_add_assocs($1, $3), $4);
2494 $$ = arg_add_block(arg_new(), $1);
2511 block_arg :
tAMPER arg_value
2521 opt_block_arg :
',' block_arg
2536 $$ = arg_add(arg_new(), $1);
2544 $$ = arg_add_star(arg_new(), $2);
2547 | args
',' arg_value
2558 $$ = arg_add($1, $3);
2561 | args
',' tSTAR arg_value
2572 $$ = arg_add_star($1, $4);
2577 mrhs : args
',' arg_value
2588 $$ = mrhs_add(args2mrhs($1), $3);
2591 | args
',' tSTAR arg_value
2603 $$ = mrhs_add_star(args2mrhs($1), $4);
2611 $$ = mrhs_add_star(mrhs_new(), $2);
2629 $$ = method_arg(dispatch1(fcall, $1), arg_new());
2654 $$ = dispatch1(begin, $3);
2659 rb_warning0(
"(...) interpreted as grouped expression");
2663 $$ = dispatch1(paren, $2);
2671 $$ = dispatch1(paren, $2);
2679 $$ = dispatch2(const_path_ref, $1, $3);
2687 $$ = dispatch1(top_const_ref, $2);
2724 $$ = dispatch1(yield, dispatch1(paren, $3));
2732 $$ = dispatch1(yield, dispatch1(paren, arg_new()));
2750 $$ = dispatch1(defined, $5);
2769 | operation brace_block
2776 $$ = method_arg(dispatch1(fcall, $1), arg_new());
2777 $$ = method_add_block($$, $2);
2781 | method_call brace_block
2789 $$ = method_add_block($1, $2);
2828 $$ = dispatch2(
while, $3, $6);
2839 $$ = dispatch2(until, $3, $6);
2850 $$ = dispatch2(
case, $2, $4);
2853 | k_case opt_terms case_body k_end
2858 $$ = dispatch2(
case,
Qnil, $3);
2920 tbl[0] = 1; tbl[1] =
id;
2924 $$ = dispatch3(
for, $2, $5, $8);
2927 | k_class cpath superclass
2930 yyerror(
"class definition in method body");
2944 $$ = dispatch3(
class, $2, $3, $5);
2966 $$ = dispatch2(sclass, $3, $7);
2975 yyerror(
"module definition in method body");
2989 $$ = dispatch2(module, $2, $4);
3010 $$ = dispatch3(def, $2, $4, $5);
3032 $$ = dispatch5(defs, $2, $3, $5, $7, $8);
3042 $$ = dispatch1(
break, arg_new());
3050 $$ = dispatch1(next, arg_new());
3071 primary_value : primary
3194 $$ = dispatch1(
else, $2);
3208 $$ = dispatch1(mlhs_paren, $$);
3216 $$ = dispatch1(mlhs_paren, $2);
3221 f_marg_list : f_marg
3226 $$ = mlhs_add(mlhs_new(), $1);
3229 | f_marg_list
',' f_marg
3234 $$ = mlhs_add($1, $3);
3239 f_margs : f_marg_list
3247 | f_marg_list
',' tSTAR f_norm_arg
3253 $$ = mlhs_add_star($1, $$);
3256 | f_marg_list
',' tSTAR f_norm_arg
',' f_marg_list
3262 $$ = mlhs_add_star($1, $$);
3265 | f_marg_list
',' tSTAR
3270 $$ = mlhs_add_star($1,
Qnil);
3273 | f_marg_list
',' tSTAR ',' f_marg_list
3278 $$ = mlhs_add_star($1, $5);
3287 $$ = mlhs_add_star(mlhs_new(), $$);
3290 |
tSTAR f_norm_arg
',' f_marg_list
3299 $$ = mlhs_add_star($$, $4);
3307 $$ = mlhs_add_star(mlhs_new(),
Qnil);
3310 |
tSTAR ',' f_marg_list
3315 $$ = mlhs_add_star(mlhs_new(),
Qnil);
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
3366 dispatch1(excessed_comma, $$);
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
'|'
3533 $$->nd_body =
NEW_SCOPE($3->nd_head, $4);
3535 $$ = dispatch2(lambda, $3, $4);
3541 f_larglist :
'(' f_args opt_bv_decl rparen
3546 $$ = dispatch1(paren, $2);
3590 block_call : command do_block
3603 $$ = method_add_block($1, $2);
3606 | block_call
'.' operation2 opt_paren_args
3612 $$ = method_optarg($$, $4);
3615 | block_call
tCOLON2 operation2 opt_paren_args
3621 $$ = method_optarg($$, $4);
3626 method_call : operation paren_args
3632 $$ = method_arg(dispatch1(fcall, $1), $2);
3635 | primary_value
'.' operation2 opt_paren_args
3642 $$ = method_optarg($$, $4);
3645 | primary_value
tCOLON2 operation2 paren_args
3652 $$ = method_optarg($$, $4);
3655 | primary_value
tCOLON2 operation3
3663 | primary_value
'.' paren_args
3671 $$ = method_optarg($$, $3);
3674 | primary_value
tCOLON2 paren_args
3682 $$ = method_optarg($$, $3);
3690 $$ = dispatch1(super, $2);
3701 | primary_value
'[' opt_call_args rbracket
3783 $$ = dispatch4(rescue,
3793 exc_list : arg_value
3824 $$ = dispatch1(ensure, $2);
3836 $$ = dispatch1(symbol_literal, $1);
3866 $$ = dispatch2(string_concat, $1, $2);
3876 $$ = dispatch1(string_literal, $2);
3903 $$ = dispatch1(xstring_literal, $2);
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;
3968 $$ = dispatch2(regexp_literal, $2, $3);
3979 $$ = dispatch1(array, $$);
3987 $$ = dispatch1(array, $2);
4000 | word_list word
' '
4005 $$ = dispatch2(words_add, $1, $2);
4010 word : string_content
4015 $$ = dispatch2(word_add, $$, $1);
4018 | word string_content
4023 $$ = dispatch2(word_add, $1, $2);
4034 $$ = dispatch1(array, $$);
4042 $$ = dispatch1(array, $2);
4060 $$ = dispatch2(qwords_add, $1, $2);
4073 | string_contents string_content
4078 $$ = dispatch2(string_add, $1, $2);
4091 | xstring_contents string_content
4096 $$ = dispatch2(xstring_add, $1, $2);
4109 | regexp_contents string_content
4112 NODE *head = $1, *tail = $2;
4133 $$ = dispatch2(regexp_add, $1, $2);
4152 $$ = dispatch1(string_dvar, $3);
4176 $$ = dispatch1(string_embexpr, $4);
4186 $$ = dispatch1(var_ref, $1);
4194 $$ = dispatch1(var_ref, $1);
4202 $$ = dispatch1(var_ref, $1);
4214 $$ = dispatch1(symbol, $2);
4250 $$ = dispatch1(dyna_symbol, $2);
4291 var_ref : user_variable
4296 if (id_is_var(
get_id($1))) {
4297 $$ = dispatch1(var_ref, $1);
4300 $$ = dispatch1(vcall, $1);
4309 $$ = dispatch1(var_ref, $1);
4314 var_lhs : user_variable
4319 $$ = dispatch1(var_field, $$);
4327 $$ = dispatch1(var_field, $$);
4364 f_arglist :
'(' f_args rparen
4369 $$ = dispatch1(paren, $2);
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");
4510 $$ = dispatch1(param_error, $1);
4516 yyerror(
"formal argument cannot be an instance variable");
4519 $$ = dispatch1(param_error, $1);
4525 yyerror(
"formal argument cannot be a global variable");
4528 $$ = dispatch1(param_error, $1);
4534 yyerror(
"formal argument cannot be a class variable");
4537 $$ = dispatch1(param_error, $1);
4542 f_norm_arg : f_bad_arg
4550 f_arg_item : f_norm_arg
4573 $$ = dispatch1(mlhs_paren, $2);
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");
4684 $$ = dispatch1(rest_param, $2);
4693 $$ = dispatch1(rest_param,
Qnil);
4706 yyerror(
"block argument must be local variable");
4708 yyerror(
"duplicated block argument name");
4714 $$ = dispatch1(blockarg, $2);
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");
4767 $$ = dispatch1(paren, $3);
4778 $$ = dispatch1(assoclist_from_args, $1);
4800 assoc : arg_value
tASSOC arg_value
4805 $$ = dispatch2(assoc_new, $1, $3);
4813 $$ = dispatch2(assoc_new, $1, $2);
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
5393 str_regexp = (STR_FUNC_REGEXP|STR_FUNC_ESCAPE|STR_FUNC_EXPAND),
5395 str_dword = (STR_FUNC_QWORDS|STR_FUNC_EXPAND),
5397 str_dsym = (STR_FUNC_SYMBOL|STR_FUNC_EXPAND)
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;
5674 if (flags & ESCAPE_META)
goto eof;
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()) !=
'-') {
5694 if (flags & ESCAPE_CONTROL)
goto eof;
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()) !=
'-') {
5758 flags |= ESCAPE_META;
5762 if (flags & ESCAPE_CONTROL)
goto eof;
5763 if ((c =
nextc()) !=
'-') {
5771 if (flags & ESCAPE_CONTROL)
goto eof;
5773 flags |= ESCAPE_CONTROL;
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) {
5894 else if ((func & STR_FUNC_EXPAND) && c ==
'#' &&
lex_p <
lex_pend) {
5896 if (c2 ==
'$' || c2 ==
'@' || c2 ==
'{') {
5901 else if (c ==
'\\') {
5902 const char *beg =
lex_p - 1;
5906 if (func & STR_FUNC_QWORDS)
break;
5907 if (func & STR_FUNC_EXPAND)
continue;
5912 if (func & STR_FUNC_ESCAPE)
tokadd(c);
5916 if ((func & STR_FUNC_EXPAND) == 0) {
5921 func & STR_FUNC_SYMBOL,
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) {
6103 if (func & STR_FUNC_INDENT) {
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;
6191 indent = (func = *eos++) & STR_FUNC_INDENT;
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);
8316 switch (
id & ID_SCOPE_MASK) {
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))
8770 int newline = (int)(node->
flags & NODE_FL_NEWLINE);
8777 *body = node = node->nd_stts;
8781 *body = node = node->nd_body;
8785 body = &node->nd_end->nd_head;
8788 if (
subnodes(nd_body, nd_else))
break;
8791 body = &node->nd_body;
8794 if (!
subnodes(nd_body, nd_next))
goto end;
8797 if (!
subnodes(nd_head, nd_resq))
goto end;
8800 if (node->nd_else) {
8801 body = &node->nd_resq;
8804 if (!
subnodes(nd_head, nd_resq))
goto end;
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;
9231 if (i && used) used->
tbl[i-1] |= LVAR_USED;
9236 static const struct vtable *
9252 if ((tmp =
lvtbl->used) != 0) {
9268 while (
lvtbl->args != lvargs) {
9300 if (used) used->
tbl[i-1] |= LVAR_USED;
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) {
9983 for (i = 0; i < op_tbl_count; i++) {
9984 if (
op_tbl[i].token ==
id) {
9998 if (
RBASIC(str)->klass == 0)
10004 ID id2 = (
id & ~ID_SCOPE_MASK) | ID_LOCAL;
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) {
10357 }
while ((n = n->
u2.
node) != NULL);
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