Class: KPeg::CharRange

Inherits:
Operator show all
Defined in:
lib/kpeg/grammar.rb

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

#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

#finObject (readonly)

Returns the value of attribute fin.



165
166
167
# File 'lib/kpeg/grammar.rb', line 165

def fin
  @fin
end

#startObject (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

#inspectObject



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

#stringObject



167
168
169
# File 'lib/kpeg/grammar.rb', line 167

def string
  @regexp.source
end