Class: KPeg::Tag

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(op, tag_name) ⇒ Tag

Returns a new instance of Tag.



516
517
518
519
520
521
522
523
524
# File 'lib/kpeg/grammar.rb', line 516

def initialize(op, tag_name)
  super()
  if op.kind_of? Multiple
    op.save_values!
  end

  @op = op
  @tag_name = tag_name
end

Instance Attribute Details

#opObject (readonly)

Returns the value of attribute op.



526
527
528
# File 'lib/kpeg/grammar.rb', line 526

def op
  @op
end

#tag_nameObject (readonly)

Returns the value of attribute tag_name.



526
527
528
# File 'lib/kpeg/grammar.rb', line 526

def tag_name
  @tag_name
end

Instance Method Details

#==(obj) ⇒ Object



534
535
536
537
538
539
540
541
542
543
# File 'lib/kpeg/grammar.rb', line 534

def ==(obj)
  case obj
  when Tag
    @op == obj.op and @tag_name == obj.tag_name
  when Operator
    @op == obj
  else
    super
  end
end

#inspectObject



545
546
547
548
549
550
551
552
553
554
555
# File 'lib/kpeg/grammar.rb', line 545

def inspect
  if @tag_name
    body = "@#{tag_name} "
  else
    body = ""
  end

  body << @op.inspect

  inspect_type "tag", body
end

#match(x) ⇒ Object



528
529
530
531
532
# File 'lib/kpeg/grammar.rb', line 528

def match(x)
  if m = @op.match(x)
    MatchComposition.new(self, [m])
  end
end