Class: TDParser::ParallelParser

Inherits:
CompositeParser show all
Defined in:
lib/tdp.rb

Instance Attribute Summary

Attributes inherited from CompositeParser

#parsers

Instance Method Summary collapse

Methods inherited from CompositeParser

#==, #optimize, #same?

Methods inherited from Parser

#%, #*, #+, #-, #/, #==, #>, #>>, #do, #optimize, #parse, #peek, #same?, #to_proc, #|, #~@

Methods included from TDParser

#any_rule, #backref, #chainl, #chainr, #condition_rule, define, #empty_rule, #fail_rule, #leftrec, #none_rule, #rightrec, #rule, #stackref, #state, #token

Methods included from BufferUtils

#prepare, #recover

Constructor Details

#initialize(r1, r2) ⇒ ParallelParser

Returns a new instance of ParallelParser.



490
491
492
# File 'lib/tdp.rb', line 490

def initialize(r1, r2)
  super(r1, r2)
end

Instance Method Details

#call(tokens, buff) ⇒ Object



494
495
496
497
498
499
500
501
502
503
# File 'lib/tdp.rb', line 494

def call(tokens, buff)
  b = prepare(buff)
  if( (x = @parsers[0].call(tokens, b)).nil? )
    recover(b, tokens)
    Sequence[Sequence[nil, @parsers[1].call(tokens, buff)]]
  else
    buff.insert(0, *b)
    Sequence[Sequence[x, nil]]
  end
end

#to_sObject



505
506
507
# File 'lib/tdp.rb', line 505

def to_s()
  "(#{@parsers[0].to_s()} + #{@parsers[1].to_s()})"
end