Class AbstractCharStream
- java.lang.Object
-
- fr.mines_stetienne.ci.sparql_generate.lang.AbstractCharStream
-
- All Implemented Interfaces:
CharStream
- Direct Known Subclasses:
JavaCharStream
public abstract class AbstractCharStream extends Object implements CharStream
An implementation of interface CharStream, where the stream is assumed to contain only ASCII characters (without unicode processing).
-
-
Field Summary
Fields Modifier and Type Field Description protected int
available
protected int[]
bufcolumn
protected char[]
buffer
protected static int
BUFFER_INCREASE
By how much should the buffer be increase?protected int[]
bufline
protected int
bufpos
Position in buffer.protected int
bufsize
protected int
column
static int
DEFAULT_BUF_SIZE
Default buffer size if nothing is specifiedprotected int
inBuf
protected int
line
protected int
maxNextCharInd
protected boolean
prevCharIsCR
protected boolean
prevCharIsLF
protected int
tokenBegin
-
Constructor Summary
Constructors Constructor Description AbstractCharStream(int startline, int startcolumn, int buffersize)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
adjustBeginLineColumn(int nNewLine, int newCol)
Method to adjust line and column numbers for the start of a token.void
backup(int amount)
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 wrapAround)
protected void
fillBuff()
int
getBeginColumn()
int
getBeginLine()
int
getEndColumn()
int
getEndLine()
String
getImage()
char[]
getSuffix(int len)
int
getTabSize()
boolean
isTrackLineColumn()
char
readChar()
Read a character.void
reInit(int startline, int startcolumn, int buffersize)
Reinitialise.void
setTabSize(int i)
Set the tab size to use.void
setTrackLineColumn(boolean tlc)
Enable or disable line number and column number tracking.protected abstract void
streamClose()
protected abstract int
streamRead(char[] aBuf, int nOfs, int nLen)
protected void
updateLineColumn(char c)
-
-
-
Field Detail
-
DEFAULT_BUF_SIZE
public static final int DEFAULT_BUF_SIZE
Default buffer size if nothing is specified- See Also:
- Constant Field Values
-
BUFFER_INCREASE
protected static final int BUFFER_INCREASE
By how much should the buffer be increase?- See Also:
- Constant Field Values
-
bufpos
protected int bufpos
Position in buffer.
-
bufsize
protected int bufsize
-
available
protected int available
-
tokenBegin
protected int tokenBegin
-
buffer
protected char[] buffer
-
inBuf
protected int inBuf
-
maxNextCharInd
protected int maxNextCharInd
-
bufline
protected int[] bufline
-
bufcolumn
protected int[] bufcolumn
-
column
protected int column
-
line
protected int line
-
prevCharIsCR
protected boolean prevCharIsCR
-
prevCharIsLF
protected boolean prevCharIsLF
-
-
Method Detail
-
setTabSize
public void setTabSize(int i)
Description copied from interface:CharStream
Set the tab size to use.- Specified by:
setTabSize
in interfaceCharStream
- Parameters:
i
- spaces per tab
-
getTabSize
public int getTabSize()
- Specified by:
getTabSize
in interfaceCharStream
- Returns:
- Current tab size.
-
expandBuff
protected void expandBuff(boolean wrapAround)
-
streamRead
protected abstract int streamRead(char[] aBuf, int nOfs, int nLen) throws IOException
- Throws:
IOException
-
streamClose
protected abstract void streamClose() throws IOException
- Throws:
IOException
-
fillBuff
protected void fillBuff() throws IOException
- Throws:
IOException
-
beginToken
public char beginToken() throws IOException
- Specified by:
beginToken
in interfaceCharStream
- Returns:
- the next character that marks the beginning of the next token. All characters must remain in the buffer between two successive calls to this method to implement backup correctly.
- Throws:
IOException
-
updateLineColumn
protected void updateLineColumn(char c)
-
readChar
public char readChar() throws IOException
Read a character.- Specified by:
readChar
in interfaceCharStream
- Returns:
- the next character from the selected input
- Throws:
IOException
- on IO error
-
getBeginColumn
public int getBeginColumn()
- Specified by:
getBeginColumn
in interfaceCharStream
- Returns:
- the column number of the first character for current token (being matched after the last call to beginToken).
-
getBeginLine
public int getBeginLine()
- Specified by:
getBeginLine
in interfaceCharStream
- Returns:
- the line number of the first character for current token (being matched after the last call to BeginToken).
-
getEndColumn
public int getEndColumn()
- Specified by:
getEndColumn
in interfaceCharStream
- Returns:
- the column number of the last character for current token (being matched after the last call to BeginToken).
-
getEndLine
public int getEndLine()
- Specified by:
getEndLine
in interfaceCharStream
- Returns:
- the line number of the last character for current token (being matched after the last call to BeginToken).
-
backup
public void backup(int amount)
Description copied from interface:CharStream
Backs up the input stream by amount steps. Lexer calls this method if it had already read some characters, but could not use them to match a (longer) token. So, they will be used again as the prefix of the next token and it is the implemetation's responsibility to do this right.- Specified by:
backup
in interfaceCharStream
- Parameters:
amount
- Number of chars to back up.
-
reInit
public void reInit(int startline, int startcolumn, int buffersize)
Reinitialise.
-
getImage
public String getImage()
- Specified by:
getImage
in interfaceCharStream
- Returns:
- a string made up of characters from the marked token beginning to the current buffer position. Implementations have the choice of returning anything that they want to. For example, for efficiency, one might decide to just return null, which is a valid implementation.
-
getSuffix
public char[] getSuffix(int len)
- Specified by:
getSuffix
in interfaceCharStream
- Returns:
- an array of characters that make up the suffix of length 'len' for
the currently matched token. This is used to build up the matched string
for use in actions in the case of MORE. A simple and inefficient
implementation of this is as follows:
{ String t = getImage(); return t.substring(t.length() - len, t.length()).toCharArray(); }
-
done
public void done()
Description copied from interface:CharStream
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. Again, the body of this function can be just empty and it will not affect the lexer's operation.- Specified by:
done
in interfaceCharStream
-
adjustBeginLineColumn
public void adjustBeginLineColumn(int nNewLine, int newCol)
Method to adjust line and column numbers for the start of a token.
-
setTrackLineColumn
public void setTrackLineColumn(boolean tlc)
Description copied from interface:CharStream
Enable or disable line number and column number tracking.- Specified by:
setTrackLineColumn
in interfaceCharStream
- Parameters:
tlc
-true
to track it,false
to not do it.
-
isTrackLineColumn
public boolean isTrackLineColumn()
- Specified by:
isTrackLineColumn
in interfaceCharStream
- Returns:
true
if line number and column numbers should be tracked.
-
-