Class: Citrus::AndPredicate
- Includes:
- Nonterminal
- Defined in:
- lib/citrus.rb
Overview
An AndPredicate is a Nonterminal that contains a rule that must match. Upon success an empty match is returned and no input is consumed. The Citrus notation is any expression preceded by an ampersand, e.g.:
&expr
Instance Attribute Summary
Attributes included from Nonterminal
Attributes included from Rule
#extension, #grammar, #label, #name
Instance Method Summary collapse
-
#exec(input, events = []) ⇒ Object
Returns an array of events for this rule on the given
input. -
#initialize(rule = '') ⇒ AndPredicate
constructor
A new instance of AndPredicate.
-
#rule ⇒ Object
Returns the Rule object this rule uses to match.
-
#to_citrus ⇒ Object
Returns the Citrus notation of this rule as a string.
Methods included from Nonterminal
Methods included from Rule
#==, #===, #default_options, #elide?, #extend_match, for, #inspect, #needs_paren?, #parse, #terminal?, #test, #to_embedded_s, #to_s
Constructor Details
#initialize(rule = '') ⇒ AndPredicate
Returns a new instance of AndPredicate.
1001 1002 1003 |
# File 'lib/citrus.rb', line 1001 def initialize(rule='') super([rule]) end |
Instance Method Details
#exec(input, events = []) ⇒ Object
Returns an array of events for this rule on the given input.
1011 1012 1013 1014 1015 1016 1017 1018 1019 |
# File 'lib/citrus.rb', line 1011 def exec(input, events=[]) if input.test(rule) events << self events << CLOSE events << 0 end events end |
#rule ⇒ Object
Returns the Rule object this rule uses to match.
1006 1007 1008 |
# File 'lib/citrus.rb', line 1006 def rule rules[0] end |
#to_citrus ⇒ Object
Returns the Citrus notation of this rule as a string.
1022 1023 1024 |
# File 'lib/citrus.rb', line 1022 def to_citrus # :nodoc: '&' + rule. end |