Skip to content

Commit d9b2ecd

Browse files
committed
Add InstanceVariableAnnotation
1 parent de00641 commit d9b2ecd

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

lib/rbs/ast/ruby/annotations.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,31 @@ def map_type_name(&block)
136136
) #: self
137137
end
138138
end
139+
140+
class InstanceVariableAnnotation < Base
141+
attr_reader :ivar_name, :ivar_name_location, :colon_location, :type, :comment_location
142+
143+
def initialize(location:, prefix_location:, ivar_name:, ivar_name_location:, colon_location:, type:, comment_location:)
144+
super(location, prefix_location)
145+
@ivar_name = ivar_name
146+
@ivar_name_location = ivar_name_location
147+
@colon_location = colon_location
148+
@type = type
149+
@comment_location = comment_location
150+
end
151+
152+
def map_type_name(&block)
153+
self.class.new(
154+
location:,
155+
prefix_location:,
156+
ivar_name:,
157+
ivar_name_location:,
158+
colon_location:,
159+
type: type.map_type_name { yield _1 },
160+
comment_location:
161+
) #: self
162+
end
163+
end
139164
end
140165
end
141166
end

sig/ast/ruby/annotations.rbs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module RBS
66
| MethodTypesAnnotation
77
| SkipAnnotation
88
| ReturnTypeAnnotation
9+
| InstanceVariableAnnotation
910

1011
type trailing_annotation = NodeTypeAssertion
1112
| TypeApplicationAnnotation
@@ -132,6 +133,39 @@ module RBS
132133

133134
def map_type_name: () { (TypeName) -> TypeName } -> self
134135
end
136+
137+
# `@rbs IVAR-NAME : TYPE` annotation in leading comments
138+
#
139+
# ```
140+
# @rbs @foo : String -- comment
141+
# ^^^^ -- prefix_location
142+
# ^^^^ -- ivar_name_location
143+
# ^ -- colon_location
144+
# ^^^^^^^^^^ -- comment_location
145+
# ```
146+
class InstanceVariableAnnotation < Base
147+
attr_reader ivar_name: Symbol
148+
149+
attr_reader ivar_name_location: Location
150+
151+
attr_reader colon_location: Location
152+
153+
attr_reader type: Types::t
154+
155+
attr_reader comment_location: Location?
156+
157+
def initialize: (
158+
location: Location,
159+
prefix_location: Location,
160+
ivar_name: Symbol,
161+
ivar_name_location: Location,
162+
colon_location: Location,
163+
type: Types::t,
164+
comment_location: Location?,
165+
) -> void
166+
167+
def map_type_name: () { (TypeName) -> TypeName } -> self
168+
end
135169
end
136170
end
137171
end

0 commit comments

Comments
 (0)