Skip to content

Commit

Permalink
+ emit "endless method def" as :def node. (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliabylich committed Jul 1, 2020
1 parent db3d450 commit fc32051
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions doc/AST_FORMAT.md
Expand Up @@ -829,7 +829,7 @@ Format:
Format:

~~~
(def_e :foo (args) (int 42))
(def :foo (args) (int 42))
"def foo() = 42"
~~~ keyword
~~~ name
Expand All @@ -843,7 +843,7 @@ Format:
Format:

~~~
(defs_e (self) :foo (args) (int 42))
(defs (self) :foo (args) (int 42))
"def self.foo() = 42"
~~~ keyword
~~~ name
Expand Down
4 changes: 0 additions & 4 deletions lib/parser/ast/processor.rb
Expand Up @@ -163,8 +163,6 @@ def on_def(node)
])
end

alias on_def_e on_def

def on_defs(node)
definee_node, name, args_node, body_node = *node

Expand All @@ -174,8 +172,6 @@ def on_defs(node)
])
end

alias on_defs_e on_defs

alias on_undef process_regular_node
alias on_alias process_regular_node

Expand Down
4 changes: 2 additions & 2 deletions lib/parser/builders/default.rb
Expand Up @@ -695,7 +695,7 @@ def def_method(def_t, name_t, args,

def def_endless_method(def_t, name_t, args,
assignment_t, body)
n(:def_e, [ value(name_t).to_sym, args, body ],
n(:def, [ value(name_t).to_sym, args, body ],
endless_definition_map(def_t, nil, name_t, assignment_t, body))
end

Expand All @@ -713,7 +713,7 @@ def def_endless_singleton(def_t, definee, dot_t,
assignment_t, body)
return unless validate_definee(definee)

n(:defs_e, [ definee, value(name_t).to_sym, args, body ],
n(:defs, [ definee, value(name_t).to_sym, args, body ],
endless_definition_map(def_t, dot_t, name_t, assignment_t, body))
end

Expand Down
2 changes: 1 addition & 1 deletion lib/parser/meta.rb
Expand Up @@ -16,7 +16,7 @@ module Meta
op_asgn and_asgn ensure rescue arg_expr
or_asgn back_ref nth_ref
match_with_lvasgn match_current_line
module class sclass def defs def_e defs_e undef alias args
module class sclass def defs undef alias args
cbase arg optarg restarg blockarg block_pass kwarg kwoptarg
kwrestarg kwnilarg send csend super zsuper yield block
and not or if when case while until while_post
Expand Down
14 changes: 7 additions & 7 deletions test/test_parser.rb
Expand Up @@ -9578,7 +9578,7 @@ def test_parser_bug_645

def test_endless_method
assert_parses(
s(:def_e, :foo,
s(:def, :foo,
s(:args),
s(:int, 42)),
%q{def foo() = 42},
Expand All @@ -9589,7 +9589,7 @@ def test_endless_method
SINCE_2_8)

assert_parses(
s(:def_e, :inc,
s(:def, :inc,
s(:args, s(:arg, :x)),
s(:send,
s(:lvar, :x), :+,
Expand All @@ -9602,7 +9602,7 @@ def test_endless_method
SINCE_2_8)

assert_parses(
s(:defs_e, s(:send, nil, :obj), :foo,
s(:defs, s(:send, nil, :obj), :foo,
s(:args),
s(:int, 42)),
%q{def obj.foo() = 42},
Expand All @@ -9614,7 +9614,7 @@ def test_endless_method
SINCE_2_8)

assert_parses(
s(:defs_e, s(:send, nil, :obj), :inc,
s(:defs, s(:send, nil, :obj), :inc,
s(:args, s(:arg, :x)),
s(:send,
s(:lvar, :x), :+,
Expand All @@ -9631,7 +9631,7 @@ def test_endless_method
def test_endless_method_forwarded_args_legacy
Parser::Builders::Default.emit_forward_arg = false
assert_parses(
s(:def_e, :foo,
s(:def, :foo,
s(:forward_args),
s(:send, nil, :bar,
s(:forwarded_args))),
Expand Down Expand Up @@ -9661,7 +9661,7 @@ def test_endless_method_without_brackets

def test_endless_method_with_rescue_mod
assert_parses(
s(:def_e, :m,
s(:def, :m,
s(:args),
s(:rescue,
s(:int, 1),
Expand All @@ -9672,7 +9672,7 @@ def test_endless_method_with_rescue_mod
SINCE_2_8)

assert_parses(
s(:defs_e,
s(:defs,
s(:self), :m,
s(:args),
s(:rescue,
Expand Down

0 comments on commit fc32051

Please sign in to comment.