Class: YARD::Parser::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/yard/parser/base.rb

Overview

This class is abstract.

Represents the abstract base parser class that parses source code in a specific way. A parser should implement #parse, #tokenize and #enumerator.

Registering a Custom Parser

To register a parser, see SourceParser.register_parser_type

See Also:

Since:

  • 0.5.6

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, filename) ⇒ Base

This default constructor does nothing. The subclass is responsible for storing the source contents and filename if they are required.

Raises:

  • (NotImplementedError)

Since:

  • 0.5.6



25
26
27
# File 'lib/yard/parser/base.rb', line 25

def initialize(source, filename)
  raise NotImplementedError, "invalid parser implementation"
end

Class Method Details

.parse(source, filename = nil) ⇒ Object

Convenience method to create a new parser and #parse

Since:

  • 0.5.6



17
18
19
# File 'lib/yard/parser/base.rb', line 17

def self.parse(source, filename = nil)
  new(source, filename).parse
end

Instance Method Details

#enumeratorArray?

This method is abstract.

This method should be implemented to return a list of semantic tokens representing the source code to be post-processed. Otherwise the method should return nil.

Since:

  • 0.5.6



51
52
53
# File 'lib/yard/parser/base.rb', line 51

def enumerator
  nil
end

#parseBase

This method is abstract.

This method should be implemented to parse the source and return itself.

Raises:

  • (NotImplementedError)

Since:

  • 0.5.6



32
33
34
# File 'lib/yard/parser/base.rb', line 32

def parse
  raise NotImplementedError, "#{self.class} must implement #parse"
end

#tokenizeArray

This method is abstract.

This method should be implemented to tokenize given source

Raises:

  • (NotImplementedError)

Since:

  • 0.5.6



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

def tokenize
  raise NotImplementedError, "#{self.class} does not support tokenization"
end