Sha256: 12ab42178d5e3f23320a01c6ac856610841504d6991d26f8c3904b2743b1095a

Contents?: true

Size: 1.94 KB

Versions: 63

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true
module YARD
  module Parser
    # 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
    class Base
      # Convenience method to create a new parser and {#parse}
      def self.parse(source, filename = nil)
        new(source, filename).parse
      end

      # 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
      def initialize(source, filename) # rubocop:disable Lint/UnusedMethodArgument
        raise NotImplementedError, "invalid parser implementation"
      end

      # This method should be implemented to parse the source and return itself.
      # @abstract
      # @return [Base] this method should return itself
      def parse
        raise NotImplementedError, "#{self.class} must implement #parse"
      end

      # This method should be implemented to tokenize given source
      # @abstract
      # @return [Array] a list/tree of lexical tokens
      def tokenize
        raise NotImplementedError, "#{self.class} does not support tokenization"
      end

      # 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
      def enumerator
        nil
      end
    end
  end
end

Version data entries

63 entries across 62 versions & 9 rubygems

Version Path
kinetic_sdk-5.0.29 gems/yard-0.9.36/lib/yard/parser/base.rb
kinetic_sdk-5.0.28 gems/yard-0.9.36/lib/yard/parser/base.rb
direct7-0.0.18 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/parser/base.rb
direct7-0.0.17 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/parser/base.rb
direct7-0.0.16 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/parser/base.rb
yard-0.9.37 lib/yard/parser/base.rb
kinetic_sdk-5.0.27 gems/yard-0.9.36/lib/yard/parser/base.rb
kinetic_sdk-5.0.26 gems/yard-0.9.36/lib/yard/parser/base.rb
kinetic_sdk-5.0.25 gems/yard-0.9.25/lib/yard/parser/base.rb
kinetic_sdk-5.0.24 gems/yard-0.9.25/lib/yard/parser/base.rb
direct7-0.0.13 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/parser/base.rb
yard-0.9.36 lib/yard/parser/base.rb
yard-0.9.35 lib/yard/parser/base.rb
direct7-0.0.12 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/parser/base.rb
kinetic_sdk-5.0.23 gems/yard-0.9.25/lib/yard/parser/base.rb
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/yard-0.9.34/lib/yard/parser/base.rb
direct7-0.0.11 vendor/bundle/ruby/2.7.0/gems/yard-0.9.34/lib/yard/parser/base.rb
kinetic_sdk-5.0.22 gems/yard-0.9.25/lib/yard/parser/base.rb
kinetic_sdk-5.0.21 gems/yard-0.9.25/lib/yard/parser/base.rb
yard-0.9.34 lib/yard/parser/base.rb