Module: ANTLR3::CharacterStream

Extended by:
ClassMacros
Includes:
Constants, Stream
Included in:
StringStream
Defined in:
lib/antlr3/streams.rb

Overview

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

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_TOKEN, ANTLR3::Constants::INVALID_TOKEN_TYPE, 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 Attribute Details

#columnObject

Returns the value of attribute column



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

def column
  @column
end

#lineObject

Returns the value of attribute line



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

def line
  @line
end