Module: Citrus::Proxy

Includes:
Rule
Included in:
Alias, Super
Defined in:
lib/citrus.rb

Overview

A Proxy is a Rule that is a placeholder for another rule. It stores the name of some other rule in the grammar internally and resolves it to the actual Rule object at runtime. This lazy evaluation permits creation of Proxy objects for rules that may not yet be defined.

Instance Attribute Summary collapse

Attributes included from Rule

#extension, #grammar, #label, #name

Instance Method Summary collapse

Methods included from Rule

#==, #===, #default_options, for, #inspect, #needs_paren?, #parse, #terminal?, #test, #to_embedded_s, #to_s

Instance Attribute Details

#rule_name ⇒ Object

The name of this proxy's rule.



769
770
771
# File 'lib/citrus.rb', line 769

def rule_name
  @rule_name
end

Instance Method Details

#elide? ⇒ Boolean

Returns true if this rule should extend a match but should not appear in its event stream.

Returns:

  • (Boolean)


791
792
793
# File 'lib/citrus.rb', line 791

def elide? # :nodoc:
  rule.elide?
end

#exec(input, events = []) ⇒ Object

Returns an array of events for this rule on the given input.



777
778
779
780
781
782
783
784
785
786
787
# File 'lib/citrus.rb', line 777

def exec(input, events=[])
  index = events.size

  if input.exec(rule, events).size > index
    # Proxy objects insert themselves into the event stream in place of the
    # rule they are proxy for.
    events[index] = self
  end

  events
end

#extend_match(match) ⇒ Object

:nodoc:



795
796
797
798
799
800
# File 'lib/citrus.rb', line 795

def extend_match(match) # :nodoc:
  # Proxy objects preserve the extension of the rule they are proxy for, and
  # may also use their own extension.
  rule.extend_match(match)
  super
end

#initialize(rule_name = '<proxy>') ⇒ Object



759
760
761
# File 'lib/citrus.rb', line 759

def initialize(rule_name='<proxy>')
  self.rule_name = rule_name
end

#rule ⇒ Object

Returns the underlying Rule for this proxy.



772
773
774
# File 'lib/citrus.rb', line 772

def rule
  @rule ||= resolve!
end