Class: BELParser::ASTGenerator
- Inherits:
-
Object
- Object
- BELParser::ASTGenerator
- Includes:
- LineContinuator, LineMapping
- Defined in:
- lib/bel_parser/ast_generator.rb
Overview
ASTGenerator yields AST results for each line in some IO. See ##each.
Constant Summary collapse
- PARSERS =
[ map_const.call(BELParser::Parsers::Common), map_const.call(BELParser::Parsers::Expression), map_const.call(BELParser::Parsers::BELScript) ].flatten!
Constants included from LineContinuator
LineContinuator::LINE_CONTINUATOR
Instance Method Summary collapse
-
#each ⇒ IO, #<Enumerator: #<BELParser::ASTGenerator#each
Yields AST results for each line of the IO.
-
#initialize(io) ⇒ ASTGenerator
constructor
A new instance of ASTGenerator.
Methods included from LineContinuator
Methods included from LineMapping
#map_lines, #normalize_line_terminator
Constructor Details
#initialize(io) ⇒ ASTGenerator
Returns a new instance of ASTGenerator.
21 22 23 |
# File 'lib/bel_parser/ast_generator.rb', line 21 def initialize(io) @io = io end |
Instance Method Details
#each ⇒ IO, #<Enumerator: #<BELParser::ASTGenerator#each
Yields AST results for each line of the IO.
- [Integer, String, Array<AST::Node>]
-
yields line number, line,
and AST results as an {Array}
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/bel_parser/ast_generator.rb', line 49 def each # rubocop:disable MethodLength if block_given? line_enumerator = map_lines(@io.each_line.lazy) line_number = 1 loop do begin line = (line_enumerator) ast_results = [] PARSERS.map do |parser| parser.parse(line) { |ast| ast_results << ast } end yield [line_number, line, ast_results] line_number += 1 rescue StopIteration return end end else enum_for(:each) end end |