ruby_mod_kit 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -8
- data/lib/ruby_mod_kit/cli.rb +10 -1
- data/lib/ruby_mod_kit/core_ext/eval.rb +36 -0
- data/lib/ruby_mod_kit/core_ext/load.rb +74 -0
- data/lib/ruby_mod_kit/core_ext.rb +7 -0
- data/lib/ruby_mod_kit/corrector.rb +22 -0
- data/lib/ruby_mod_kit/corrector_manager.rb +68 -0
- data/lib/ruby_mod_kit/feature/instance_variable_parameter/instance_variable_parameter_corrector.rb +42 -0
- data/lib/ruby_mod_kit/feature/instance_variable_parameter/instance_variable_parameter_mission.rb +49 -0
- data/lib/ruby_mod_kit/feature/instance_variable_parameter.rb +27 -0
- data/lib/ruby_mod_kit/feature/overload/overload_mission.rb +80 -0
- data/lib/ruby_mod_kit/feature/overload.rb +19 -0
- data/lib/ruby_mod_kit/feature/type/instance_variable_colon_corrector.rb +49 -0
- data/lib/ruby_mod_kit/feature/type/parameter_arrow_corrector.rb +90 -0
- data/lib/ruby_mod_kit/feature/type/rbs_inline/type_attr_mission.rb +41 -0
- data/lib/ruby_mod_kit/feature/type/rbs_inline/type_instance_variable_mission.rb +31 -0
- data/lib/ruby_mod_kit/feature/type/rbs_inline/type_overload_mission.rb +43 -0
- data/lib/ruby_mod_kit/feature/type/rbs_inline/type_parameter_mission.rb +38 -0
- data/lib/ruby_mod_kit/feature/type/rbs_inline/type_return_mission.rb +32 -0
- data/lib/ruby_mod_kit/feature/type/rbs_inline.rb +29 -0
- data/lib/ruby_mod_kit/feature/type/return_value_colon_corrector.rb +45 -0
- data/lib/ruby_mod_kit/feature/type/type_attr_mission.rb +67 -0
- data/lib/ruby_mod_kit/feature/type.rb +31 -0
- data/lib/ruby_mod_kit/feature.rb +24 -0
- data/lib/ruby_mod_kit/generation.rb +60 -22
- data/lib/ruby_mod_kit/memo/def_parent_memo.rb +36 -0
- data/lib/ruby_mod_kit/memo/{ivar.rb → ivar_memo.rb} +17 -3
- data/lib/ruby_mod_kit/memo/{method.rb → method_memo.rb} +7 -7
- data/lib/ruby_mod_kit/memo/offset_memo.rb +1 -1
- data/lib/ruby_mod_kit/memo/overload_memo.rb +46 -0
- data/lib/ruby_mod_kit/memo/{parameter.rb → parameter_memo.rb} +3 -3
- data/lib/ruby_mod_kit/memo.rb +7 -64
- data/lib/ruby_mod_kit/memo_pad.rb +69 -0
- data/lib/ruby_mod_kit/mission.rb +5 -24
- data/lib/ruby_mod_kit/node/base_node.rb +137 -0
- data/lib/ruby_mod_kit/node/call_node.rb +10 -6
- data/lib/ruby_mod_kit/node/def_node.rb +10 -6
- data/lib/ruby_mod_kit/node/def_parent_node.rb +41 -0
- data/lib/ruby_mod_kit/node/parameter_node.rb +12 -8
- data/lib/ruby_mod_kit/node/program_node.rb +2 -2
- data/lib/ruby_mod_kit/node/statements_node.rb +10 -6
- data/lib/ruby_mod_kit/node/symbol_node.rb +10 -6
- data/lib/ruby_mod_kit/node/untyped_node.rb +10 -6
- data/lib/ruby_mod_kit/node/wrap.rb +43 -0
- data/lib/ruby_mod_kit/node.rb +5 -149
- data/lib/ruby_mod_kit/offset_diff.rb +12 -6
- data/lib/ruby_mod_kit/version.rb +1 -1
- data/lib/ruby_mod_kit.rb +43 -11
- data/ruby_mod_kit.gemspec +1 -6
- data/sig/generated/ruby_mod_kit/core_ext/eval.rbs +17 -0
- data/sig/generated/ruby_mod_kit/core_ext/load.rbs +33 -0
- data/sig/generated/ruby_mod_kit/corrector.rbs +16 -0
- data/sig/generated/ruby_mod_kit/corrector_manager.rbs +26 -0
- data/sig/generated/ruby_mod_kit/feature/instance_variable_parameter/instance_variable_parameter_corrector.rbs +20 -0
- data/sig/generated/ruby_mod_kit/feature/instance_variable_parameter/instance_variable_parameter_mission.rbs +21 -0
- data/sig/generated/ruby_mod_kit/feature/instance_variable_parameter.rbs +14 -0
- data/sig/generated/ruby_mod_kit/feature/overload/overload_mission.rbs +24 -0
- data/sig/generated/ruby_mod_kit/feature/overload.rbs +11 -0
- data/sig/generated/ruby_mod_kit/feature/type/instance_variable_colon_corrector.rbs +20 -0
- data/sig/generated/ruby_mod_kit/feature/type/parameter_arrow_corrector.rbs +39 -0
- data/sig/generated/ruby_mod_kit/feature/type/rbs_inline/type_attr_mission.rbs +19 -0
- data/sig/generated/ruby_mod_kit/feature/type/rbs_inline/type_instance_variable_mission.rbs +19 -0
- data/sig/generated/ruby_mod_kit/feature/type/rbs_inline/type_overload_mission.rbs +19 -0
- data/sig/generated/ruby_mod_kit/feature/type/rbs_inline/type_parameter_mission.rbs +19 -0
- data/sig/generated/ruby_mod_kit/feature/type/rbs_inline/type_return_mission.rbs +19 -0
- data/sig/generated/ruby_mod_kit/feature/type/rbs_inline.rbs +13 -0
- data/sig/generated/ruby_mod_kit/feature/type/return_value_colon_corrector.rbs +20 -0
- data/sig/generated/ruby_mod_kit/feature/type/type_attr_mission.rbs +20 -0
- data/sig/generated/ruby_mod_kit/feature/type.rbs +14 -0
- data/sig/generated/ruby_mod_kit/feature.rbs +16 -0
- data/sig/generated/ruby_mod_kit/generation.rbs +25 -10
- data/sig/generated/ruby_mod_kit/memo/def_parent_memo.rbs +24 -0
- data/sig/generated/ruby_mod_kit/memo/{ivar.rbs → ivar_memo.rbs} +15 -3
- data/sig/generated/ruby_mod_kit/memo/{method.rbs → method_memo.rbs} +8 -8
- data/sig/generated/ruby_mod_kit/memo/offset_memo.rbs +1 -1
- data/sig/generated/ruby_mod_kit/memo/overload_memo.rbs +32 -0
- data/sig/generated/ruby_mod_kit/memo/{parameter.rbs → parameter_memo.rbs} +3 -3
- data/sig/generated/ruby_mod_kit/memo.rbs +2 -36
- data/sig/generated/ruby_mod_kit/memo_pad.rbs +46 -0
- data/sig/generated/ruby_mod_kit/mission.rbs +4 -12
- data/sig/generated/ruby_mod_kit/node/base_node.rbs +65 -0
- data/sig/generated/ruby_mod_kit/node/call_node.rbs +11 -6
- data/sig/generated/ruby_mod_kit/node/def_node.rbs +11 -6
- data/sig/generated/ruby_mod_kit/node/def_parent_node.rbs +31 -0
- data/sig/generated/ruby_mod_kit/node/parameter_node.rbs +13 -8
- data/sig/generated/ruby_mod_kit/node/program_node.rbs +2 -2
- data/sig/generated/ruby_mod_kit/node/statements_node.rbs +11 -6
- data/sig/generated/ruby_mod_kit/node/symbol_node.rbs +11 -6
- data/sig/generated/ruby_mod_kit/node/untyped_node.rbs +11 -6
- data/sig/generated/ruby_mod_kit/node/wrap.rbs +12 -0
- data/sig/generated/ruby_mod_kit/node.rbs +2 -58
- data/sig/generated/ruby_mod_kit/offset_diff.rbs +3 -1
- data/sig/generated/ruby_mod_kit.rbs +13 -2
- data/sig/thor.rbs +2 -0
- metadata +63 -43
- data/lib/ruby_mod_kit/memo/class.rb +0 -27
- data/lib/ruby_mod_kit/mission/fix_parse_error.rb +0 -213
- data/lib/ruby_mod_kit/mission/ivar_arg.rb +0 -42
- data/lib/ruby_mod_kit/mission/overload.rb +0 -73
- data/lib/ruby_mod_kit/mission/type_attr.rb +0 -75
- data/lib/ruby_mod_kit/mission/type_parameter.rb +0 -39
- data/lib/ruby_mod_kit/mission/type_return.rb +0 -33
- data/lib/ruby_mod_kit/node/class_node.rb +0 -37
- data/lib/ruby_mod_kit/transpiler.rb +0 -20
- data/sig/generated/examples/user.rbs +0 -60
- data/sig/generated/ruby_mod_kit/memo/class.rbs +0 -20
- data/sig/generated/ruby_mod_kit/memo/located.rbs +0 -14
- data/sig/generated/ruby_mod_kit/memo/parameter_type.rbs +0 -14
- data/sig/generated/ruby_mod_kit/mission/fix_parse_error.rbs +0 -73
- data/sig/generated/ruby_mod_kit/mission/ivar_arg.rbs +0 -19
- data/sig/generated/ruby_mod_kit/mission/overload.rbs +0 -20
- data/sig/generated/ruby_mod_kit/mission/type_attr.rbs +0 -18
- data/sig/generated/ruby_mod_kit/mission/type_parameter.rbs +0 -18
- data/sig/generated/ruby_mod_kit/mission/type_return.rbs +0 -18
- data/sig/generated/ruby_mod_kit/node/class_node.rbs +0 -29
- data/sig/generated/ruby_mod_kit/transpiler.rbs +0 -11
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rbs_inline: enabled
|
4
|
+
|
5
|
+
module RubyModKit
|
6
|
+
module Memo
|
7
|
+
# The memo for parameter type
|
8
|
+
class OverloadMemo < OffsetMemo
|
9
|
+
# @rbs @name: Symbol
|
10
|
+
# @rbs @overload_types: [[Array[String], String]]
|
11
|
+
# @rbs @offset_corrected: bool
|
12
|
+
|
13
|
+
attr_reader :name #: Symbol
|
14
|
+
attr_reader :overload_types #: [[Array[String], String]]
|
15
|
+
|
16
|
+
# @rbs offset: Integer
|
17
|
+
# @rbs name: Symbol
|
18
|
+
# @rbs return: void
|
19
|
+
def initialize(offset, name)
|
20
|
+
@name = name
|
21
|
+
@overload_types = []
|
22
|
+
@offset_corrected = false
|
23
|
+
super(offset)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @rbs root_node: Node::ProgramNode
|
27
|
+
# @rbs return: Integer
|
28
|
+
def correct_offset(root_node)
|
29
|
+
return @offset if @offset_corrected
|
30
|
+
|
31
|
+
node = root_node.def_node_at(@offset)&.prev
|
32
|
+
raise RubyModKit::Error unless node.is_a?(Node::DefNode)
|
33
|
+
|
34
|
+
@offset_corrected = true
|
35
|
+
@offset = node.offset
|
36
|
+
end
|
37
|
+
|
38
|
+
# @rbs parameter_types: Array[String]
|
39
|
+
# @rbs return_value_type: String
|
40
|
+
# @rbs return: void
|
41
|
+
def add_overload_type(parameter_types, return_value_type)
|
42
|
+
@overload_types << [parameter_types, return_value_type]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
# rbs_inline: enabled
|
4
4
|
|
5
5
|
module RubyModKit
|
6
|
-
|
6
|
+
module Memo
|
7
7
|
# The memo for parameter type
|
8
|
-
class
|
8
|
+
class ParameterMemo < OffsetMemo
|
9
9
|
# @rbs @type: String
|
10
10
|
# @rbs @ivar_parameter: bool
|
11
11
|
# @rbs @qualifier: String
|
@@ -32,7 +32,7 @@ module RubyModKit
|
|
32
32
|
# @rbs type: String
|
33
33
|
# @rbs return: void
|
34
34
|
def type=(type)
|
35
|
-
@type =
|
35
|
+
@type = RubyModKit.unify_type(type)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/lib/ruby_mod_kit/memo.rb
CHANGED
@@ -3,71 +3,14 @@
|
|
3
3
|
# rbs_inline: enabled
|
4
4
|
|
5
5
|
module RubyModKit
|
6
|
-
# The
|
7
|
-
|
8
|
-
# @rbs @classes_memo: Hash[Integer, Memo::Class]
|
9
|
-
# @rbs @methods_memo: Hash[Integer, Memo::Method]
|
10
|
-
# @rbs @parameters_memo: Hash[Integer, Memo::Parameter]
|
11
|
-
|
12
|
-
attr_reader :classes_memo #: Hash[Integer, Memo::Class]
|
13
|
-
attr_reader :methods_memo #: Hash[Integer, Memo::Method]
|
14
|
-
attr_reader :parameters_memo #: Hash[Integer, Memo::Parameter]
|
15
|
-
|
16
|
-
# @rbs return: void
|
17
|
-
def initialize
|
18
|
-
@classes_memo = {}
|
19
|
-
@methods_memo = {}
|
20
|
-
@parameters_memo = {}
|
21
|
-
end
|
22
|
-
|
23
|
-
# @rbs offset_diff: OffsetDiff
|
24
|
-
# @rbs return: void
|
25
|
-
def succ(offset_diff)
|
26
|
-
[@methods_memo, @parameters_memo, @classes_memo].each do |offset_node_memo|
|
27
|
-
new_offset_node_memo = {}
|
28
|
-
offset_node_memo.each_value do |node_memo|
|
29
|
-
node_memo.succ(offset_diff)
|
30
|
-
new_offset_node_memo[node_memo.offset] = node_memo
|
31
|
-
end
|
32
|
-
offset_node_memo.replace(new_offset_node_memo)
|
33
|
-
end
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
# @rbs class_node: Node::ClassNode
|
38
|
-
# @rbs return: Memo::Class
|
39
|
-
def class_memo(class_node)
|
40
|
-
@classes_memo[class_node.offset] ||= Memo::Class.new(class_node)
|
41
|
-
end
|
42
|
-
|
43
|
-
# @rbs def_node: Node::DefNode
|
44
|
-
# @rbs return: Memo::Method
|
45
|
-
def method_memo(def_node)
|
46
|
-
@methods_memo[def_node.offset] ||= Memo::Method.new(def_node)
|
47
|
-
end
|
48
|
-
|
49
|
-
# @rbs node: Node
|
50
|
-
# @rbs return: Memo::Parameter
|
51
|
-
def parameter_memo(node)
|
52
|
-
memo = @parameters_memo[node.offset] ||= Memo::Parameter.new(node.offset)
|
53
|
-
def_node = node.def_node_at(node.offset)
|
54
|
-
raise RubyModKit::Error unless def_node.is_a?(Node::DefNode)
|
55
|
-
|
56
|
-
method_memo(def_node).add_parameter(memo)
|
57
|
-
end
|
58
|
-
|
59
|
-
class << self
|
60
|
-
# @rbs type: String
|
61
|
-
# @rbs return: String
|
62
|
-
def unify_type(type)
|
63
|
-
type[/\A\(([^()]*)\)\z/, 1] || type
|
64
|
-
end
|
65
|
-
end
|
6
|
+
# The namespace of transpiler memo.
|
7
|
+
module Memo
|
66
8
|
end
|
67
9
|
end
|
68
10
|
|
69
11
|
require_relative "memo/offset_memo"
|
70
|
-
require_relative "memo/
|
71
|
-
require_relative "memo/
|
72
|
-
require_relative "memo/
|
73
|
-
require_relative "memo/
|
12
|
+
require_relative "memo/def_parent_memo"
|
13
|
+
require_relative "memo/ivar_memo"
|
14
|
+
require_relative "memo/method_memo"
|
15
|
+
require_relative "memo/overload_memo"
|
16
|
+
require_relative "memo/parameter_memo"
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rbs_inline: enabled
|
4
|
+
|
5
|
+
module RubyModKit
|
6
|
+
# The class for bundling memos.
|
7
|
+
class MemoPad
|
8
|
+
# @rbs @def_parents_memo: Hash[Integer, Memo::DefParentMemo]
|
9
|
+
# @rbs @methods_memo: Hash[Integer, Memo::MethodMemo]
|
10
|
+
# @rbs @parameters_memo: Hash[Integer, Memo::ParameterMemo]
|
11
|
+
# @rbs @overloads_memo: Hash[Integer, Memo::OverloadMemo]
|
12
|
+
|
13
|
+
attr_reader :def_parents_memo #: Hash[Integer, Memo::DefParentMemo]
|
14
|
+
attr_reader :methods_memo #: Hash[Integer, Memo::MethodMemo]
|
15
|
+
attr_reader :parameters_memo #: Hash[Integer, Memo::ParameterMemo]
|
16
|
+
attr_reader :overloads_memo #: Hash[Integer, Memo::OverloadMemo]
|
17
|
+
|
18
|
+
# @rbs return: void
|
19
|
+
def initialize
|
20
|
+
@def_parents_memo = {}
|
21
|
+
@methods_memo = {}
|
22
|
+
@parameters_memo = {}
|
23
|
+
@overloads_memo = {}
|
24
|
+
end
|
25
|
+
|
26
|
+
# @rbs offset_diff: OffsetDiff
|
27
|
+
# @rbs return: void
|
28
|
+
def succ(offset_diff)
|
29
|
+
[@methods_memo, @parameters_memo, @def_parents_memo, @overloads_memo].each do |offset_node_memo|
|
30
|
+
new_offset_node_memo = {}
|
31
|
+
offset_node_memo.each_value do |node_memo|
|
32
|
+
node_memo.succ(offset_diff)
|
33
|
+
new_offset_node_memo[node_memo.offset] = node_memo
|
34
|
+
end
|
35
|
+
offset_node_memo.replace(new_offset_node_memo)
|
36
|
+
end
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
# @rbs def_parent_node: Node::DefParentNode
|
41
|
+
# @rbs return: Memo::DefParentMemo
|
42
|
+
def def_parent_memo(def_parent_node)
|
43
|
+
@def_parents_memo[def_parent_node.offset] ||= Memo::DefParentMemo.new(def_parent_node)
|
44
|
+
end
|
45
|
+
|
46
|
+
# @rbs def_node: Node::DefNode
|
47
|
+
# @rbs return: Memo::MethodMemo
|
48
|
+
def method_memo(def_node)
|
49
|
+
@methods_memo[def_node.offset] ||= Memo::MethodMemo.new(def_node)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @rbs offset: Integer
|
53
|
+
# @rbs name: Symbol
|
54
|
+
# @rbs return: Memo::OverloadMemo
|
55
|
+
def overload_memo(offset, name)
|
56
|
+
@overloads_memo[offset] ||= Memo::OverloadMemo.new(offset, name)
|
57
|
+
end
|
58
|
+
|
59
|
+
# @rbs node: Node::BaseNode
|
60
|
+
# @rbs return: Memo::ParameterMemo
|
61
|
+
def parameter_memo(node)
|
62
|
+
memo = @parameters_memo[node.offset] ||= Memo::ParameterMemo.new(node.offset)
|
63
|
+
def_node = node.def_node_at(node.offset)
|
64
|
+
raise RubyModKit::Error unless def_node.is_a?(Node::DefNode)
|
65
|
+
|
66
|
+
method_memo(def_node).add_parameter(memo)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/ruby_mod_kit/mission.rb
CHANGED
@@ -3,38 +3,19 @@
|
|
3
3
|
# rbs_inline: enabled
|
4
4
|
|
5
5
|
module RubyModKit
|
6
|
-
# The class of transpiler mission.
|
6
|
+
# The base class of transpiler mission.
|
7
7
|
class Mission
|
8
|
-
# @rbs @offset: Integer
|
9
|
-
|
10
|
-
attr_accessor :offset #: Integer
|
11
|
-
|
12
|
-
# @rbs offset: Integer
|
13
|
-
# @rbs return: void
|
14
|
-
def initialize(offset)
|
15
|
-
@offset = offset
|
16
|
-
end
|
17
|
-
|
18
8
|
# @rbs _generation: Generation
|
19
|
-
# @rbs _root_node: Node
|
9
|
+
# @rbs _root_node: Node::ProgramNode
|
20
10
|
# @rbs _parse_result: Prism::ParseResult
|
21
|
-
# @rbs
|
11
|
+
# @rbs _memo_pad: MemoPad
|
22
12
|
# @rbs return: void
|
23
|
-
def perform(_generation, _root_node, _parse_result,
|
13
|
+
def perform(_generation, _root_node, _parse_result, _memo_pad)
|
24
14
|
raise RubyModKit::Error, "Unexpected type #{self.class}"
|
25
15
|
end
|
26
16
|
|
27
17
|
# @rbs offset_diff: OffsetDiff
|
28
18
|
# @rbs return: void
|
29
|
-
def succ(offset_diff)
|
30
|
-
@offset = offset_diff[@offset]
|
31
|
-
end
|
19
|
+
def succ(offset_diff); end
|
32
20
|
end
|
33
21
|
end
|
34
|
-
|
35
|
-
require_relative "mission/ivar_arg"
|
36
|
-
require_relative "mission/type_attr"
|
37
|
-
require_relative "mission/type_parameter"
|
38
|
-
require_relative "mission/type_return"
|
39
|
-
require_relative "mission/fix_parse_error"
|
40
|
-
require_relative "mission/overload"
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rbs_inline: enabled
|
4
|
+
|
5
|
+
module RubyModKit
|
6
|
+
module Node
|
7
|
+
# The class of transpile node.
|
8
|
+
class BaseNode
|
9
|
+
# @rbs @location: Prism::Location
|
10
|
+
# @rbs @children: Array[Node::BaseNode]
|
11
|
+
# @rbs @ancestors: Array[Node::BaseNode]
|
12
|
+
# @rbs @prev: Node::BaseNode | nil
|
13
|
+
|
14
|
+
attr_reader :location #: Prism::Location
|
15
|
+
attr_reader :prev #: Node::BaseNode | nil
|
16
|
+
|
17
|
+
# @rbs return: void
|
18
|
+
def initialize
|
19
|
+
@location = prism_node.location
|
20
|
+
end
|
21
|
+
|
22
|
+
# @rbs return: Array[Node::BaseNode]
|
23
|
+
def children
|
24
|
+
return @children if @children
|
25
|
+
|
26
|
+
prev = nil
|
27
|
+
@children = prism_node.child_nodes.compact.map do |prism_child_node|
|
28
|
+
prev = Node.wrap(prism_child_node, parent: self, prev: prev)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# @rbs return: Array[Node::BaseNode]
|
33
|
+
def ancestors
|
34
|
+
return @ancestors if @ancestors
|
35
|
+
|
36
|
+
parent = @parent
|
37
|
+
@ancestors = if parent
|
38
|
+
[parent] + parent.ancestors
|
39
|
+
else
|
40
|
+
[]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# @rbs return: Symbol
|
45
|
+
def name
|
46
|
+
raise(RubyModKit::Error, "Expected ParameterNode but #{self.class}:#{prism_node.inspect}")
|
47
|
+
end
|
48
|
+
|
49
|
+
# @rbs offset: Integer
|
50
|
+
# @rbs return: Node::BaseNode | nil
|
51
|
+
def node_at(offset)
|
52
|
+
return nil unless include?(offset)
|
53
|
+
|
54
|
+
child = children.find { _1.include?(offset) }
|
55
|
+
child&.node_at(offset) || self
|
56
|
+
end
|
57
|
+
|
58
|
+
# @rbs offset: Integer
|
59
|
+
# @rbs return: Node::StatementsNode | nil
|
60
|
+
def statements_node_at(offset)
|
61
|
+
node = node_at(offset) || return
|
62
|
+
[node, *node.ancestors].each { return _1 if _1.is_a?(Node::StatementsNode) }
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
|
66
|
+
# @rbs offset: Integer
|
67
|
+
# @rbs return: Node::DefNode | nil
|
68
|
+
def def_node_at(offset)
|
69
|
+
node = node_at(offset) || return
|
70
|
+
[node, *node.ancestors].each { return _1 if _1.is_a?(Node::DefNode) }
|
71
|
+
nil
|
72
|
+
end
|
73
|
+
|
74
|
+
# @rbs offset: Integer
|
75
|
+
# @rbs return: Node::ParameterNode | nil
|
76
|
+
def parameter_node_at(offset)
|
77
|
+
node = node_at(offset) || return
|
78
|
+
[node, *node.ancestors].each { return _1 if _1.is_a?(Node::ParameterNode) }
|
79
|
+
nil
|
80
|
+
end
|
81
|
+
|
82
|
+
# @rbs offset: Integer
|
83
|
+
# @rbs return: Node::DefParentNode | nil
|
84
|
+
def def_parent_node_at(offset)
|
85
|
+
node = node_at(offset) || return
|
86
|
+
[node, *node.ancestors].each { return _1 if _1.is_a?(Node::DefParentNode) }
|
87
|
+
nil
|
88
|
+
end
|
89
|
+
|
90
|
+
# @rbs offset: Integer
|
91
|
+
# @rbs return: bool
|
92
|
+
def include?(offset)
|
93
|
+
self.offset <= offset && offset <= prism_node.location.end_offset
|
94
|
+
end
|
95
|
+
|
96
|
+
# @rbs return: Prism::Node & Prism::_Node
|
97
|
+
def prism_node
|
98
|
+
raise RubyModKit::Error
|
99
|
+
end
|
100
|
+
|
101
|
+
# @rbs return: Integer
|
102
|
+
def offset
|
103
|
+
location.start_offset
|
104
|
+
end
|
105
|
+
|
106
|
+
# @rbs return: String
|
107
|
+
def inspect
|
108
|
+
str = +"#<#{self.class} "
|
109
|
+
first = true
|
110
|
+
instance_variables.each do |ivar_name|
|
111
|
+
case ivar_name
|
112
|
+
when :@children, :@ancestors, :@parent
|
113
|
+
next
|
114
|
+
end
|
115
|
+
|
116
|
+
if first
|
117
|
+
first = false
|
118
|
+
else
|
119
|
+
str << ", "
|
120
|
+
end
|
121
|
+
str << "#{ivar_name}="
|
122
|
+
value = instance_variable_get(ivar_name)
|
123
|
+
str << (
|
124
|
+
case value
|
125
|
+
when Prism::Node
|
126
|
+
"#<#{value.class} location=#{value.location.inspect}>"
|
127
|
+
else
|
128
|
+
value.inspect
|
129
|
+
end
|
130
|
+
)
|
131
|
+
end
|
132
|
+
str << ">"
|
133
|
+
str
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -3,23 +3,27 @@
|
|
3
3
|
# rbs_inline: enabled
|
4
4
|
|
5
5
|
module RubyModKit
|
6
|
-
|
6
|
+
module Node
|
7
7
|
# Transpiler method call node
|
8
|
-
class CallNode < Node
|
8
|
+
class CallNode < Node::BaseNode
|
9
9
|
# @rbs @prism_node: Prism::CallNode
|
10
10
|
# @rbs @name: Symbol
|
11
|
-
# @rbs @parent: Node
|
11
|
+
# @rbs @parent: Node::BaseNode
|
12
|
+
# @rbs @prev: Node::BaseNode | nil
|
12
13
|
|
13
14
|
attr_reader :prism_node #: Prism::CallNode
|
14
15
|
attr_reader :name #: Symbol
|
15
|
-
attr_reader :parent #: Node
|
16
|
+
attr_reader :parent #: Node::BaseNode
|
17
|
+
attr_reader :prev #: Node::BaseNode | nil
|
16
18
|
|
17
19
|
# @rbs prism_node: Prism::CallNode
|
18
|
-
# @rbs parent: Node
|
20
|
+
# @rbs parent: Node::BaseNode
|
21
|
+
# @rbs prev: Node::BaseNode | nil
|
19
22
|
# @rbs return: void
|
20
|
-
def initialize(prism_node, parent:)
|
23
|
+
def initialize(prism_node, parent:, prev: nil)
|
21
24
|
@prism_node = prism_node
|
22
25
|
@parent = parent
|
26
|
+
@prev = prev
|
23
27
|
raise RubyModKit::Error unless prism_node.is_a?(Prism::CallNode)
|
24
28
|
|
25
29
|
@name = prism_node.name.to_sym
|
@@ -3,21 +3,25 @@
|
|
3
3
|
# rbs_inline: enabled
|
4
4
|
|
5
5
|
module RubyModKit
|
6
|
-
|
6
|
+
module Node
|
7
7
|
# Transpiler program node
|
8
|
-
class DefNode < Node
|
8
|
+
class DefNode < Node::BaseNode
|
9
9
|
# @rbs @prism_node: Prism::DefNode
|
10
|
-
# @rbs @parent: Node
|
10
|
+
# @rbs @parent: Node::BaseNode
|
11
|
+
# @rbs @prev: Node::BaseNode | nil
|
11
12
|
|
12
13
|
attr_reader :prism_node #: Prism::DefNode
|
13
|
-
attr_reader :parent #: Node
|
14
|
+
attr_reader :parent #: Node::BaseNode
|
15
|
+
attr_reader :prev #: Node::BaseNode | nil
|
14
16
|
|
15
17
|
# @rbs prism_node: Prism::DefNode
|
16
|
-
# @rbs parent: Node
|
18
|
+
# @rbs parent: Node::BaseNode
|
19
|
+
# @rbs prev: Node::BaseNode | nil
|
17
20
|
# @rbs return: void
|
18
|
-
def initialize(prism_node, parent:)
|
21
|
+
def initialize(prism_node, parent:, prev: nil)
|
19
22
|
@prism_node = prism_node
|
20
23
|
@parent = parent
|
24
|
+
@prev = prev
|
21
25
|
raise RubyModKit::Error unless prism_node.is_a?(Prism::DefNode)
|
22
26
|
|
23
27
|
super()
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rbs_inline: enabled
|
4
|
+
|
5
|
+
module RubyModKit
|
6
|
+
module Node
|
7
|
+
# Transpiler program node
|
8
|
+
class DefParentNode < Node::BaseNode
|
9
|
+
# @rbs @prism_node: Prism::ClassNode | Prism::ModuleNode
|
10
|
+
# @rbs @body_node: nil | Node::StatementsNode
|
11
|
+
# @rbs @parent: Node::BaseNode
|
12
|
+
# @rbs @prev: Node::BaseNode | nil
|
13
|
+
|
14
|
+
attr_reader :prism_node #: Prism::ClassNode | Prism::ModuleNode
|
15
|
+
attr_reader :parent #: Node::BaseNode
|
16
|
+
attr_reader :prev #: Node::BaseNode | nil
|
17
|
+
|
18
|
+
# @rbs prism_node: Prism::ClassNode | Prism::ModuleNode
|
19
|
+
# @rbs parent: Node::BaseNode
|
20
|
+
# @rbs prev: Node::BaseNode | nil
|
21
|
+
# @rbs return: void
|
22
|
+
def initialize(prism_node, parent:, prev: nil)
|
23
|
+
@prism_node = prism_node
|
24
|
+
@parent = parent
|
25
|
+
@prev = prev
|
26
|
+
raise RubyModKit::Error if !prism_node.is_a?(Prism::ClassNode) && !prism_node.is_a?(Prism::ModuleNode)
|
27
|
+
|
28
|
+
super()
|
29
|
+
end
|
30
|
+
|
31
|
+
# @rbs return: nil | Node::StatementsNode
|
32
|
+
def body_node
|
33
|
+
return @body_node if defined?(@body_node)
|
34
|
+
|
35
|
+
body_node = children.find { |node| node.prism_node == @prism_node.body }
|
36
|
+
body_node = nil unless body_node.is_a?(Node::StatementsNode)
|
37
|
+
@body_node = body_node
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -3,26 +3,30 @@
|
|
3
3
|
# rbs_inline: enabled
|
4
4
|
|
5
5
|
module RubyModKit
|
6
|
-
|
6
|
+
module Node
|
7
7
|
# Transpiler program node
|
8
|
-
class ParameterNode < Node
|
8
|
+
class ParameterNode < Node::BaseNode
|
9
|
+
# @rbs @prism_node: prism_node
|
10
|
+
# @rbs @parent: Node::BaseNode
|
11
|
+
# @rbs @prev: Node::BaseNode | nil
|
12
|
+
|
9
13
|
# @rbs!
|
10
14
|
# type prism_node = Prism::RequiredParameterNode | Prism::OptionalKeywordParameterNode
|
11
15
|
# | Prism::OptionalParameterNode | Prism::RequiredKeywordParameterNode
|
12
16
|
# | Prism::RestParameterNode
|
13
17
|
|
14
|
-
# @rbs @prism_node: prism_node
|
15
|
-
# @rbs @parent: Node
|
16
|
-
|
17
18
|
attr_reader :prism_node #: prism_node
|
18
|
-
attr_reader :parent #: Node
|
19
|
+
attr_reader :parent #: Node::BaseNode
|
20
|
+
attr_reader :prev #: Node::BaseNode | nil
|
19
21
|
|
20
22
|
# @rbs prism_node: prism_node
|
21
|
-
# @rbs parent: Node
|
23
|
+
# @rbs parent: Node::BaseNode
|
24
|
+
# @rbs prev: Node::BaseNode | nil
|
22
25
|
# @rbs return: void
|
23
|
-
def initialize(prism_node, parent:)
|
26
|
+
def initialize(prism_node, parent:, prev: nil)
|
24
27
|
@prism_node = prism_node
|
25
28
|
@parent = parent
|
29
|
+
@prev = prev
|
26
30
|
case prism_node
|
27
31
|
when Prism::RequiredParameterNode, Prism::OptionalKeywordParameterNode,
|
28
32
|
Prism::OptionalParameterNode, Prism::RequiredKeywordParameterNode,
|
@@ -3,21 +3,25 @@
|
|
3
3
|
# rbs_inline: enabled
|
4
4
|
|
5
5
|
module RubyModKit
|
6
|
-
|
6
|
+
module Node
|
7
7
|
# Transpiler program node
|
8
|
-
class StatementsNode < Node
|
8
|
+
class StatementsNode < Node::BaseNode
|
9
9
|
# @rbs @prism_node: Prism::StatementsNode
|
10
|
-
# @rbs @parent: Node
|
10
|
+
# @rbs @parent: Node::BaseNode
|
11
|
+
# @rbs @prev: Node::BaseNode | nil
|
11
12
|
|
12
13
|
attr_reader :prism_node #: Prism::StatementsNode
|
13
|
-
attr_reader :parent #: Node
|
14
|
+
attr_reader :parent #: Node::BaseNode
|
15
|
+
attr_reader :prev #: Node::BaseNode | nil
|
14
16
|
|
15
17
|
# @rbs prism_node: Prism::StatementsNode
|
16
|
-
# @rbs parent: Node
|
18
|
+
# @rbs parent: Node::BaseNode
|
19
|
+
# @rbs prev: Node::BaseNode | nil
|
17
20
|
# @rbs return: void
|
18
|
-
def initialize(prism_node, parent:)
|
21
|
+
def initialize(prism_node, parent:, prev: nil)
|
19
22
|
@prism_node = prism_node
|
20
23
|
@parent = parent
|
24
|
+
@prev = prev
|
21
25
|
raise RubyModKit::Error unless prism_node.is_a?(Prism::StatementsNode)
|
22
26
|
|
23
27
|
super()
|
@@ -3,21 +3,25 @@
|
|
3
3
|
# rbs_inline: enabled
|
4
4
|
|
5
5
|
module RubyModKit
|
6
|
-
|
6
|
+
module Node
|
7
7
|
# Transpiler program node
|
8
|
-
class SymbolNode < Node
|
8
|
+
class SymbolNode < Node::BaseNode
|
9
9
|
# @rbs @prism_node: Prism::SymbolNode
|
10
|
-
# @rbs @parent: Node
|
10
|
+
# @rbs @parent: Node::BaseNode
|
11
|
+
# @rbs @prev: Node::BaseNode | nil
|
11
12
|
|
12
13
|
attr_reader :prism_node #: Prism::SymbolNode
|
13
|
-
attr_reader :parent #: Node
|
14
|
+
attr_reader :parent #: Node::BaseNode
|
15
|
+
attr_reader :prev #: Node::BaseNode | nil
|
14
16
|
|
15
17
|
# @rbs prism_node: Prism::SymbolNode
|
16
|
-
# @rbs parent: Node
|
18
|
+
# @rbs parent: Node::BaseNode
|
19
|
+
# @rbs prev: Node::BaseNode | nil
|
17
20
|
# @rbs return: void
|
18
|
-
def initialize(prism_node, parent:)
|
21
|
+
def initialize(prism_node, parent:, prev: nil)
|
19
22
|
@prism_node = prism_node
|
20
23
|
@parent = parent
|
24
|
+
@prev = prev
|
21
25
|
raise RubyModKit::Error unless prism_node.is_a?(Prism::SymbolNode)
|
22
26
|
|
23
27
|
super()
|
@@ -3,21 +3,25 @@
|
|
3
3
|
# rbs_inline: enabled
|
4
4
|
|
5
5
|
module RubyModKit
|
6
|
-
|
6
|
+
module Node
|
7
7
|
# Transpiler program node
|
8
|
-
class UntypedNode < Node
|
8
|
+
class UntypedNode < Node::BaseNode
|
9
9
|
# @rbs @prism_node: Prism::Node
|
10
|
-
# @rbs @parent: Node
|
10
|
+
# @rbs @parent: Node::BaseNode
|
11
|
+
# @rbs @prev: Node::BaseNode | nil
|
11
12
|
|
12
13
|
attr_reader :prism_node #: Prism::Node
|
13
|
-
attr_reader :parent #: Node
|
14
|
+
attr_reader :parent #: Node::BaseNode
|
15
|
+
attr_reader :prev #: Node::BaseNode | nil
|
14
16
|
|
15
17
|
# @rbs prism_node: Prism::Node
|
16
|
-
# @rbs parent: Node
|
18
|
+
# @rbs parent: Node::BaseNode
|
19
|
+
# @rbs prev: Node::BaseNode | nil
|
17
20
|
# @rbs return: void
|
18
|
-
def initialize(prism_node, parent:)
|
21
|
+
def initialize(prism_node, parent:, prev: nil)
|
19
22
|
@prism_node = prism_node
|
20
23
|
@parent = parent
|
24
|
+
@prev = prev
|
21
25
|
super()
|
22
26
|
end
|
23
27
|
end
|