Class: ANTLR3::AST::RewriteRuleElementStream

Inherits:
Object
  • Object
show all
Extended by:
ClassMacros
Includes:
Error
Defined in:
lib/antlr3/tree.rb

Overview

Special type of stream that is used internally by tree-building and tree- rewriting parsers.

Instance Method Summary collapse

Methods included from Error

EarlyExit, FailedPredicate, MismatchedNotSet, MismatchedRange, MismatchedSet, MismatchedToken, MismatchedTreeNode, MissingToken, NoViableAlternative, RewriteCardinalityError, RewriteEarlyExit, RewriteEmptyStream, UnwantedToken

Constructor Details

#initialize(adaptor, element_description, elements = nil) ⇒ RewriteRuleElementStream


1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
# 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

Instance Method Details

#add(el) ⇒ Object


1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
# 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?Boolean


1289
1290
1291
1292
# File 'lib/antlr3/tree.rb', line 1289

def has_next?
  return( @single_element && @cursor < 1 or
         @elements && @cursor < @elements.length )
end

#next_treeObject


1276
1277
1278
1279
1280
1281
# File 'lib/antlr3/tree.rb', line 1276

def next_tree
  if @dirty or @cursor >= length && length == 1
    return dup( __next__ )
  end
  __next__
end

#resetObject


1258
1259
1260
1261
# File 'lib/antlr3/tree.rb', line 1258

def reset
  @cursor = 0
  @dirty = true
end

#sizeObject Also known as: length


1294
1295
1296
1297
1298
# File 'lib/antlr3/tree.rb', line 1294

def size
  @single_element and return 1
  @elements and return @elements.length
  return 0
end

#to_tree(el) ⇒ Object


1285
1286
1287
# File 'lib/antlr3/tree.rb', line 1285

def to_tree( el )
  return el
end