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.



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

#finObject (readonly)

Returns the value of attribute fin.



175
176
177
# File 'lib/kpeg/grammar.rb', line 175

def fin
  @fin
end

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

#inspectObject



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

#stringObject



177
178
179
# File 'lib/kpeg/grammar.rb', line 177

def string
  @regexp.source
end