Class: Language::Atom::Maybe

Inherits:
Language::Atom show all
Defined in:
lib/language/atom.rb

Instance Method Summary collapse

Methods inherited from Language::Atom

#<<, #>>, #absent, #aka, #any, #ignore, #inspect, #maybe, #repeat, #rule, #str, #then, #|

Constructor Details

#initialize(parent:) ⇒ Maybe

Returns a new instance of Maybe.



162
163
164
# File 'lib/language/atom.rb', line 162

def initialize(parent:)
  @parent = parent
end

Instance Method Details

#parse(parser) ⇒ Object



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/language/atom.rb', line 166

def parse(parser)
  clone =
    Parser.new(
      root: self,
      input: parser.input,
      cursor: parser.cursor,
      buffer: parser.buffer
    )

  @parent.parse(clone)
rescue Parser::Interuption
else
  parser.cursor = clone.cursor
  parser.output = clone.output
end

#to_sObject



182
183
184
# File 'lib/language/atom.rb', line 182

def to_s
  @parent ? "#{@parent}.maybe" : "maybe"
end