Method: ActiveFacts::CQL::Parser#parse_all

Defined in:
lib/activefacts/cql/parser.rb

#parse_all(input, rule_name = nil, &block) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/activefacts/cql/parser.rb', line 251

def parse_all(input, rule_name = nil, &block)
  self.root = rule_name if rule_name

  @index = 0  # Byte offset to start next parse
  @block = block
  self.consume_all_input = false
  nodes = []
  begin
    node = parse(InputProxy.new(input, context, self), :index => @index)
    unless node 
      raise failure_reason || "not all input was understood" unless @index == input.size
      return nil  # No input, or no more input
    end
    unless @vocabulary_seen || !node.ast
      @vocabulary_seen = Compiler::Vocabulary === node.ast
      raise "CQL files must begin with a vocabulary, schema or transform definition" unless @vocabulary_seen
    end
    if @block
      @block.call(node)
    else
      nodes << node
    end
  end until self.index == @input_length
  @block ? true : nodes
end