Class: KPeg::RuleReference
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#rule_name ⇒ Object
readonly
Returns the value of attribute rule_name.
Attributes inherited from Operator
Instance Method Summary collapse
- #==(obj) ⇒ Object
-
#initialize(name, grammar = nil, args = nil) ⇒ RuleReference
constructor
A new instance of RuleReference.
- #inspect ⇒ Object
- #match(x) ⇒ Object
Methods inherited from Operator
#detect_tags, #inspect_type, #prune_values, #set_action, #|
Constructor Details
#initialize(name, grammar = nil, args = nil) ⇒ RuleReference
Returns a new instance of RuleReference.
399 400 401 402 403 404 |
# File 'lib/kpeg/grammar.rb', line 399 def initialize(name, grammar=nil, args=nil) super() @rule_name = name @grammar = grammar @arguments = args end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
406 407 408 |
# File 'lib/kpeg/grammar.rb', line 406 def arguments @arguments end |
#rule_name ⇒ Object (readonly)
Returns the value of attribute rule_name.
406 407 408 |
# File 'lib/kpeg/grammar.rb', line 406 def rule_name @rule_name end |
Instance Method Details
#==(obj) ⇒ Object
422 423 424 425 426 427 428 429 |
# File 'lib/kpeg/grammar.rb', line 422 def ==(obj) case obj when RuleReference @rule_name == obj.rule_name and @arguments == obj.arguments else super end end |
#inspect ⇒ Object
431 432 433 434 435 436 437 438 |
# File 'lib/kpeg/grammar.rb', line 431 def inspect if @arguments body = "#{@rule_name} #{@arguments}" else body = @rule_name end inspect_type "ref", body end |
#match(x) ⇒ Object
408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/kpeg/grammar.rb', line 408 def match(x) if @grammar and @grammar != x.grammar x.switch_grammar(@grammar) do rule = @grammar.find(@rule_name) raise "Unknown rule: '#{@rule_name}'" unless rule x.apply rule end else rule = x.grammar.find(@rule_name) raise "Unknown rule: '#{@rule_name}'" unless rule x.apply rule end end |