Class: KPeg::CharRange
Instance Attribute Summary collapse
-
#fin ⇒ Object
readonly
Returns the value of attribute fin.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Attributes inherited from Operator
Instance Method Summary collapse
- #==(obj) ⇒ Object
-
#initialize(start, fin) ⇒ CharRange
constructor
A new instance of CharRange.
- #inspect ⇒ Object
- #match(x) ⇒ Object
- #string ⇒ Object
Methods inherited from Operator
#detect_tags, #inspect_type, #prune_values, #set_action, #|
Constructor Details
#initialize(start, fin) ⇒ CharRange
Returns a new instance of CharRange.
168 169 170 171 172 173 |
# File 'lib/kpeg/grammar.rb', line 168 def initialize(start, fin) super() @start = start @fin = fin @regexp = Regexp.new "[#{Regexp.quote start}-#{Regexp.quote fin}]" end |
Instance Attribute Details
#fin ⇒ Object (readonly)
Returns the value of attribute fin.
175 176 177 |
# File 'lib/kpeg/grammar.rb', line 175 def fin @fin end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
175 176 177 |
# File 'lib/kpeg/grammar.rb', line 175 def start @start end |
Instance Method Details
#==(obj) ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'lib/kpeg/grammar.rb', line 189 def ==(obj) case obj when CharRange @start == obj.start and @fin == obj.fin else super end end |
#inspect ⇒ Object
198 199 200 |
# File 'lib/kpeg/grammar.rb', line 198 def inspect inspect_type 'range', "#{@start}-#{@fin}" end |
#match(x) ⇒ Object
181 182 183 184 185 186 187 |
# File 'lib/kpeg/grammar.rb', line 181 def match(x) if str = x.scan(@regexp) MatchString.new(self, str) else x.fail(self) end end |
#string ⇒ Object
177 178 179 |
# File 'lib/kpeg/grammar.rb', line 177 def string @regexp.source end |