Class: YARD::Parser::OrderedParser
- Inherits:
-
Object
- Object
- YARD::Parser::OrderedParser
- Defined in:
- lib/yard/parser/source_parser.rb
Overview
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.
Instance Attribute Summary collapse
-
#deferred_statements ⇒ Array<Array(Handlers::Processor, Object)>
readonly
The statements whose handlers were deferred until all files are parsed, each with the processor state to process it with.
-
#files ⇒ Array<String>
The list of remaining files to parse.
Instance Method Summary collapse
-
#deferring? ⇒ Boolean
Whether handlers can currently be deferred.
-
#initialize(global_state, files) ⇒ OrderedParser
constructor
Creates a new OrderedParser with the global state and a list of files to parse.
-
#parse ⇒ Object
Parses the remainder of the #files list, then processes any handlers that were deferred while parsing.
Constructor Details
#initialize(global_state, files) ⇒ OrderedParser
OrderedParser sets itself as the ordered_parser key on
global_state for later use in Handlers::Processor.
Creates a new OrderedParser with the global state and a list of files to parse.
42 43 44 45 46 47 48 |
# 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 |
Instance Attribute Details
#deferred_statements ⇒ Array<Array(Handlers::Processor, Object)> (readonly)
Returns the statements whose handlers were deferred until all files are parsed, each with the processor state to process it with.
32 33 34 |
# File 'lib/yard/parser/source_parser.rb', line 32 def deferred_statements @deferred_statements end |
Instance Method Details
#deferring? ⇒ Boolean
Returns 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.
81 82 83 |
# File 'lib/yard/parser/source_parser.rb', line 81 def deferring? @deferring end |
#parse ⇒ Object
Parses the remainder of the #files list, then processes any handlers that were deferred while parsing.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# 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 |