org.antlr.runtime.ANTLRStringStream Class Reference

Inheritance diagram for org.antlr.runtime.ANTLRStringStream:

Inheritance graph
[legend]
Collaboration diagram for org.antlr.runtime.ANTLRStringStream:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 ANTLRStringStream ()
 ANTLRStringStream (String input)
 ANTLRStringStream (char[] data, int numberOfActualCharsInArray)
void reset ()
void consume ()
int LA (int i)
int LT (int i)
int index ()
int size ()
int mark ()
void rewind (int m)
void rewind ()
void release (int marker)
void seek (int index)
String substring (int start, int stop)
int getLine ()
int getCharPositionInLine ()
void setLine (int line)
void setCharPositionInLine (int pos)
String getSourceName ()

Public Attributes

String name

Protected Attributes

char[] data
int n
int p = 0
int line = 1
int charPositionInLine = 0
int markDepth = 0
List markers
int lastMarker


Detailed Description

A pretty quick CharStream that pulls all data from an array directly. Every method call counts in the lexer. Java's strings aren't very good so I'm avoiding.

Definition at line 37 of file ANTLRStringStream.java.


Constructor & Destructor Documentation

org.antlr.runtime.ANTLRStringStream.ANTLRStringStream (  ) 

Definition at line 69 of file ANTLRStringStream.java.

org.antlr.runtime.ANTLRStringStream.ANTLRStringStream ( String  input  ) 

Copy data in string to a local char array

Definition at line 73 of file ANTLRStringStream.java.

org.antlr.runtime.ANTLRStringStream.ANTLRStringStream ( char[]  data,
int  numberOfActualCharsInArray 
)

This is the preferred constructor as no data is copied

Definition at line 80 of file ANTLRStringStream.java.


Member Function Documentation

void org.antlr.runtime.ANTLRStringStream.reset (  ) 

Reset the stream so that it's in the same state it was when the object was created *except* the data array is not touched.

Definition at line 90 of file ANTLRStringStream.java.

void org.antlr.runtime.ANTLRStringStream.consume (  ) 

Implements org.antlr.runtime.IntStream.

Definition at line 97 of file ANTLRStringStream.java.

int org.antlr.runtime.ANTLRStringStream.LA ( int  i  ) 

Get int at current input pointer + i ahead where i=1 is next int. Negative indexes are allowed. LA(-1) is previous token (token just matched). LA(-i) where i is before first token should yield -1, invalid char / EOF.

Implements org.antlr.runtime.IntStream.

Definition at line 114 of file ANTLRStringStream.java.

int org.antlr.runtime.ANTLRStringStream.LT ( int  i  ) 

Get the ith character of lookahead. This is the same usually as LA(i). This will be used for labels in the generated lexer code. I'd prefer to return a char here type-wise, but it's probably better to be 32-bit clean and be consistent with LA.

Implements org.antlr.runtime.CharStream.

Definition at line 134 of file ANTLRStringStream.java.

int org.antlr.runtime.ANTLRStringStream.index (  ) 

Return the current input symbol index 0..n where n indicates the last symbol has been read. The index is the index of char to be returned from LA(1).

Implements org.antlr.runtime.IntStream.

Definition at line 142 of file ANTLRStringStream.java.

int org.antlr.runtime.ANTLRStringStream.size (  ) 

Only makes sense for streams that buffer everything up probably, but might be useful to display the entire stream or for testing. This value includes a single EOF.

Implements org.antlr.runtime.IntStream.

Definition at line 146 of file ANTLRStringStream.java.

int org.antlr.runtime.ANTLRStringStream.mark (  ) 

Tell the stream to start buffering if it hasn't already. Return current input position, index(), or some other marker so that when passed to rewind() you get back to the same spot. rewind(mark()) should not affect the input cursor. The Lexer track line/col info as well as input index so its markers are not pure input indexes. Same for tree node streams.

Implements org.antlr.runtime.IntStream.

Definition at line 150 of file ANTLRStringStream.java.

void org.antlr.runtime.ANTLRStringStream.rewind ( int  marker  ) 

Reset the stream so that next call to index would return marker. The marker will usually be index() but it doesn't have to be. It's just a marker to indicate what state the stream was in. This is essentially calling release() and seek(). If there are markers created after this marker argument, this routine must unroll them like a stack. Assume the state the stream was in when this marker was created.

