Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified endless method definition #3051

Merged
merged 3 commits into from Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 8 additions & 30 deletions parse.y
Expand Up @@ -1104,7 +1104,7 @@ static int looking_at_eol_p(struct parser_params *p);
%type <node> string_contents xstring_contents regexp_contents string_content
%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 def_name defn_head defs_head
%type <node> top_compstmt top_stmts top_stmt begin_block rassign arg_rassign
%type <node> top_compstmt top_stmts top_stmt begin_block rassign
%type <node> bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call
%type <node> expr_value expr_value_do arg_value primary_value fcall rel_expr
%type <node> if_tail opt_else case_body case_args cases opt_rescue exc_list exc_var opt_ensure
Expand All @@ -1114,7 +1114,7 @@ static int looking_at_eol_p(struct parser_params *p);
%type <node> command_rhs arg_rhs
%type <node> command_asgn mrhs mrhs_arg superclass block_call block_command
%type <node> f_block_optarg f_block_opt
%type <node> f_arglist f_arglist_opt f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs f_rest_marg
%type <node> f_arglist f_paren_args f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs f_rest_marg
%type <node> assoc_list assocs assoc undef_list backref string_dvar for_var
%type <node> block_param opt_block_param block_param_def f_opt
%type <node> f_kwarg f_kw f_block_kwarg f_block_kw
Expand Down Expand Up @@ -1195,7 +1195,6 @@ static int looking_at_eol_p(struct parser_params *p);

%nonassoc tLOWEST
%nonassoc tLBRACE_ARG
%left tASSOC

%nonassoc modifier_if modifier_unless modifier_while modifier_until keyword_in
%left keyword_or keyword_and
Expand Down Expand Up @@ -1537,19 +1536,6 @@ rassign : arg_value tASSOC lhs
}
;

arg_rassign : arg tASSOC lhs %prec tLOWEST
{
/*%%%*/
$$ = node_assign(p, $3, $1, &@$);
/*% %*/
/*% ripper: assign!($3, $1) %*/
}
| arg %prec tLOWEST
{
$$ = $1;
}
;

command_asgn : lhs '=' command_rhs
{
/*%%%*/
Expand Down Expand Up @@ -2459,7 +2445,7 @@ arg : lhs '=' arg_rhs
/*% %*/
/*% ripper: ifop!($1, $3, $6) %*/
}
| defn_head f_arglist_opt '=' arg_rassign
| defn_head f_paren_args '=' arg
{
restore_defun(p, $<node>1->nd_defn);
/*%%%*/
Expand All @@ -2468,7 +2454,7 @@ arg : lhs '=' arg_rhs
/*% ripper: def!(get_value($1), $2, $4) %*/
local_pop(p);
}
| defs_head f_arglist_opt '=' arg_rassign
| defs_head f_paren_args '=' arg
{
restore_defun(p, $<node>1->nd_defn);
/*%%%*/
Expand Down Expand Up @@ -4902,18 +4888,7 @@ superclass : '<'
}
;

f_arglist_opt : f_arglist
| /* none */
{
/*%%%*/
$$ = new_args_tail(p, Qnone, Qnone, Qnone, &@0);
$$ = new_args(p, Qnone, Qnone, Qnone, Qnone, $$, &@0);
/*% %*/
/*% ripper: Qnil %*/
}
;

f_arglist : '(' f_args rparen
f_paren_args : '(' f_args rparen
{
/*%%%*/
$$ = $2;
Expand All @@ -4937,6 +4912,9 @@ f_arglist : '(' f_args rparen
SET_LEX_STATE(EXPR_BEG);
p->command_start = TRUE;
}
;

f_arglist : f_paren_args
| {
$<ctxt>$ = p->ctxt;
p->ctxt.in_kwarg = 1;
Expand Down
9 changes: 6 additions & 3 deletions test/ruby/test_syntax.rb
Expand Up @@ -1415,11 +1415,14 @@ def test_method_call_location
end

def test_methoddef_endless
assert_valid_syntax('private def foo = 42')
assert_syntax_error('private def foo = 42', /unexpected '='/)
assert_valid_syntax('private def foo() = 42')
assert_valid_syntax('private def inc(x) = x + 1')
assert_valid_syntax('private def obj.foo = 42')
assert_syntax_error('private def obj.foo = 42', /unexpected '='/)
assert_valid_syntax('private def obj.foo() = 42')
assert_valid_syntax('private def obj.inc(x) = x + 1')
assert_valid_syntax('private def obj.inc(x) = x + 1 => @x')
eval('def self.inc(x) = x + 1 => @x')
assert_equal(:inc, @x)
end

def test_methoddef_in_cond
Expand Down