Class: KPeg::ForeignInvokeRule

Inherits:
Operator
  • Object
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(grammar, name, args = nil) ⇒ ForeignInvokeRule

Returns a new instance of ForeignInvokeRule.



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

def initialize(grammar, name, args=nil)
  super()
  @grammar_name = grammar
  @rule_name = name
  if !args or args.empty?
    @arguments = nil
  else
    @arguments = args
  end
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



477
478
479
# File 'lib/kpeg/grammar.rb', line 477

def arguments
  @arguments
end

#grammar_nameObject (readonly)

Returns the value of attribute grammar_name.



477
478
479
# File 'lib/kpeg/grammar.rb', line 477

def grammar_name
  @grammar_name
end

#rule_nameObject (readonly)

Returns the value of attribute rule_name.



477
478
479
# File 'lib/kpeg/grammar.rb', line 477

def rule_name
  @rule_name
end

Instance Method Details

#==(obj) ⇒ Object



485
486
487
488
489
490
491
492
493
# File 'lib/kpeg/grammar.rb', line 485

def ==(obj)
  case obj
  when ForeignInvokeRule
    @grammar_name == obj.grammar_name and \
      @rule_name == obj.rule_name and @arguments == obj.arguments
  else
    super
  end
end

#inspectObject



495
496
497
498
499
500
501
502
# File 'lib/kpeg/grammar.rb', line 495

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

#match(x) ⇒ Object



479
480
481
482
483
# File 'lib/kpeg/grammar.rb', line 479

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