Implements org.antlr.runtime.IntStream.

Definition at line 171 of file ANTLRStringStream.java.

void org.antlr.runtime.ANTLRStringStream.rewind (  ) 

Rewind to the input position of the last marker. Used currently only after a cyclic DFA and just before starting a sem/syn predicate to get the input position back to the start of the decision. Do not "pop" the marker off the state. mark(i) and rewind(i) should balance still. It is like invoking rewind(last marker) but it should not "pop" the marker off. It's like seek(last marker's input position).

Implements org.antlr.runtime.IntStream.

Definition at line 180 of file ANTLRStringStream.java.

void org.antlr.runtime.ANTLRStringStream.release ( int  marker  ) 

You may want to commit to a backtrack but don't want to force the stream to keep bookkeeping objects around for a marker that is no longer necessary. This will have the same behavior as rewind() except it releases resources without the backward seek. This must throw away resources for all markers back to the marker argument. So if you're nested 5 levels of mark(), and then release(2) you have to release resources for depths 2..5.

Implements org.antlr.runtime.IntStream.

Definition at line 184 of file ANTLRStringStream.java.

void org.antlr.runtime.ANTLRStringStream.seek ( int  index  ) 

consume() ahead until p==index; can't just set p=index as we must update line and charPositionInLine.

Implements org.antlr.runtime.IntStream.

Definition at line 194 of file ANTLRStringStream.java.

String org.antlr.runtime.ANTLRStringStream.substring ( int  start,
int  stop 
)

For infinite streams, you don't need this; primarily I'm providing a useful interface for action code. Just make sure actions don't use this on streams that don't support it.

Implements org.antlr.runtime.CharStream.

Definition at line 205 of file ANTLRStringStream.java.

int org.antlr.runtime.ANTLRStringStream.getLine (  ) 

ANTLR tracks the line information automatically

Implements org.antlr.runtime.CharStream.

Definition at line 209 of file ANTLRStringStream.java.

int org.antlr.runtime.ANTLRStringStream.getCharPositionInLine (  ) 

The index of the character relative to the beginning of the line 0..n-1

Implements org.antlr.runtime.CharStream.

Definition at line 213 of file ANTLRStringStream.java.

void org.antlr.runtime.ANTLRStringStream.setLine ( int  line  ) 

Because this stream can rewind, we need to be able to reset the line

Implements org.antlr.runtime.CharStream.

Definition at line 217 of file ANTLRStringStream.java.

void org.antlr.runtime.ANTLRStringStream.setCharPositionInLine ( int  pos  ) 

Implements org.antlr.runtime.CharStream.

Definition at line 221 of file ANTLRStringStream.java.

String org.antlr.runtime.ANTLRStringStream.getSourceName (  ) 

Where are you getting symbols from? Normally, implementations will pass the buck all the way to the lexer who can ask its input stream for the file name or whatever.

Implements org.antlr.runtime.IntStream.

Reimplemented in org.antlr.runtime.ANTLRFileStream.

Definition at line 225 of file ANTLRStringStream.java.


Member Data Documentation

The data being scanned

Definition at line 39 of file ANTLRStringStream.java.

How many characters are actually in the buffer

Definition at line 42 of file ANTLRStringStream.java.

0..n-1 index into string of next char

Definition at line 45 of file ANTLRStringStream.java.

line number 1..n within the input

Definition at line 48 of file ANTLRStringStream.java.

The index of the character relative to the beginning of the line 0..n-1

Definition at line 51 of file ANTLRStringStream.java.

tracks how deep mark() calls are nested

Definition at line 54 of file ANTLRStringStream.java.

A list of CharStreamState objects that tracks the stream state values line, charPositionInLine, and p that can change as you move through the input stream. Indexed from 1..markDepth. A null is kept @ index 0. Create upon first call to mark().

Definition at line 61 of file ANTLRStringStream.java.

Track the last mark() call result value for use in rewind().

Definition at line 64 of file ANTLRStringStream.java.

What is name or source of this char stream?

Definition at line 67 of file ANTLRStringStream.java.


The documentation for this class was generated from the following file:

Generated on Tue Aug 12 11:41:51 2008 for ANTLR API by  doxygen 1.5.5