Class: Citrus::ButPredicate
- Includes:
- Nonterminal
- Defined in:
- lib/citrus.rb
Overview
A ButPredicate is a Nonterminal that consumes all characters until its rule matches. It must match at least one character in order to succeed. The Citrus notation is any expression preceded by a tilde, e.g.:
~expr
Constant Summary collapse
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 = '') ⇒ ButPredicate
constructor
A new instance of ButPredicate.
-
#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 = '') ⇒ ButPredicate
Returns a new instance of ButPredicate.
1073 1074 1075 |
# File 'lib/citrus.rb', line 1073 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.
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
# File 'lib/citrus.rb', line 1083 def exec(input, events=[]) length = 0 until input.test(rule) len = input.exec(DOT_RULE)[-1] break unless len length += len end if length > 0 events << self events << CLOSE events << length end events end |
#rule ⇒ Object
Returns the Rule object this rule uses to match.
1078 1079 1080 |
# File 'lib/citrus.rb', line 1078 def rule rules[0] end |
#to_citrus ⇒ Object
Returns the Citrus notation of this rule as a string.
1102 1103 1104 |
# File 'lib/citrus.rb', line 1102 def to_citrus # :nodoc: '~' + rule. end |