Class: Citrus::Choice
Overview
A Choice is a Nonterminal where only one rule must match. The Citrus notation is two or more expressions separated by a vertical bar, e.g.:
expr | expr
Instance Attribute Summary
Attributes included from Nonterminal
Attributes included from Rule
#extension, #grammar, #label, #name
Instance Method Summary collapse
-
#elide? ⇒ Boolean
Returns
trueif this rule should extend a match but should not appear in its event stream. -
#exec(input, events = []) ⇒ Object
Returns an array of events for this rule on the given
input. -
#to_citrus ⇒ Object
Returns the Citrus notation of this rule as a string.
Methods included from Nonterminal
Methods included from Rule
#==, #===, #default_options, #extend_match, for, #inspect, #needs_paren?, #parse, #terminal?, #test, #to_embedded_s, #to_s
Instance Method Details
#elide? ⇒ Boolean
Returns true if this rule should extend a match but should not appear in
its event stream.
1260 1261 1262 |
# File 'lib/citrus.rb', line 1260 def elide? # :nodoc: true end |
#exec(input, events = []) ⇒ Object
Returns an array of events for this rule on the given input.
1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 |
# File 'lib/citrus.rb', line 1237 def exec(input, events=[]) events << self index = events.size n = 0 m = rules.length while n < m && input.exec(rules[n], events).size == index n += 1 end if index < events.size events << CLOSE events << events[-2] else events.pop end events end |
#to_citrus ⇒ Object
Returns the Citrus notation of this rule as a string.
1265 1266 1267 |
# File 'lib/citrus.rb', line 1265 def to_citrus # :nodoc: rules.map {|r| r. }.join(' | ') end |