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.



506
507
508
509
510
511
512
513
514
# File 'lib/kpeg/grammar.rb', line 506

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.



516
517
518
# File 'lib/kpeg/grammar.rb', line 516

def op
  @op
end

#tag_nameObject (readonly)

Returns the value of attribute tag_name.



516
517
518
# File 'lib/kpeg/grammar.rb', line 516

def tag_name
  @tag_name
end

Instance Method Details

#==(obj) ⇒ Object



524
525
526
527
528
529
530
531
532
533
# File 'lib/kpeg/grammar.rb', line 524

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

#inspectObject



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

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

  body << @op.inspect

  inspect_type "tag", body
end

#match(x) ⇒ Object



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

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