Class: KPeg::LiteralRegexp

Inherits:
Rule
  • Object
show all
Defined in:
lib/vendor/kpeg/lib/kpeg.rb

Instance Attribute Summary (collapse)

Attributes inherited from Rule

#action, #name

Instance Method Summary (collapse)

Methods inherited from Rule

#detect_tags, #inspect_type, #prune_values, #set_action, #|

Constructor Details

- (LiteralRegexp) initialize(reg)

Returns a new instance of LiteralRegexp



350
351
352
353
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 350

def initialize(reg)
  super()
  @regexp = reg
end

Instance Attribute Details

- (Object) regexp (readonly)

Returns the value of attribute regexp



355
356
357
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 355

def regexp
  @regexp
end

Instance Method Details

- (Object) ==(obj)



369
370
371
372
373
374
375
376
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 369

def ==(obj)
  case obj
  when LiteralRegexp
    @regexp == obj.regexp
  else
    super
  end
end

- (Object) inspect



378
379
380
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 378

def inspect
  inspect_type 'reg', @regexp.inspect
end

- (Object) match(x)



361
362
363
364
365
366
367
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 361

def match(x)
  if str = x.scan(@regexp)
    Match.new(self, str)
  else
    x.fail(self)
  end
end

- (Object) string



357
358
359
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 357

def string
  @regexp.source
end