Class: TRuby::ParserCombinator::Lazy

Inherits:
Parser
  • Object
show all
Defined in:
lib/t_ruby/parser_combinator.rb

Overview

Lazy parser (for recursive grammars)

Instance Method Summary collapse

Methods inherited from Parser

#<<, #>>, #between, #flat_map, #label, #lookahead, #many, #many1, #map, #not_followed_by, #optional, #sep_by, #sep_by1, #|

Constructor Details

#initialize(&block) ⇒ Lazy

Returns a new instance of Lazy.



214
215
216
217
# File 'lib/t_ruby/parser_combinator.rb', line 214

def initialize(&block)
  @block = block
  @parser = nil
end

Instance Method Details

#parse(input, position = 0) ⇒ Object



219
220
221
222
# File 'lib/t_ruby/parser_combinator.rb', line 219

def parse(input, position = 0)
  @parser ||= @block.call
  @parser.parse(input, position)
end