Module: ANTLR3::CharacterStream

Extended by:
Constants, Stream
Included in:
Defined in:


CharacterStream further extends the abstract-ish base mixin Stream to add methods specific to navigating character-based input data. Thus, it serves as an immitation of the Java interface for text-based streams, which are primarily used by lexers.

It adds the “abstract'' method, substring(start, stop), which must be implemented to return a slice of the input string from position start to position stop. It also adds attribute accessor methods line and column, which are expected to indicate the current line number and position within the current line, respectively.

A Word About line and column attributes

Presumably, the concept of line and column attirbutes of text are familliar to most developers. Line numbers of text are indexed from number 1 up (not 0). Column numbers are indexed from 0 up. Thus, examining sample text:

Hey this is the first line.
Oh, and this is the second line.

Line 1 is the string “Hey this is the first line\n”. If a character stream is at line 2, character 0, the stream cursor is sitting between the characters “\n” and “O”.

Note: most ANTLR runtime APIs for other languages refer to column with the more-precise, but lengthy name charPositionInLine. I prefered to keep it simple and familliar in this Ruby runtime API.

Constant Summary

Constants included from Constants

ANTLR3::Constants::BUILT_IN_TOKEN_NAMES, ANTLR3::Constants::DEFAULT, ANTLR3::Constants::DOWN, ANTLR3::Constants::EOF, ANTLR3::Constants::EOF_TOKEN, ANTLR3::Constants::EOR_TOKEN_TYPE, ANTLR3::Constants::HIDDEN, ANTLR3::Constants::INVALID, ANTLR3::Constants::INVALID_TOKEN, ANTLR3::Constants::MEMO_RULE_FAILED, ANTLR3::Constants::MEMO_RULE_UNKNOWN, ANTLR3::Constants::MIN_TOKEN_TYPE, ANTLR3::Constants::SKIP_TOKEN, ANTLR3::Constants::UP

Instance Attribute Summary collapse

Attributes included from Stream

#size, #source_name

Instance Method Summary collapse

Methods included from Stream

#consume, #index, #look, #mark, #peek, #release, #rewind, #seek

Instance Attribute Details


Returns the value of attribute column

# File 'lib/antlr3/streams.rb', line 266

def column


Returns the value of attribute line

# File 'lib/antlr3/streams.rb', line 265

def line

Instance Method Details


:method: substring(start,stop)

# File 'lib/antlr3/streams.rb', line 263

abstract :substring