Skip to content

Instantly share code, notes, and snippets.

@wanabe
Last active August 11, 2019 10:11
Show Gist options
  • Select an option

  • Save wanabe/827ef88896f655cfe46631bb5cfb5d6d to your computer and use it in GitHub Desktop.

Select an option

Save wanabe/827ef88896f655cfe46631bb5cfb5d6d to your computer and use it in GitHub Desktop.
たぶん互換性を壊している(メソッド定義が primary_value にならない)
diff --git a/parse.y b/parse.y
index a6a9a4160b..4470f226a8 100644
--- a/parse.y
+++ b/parse.y
@@ -1004,7 +1004,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in
%type <node> words symbols symbol_list qwords qsymbols word_list qword_list qsym_list word
%type <node> literal numeric simple_numeric ssym dsym symbol cpath
%type <node> top_compstmt top_stmts top_stmt begin_block
-%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call
+%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary1 primary2 primary command command_call method_call
%type <node> expr_value expr_value_do arg_value primary_value fcall rel_expr pipeline
%type <node> if_tail opt_else case_body case_args cases opt_rescue exc_list exc_var opt_ensure
%type <node> args call_args opt_call_args
@@ -1025,7 +1025,7 @@ static void token_info_warn(struct parser_params *p, const char *token, token_in
%type <node> p_expr p_as p_alt p_expr_basic
%type <node> p_args p_args_head p_args_tail p_args_post p_arg
%type <node> p_value p_primitive p_variable p_var_ref p_const
-%type <node> p_kwargs p_kwarg p_kw
+%type <node> p_kwargs p_kwarg p_kw fbody
%type <id> keyword_variable user_variable sym operation operation2 operation3
%type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg f_bad_arg
%type <id> f_kwrest f_label f_arg_asgn call_op call_op2 reswords relop dot_or_colon
@@ -2564,7 +2564,7 @@ mrhs : args ',' arg_value
}
;
-primary : literal
+primary1 : literal
| strings
| xstring
| regexp
@@ -2574,6 +2574,11 @@ primary : literal
| qsymbols
| var_ref
| backref
+ {
+ /*%%%*/
+ $$ = $1;
+ /*% %*/
+ }
| tFID
{
/*%%%*/
@@ -2910,32 +2915,6 @@ primary : literal
local_pop(p);
p->in_class = $<num>1 & 1;
}
- | k_def fname
- {
- local_push(p, 0);
- $<id>$ = p->cur_arg;
- p->cur_arg = 0;
- }
- {
- $<num>$ = p->in_def;
- p->in_def = 1;
- }
- f_arglist
- bodystmt
- k_end
- {
- /*%%%*/
- NODE *body = remove_begin($6);
- reduce_nodes(p, &body);
- $$ = NEW_DEFN($2, $5, body, &@$);
- nd_set_line($$->nd_defn, @7.end_pos.lineno);
- set_line_body(body, @1.beg_pos.lineno);
- /*% %*/
- /*% ripper: def!($2, $5, $6) %*/
- local_pop(p);
- p->in_def = $<num>4 & 1;
- p->cur_arg = $<id>3;
- }
| k_def singleton dot_or_colon {SET_LEX_STATE(EXPR_FNAME);} fname
{
$<num>4 = p->in_def;
@@ -2998,7 +2977,56 @@ primary : literal
}
;
-primary_value : primary
+primary2 : k_def fname
+ {
+ local_push(p, 0);
+ $<id>$ = p->cur_arg;
+ p->cur_arg = 0;
+ }
+ {
+ $<num>$ = p->in_def;
+ p->in_def = 1;
+ }
+ f_arglist
+ fbody
+ {
+ /*%%%*/
+ $$ = NEW_DEFN($2, $5, $6, &@$);
+ nd_set_line($$->nd_defn, @6.end_pos.lineno);
+ set_line_body($6, @1.beg_pos.lineno);
+ /*% %*/
+ /*% ripper: def!($2, $5, $6) %*/
+ local_pop(p);
+ p->in_def = $<num>4 & 1;
+ p->cur_arg = $<id>3;
+ }
+ ;
+
+primary : primary1
+ | primary2
+ {
+ /*%%%*/
+ $$ = $1;
+ /*% %*/
+ }
+ ;
+
+fbody : bodystmt
+ k_end
+ {
+ /*%%%*/
+ NODE *body = remove_begin($1);
+ reduce_nodes(p, &body);
+ $$ = body;
+ /*% %*/
+ }
+ | '=' arg
+ {
+ $$ = $2;
+ }
+ ;
+
+primary_value : primary1
{
value_expr($1);
$$ = $1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment