Class: GhostWheel::Expression::LookAhead

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GhostWheel::Expression

#parse

Constructor Details

#initialize(expression, negate = false) ⇒ LookAhead

Returns a new instance of LookAhead.



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

def initialize(expression, negate = false)
  @expression = expression
  @negate     = negate
end

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



11
12
13
# File 'lib/ghost_wheel/expression/look_ahead.rb', line 11

def expression
  @expression
end

#negateObject (readonly) Also known as: negate?

Returns the value of attribute negate.



11
12
13
# File 'lib/ghost_wheel/expression/look_ahead.rb', line 11

def negate
  @negate
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
# File 'lib/ghost_wheel/expression/look_ahead.rb', line 28

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

#uncached_parse(scanner, cache) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ghost_wheel/expression/look_ahead.rb', line 14

def uncached_parse(scanner, cache)
  matched = nil
  scanner.transaction do
    matched = @expression.parse(scanner, cache)
    scanner.abort
  end

  if matched.is_a? FailedParseResult
    @negate ? EmptyParseResult.instance : matched
  else
    @negate ? FailedParseResult.instance : EmptyParseResult.instance
  end
end