Class: RBS::Inline::AST::Annotations::RBSAnnotation

Inherits:
Base
  • Object
show all
Defined in:
lib/rbs/inline/ast/annotations.rb

Overview

‘# @rbs %aa %aa …`

Instance Attribute Summary collapse

Attributes inherited from Base

#source, #tree

Instance Method Summary collapse

Constructor Details

#initialize(tree, comments) ⇒ RBSAnnotation

Returns a new instance of RBSAnnotation.



397
398
399
400
401
402
403
404
405
406
# File 'lib/rbs/inline/ast/annotations.rb', line 397

def initialize(tree, comments)
  @source = comments
  @tree = tree

  annots = tree.nth_tree!(1)
  @contents = annots.non_trivia_trees.map do |token|
    raise unless token.is_a?(Array)
    token[1]
  end
end

Instance Attribute Details

#contentsObject (readonly)

: Array



394
395
396
# File 'lib/rbs/inline/ast/annotations.rb', line 394

def contents
  @contents
end

Instance Method Details

#annotationsObject

: Array



408
409
410
411
412
# File 'lib/rbs/inline/ast/annotations.rb', line 408

def annotations #: Array[RBS::AST::Annotation]
  contents.map do |content|
    RBS::AST::Annotation.new(string: content[3..-2] || raise, location: nil)
  end
end