Class: KPeg::InvokeRule

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(name, args = nil) ⇒ InvokeRule

Returns a new instance of InvokeRule.



442
443
444
445
446
# File 'lib/kpeg/grammar.rb', line 442

def initialize(name, args=nil)
  super()
  @rule_name = name
  @arguments = args
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



448
449
450
# File 'lib/kpeg/grammar.rb', line 448

def arguments
  @arguments
end

#rule_nameObject (readonly)

Returns the value of attribute rule_name.



448
449
450
# File 'lib/kpeg/grammar.rb', line 448

def rule_name
  @rule_name
end

Instance Method Details

#==(obj) ⇒ Object



456
457
458
459
460
461
462
463
# File 'lib/kpeg/grammar.rb', line 456

def ==(obj)
  case obj
  when InvokeRule
    @rule_name == obj.rule_name and @arguments == obj.arguments
  else
    super
  end
end

#inspectObject



465
466
467
468
469
470
471
472
# File 'lib/kpeg/grammar.rb', line 465

def inspect
  if @arguments
    body = "#{@rule_name} #{@arguments}"
  else
    body = @rule_name
  end
  inspect_type "invoke", body
end

#match(x) ⇒ Object



450
451
452
453
454
# File 'lib/kpeg/grammar.rb', line 450

def match(x)
  rule = x.grammar.find(@rule_name)
  raise "Unknown rule: '#{@rule_name}'" unless rule
  x.invoke rule
end