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.



476
477
478
479
480
481
482
483
484
485
# File 'lib/kpeg/grammar.rb', line 476

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.



487
488
489
# File 'lib/kpeg/grammar.rb', line 487

def arguments
  @arguments
end

#grammar_nameObject (readonly)

Returns the value of attribute grammar_name.



487
488
489
# File 'lib/kpeg/grammar.rb', line 487

def grammar_name
  @grammar_name
end

#rule_nameObject (readonly)

Returns the value of attribute rule_name.



487
488
489
# File 'lib/kpeg/grammar.rb', line 487

def rule_name
  @rule_name
end

Instance Method Details

#==(obj) ⇒ Object



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

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



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

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

#match(x) ⇒ Object



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

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