module ANTLR3::CharacterStream

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.

Attributes

column[RW]
line[RW]

Public Instance Methods

substring(start,stop)() click to toggle source
# File lib/antlr3/streams.rb, line 263
abstract :substring