Class: RBS::Inline::AST::Members::RBSEmbedded

Inherits:
RBSBase
  • Object
show all
Defined in:
lib/rbs/inline/ast/members.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#location

Instance Method Summary collapse

Methods inherited from Base

#start_line

Constructor Details

#initialize(comment, annotation) ⇒ RBSEmbedded

Returns a new instance of RBSEmbedded.



561
562
563
564
565
566
# File 'lib/rbs/inline/ast/members.rb', line 561

def initialize(comment, annotation) #: void
  @comment = comment
  @annotation = annotation

  super(comment.comments[0].location)
end

Instance Attribute Details

#annotationObject (readonly)

: Annotations::Embedded



555
556
557
# File 'lib/rbs/inline/ast/members.rb', line 555

def annotation
  @annotation
end

#commentObject (readonly)

: AnnotationParser::ParsingResult



557
558
559
# File 'lib/rbs/inline/ast/members.rb', line 557

def comment
  @comment
end

Instance Method Details

#membersObject

Returns the array of ‘RBS::AST` members

Returns ‘RBS::ParsingError` when the `content` has syntax error.



572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
# File 'lib/rbs/inline/ast/members.rb', line 572

def members #: Array[RBS::AST::Members::t | RBS::AST::Declarations::t] | RBS::ParsingError
  source = <<~RBS
    module EmbeddedModuleTest
      #{annotation.content}
    end
  RBS

  _, _, decls = RBS::Parser.parse_signature(source)

  mod = decls[0]
  mod.is_a?(RBS::AST::Declarations::Module) or raise

  mod.members.each do |member|
    # Clear `@location` of each member so that new lines are inserted between members.
    # See `RBS::Writer#preserve_empty_line`.
    member.instance_variable_set(:@location, nil)
  end

rescue RBS::ParsingError => exn
  exn
end