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.



503
504
505
506
507
508
509
510
511
# File 'lib/kpeg/grammar.rb', line 503

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.



513
514
515
# File 'lib/kpeg/grammar.rb', line 513

def op
  @op
end

#tag_nameObject (readonly)

Returns the value of attribute tag_name.



513
514
515
# File 'lib/kpeg/grammar.rb', line 513

def tag_name
  @tag_name
end

Instance Method Details

#==(obj) ⇒ Object



521
522
523
524
525
526
527
528
529
530
# File 'lib/kpeg/grammar.rb', line 521

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

#inspectObject



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

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

  body << @op.inspect

  inspect_type "tag", body
end

#match(x) ⇒ Object



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

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