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.

Constant Summary collapse

MODIFIER =

Optional visibility modifier before a member, e.g. private def.

/(?:(?:public|private|protected)\s+)?/

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



19
20
21
22
23
# File 'lib/yard/parser/rbs/rbs_parser.rb', line 19

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

Instance Method Details

#enumerator ⇒ Array<Statement>

Returns top-level statements for the post-processor.

Returns:



39
40
41
# File 'lib/yard/parser/rbs/rbs_parser.rb', line 39

def enumerator
  @statements
end

#parse ⇒ RbsParser

Parses the source and returns self.

Returns:



27
28
29
30
31
# File 'lib/yard/parser/rbs/rbs_parser.rb', line 27

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

#tokenize ⇒ Object

Tokenization is not implemented for RBS.

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/yard/parser/rbs/rbs_parser.rb', line 34

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