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.
161 162 163 164 165 166 |
# File 'lib/kpeg/grammar.rb', line 161 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.
168 169 170 |
# File 'lib/kpeg/grammar.rb', line 168 def fin @fin end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
168 169 170 |
# File 'lib/kpeg/grammar.rb', line 168 def start @start end |
Instance Method Details
#==(obj) ⇒ Object
182 183 184 185 186 187 188 189 |
# File 'lib/kpeg/grammar.rb', line 182 def ==(obj) case obj when CharRange @start == obj.start and @fin == obj.fin else super end end |
#inspect ⇒ Object
191 192 193 |
# File 'lib/kpeg/grammar.rb', line 191 def inspect inspect_type 'range', "#{@start}-#{@fin}" end |
#match(x) ⇒ Object
174 175 176 177 178 179 180 |
# File 'lib/kpeg/grammar.rb', line 174 def match(x) if str = x.scan(@regexp) MatchString.new(self, str) else x.fail(self) end end |
#string ⇒ Object
170 171 172 |
# File 'lib/kpeg/grammar.rb', line 170 def string @regexp.source end |