Class: Neg::Parser::AlternativeParser

Inherits:
CompositeParser show all
Defined in:
lib/neg/parser.rb

Instance Method Summary collapse

Methods inherited from CompositeParser

#initialize

Methods inherited from SubParser

#*, #+, #-@, #[], #parse, #~

Constructor Details

This class inherits a constructor from Neg::Parser::CompositeParser

Instance Method Details

#do_parse(i, opts) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/neg/parser.rb', line 325

def do_parse(i, opts)

  results = []

  @children.each { |c|
    results << c.parse(i, opts)
    break if results.last[2]
  }

  results = results[-1, 1] if results.last[2] && ! opts[:noreduce]

  [ results.last[2], nil, results ]
end

#to_s(parent = nil) ⇒ Object



339
340
341
342
# File 'lib/neg/parser.rb', line 339

def to_s(parent=nil)

  "(#{@children.collect { |c| c.to_s(self) }.join(' | ')})"
end

#|(pa) ⇒ Object



318
319
320
321
322
323
# File 'lib/neg/parser.rb', line 318

def |(pa)

  @children << pa

  self
end