Class StringCharStream
- java.lang.Object
-
- com.google.common.css.compiler.ast.StringCharStream
-
- All Implemented Interfaces:
CharStream
public class StringCharStream extends java.lang.Object implements CharStream
EfficientStringbasedCharStreamimplementation.
-
-
Constructor Summary
Constructors Constructor Description StringCharStream(java.lang.String inputString)Creates a character stream for a given string.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbackup(int amount)Backs up the input stream by amount steps.charbeginToken()Returns the next character that marks the beginning of the next token.intconvertToCharacterIndex(int lineNumber, int indexInLine)Returns an absolute character location for given line and column location.voiddone()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.intgetBeginColumn()Returns the column number of the first character for current token (being matched after the last call to beginToken).intgetBeginLine()Returns the line number of the first character for current token (being matched after the last call to beginToken).intgetCharIndex()intgetEndColumn()Returns the column number of the last character for current token (being matched after the last call to beginToken).intgetEndLine()Returns the line number of the last character for current token (being matched after the last call to beginToken).java.lang.StringgetImage()Returns a string made up of characters from the marked token beginning to the current buffer position.char[]getSuffix(int len)Returns an array of characters that make up the suffix of length 'len' for the currently matched token.intgetTabSize()booleangetTrackLineColumn()charreadChar()Returns the next character from the selected input.voidsetTabSize(int tabSize)voidsetTrackLineColumn(boolean trackLineColumn)
-
-
-
Method Detail
-
convertToCharacterIndex
public int convertToCharacterIndex(int lineNumber, int indexInLine)Returns an absolute character location for given line and column location.- Parameters:
lineNumber- line number (1 based)indexInLine- column number (1 based)- Returns:
- 0 based absolute character index in the input string
-
getCharIndex
public int getCharIndex()
- Returns:
- index of last read character
-
readChar
public char readChar() throws java.io.IOExceptionReturns the next character from the selected input. The method of selecting the input is the responsibility of the class implementing this interface. Can throw any java.io.IOException.- Specified by:
readCharin interfaceCharStream- Throws:
java.io.IOException
-
getEndColumn
public int getEndColumn()
Returns the column number of the last character for current token (being matched after the last call to beginToken).- Specified by:
getEndColumnin interfaceCharStream
-
getEndLine
public int getEndLine()
Returns the line number of the last character for current token (being matched after the last call to beginToken).- Specified by:
getEndLinein interfaceCharStream
-
getBeginColumn
public int getBeginColumn()
Returns the column number of the first character for current token (being matched after the last call to beginToken).- Specified by:
getBeginColumnin interfaceCharStream
-
getBeginLine
public int getBeginLine()
Returns the line number of the first character for current token (being matched after the last call to beginToken).- Specified by:
getBeginLinein interfaceCharStream
-
backup
public void backup(int amount)
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:
backupin interfaceCharStream- Parameters:
amount- amount
-
beginToken
public char beginToken() throws java.io.IOExceptionReturns 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.- Specified by:
beginTokenin interfaceCharStream- Returns:
- next character
- Throws:
java.io.IOException
-
getImage
public java.lang.String getImage()
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.- Specified by:
getImagein interfaceCharStream
-
getSuffix
public char[] getSuffix(int len)
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(); }
- Specified by:
getSuffixin interfaceCharStream
-
done
public 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. Again, the body of this function can be just empty and it will not affect the lexer's operation.- Specified by:
donein interfaceCharStream
-
setTabSize
public void setTabSize(int tabSize)
- Specified by:
setTabSizein interfaceCharStream
-
getTabSize
public int getTabSize()
- Specified by:
getTabSizein interfaceCharStream
-
getTrackLineColumn
public boolean getTrackLineColumn()
- Specified by:
getTrackLineColumnin interfaceCharStream
-
setTrackLineColumn
public void setTrackLineColumn(boolean trackLineColumn)
- Specified by:
setTrackLineColumnin interfaceCharStream
-
-