C# Class Antlr4.Runtime.UnbufferedCharStream

Do not buffer up the entire char stream.
Do not buffer up the entire char stream. It does keep a small buffer for efficiency and also buffers while a mark exists (set by the lookahead prediction in parser). "Unbuffered" here refers to fact that it doesn't buffer all data, not that's it's on demand loading of char.
Inheritance: ICharStream
Show file Open project: sharwell/antlr4cs

Public Properties

Property Type Description
name string

Protected Properties

Property Type Description
currentCharIndex int
data char[]
input System.IO.TextReader
lastChar int
lastCharBufferStart int
n int
numMarkers int
p int

Public Methods

Method Description
Consume ( ) : void
GetText ( Interval interval ) : string
La ( int i ) : int
Mark ( ) : int

Return a marker that we can release later.

Return a marker that we can release later.

The specific marker value used for this class allows for some level of protection against misuse where seek() is called on a mark or release() is called in the wrong order.

Release ( int marker ) : void

Decrement number of markers, resetting buffer if we hit 0.

Seek ( int index ) : void

Seek to absolute character index, which might not be in the current sliding window.

Seek to absolute character index, which might not be in the current sliding window. Move p to index-bufferStartIndex .

UnbufferedCharStream ( ) : System

Useful for subclasses that pull char from other than this.input.

UnbufferedCharStream ( Stream input ) : System
UnbufferedCharStream ( Stream input, int bufferSize ) : System
UnbufferedCharStream ( TextReader input ) : System
UnbufferedCharStream ( TextReader input, int bufferSize ) : System
UnbufferedCharStream ( int bufferSize ) : System

Useful for subclasses that pull char from other than this.input.

Protected Methods

Method Description
Add ( int c ) : void
Fill ( int n ) : int

Add n characters to the buffer. Returns the number of characters actually added to the buffer. If the return value is less than n , then EOF was reached before n characters could be added.

NextChar ( ) : int

Override to provide different source of characters than input .

Sync ( int want ) : void

Make sure we have 'need' elements from current position p . Last valid p index is data.length-1 . p+need-1 is the char index 'need' elements ahead. If we need 1 element, (p+1-1)==p must be less than data.length .

Method Details

Add() protected method

protected Add ( int c ) : void
c int
return void

Consume() public method

public Consume ( ) : void
return void

Fill() protected method

Add n characters to the buffer. Returns the number of characters actually added to the buffer. If the return value is less than n , then EOF was reached before n characters could be added.
protected Fill ( int n ) : int
n int
return int

GetText() public method

public GetText ( Interval interval ) : string
interval Antlr4.Runtime.Misc.Interval
return string

La() public method

public La ( int i ) : int
i int
return int

Mark() public method

Return a marker that we can release later.
Return a marker that we can release later.

The specific marker value used for this class allows for some level of protection against misuse where seek() is called on a mark or release() is called in the wrong order.

public Mark ( ) : int
return int

NextChar() protected method

Override to provide different source of characters than input .
protected NextChar ( ) : int
return int

Release() public method

Decrement number of markers, resetting buffer if we hit 0.
public Release ( int marker ) : void
marker int
return void

Seek() public method

Seek to absolute character index, which might not be in the current sliding window.
Seek to absolute character index, which might not be in the current sliding window. Move p to index-bufferStartIndex .
public Seek ( int index ) : void
index int
return void

Sync() protected method

Make sure we have 'need' elements from current position p . Last valid p index is data.length-1 . p+need-1 is the char index 'need' elements ahead. If we need 1 element, (p+1-1)==p must be less than data.length .
protected Sync ( int want ) : void
want int
return void

UnbufferedCharStream() public method

Useful for subclasses that pull char from other than this.input.
public UnbufferedCharStream ( ) : System
return System

UnbufferedCharStream() public method

public UnbufferedCharStream ( Stream input ) : System
input Stream
return System

UnbufferedCharStream() public method

public UnbufferedCharStream ( Stream input, int bufferSize ) : System
input Stream
bufferSize int
return System

UnbufferedCharStream() public method

public UnbufferedCharStream ( TextReader input ) : System
input System.IO.TextReader
return System

UnbufferedCharStream() public method

public UnbufferedCharStream ( TextReader input, int bufferSize ) : System
input System.IO.TextReader
bufferSize int
return System

UnbufferedCharStream() public method

Useful for subclasses that pull char from other than this.input.
public UnbufferedCharStream ( int bufferSize ) : System
bufferSize int
return System

Property Details

currentCharIndex protected property

Absolute character index.
Absolute character index. It's the index of the character about to be read via LA(1) . Goes from 0 to the number of characters in the entire stream, although the stream size is unknown before the end is reached.
protected int currentCharIndex
return int

data protected property

A moving window buffer of the data being scanned.
A moving window buffer of the data being scanned. While there's a marker, we keep adding to buffer. Otherwise, consume() resets so we start filling at index 0 again.
protected char[] data
return char[]

input protected property

protected TextReader,System.IO input
return System.IO.TextReader

lastChar protected property

This is the LA(-1) character for the current position.
protected int lastChar
return int

lastCharBufferStart protected property

When numMarkers > 0 , this is the LA(-1) character for the first character in data . Otherwise, this is unspecified.
protected int lastCharBufferStart
return int

n protected property

The number of characters currently in data .

This is not the buffer capacity, that's data.length .

protected int n
return int

name public property

The name or source of this char stream.
public string name
return string

numMarkers protected property

Count up with mark() and down with release() . When we release() the last mark, numMarkers reaches 0 and we reset the buffer. Copy data[p]..data[n-1] to data[0]..data[(n-1)-p] .
protected int numMarkers
return int

p protected property

0..n-1 index into data of next character.

The LA(1) character is data[p] . If p == n , we are out of buffered characters.

protected int p
return int