module ANTLR3::Stream

ANTLR3 Streams

This documentation first covers the general concept of streams as used by ANTLR recognizers, and then discusses the specific ANTLR3::Stream module.

ANTLR Stream Classes

ANTLR recognizers need a way to walk through input data in a serialized IO-style fashion. They also need some book-keeping about the input to provide useful information to developers, such as current line number and column. Furthermore, to implement backtracking and various error recovery techniques, recognizers need a way to record various locations in the input at a number of points in the recognition process so the input state may be restored back to a prior state.

ANTLR bundles all of this functionality into a number of Stream classes, each designed to be used by recognizers for a specific recognition task. Most of the Stream hierarchy is implemented in antlr3/stream.rb, which is loaded by default when ‘antlr3’ is required.

Attributes

size[R]

the total number of symbols in the stream

source_name[RW]

indicates an identifying name for the stream – usually the file path of the input

Public Instance Methods

consume() click to toggle source

used to advance a stream one unit (such as character or token)

# File lib/antlr3/streams.rb, line 173
abstract :consume
index() click to toggle source

returns the current position of the stream

# File lib/antlr3/streams.rb, line 197
abstract :index
look(() click to toggle source

used to retreive the full object of interest at lookahead position specified by k (such as a character string or a token structure)

# File lib/antlr3/streams.rb, line 186
abstract :look
mark() click to toggle source

saves the current position for the purposes of backtracking and returns a value to pass to rewind at a later time

# File lib/antlr3/streams.rb, line 192
abstract :mark
peek(() click to toggle source

used to quickly retreive the object of interest to a recognizer at lookahead position specified by k (such as integer value of a character or an integer token type)

# File lib/antlr3/streams.rb, line 180
abstract :peek
release(() click to toggle source

clears the saved state information associated with the given marker value

# File lib/antlr3/streams.rb, line 208
abstract :release
rewind(() click to toggle source

restores the stream position using the state information previously saved by the given marker

# File lib/antlr3/streams.rb, line 203
abstract :rewind
seek(() click to toggle source

move the stream to the given absolute index given by position

# File lib/antlr3/streams.rb, line 213
abstract :seek