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)
108 #define DVARS_INHERIT ((void*)1)
109 #define DVARS_TOPSCOPE NULL
110 #define DVARS_SPECIAL_P(tbl) (!POINTER_P(tbl))
111 #define POINTER_P(val) ((VALUE)(val) & ~(VALUE)3)
154 rb_bug(
"vtable_add: vtable is not allocated (%p)", (
void *)tbl);
171 for (i = 0; i < tbl->
pos; i++) {
256 VALUE parser_ruby_sourcefile_string;
264 VALUE parsing_thread;
269 #define UTF8_ENC() (parser->utf8 ? parser->utf8 : \
270 (parser->utf8 = rb_utf8_encoding()))
271 #define STR_NEW(p,n) rb_enc_str_new((p),(n),parser->enc)
272 #define STR_NEW0() rb_enc_str_new(0,0,parser->enc)
273 #define STR_NEW2(p) rb_enc_str_new((p),strlen(p),parser->enc)
274 #define STR_NEW3(p,n,e,func) parser_str_new((p),(n),(e),(func),parser->enc)
275 #define ENC_SINGLE(cr) ((cr)==ENC_CODERANGE_7BIT)
276 #define TOK_INTERN(mb) rb_intern3(tok(), toklen(), parser->enc)
279 #define yyerror(msg) parser_yyerror(parser, (msg))
281 #define lex_strterm (parser->parser_lex_strterm)
282 #define lex_state (parser->parser_lex_state)
283 #define cond_stack (parser->parser_cond_stack)
284 #define cmdarg_stack (parser->parser_cmdarg_stack)
285 #define class_nest (parser->parser_class_nest)
286 #define paren_nest (parser->parser_paren_nest)
287 #define lpar_beg (parser->parser_lpar_beg)
288 #define in_single (parser->parser_in_single)
289 #define in_def (parser->parser_in_def)
290 #define compile_for_eval (parser->parser_compile_for_eval)
291 #define cur_mid (parser->parser_cur_mid)
292 #define in_defined (parser->parser_in_defined)
293 #define tokenbuf (parser->parser_tokenbuf)
294 #define tokidx (parser->parser_tokidx)
295 #define toksiz (parser->parser_toksiz)
296 #define lex_input (parser->parser_lex_input)
297 #define lex_lastline (parser->parser_lex_lastline)
298 #define lex_nextline (parser->parser_lex_nextline)
299 #define lex_pbeg (parser->parser_lex_pbeg)
300 #define lex_p (parser->parser_lex_p)
301 #define lex_pend (parser->parser_lex_pend)
302 #define heredoc_end (parser->parser_heredoc_end)
303 #define command_start (parser->parser_command_start)
304 #define deferred_nodes (parser->parser_deferred_nodes)
305 #define lex_gets_ptr (parser->parser_lex_gets_ptr)
306 #define lex_gets (parser->parser_lex_gets)
307 #define lvtbl (parser->parser_lvtbl)
308 #define ruby__end__seen (parser->parser_ruby__end__seen)
309 #define ruby_sourceline (parser->parser_ruby_sourceline)
310 #define ruby_sourcefile (parser->parser_ruby_sourcefile)
311 #define current_enc (parser->enc)
312 #define yydebug (parser->parser_yydebug)
315 #define ruby_eval_tree (parser->parser_eval_tree)
316 #define ruby_eval_tree_begin (parser->parser_eval_tree_begin)
317 #define ruby_debug_lines (parser->debug_lines)
318 #define ruby_coverage (parser->coverage)
322 static int yylex(
void*,
void*);
324 static int yylex(
void*);
328 #define yyparse ruby_yyparse
331 #define rb_node_newnode(type, a1, a2, a3) node_newnode(parser, (type), (a1), (a2), (a3))
334 #define cond(node) cond_gen(parser, (node))
336 #define logop(type,node1,node2) logop_gen(parser, (type), (node1), (node2))
344 #define value_expr(node) value_expr_gen(parser, (node) = remove_begin(node))
345 #define void_expr0(node) void_expr_gen(parser, (node))
346 #define void_expr(node) void_expr0((node) = remove_begin(node))
348 #define void_stmts(node) void_stmts_gen(parser, (node))
350 #define reduce_nodes(n) reduce_nodes_gen(parser,(n))
352 #define block_dup_check(n1,n2) block_dup_check_gen(parser,(n1),(n2))
355 #define block_append(h,t) block_append_gen(parser,(h),(t))
357 #define list_append(l,i) list_append_gen(parser,(l),(i))
359 #define list_concat(h,t) list_concat_gen(parser,(h),(t))
361 #define arg_append(h,t) arg_append_gen(parser,(h),(t))
363 #define arg_concat(h,t) arg_concat_gen(parser,(h),(t))
365 #define literal_concat(h,t) literal_concat_gen(parser,(h),(t))
368 #define new_evstr(n) new_evstr_gen(parser,(n))
370 #define evstr2dstr(n) evstr2dstr_gen(parser,(n))
374 #define call_bin_op(recv,id,arg1) call_bin_op_gen(parser, (recv),(id),(arg1))
376 #define call_uni_op(recv,id) call_uni_op_gen(parser, (recv),(id))
379 #define new_args(f,o,r,p,b) new_args_gen(parser, (f),(o),(r),(p),(b))
383 #define ret_args(node) ret_args_gen(parser, (node))
386 #define new_yield(node) new_yield_gen(parser, (node))
389 #define gettable(id) gettable_gen(parser,(id))
391 #define assignable(id,node) assignable_gen(parser, (id), (node))
394 #define aryset(node1,node2) aryset_gen(parser, (node1), (node2))
396 #define attrset(node,id) attrset_gen(parser, (node), (id))
399 #define rb_backref_error(n) rb_backref_error_gen(parser,(n))
401 #define node_assign(node1, node2) node_assign_gen(parser, (node1), (node2))
404 #define match_op(node1,node2) match_op_gen(parser, (node1), (node2))
407 #define local_tbl() local_tbl_gen(parser)
412 #define reg_compile(str,options) reg_compile_gen(parser, (str), (options))
414 #define reg_fragment_setenc(str,options) reg_fragment_setenc_gen(parser, (str), (options))
416 #define reg_fragment_check(str,options) reg_fragment_check_gen(parser, (str), (options))
418 #define reg_named_capture_assign(regexp,match) reg_named_capture_assign_gen(parser,(regexp),(match))
420 #define get_id(id) (id)
421 #define get_value(val) (val)
423 #define remove_begin(node) (node)
424 #define rb_dvar_defined(id) 0
425 #define rb_local_defined(id) 0
426 static ID ripper_get_id(
VALUE);
427 #define get_id(id) ripper_get_id(id)
429 #define get_value(val) ripper_get_value(val)
431 #define assignable(lhs,node) assignable_gen(parser, (lhs))
433 #define id_is_var(id) id_is_var_gen(parser, (id))
437 #define formal_argument(id) formal_argument_gen(parser, (id))
439 #define shadowing_lvar(name) shadowing_lvar_gen(parser, (name))
441 #define new_bv(id) new_bv_gen(parser, (id))
444 #define local_push(top) local_push_gen(parser,(top))
446 #define local_pop() local_pop_gen(parser)
448 #define local_var(id) local_var_gen(parser, (id));
450 #define arg_var(id) arg_var_gen(parser, (id))
452 #define local_id(id) local_id_gen(parser, (id))
454 #define internal_id() internal_id_gen(parser)
457 #define dyna_push() dyna_push_gen(parser)
459 #define dyna_pop(node) dyna_pop_gen(parser, (node))
461 #define dyna_in_block() dyna_in_block_gen(parser)
462 #define dyna_var(id) local_var(id)
464 #define dvar_defined(id) dvar_defined_gen(parser, (id), 0)
465 #define dvar_defined_get(id) dvar_defined_gen(parser, (id), 1)
467 #define dvar_curr(id) dvar_curr_gen(parser, (id))
470 #define lvar_defined(id) lvar_defined_gen(parser, (id))
472 #define RE_OPTION_ONCE (1<<16)
473 #define RE_OPTION_ENCODING_SHIFT 8
474 #define RE_OPTION_ENCODING(e) (((e)&0xff)<<RE_OPTION_ENCODING_SHIFT)
475 #define RE_OPTION_ENCODING_IDX(o) (((o)>>RE_OPTION_ENCODING_SHIFT)&0xff)
476 #define RE_OPTION_ENCODING_NONE(o) ((o)&RE_OPTION_ARG_ENCODING_NONE)
477 #define RE_OPTION_MASK 0xff
478 #define RE_OPTION_ARG_ENCODING_NONE 32
480 #define NODE_STRTERM NODE_ZARRAY
481 #define NODE_HEREDOC NODE_ARRAY
482 #define SIGN_EXTEND(x,n) (((1<<(n)-1)^((x)&~(~0<<(n))))-(1<<(n)-1))
483 #define nd_func u1.id
484 #if SIZEOF_SHORT == 2
485 #define nd_term(node) ((signed short)(node)->u2.id)
487 #define nd_term(node) SIGN_EXTEND((node)->u2.id, CHAR_BIT*2)
489 #define nd_paren(node) (char)((node)->u2.id >> CHAR_BIT*2)
490 #define nd_nest u3.cnt
495 #define RIPPER_VERSION "0.1.0"
499 static ID ripper_id_gets;
508 #define dispatch0(n) ripper_dispatch0(parser, TOKEN_PASTE(ripper_id_, n))
509 #define dispatch1(n,a) ripper_dispatch1(parser, TOKEN_PASTE(ripper_id_, n), (a))
510 #define dispatch2(n,a,b) ripper_dispatch2(parser, TOKEN_PASTE(ripper_id_, n), (a), (b))
511 #define dispatch3(n,a,b,c) ripper_dispatch3(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c))
512 #define dispatch4(n,a,b,c,d) ripper_dispatch4(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d))
513 #define dispatch5(n,a,b,c,d,e) ripper_dispatch5(parser, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d), (e))
515 #define yyparse ripper_yyparse
517 #define ripper_intern(s) ID2SYM(rb_intern(s))
520 #define ripper_id2sym(id) ((id) < 256 && rb_ispunct(id) ? \
521 ID2SYM(id) : ripper_id2sym(id))
524 #define arg_new() dispatch0(args_new)
525 #define arg_add(l,a) dispatch2(args_add, (l), (a))
526 #define arg_add_star(l,a) dispatch2(args_add_star, (l), (a))
527 #define arg_add_block(l,b) dispatch2(args_add_block, (l), (b))
528 #define arg_add_optblock(l,b) ((b)==Qundef? (l) : dispatch2(args_add_block, (l), (b)))
529 #define bare_assoc(v) dispatch1(bare_assoc_hash, (v))
530 #define arg_add_assocs(l,b) arg_add((l), bare_assoc(b))
532 #define args2mrhs(a) dispatch1(mrhs_new_from_args, (a))
533 #define mrhs_new() dispatch0(mrhs_new)
534 #define mrhs_add(l,a) dispatch2(mrhs_add, (l), (a))
535 #define mrhs_add_star(l,a) dispatch2(mrhs_add_star, (l), (a))
537 #define mlhs_new() dispatch0(mlhs_new)
538 #define mlhs_add(l,a) dispatch2(mlhs_add, (l), (a))
539 #define mlhs_add_star(l,a) dispatch2(mlhs_add_star, (l), (a))
541 #define params_new(pars, opts, rest, pars2, blk) \
542 dispatch5(params, (pars), (opts), (rest), (pars2), (blk))
544 #define blockvar_new(p,v) dispatch2(block_var, (p), (v))
545 #define blockvar_add_star(l,a) dispatch2(block_var_add_star, (l), (a))
546 #define blockvar_add_block(l,a) dispatch2(block_var_add_block, (l), (a))
548 #define method_optarg(m,a) ((a)==Qundef ? (m) : dispatch2(method_add_arg,(m),(a)))
549 #define method_arg(m,a) dispatch2(method_add_arg,(m),(a))
550 #define method_add_block(m,b) dispatch2(method_add_block, (m), (b))
552 #define escape_Qundef(x) ((x)==Qundef ? Qnil : (x))
559 # define ifndef_ripper(x) (x)
561 # define ifndef_ripper(x)
565 # define rb_warn0(fmt) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt))
566 # define rb_warnI(fmt,a) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt), (a))
567 # define rb_warnS(fmt,a) rb_compile_warn(ruby_sourcefile, ruby_sourceline, (fmt), (a))
568 # define rb_warning0(fmt) rb_compile_warning(ruby_sourcefile, ruby_sourceline, (fmt))
569 # define rb_warningS(fmt,a) rb_compile_warning(ruby_sourcefile, ruby_sourceline, (fmt), (a))
571 # define rb_warn0(fmt) ripper_warn0(parser, (fmt))
572 # define rb_warnI(fmt,a) ripper_warnI(parser, (fmt), (a))
573 # define rb_warnS(fmt,a) ripper_warnS(parser, (fmt), (a))
574 # define rb_warning0(fmt) ripper_warning0(parser, (fmt))
575 # define rb_warningS(fmt,a) ripper_warningS(parser, (fmt), (a))
576 static void ripper_warn0(
struct parser_params*,
const char*);
577 static void ripper_warnI(
struct parser_params*,
const char*,
int);
579 static void ripper_warnS(
struct parser_params*,
const char*,
const char*);
581 static void ripper_warning0(
struct parser_params*,
const char*);
582 static void ripper_warningS(
struct parser_params*,
const char*,
const char*);
586 static void ripper_compile_error(
struct parser_params*,
const char *fmt, ...);
587 # define rb_compile_error ripper_compile_error
588 # define compile_error ripper_compile_error
589 # define PARSER_ARG parser,
591 # define rb_compile_error rb_compile_error_with_enc
592 # define compile_error parser->nerr++,rb_compile_error_with_enc
593 # define PARSER_ARG ruby_sourcefile, ruby_sourceline, current_enc,
601 #define YYMAXDEPTH 10000
608 #define token_info_push(token) (RTEST(ruby_verbose) ? token_info_push(parser, (token)) : (void)0)
609 #define token_info_pop(token) (RTEST(ruby_verbose) ? token_info_pop(parser, (token)) : (void)0)
611 #define token_info_push(token)
612 #define token_info_pop(token)
625 const struct vtable *vars;
688 %type <val> singleton strings
string string1 xstring regexp
689 %type <val> string_contents xstring_contents regexp_contents string_content
690 %type <val> words qwords word_list qword_list word
691 %type <val> literal numeric dsym cpath
692 %type <val> top_compstmt top_stmts
top_stmt
694 %type <val>
expr_value arg_value primary_value
695 %type <val> if_tail opt_else case_body cases opt_rescue exc_list exc_var opt_ensure
697 %type <val> paren_args opt_paren_args
698 %type <val>
command_args aref_args opt_block_arg block_arg var_ref var_lhs
699 %type <val> command_asgn mrhs superclass block_call block_command
700 %type <val> f_block_optarg f_block_opt
701 %type <val> f_arglist f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs
702 %type <val> assoc_list assocs assoc
undef_list backref string_dvar for_var
703 %type <val> block_param opt_block_param block_param_def f_opt
704 %type <val> bv_decls opt_bv_decl bvar
705 %type <val> lambda f_larglist lambda_body
709 %type <val> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
712 %type <val> program reswords then
do dot_or_colon
802 while (node->nd_next) {
803 node = node->nd_next;
811 parser->result = dispatch1(program, $$);
817 top_compstmt : top_stmts opt_terms
833 $$ = dispatch2(stmts_add,
dispatch0(stmts_new),
842 $$ = dispatch2(stmts_add,
dispatch0(stmts_new), $1);
850 $$ = dispatch2(stmts_add, $1, $3);
879 $$ = dispatch1(BEGIN, $4);
895 rb_warn0(
"else without rescue is useless");
908 $$ = dispatch4(bodystmt,
933 $$ = dispatch2(stmts_add,
dispatch0(stmts_new),
942 $$ = dispatch2(stmts_add,
dispatch0(stmts_new), $1);
950 $$ = dispatch2(stmts_add, $1, $3);
964 $$ = dispatch2(
alias, $2, $4);
972 $$ = dispatch2(var_alias, $2, $3);
980 buf[1] = (char)$3->
nd_nth;
983 $$ = dispatch2(var_alias, $2, $3);
989 yyerror(
"can't make alias for the number variables");
992 $$ = dispatch2(var_alias, $2, $3);
993 $$ = dispatch1(alias_error, $$);
1001 $$ = dispatch1(undef, $2);
1010 $$ = dispatch2(if_mod, $3, $1);
1019 $$ = dispatch2(unless_mod, $3, $1);
1032 $$ = dispatch2(while_mod, $3, $1);
1045 $$ = dispatch2(until_mod, $3, $1);
1054 $$ = dispatch2(rescue_mod, $1, $3);
1060 rb_warn0(
"END in method; use at_exit");
1066 $$ = dispatch1(
END, $3);
1077 $$ = dispatch2(massign, $1, $3);
1085 ID vid = $1->nd_vid;
1106 $$ = dispatch3(opassign, $1, $2, $3);
1127 $$ = dispatch3(opassign, $$, $5, $6);
1144 $$ = dispatch3(opassign, $$, $4, $5);
1161 $$ = dispatch3(opassign, $$, $4, $5);
1167 yyerror(
"constant re-assignment");
1170 $$ = dispatch2(const_path_field, $1, $3);
1171 $$ = dispatch3(opassign, $$, $4, $5);
1172 $$ = dispatch1(assign_error, $$);
1189 $$ = dispatch3(opassign, $$, $4, $5);
1198 $$ = dispatch2(assign, dispatch1(var_field, $1), $3);
1199 $$ = dispatch1(assign_error, $$);
1208 $$ = dispatch2(assign, $1, $3);
1211 | mlhs
'=' arg_value
1217 $$ = dispatch2(massign, $1, $3);
1226 $$ = dispatch2(massign, $1, $3);
1238 $$ = dispatch2(assign, $1, $3);
1247 $$ = dispatch2(assign, $1, $3);
1305 block_command : block_call
1312 $$ = method_arg($$, $4);
1321 $$ = method_arg($$, $4);
1354 $$ = dispatch2(command, $1, $2);
1365 $$ = dispatch2(command, $1, $2);
1366 $$ = method_add_block($$, $3);
1382 $5->nd_iter =
NEW_CALL($1, $3, $4);
1387 $$ = method_add_block($$, $5);
1403 $5->nd_iter =
NEW_CALL($1, $3, $4);
1408 $$ = method_add_block($$, $5);
1417 $$ = dispatch1(super, $2);
1426 $$ = dispatch1(yield, $2);
1434 $$ = dispatch1(
return, $2);
1442 $$ = dispatch1(
break, $2);
1450 $$ = dispatch1(next, $2);
1461 $$ = dispatch1(mlhs_paren, $2);
1472 $$ = dispatch1(mlhs_paren, $2);
1490 $$ = mlhs_add($1, $2);
1498 $$ = mlhs_add_star($1, $3);
1506 $1 = mlhs_add_star($1, $3);
1507 $$ = mlhs_add($1, $5);
1515 $$ = mlhs_add_star($1,
Qnil);
1523 $1 = mlhs_add_star($1,
Qnil);
1524 $$ = mlhs_add($1, $4);
1532 $$ = mlhs_add_star(mlhs_new(), $2);
1540 $2 = mlhs_add_star(mlhs_new(), $2);
1541 $$ = mlhs_add($2, $4);
1549 $$ = mlhs_add_star(mlhs_new(),
Qnil);
1557 $$ = mlhs_add_star(mlhs_new(),
Qnil);
1558 $$ = mlhs_add($$, $3);
1569 $$ = dispatch1(mlhs_paren, $2);
1579 $$ = mlhs_add(mlhs_new(), $1);
1587 $$ = mlhs_add($1, $2);
1597 $$ = mlhs_add(mlhs_new(), $1);
1605 $$ = mlhs_add($1, $3);
1618 | primary_value
'[' opt_call_args rbracket
1639 $$ = dispatch2(const_path_field, $1, $3);
1654 yyerror(
"dynamic constant assignment");
1658 yyerror(
"dynamic constant assignment");
1659 $$ = dispatch2(const_path_field, $1, $3);
1666 yyerror(
"dynamic constant assignment");
1669 $$ = dispatch1(top_const_field, $2);
1678 $$ = dispatch1(var_field, $1);
1679 $$ = dispatch1(assign_error, $$);
1690 $$ = dispatch1(var_field, $$);
1699 $$ = dispatch1(var_field, $$);
1702 | primary_value
'[' opt_call_args rbracket
1738 yyerror(
"dynamic constant assignment");
1741 $$ = dispatch2(const_path_field, $1, $3);
1743 $$ = dispatch1(assign_error, $$);
1751 yyerror(
"dynamic constant assignment");
1754 $$ = dispatch1(top_const_field, $2);
1756 $$ = dispatch1(assign_error, $$);
1766 $$ = dispatch1(assign_error, $1);
1774 yyerror(
"class/module name must be CONSTANT");
1776 $$ = dispatch1(class_name_error, $1);
1787 $$ = dispatch1(top_const_ref, $2);
1795 $$ = dispatch1(const_ref, $1);
1803 $$ = dispatch2(const_path_ref, $1, $3);
1836 $$ = dispatch1(symbol_literal, $1);
1911 $$ = dispatch2(assign, $1, $3);
1921 $$ = dispatch2(assign, $1, dispatch2(rescue_mod, $3, $5));
1929 ID vid = $1->nd_vid;
1950 $$ = dispatch3(opassign, $1, $2, $3);
1959 ID vid = $1->nd_vid;
1980 $3 = dispatch2(rescue_mod, $3, $5);
1981 $$ = dispatch3(opassign, $1, $2, $3);
1984 | primary_value
'[' opt_call_args rbracket
tOP_ASGN arg
2007 $$ = dispatch3(opassign, $1, $5, $6);
2024 $$ = dispatch3(opassign, $1, $4, $5);
2041 $$ = dispatch3(opassign, $1, $4, $5);
2058 $$ = dispatch3(opassign, $1, $4, $5);
2064 yyerror(
"constant re-assignment");
2067 $$ = dispatch2(const_path_field, $1, $3);
2068 $$ = dispatch3(opassign, $$, $4, $5);
2069 $$ = dispatch1(assign_error, $$);
2075 yyerror(
"constant re-assignment");
2078 $$ = dispatch1(top_const_field, $2);
2079 $$ = dispatch3(opassign, $$, $3, $4);
2080 $$ = dispatch1(assign_error, $$);
2089 $$ = dispatch1(var_field, $1);
2090 $$ = dispatch3(opassign, $$, $2, $3);
2091 $$ = dispatch1(assign_error, $$);
2105 $$ = dispatch2(dot2, $1, $3);
2119 $$ = dispatch2(dot3, $1, $3);
2127 $$ = dispatch3(binary, $1,
ID2SYM(
'+'), $3);
2135 $$ = dispatch3(binary, $1,
ID2SYM(
'-'), $3);
2143 $$ = dispatch3(binary, $1,
ID2SYM(
'*'), $3);
2151 $$ = dispatch3(binary, $1,
ID2SYM(
'/'), $3);
2159 $$ = dispatch3(binary, $1,
ID2SYM(
'%'), $3);
2209 $$ = dispatch3(binary, $1,
ID2SYM(
'|'), $3);
2217 $$ = dispatch3(binary, $1,
ID2SYM(
'^'), $3);
2225 $$ = dispatch3(binary, $1,
ID2SYM(
'&'), $3);
2241 $$ = dispatch3(binary, $1,
ID2SYM(
'>'), $3);
2257 $$ = dispatch3(binary, $1,
ID2SYM(
'<'), $3);
2316 $$ = dispatch2(unary,
ID2SYM(
'!'), $2);
2324 $$ = dispatch2(unary,
ID2SYM(
'~'), $2);
2366 $$ = dispatch1(defined, $4);
2376 $$ = dispatch3(ifop, $1, $3, $6);
2402 | args
',' assocs trailer
2407 $$ = arg_add_assocs($1, $3);
2415 $$ = arg_add_assocs(arg_new(), $1);
2420 paren_args :
'(' opt_call_args rparen
2430 opt_paren_args : none
2434 opt_call_args : none
2440 | args
',' assocs
','
2445 $$ = arg_add_assocs($1, $3);
2453 $$ = arg_add_assocs(arg_new(), $1);
2464 $$ = arg_add(arg_new(), $1);
2467 | args opt_block_arg
2472 $$ = arg_add_optblock($1, $2);
2475 | assocs opt_block_arg
2481 $$ = arg_add_assocs(arg_new(), $1);
2482 $$ = arg_add_optblock($$, $2);
2485 | args
',' assocs opt_block_arg
2491 $$ = arg_add_optblock(arg_add_assocs($1, $3), $4);
2498 $$ = arg_add_block(arg_new(), $1);
2515 block_arg :
tAMPER arg_value
2525 opt_block_arg :
',' block_arg
2540 $$ = arg_add(arg_new(), $1);
2548 $$ = arg_add_star(arg_new(), $2);
2551 | args
',' arg_value
2562 $$ = arg_add($1, $3);
2565 | args
',' tSTAR arg_value
2576 $$ = arg_add_star($1, $4);
2581 mrhs : args
',' arg_value
2592 $$ = mrhs_add(args2mrhs($1), $3);
2595 | args
',' tSTAR arg_value
2607 $$ = mrhs_add_star(args2mrhs($1), $4);
2615 $$ = mrhs_add_star(mrhs_new(), $2);
2633 $$ = method_arg(dispatch1(fcall, $1), arg_new());
2658 $$ = dispatch1(begin, $3);
2663 rb_warning0(
"(...) interpreted as grouped expression");
2667 $$ = dispatch1(paren, $2);
2675 $$ = dispatch1(paren, $2);
2683 $$ = dispatch2(const_path_ref, $1, $3);
2691 $$ = dispatch1(top_const_ref, $2);
2728 $$ = dispatch1(yield, dispatch1(paren, $3));
2736 $$ = dispatch1(yield, dispatch1(paren, arg_new()));
2754 $$ = dispatch1(defined, $5);
2773 | operation brace_block
2780 $$ = method_arg(dispatch1(fcall, $1), arg_new());
2781 $$ = method_add_block($$, $2);
2785 | method_call brace_block
2793 $$ = method_add_block($1, $2);
2832 $$ = dispatch2(
while, $3, $6);
2843 $$ = dispatch2(until, $3, $6);
2854 $$ = dispatch2(
case, $2, $4);
2857 | k_case opt_terms case_body k_end
2862 $$ = dispatch2(
case,
Qnil, $3);
2924 tbl[0] = 1; tbl[1] =
id;
2928 $$ = dispatch3(
for, $2, $5, $8);
2931 | k_class cpath superclass
2934 yyerror(
"class definition in method body");
2948 $$ = dispatch3(
class, $2, $3, $5);
2970 $$ = dispatch2(sclass, $3, $7);
2979 yyerror(
"module definition in method body");
2993 $$ = dispatch2(module, $2, $4);
3014 $$ = dispatch3(def, $2, $4, $5);
3036 $$ = dispatch5(defs, $2, $3, $5, $7, $8);
3046 $$ = dispatch1(
break, arg_new());
3054 $$ = dispatch1(next, arg_new());
3075 primary_value : primary
3198 $$ = dispatch1(
else, $2);
3212 $$ = dispatch1(mlhs_paren, $$);
3220 $$ = dispatch1(mlhs_paren, $2);
3225 f_marg_list : f_marg
3230 $$ = mlhs_add(mlhs_new(), $1);
3233 | f_marg_list
',' f_marg
3238 $$ = mlhs_add($1, $3);
3243 f_margs : f_marg_list
3251 | f_marg_list
',' tSTAR f_norm_arg
3257 $$ = mlhs_add_star($1, $$);
3260 | f_marg_list
',' tSTAR f_norm_arg
',' f_marg_list
3266 $$ = mlhs_add_star($1, $$);
3269 | f_marg_list
',' tSTAR
3274 $$ = mlhs_add_star($1,
Qnil);
3277 | f_marg_list
',' tSTAR ',' f_marg_list
3282 $$ = mlhs_add_star($1, $5);
3291 $$ = mlhs_add_star(mlhs_new(), $$);
3294 |
tSTAR f_norm_arg
',' f_marg_list
3303 $$ = mlhs_add_star($$, $4);
3311 $$ = mlhs_add_star(mlhs_new(),
Qnil);
3314 |
tSTAR ',' f_marg_list
3319 $$ = mlhs_add_star(mlhs_new(),
Qnil);
3324 block_param : f_arg
',' f_block_optarg
',' f_rest_arg opt_f_block_arg
3332 | f_arg
',' f_block_optarg
',' f_rest_arg
',' f_arg opt_f_block_arg
3340 | f_arg
',' f_block_optarg opt_f_block_arg
3348 | f_arg
',' f_block_optarg
',' f_arg opt_f_block_arg
3356 | f_arg
',' f_rest_arg opt_f_block_arg
3370 dispatch1(excessed_comma, $$);
3373 | f_arg
',' f_rest_arg
',' f_arg opt_f_block_arg
3381 | f_arg opt_f_block_arg
3389 | f_block_optarg
',' f_rest_arg opt_f_block_arg
3397 | f_block_optarg
',' f_rest_arg
',' f_arg opt_f_block_arg
3405 | f_block_optarg opt_f_block_arg
3413 | f_block_optarg
',' f_arg opt_f_block_arg
3421 | f_rest_arg opt_f_block_arg
3429 | f_rest_arg
',' f_arg opt_f_block_arg
3447 opt_block_param : none
3454 block_param_def :
'|' opt_bv_decl
'|'
3472 |
'|' block_param opt_bv_decl
'|'
3537 $$->nd_body =
NEW_SCOPE($3->nd_head, $4);
3539 $$ = dispatch2(lambda, $3, $4);
3545 f_larglist :
'(' f_args opt_bv_decl rparen
3550 $$ = dispatch1(paren, $2);
3594 block_call : command do_block
3607 $$ = method_add_block($1, $2);
3610 | block_call
'.' operation2 opt_paren_args
3616 $$ = method_optarg($$, $4);
3619 | block_call
tCOLON2 operation2 opt_paren_args
3625 $$ = method_optarg($$, $4);
3630 method_call : operation paren_args
3636 $$ = method_arg(dispatch1(fcall, $1), $2);
3639 | primary_value
'.' operation2 opt_paren_args
3646 $$ = method_optarg($$, $4);
3649 | primary_value
tCOLON2 operation2 paren_args
3656 $$ = method_optarg($$, $4);
3659 | primary_value
tCOLON2 operation3
3667 | primary_value
'.' paren_args
3675 $$ = method_optarg($$, $3);
3678 | primary_value
tCOLON2 paren_args
3686 $$ = method_optarg($$, $3);
3694 $$ = dispatch1(super, $2);
3705 | primary_value
'[' opt_call_args rbracket
3787 $$ = dispatch4(rescue,
3797 exc_list : arg_value
3828 $$ = dispatch1(ensure, $2);
3840 $$ = dispatch1(symbol_literal, $1);
3870 $$ = dispatch2(string_concat, $1, $2);
3880 $$ = dispatch1(string_literal, $2);
3907 $$ = dispatch1(xstring_literal, $2);
3924 VALUE src = node->nd_lit;
3940 for (list = (prev = node)->nd_next;
list; list = list->nd_next) {
3942 VALUE tail = list->nd_head->nd_lit;
3944 VALUE lit = prev == node ? prev->nd_lit : prev->nd_head->nd_lit;
3950 prev->nd_next = list->nd_next;
3963 if (!node->nd_next) {
3964 VALUE src = node->nd_lit;
3972 $$ = dispatch2(regexp_literal, $2, $3);
3983 $$ = dispatch1(array, $$);
3991 $$ = dispatch1(array, $2);
4004 | word_list word
' '
4009 $$ = dispatch2(words_add, $1, $2);
4014 word : string_content
4019 $$ = dispatch2(word_add, $$, $1);
4022 | word string_content
4027 $$ = dispatch2(word_add, $1, $2);
4038 $$ = dispatch1(array, $$);
4046 $$ = dispatch1(array, $2);
4064 $$ = dispatch2(qwords_add, $1, $2);
4077 | string_contents string_content
4082 $$ = dispatch2(string_add, $1, $2);
4095 | xstring_contents string_content
4100 $$ = dispatch2(xstring_add, $1, $2);
4113 | regexp_contents string_content
4116 NODE *head = $1, *tail = $2;
4137 $$ = dispatch2(regexp_add, $1, $2);
4156 $$ = dispatch1(string_dvar, $3);
4180 $$ = dispatch1(string_embexpr, $4);
4190 $$ = dispatch1(var_ref, $1);
4198 $$ = dispatch1(var_ref, $1);
4206 $$ = dispatch1(var_ref, $1);
4218 $$ = dispatch1(symbol, $2);
4254 $$ = dispatch1(dyna_symbol, $2);
4295 var_ref : user_variable
4300 if (id_is_var(
get_id($1))) {
4301 $$ = dispatch1(var_ref, $1);
4304 $$ = dispatch1(vcall, $1);
4313 $$ = dispatch1(var_ref, $1);
4318 var_lhs : user_variable
4323 $$ = dispatch1(var_field, $$);
4331 $$ = dispatch1(var_field, $$);
4368 f_arglist :
'(' f_args rparen
4373 $$ = dispatch1(paren, $2);
4386 f_args : f_arg
',' f_optarg
',' f_rest_arg opt_f_block_arg
4394 | f_arg
',' f_optarg
',' f_rest_arg
',' f_arg opt_f_block_arg
4402 | f_arg
',' f_optarg opt_f_block_arg
4410 | f_arg
',' f_optarg
',' f_arg opt_f_block_arg
4418 | f_arg
',' f_rest_arg opt_f_block_arg
4426 | f_arg
',' f_rest_arg
',' f_arg opt_f_block_arg
4434 | f_arg opt_f_block_arg
4442 | f_optarg
',' f_rest_arg opt_f_block_arg
4450 | f_optarg
',' f_rest_arg
',' f_arg opt_f_block_arg
4458 | f_optarg opt_f_block_arg
4466 | f_optarg
',' f_arg opt_f_block_arg
4474 | f_rest_arg opt_f_block_arg
4482 | f_rest_arg
',' f_arg opt_f_block_arg
4511 yyerror(
"formal argument cannot be a constant");
4514 $$ = dispatch1(param_error, $1);
4520 yyerror(
"formal argument cannot be an instance variable");
4523 $$ = dispatch1(param_error, $1);
4529 yyerror(
"formal argument cannot be a global variable");
4532 $$ = dispatch1(param_error, $1);
4538 yyerror(
"formal argument cannot be a class variable");
4541 $$ = dispatch1(param_error, $1);
4546 f_norm_arg : f_bad_arg
4554 f_arg_item : f_norm_arg
4577 $$ = dispatch1(mlhs_paren, $2);
4589 | f_arg
',' f_arg_item
4626 f_block_optarg : f_block_opt
4634 | f_block_optarg
',' f_block_opt
4639 while (opts->nd_next) {
4640 opts = opts->nd_next;
4658 | f_optarg
',' f_opt
4663 while (opts->nd_next) {
4664 opts = opts->nd_next;
4682 yyerror(
"rest argument must be local variable");
4688 $$ = dispatch1(rest_param, $2);
4697 $$ = dispatch1(rest_param,
Qnil);
4710 yyerror(
"block argument must be local variable");
4712 yyerror(
"duplicated block argument name");
4718 $$ = dispatch1(blockarg, $2);
4723 opt_f_block_arg :
',' f_block_arg
4751 yyerror(
"can't define singleton method for ().");
4763 yyerror(
"can't define singleton method for literals");
4771 $$ = dispatch1(paren, $3);
4782 $$ = dispatch1(assoclist_from_args, $1);
4804 assoc : arg_value
tASSOC arg_value
4809 $$ = dispatch2(assoc_new, $1, $3);
4817 $$ = dispatch2(assoc_new, $1, $2);
4861 rbracket : opt_nl
']'
4890 # define yylval (*((YYSTYPE*)(parser->parser_yylval)))
4899 # define nextc() parser_nextc(parser)
4900 # define pushback(c) parser_pushback(parser, (c))
4901 # define newtok() parser_newtok(parser)
4902 # define tokspace(n) parser_tokspace(parser, (n))
4903 # define tokadd(c) parser_tokadd(parser, (c))
4904 # define tok_hex(numlen) parser_tok_hex(parser, (numlen))
4905 # define read_escape(flags,e) parser_read_escape(parser, (flags), (e))
4906 # define tokadd_escape(e) parser_tokadd_escape(parser, (e))
4907 # define regx_options() parser_regx_options(parser)
4908 # define tokadd_string(f,t,p,n,e) parser_tokadd_string(parser,(f),(t),(p),(n),(e))
4909 # define parse_string(n) parser_parse_string(parser,(n))
4910 # define tokaddmbc(c, enc) parser_tokaddmbc(parser, (c), (enc))
4911 # define here_document(n) parser_here_document(parser,(n))
4912 # define heredoc_identifier() parser_heredoc_identifier(parser)
4913 # define heredoc_restore(n) parser_heredoc_restore(parser,(n))
4914 # define whole_match_p(e,l,i) parser_whole_match_p(parser,(e),(l),(i))
4917 # define set_yylval_str(x) (yylval.node = NEW_STR(x))
4918 # define set_yylval_num(x) (yylval.num = (x))
4919 # define set_yylval_id(x) (yylval.id = (x))
4920 # define set_yylval_name(x) (yylval.id = (x))
4921 # define set_yylval_literal(x) (yylval.node = NEW_LIT(x))
4922 # define set_yylval_node(x) (yylval.node = (x))
4923 # define yylval_id() (yylval.id)
4926 ripper_yylval_id(
ID x)
4930 # define set_yylval_str(x) (void)(x)
4931 # define set_yylval_num(x) (void)(x)
4932 # define set_yylval_id(x) (void)(x)
4933 # define set_yylval_name(x) (void)(yylval.val = ripper_yylval_id(x))
4934 # define set_yylval_literal(x) (void)(x)
4935 # define set_yylval_node(x) (void)(x)
4936 # define yylval_id() yylval.id
4940 #define ripper_flush(p) (void)(p)
4942 #define ripper_flush(p) ((p)->tokp = (p)->parser_lex_p)
4944 #define yylval_rval (*(RB_TYPE_P(yylval.val, T_NODE) ? &yylval.node->nd_rval : &yylval.val))
4951 return lex_p > parser->tokp;
4964 ripper_dispatch_scan_event(
struct parser_params *parser,
int t)
4966 if (!ripper_has_scan_event(parser))
return;
4967 yylval_rval = ripper_scan_event_val(parser, t);
4971 ripper_dispatch_ignored_scan_event(
struct parser_params *parser,
int t)
4973 if (!ripper_has_scan_event(parser))
return;
4974 (void)ripper_scan_event_val(parser, t);
4978 ripper_dispatch_delayed_token(
struct parser_params *parser,
int t)
4981 const char *saved_tokp = parser->tokp;
4984 parser->tokp =
lex_pbeg + parser->delayed_col;
4986 parser->delayed =
Qnil;
4988 parser->tokp = saved_tokp;
4999 #undef SIGN_EXTEND_CHAR
5001 # define SIGN_EXTEND_CHAR(c) ((signed char)(c))
5004 # define SIGN_EXTEND_CHAR(c) ((((unsigned char)(c)) ^ 128) - 128)
5007 #define parser_encoding_name() (parser->enc->name)
5008 #define parser_mbclen() mbclen((lex_p-1),lex_pend,parser->enc)
5009 #define parser_precise_mbclen() rb_enc_precise_mbclen((lex_p-1),lex_pend,parser->enc)
5010 #define is_identchar(p,e,enc) (rb_enc_isalnum(*(p),(enc)) || (*(p)) == '_' || !ISASCII(*(p)))
5011 #define parser_is_identchar() (!parser->eofp && is_identchar((lex_p-1),lex_pend,parser->enc))
5013 #define parser_isascii() ISASCII(*(lex_p-1))
5021 for (p =
lex_pbeg; p < pend; p++) {
5023 column = (((column - 1) / 8) + 1) * 8;
5034 for (p =
lex_pbeg; p < pend; p++) {
5035 if (*p !=
' ' && *p !=
'\t') {
5042 #undef token_info_push
5059 #undef token_info_pop
5066 if (!ptinfo)
return;
5072 if (linenum == ptinfo->
linenum) {
5080 "mismatched indentations at '%s' with '%s' at %d",
5093 const int max_line_margin = 30;
5102 if (*p ==
'\n')
break;
5109 if (*pe ==
'\n')
break;
5116 const char *pre =
"", *post =
"";
5118 if (len > max_line_margin * 2 + 10) {
5119 if (
lex_p - p > max_line_margin) {
5123 if (pe -
lex_p > max_line_margin) {
5130 MEMCPY(buf, p,
char, len);
5134 i = (int)(
lex_p - p);
5135 p2 =
buf; pe = buf +
len;
5138 if (*p2 !=
'\t') *p2 =
' ';
5146 dispatch1(parse_error,
STR_NEW2(msg));
5158 CONST_ID(script_lines,
"SCRIPT_LINES__");
5175 if (
RTEST(coverages) &&
RBASIC(coverages)->klass == 0) {
5179 RBASIC(lines)->klass = 0;
5181 RARRAY(lines)->as.heap.len = n;
5264 char *beg, *end, *pend;
5274 while (end < pend) {
5275 if (*end++ ==
'\n')
break;
5285 if (
NIL_P(line))
return line;
5386 #define STR_FUNC_ESCAPE 0x01
5387 #define STR_FUNC_EXPAND 0x02
5388 #define STR_FUNC_REGEXP 0x04
5389 #define STR_FUNC_QWORDS 0x08
5390 #define STR_FUNC_SYMBOL 0x10
5391 #define STR_FUNC_INDENT 0x20
5397 str_regexp = (STR_FUNC_REGEXP|STR_FUNC_ESCAPE|STR_FUNC_EXPAND),
5399 str_dword = (STR_FUNC_QWORDS|STR_FUNC_EXPAND),
5401 str_dsym = (STR_FUNC_SYMBOL|STR_FUNC_EXPAND)
5421 #define lex_goto_eol(parser) ((parser)->parser_lex_p = (parser)->parser_lex_pend)
5422 #define lex_eol_p() (lex_p >= lex_pend)
5423 #define peek(c) peek_n((c), 0)
5424 #define peek_n(c,n) (lex_p+(n) < lex_pend && (c) == (unsigned char)lex_p[n])
5447 if (
NIL_P(parser->delayed)) {
5451 parser->tokp,
lex_pend - parser->tokp);
5453 parser->delayed_col = (int)(parser->tokp -
lex_pbeg);
5457 parser->tokp,
lex_pend - parser->tokp);
5473 c = (
unsigned char)*
lex_p++;
5474 if (c ==
'\r' &&
peek(
'\n')) {
5485 if (c == -1)
return;
5492 #define was_bol() (lex_p == lex_pbeg + 1)
5494 #define tokfix() (tokenbuf[tokidx]='\0')
5495 #define tok() tokenbuf
5496 #define toklen() tokidx
5497 #define toklast() (tokidx>0?tokenbuf[tokidx-1]:0)
5543 yyerror(
"invalid hex escape");
5550 #define tokcopy(n) memcpy(tokspace(n), lex_p - (n), (n))
5554 int string_literal,
int symbol_literal,
int regexp_literal)
5574 yyerror(
"invalid Unicode escape");
5577 if (codepoint > 0x10ffff) {
5578 yyerror(
"invalid Unicode codepoint (too large)");
5582 if (regexp_literal) {
5585 else if (codepoint >= 0x80) {
5587 if (string_literal)
tokaddmbc(codepoint, *encp);
5589 else if (string_literal) {
5592 }
while (string_literal && (
peek(
' ') ||
peek(
'\t')));
5595 yyerror(
"unterminated Unicode escape");
5599 if (regexp_literal) {
tokadd(
'}'); }
5605 yyerror(
"invalid Unicode escape");
5609 if (regexp_literal) {
5612 else if (codepoint >= 0x80) {
5614 if (string_literal)
tokaddmbc(codepoint, *encp);
5616 else if (string_literal) {
5624 #define ESCAPE_CONTROL 1
5625 #define ESCAPE_META 2
5634 switch (c =
nextc()) {
5659 case '0':
case '1':
case '2':
case '3':
5660 case '4':
case '5':
case '6':
case '7':
5668 if (numlen == 0)
return 0;
5678 if (flags & ESCAPE_META)
goto eof;
5679 if ((c =
nextc()) !=
'-') {
5683 if ((c =
nextc()) ==
'\\') {
5684 if (
peek(
'u'))
goto eof;
5685 return read_escape(flags|ESCAPE_META, encp) | 0x80;
5687 else if (c == -1 || !
ISASCII(c))
goto eof;
5689 return ((c & 0xff) | 0x80);
5693 if ((c =
nextc()) !=
'-') {
5698 if (flags & ESCAPE_CONTROL)
goto eof;
5699 if ((c =
nextc())==
'\\') {
5700 if (
peek(
'u'))
goto eof;
5705 else if (c == -1 || !
ISASCII(c))
goto eof;
5710 yyerror(
"Invalid escape character syntax");
5733 switch (c =
nextc()) {
5737 case '0':
case '1':
case '2':
case '3':
5738 case '4':
case '5':
case '6':
case '7':
5741 if (numlen == 0)
goto eof;
5750 if (numlen == 0)
return -1;
5756 if (flags & ESCAPE_META)
goto eof;
5757 if ((c =
nextc()) !=
'-') {
5762 flags |= ESCAPE_META;
5766 if (flags & ESCAPE_CONTROL)
goto eof;
5767 if ((c =
nextc()) !=
'-') {
5775 if (flags & ESCAPE_CONTROL)
goto eof;
5777 flags |= ESCAPE_CONTROL;
5779 if ((c =
nextc()) ==
'\\') {
5782 else if (c == -1)
goto eof;
5788 yyerror(
"Invalid escape character syntax");
5857 #define tokadd_mbchar(c) parser_tokadd_mbchar(parser, (c))
5861 int func,
int term,
int paren,
long *nest,
5865 int has_nonascii = 0;
5868 static const char mixed_msg[] =
"%s mixed within %s source";
5870 #define mixed_error(enc1, enc2) if (!errbuf) { \
5871 size_t len = sizeof(mixed_msg) - 4; \
5872 len += strlen(rb_enc_name(enc1)); \
5873 len += strlen(rb_enc_name(enc2)); \
5874 errbuf = ALLOCA_N(char, len); \
5875 snprintf(errbuf, len, mixed_msg, \
5876 rb_enc_name(enc1), \
5877 rb_enc_name(enc2)); \
5880 #define mixed_escape(beg, enc1, enc2) do { \
5881 const char *pos = lex_p; \
5883 mixed_error((enc1), (enc2)); \
5887 while ((c =
nextc()) != -1) {
5888 if (paren && c == paren) {
5891 else if (c == term) {
5892 if (!nest || !*nest) {
5898 else if ((func & STR_FUNC_EXPAND) && c ==
'#' &&
lex_p <
lex_pend) {
5900 if (c2 ==
'$' || c2 ==
'@' || c2 ==
'{') {
5905 else if (c ==
'\\') {
5906 const char *beg =
lex_p - 1;
5910 if (func & STR_FUNC_QWORDS)
break;
5911 if (func & STR_FUNC_EXPAND)
continue;
5916 if (func & STR_FUNC_ESCAPE)
tokadd(c);
5920 if ((func & STR_FUNC_EXPAND) == 0) {
5925 func & STR_FUNC_SYMBOL,
5926 func & STR_FUNC_REGEXP);
5927 if (has_nonascii && enc != *encp) {
5933 if (c == -1)
return -1;
5935 if ((func & STR_FUNC_EXPAND) == 0)
tokadd(
'\\');
5938 if (func & STR_FUNC_REGEXP) {
5942 if (has_nonascii && enc != *encp) {
5947 else if (func & STR_FUNC_EXPAND) {
5949 if (func & STR_FUNC_ESCAPE)
tokadd(
'\\');
5952 else if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
5955 else if (c != term && !(paren && c == paren)) {
5972 else if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
5989 #define NEW_STRTERM(func, term, paren) \
5990 rb_node_newnode(NODE_STRTERM, (func), (term) | ((paren) << (CHAR_BIT * 2)), 0)
5996 if (!
NIL_P(parser->delayed)) {
5997 ptrdiff_t len =
lex_p - parser->tokp;
6002 parser->tokp =
lex_p;
6006 #define flush_string_content(enc) ripper_flush_string_content(parser, (enc))
6008 #define flush_string_content(enc) ((void)(enc))
6015 #define BIT(c, idx) (((c) / 32 - 1 == idx) ? (1U << ((c) % 32)) : 0)
6016 #define SPECIAL_PUNCT(idx) ( \
6017 BIT('~', idx) | BIT('*', idx) | BIT('$', idx) | BIT('?', idx) | \
6018 BIT('!', idx) | BIT('@', idx) | BIT('/', idx) | BIT('\\', idx) | \
6019 BIT(';', idx) | BIT(',', idx) | BIT('.', idx) | BIT('=', idx) | \
6020 BIT(':', idx) | BIT('<', idx) | BIT('>', idx) | BIT('\"', idx) | \
6021 BIT('&', idx) | BIT('`', idx) | BIT('\'', idx) | BIT('+', idx) | \
6029 #undef SPECIAL_PUNCT
6035 if (c <= 0x20 || 0x7e < c)
return 0;
6036 return (ruby_global_name_punct_bits[(c - 0x20) / 32] >> (c % 32)) & 1;
6043 const char *p =
lex_p;
6049 if ((c = *p) ==
'-') {
6058 if ((c = *p) ==
'@') {
6078 int func = (int)quote->nd_func;
6086 if ((func & STR_FUNC_QWORDS) &&
ISSPACE(c)) {
6090 if (c == term && !quote->nd_nest) {
6091 if (func & STR_FUNC_QWORDS) {
6092 quote->nd_func = -1;
6095 if (!(func & STR_FUNC_REGEXP))
return tSTRING_END;
6104 if ((func & STR_FUNC_EXPAND) && c ==
'#') {
6114 if (func & STR_FUNC_REGEXP) {
6136 int c =
nextc(), term, func = 0;
6154 while ((c =
nextc()) != -1 && c != term) {
6166 if (func & STR_FUNC_INDENT) {
6201 line = here->nd_orig;
6205 lex_p = lex_pbeg + here->nd_nth;
6215 const char *eos,
long len,
int indent)
6221 while (*p &&
ISSPACE(*p)) p++;
6224 if (n < 0 || (n > 0 && p[len] !=
'\n' && p[len] !=
'\r'))
return FALSE;
6225 return strncmp(eos, p, len) == 0;
6232 if (!
NIL_P(parser->delayed))
6235 ripper_dispatch_ignored_scan_event(parser,
tHEREDOC_END);
6238 #define dispatch_heredoc_end() ripper_dispatch_heredoc_end(parser)
6240 #define dispatch_heredoc_end() ((void)0)
6246 int c,
func, indent = 0;
6247 const char *eos, *
p, *pend;
6254 indent = (func = *eos++) & STR_FUNC_INDENT;
6256 if ((c =
nextc()) == -1) {
6260 if (
NIL_P(parser->delayed)) {
6265 ((len =
lex_p - parser->tokp) > 0 &&
6266 (str =
STR_NEW3(parser->tokp, len, enc, func), 1))) {
6284 if (!(func & STR_FUNC_EXPAND)) {
6291 if (--pend == p || pend[-1] !=
'\r') {
6305 if (
nextc() == -1) {
6323 if (parser->
eofp)
goto error;
6333 if ((c =
nextc()) == -1)
goto error;
6350 rb_warning0(
"ambiguous first argument; put parentheses or even spaces");
6355 #define arg_ambiguous() (arg_ambiguous_gen(parser), 1)
6362 yyerror(
"formal argument must be local variable");
6380 if (len > 5 && name[nlen = len - 5] ==
'-') {
6384 if (len > 4 && name[nlen = len - 4] ==
'-') {
6387 if (
rb_memcicmp(name + nlen + 1,
"mac", 3) == 0 &&
6388 !(len == 8 &&
rb_memcicmp(name,
"utf8-mac", len) == 0))
6403 excargs[1] =
rb_sprintf(
"unknown encoding name: %s", name);
6420 for (i = 0; i < n; ++
i) {
6495 if (str[i-1] ==
'*' && str[i-2] ==
'-') {
6501 if (i + 1 >= len)
return 0;
6502 if (str[i+1] !=
'-') {
6505 else if (str[i-1] !=
'-') {
6523 VALUE name = 0, val = 0;
6524 const char *beg, *end, *vbeg, *vend;
6525 #define str_copy(_s, _p, _n) ((_s) \
6526 ? (void)(rb_str_resize((_s), (_n)), \
6527 MEMCPY(RSTRING_PTR(_s), (_p), char, (_n)), (_s)) \
6528 : (void)((_s) = STR_NEW((_p), (_n))))
6530 if (len <= 7)
return FALSE;
6534 len = end - beg - 3;
6545 for (; len > 0 && *str; str++, --
len) {
6547 case '\'':
case '"':
case ':':
case ';':
6552 for (beg = str; len > 0; str++, --
len) {
6554 case '\'':
case '"':
case ':':
case ';':
6562 for (end = str; len > 0 &&
ISSPACE(*str); str++, --
len);
6564 if (*str !=
':')
continue;
6566 do str++;
while (--len > 0 &&
ISSPACE(*str));
6569 for (vbeg = ++str; --len > 0 && *str !=
'"'; str++) {
6582 for (vbeg = str; len > 0 && *str !=
'"' && *str !=
';' && !
ISSPACE(*str); --
len, str++);
6585 while (len > 0 && (*str ==
';' ||
ISSPACE(*str))) --len, str++;
6590 for (i = 0; i < n; ++
i) {
6591 if (s[i] ==
'-') s[
i] =
'_';
6598 n = (*p->
length)(parser, vbeg, n);
6604 }
while (++p < magic_comments +
numberof(magic_comments));
6618 const char *beg = str;
6622 if (send - str <= 6)
return;
6624 case 'C':
case 'c': str += 6;
continue;
6625 case 'O':
case 'o': str += 5;
continue;
6626 case 'D':
case 'd': str += 4;
continue;
6627 case 'I':
case 'i': str += 3;
continue;
6628 case 'N':
case 'n': str += 2;
continue;
6629 case 'G':
case 'g': str += 1;
continue;
6643 if (++str >= send)
return;
6646 if (*str !=
'=' && *str !=
':')
return;
6651 while ((*str ==
'-' || *str ==
'_' ||
ISALNUM(*str)) && ++str < send);
6667 (
unsigned char)
lex_p[0] == 0xbb &&
6668 (
unsigned char)
lex_p[1] == 0xbf) {
6682 #define IS_ARG() (lex_state == EXPR_ARG || lex_state == EXPR_CMDARG)
6683 #define IS_END() (lex_state == EXPR_END || lex_state == EXPR_ENDARG || lex_state == EXPR_ENDFN)
6684 #define IS_BEG() (lex_state == EXPR_BEG || lex_state == EXPR_MID || lex_state == EXPR_VALUE || lex_state == EXPR_CLASS)
6685 #define IS_SPCARG(c) (IS_ARG() && space_seen && !ISSPACE(c))
6686 #define IS_LABEL_POSSIBLE() ((lex_state == EXPR_BEG && !cmd_state) || IS_ARG())
6687 #define IS_LABEL_SUFFIX(n) (peek_n(':',(n)) && !peek_n(':', (n)+1))
6690 #define ambiguous_operator(op, syn) ( \
6691 rb_warning0("`"op"' after local variable is interpreted as binary operator"), \
6692 rb_warning0("even though it seems like "syn""))
6694 #define ambiguous_operator(op, syn) dispatch2(operator_ambiguous, ripper_intern(op), rb_str_new_cstr(syn))
6696 #define warn_balanced(op, syn) ((void) \
6697 (last_state != EXPR_CLASS && last_state != EXPR_DOT && \
6698 last_state != EXPR_FNAME && last_state != EXPR_ENDFN && \
6699 last_state != EXPR_ENDARG && \
6700 space_seen && !ISSPACE(c) && \
6701 (ambiguous_operator(op, syn), 0)))
6713 int fallthru =
FALSE;
6739 switch (c =
nextc()) {
6747 case ' ':
case '\t':
case '\f':
case '\r':
6751 while ((c =
nextc())) {
6753 case ' ':
case '\t':
case '\f':
case '\r':
6762 ripper_dispatch_scan_event(parser,
tSP);
6775 ripper_dispatch_scan_event(parser,
tCOMMENT);
6796 while ((c =
nextc())) {
6798 case ' ':
case '\t':
case '\f':
case '\r':
6803 if ((c =
nextc()) !=
'.') {
6816 parser->tokp =
lex_p;
6819 goto normal_newline;
6828 if ((c =
nextc()) ==
'*') {
6829 if ((c =
nextc()) ==
'=') {
6845 rb_warning0(
"`*' interpreted as argument prefix");
6898 ripper_dispatch_scan_event(parser,
tEMBDOC);
6907 if (c !=
'=')
continue;
6908 if (strncmp(
lex_p,
"end", 3) == 0 &&
6927 if ((c =
nextc()) ==
'=') {
6928 if ((c =
nextc()) ==
'=') {
6937 else if (c ==
'>') {
6950 (!
IS_ARG() || space_seen)) {
6952 if (token)
return token;
6961 if ((c =
nextc()) ==
'>') {
6968 if ((c =
nextc()) ==
'=') {
6987 if ((c =
nextc()) ==
'=') {
6991 if ((c =
nextc()) ==
'=') {
7059 rb_warnI(
"invalid character syntax; use ?\\%c", c2);
7076 else if (c ==
'\\') {
7105 if ((c =
nextc()) ==
'&') {
7107 if ((c =
nextc()) ==
'=') {
7115 else if (c ==
'=') {
7122 rb_warning0(
"`&' interpreted as argument prefix");
7141 if ((c =
nextc()) ==
'|') {
7143 if ((c =
nextc()) ==
'=') {
7228 if ((c =
nextc()) ==
'.') {
7229 if ((c =
nextc()) ==
'.') {
7237 yyerror(
"no .<digit> floating literal anymore; put 0 before dot");
7243 case '0':
case '1':
case '2':
case '3':
case '4':
7244 case '5':
case '6':
case '7':
case '8':
case '9':
7246 int is_float, seen_point, seen_e, nondigit;
7248 is_float = seen_point = seen_e = nondigit = 0;
7251 if (c ==
'-' || c ==
'+') {
7256 #define no_digits() do {yyerror("numeric literal without digits"); return 0;} while (0)
7259 if (c ==
'x' || c ==
'X') {
7265 if (nondigit)
break;
7272 }
while ((c =
nextc()) != -1);
7279 else if (nondigit)
goto trailing_uc;
7283 if (c ==
'b' || c ==
'B') {
7286 if (c ==
'0' || c ==
'1') {
7289 if (nondigit)
break;
7293 if (c !=
'0' && c !=
'1')
break;
7296 }
while ((c =
nextc()) != -1);
7303 else if (nondigit)
goto trailing_uc;
7307 if (c ==
'd' || c ==
'D') {
7313 if (nondigit)
break;
7320 }
while ((c =
nextc()) != -1);
7327 else if (nondigit)
goto trailing_uc;
7335 if (c ==
'o' || c ==
'O') {
7338 if (c == -1 || c ==
'_' || !
ISDIGIT(c)) {
7342 if (c >=
'0' && c <=
'7') {
7347 if (nondigit)
break;
7351 if (c < '0' || c >
'9')
break;
7352 if (c >
'7')
goto invalid_octal;
7355 }
while ((c =
nextc()) != -1);
7359 if (nondigit)
goto trailing_uc;
7368 if (c >
'7' && c <=
'9') {
7370 yyerror(
"Invalid octal digit");
7372 else if (c ==
'.' || c ==
'e' || c ==
'E') {
7384 case '0':
case '1':
case '2':
case '3':
case '4':
7385 case '5':
case '6':
case '7':
case '8':
case '9':
7391 if (nondigit)
goto trailing_uc;
7392 if (seen_point || seen_e) {
7397 if (c0 == -1 || !
ISDIGIT(c0)) {
7425 if (c !=
'-' && c !=
'+')
continue;
7431 if (nondigit)
goto decode_num;
7446 snprintf(tmp,
sizeof(tmp),
"trailing `%c' in number", nondigit);
7452 if (errno == ERANGE) {
7510 if ((c =
nextc()) ==
'=') {
7531 if ((c =
nextc()) ==
'=') {
7556 if ((c =
nextc()) !=
'@') {
7583 if ((c =
nextc()) ==
']') {
7584 if ((c =
nextc()) ==
'=') {
7596 else if (
IS_ARG() && space_seen) {
7630 ripper_dispatch_scan_event(parser,
tSP);
7651 yyerror(
"unknown type of %string");
7655 if (c == -1 || term == -1) {
7660 if (term ==
'(') term =
')';
7661 else if (term ==
'[') term =
']';
7662 else if (term ==
'{') term =
'}';
7663 else if (term ==
'<') term =
'>';
7701 yyerror(
"unknown type of %string");
7705 if ((c =
nextc()) ==
'=') {
7787 case '1':
case '2':
case '3':
7788 case '4':
case '5':
case '6':
7789 case '7':
case '8':
case '9':
7794 }
while (c != -1 &&
ISDIGIT(c));
7840 ripper_dispatch_scan_event(parser,
k__END__);
7868 if ((c ==
'!' || c ==
'?') && !
peek(
'=')) {
7888 if (
tok()[1] ==
'@')
7955 if (kw->
id[0] != kw->
id[1])
7994 yylex(
void *lval,
void *p)
8008 if (!
NIL_P(parser->delayed)) {
8009 ripper_dispatch_delayed_token(parser, t);
8013 ripper_dispatch_scan_event(parser, t);
8055 if (orig == (
NODE*)1)
return;
8064 #define parser_warning(node, mesg) parser_warning(parser, (node), (mesg))
8071 #define parser_warn(node, mesg) parser_warn(parser, (node), (mesg))
8076 NODE *end, *h = head, *nd;
8078 if (tail == 0)
return head;
8080 if (h == 0)
return tail;
8119 tail->nd_end = tail;
8121 end->nd_next = tail;
8122 h->nd_end = tail->nd_end;
8132 if (list == 0)
return NEW_LIST(item);
8133 if (list->nd_next) {
8134 last = list->nd_next->nd_end;
8142 list->nd_next->nd_end = last->nd_next;
8152 if (head->nd_next) {
8153 last = head->nd_next->nd_end;
8159 head->nd_alen += tail->nd_alen;
8160 last->nd_next = tail;
8161 if (tail->nd_next) {
8162 head->nd_next->nd_end = tail->nd_next->nd_end;
8165 head->nd_next->nd_end = tail;
8174 if (
NIL_P(tail))
return 1;
8193 if (!head)
return tail;
8194 if (!tail)
return head;
8221 tail->nd_lit = head->nd_lit;
8225 else if (
NIL_P(tail->nd_lit)) {
8226 head->nd_alen += tail->nd_alen - 1;
8227 head->nd_next->nd_end->nd_next = tail->nd_next;
8228 head->nd_next->nd_end = tail->nd_next->nd_end;
8233 tail->nd_head =
NEW_STR(tail->nd_lit);
8372 switch (
id & ID_SCOPE_MASK) {
8397 # define assignable_result(x) get_value(lhs)
8398 # define parser_yyerror(parser, x) dispatch1(assign_error, lhs)
8400 # define assignable_result(x) (x)
8404 yyerror(
"Can't change the value of self");
8407 yyerror(
"Can't assign to nil");
8410 yyerror(
"Can't assign to true");
8413 yyerror(
"Can't assign to false");
8416 yyerror(
"Can't assign to __FILE__");
8419 yyerror(
"Can't assign to __LINE__");
8422 yyerror(
"Can't assign to __ENCODING__");
8456 yyerror(
"dynamic constant assignment");
8465 #undef assignable_result
8466 #undef parser_yyerror
8469 #define LVAR_USED ((int)1 << (sizeof(int) * CHAR_BIT - 1))
8474 if (idUScore == name)
return name;
8477 yyerror(
"duplicated argument name");
8489 yyerror(
"duplicated argument name");
8528 id &= ~ID_SCOPE_MASK;
8557 if (!node2)
return node1;
8561 node1->nd_head =
arg_concat(node1->nd_head, node2);
8573 node1->nd_body =
list_concat(node1->nd_body, node2);
8582 if (!node1)
return NEW_LIST(node2);
8587 node1->nd_head =
arg_append(node1->nd_head, node2);
8620 lhs->nd_value = rhs;
8625 lhs->nd_args =
arg_append(lhs->nd_args, rhs);
8656 if (!cond)
yyerror(
"void value expression");
8661 while (node->nd_next) {
8662 node = node->nd_next;
8664 node = node->nd_head;
8668 node = node->nd_body;
8672 if (!node->nd_body) {
8673 node = node->nd_else;
8676 else if (!node->nd_else) {
8677 node = node->nd_body;
8681 node = node->nd_else;
8687 node = node->nd_2nd;
8701 const char *useless = 0;
8708 switch (node->nd_mid) {
8739 useless =
"a variable";
8742 useless =
"a constant";
8749 useless =
"a literal";
8774 useless =
"defined?";
8782 rb_warnS(
"possibly useless use of %s in void context", useless);
8795 if (!node->nd_next)
return;
8797 node = node->nd_next;
8804 NODE **n = &node, *n1 = node;
8806 *n = n1 = n1->nd_body;
8820 #define subnodes(n1, n2) \
8821 ((!node->n1) ? (node->n2 ? (body = &node->n2, 1) : 0) : \
8822 (!node->n2) ? (body = &node->n1, 1) : \
8823 (reduce_nodes(&node->n1), body = &node->n2, 1))
8826 int newline = (int)(node->
flags & NODE_FL_NEWLINE);
8833 *body = node = node->nd_stts;
8837 *body = node = node->nd_body;
8841 body = &node->nd_end->nd_head;
8844 if (
subnodes(nd_body, nd_else))
break;
8847 body = &node->nd_body;
8850 if (!
subnodes(nd_body, nd_next))
goto end;
8853 if (!
subnodes(nd_head, nd_resq))
goto end;
8856 if (node->nd_else) {
8857 body = &node->nd_resq;
8860 if (!
subnodes(nd_head, nd_resq))
goto end;
8877 yyerror(
"multiple assignment in conditional");
8891 if (!node->nd_value)
return 1;
8892 switch (
nd_type(node->nd_value)) {
8899 parser_warn(node->nd_value,
"found = in conditional, should be ==");
8928 NODE *node, *next, *head;
8930 for (node = *rootnode; node; node = next) {
8934 next = node->nd_next;
8935 head = node->nd_head;
8938 switch (type =
nd_type(head)) {
8941 val =
rb_range_new(head->nd_beg->nd_lit, head->nd_end->nd_lit,
8961 if (node == 0)
return 0;
8969 return cond0(parser, node);
8975 if (!node)
return 1;
8996 if (node == 0)
return 0;
9003 rb_warn0(
"string literal in condition");
9013 node->nd_1st =
cond0(parser, node->nd_1st);
9014 node->nd_2nd =
cond0(parser, node->nd_2nd);
9019 node->nd_beg =
range_op(parser, node->nd_beg);
9020 node->nd_end =
range_op(parser, node->nd_end);
9053 if (node == 0)
return 0;
9054 return cond0(parser, node);
9062 NODE *node = left, *second;
9063 while ((second = node->nd_2nd) != 0 && (
enum node_type)
nd_type(second) == type) {
9066 node->nd_2nd =
NEW_NODE(type, second, right, 0);
9069 return NEW_NODE(type, left, right, 0);
9086 if (node->nd_next == 0) {
9087 node = node->nd_head;
9117 switch (
TYPE(node->nd_lit)) {
9137 node2->nd_head = node1;
9150 node =
NEW_ARGS(m ? m->nd_plen : 0, o);
9151 i1 = m ? m->nd_next : 0;
9156 node->nd_next->nd_next =
NEW_ARGS_AUX(p->nd_pid, p->nd_plen);
9175 if (!local->
used)
return;
9179 if (cnt != local->
vars->
pos) {
9180 rb_bug(
"local->used->pos != local->vars->pos");
9182 for (i = 0; i <
cnt; ++
i) {
9183 if (!v[i] || (u[i] & LVAR_USED))
continue;
9184 if (idUScore == v[i])
continue;
9227 for (i = 0; i <
cnt; i++) {
9228 buf[
i] = src->
tbl[
i];
9241 if (cnt <= 0)
return 0;
9279 if (used) used = used->
prev;
9290 if (i && used) used->
tbl[i-1] |= LVAR_USED;
9295 static const struct vtable *
9311 if ((tmp =
lvtbl->used) != 0) {
9327 while (
lvtbl->args != lvargs) {
9359 if (used) used->
tbl[i-1] |= LVAR_USED;
9365 if (used) used = used->
prev;
9418 "regexp encoding option '%c' differs from source encoding '%s'",
9447 int back_num,
int *back_refs,
OnigRegex regex,
void *arg0)
9452 long len = name_end -
name;
9453 const char *s = (
const char *)name;
9470 rb_warningS(
"named capture conflicts a local variable - %s",
9553 if (!node)
return node;
9557 node = node->nd_body;
9561 node = node->nd_body;
9568 prelude->nd_body = node;
9569 scope->nd_body = prelude;
9572 scope->nd_body = node;
9585 if (!node)
return node;
9589 node = node->nd_body;
9593 node = node->nd_body;
9609 prelude->nd_body = node;
9610 scope->nd_body = prelude;
9613 scope->nd_body = node;
9619 static const struct {
9643 #define op_tbl_count numberof(op_tbl)
9645 #ifndef ENABLE_SELECTOR_NAMESPACE
9646 #define ENABLE_SELECTOR_NAMESPACE 0
9653 #if ENABLE_SELECTOR_NAMESPACE
9665 #if ENABLE_SELECTOR_NAMESPACE
9672 ivar2_cmp(
struct ivar2_key *key1,
struct ivar2_key *key2)
9674 if (key1->id == key2->id && key1->klass == key2->klass) {
9681 ivar2_hash(
struct ivar2_key *
key)
9683 return (key->id << 8) ^ (key->klass >> 2);
9697 #if ENABLE_SELECTOR_NAMESPACE
9728 if (m >= e)
return 0;
9732 else if (*m ==
'-') {
9746 return m == e ? mb + 1 : 0;
9764 const char *m =
name;
9765 const char *e = m +
len;
9766 int localid =
FALSE;
9768 if (!m || len <= 0)
return FALSE;
9778 if (*++m ==
'@') ++m;
9783 case '<': ++m;
break;
9784 case '=':
if (*++m ==
'>') ++m;
break;
9791 case '>':
case '=': ++m;
break;
9797 case '~': ++m;
break;
9798 case '=':
if (*++m ==
'=') ++m;
break;
9799 default:
return FALSE;
9804 if (*++m ==
'*') ++m;
9808 if (*++m ==
'@') ++m;
9811 case '|':
case '^':
case '&':
case '/':
case '%':
case '~':
case '`':
9816 if (*++m !=
']')
return FALSE;
9817 if (*++m ==
'=') ++m;
9821 if (len == 1)
return TRUE;
9823 case '=':
case '~': ++m;
break;
9824 default:
return FALSE;
9836 case '!':
case '?':
case '=': ++m;
9857 const char *m =
name;
9858 const char *e = m +
len;
9868 fake_str.as.heap.len =
len;
9869 fake_str.as.heap.ptr = (
char *)name;
9870 fake_str.as.heap.aux.capa =
len;
9871 str = (
VALUE)&fake_str;
9917 if (*
op_tbl[i].name == *m &&
9918 strcmp(
op_tbl[i].name, m) == 0) {
9925 if (m[last] ==
'=') {
9955 if (m - name < len)
id =
ID_JUNK;
9962 for (; m <= name +
len; ++m) {
10027 name[0] = (char)
id;
10035 for (i = 0; i < op_tbl_count; i++) {
10036 if (
op_tbl[i].token ==
id) {
10050 if (
RBASIC(str)->klass == 0)
10056 ID id2 = (
id & ~ID_SCOPE_MASK) | ID_LOCAL;
10061 id2 = (
id & ~ID_SCOPE_MASK) | ID_CONST;
10068 if (
RBASIC(str)->klass == 0)
10081 if (!str)
return 0;
10183 parser->parser_ruby_sourcefile_string =
Qnil;
10184 parser->delayed =
Qnil;
10186 parser->result =
Qnil;
10187 parser->parsing_thread =
Qnil;
10188 parser->toplevel_p =
TRUE;
10197 #define parser_mark ripper_parser_mark
10198 #define parser_free ripper_parser_free
10216 rb_gc_mark(p->parser_ruby_sourcefile_string);
10238 prev = local->
prev;
10252 size_t size =
sizeof(*p);
10254 if (!ptr)
return 0;
10257 size +=
sizeof(*local);
10282 #undef rb_reserved_word
10371 #define HEAPCNT(n, size) ((n) * (size) / sizeof(YYSTYPE))
10372 #define NEWHEAP() rb_node_newnode(NODE_ALLOCA, 0, (VALUE)parser->heap, 0)
10373 #define ADD2HEAP(n, c, p) ((parser->heap = (n))->u1.node = (p), \
10374 (n)->u3.cnt = (c), (p))
10379 size_t cnt =
HEAPCNT(1, size);
10389 size_t cnt =
HEAPCNT(nelem, size);
10391 void *ptr =
xcalloc(nelem, size);
10400 size_t cnt =
HEAPCNT(1, size);
10402 if (ptr && (n = parser->
heap) != NULL) {
10404 if (n->
u1.
node == ptr) {
10409 }
while ((n = n->
u2.
node) != NULL);
10421 while ((n = *prev) != NULL) {
10422 if (n->
u1.
node == ptr) {
10435 #ifdef RIPPER_DEBUG
10436 extern int rb_is_pointer_to_heap(
VALUE);
10442 if (x ==
Qfalse)
return x;
10443 if (x ==
Qtrue)
return x;
10444 if (x ==
Qnil)
return x;
10449 if (!rb_is_pointer_to_heap(x))
10462 return ((
NODE *)x)->nd_rval;
10471 #define validate(x) ((x) = get_value(x))
10483 return rb_funcall(parser->value, mid, 1, a);
10491 return rb_funcall(parser->value, mid, 2, a, b);
10500 return rb_funcall(parser->value, mid, 3, a, b, c);
10510 return rb_funcall(parser->value, mid, 4, a, b, c, d);
10521 return rb_funcall(parser->value, mid, 5, a, b, c, d, e);
10524 static const struct kw_assoc {
10527 } keyword_to_name[] = {
10580 keyword_id_to_str(
ID id)
10582 const struct kw_assoc *a;
10584 for (a = keyword_to_name; a->id; a++) {
10591 #undef ripper_id2sym
10603 if ((name = keyword_id_to_str(
id))) {
10616 rb_bug(
"cannot convert ID to string: %ld", (
unsigned long)
id);
10624 ripper_get_id(
VALUE v)
10634 ripper_get_value(
VALUE v)
10641 return nd->nd_rval;
10645 ripper_compile_error(
struct parser_params *parser,
const char *fmt, ...)
10650 va_start(args, fmt);
10657 ripper_warn0(
struct parser_params *parser,
const char *fmt)
10663 ripper_warnI(
struct parser_params *parser,
const char *fmt,
int a)
10671 ripper_warnS(
struct parser_params *parser,
const char *fmt,
const char *str)
10679 ripper_warning0(
struct parser_params *parser,
const char *fmt)
10685 ripper_warningS(
struct parser_params *parser,
const char *fmt,
const char *str)
10698 ripper_s_allocate(
VALUE klass)
10710 #define ripper_initialized_p(r) ((r)->parser_lex_input != 0)
10726 VALUE src, fname, lineno;
10729 rb_scan_args(argc, argv,
"12", &src, &fname, &lineno);
10739 if (
NIL_P(fname)) {
10747 parser->parser_ruby_sourcefile_string = fname;
10754 struct ripper_args {
10761 ripper_parse0(
VALUE parser_v)
10767 ripper_yyparse((
void*)parser);
10768 return parser->result;
10772 ripper_ensure(
VALUE parser_v)
10777 parser->parsing_thread =
Qnil;
10788 ripper_parse(
VALUE self)
10793 if (!ripper_initialized_p(parser)) {
10796 if (!
NIL_P(parser->parsing_thread)) {
10803 rb_ensure(ripper_parse0,
self, ripper_ensure,
self);
10805 return parser->result;
10816 ripper_column(
VALUE self)
10822 if (!ripper_initialized_p(parser)) {
10825 if (
NIL_P(parser->parsing_thread))
return Qnil;
10837 ripper_filename(
VALUE self)
10842 if (!ripper_initialized_p(parser)) {
10845 return parser->parser_ruby_sourcefile_string;
10856 ripper_lineno(
VALUE self)
10861 if (!ripper_initialized_p(parser)) {
10864 if (
NIL_P(parser->parsing_thread))
return Qnil;
10868 #ifdef RIPPER_DEBUG
10890 InitVM_ripper(
void)
10913 #ifdef RIPPER_DEBUG