Class: YARD::Parser::RBS::RbsParser

Inherits:
Base
  • Object
show all
Defined in:
lib/yard/parser/rbs/rbs_parser.rb

Overview

Parses RBS (Ruby type signature) files and produces a list of Statement objects for post-processing by handlers.

RBS is Ruby’s official type signature format (introduced in Ruby 3.0). This parser handles: class/module/interface declarations, method signatures, attribute accessors, mixins, and constants.

No external gem dependencies are used; the parser is hand-written.

Instance Method Summary collapse

Constructor Details

#initialize(source, filename) ⇒ RbsParser

Returns a new instance of RbsParser.

Parameters:

  • source (String)

    source code to parse

  • filename (String)

    path to the source file



16
17
18
19
20
# File 'lib/yard/parser/rbs/rbs_parser.rb', line 16

def initialize(source, filename)
  @source   = source
  @filename = filename
  @statements = nil
end

Instance Method Details

#enumeratorArray<Statement>

Returns top-level statements for the post-processor.

Returns:



36
37
38
# File 'lib/yard/parser/rbs/rbs_parser.rb', line 36

def enumerator
  @statements
end

#parseRbsParser

Parses the source and returns self.

Returns:



24
25
26
27
28
# File 'lib/yard/parser/rbs/rbs_parser.rb', line 24

def parse
  lines = @source.lines.map { |l| l.chomp }
  @statements, = parse_body(lines, 0, false)
  self
end

#tokenizeObject

Tokenization is not implemented for RBS.

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/yard/parser/rbs/rbs_parser.rb', line 31

def tokenize
  raise NotImplementedError, "RBS parser does not support tokenization"
end