summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y1191
1 files changed, 464 insertions, 727 deletions
diff --git a/parse.y b/parse.y
index 24f19a683c..4cae4b8165 100644
--- a/parse.y
+++ b/parse.y
@@ -83,6 +83,9 @@ static NODE *reg_named_capture_assign(struct parser_params* p, VALUE regexp, con
#define compile_callback rb_suppress_tracing
#endif /* !UNIVERSAL_PARSER */
+#define NODE_SPECIAL_EMPTY_ARGS ((NODE *)-1)
+#define NODE_EMPTY_ARGS_P(node) ((node) == NODE_SPECIAL_EMPTY_ARGS)
+
static int rb_parser_string_hash_cmp(rb_parser_string_t *str1, rb_parser_string_t *str2);
#ifndef RIPPER
@@ -297,7 +300,6 @@ parse_isxdigit(int c)
#define STRNCASECMP rb_parser_st_locale_insensitive_strncasecmp
#ifdef RIPPER
-VALUE rb_ripper_none;
#include "ripper_init.h"
#endif
@@ -489,7 +491,7 @@ struct parser_params {
struct {
rb_strterm_t *strterm;
- VALUE (*gets)(struct parser_params*,rb_parser_input_data,int);
+ rb_parser_lex_gets_func *gets;
rb_parser_input_data input;
parser_string_buffer_t string_buffer;
rb_parser_string_t *lastline;
@@ -537,8 +539,6 @@ struct parser_params {
int end_col;
} delayed;
- ID cur_arg;
-
rb_ast_t *ast;
int node_id;
@@ -637,10 +637,10 @@ static void
after_reduce(int len, struct parser_params *p)
{
for (int i = 0; i < len; i++) {
+ VALUE tos = rb_ary_pop(p->s_value_stack);
if (p->debug) {
- rb_parser_printf(p, "after-reduce pop: %+"PRIsVALUE"\n", rb_ary_entry(p->s_value_stack, -1));
+ rb_parser_printf(p, "after-reduce pop: %+"PRIsVALUE"\n", tos);
}
- rb_ary_pop(p->s_value_stack);
}
if (p->debug) {
rb_parser_printf(p, "after-reduce push: %+"PRIsVALUE"\n", p->s_lvalue);
@@ -662,10 +662,10 @@ static void
after_pop_stack(int len, struct parser_params *p)
{
for (int i = 0; i < len; i++) {
+ VALUE tos = rb_ary_pop(p->s_value_stack);
if (p->debug) {
- rb_parser_printf(p, "after-pop-stack pop: %+"PRIsVALUE"\n", rb_ary_entry(p->s_value_stack, -1));
+ rb_parser_printf(p, "after-pop-stack pop: %+"PRIsVALUE"\n", tos);
}
- rb_ary_pop(p->s_value_stack);
}
}
#else
@@ -1303,7 +1303,6 @@ struct RNode_DEF_TEMP {
ID nd_mid;
struct {
- ID cur_arg;
int max_numparam;
NODE *numparam_save;
struct lex_context ctxt;
@@ -1449,7 +1448,7 @@ static NODE *assignable(struct parser_params*,ID,NODE*,const YYLTYPE*);
static NODE *aryset(struct parser_params*,NODE*,NODE*,const YYLTYPE*);
static NODE *attrset(struct parser_params*,NODE*,ID,ID,const YYLTYPE*);
-static void rb_backref_error(struct parser_params*,NODE*);
+static VALUE rb_backref_error(struct parser_params*,NODE*);
static NODE *node_assign(struct parser_params*,NODE*,NODE*,struct lex_context,const YYLTYPE*);
static NODE *new_op_assign(struct parser_params *p, NODE *lhs, ID op, NODE *rhs, struct lex_context, const YYLTYPE *loc);
@@ -1491,14 +1490,8 @@ static NODE *heredoc_dedent(struct parser_params*,NODE*);
static void check_literal_when(struct parser_params *p, NODE *args, const YYLTYPE *loc);
#ifdef RIPPER
-static VALUE var_field(struct parser_params *p, VALUE a);
#define get_value(idx) (rb_ary_entry(p->s_value_stack, idx))
#define set_value(val) (p->s_lvalue = val)
-static VALUE defs(struct parser_params *p, VALUE head, VALUE args, VALUE bodystmt);
-static VALUE backref_error(struct parser_params*, NODE *, VALUE);
-static VALUE ripper_assignable(struct parser_params *p, ID id, VALUE lhs);
-static VALUE ripper_const_decl(struct parser_params *p, VALUE path);
-static VALUE ripper_heredoc_dedent(struct parser_params *p, int indent, VALUE array);
static VALUE assign_error(struct parser_params *p, const char *mesg, VALUE a);
static int id_is_var(struct parser_params *p, ID id);
#endif
@@ -1521,7 +1514,7 @@ RUBY_SYMBOL_EXPORT_END
static void error_duplicate_pattern_variable(struct parser_params *p, ID id, const YYLTYPE *loc);
static void error_duplicate_pattern_key(struct parser_params *p, ID id, const YYLTYPE *loc);
-static ID formal_argument(struct parser_params*, ID);
+static VALUE formal_argument_error(struct parser_params*, ID);
static ID shadowing_lvar(struct parser_params*,ID);
static void new_bv(struct parser_params*,ID);
@@ -1575,7 +1568,7 @@ static void numparam_pop(struct parser_params *p, NODE *prev_inner);
#define CASE_LABELS_ENABLED_P(case_labels) (case_labels && case_labels != CHECK_LITERAL_WHEN)
#define yytnamerr(yyres, yystr) (YYSIZE_T)rb_yytnamerr(p, yyres, yystr)
-size_t rb_yytnamerr(struct parser_params *p, char *yyres, const char *yystr);
+RUBY_FUNC_EXPORTED size_t rb_yytnamerr(struct parser_params *p, char *yyres, const char *yystr);
#define TOKEN2ID(tok) ( \
tTOKEN_LOCAL_BEGIN<(tok)&&(tok)<tTOKEN_LOCAL_END ? TOKEN2LOCALID(tok) : \
@@ -1604,34 +1597,19 @@ static VALUE ripper_dispatch5(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,V
static VALUE ripper_dispatch7(struct parser_params*,ID,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE,VALUE);
void ripper_error(struct parser_params *p);
-#define dispatch0(n) ripper_dispatch0(p, TOKEN_PASTE(ripper_id_, n))
-#define dispatch1(n,a) ripper_dispatch1(p, TOKEN_PASTE(ripper_id_, n), (a))
-#define dispatch2(n,a,b) ripper_dispatch2(p, TOKEN_PASTE(ripper_id_, n), (a), (b))
-#define dispatch3(n,a,b,c) ripper_dispatch3(p, TOKEN_PASTE(ripper_id_, n), (a), (b), (c))
-#define dispatch4(n,a,b,c,d) ripper_dispatch4(p, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d))
-#define dispatch5(n,a,b,c,d,e) ripper_dispatch5(p, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d), (e))
-#define dispatch7(n,a,b,c,d,e,f,g) ripper_dispatch7(p, TOKEN_PASTE(ripper_id_, n), (a), (b), (c), (d), (e), (f), (g))
+#define dispatch0(n) ripper_dispatch0(p, RIPPER_ID(n))
+#define dispatch1(n,a) ripper_dispatch1(p, RIPPER_ID(n), (a))
+#define dispatch2(n,a,b) ripper_dispatch2(p, RIPPER_ID(n), (a), (b))
+#define dispatch3(n,a,b,c) ripper_dispatch3(p, RIPPER_ID(n), (a), (b), (c))
+#define dispatch4(n,a,b,c,d) ripper_dispatch4(p, RIPPER_ID(n), (a), (b), (c), (d))
+#define dispatch5(n,a,b,c,d,e) ripper_dispatch5(p, RIPPER_ID(n), (a), (b), (c), (d), (e))
+#define dispatch7(n,a,b,c,d,e,f,g) ripper_dispatch7(p, RIPPER_ID(n), (a), (b), (c), (d), (e), (f), (g))
#define yyparse ripper_yyparse
-static void ripper_formal_argument(struct parser_params *p, ID id, VALUE lhs);
-
static VALUE
-ripper_new_args(struct parser_params *p, VALUE pre_args, VALUE opt_args, VALUE rest_arg, VALUE post_args, VALUE tail)
+aryptn_pre_args(struct parser_params *p, VALUE pre_arg, VALUE pre_args)
{
- VALUE kw_args = rb_ary_entry(tail, 0);
- VALUE kw_rest_arg = rb_ary_entry(tail, 1);
- VALUE block = rb_ary_entry(tail, 2);
- return dispatch7(params, pre_args, opt_args, rest_arg, post_args, kw_args, kw_rest_arg, block);
-}
-
-static VALUE
-ripper_new_array_pattern(struct parser_params *p, VALUE constant, VALUE pre_arg, VALUE aryptn)
-{
- VALUE pre_args = rb_ary_entry(aryptn, 0);
- VALUE rest_arg = rb_ary_entry(aryptn, 1);
- VALUE post_args = rb_ary_entry(aryptn, 2);
-
if (!NIL_P(pre_arg)) {
if (!NIL_P(pre_args)) {
rb_ary_unshift(pre_args, pre_arg);
@@ -1640,50 +1618,7 @@ ripper_new_array_pattern(struct parser_params *p, VALUE constant, VALUE pre_arg,
pre_args = rb_ary_new_from_args(1, pre_arg);
}
}
- return dispatch4(aryptn, constant, pre_args, rest_arg, post_args);
-}
-
-static VALUE
-ripper_new_array_pattern_tail(struct parser_params *p, VALUE pre_args, VALUE rest_arg, VALUE post_args)
-{
- return rb_ary_new_from_args(3, pre_args, rest_arg, post_args);
-}
-
-static VALUE
-ripper_new_hash_pattern(struct parser_params *p, VALUE constant, VALUE hshptn)
-{
- VALUE kw_args = rb_ary_entry(hshptn, 0);
- VALUE kw_rest_arg = rb_ary_entry(hshptn, 1);
-
- return dispatch3(hshptn, constant, kw_args, kw_rest_arg);
-}
-
-static VALUE
-ripper_new_hash_pattern_tail(struct parser_params *p, VALUE kw_args, VALUE kw_rest_arg)
-{
- if (kw_rest_arg) {
- kw_rest_arg = dispatch1(var_field, kw_rest_arg);
- }
- else {
- kw_rest_arg = Qnil;
- }
- return rb_ary_new_from_args(2, kw_args, kw_rest_arg);
-}
-
-static VALUE
-ripper_new_find_pattern(struct parser_params *p, VALUE constant, VALUE fndptn)
-{
- VALUE pre_rest_arg = rb_ary_entry(fndptn, 0);
- VALUE args = rb_ary_entry(fndptn, 1);
- VALUE post_rest_arg = rb_ary_entry(fndptn, 2);
-
- return dispatch4(fndptn, constant, pre_rest_arg, args, post_rest_arg);
-}
-
-static VALUE
-ripper_new_find_pattern_tail(struct parser_params *p, VALUE pre_rest_arg, VALUE args, VALUE post_rest_arg)
-{
- return rb_ary_new_from_args(3, pre_rest_arg, args, post_rest_arg);
+ return pre_args;
}
#define ID2VAL(id) STATIC_ID2SYM(id)
@@ -1730,7 +1665,6 @@ restore_defun(struct parser_params *p, rb_node_def_temp_t *temp)
{
/* See: def_name action */
struct lex_context ctxt = temp->save.ctxt;
- p->cur_arg = temp->save.cur_arg;
p->ctxt.in_def = ctxt.in_def;
p->ctxt.shareable_constant_value = ctxt.shareable_constant_value;
p->ctxt.in_rescue = ctxt.in_rescue;
@@ -1772,8 +1706,10 @@ endless_method_name(struct parser_params *p, ID mid, const YYLTYPE *loc)
#ifndef RIPPER
# define ifndef_ripper(x) (x)
+# define ifdef_ripper(r,x) (x)
#else
# define ifndef_ripper(x)
+# define ifdef_ripper(r,x) (r)
#endif
# define rb_warn0(fmt) WARN_CALL(WARN_ARGS(fmt, 1))
@@ -1856,7 +1792,7 @@ add_block_exit(struct parser_params *p, NODE *node)
switch (nd_type(node)) {
case NODE_BREAK: case NODE_NEXT: case NODE_REDO: break;
default:
- compile_error(p, "unexpected node: %s", parser_node_name(nd_type(node)));
+ compile_error(p, "add_block_exit: unexpected node: %s", parser_node_name(nd_type(node)));
return node;
}
if (!p->ctxt.in_defined) {
@@ -1947,7 +1883,7 @@ get_nd_value(struct parser_params *p, NODE *node)
case NODE_CDECL:
return RNODE_CDECL(node)->nd_value;
default:
- compile_error(p, "unexpected node: %s", parser_node_name(nd_type(node)));
+ compile_error(p, "get_nd_value: unexpected node: %s", parser_node_name(nd_type(node)));
return 0;
}
}
@@ -1978,7 +1914,7 @@ set_nd_value(struct parser_params *p, NODE *node, NODE *rhs)
RNODE_CVASGN(node)->nd_value = rhs;
break;
default:
- compile_error(p, "unexpected node: %s", parser_node_name(nd_type(node)));
+ compile_error(p, "set_nd_value: unexpected node: %s", parser_node_name(nd_type(node)));
break;
}
}
@@ -2000,7 +1936,7 @@ get_nd_vid(struct parser_params *p, NODE *node)
case NODE_CVASGN:
return RNODE_CVASGN(node)->nd_vid;
default:
- compile_error(p, "unexpected node: %s", parser_node_name(nd_type(node)));
+ compile_error(p, "get_nd_vid: unexpected node: %s", parser_node_name(nd_type(node)));
return 0;
}
}
@@ -2027,7 +1963,7 @@ get_nd_args(struct parser_params *p, NODE *node)
case NODE_NEXT:
return 0;
default:
- compile_error(p, "unexpected node: %s", parser_node_name(nd_type(node)));
+ compile_error(p, "get_nd_args: unexpected node: %s", parser_node_name(nd_type(node)));
return 0;
}
}
@@ -2107,7 +2043,9 @@ rb_parser_string_t *
rb_str_to_parser_string(rb_parser_t *p, VALUE str)
{
/* Type check */
- return rb_parser_encoding_string_new(p, RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
+ rb_parser_string_t *ret = rb_parser_encoding_string_new(p, RSTRING_PTR(str), RSTRING_LEN(str), rb_enc_get(str));
+ RB_GC_GUARD(str);
+ return ret;
}
#endif
@@ -2643,21 +2581,21 @@ rb_parser_ast_token_free(rb_parser_t *p, rb_parser_ast_token_t *token)
static void
rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
{
- void (*free_func)(rb_parser_t *, rb_parser_ary_data) = NULL;
+# define foreach_ary(ptr) \
+ for (rb_parser_ary_data *ptr = ary->data, *const end_ary_data = ptr + ary->len; \
+ ptr < end_ary_data; ptr++)
switch (ary->data_type) {
case PARSER_ARY_DATA_AST_TOKEN:
- free_func = (void (*)(rb_parser_t *, rb_parser_ary_data))rb_parser_ast_token_free;
+ foreach_ary(data) {rb_parser_ast_token_free(p, *data);}
break;
case PARSER_ARY_DATA_SCRIPT_LINE:
- free_func = (void (*)(rb_parser_t *, rb_parser_ary_data))rb_parser_string_free;
+ foreach_ary(data) {rb_parser_string_free(p, *data);}
break;
default:
rb_bug("unexpected rb_parser_ary_data_type: %d", ary->data_type);
break;
}
- for (long i = 0; i < ary->len; i++) {
- free_func(p, ary->data[i]);
- }
+# undef foreach_ary
xfree(ary);
}
@@ -2738,6 +2676,7 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
const struct vtable *vars;
struct rb_strterm_struct *strterm;
struct lex_context ctxt;
+ enum lex_state_e state;
}
%token <id>
@@ -2822,22 +2761,19 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
%type <node> if_tail opt_else case_body case_args cases opt_rescue exc_list exc_var opt_ensure
%type <node> args arg_splat call_args opt_call_args
%type <node> paren_args opt_paren_args
-%type <node_args> args_tail opt_args_tail block_args_tail opt_block_args_tail
+%type <node_args> args_tail block_args_tail
%type <node> command_args aref_args
%type <node_block_pass> opt_block_arg block_arg
%type <node> var_ref var_lhs
%type <node> command_rhs arg_rhs
%type <node> command_asgn mrhs mrhs_arg superclass block_call block_command
-%type <node_opt_arg> f_block_optarg f_block_opt
%type <node_args> f_arglist f_opt_paren_args f_paren_args f_args
%type <node_args_aux> f_arg f_arg_item
-%type <node_opt_arg> f_optarg
%type <node> f_marg f_marg_list f_rest_marg
%type <node_masgn> f_margs
%type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
%type <node_args> block_param opt_block_param block_param_def
-%type <node_opt_arg> f_opt
-%type <node_kw_arg> f_kwarg f_kw f_block_kwarg f_block_kw
+%type <node_kw_arg> f_kw f_block_kw
%type <id> bv_decls opt_bv_decl bvar
%type <node> lambda lambda_body brace_body do_body
%type <node_args> f_larglist
@@ -2905,7 +2841,7 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
%token tSTAR "*"
%token tDSTAR "**arg"
%token tAMPER "&"
-%token tLAMBDA "->"
+%token <num> tLAMBDA "->"
%token tSYMBEG "symbol literal"
%token tSTRING_BEG "string literal"
%token tXSTRING_BEG "backtick literal"
@@ -2916,7 +2852,8 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
%token tQSYMBOLS_BEG "verbatim symbol list"
%token tSTRING_END "terminator"
%token tSTRING_DEND "'}'"
-%token tSTRING_DBEG tSTRING_DVAR tLAMBEG tLABEL_END
+%token <state> tSTRING_DBEG "'#{'"
+%token tSTRING_DVAR tLAMBEG tLABEL_END
%token tIGNORED_NL tCOMMENT tEMBDOC_BEG tEMBDOC tEMBDOC_END
%token tHEREDOC_BEG tHEREDOC_END k__END__
@@ -2951,6 +2888,60 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
%token tLAST_TOKEN
+/*
+ * parameterizing rules
+ */
+%rule f_opt(value) <node_opt_arg>: f_arg_asgn f_eq value
+ {
+ p->ctxt.in_argdef = 1;
+ $$ = NEW_OPT_ARG(assignable(p, $1, $3, &@$), &@$);
+ /*% ripper: [$:$, $:3] %*/
+ }
+ ;
+
+%rule f_optarg(value) <node_opt_arg>: f_opt(value)
+ {
+ $$ = $1;
+ /*% ripper: rb_ary_new3(1, $:1) %*/
+ }
+ | f_optarg(value) ',' f_opt(value)
+ {
+ $$ = opt_arg_append($1, $3);
+ /*% ripper: rb_ary_push($:1, $:3) %*/
+ }
+ ;
+
+%rule f_kwarg(kw) <node_kw_arg>: kw
+ {
+ $$ = $1;
+ /*% ripper: rb_ary_new3(1, $:1) %*/
+ }
+ | f_kwarg(kw) ',' kw
+ {
+ $$ = kwd_append($1, $3);
+ /*% ripper: rb_ary_push($:1, $:3) %*/
+ }
+ ;
+
+%rule opt_args_tail(tail) <node_args>: ',' tail
+ {
+ $$ = $2;
+ /*% ripper: $:2 %*/
+ }
+ | /* none */
+ {
+ $$ = new_args_tail(p, 0, 0, 0, &@0);
+ /*% ripper: [Qnil, Qnil, Qnil] %*/
+ }
+ ;
+
+%rule words(begin, word_list): begin ' '+ word_list tSTRING_END
+ {
+ $$ = make_list($3, &@$);
+ /*% ripper: array!($:3) %*/
+ }
+ ;
+
%%
program : {
SET_LEX_STATE(EXPR_BEG);
@@ -3009,7 +3000,7 @@ top_stmt : stmt
| keyword_BEGIN begin_block
{
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
;
@@ -3098,7 +3089,7 @@ k_END : keyword_END lex_ctxt
{
$$ = $2;
p->ctxt.in_rescue = before_rescue;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
};
stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
@@ -3269,12 +3260,8 @@ command_asgn : lhs '=' lex_ctxt command_rhs
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFN($$)->nd_defn = $bodystmt;
- /*%%%*/
- /*%
- VALUE val = dispatch4(bodystmt, get_value($:bodystmt), Qnil, Qnil, Qnil);
- val = dispatch3(def, get_value($:head), get_value($:args), val);
- set_value(val);
- %*/
+ /*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
+ /*% ripper: def!($:head, $:args, $:$) %*/
local_pop(p);
}
| defs_head[head] f_opt_paren_args[args] '=' endless_command[bodystmt]
@@ -3284,21 +3271,15 @@ command_asgn : lhs '=' lex_ctxt command_rhs
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFS($$)->nd_defn = $bodystmt;
- /*%%%*/
- /*%
- VALUE val = dispatch4(bodystmt, get_value($:bodystmt), Qnil, Qnil, Qnil);
- val = defs(p, get_value($:head), get_value($:args), val);
- set_value(val);
- %*/
+ /*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
+ /*% ripper: defs!(*$:head[0..2], $:args, $:$) %*/
local_pop(p);
}
| backref tOP_ASGN lex_ctxt command_rhs
{
- /*%%%*/
- rb_backref_error(p, $1);
- /*% %*/
+ VALUE MAYBE_UNUSED(e) = rb_backref_error(p, $1);
$$ = NEW_ERROR(&@$);
- /*% ripper[error]: backref_error(p, RNODE($:1), assign!(var_field(p, get_value($:1)), $:4)) %*/
+ /*% ripper[error]: assign_error!(?e, opassign!(var_field!($:1), $:2, $:4)) %*/
}
;
@@ -3387,7 +3368,6 @@ def_name : fname
ID fname = $1;
numparam_name(p, fname);
local_push(p, 0);
- p->cur_arg = 0;
p->ctxt.in_def = 1;
p->ctxt.in_rescue = before_rescue;
$$ = $1;
@@ -3399,7 +3379,7 @@ defn_head : k_def def_name
$$ = def_head_save(p, $k_def);
$$->nd_mid = $def_name;
$$->nd_def = NEW_DEFN($def_name, 0, &@$);
- /*% ripper: get_value($:def_name); %*/
+ /*% ripper: $:def_name %*/
}
;
@@ -3414,10 +3394,7 @@ defs_head : k_def singleton dot_or_colon
$$ = def_head_save(p, $k_def);
$$->nd_mid = $def_name;
$$->nd_def = NEW_DEFS($singleton, $def_name, 0, &@$);
- /*%%%*/
- /*%
- set_value(rb_ary_new_from_args(3, get_value($:singleton), get_value($:dot_or_colon), get_value($:def_name)));
- %*/
+ /*% ripper: [$:singleton, $:dot_or_colon, $:def_name] %*/
}
;
@@ -3435,7 +3412,7 @@ expr_value : expr
expr_value_do : {COND_PUSH(1);} expr_value do {COND_POP();}
{
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
;
@@ -3455,14 +3432,14 @@ cmd_brace_block : tLBRACE_ARG brace_body '}'
{
$$ = $2;
set_embraced_location($$, &@1, &@3);
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
;
fcall : operation
{
$$ = NEW_FCALL($1, 0, &@$);
- /*% ripper: get_value($:1); %*/
+ /*% ripper: $:1 %*/
}
;
@@ -3529,14 +3506,14 @@ command : fcall command_args %prec tLOWEST
{
NODE *args = 0;
args = ret_args(p, $2);
- $<node>$ = add_block_exit(p, NEW_BREAK(args, &@$));
+ $$ = add_block_exit(p, NEW_BREAK(args, &@$));
/*% ripper: break!($:2) %*/
}
| keyword_next call_args
{
NODE *args = 0;
args = ret_args(p, $2);
- $<node>$ = add_block_exit(p, NEW_NEXT(args, &@$));
+ $$ = add_block_exit(p, NEW_NEXT(args, &@$));
/*% ripper: next!($:2) %*/
}
;
@@ -3560,7 +3537,7 @@ mlhs_inner : mlhs_basic
mlhs_basic : mlhs_head
{
$$ = NEW_MASGN($1, 0, &@$);
- /*% ripper: get_value($:1) %*/
+ /*% ripper: $:1 %*/
}
| mlhs_head mlhs_item
{
@@ -3643,13 +3620,13 @@ mlhs_post : mlhs_item
mlhs_node : user_variable
{
+ /*% ripper: var_field!($:1) %*/
$$ = assignable(p, $1, 0, &@$);
- /*% ripper: ripper_assignable(p, $1, var_field(p, get_value($:1))) %*/
}
| keyword_variable
{
+ /*% ripper: var_field!($:1) %*/
$$ = assignable(p, $1, 0, &@$);
- /*% ripper: ripper_assignable(p, $1, var_field(p, get_value($:1))) %*/
}
| primary_value '[' opt_call_args rbracket
{
@@ -3675,33 +3652,31 @@ mlhs_node : user_variable
}
| primary_value tCOLON2 tCONSTANT
{
+ /*% ripper: const_path_field!($:1, $:3) %*/
$$ = const_decl(p, NEW_COLON2($1, $3, &@$), &@$);
- /*% ripper: ripper_const_decl(p, const_path_field!($:1, $:3)) %*/
}
| tCOLON3 tCONSTANT
{
+ /*% ripper: top_const_field!($:2) %*/
$$ = const_decl(p, NEW_COLON3($2, &@$), &@$);
- /*% ripper: ripper_const_decl(p, top_const_field!($:2)) %*/
}
| backref
{
- /*%%%*/
- rb_backref_error(p, $1);
- /*% %*/
+ VALUE MAYBE_UNUSED(e) = rb_backref_error(p, $1);
$$ = NEW_ERROR(&@$);
- /*% ripper[error]: backref_error(p, $1, var_field(p, get_value($:1))) %*/
+ /*% ripper[error]: assign_error!(?e, var_field!($:1)) %*/
}
;
lhs : user_variable
{
+ /*% ripper: var_field!($:1) %*/
$$ = assignable(p, $1, 0, &@$);
- /*% ripper: ripper_assignable(p, $1, var_field(p, get_value($:1))) %*/
}
| keyword_variable
{
+ /*% ripper: var_field!($:1) %*/
$$ = assignable(p, $1, 0, &@$);
- /*% ripper: ripper_assignable(p, $1, var_field(p, get_value($:1))) %*/
}
| primary_value '[' opt_call_args rbracket
{
@@ -3725,21 +3700,19 @@ lhs : user_variable
}
| primary_value tCOLON2 tCONSTANT
{
+ /*% ripper: const_path_field!($:1, $:3) %*/
$$ = const_decl(p, NEW_COLON2($1, $3, &@$), &@$);
- /*% ripper: ripper_const_decl(p, const_path_field!($:1, $:3)) %*/
}
| tCOLON3 tCONSTANT
{
+ /*% ripper: top_const_field!($:2) %*/
$$ = const_decl(p, NEW_COLON3($2, &@$), &@$);
- /*% ripper: ripper_const_decl(p, top_const_field!($:2)) %*/
}
| backref
{
- /*%%%*/
- rb_backref_error(p, $1);
- /*% %*/
+ VALUE MAYBE_UNUSED(e) = rb_backref_error(p, $1);
$$ = NEW_ERROR(&@$);
- /*% ripper[error]: backref_error(p, $1, var_field(p, get_value($:1))) %*/
+ /*% ripper[error]: assign_error!(?e, var_field!($:1)) %*/
}
;
@@ -3793,13 +3766,13 @@ fitem : fname
undef_list : fitem
{
$$ = NEW_UNDEF($1, &@$);
- /*% ripper: rb_ary_new3(1, get_value($:1)) %*/
+ /*% ripper: rb_ary_new3(1, $:1) %*/
}
| undef_list ',' {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
{
NODE *undef = NEW_UNDEF($4, &@4);
$$ = block_append(p, $1, undef);
- /*% ripper: rb_ary_push(get_value($:1), get_value($:4)) %*/
+ /*% ripper: rb_ary_push($:1, $:4) %*/
}
;
@@ -3893,11 +3866,9 @@ arg : lhs '=' lex_ctxt arg_rhs
}
| backref tOP_ASGN lex_ctxt arg_rhs
{
- rb_backref_error(p, $1);
- /*%%%*/
+ VALUE MAYBE_UNUSED(e) = rb_backref_error(p, $1);
$$ = NEW_ERROR(&@$);
- /*% %*/
- /*% ripper[error]: backref_error(p, RNODE($:1), opassign!(var_field(p, get_value($:1)), $:2, $:4)) %*/
+ /*% ripper[error]: assign_error!(?e, opassign!(var_field!($:1), $:2, $:4)) %*/
}
| arg tDOT2 arg
{
@@ -3970,12 +3941,7 @@ arg : lhs '=' lex_ctxt arg_rhs
| tUMINUS_NUM simple_numeric tPOW arg
{
$$ = call_uni_op(p, call_bin_op(p, $2, idPow, $4, &@2, &@$), idUMinus, &@1, &@$);
- /*%%%*/
- /*%
- VALUE val = dispatch3(binary, get_value($:2), ID2VAL(idPow), get_value($:4));
- val = dispatch2(unary, ID2VAL(idUMinus), val);
- set_value(val);
- %*/
+ /*% ripper: unary!(ID2VAL(idUMinus), binary!($:2, ID2VAL(idPow), $:4)) %*/
}
| tUPLUS arg
{
@@ -4083,12 +4049,8 @@ arg : lhs '=' lex_ctxt arg_rhs
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFN($$)->nd_defn = $bodystmt;
- /*%%%*/
- /*%
- VALUE val = dispatch4(bodystmt, get_value($:bodystmt), Qnil, Qnil, Qnil);
- val = dispatch3(def, get_value($:head), get_value($:args), val);
- set_value(val);
- %*/
+ /*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
+ /*% ripper: def!($:head, $:args, $:$) %*/
local_pop(p);
}
| defs_head[head] f_opt_paren_args[args] '=' endless_arg[bodystmt]
@@ -4098,12 +4060,8 @@ arg : lhs '=' lex_ctxt arg_rhs
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFS($$)->nd_defn = $bodystmt;
- /*%%%*/
- /*%
- VALUE val = dispatch4(bodystmt, get_value($:bodystmt), Qnil, Qnil, Qnil);
- val = defs(p, get_value($:head), get_value($:args), val);
- set_value(val);
- %*/
+ /*% ripper: bodystmt!($:bodystmt, Qnil, Qnil, Qnil) %*/
+ /*% ripper: defs!(*$:head[0..2], $:args, $:$) %*/
local_pop(p);
}
| primary
@@ -4232,13 +4190,16 @@ paren_args : '(' opt_call_args rparen
opt_paren_args : none
| paren_args
+ {
+ $$ = $1 ? $1 : NODE_SPECIAL_EMPTY_ARGS;
+ }
;
opt_call_args : none
| call_args
| args ','
{
- $$ = $1;
+ $$ = $1;
}
| args ',' assocs ','
{
@@ -4313,14 +4274,14 @@ command_args : {
CMDARG_POP();
if (lookahead) CMDARG_PUSH(0);
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
;
block_arg : tAMPER arg_value
{
$$ = NEW_BLOCK_PASS($2, &@$);
- /*% ripper: get_value($:2) %*/
+ /*% ripper: $:2 %*/
}
| tAMPER
{
@@ -4333,7 +4294,7 @@ block_arg : tAMPER arg_value
opt_block_arg : ',' block_arg
{
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
| none
{
@@ -4369,7 +4330,7 @@ args : arg_value
arg_splat : tSTAR arg_value
{
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
| tSTAR /* none */
{
@@ -4557,7 +4518,7 @@ primary : literal
k_end
{
if (CASE_LABELS_ENABLED_P(p->case_labels)) st_free_table(p->case_labels);
- p->case_labels = $<labels>4;
+ p->case_labels = $4;
$$ = NEW_CASE($2, $5, &@$);
fixpos($$, $2);
/*% ripper: case!($:2, $:5) %*/
@@ -4571,7 +4532,7 @@ primary : literal
k_end
{
if (p->case_labels) st_free_table(p->case_labels);
- p->case_labels = $<labels>3;
+ p->case_labels = $3;
$$ = NEW_CASE2($4, &@$);
/*% ripper: case!(Qnil, $:4) %*/
}
@@ -4701,22 +4662,22 @@ primary : literal
$bodystmt = new_scope_body(p, $args, $bodystmt, &@$);
($$ = $head->nd_def)->nd_loc = @$;
RNODE_DEFS($$)->nd_defn = $bodystmt;
- /*% ripper: defs(p, get_value($:head), get_value($:args), get_value($:bodystmt)) %*/
+ /*% ripper: defs!(*$:head[0..2], $:args, $:bodystmt) %*/
local_pop(p);
}
| keyword_break
{
- $<node>$ = add_block_exit(p, NEW_BREAK(0, &@$));
+ $$ = add_block_exit(p, NEW_BREAK(0, &@$));
/*% ripper: break!(args_new!) %*/
}
| keyword_next
{
- $<node>$ = add_block_exit(p, NEW_NEXT(0, &@$));
+ $$ = add_block_exit(p, NEW_NEXT(0, &@$));
/*% ripper: next!(args_new!) %*/
}
| keyword_redo
{
- $<node>$ = add_block_exit(p, NEW_REDO(&@$));
+ $$ = add_block_exit(p, NEW_REDO(&@$));
/*% ripper: redo! %*/
}
| keyword_retry
@@ -4948,7 +4909,6 @@ f_marg : f_norm_arg
{
$$ = assignable(p, $1, 0, &@$);
mark_lvar_used(p, $$);
- /*% ripper: ripper_assignable(p, $1, get_value($:1)) %*/
}
| tLPAREN f_margs rparen
{
@@ -4972,7 +4932,7 @@ f_marg_list : f_marg
f_margs : f_marg_list
{
$$ = NEW_MASGN($1, 0, &@$);
- /*% ripper: get_value($:1) %*/
+ /*% ripper: $:1 %*/
}
| f_marg_list ',' f_rest_marg
{
@@ -4998,9 +4958,9 @@ f_margs : f_marg_list
f_rest_marg : tSTAR f_norm_arg
{
+ /*% ripper: $:2 %*/
$$ = assignable(p, $2, 0, &@$);
mark_lvar_used(p, $$);
- /*% ripper: ripper_assignable(p, $2, get_value($:2)) %*/
}
| tSTAR
{
@@ -5019,37 +4979,25 @@ f_any_kwrest : f_kwrest
f_eq : {p->ctxt.in_argdef = 0;} '=';
-block_args_tail : f_block_kwarg ',' f_kwrest opt_f_block_arg
+block_args_tail : f_kwarg(f_block_kw) ',' f_kwrest opt_f_block_arg
{
$$ = new_args_tail(p, $1, $3, $4, &@3);
- /*% ripper: rb_ary_new_from_args(3, get_value($:1), get_value($:3), get_value($:4)); %*/
+ /*% ripper: [$:1, $:3, $:4] %*/
}
- | f_block_kwarg opt_f_block_arg
+ | f_kwarg(f_block_kw) opt_f_block_arg
{
$$ = new_args_tail(p, $1, 0, $2, &@1);
- /*% ripper: rb_ary_new_from_args(3, get_value($:1), Qnil, get_value($:2)); %*/
+ /*% ripper: [$:1, Qnil, $:2] %*/
}
| f_any_kwrest opt_f_block_arg
{
$$ = new_args_tail(p, 0, $1, $2, &@1);
- /*% ripper: rb_ary_new_from_args(3, Qnil, get_value($:1), get_value($:2)); %*/
+ /*% ripper: [Qnil, $:1, $:2] %*/
}
| f_block_arg
{
$$ = new_args_tail(p, 0, 0, $1, &@1);
- /*% ripper: rb_ary_new_from_args(3, Qnil, Qnil, get_value($:1)); %*/
- }
- ;
-
-opt_block_args_tail : ',' block_args_tail
- {
- $$ = $2;
- /*% ripper: get_value($:2); %*/
- }
- | /* none */
- {
- $$ = new_args_tail(p, 0, 0, 0, &@0);
- /*% ripper: rb_ary_new_from_args(3, Qnil, Qnil, Qnil); %*/
+ /*% ripper: [Qnil, Qnil, $:1] %*/
}
;
@@ -5061,81 +5009,81 @@ excessed_comma : ','
}
;
-block_param : f_arg ',' f_block_optarg ',' f_rest_arg opt_block_args_tail
+block_param : f_arg ',' f_optarg(primary_value) ',' f_rest_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, $1, $3, $5, 0, $6, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), get_value($:3), get_value($:5), Qnil, get_value($:6)) %*/
+ /*% ripper: params!($:1, $:3, $:5, Qnil, *$:6[0..2]) %*/
}
- | f_arg ',' f_block_optarg ',' f_rest_arg ',' f_arg opt_block_args_tail
+ | f_arg ',' f_optarg(primary_value) ',' f_rest_arg ',' f_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, $1, $3, $5, $7, $8, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), get_value($:3), get_value($:5), get_value($:7), get_value($:8)) %*/
+ /*% ripper: params!($:1, $:3, $:5, $:7, *$:8[0..2]) %*/
}
- | f_arg ',' f_block_optarg opt_block_args_tail
+ | f_arg ',' f_optarg(primary_value) opt_args_tail(block_args_tail)
{
$$ = new_args(p, $1, $3, 0, 0, $4, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), get_value($:3), Qnil, Qnil, get_value($:4)) %*/
+ /*% ripper: params!($:1, $:3, Qnil, Qnil, *$:4[0..2]) %*/
}
- | f_arg ',' f_block_optarg ',' f_arg opt_block_args_tail
+ | f_arg ',' f_optarg(primary_value) ',' f_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, $1, $3, 0, $5, $6, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), get_value($:3), Qnil, get_value($:5), get_value($:6)) %*/
+ /*% ripper: params!($:1, $:3, Qnil, $:5, *$:6[0..2]) %*/
}
- | f_arg ',' f_rest_arg opt_block_args_tail
+ | f_arg ',' f_rest_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, $1, 0, $3, 0, $4, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), Qnil, get_value($:3), Qnil, get_value($:4)) %*/
+ /*% ripper: params!($:1, Qnil, $:3, Qnil, *$:4[0..2]) %*/
}
| f_arg excessed_comma
{
$$ = new_args_tail(p, 0, 0, 0, &@2);
$$ = new_args(p, $1, 0, $2, 0, $$, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), Qnil, get_value($:2), Qnil, rb_ary_new_from_args(3, Qnil, Qnil, Qnil)) %*/
+ /*% ripper: params!($:1, Qnil, $:2, Qnil, Qnil, Qnil, Qnil) %*/
}
- | f_arg ',' f_rest_arg ',' f_arg opt_block_args_tail
+ | f_arg ',' f_rest_arg ',' f_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, $1, 0, $3, $5, $6, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), Qnil, get_value($:3), get_value($:5), get_value($:6)) %*/
+ /*% ripper: params!($:1, Qnil, $:3, $:5, *$:6[0..2]) %*/
}
- | f_arg opt_block_args_tail
+ | f_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, $1, 0, 0, 0, $2, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), Qnil, Qnil, Qnil, get_value($:2)) %*/
+ /*% ripper: params!($:1, Qnil, Qnil, Qnil, *$:2[0..2]) %*/
}
- | f_block_optarg ',' f_rest_arg opt_block_args_tail
+ | f_optarg(primary_value) ',' f_rest_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, 0, $1, $3, 0, $4, &@$);
- /*% ripper: ripper_new_args(p, Qnil, get_value($:1), get_value($:3), Qnil, get_value($:4)) %*/
+ /*% ripper: params!(Qnil, $:1, $:3, Qnil, *$:4[0..2]) %*/
}
- | f_block_optarg ',' f_rest_arg ',' f_arg opt_block_args_tail
+ | f_optarg(primary_value) ',' f_rest_arg ',' f_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, 0, $1, $3, $5, $6, &@$);
- /*% ripper: ripper_new_args(p, Qnil, get_value($:1), get_value($:3), get_value($:5), get_value($:6)) %*/
+ /*% ripper: params!(Qnil, $:1, $:3, $:5, *$:6[0..2]) %*/
}
- | f_block_optarg opt_block_args_tail
+ | f_optarg(primary_value) opt_args_tail(block_args_tail)
{
$$ = new_args(p, 0, $1, 0, 0, $2, &@$);
- /*% ripper: ripper_new_args(p, Qnil, get_value($:1), Qnil, Qnil, get_value($:2)) %*/
+ /*% ripper: params!(Qnil, $:1, Qnil, Qnil, *$:2[0..2]) %*/
}
- | f_block_optarg ',' f_arg opt_block_args_tail
+ | f_optarg(primary_value) ',' f_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, 0, $1, 0, $3, $4, &@$);
- /*% ripper: ripper_new_args(p, Qnil, get_value($:1), Qnil, get_value($:3), get_value($:4)) %*/
+ /*% ripper: params!(Qnil, $:1, Qnil, $:3, *$:4[0..2]) %*/
}
- | f_rest_arg opt_block_args_tail
+ | f_rest_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, 0, 0, $1, 0, $2, &@$);
- /*% ripper: ripper_new_args(p, Qnil, Qnil, get_value($:1), Qnil, get_value($:2)) %*/
+ /*% ripper: params!(Qnil, Qnil, $:1, Qnil, *$:2[0..2]) %*/
}
- | f_rest_arg ',' f_arg opt_block_args_tail
+ | f_rest_arg ',' f_arg opt_args_tail(block_args_tail)
{
$$ = new_args(p, 0, 0, $1, $3, $4, &@$);
- /*% ripper: ripper_new_args(p, Qnil, Qnil, get_value($:1), get_value($:3), get_value($:4)) %*/
+ /*% ripper: params!(Qnil, Qnil, $:1, $:3, *$:4[0..2]) %*/
}
| block_args_tail
{
$$ = new_args(p, 0, 0, 0, 0, $1, &@$);
- /*% ripper: ripper_new_args(p, Qnil, Qnil, Qnil, Qnil, get_value($:1)) %*/
+ /*% ripper: params!(Qnil, Qnil, Qnil, Qnil, *$:1[0..2]) %*/
}
;
@@ -5148,20 +5096,13 @@ opt_block_param : none
block_param_def : '|' opt_bv_decl '|'
{
- p->cur_arg = 0;
p->max_numparam = ORDINAL_PARAM;
p->ctxt.in_argdef = 0;
$$ = 0;
- /*%%%*/
- /*%
- VALUE val = dispatch7(params, Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,Qnil);
- val = dispatch2(block_var, val, get_value($:2));
- set_value(val);
- %*/
+ /*% ripper: block_var!(params!(Qnil,Qnil,Qnil,Qnil,Qnil,Qnil,Qnil), $:2) %*/
}
| '|' block_param opt_bv_decl '|'
{
- p->cur_arg = 0;
p->max_numparam = ORDINAL_PARAM;
p->ctxt.in_argdef = 0;
$$ = $2;
@@ -5178,20 +5119,20 @@ opt_bv_decl : '\n'?
| '\n'? ';' bv_decls '\n'?
{
$$ = 0;
- /*% ripper: get_value($:3) %*/
+ /*% ripper: $:3 %*/
}
;
bv_decls : bvar
- /*% ripper[brace]: rb_ary_new3(1, get_value($:1)) %*/
+ /*% ripper[brace]: rb_ary_new3(1, $:1) %*/
| bv_decls ',' bvar
- /*% ripper[brace]: rb_ary_push(get_value($:1), get_value($:3)) %*/
+ /*% ripper[brace]: rb_ary_push($:1, $:3) %*/
;
bvar : tIDENTIFIER
{
new_bv(p, $1);
- /*% ripper: get_value($:1) %*/
+ /*% ripper: $:1 %*/
}
| f_bad_arg
{
@@ -5216,13 +5157,12 @@ it_id : {
}
;
-lambda : tLAMBDA[dyna]
+lambda : tLAMBDA[lpar]
{
token_info_push(p, "->", &@1);
- $<vars>dyna = dyna_push(p);
- $<num>$ = p->lex.lpar_beg;
+ $$ = dyna_push(p);
p->lex.lpar_beg = p->lex.paren_nest;
- }[lpar]
+ }[dyna]<vars>
max_numparam numparam it_id allow_exits
f_larglist[args]
{
@@ -5232,7 +5172,7 @@ lambda : tLAMBDA[dyna]
{
int max_numparam = p->max_numparam;
ID it_id = p->it_id;
- p->lex.lpar_beg = $<num>lpar;
+ p->lex.lpar_beg = $lpar;
p->max_numparam = $max_numparam;
p->it_id = $it_id;
restore_block_exit(p, $allow_exits);
@@ -5247,7 +5187,7 @@ lambda : tLAMBDA[dyna]
}
/*% ripper: lambda!($:args, $:body) %*/
numparam_pop(p, $numparam);
- dyna_pop(p, $<vars>dyna);
+ dyna_pop(p, $dyna);
}
;
@@ -5271,7 +5211,7 @@ lambda_body : tLAMBEG compstmt '}'
{
token_info_pop(p, "}", &@3);
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
| keyword_do_LAMBDA
{
@@ -5280,7 +5220,7 @@ lambda_body : tLAMBEG compstmt '}'
bodystmt k_end
{
$$ = $3;
- /*% ripper: get_value($:3); %*/
+ /*% ripper: $:3 %*/
}
;
@@ -5288,7 +5228,7 @@ do_block : k_do_block do_body k_end
{
$$ = $2;
set_embraced_location($$, &@1, &@3);
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
;
@@ -5306,13 +5246,23 @@ block_call : command do_block
}
| block_call call_op2 operation2 opt_paren_args
{
+ bool has_args = $4 != 0;
+ if (NODE_EMPTY_ARGS_P($4)) $4 = 0;
$$ = new_qcall(p, $2, $1, $3, $4, &@3, &@$);
- /*% ripper: opt_event(:method_add_arg!, call!($:1, $:2, $:3), $:4) %*/
+ /*% ripper: call!($:1, $:2, $:3) %*/
+ if (has_args) {
+ /*% ripper: method_add_arg!($:$, $:4) %*/
+ }
}
| block_call call_op2 operation2 opt_paren_args brace_block
{
+ bool has_args = $5 != 0;
+ if (NODE_EMPTY_ARGS_P($5)) $5 = 0;
$$ = new_command_qcall(p, $2, $1, $3, $4, $5, &@3, &@$);
- /*% ripper: opt_event(:method_add_block!, command_call!($:1, $:2, $:3, $:4), $:5) %*/
+ /*% ripper: command_call!($:1, $:2, $:3, $:4) %*/
+ if (has_args) {
+ /*% ripper: method_add_block!($:$, $:5) %*/
+ }
}
| block_call call_op2 operation2 command_args do_block
{
@@ -5330,9 +5280,14 @@ method_call : fcall paren_args
}
| primary_value call_op operation2 opt_paren_args
{
+ bool has_args = $4 != 0;
+ if (NODE_EMPTY_ARGS_P($4)) $4 = 0;
$$ = new_qcall(p, $2, $1, $3, $4, &@3, &@$);
nd_set_line($$, @3.end_pos.lineno);
- /*% ripper: opt_event(:method_add_arg!, call!($:1, $:2, $:3), $:4) %*/
+ /*% ripper: call!($:1, $:2, $:3) %*/
+ if (has_args) {
+ /*% ripper: method_add_arg!($:$, $:4) %*/
+ }
}
| primary_value tCOLON2 operation2 paren_args
{
@@ -5379,17 +5334,17 @@ brace_block : '{' brace_body '}'
{
$$ = $2;
set_embraced_location($$, &@1, &@3);
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
| k_do do_body k_end
{
$$ = $2;
set_embraced_location($$, &@1, &@3);
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
;
-brace_body : {$<vars>$ = dyna_push(p);}[dyna]
+brace_body : {$$ = dyna_push(p);}[dyna]<vars>
max_numparam numparam it_id allow_exits
opt_block_param[args] compstmt
{
@@ -5402,28 +5357,28 @@ brace_body : {$<vars>$ = dyna_push(p);}[dyna]
/*% ripper: brace_block!($:args, $:compstmt) %*/
restore_block_exit(p, $allow_exits);
numparam_pop(p, $numparam);
- dyna_pop(p, $<vars>dyna);
+ dyna_pop(p, $dyna);
}
;
do_body : {
- $<vars>$ = dyna_push(p);
+ $$ = dyna_push(p);
CMDARG_PUSH(0);
- }[dyna]
+ }[dyna]<vars>
max_numparam numparam it_id allow_exits
opt_block_param[args] bodystmt
{
int max_numparam = p->max_numparam;
ID it_id = p->it_id;
p->max_numparam = $max_numparam;
- p->it_id = $<id>it_id;
+ p->it_id = $it_id;
$args = args_with_numbered(p, $args, max_numparam, it_id);
$$ = NEW_ITER($args, $bodystmt, &@$);
/*% ripper: do_block!($:args, $:bodystmt) %*/
CMDARG_POP();
restore_block_exit(p, $allow_exits);
numparam_pop(p, $numparam);
- dyna_pop(p, $<vars>dyna);
+ dyna_pop(p, $dyna);
}
;
@@ -5516,28 +5471,28 @@ p_top_expr_body : p_expr
{
$$ = new_array_pattern_tail(p, 0, 1, 0, 0, &@$);
$$ = new_array_pattern(p, 0, $1, $$, &@$);
- /*% ripper: ripper_new_array_pattern(p, Qnil, get_value($:1), rb_ary_new()); %*/
+ /*% ripper: aryptn!(Qnil, [$:1], Qnil, Qnil) %*/
}
| p_expr ',' p_args
{
$$ = new_array_pattern(p, 0, $1, $3, &@$);
nd_set_first_loc($$, @1.beg_pos);
- /*% ripper: ripper_new_array_pattern(p, Qnil, get_value($:1), get_value($:3)); %*/
+ /*% ripper: aryptn!(Qnil, aryptn_pre_args(p, $:1, $:3[0]), *$:3[1..2]) %*/
}
| p_find
{
$$ = new_find_pattern(p, 0, $1, &@$);
- /*% ripper: ripper_new_find_pattern(p, Qnil, get_value($:1)); %*/
+ /*% ripper: fndptn!(Qnil, *$:1[0..2]) %*/
}
| p_args_tail
{
$$ = new_array_pattern(p, 0, 0, $1, &@$);
- /*% ripper: ripper_new_array_pattern(p, Qnil, Qnil, get_value($:1)); %*/
+ /*% ripper: aryptn!(Qnil, *$:1[0..2]) %*/
}
| p_kwargs
{
$$ = new_hash_pattern(p, 0, $1, &@$);
- /*% ripper: ripper_new_hash_pattern(p, Qnil, get_value($:1)); %*/
+ /*% ripper: hshptn!(Qnil, *$:1[0..1]) %*/
}
;
@@ -5565,14 +5520,14 @@ p_alt : p_alt '|' p_expr_basic
p_lparen : '(' p_pktbl
{
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
;
p_lbracket : '[' p_pktbl
{
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
;
@@ -5583,70 +5538,70 @@ p_expr_basic : p_value
pop_pktbl(p, $p_pktbl);
$$ = new_array_pattern(p, $p_const, 0, $p_args, &@$);
nd_set_first_loc($$, @p_const.beg_pos);
- /*% ripper: ripper_new_array_pattern(p, get_value($:p_const), Qnil, get_value($:p_args)); %*/
+ /*% ripper: aryptn!($:p_const, *$:p_args[0..2]) %*/
}
| p_const p_lparen[p_pktbl] p_find rparen
{
pop_pktbl(p, $p_pktbl);
$$ = new_find_pattern(p, $p_const, $p_find, &@$);
nd_set_first_loc($$, @p_const.beg_pos);
- /*% ripper: ripper_new_find_pattern(p, get_value($:p_const), get_value($:p_find)); %*/
+ /*% ripper: fndptn!($:p_const, *$:p_find[0..2]) %*/
}
| p_const p_lparen[p_pktbl] p_kwargs rparen
{
pop_pktbl(p, $p_pktbl);
$$ = new_hash_pattern(p, $p_const, $p_kwargs, &@$);
nd_set_first_loc($$, @p_const.beg_pos);
- /*% ripper: ripper_new_hash_pattern(p, get_value($:p_const), get_value($:p_kwargs)); %*/
+ /*% ripper: hshptn!($:p_const, *$:p_kwargs[0..1]) %*/
}
| p_const '(' rparen
{
$$ = new_array_pattern_tail(p, 0, 0, 0, 0, &@$);
$$ = new_array_pattern(p, $p_const, 0, $$, &@$);
- /*% ripper: ripper_new_array_pattern(p, get_value($:p_const), Qnil, rb_ary_new()); %*/
+ /*% ripper: aryptn!($:p_const, Qnil, Qnil, Qnil) %*/
}
| p_const p_lbracket[p_pktbl] p_args rbracket
{
pop_pktbl(p, $p_pktbl);
$$ = new_array_pattern(p, $p_const, 0, $p_args, &@$);
nd_set_first_loc($$, @p_const.beg_pos);
- /*% ripper: ripper_new_array_pattern(p, get_value($:p_const), Qnil, get_value($:p_args)); %*/
+ /*% ripper: aryptn!($:p_const, *$:p_args[0..2]) %*/
}
| p_const p_lbracket[p_pktbl] p_find rbracket
{
pop_pktbl(p, $p_pktbl);
$$ = new_find_pattern(p, $p_const, $p_find, &@$);
nd_set_first_loc($$, @p_const.beg_pos);
- /*% ripper: ripper_new_find_pattern(p, get_value($:p_const), get_value($:p_find)); %*/
+ /*% ripper: fndptn!($:p_const, *$:p_find[0..2]) %*/
}
| p_const p_lbracket[p_pktbl] p_kwargs rbracket
{
pop_pktbl(p, $p_pktbl);
$$ = new_hash_pattern(p, $p_const, $p_kwargs, &@$);
nd_set_first_loc($$, @p_const.beg_pos);
- /*% ripper: ripper_new_hash_pattern(p, get_value($:p_const), get_value($:p_kwargs)); %*/
+ /*% ripper: hshptn!($:p_const, *$:p_kwargs[0..1]) %*/
}
| p_const '[' rbracket
{
$$ = new_array_pattern_tail(p, 0, 0, 0, 0, &@$);
$$ = new_array_pattern(p, $1, 0, $$, &@$);
- /*% ripper: ripper_new_array_pattern(p, get_value($:1), Qnil, rb_ary_new()); %*/
+ /*% ripper: aryptn!($:1, Qnil, Qnil, Qnil) %*/
}
| tLBRACK p_args rbracket
{
$$ = new_array_pattern(p, 0, 0, $p_args, &@$);
- /*% ripper: ripper_new_array_pattern(p, Qnil, Qnil, get_value($:p_args)); %*/
+ /*% ripper: aryptn!(Qnil, *$:p_args[0..2]) %*/
}
| tLBRACK p_find rbracket
{
$$ = new_find_pattern(p, 0, $p_find, &@$);
- /*% ripper: ripper_new_find_pattern(p, Qnil, get_value($:p_find)); %*/
+ /*% ripper: fndptn!(Qnil, *$:p_find[0..2]) %*/
}
| tLBRACK rbracket
{
$$ = new_array_pattern_tail(p, 0, 0, 0, 0, &@$);
$$ = new_array_pattern(p, 0, 0, $$, &@$);
- /*% ripper: ripper_new_array_pattern(p, Qnil, Qnil, rb_ary_new()); %*/
+ /*% ripper: aryptn!(Qnil, Qnil, Qnil, Qnil) %*/
}
| tLBRACE p_pktbl lex_ctxt[ctxt]
{
@@ -5657,24 +5612,19 @@ p_expr_basic : p_value
pop_pktbl(p, $p_pktbl);
p->ctxt.in_kwarg = $ctxt.in_kwarg;
$$ = new_hash_pattern(p, 0, $p_kwargs, &@$);
- /*% ripper: ripper_new_hash_pattern(p, Qnil, get_value($:p_kwargs)); %*/
+ /*% ripper: hshptn!(Qnil, *$:p_kwargs[0..1]) %*/
}
| tLBRACE rbrace
{
$$ = new_hash_pattern_tail(p, 0, 0, &@$);
$$ = new_hash_pattern(p, 0, $$, &@$);
- /*%%%*/
- /*%
- VALUE val = ripper_new_hash_pattern_tail(p, Qnil, 0);
- val = ripper_new_hash_pattern(p, Qnil, val);
- set_value(val);
- %*/
+ /*% ripper: hshptn!(Qnil, Qnil, Qnil) %*/
}
| tLPAREN p_pktbl p_expr rparen
{
pop_pktbl(p, $p_pktbl);
$$ = $p_expr;
- /*% ripper: get_value($:p_expr); %*/
+ /*% ripper: $:p_expr %*/
}
;
@@ -5682,44 +5632,27 @@ p_args : p_expr
{
NODE *pre_args = NEW_LIST($1, &@$);
$$ = new_array_pattern_tail(p, pre_args, 0, 0, 0, &@$);
- /*%%%*/
- /*%
- VALUE ary = rb_ary_new_from_args(1, get_value($:1));
- set_value(rb_ary_new_from_args(3, ary, Qnil, Qnil));
- %*/
+ /*% ripper: [[$:1], Qnil, Qnil] %*/
}
| p_args_head
{
$$ = new_array_pattern_tail(p, $1, 1, 0, 0, &@$);
- /*%%%*/
- /*%
- set_value(rb_ary_new_from_args(3, get_value($:1), Qnil, Qnil));
- %*/
+ /*% ripper: [$:1, Qnil, Qnil] %*/
}
| p_args_head p_arg
{
$$ = new_array_pattern_tail(p, list_concat($1, $2), 0, 0, 0, &@$);
- /*%%%*/
- /*%
- VALUE pre_args = rb_ary_concat(get_value($:1), get_value($:2));
- set_value(rb_ary_new_from_args(3, pre_args, Qnil, Qnil));
- %*/
+ /*% ripper: [rb_ary_concat($:1, $:2), Qnil, Qnil] %*/
}
| p_args_head p_rest
{
$$ = new_array_pattern_tail(p, $1, 1, $2, 0, &@$);
- /*%%%*/
- /*%
- set_value(rb_ary_new_from_args(3, get_value($:1), get_value($:2), Qnil));
- %*/
+ /*% ripper: [$:1, $:2, Qnil] %*/
}
| p_args_head p_rest ',' p_args_post
{
$$ = new_array_pattern_tail(p, $1, 1, $2, $4, &@$);
- /*%%%*/
- /*%
- set_value(rb_ary_new_from_args(3, get_value($:1), get_value($:2), get_value($:4)));
- %*/
+ /*% ripper: [$:1, $:2, $:4] %*/
}
| p_args_tail
;
@@ -5731,26 +5664,26 @@ p_args_head : p_arg ','
| p_args_head p_arg ','
{
$$ = list_concat($1, $2);
- /*% ripper: rb_ary_concat(get_value($:1), get_value($:2)) %*/
+ /*% ripper: rb_ary_concat($:1, $:2) %*/
}
;
p_args_tail : p_rest
{
$$ = new_array_pattern_tail(p, 0, 1, $1, 0, &@$);
- /*% ripper: ripper_new_array_pattern_tail(p, Qnil, get_value($:1), Qnil); %*/
+ /*% ripper: [Qnil, $:1, Qnil] %*/
}
| p_rest ',' p_args_post
{
$$ = new_array_pattern_tail(p, 0, 1, $1, $3, &@$);
- /*% ripper: ripper_new_array_pattern_tail(p, Qnil, get_value($:1), get_value($:3)); %*/
+ /*% ripper: [Qnil, $:1, $:3] %*/
}
;
p_find : p_rest ',' p_args_post ',' p_rest
{
$$ = new_find_pattern_tail(p, $1, $3, $5, &@$);
- /*% ripper: ripper_new_find_pattern_tail(p, get_value($:1), get_value($:3), get_value($:5)) %*/
+ /*% ripper: [$:1, $:3, $:5] %*/
}
;
@@ -5758,13 +5691,13 @@ p_find : p_rest ',' p_args_post ',' p_rest
p_rest : tSTAR tIDENTIFIER
{
error_duplicate_pattern_variable(p, $2, &@2);
+ /*% ripper: var_field!($:2) %*/
$$ = assignable(p, $2, 0, &@$);
- /*% ripper: ripper_assignable(p, $2, var_field(p, get_value($:2))) %*/
}
| tSTAR
{
$$ = 0;
- /*% ripper: var_field(p, Qnil) %*/
+ /*% ripper: var_field!(Qnil) %*/
}
;
@@ -5772,45 +5705,45 @@ p_args_post : p_arg
| p_args_post ',' p_arg
{
$$ = list_concat($1, $3);
- /*% ripper: rb_ary_concat(get_value($:1), get_value($:3)) %*/
+ /*% ripper: rb_ary_concat($:1, $:3) %*/
}
;
p_arg : p_expr
{
$$ = NEW_LIST($1, &@$);
- /*% ripper: rb_ary_new_from_args(1, get_value($:1)) %*/
+ /*% ripper: [$:1] %*/
}
;
p_kwargs : p_kwarg ',' p_any_kwrest
{
$$ = new_hash_pattern_tail(p, new_unique_key_hash(p, $1, &@$), $3, &@$);
- /*% ripper: ripper_new_hash_pattern_tail(p, get_value($:1), get_value($:3)) %*/
+ /*% ripper: [$:1, $:3] %*/
}
| p_kwarg
{
$$ = new_hash_pattern_tail(p, new_unique_key_hash(p, $1, &@$), 0, &@$);
- /*% ripper: ripper_new_hash_pattern_tail(p, get_value($:1), 0) %*/
+ /*% ripper: [$:1, Qnil] %*/
}
| p_kwarg ','
{
$$ = new_hash_pattern_tail(p, new_unique_key_hash(p, $1, &@$), 0, &@$);
- /*% ripper: ripper_new_hash_pattern_tail(p, get_value($:1), 0) %*/
+ /*% ripper: [$:1, Qnil] %*/
}
| p_any_kwrest
{
$$ = new_hash_pattern_tail(p, new_hash(p, 0, &@$), $1, &@$);
- /*% ripper: ripper_new_hash_pattern_tail(p, rb_ary_new(), get_value($:1)) %*/
+ /*% ripper: [[], $:1] %*/
}
;
p_kwarg : p_kw
- /*% ripper[brace]: rb_ary_new_from_args(1, get_value($:1)) %*/
+ /*% ripper[brace]: [$:1] %*/
| p_kwarg ',' p_kw
{
$$ = list_concat($1, $3);
- /*% ripper: rb_ary_push(get_value($:1), get_value($:3)) %*/
+ /*% ripper: rb_ary_push($:1, $:3) %*/
}
;
@@ -5818,7 +5751,7 @@ p_kw : p_kw_label p_expr
{
error_duplicate_pattern_key(p, $1, &@1);
$$ = list_append(p, NEW_LIST(NEW_SYM(rb_id2str($1), &@1), &@$), $2);
- /*% ripper: rb_ary_new_from_args(2, get_value($:1), get_value($:2)) %*/
+ /*% ripper: [$:1, $:2] %*/
}
| p_kw_label
{
@@ -5828,7 +5761,7 @@ p_kw : p_kw_label p_expr
}
error_duplicate_pattern_variable(p, $1, &@1);
$$ = list_append(p, NEW_LIST(NEW_SYM(rb_id2str($1), &@$), &@$), assignable(p, $1, 0, &@$));
- /*% ripper: rb_ary_new_from_args(2, ripper_assignable(p, $1, get_value($:1)), Qnil) %*/
+ /*% ripper: [$:1, Qnil] %*/
}
;
@@ -5844,19 +5777,19 @@ p_kw_label : tLABEL
yyerror1(&loc, "symbol literal with interpolation is not allowed");
$$ = rb_intern_str(STR_NEW0());
}
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
;
p_kwrest : kwrest_mark tIDENTIFIER
{
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: var_field!($:2) %*/
}
| kwrest_mark
{
$$ = 0;
- /*% ripper: 0; %*/
+ /*% ripper: Qnil %*/
}
;
@@ -5870,7 +5803,7 @@ p_any_kwrest : p_kwrest
| p_kwnorest
{
$$ = idNil;
- /*% ripper: ID2VAL(idNil) %*/
+ /*% ripper: var_field!(ID2VAL(idNil)) %*/
}
;
@@ -5937,8 +5870,8 @@ p_primitive : literal
p_variable : tIDENTIFIER
{
error_duplicate_pattern_variable(p, $1, &@1);
+ /*% ripper: var_field!($:1) %*/
$$ = assignable(p, $1, 0, &@$);
- /*% ripper: ripper_assignable(p, $1, var_field(p, get_value($:1))) %*/
}
;
@@ -6013,7 +5946,7 @@ opt_rescue : k_rescue exc_list exc_var then
exc_list : arg_value
{
$$ = NEW_LIST($1, &@$);
- /*% ripper: rb_ary_new3(1, get_value($:1)) %*/
+ /*% ripper: rb_ary_new3(1, $:1) %*/
}
| mrhs
{
@@ -6025,7 +5958,7 @@ exc_list : arg_value
exc_var : tASSOC lhs
{
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
| none
;
@@ -6053,7 +5986,7 @@ strings : string
node = evstr2dstr(p, node);
}
$$ = node;
- /*% ripper: get_value($:1); %*/
+ /*% ripper: $:1 %*/
}
;
@@ -6068,32 +6001,26 @@ string : tCHAR
string1 : tSTRING_BEG string_contents tSTRING_END
{
- /*%%%*/
- /*%
- int indent = p->heredoc_indent;
- %*/
$$ = heredoc_dedent(p, $2);
if ($$) nd_set_loc($$, &@$);
- /*%%%*/
- /*%
- VALUE val = dispatch1(string_literal, ripper_heredoc_dedent(p, indent, get_value($:2)));
- set_value(val);
- %*/
+ /*% ripper: $:2 %*/
+ if (p->heredoc_indent > 0) {
+ /*% ripper: heredoc_dedent!($:$, INT2NUM(%{p->heredoc_indent})) %*/
+ p->heredoc_indent = 0;
+ }
+ /*% ripper: string_literal!($:$) %*/
}
;
xstring : tXSTRING_BEG xstring_contents tSTRING_END
{
- /*%%%*/
- /*%
- int indent = p->heredoc_indent;
- %*/
$$ = new_xstring(p, heredoc_dedent(p, $2), &@$);
- /*%%%*/
- /*%
- VALUE val = dispatch1(xstring_literal, ripper_heredoc_dedent(p, indent, get_value($:2)));
- set_value(val);
- %*/
+ /*% ripper: $:2 %*/
+ if (p->heredoc_indent > 0) {
+ /*% ripper: heredoc_dedent!($:$, INT2NUM(%{p->heredoc_indent})) %*/
+ p->heredoc_indent = 0;
+ }
+ /*% ripper: xstring_literal!($:$) %*/
}
;
@@ -6104,15 +6031,7 @@ regexp : tREGEXP_BEG regexp_contents tREGEXP_END
}
;
-words_sep : ' ' {}
- | words_sep ' '
- ;
-
-words : tWORDS_BEG words_sep word_list tSTRING_END
- {
- $$ = make_list($3, &@$);
- /*% ripper: array!($:3) %*/
- }
+words : words(tWORDS_BEG, word_list) <node>
;
word_list : /* none */
@@ -6120,7 +6039,7 @@ word_list : /* none */
$$ = 0;
/*% ripper: words_new! %*/
}
- | word_list word words_sep
+ | word_list word ' '+
{
$$ = list_append(p, $1, evstr2dstr(p, $2));
/*% ripper: words_add!($:1, $:2) %*/
@@ -6136,11 +6055,7 @@ word : string_content
}
;
-symbols : tSYMBOLS_BEG words_sep symbol_list tSTRING_END
- {
- $$ = make_list($3, &@$);
- /*% ripper: array!($:3) %*/
- }
+symbols : words(tSYMBOLS_BEG, symbol_list) <node>
;
symbol_list : /* none */
@@ -6148,25 +6063,17 @@ symbol_list : /* none */
$$ = 0;
/*% ripper: symbols_new! %*/
}
- | symbol_list word words_sep
+ | symbol_list word ' '+
{
$$ = symbol_append(p, $1, evstr2dstr(p, $2));
/*% ripper: symbols_add!($:1, $:2) %*/
}
;
-qwords : tQWORDS_BEG words_sep qword_list tSTRING_END
- {
- $$ = make_list($3, &@$);
- /*% ripper: array!($:3) %*/
- }
+qwords : words(tQWORDS_BEG, qword_list) <node>
;
-qsymbols : tQSYMBOLS_BEG words_sep qsym_list tSTRING_END
- {
- $$ = make_list($3, &@$);
- /*% ripper: array!($:3) %*/
- }
+qsymbols : words(tQSYMBOLS_BEG, qsym_list) <node>
;
qword_list : /* none */
@@ -6174,7 +6081,7 @@ qword_list : /* none */
$$ = 0;
/*% ripper: qwords_new! %*/
}
- | qword_list tSTRING_CONTENT words_sep
+ | qword_list tSTRING_CONTENT ' '+
{
$$ = list_append(p, $1, $2);
/*% ripper: qwords_add!($:1, $:2) %*/
@@ -6186,7 +6093,7 @@ qsym_list : /* none */
$$ = 0;
/*% ripper: qsymbols_new! %*/
}
- | qsym_list tSTRING_CONTENT words_sep
+ | qsym_list tSTRING_CONTENT ' '+
{
$$ = symbol_append(p, $1, $2);
/*% ripper: qsymbols_add!($:1, $:2) %*/
@@ -6196,8 +6103,6 @@ qsym_list : /* none */
string_contents : /* none */
{
$$ = 0;
- /*%%%*/
- /*% %*/
/*% ripper: string_content! %*/
}
| string_contents string_content
@@ -6251,47 +6156,46 @@ regexp_contents: /* none */
;
string_content : tSTRING_CONTENT
- /*% ripper[brace]: get_value($:1); %*/
+ /*% ripper[brace]: $:1 %*/
| tSTRING_DVAR
{
/* need to backup p->lex.strterm so that a string literal `%&foo,#$&,bar&` can be parsed */
- $<strterm>$ = p->lex.strterm;
+ $$ = p->lex.strterm;
p->lex.strterm = 0;
SET_LEX_STATE(EXPR_BEG);
- }
+ }<strterm>
string_dvar
{
- p->lex.strterm = $<strterm>2;
+ p->lex.strterm = $2;
$$ = NEW_EVSTR($3, &@$);
nd_set_line($$, @3.end_pos.lineno);
/*% ripper: string_dvar!($:3) %*/
}
- | tSTRING_DBEG[term]
+ | tSTRING_DBEG[state]
{
CMDARG_PUSH(0);
COND_PUSH(0);
/* need to backup p->lex.strterm so that a string literal `%!foo,#{ !0 },bar!` can be parsed */
- $<strterm>term = p->lex.strterm;
+ $$ = p->lex.strterm;
p->lex.strterm = 0;
- $<num>$ = p->lex.state;
SET_LEX_STATE(EXPR_BEG);
- }[state]
+ }[term]<strterm>
{
- $<num>$ = p->lex.brace_nest;
+ $$ = p->lex.brace_nest;
p->lex.brace_nest = 0;
- }[brace]
+ }[brace]<num>
{
- $<num>$ = p->heredoc_indent;
+ $$ = p->heredoc_indent;
p->heredoc_indent = 0;
- }[indent]
+ }[indent]<num>
compstmt string_dend
{
COND_POP();
CMDARG_POP();
- p->lex.strterm = $<strterm>term;
- SET_LEX_STATE($<num>state);
- p->lex.brace_nest = $<num>brace;
- p->heredoc_indent = $<num>indent;
+ p->lex.strterm = $term;
+ SET_LEX_STATE($state);
+ p->lex.brace_nest = $brace;
+ p->heredoc_indent = $indent;
p->heredoc_line_indent = -1;
if ($compstmt) nd_unset_fl_newline($compstmt);
$$ = new_evstr(p, $compstmt, &@$);
@@ -6380,17 +6284,12 @@ keyword_variable: keyword_nil {$$ = KWD2EID(nil, $1);}
var_ref : user_variable
{
if (!($$ = gettable(p, $1, &@$))) $$ = NEW_ERROR(&@$);
- /*%%%*/
- /*%
- if (id_is_var(p, $1)) {
- VALUE val = dispatch1(var_ref, get_value($:1));
- set_value(val);
+ if (ifdef_ripper(id_is_var(p, $1), false)) {
+ /*% ripper: var_ref!($:1) %*/
}
else {
- VALUE val = dispatch1(vcall, get_value($:1));
- set_value(val);
+ /*% ripper: vcall!($:1) %*/
}
- %*/
}
| keyword_variable
{
@@ -6401,13 +6300,13 @@ var_ref : user_variable
var_lhs : user_variable
{
+ /*% ripper: var_field!($:1) %*/
$$ = assignable(p, $1, 0, &@$);
- /*% ripper: ripper_assignable(p, $1, var_field(p, get_value($:1))) %*/
}
| keyword_variable
{
+ /*% ripper: var_field!($:1) %*/
$$ = assignable(p, $1, 0, &@$);
- /*% ripper: ripper_assignable(p, $1, var_field(p, get_value($:1))) %*/
}
;
@@ -6423,7 +6322,7 @@ superclass : '<'
expr_value term
{
$$ = $3;
- /*% ripper: get_value($:3); %*/
+ /*% ripper: $:3 %*/
}
| /* none */
{
@@ -6438,7 +6337,7 @@ f_opt_paren_args: f_paren_args
p->ctxt.in_argdef = 0;
$$ = new_args_tail(p, 0, 0, 0, &@0);
$$ = new_args(p, 0, 0, 0, 0, $$, &@0);
- /*% ripper: ripper_new_args(p, Qnil, Qnil, Qnil, Qnil, rb_ary_new_from_args(3, Qnil, Qnil, Qnil)) %*/
+ /*% ripper: params!(Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil) %*/
}
;
@@ -6454,138 +6353,126 @@ f_paren_args : '(' f_args rparen
f_arglist : f_paren_args
| {
- $<ctxt>$ = p->ctxt;
+ $$ = p->ctxt;
p->ctxt.in_kwarg = 1;
p->ctxt.in_argdef = 1;
SET_LEX_STATE(p->lex.state|EXPR_LABEL); /* force for args */
- }
+ }<ctxt>
f_args term
{
- p->ctxt.in_kwarg = $<ctxt>1.in_kwarg;
+ p->ctxt.in_kwarg = $1.in_kwarg;
p->ctxt.in_argdef = 0;
$$ = $2;
SET_LEX_STATE(EXPR_BEG);
p->command_start = TRUE;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
;
-args_tail : f_kwarg ',' f_kwrest opt_f_block_arg
+args_tail : f_kwarg(f_kw) ',' f_kwrest opt_f_block_arg
{
$$ = new_args_tail(p, $1, $3, $4, &@3);
- /*% ripper: rb_ary_new_from_args(3, get_value($:1), get_value($:3), get_value($:4)); %*/
+ /*% ripper: [$:1, $:3, $:4] %*/
}
- | f_kwarg opt_f_block_arg
+ | f_kwarg(f_kw) opt_f_block_arg
{
$$ = new_args_tail(p, $1, 0, $2, &@1);
- /*% ripper: rb_ary_new_from_args(3, get_value($:1), Qnil, get_value($:2)); %*/
+ /*% ripper: [$:1, Qnil, $:2] %*/
}
| f_any_kwrest opt_f_block_arg
{
$$ = new_args_tail(p, 0, $1, $2, &@1);
- /*% ripper: rb_ary_new_from_args(3, Qnil, get_value($:1), get_value($:2)); %*/
+ /*% ripper: [Qnil, $:1, $:2] %*/
}
| f_block_arg
{
$$ = new_args_tail(p, 0, 0, $1, &@1);
- /*% ripper: rb_ary_new_from_args(3, Qnil, Qnil, get_value($:1)); %*/
+ /*% ripper: [Qnil, Qnil, $:1] %*/
}
| args_forward
{
add_forwarding_args(p);
$$ = new_args_tail(p, 0, $1, arg_FWD_BLOCK, &@1);
$$->nd_ainfo.forwarding = 1;
- /*% ripper: rb_ary_new_from_args(3, Qnil, get_value($:1), Qnil); %*/
+ /*% ripper: [Qnil, $:1, Qnil] %*/
}
;
-opt_args_tail : ',' args_tail
- {
- $$ = $2;
- /*% ripper: get_value($:2); %*/
- }
- | /* none */
- {
- $$ = new_args_tail(p, 0, 0, 0, &@0);
- /*% ripper: rb_ary_new_from_args(3, Qnil, Qnil, Qnil); %*/
- }
- ;
-
-f_args : f_arg ',' f_optarg ',' f_rest_arg opt_args_tail
+f_args : f_arg ',' f_optarg(arg_value) ',' f_rest_arg opt_args_tail(args_tail)
{
$$ = new_args(p, $1, $3, $5, 0, $6, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), get_value($:3), get_value($:5), Qnil, get_value($:6)) %*/
+ /*% ripper: params!($:1, $:3, $:5, Qnil, *$:6[0..2]) %*/
}
- | f_arg ',' f_optarg ',' f_rest_arg ',' f_arg opt_args_tail
+ | f_arg ',' f_optarg(arg_value) ',' f_rest_arg ',' f_arg opt_args_tail(args_tail)
{
$$ = new_args(p, $1, $3, $5, $7, $8, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), get_value($:3), get_value($:5), get_value($:7), get_value($:8)) %*/
+ /*% ripper: params!($:1, $:3, $:5, $:7, *$:8[0..2]) %*/
}
- | f_arg ',' f_optarg opt_args_tail
+ | f_arg ',' f_optarg(arg_value) opt_args_tail(args_tail)
{
$$ = new_args(p, $1, $3, 0, 0, $4, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), get_value($:3), Qnil, Qnil, get_value($:4)) %*/
+ /*% ripper: params!($:1, $:3, Qnil, Qnil, *$:4[0..2]) %*/
}
- | f_arg ',' f_optarg ',' f_arg opt_args_tail
+ | f_arg ',' f_optarg(arg_value) ',' f_arg opt_args_tail(args_tail)
{
$$ = new_args(p, $1, $3, 0, $5, $6, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), get_value($:3), Qnil, get_value($:5), get_value($:6)) %*/
+ /*% ripper: params!($:1, $:3, Qnil, $:5, *$:6[0..2]) %*/
}
- | f_arg ',' f_rest_arg opt_args_tail
+ | f_arg ',' f_rest_arg opt_args_tail(args_tail)
{
$$ = new_args(p, $1, 0, $3, 0, $4, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), Qnil, get_value($:3), Qnil, get_value($:4)) %*/
+ /*% ripper: params!($:1, Qnil, $:3, Qnil, *$:4[0..2]) %*/
}
- | f_arg ',' f_rest_arg ',' f_arg opt_args_tail
+ | f_arg ',' f_rest_arg ',' f_arg opt_args_tail(args_tail)
{
$$ = new_args(p, $1, 0, $3, $5, $6, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), Qnil, get_value($:3), get_value($:5), get_value($:6)) %*/
+ /*% ripper: params!($:1, Qnil, $:3, $:5, *$:6[0..2]) %*/
}
- | f_arg opt_args_tail
+ | f_arg opt_args_tail(args_tail)
{
$$ = new_args(p, $1, 0, 0, 0, $2, &@$);
- /*% ripper: ripper_new_args(p, get_value($:1), Qnil, Qnil, Qnil, get_value($:2)) %*/
+ /*% ripper: params!($:1, Qnil, Qnil, Qnil, *$:2[0..2]) %*/
}
- | f_optarg ',' f_rest_arg opt_args_tail
+ | f_optarg(arg_value) ',' f_rest_arg opt_args_tail(args_tail)
{
$$ = new_args(p, 0, $1, $3, 0, $4, &@$);
- /*% ripper: ripper_new_args(p, Qnil, get_value($:1), get_value($:3), Qnil, get_value($:4)) %*/
+ /*% ripper: params!(Qnil, $:1, $:3, Qnil, *$:4[0..2]) %*/
}
- | f_optarg ',' f_rest_arg ',' f_arg opt_args_tail
+ | f_optarg(arg_value) ',' f_rest_arg ',' f_arg opt_args_tail(args_tail)
{
$$ = new_args(p, 0, $1, $3, $5, $6, &@$);
- /*% ripper: ripper_new_args(p, Qnil, get_value($:1), get_value($:3), get_value($:5), get_value($:6)) %*/
+ /*% ripper: params!(Qnil, $:1, $:3, $:5, *$:6[0..2]) %*/
}
- | f_optarg opt_args_tail
+ | f_optarg(arg_value) opt_args_tail(args_tail)
{
$$ = new_args(p, 0, $1, 0, 0, $2, &@$);
- /*% ripper: ripper_new_args(p, Qnil, get_value($:1), Qnil, Qnil, get_value($:2)) %*/
+ /*% ripper: params!(Qnil, $:1, Qnil, Qnil, *$:2[0..2]) %*/
}
- | f_optarg ',' f_arg opt_args_tail
+ | f_optarg(arg_value) ',' f_arg opt_args_tail(args_tail)
{
$$ = new_args(p, 0, $1, 0, $3, $4, &@$);
- /*% ripper: ripper_new_args(p, Qnil, get_value($:1), Qnil, get_value($:3), get_value($:4)) %*/
+ /*% ripper: params!(Qnil, $:1, Qnil, $:3, *$:4[0..2]) %*/
}
- | f_rest_arg opt_args_tail
+ | f_rest_arg opt_args_tail(args_tail)
{
$$ = new_args(p, 0, 0, $1, 0, $2, &@$);
- /*% ripper: ripper_new_args(p, Qnil, Qnil, get_value($:1), Qnil, get_value($:2)) %*/
+ /*% ripper: params!(Qnil, Qnil, $:1, Qnil, *$:2[0..2]) %*/
}
- | f_rest_arg ',' f_arg opt_args_tail
+ | f_rest_arg ',' f_arg opt_args_tail(args_tail)
{
$$ = new_args(p, 0, 0, $1, $3, $4, &@$);
- /*% ripper: ripper_new_args(p, Qnil, Qnil, get_value($:1), get_value($:3), get_value($:4)) %*/
+ /*% ripper: params!(Qnil, Qnil, $:1, $:3, *$:4[0..2]) %*/
}
| args_tail
{
$$ = new_args(p, 0, 0, 0, 0, $1, &@$);
- /*% ripper: ripper_new_args(p, Qnil, Qnil, Qnil, Qnil, get_value($:1)) %*/
+ /*% ripper: params!(Qnil, Qnil, Qnil, Qnil, *$:1[0..2]) %*/
}
| /* none */
{
$$ = new_args_tail(p, 0, 0, 0, &@0);
$$ = new_args(p, 0, 0, 0, 0, $$, &@0);
- /*% ripper: ripper_new_args(p, Qnil, Qnil, Qnil, Qnil, rb_ary_new_from_args(3, Qnil, Qnil, Qnil)) %*/
+ /*% ripper: params!(Qnil, Qnil, Qnil, Qnil, Qnil, Qnil, Qnil) %*/
}
;
@@ -6641,13 +6528,11 @@ f_bad_arg : tCONSTANT
f_norm_arg : f_bad_arg
| tIDENTIFIER
{
- formal_argument(p, $1);
+ VALUE e = formal_argument_error(p, $$ = $1);
+ if (e) {
+ /*% ripper[error]: param_error!(?e, $:1) %*/
+ }
p->max_numparam = ORDINAL_PARAM;
- $$ = $1;
- /*%%%*/
- /*%
- ripper_formal_argument(p, $1, get_value($:1));
- %*/
}
;
@@ -6655,16 +6540,14 @@ f_arg_asgn : f_norm_arg
{
ID id = $1;
arg_var(p, id);
- p->cur_arg = id;
$$ = $1;
}
;
f_arg_item : f_arg_asgn
{
- p->cur_arg = 0;
$$ = NEW_ARGS_AUX($1, 1, &NULL_LOC);
- /*% ripper: get_value($:1) %*/
+ /*% ripper: $:1 %*/
}
| tLPAREN f_margs rparen
{
@@ -6686,45 +6569,49 @@ f_arg_item : f_arg_asgn
;
f_arg : f_arg_item
- /*% ripper[brace]: rb_ary_new3(1, get_value($:1)) %*/
+ /*% ripper[brace]: rb_ary_new3(1, $:1) %*/
| f_arg ',' f_arg_item
{
$$ = $1;
$$->nd_plen++;
$$->nd_next = block_append(p, $$->nd_next, $3->nd_next);
rb_discard_node(p, (NODE *)$3);
- /*% ripper: rb_ary_push(get_value($:1), get_value($:3)) %*/
+ /*% ripper: rb_ary_push($:1, $:3) %*/
}
;
f_label : tLABEL
{
- arg_var(p, formal_argument(p, $1));
- p->cur_arg = $1;
+ VALUE e = formal_argument_error(p, $$ = $1);
+ if (e) {
+ $$ = 0;
+ /*% ripper[error]: param_error!(?e, $:1) %*/
+ }
+ /*
+ * Workaround for Prism::ParseTest#test_filepath for
+ * "unparser/corpus/literal/def.txt"
+ *
+ * See the discussion on https://github.com/ruby/ruby/pull/9923
+ */
+ arg_var(p, ifdef_ripper(0, $1));
+ /*% ripper: $:1 %*/
p->max_numparam = ORDINAL_PARAM;
p->ctxt.in_argdef = 0;
- $$ = $1;
- /*%%%*/
- /*%
- ripper_formal_argument(p, $1, get_value($:1));
- %*/
}
;
f_kw : f_label arg_value
{
- p->cur_arg = 0;
p->ctxt.in_argdef = 1;
$$ = new_kw_arg(p, assignable(p, $1, $2, &@$), &@$);
- /*% ripper: rb_assoc_new(ripper_assignable(p, $1, get_value($:1)), get_value($:2)) %*/
+ /*% ripper: [$:$, $:2] %*/
}
| f_label
{
- p->cur_arg = 0;
p->ctxt.in_argdef = 1;
$$ = new_kw_arg(p, assignable(p, $1, NODE_SPECIAL_REQUIRED_KEYWORD, &@$), &@$);
- /*% ripper: rb_assoc_new(ripper_assignable(p, $1, get_value($:1)), 0) %*/
+ /*% ripper: [$:$, 0] %*/
}
;
@@ -6732,38 +6619,13 @@ f_block_kw : f_label primary_value
{
p->ctxt.in_argdef = 1;
$$ = new_kw_arg(p, assignable(p, $1, $2, &@$), &@$);
- /*% ripper: rb_assoc_new(ripper_assignable(p, $1, get_value($:1)), get_value($:2)) %*/
+ /*% ripper: [$:$, $:2] %*/
}
| f_label
{
p->ctxt.in_argdef = 1;
$$ = new_kw_arg(p, assignable(p, $1, NODE_SPECIAL_REQUIRED_KEYWORD, &@$), &@$);
- /*% ripper: rb_assoc_new(ripper_assignable(p, $1, get_value($:1)), 0) %*/
- }
- ;
-
-f_block_kwarg : f_block_kw
- {
- $$ = $1;
- /*% ripper: rb_ary_new3(1, get_value($:1)) %*/
- }
- | f_block_kwarg ',' f_block_kw
- {
- $$ = kwd_append($1, $3);
- /*% ripper: rb_ary_push(get_value($:1), get_value($:3)) %*/
- }
- ;
-
-
-f_kwarg : f_kw
- {
- $$ = $1;
- /*% ripper: rb_ary_new3(1, get_value($:1)) %*/
- }
- | f_kwarg ',' f_kw
- {
- $$ = kwd_append($1, $3);
- /*% ripper: rb_ary_push(get_value($:1), get_value($:3)) %*/
+ /*% ripper: [$:$, 0] %*/
}
;
@@ -6791,48 +6653,6 @@ f_kwrest : kwrest_mark tIDENTIFIER
}
;
-f_opt : f_arg_asgn f_eq arg_value
- {
- p->cur_arg = 0;
- p->ctxt.in_argdef = 1;
- $$ = NEW_OPT_ARG(assignable(p, $1, $3, &@$), &@$);
- /*% ripper: rb_assoc_new(ripper_assignable(p, $1, get_value($:1)), get_value($:3)) %*/
- }
- ;
-
-f_block_opt : f_arg_asgn f_eq primary_value
- {
- p->cur_arg = 0;
- p->ctxt.in_argdef = 1;
- $$ = NEW_OPT_ARG(assignable(p, $1, $3, &@$), &@$);
- /*% ripper: rb_assoc_new(ripper_assignable(p, $1, get_value($:1)), get_value($:3)) %*/
- }
- ;
-
-f_block_optarg : f_block_opt
- {
- $$ = $1;
- /*% ripper: rb_ary_new3(1, get_value($:1)) %*/
- }
- | f_block_optarg ',' f_block_opt
- {
- $$ = opt_arg_append($1, $3);
- /*% ripper: rb_ary_push(get_value($:1), get_value($:3)) %*/
- }
- ;
-
-f_optarg : f_opt
- {
- $$ = $1;
- /*% ripper: rb_ary_new3(1, get_value($:1)) %*/
- }
- | f_optarg ',' f_opt
- {
- $$ = opt_arg_append($1, $3);
- /*% ripper: rb_ary_push(get_value($:1), get_value($:3)) %*/
- }
- ;
-
restarg_mark : '*'
| tSTAR
;
@@ -6872,12 +6692,12 @@ f_block_arg : blkarg_mark tIDENTIFIER
opt_f_block_arg : ',' f_block_arg
{
$$ = $2;
- /*% ripper: get_value($:2); %*/
+ /*% ripper: $:2 %*/
}
| none
{
$$ = 0;
- /*% ripper: Qnil; %*/
+ /*% ripper: Qnil %*/
}
;
@@ -6927,7 +6747,7 @@ assoc_list : none
;
assocs : assoc
- /*% ripper[brace]: rb_ary_new3(1, get_value($:1)) %*/
+ /*% ripper[brace]: rb_ary_new3(1, $:1) %*/
| assocs ',' assoc
{
NODE *assocs = $1;
@@ -6949,7 +6769,7 @@ assocs : assoc
}
}
$$ = assocs;
- /*% ripper: rb_ary_push(get_value($:1), get_value($:3)) %*/
+ /*% ripper: rb_ary_push($:1, $:3) %*/
}
;
@@ -7044,10 +6864,6 @@ terms : term
none : /* none */
{
$$ = 0;
- /*%%%*/
- /*%
- set_value(rb_ripper_none);
- %*/
}
;
%%
@@ -7755,7 +7571,7 @@ yycompile0(VALUE arg)
}
}
p->ast->body.root = tree;
- if (!p->ast->body.script_lines) p->ast->body.script_lines = (rb_parser_ary_t *)INT2FIX(p->line_count);
+ p->ast->body.line_count = p->line_count;
return TRUE;
}
@@ -7788,9 +7604,9 @@ yycompile(struct parser_params *p, VALUE fname, int line)
#endif /* !RIPPER */
static rb_encoding *
-must_be_ascii_compatible(struct parser_params *p, VALUE s)
+must_be_ascii_compatible(struct parser_params *p, rb_parser_string_t *s)
{
- rb_encoding *enc = rb_enc_get(s);
+ rb_encoding *enc = rb_parser_str_get_encoding(s);
if (!rb_enc_asciicompat(enc)) {
rb_raise(rb_eArgError, "invalid source encoding");
}
@@ -7800,14 +7616,12 @@ must_be_ascii_compatible(struct parser_params *p, VALUE s)
static rb_parser_string_t *
lex_getline(struct parser_params *p)
{
- rb_parser_string_t *str;
- VALUE line = (*p->lex.gets)(p, p->lex.input, p->line_count);
- if (NIL_P(line)) return 0;
- must_be_ascii_compatible(p, line);
+ rb_parser_string_t *line = (*p->lex.gets)(p, p->lex.input, p->line_count);
+ if (!line) return 0;
p->line_count++;
- str = rb_str_to_parser_string(p, line);
- string_buffer_append(p, str);
- return str;
+ string_buffer_append(p, line);
+ must_be_ascii_compatible(p, line);
+ return line;
}
#ifndef RIPPER
@@ -8326,7 +8140,11 @@ read_escape(struct parser_params *p, int flags)
}
return read_escape(p, flags|ESCAPE_META) | 0x80;
}
- else if (c == -1 || !ISASCII(c)) goto eof;
+ else if (c == -1) goto eof;
+ else if (!ISASCII(c)) {
+ tokskip_mbchar(p);
+ goto eof;
+ }
else {
int c2 = escaped_control_code(c);
if (c2) {
@@ -8584,6 +8402,10 @@ parser_update_heredoc_indent(struct parser_params *p, int c)
}
p->heredoc_line_indent = -1;
}
+ else {
+ /* Whitespace only line has no indentation */
+ p->heredoc_line_indent = 0;
+ }
}
return FALSE;
}
@@ -8791,7 +8613,6 @@ flush_string_content(struct parser_params *p, rb_encoding *enc)
dispatch_scan_event(p, tSTRING_CONTENT);
}
-RUBY_FUNC_EXPORTED const uint_least32_t ruby_global_name_punct_bits[(0x7e - 0x20 + 31) / 32];
/* this can be shared with ripper, since it's independent from struct
* parser_params. */
#ifndef RIPPER
@@ -8839,6 +8660,7 @@ parser_peek_variable_name(struct parser_params *p)
case '{':
p->lex.pcur = ptr;
p->command_start = TRUE;
+ yylval.state = p->lex.state;
return tSTRING_DBEG;
default:
return 0;
@@ -9117,7 +8939,6 @@ heredoc_dedent(struct parser_params *p, NODE *root)
rb_parser_string_t *prev_lit = 0;
if (indent <= 0) return root;
- p->heredoc_indent = 0;
if (!root) return root;
prev_node = node = str_node = root;
@@ -9161,17 +8982,6 @@ heredoc_dedent(struct parser_params *p, NODE *root)
return root;
}
-#ifdef RIPPER
-static VALUE
-ripper_heredoc_dedent(struct parser_params *p, int indent, VALUE array)
-{
- if (indent <= 0) return array;
- p->heredoc_indent = 0;
- dispatch2(heredoc_dedent, array, INT2NUM(indent));
- return array;
-}
-#endif
-
static int
whole_match_p(struct parser_params *p, const char *eos, long len, int indent)
{
@@ -9498,71 +9308,35 @@ arg_ambiguous(struct parser_params *p, char c)
return TRUE;
}
-static ID
-formal_argument(struct parser_params *p, ID id)
+/* returns true value if formal argument error;
+ * Qtrue, or error message if ripper */
+static VALUE
+formal_argument_error(struct parser_params *p, ID id)
{
switch (id_type(id)) {
case ID_LOCAL:
break;
-#define ERR(mesg) yyerror0(mesg)
- case ID_CONST:
- ERR("formal argument cannot be a constant");
- return 0;
- case ID_INSTANCE:
- ERR("formal argument cannot be an instance variable");
- return 0;
- case ID_GLOBAL:
- ERR("formal argument cannot be a global variable");
- return 0;
- case ID_CLASS:
- ERR("formal argument cannot be a class variable");
- return 0;
- default:
- ERR("formal argument must be local variable");
- return 0;
-#undef ERR
- }
- shadowing_lvar(p, id);
-
-/*
- * Workaround for Prism::ParseTest#test_filepath for "unparser/corpus/literal/def.txt"
- *
- * See the discussion on https://github.com/ruby/ruby/pull/9923
- */
#ifndef RIPPER
- return id;
+# define ERR(mesg) (yyerror0(mesg), Qtrue)
#else
- return 0;
+# define ERR(mesg) WARN_S(mesg)
#endif
-}
-
-#ifdef RIPPER
-static void
-ripper_formal_argument(struct parser_params *p, ID id, VALUE lhs)
-{
- switch (id_type(id)) {
- case ID_LOCAL:
- break;
-#define ERR(mesg) (dispatch2(param_error, WARN_S(mesg), lhs), ripper_error(p))
case ID_CONST:
- ERR("formal argument cannot be a constant");
- return;
+ return ERR("formal argument cannot be a constant");
case ID_INSTANCE:
- ERR("formal argument cannot be an instance variable");
- return;
+ return ERR("formal argument cannot be an instance variable");
case ID_GLOBAL:
- ERR("formal argument cannot be a global variable");
- return;
+ return ERR("formal argument cannot be a global variable");
case ID_CLASS:
- ERR("formal argument cannot be a class variable");
- return;
+ return ERR("formal argument cannot be a class variable");
default:
- ERR("formal argument must be local variable");
- return;
+ return ERR("formal argument must be local variable");
#undef ERR
}
+ shadowing_lvar(p, id);
+
+ return Qfalse;
}
-#endif
static int
lvar_defined(struct parser_params *p, ID id)
@@ -10491,7 +10265,7 @@ parse_gvar(struct parser_params *p, const enum lex_state_e last_state)
case '.': /* $.: last read line number */
case '=': /* $=: ignorecase */
case ':': /* $:: load path */
- case '<': /* $<: reading filename */
+ case '<': /* $<: default input handle */
case '>': /* $>: default output handle */
case '\"': /* $": already loaded files */
tokadd(p, '$');
@@ -11221,6 +10995,7 @@ parser_yylex(struct parser_params *p)
}
if (c == '>') {
SET_LEX_STATE(EXPR_ENDFN);
+ yylval.num = p->lex.lpar_beg;
return tLAMBDA;
}
if (IS_BEG() || (IS_SPCARG(c) && arg_ambiguous(p, '-'))) {
@@ -12285,7 +12060,7 @@ rb_node_dxstr_new(struct parser_params *p, rb_parser_string_t *string, long nd_a
{
rb_node_dxstr_t *n = NODE_NEWNODE(NODE_DXSTR, rb_node_dxstr_t, loc);
n->string = string;
- n->nd_alen = nd_alen;
+ n->as.nd_alen = nd_alen;
n->nd_next = (rb_node_list_t *)nd_next;
return n;
@@ -12305,7 +12080,7 @@ rb_node_dsym_new(struct parser_params *p, rb_parser_string_t *string, long nd_al
{
rb_node_dsym_t *n = NODE_NEWNODE(NODE_DSYM, rb_node_dsym_t, loc);
n->string = string;
- n->nd_alen = nd_alen;
+ n->as.nd_alen = nd_alen;
n->nd_next = (rb_node_list_t *)nd_next;
return n;
@@ -12672,7 +12447,6 @@ static rb_node_def_temp_t *
rb_node_def_temp_new(struct parser_params *p, const YYLTYPE *loc)
{
rb_node_def_temp_t *n = NODE_NEWNODE((enum node_type)NODE_DEF_TEMP, rb_node_def_temp_t, loc);
- n->save.cur_arg = p->cur_arg;
n->save.numparam_save = 0;
n->save.max_numparam = 0;
n->save.ctxt = p->ctxt;
@@ -13203,19 +12977,11 @@ gettable(struct parser_params *p, ID id, const YYLTYPE *loc)
case ID_LOCAL:
if (dyna_in_block(p) && dvar_defined_ref(p, id, &vidp)) {
if (NUMPARAM_ID_P(id) && (numparam_nested_p(p) || it_used_p(p))) return 0;
- if (id == p->cur_arg) {
- compile_error(p, "circular argument reference - %"PRIsWARN, rb_id2str(id));
- return 0;
- }
if (vidp) *vidp |= LVAR_USED;
node = NEW_DVAR(id, loc);
return node;
}
if (local_id_ref(p, id, &vidp)) {
- if (id == p->cur_arg) {
- compile_error(p, "circular argument reference - %"PRIsWARN, rb_id2str(id));
- return 0;
- }
if (vidp) *vidp |= LVAR_USED;
node = NEW_LVAR(id, loc);
return node;
@@ -13364,15 +13130,17 @@ new_regexp(struct parser_params *p, NODE *node, int options, const YYLTYPE *loc)
case NODE_DSTR:
nd_set_type(node, NODE_DREGX);
nd_set_loc(node, loc);
- RNODE_DREGX(node)->nd_cflag = options & RE_OPTION_MASK;
- if (RNODE_DREGX(node)->string) reg_fragment_check(p, RNODE_DREGX(node)->string, options);
- for (list = RNODE_DREGX(prev = node)->nd_next; list; list = RNODE_LIST(list->nd_next)) {
+ rb_node_dregx_t *const dreg = RNODE_DREGX(node);
+ dreg->as.nd_cflag = options & RE_OPTION_MASK;
+ if (dreg->string) reg_fragment_check(p, dreg->string, options);
+ prev = node;
+ for (list = dreg->nd_next; list; list = RNODE_LIST(list->nd_next)) {
NODE *frag = list->nd_head;
enum node_type type = nd_type(frag);
if (type == NODE_STR || (type == NODE_DSTR && !RNODE_DSTR(frag)->nd_next)) {
rb_parser_string_t *tail = RNODE_STR(frag)->string;
if (reg_fragment_check(p, tail, options) && prev && RNODE_DREGX(prev)->string) {
- rb_parser_string_t *lit = prev == node ? RNODE_DREGX(prev)->string : RNODE_STR(RNODE_LIST(prev)->nd_head)->string;
+ rb_parser_string_t *lit = prev == node ? dreg->string : RNODE_STR(RNODE_LIST(prev)->nd_head)->string;
if (!literal_concat0(p, lit, tail)) {
return NEW_NIL(loc); /* dummy node on error */
}
@@ -13390,9 +13158,9 @@ new_regexp(struct parser_params *p, NODE *node, int options, const YYLTYPE *loc)
prev = 0;
}
}
- if (!RNODE_DREGX(node)->nd_next) {
+ if (!dreg->nd_next) {
/* Check string is valid regex */
- reg_compile(p, RNODE_DREGX(node)->string, options);
+ reg_compile(p, dreg->string, options);
}
if (options & RE_OPTION_ONCE) {
node = NEW_ONCE(node, loc);
@@ -13453,8 +13221,8 @@ check_literal_when(struct parser_params *p, NODE *arg, const YYLTYPE *loc)
else {
st_data_t line;
if (st_lookup(p->case_labels, (st_data_t)arg, &line)) {
- rb_warning1("duplicated 'when' clause with line %d is ignored",
- WARN_I((int)line));
+ rb_warning2("'when' clause on line %d duplicates 'when' clause on line %d and is ignored",
+ WARN_I((int)nd_line(arg)), WARN_I((int)line));
return;
}
}
@@ -13747,19 +13515,11 @@ assignable(struct parser_params *p, ID id, NODE *val, const YYLTYPE *loc)
/* TODO: FIXME */
#ifndef RIPPER
if (err) yyerror1(loc, err);
+#else
+ if (err) set_value(assign_error(p, err, p->s_lvalue));
#endif
return NEW_ERROR(loc);
}
-#ifdef RIPPER
-static VALUE
-ripper_assignable(struct parser_params *p, ID id, VALUE lhs)
-{
- const char *err = 0;
- assignable0(p, id, &err);
- if (err) lhs = assign_error(p, err, lhs);
- return lhs;
-}
-#endif
static int
is_private_local_id(struct parser_params *p, ID name)
@@ -13842,10 +13602,10 @@ aryset_check(struct parser_params *p, NODE *args)
}
}
if (kwds && nd_type_p(kwds, NODE_HASH) && !RNODE_HASH(kwds)->nd_brace) {
- yyerror1(&kwds->nd_loc, "keyword arg given in index");
+ yyerror1(&kwds->nd_loc, "keyword arg given in index assignment");
}
if (block) {
- yyerror1(&block->nd_loc, "block arg given in index");
+ yyerror1(&block->nd_loc, "block arg given in index assignment");
}
}
@@ -13871,46 +13631,23 @@ attrset(struct parser_params *p, NODE *recv, ID atype, ID id, const YYLTYPE *loc
return NEW_ATTRASGN(recv, id, 0, loc);
}
-static void
-rb_backref_error(struct parser_params *p, NODE *node)
-{
- switch (nd_type(node)) {
- case NODE_NTH_REF:
- compile_error(p, "Can't set variable $%ld", RNODE_NTH_REF(node)->nd_nth);
- break;
- case NODE_BACK_REF:
- compile_error(p, "Can't set variable $%c", (int)RNODE_BACK_REF(node)->nd_nth);
- break;
- }
-}
-
-#ifdef RIPPER
static VALUE
-defs(struct parser_params *p, VALUE head, VALUE args, VALUE bodystmt)
-{
- return dispatch5(defs,
- rb_ary_entry(head, 0), /* nd_recv */
- rb_ary_entry(head, 1), /* dot_or_colon */
- rb_ary_entry(head, 2), /* nd_mid */
- args,
- bodystmt);
-}
-
-static VALUE
-backref_error(struct parser_params *p, NODE *node, VALUE expr)
+rb_backref_error(struct parser_params *p, NODE *node)
{
- VALUE mesg = rb_str_new_cstr("Can't set variable ");
+#ifndef RIPPER
+# define ERR(...) (compile_error(p, __VA_ARGS__), Qtrue)
+#else
+# define ERR(...) rb_sprintf(__VA_ARGS__)
+#endif
switch (nd_type(node)) {
case NODE_NTH_REF:
- rb_str_catf(mesg, "$%ld", RNODE_NTH_REF(node)->nd_nth);
- break;
+ return ERR("Can't set variable $%ld", RNODE_NTH_REF(node)->nd_nth);
case NODE_BACK_REF:
- rb_str_catf(mesg, "$%c", (int)RNODE_BACK_REF(node)->nd_nth);
- break;
+ return ERR("Can't set variable $%c", (int)RNODE_BACK_REF(node)->nd_nth);
}
- return dispatch2(assign_error, mesg, expr);
+#undef ERR
+ UNREACHABLE_RETURN(Qfalse); /* only called on syntax error */
}
-#endif
static NODE *
arg_append(struct parser_params *p, NODE *node1, NODE *node2, const YYLTYPE *loc)
@@ -14484,8 +14221,18 @@ cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *l
if (!top) break;
RNODE_DOT2(node)->nd_beg = range_op(p, RNODE_DOT2(node)->nd_beg, loc);
RNODE_DOT2(node)->nd_end = range_op(p, RNODE_DOT2(node)->nd_end, loc);
- if (nd_type_p(node, NODE_DOT2)) nd_set_type(node,NODE_FLIP2);
- else if (nd_type_p(node, NODE_DOT3)) nd_set_type(node, NODE_FLIP3);
+ switch (nd_type(node)) {
+ case NODE_DOT2:
+ nd_set_type(node,NODE_FLIP2);
+ rb_node_flip2_t *flip2 = RNODE_FLIP2(node); /* for debug info */
+ (void)flip2;
+ break;
+ case NODE_DOT3:
+ nd_set_type(node, NODE_FLIP3);
+ rb_node_flip3_t *flip3 = RNODE_FLIP3(node); /* for debug info */
+ (void)flip3;
+ break;
+ }
break;
case NODE_SYM:
@@ -15051,20 +14798,16 @@ static NODE *
const_decl(struct parser_params *p, NODE *path, const YYLTYPE *loc)
{
if (p->ctxt.in_def) {
+#ifndef RIPPER
yyerror1(loc, "dynamic constant assignment");
+#else
+ set_value(assign_error(p, "dynamic constant assignment", p->s_lvalue));
+#endif
}
return NEW_CDECL(0, 0, (path), p->ctxt.shareable_constant_value, loc);
}
-#ifdef RIPPER
-static VALUE
-ripper_const_decl(struct parser_params *p, VALUE path)
-{
- if (p->ctxt.in_def) {
- path = assign_error(p, "dynamic constant assignment", path);
- }
- return path;
-}
+#ifdef RIPPER
static VALUE
assign_error(struct parser_params *p, const char *mesg, VALUE a)
{
@@ -15072,12 +14815,6 @@ assign_error(struct parser_params *p, const char *mesg, VALUE a)
ripper_error(p);
return a;
}
-
-static VALUE
-var_field(struct parser_params *p, VALUE a)
-{
- return dispatch1(var_field, a);
-}
#endif
static NODE *
@@ -15091,9 +14828,6 @@ new_bodystmt(struct parser_params *p, NODE *head, NODE *rescue, NODE *rescue_els
result = NEW_RESCUE(head, rescue, rescue_else, &rescue_loc);
nd_set_line(result, rescue->nd_loc.beg_pos.lineno);
}
- else if (rescue_else) {
- result = block_append(p, result, rescue_else);
- }
if (ensure) {
result = NEW_ENSURE(result, ensure, loc);
}
@@ -15860,6 +15594,9 @@ rb_ruby_parser_free(void *ptr)
st_free_table(p->case_labels);
}
+ xfree(p->lex.strterm);
+ p->lex.strterm = 0;
+
xfree(ptr);
}
@@ -16061,7 +15798,7 @@ rb_ruby_ripper_parse0(rb_parser_t *p)
parser_prepare(p);
p->ast = rb_ast_new();
ripper_yyparse((void*)p);
- rb_ast_dispose(p->ast);
+ rb_ast_free(p->ast);
p->ast = 0;
p->eval_tree = 0;
p->eval_tree_begin = 0;
@@ -16197,7 +15934,7 @@ count_char(const char *str, int c)
*
* "\"`class' keyword\"" => "`class' keyword"
*/
-RUBY_FUNC_EXPORTED size_t
+size_t
rb_yytnamerr(struct parser_params *p, char *yyres, const char *yystr)
{
if (*yystr == '"') {
@@ -16261,7 +15998,7 @@ rb_yytnamerr(struct parser_params *p, char *yyres, const char *yystr)
#endif
#ifdef RIPPER
-#define validate(x) ((x) = (x) == rb_ripper_none ? Qnil : x)
+#define validate(x) (void)(x)
static VALUE
ripper_dispatch0(struct parser_params *p, ID mid)