Class: Packrat::Maybe

Inherits:
GrammarElement show all
Defined in:
lib/packrat/grammar.rb

Instance Attribute Summary

Attributes inherited from GrammarElement

#hidden

Instance Method Summary collapse

Methods inherited from GrammarElement

#to_packrat_grammar_element

Constructor Details

#initialize(sub) ⇒ Maybe

Returns a new instance of Maybe.



224
225
226
# File 'lib/packrat/grammar.rb', line 224

def initialize(sub)
  @sub = sub.to_packrat_grammar_element
end

Instance Method Details

#inspectObject



231
232
233
# File 'lib/packrat/grammar.rb', line 231

def inspect
  "(#{@sub.inspect})?"
end

#parse(parser) ⇒ Object



227
228
229
230
# File 'lib/packrat/grammar.rb', line 227

def parse(parser)
  res = @sub.parse(parser)
  false == res ? nil : res
end