Class: GhostWheel::Expression::Literal

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from GhostWheel::Expression

#parse

Constructor Details

#initialize(literal, skip = false) ⇒ Literal

Returns a new instance of Literal.



6
7
8
9
10
11
12
13
# File 'lib/ghost_wheel/expression/literal.rb', line 6

def initialize(literal, skip = false)
  @literal = case literal
             when Regexp then literal
             when Fixnum then /#{Regexp.escape(literal.chr)}/
             else             /#{Regexp.escape(literal.to_s)}/
             end
  @skip = skip
end

Instance Attribute Details

#literalObject (readonly)

Returns the value of attribute literal.



15
16
17
# File 'lib/ghost_wheel/expression/literal.rb', line 15

def literal
  @literal
end

#skipObject (readonly) Also known as: skip?

Returns the value of attribute skip.



15
16
17
# File 'lib/ghost_wheel/expression/literal.rb', line 15

def skip
  @skip
end

Instance Method Details

#==(other) ⇒ Object



26
27
28
# File 'lib/ghost_wheel/expression/literal.rb', line 26

def ==(other)
  super and @literal.to_s == other.literal.to_s and @skip == other.skip
end

#uncached_parse(scanner, cache) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/ghost_wheel/expression/literal.rb', line 18

def uncached_parse(scanner, cache)
  if scanner.scan(@literal)
    @skip ? EmptyParseResult.instance : ParseResult.new(scanner.matched)
  else
    FailedParseResult.instance
  end
end