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.



432
433
434
435
436
# File 'lib/kpeg/grammar.rb', line 432

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

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



438
439
440
# File 'lib/kpeg/grammar.rb', line 438

def arguments
  @arguments
end

#rule_nameObject (readonly)

Returns the value of attribute rule_name.



438
439
440
# File 'lib/kpeg/grammar.rb', line 438

def rule_name
  @rule_name
end

Instance Method Details

#==(obj) ⇒ Object



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

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

#inspectObject



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

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

#match(x) ⇒ Object



440
441
442
443
444
# File 'lib/kpeg/grammar.rb', line 440

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