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

Inherits:
  Base
  - Object
  - Base
  - YARD::Parser::RBS::RbsParser
  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

- #enumerator ⇒ Array<Statement>

  Top-level statements for the post-processor.

- #initialize(source, filename) ⇒ RbsParser constructor

  A new instance of RbsParser.

- #parse ⇒ RbsParser

  Parses the source and returns self.

- #tokenize ⇒ Object

  Tokenization is not implemented for RBS.

## 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

### #enumerator ⇒ `Array<Statement>`

Returns top-level statements for the post-processor.

Returns:

- (`Array<Statement>`) —

  top-level statements for the post-processor

    36
    37
    38

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

    def enumerator
      @statements
    end

### #parse ⇒ `RbsParser`

Parses the source and returns self.

Returns:

- (`RbsParser`) —

  self

    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

### #tokenize ⇒ `Object`

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