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