Class: Citrus::NotPredicate
- Includes:
- Nonterminal
- Defined in:
- lib/citrus.rb
Overview
A NotPredicate is a Nonterminal that contains a rule that must not match. Upon success an empty match is returned and no input is consumed. The Citrus notation is any expression preceded by an exclamation mark, 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 = '') ⇒ NotPredicate
constructor
A new instance of NotPredicate.
-
#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 = '') ⇒ NotPredicate
Returns a new instance of NotPredicate.
1036 1037 1038 |
# File 'lib/citrus.rb', line 1036 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.
1046 1047 1048 1049 1050 1051 1052 1053 1054 |
# File 'lib/citrus.rb', line 1046 def exec(input, events=[]) unless input.test(rule) events << self events << CLOSE events << 0 end events end |
#rule ⇒ Object
Returns the Rule object this rule uses to match.
1041 1042 1043 |
# File 'lib/citrus.rb', line 1041 def rule rules[0] end |
#to_citrus ⇒ Object
Returns the Citrus notation of this rule as a string.
1057 1058 1059 |
# File 'lib/citrus.rb', line 1057 def to_citrus # :nodoc: '!' + rule. end |