Class CharStream
- java.lang.Object
-
- net.sourceforge.pmd.lang.ast.impl.javacc.CharStream
-
public final class CharStream extends Object
PMD flavour of character streams used by JavaCC parsers.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
appendSuffix(StringBuilder sb, int len)
Appends the suffix of length 'len' of the current token to the given string builder.void
backup(int amount)
Pushes a given number of already read chars into the buffer.static CharStream
create(TextDocument doc)
Create a new char stream for the given document with the default token document behavior.static CharStream
create(TextDocument doc, JavaccTokenDocument.TokenDocumentBehavior behavior)
Create a new char stream for the given document.int
getEndColumn()
Returns the column number of the last character for the current token.int
getEndLine()
Returns the line number of the last character for current token.int
getEndOffset()
Returns the end offset of the current token (in the translated source), exclusive.int
getStartOffset()
Returns the start offset of the current token (in the translated source), inclusive.JavaccTokenDocument
getTokenDocument()
Returns the token document for the tokens being built.String
getTokenImage()
Returns a string made up of characters from the token mark up to to the current buffer position.Chars
getTokenImageCs()
Returns a string made up of characters from the token mark up to to the current buffer position.char
markTokenStart()
CallsreadChar()
and returns its value, marking its position as the beginning of the next token.char
readChar()
Returns the next character from the input.
-
-
-
Method Detail
-
create
public static CharStream create(TextDocument doc, JavaccTokenDocument.TokenDocumentBehavior behavior) throws MalformedSourceException
Create a new char stream for the given document. This may create a newTextDocument
view over the original, which reflects its character escapes.- Throws:
MalformedSourceException
-
create
public static CharStream create(TextDocument doc) throws MalformedSourceException
Create a new char stream for the given document with the default token document behavior. This may create a newTextDocument
view over the original, which reflects its character escapes.- Throws:
MalformedSourceException
-
readChar
public char readChar() throws EOFException
Returns the next character from the input. After abackup(int)
, some of the already read chars must be spit out again.- Returns:
- The next character
- Throws:
EOFException
- Upon EOF
-
markTokenStart
public char markTokenStart() throws EOFException
CallsreadChar()
and returns its value, marking its position as 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:
EOFException
-
getTokenImage
public String getTokenImage()
Returns a string made up of characters from the token mark up to to the current buffer position.
-
getTokenImageCs
public Chars getTokenImageCs()
Returns a string made up of characters from the token mark up to to the current buffer position.
-
appendSuffix
public void appendSuffix(StringBuilder sb, int len)
Appends the suffix of length 'len' of the current token to the given string builder. This is used to build up the matched string for use in actions in the case of MORE.- Parameters:
len
- Length of the returned array- Throws:
IndexOutOfBoundsException
- If len is greater than the length of the current token
-
backup
public void backup(int amount)
Pushes a given number of already read chars into the buffer. Subsequent calls toreadChar()
will read those characters before proceeding to read the underlying char stream.A lexer calls this method if it has already read some characters, but cannot use them to match a (longer) token. So, they will be used again as the prefix of the next token.
- Throws:
AssertionError
- If the requested amount is greater than the length of the mark
-
getEndColumn
public int getEndColumn()
Returns the column number of the last character for the current token. This is only used for parse exceptions and is very inefficient.
-
getEndLine
public int getEndLine()
Returns the line number of the last character for current token. This is only used for parse exceptions and is very inefficient.
-
getStartOffset
public int getStartOffset()
Returns the start offset of the current token (in the translated source), inclusive.
-
getEndOffset
public int getEndOffset()
Returns the end offset of the current token (in the translated source), exclusive.
-
getTokenDocument
public JavaccTokenDocument getTokenDocument()
Returns the token document for the tokens being built. Having it here is the most convenient place for the time being.
-
-