class YARD::Parser::OrderedParser
Responsible for parsing a list of files in order. The {#parse} method of this class can be called from the {SourceParser#globals} globals state list to re-enter parsing for the remainder of files in the list recursively.
Handlers that need an object from a file later in the list can be deferred (see {Handlers::Base#ensure_loaded!}). Deferred handlers are processed again once all files have been parsed.
Attributes
@return [Array<Array(Handlers::Processor, Object)>] the statements
whose handlers were deferred until all files are parsed, each with the processor state to process it with
@return [Array<String>] the list of remaining files to parse
Public Class Methods
Source
# File lib/yard/parser/source_parser.rb, line 42 def initialize(global_state, files) @global_state = global_state @files = files.dup @deferred_statements = [] @deferring = true @global_state.ordered_parser = self end
Creates a new OrderedParser with the global state and a list of files to parse.
@note OrderedParser sets itself as the ordered_parser key on
global_state for later use in {Handlers::Processor}.
@param [OpenStruct] global_state a structure containing all global
state during parsing
@param [Array<String>] files the list of files to parse
Public Instance Methods
Source
# File lib/yard/parser/source_parser.rb, line 81 def deferring? @deferring end
@return [Boolean] whether handlers can currently be deferred. Handlers
can no longer be deferred once all files have been parsed and no deferred handler could be resolved.
Source
# File lib/yard/parser/source_parser.rb, line 54 def parse until files.empty? file = files.shift log.capture("Parsing #{file}") do SourceParser.new(SourceParser.parser_type, @global_state).parse(file) end end # Process deferred statements in passes until they all complete. A # pass that ends with as many deferred as it started with made no # progress: the rest wait on objects that will never be resolved, so # they are processed one last time without deferring, which raises # their missing object errors. until @deferred_statements.empty? statements = @deferred_statements @deferred_statements = [] statements.each do |processor, statement| log.debug "Re-processing #{processor.file}:#{statement.line}..." processor.process([statement]) end @deferring = false if @deferred_statements.size >= statements.size end end
Parses the remainder of the {#files} list, then processes any handlers that were deferred while parsing.