Method: Grammar::Ruby#redirect

Defined in:
lib/grammar/ruby.rb

#redirect(gram, buf0, &block) ⇒ Object

:yield: buf[, engine]



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/grammar/ruby.rb', line 522

def redirect(gram, buf0, &block) # :yield: buf[, engine]
    @consume or return(gram[self])
    output = @output
    consume = @consume
    @followed += 1 if block_given?
    Code::Local.new { |buf|
        begin
            @output = buf
            @consume = true
            output_init = self[buf0,true]
            if @failure
                @output._assign(output_init)._step(gram[self])
            else
                @output_init = output_init
                gram[self]
            end
        ensure
            @followed -= 1 if block_given?
            @output = output
            @consume = consume
        end._and {
            !block_given? ? Code::True :
            (@output_init ? (@output._assign(@output_init)) : Code::True).
            _step(Code::Always.new(
                block.arity==1 ? yield(buf) : yield(buf, self)
            ))
        }
    }
end