Class: KPeg::Choice

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

- (Choice) initialize(*many)

Returns a new instance of Choice



420
421
422
423
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 420

def initialize(*many)
  super()
  @rules = many
end

Instance Attribute Details

- (Object) rules (readonly)

Returns the value of attribute rules



425
426
427
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 425

def rules
  @rules
end

Instance Method Details

- (Object) ==(obj)



446
447
448
449
450
451
452
453
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 446

def ==(obj)
  case obj
  when Choice
    @rules == obj.rules
  else
    super
  end
end

- (Object) inspect



455
456
457
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 455

def inspect
  inspect_type "any", @rules.map { |i| i.inspect }.join(' | ')
end

- (Object) match(x)



432
433
434
435
436
437
438
439
440
441
442
443
444
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 432

def match(x)
  pos = x.pos

  @rules.each do |c|
    if m = c.match(x)
      return m
    end

    x.pos = pos
  end

  return nil
end

- (Object) |(other)



427
428
429
430
# File 'lib/vendor/kpeg/lib/kpeg.rb', line 427

def |(other)
  @rules << Grammar.resolve(other)
  self
end