Class: GhostWheel::Expression::Optional

Inherits:
GhostWheel::Expression show all
Defined in:
lib/ghost_wheel/expression/optional.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GhostWheel::Expression

#parse

Constructor Details

#initialize(expression) ⇒ Optional

Returns a new instance of Optional.



6
7
8
# File 'lib/ghost_wheel/expression/optional.rb', line 6

def initialize(expression)
  @expression = expression
end

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



10
11
12
# File 'lib/ghost_wheel/expression/optional.rb', line 10

def expression
  @expression
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/ghost_wheel/expression/optional.rb', line 21

def ==(other)
  super and @expression == other.expression
end

#uncached_parse(scanner, cache) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/ghost_wheel/expression/optional.rb', line 12

def uncached_parse(scanner, cache)
  result = @expression.parse(scanner, cache)
  if result.is_a? FailedParseResult
    EmptyParseResult.instance
  else
    result
  end
end