public abstract class AbstractCharStream extends Object implements CharStream
Modifier and Type | Field and Description |
---|---|
protected int |
available
The number of unoccupied buffer array positions
|
protected char[] |
buffer
Internal circular buffer
|
protected int |
bufpos
Current read position in buffer.
|
protected int |
bufsize
Overall buffer size - same as buffer.length
|
static int |
DEFAULT_BUF_SIZE
Default buffer size if nothing is specified
|
protected int |
inBuf
Characters in the backup/pushBack buffer
|
protected int |
maxNextCharInd |
protected int |
tokenBegin
The first array index (of `buffer`) that the current token starts
|
Constructor and Description |
---|
AbstractCharStream(int nStartLine,
int nStartColumn,
int nBufferSize)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
adjustBeginLineColumn(int nNewLine,
int newCol)
Method to adjust line and column numbers for the start of a token.
|
void |
backup(int nAmount)
Backs up the input stream by amount steps.
|
char |
beginToken() |
void |
done()
The lexer calls this function to indicate that it is done with the stream
and hence implementations can free any resources held by this class.
|
protected void |
expandBuff(boolean bWrapAround) |
protected void |
fillBuff() |
int |
getBeginColumn() |
int |
getBeginLine() |
protected int |
getBufSizeAfterExpansion() |
protected int |
getColumn() |
int |
getEndColumn() |
int |
getEndLine() |
String |
getImage() |
protected int |
getLine() |
char[] |
getSuffix(int len) |
int |
getTabSize() |
protected void |
internalAdjustBuffSize() |
protected void |
internalSetBufLineColumn(int nLine,
int nColumn) |
protected void |
internalUpdateLineColumn(char c) |
boolean |
isTrackLineColumn() |
char |
readChar()
Get the next character from the selected input.
|
void |
reInit(int nStartLine,
int nStartColumn,
int nBufferSize)
Reinitialise.
|
void |
setTabSize(int nTabSize)
Set the tab size to use.
|
void |
setTrackLineColumn(boolean bTrackLineColumn)
Enable or disable line number and column number tracking.
|
protected abstract void |
streamClose()
Close the underlying stream.
|
protected abstract int |
streamRead(char[] aBuf,
int nOfs,
int nLen)
Read from the underlying stream.
|
public static final int DEFAULT_BUF_SIZE
protected char[] buffer
protected int bufsize
protected int bufpos
protected int available
protected int tokenBegin
protected int inBuf
protected int maxNextCharInd
public AbstractCharStream(int nStartLine, int nStartColumn, int nBufferSize)
public final void reInit(int nStartLine, int nStartColumn, int nBufferSize)
protected abstract int streamRead(char[] aBuf, int nOfs, int nLen) throws IOException
aBuf
- the buffer to be fillednOfs
- The offset into the buffer. 0-basednLen
- Number of chars to read.IOException
protected abstract void streamClose() throws IOException
IOException
- If closing fails.protected int getBufSizeAfterExpansion()
protected void expandBuff(boolean bWrapAround)
protected final void internalAdjustBuffSize()
protected void fillBuff() throws IOException
IOException
protected final void internalSetBufLineColumn(int nLine, int nColumn)
protected final void internalUpdateLineColumn(char c)
public char readChar() throws IOException
CharStream
readChar
in interface CharStream
IOException
- on IO errorpublic char beginToken() throws IOException
beginToken
in interface CharStream
IOException
public int getBeginColumn()
getBeginColumn
in interface CharStream
public int getBeginLine()
getBeginLine
in interface CharStream
public int getEndColumn()
getEndColumn
in interface CharStream
public int getEndLine()
getEndLine
in interface CharStream
public void backup(int nAmount)
CharStream
backup
in interface CharStream
nAmount
- Number of chars to back up.public String getImage()
getImage
in interface CharStream
public char[] getSuffix(int len)
getSuffix
in interface CharStream
{ String t = getImage(); return t.substring(t.length() - len, t.length()).toCharArray(); }
public void done()
CharStream
done
in interface CharStream
public final int getTabSize()
getTabSize
in interface CharStream
public final void setTabSize(int nTabSize)
CharStream
setTabSize
in interface CharStream
nTabSize
- spaces per tabpublic final void adjustBeginLineColumn(int nNewLine, int newCol)
protected final int getLine()
protected final int getColumn()
public final boolean isTrackLineColumn()
isTrackLineColumn
in interface CharStream
true
if line number and column numbers should be tracked.public final void setTrackLineColumn(boolean bTrackLineColumn)
CharStream
setTrackLineColumn
in interface CharStream
bTrackLineColumn
- true
to track it, false
to not do it.Copyright © 2007–2020. All rights reserved.