Class: Citrus::Sequence

Inherits:
Object show all
Includes:
Nonterminal
Defined in:
lib/citrus.rb

Overview

A Sequence is a Nonterminal where all rules must match. The Citrus notation is two or more expressions separated by a space, e.g.:

expr expr

Instance Attribute Summary

Attributes included from Nonterminal

#rules

Attributes included from Rule

#extension, #grammar, #label, #name

Instance Method Summary collapse

Methods included from Nonterminal

#grammar=, #initialize

Methods included from Rule

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

Instance Method Details

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

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



1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
# File 'lib/citrus.rb', line 1198

def exec(input, events=[])
  events << self

  index = events.size
  start = index - 1
  length = n = 0
  m = rules.length

  while n < m && input.exec(rules[n], events).size > index
    length += events[-1]
    index = events.size
    n += 1
  end

  if n == m
    events << CLOSE
    events << length
  else
    events.slice!(start, index)
  end

  events
end

#to_citrus ⇒ Object

Returns the Citrus notation of this rule as a string.



1223
1224
1225
# File 'lib/citrus.rb', line 1223

def to_citrus # :nodoc:
  rules.map {|r| r.to_embedded_s }.join(' ')
end