class YARD::Parser::Base

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}

@abstract @see parse @see tokenize @see enumerator @since 0.5.6

Public Class Methods

new(source, filename) click to toggle source

This default constructor does nothing. The subclass is responsible for storing the source contents and filename if they are required. @param [String] source the source contents @param [String] filename the name of the file if from disk

# File lib/yard/parser/base.rb, line 26
def initialize(source, filename) # rubocop:disable Lint/UnusedMethodArgument
  raise NotImplementedError, "invalid parser implementation"
end
parse(source, filename = nil) click to toggle source

Convenience method to create a new parser and {#parse}

# File lib/yard/parser/base.rb, line 18
def self.parse(source, filename = nil)
  new(source, filename).parse
end

Public Instance Methods

enumerator() click to toggle source

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.

@abstract @return [Array] a list of semantic tokens representing the source code

to be post-processed

@return [nil] if no post-processing should be done

# File lib/yard/parser/base.rb, line 52
def enumerator
  nil
end
parse() click to toggle source

This method should be implemented to parse the source and return itself. @abstract @return [Base] this method should return itself

# File lib/yard/parser/base.rb, line 33
def parse
  raise NotImplementedError, "#{self.class} must implement #parse"
end
tokenize() click to toggle source

This method should be implemented to tokenize given source @abstract @return [Array] a list/tree of lexical tokens

# File lib/yard/parser/base.rb, line 40
def tokenize
  raise NotImplementedError, "#{self.class} does not support tokenization"
end