class ANTLR3::AST::RewriteRuleElementStream
Special type of stream that is used internally by tree-building and tree- rewriting parsers.
Public Class Methods
new( adaptor, element_description, elements = nil )
click to toggle source
# File lib/antlr3/tree.rb, line 1244 def initialize( adaptor, element_description, elements = nil ) @cursor = 0 @single_element = nil @elements = nil @dirty = false @element_description = element_description @adaptor = adaptor if elements.instance_of?( Array ) @elements = elements else add( elements ) end end
Public Instance Methods
add( el )
click to toggle source
# File lib/antlr3/tree.rb, line 1263 def add( el ) return( nil ) unless el case when ! el then return( nil ) when @elements then @elements << el when @single_element.nil? then @single_element = el else @elements = [ @single_element, el ] @single_element = nil return( @elements ) end end
has_next?()
click to toggle source
# File lib/antlr3/tree.rb, line 1289 def has_next? return( @single_element && @cursor < 1 or @elements && @cursor < @elements.length ) end
next_tree()
click to toggle source
# File lib/antlr3/tree.rb, line 1276 def next_tree if @dirty or @cursor >= length && length == 1 return dup( __next__ ) end __next__ end
reset()
click to toggle source
# File lib/antlr3/tree.rb, line 1258 def reset @cursor = 0 @dirty = true end
size()
click to toggle source
# File lib/antlr3/tree.rb, line 1294 def size @single_element and return 1 @elements and return @elements.length return 0 end
Also aliased as: length
to_tree( el )
click to toggle source
# File lib/antlr3/tree.rb, line 1285 def to_tree( el ) return el end
Private Instance Methods
__next__()
click to toggle source
# File lib/antlr3/tree.rb, line 1304 def __next__ l = length case when l.zero? raise Error::RewriteEmptyStream.new( @element_description ) when @cursor >= l l == 1 and return to_tree( @single_element ) raise RewriteCardinalityError.new( @element_description ) when @single_element @cursor += 1 return( to_tree( @single_element ) ) else out = to_tree( @elements.at( @cursor ) ) @cursor += 1 return( out ) end end