Class: KPeg::LiteralString
Instance Attribute Summary collapse
Attributes inherited from Operator
#action
Instance Method Summary
collapse
Methods inherited from Operator
#detect_tags, #inspect_type, #prune_values, #set_action, #|
Constructor Details
73
74
75
76
77
|
# File 'lib/kpeg/grammar.rb', line 73
def initialize(str)
super()
@string = str
@reg = Regexp.new Regexp.quote(str)
end
|
Instance Attribute Details
#string ⇒ Object
Returns the value of attribute string.
79
80
81
|
# File 'lib/kpeg/grammar.rb', line 79
def string
@string
end
|
Instance Method Details
#==(obj) ⇒ Object
89
90
91
92
93
94
95
96
|
# File 'lib/kpeg/grammar.rb', line 89
def ==(obj)
case obj
when LiteralString
@string == obj.string
else
super
end
end
|
#inspect ⇒ Object
98
99
100
|
# File 'lib/kpeg/grammar.rb', line 98
def inspect
inspect_type 'str', @string.inspect
end
|
#match(x) ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/kpeg/grammar.rb', line 81
def match(x)
if str = x.scan(@reg)
MatchString.new(self, str)
else
x.fail(self)
end
end
|