Class: KPeg::LiteralString
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Attributes inherited from Operator
Instance Method Summary collapse
- #==(obj) ⇒ Object
-
#initialize(str) ⇒ LiteralString
constructor
A new instance of LiteralString.
- #inspect ⇒ Object
- #match(x) ⇒ Object
Methods inherited from Operator
#detect_tags, #inspect_type, #prune_values, #set_action, #|
Constructor Details
#initialize(str) ⇒ LiteralString
Returns a new instance of LiteralString.
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 (readonly)
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 |