Class: Packrat::StringLiteral

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

Overview

A StringLiteral works like a RegexpLiteral. The only reason we use a special class for it is so that we can inspect it in a more natural way (as a string instead of a Regexp).

Instance Attribute Summary collapse

Attributes inherited from GrammarElement

#hidden

Instance Method Summary collapse

Methods inherited from RegexpLiteral

#parse

Methods inherited from GrammarElement

#to_packrat_grammar_element

Constructor Details

#initialize(str) ⇒ StringLiteral

Returns a new instance of StringLiteral.



61
62
63
64
# File 'lib/packrat/grammar.rb', line 61

def initialize(str)
  super(Regexp.new(Regexp.escape(str)))
  @string = str
end

Instance Attribute Details

#stringObject (readonly)

Returns the value of attribute string.



60
61
62
# File 'lib/packrat/grammar.rb', line 60

def string
  @string
end

Instance Method Details

#inspectObject



65
# File 'lib/packrat/grammar.rb', line 65

def inspect; @string.inspect; end