Class: YARD::Parser::Base Abstract
- Inherits:
 - 
      Object
      
        
- Object
 - YARD::Parser::Base
 
 
- Defined in:
 - lib/yard/parser/base.rb
 
Overview
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
Direct Known Subclasses
Class Method Summary collapse
- 
  
    
      .parse(source, filename = nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Convenience method to create a new parser and #parse.
 
Instance Method Summary collapse
- 
  
    
      #enumerator  ⇒ Array? 
    
    
  
  
  
  
  
  abstract
  
  
  
    
This method should be implemented to return a list of semantic tokens representing the source code to be post-processed.
 - 
  
    
      #initialize(source, filename)  ⇒ Base 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
This default constructor does nothing.
 - 
  
    
      #parse  ⇒ Base 
    
    
  
  
  
  
  
  abstract
  
  
  
    
This method should be implemented to parse the source and return itself.
 - 
  
    
      #tokenize  ⇒ Array 
    
    
  
  
  
  
  
  abstract
  
  
  
    
This method should be implemented to tokenize given source.
 
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.
      26 27 28  | 
    
      # File 'lib/yard/parser/base.rb', line 26 def initialize(source, filename) # rubocop:disable Lint/UnusedMethodArgument raise NotImplementedError, "invalid parser implementation" end  | 
  
Class Method Details
.parse(source, filename = nil) ⇒ Object
Convenience method to create a new parser and #parse
      18 19 20  | 
    
      # File 'lib/yard/parser/base.rb', line 18 def self.parse(source, filename = nil) new(source, filename).parse end  | 
  
Instance Method Details
#enumerator ⇒ Array?
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.
      52 53 54  | 
    
      # File 'lib/yard/parser/base.rb', line 52 def enumerator nil end  | 
  
#parse ⇒ Base
This method should be implemented to parse the source and return itself.
      33 34 35  | 
    
      # File 'lib/yard/parser/base.rb', line 33 def parse raise NotImplementedError, "#{self.class} must implement #parse" end  | 
  
#tokenize ⇒ Array
This method should be implemented to tokenize given source
      40 41 42  | 
    
      # File 'lib/yard/parser/base.rb', line 40 def tokenize raise NotImplementedError, "#{self.class} does not support tokenization" end  |