Class CharStream
java.lang.Object
net.sourceforge.pmd.lang.ast.impl.javacc.CharStream
PMD flavour of character streams used by JavaCC parsers.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Returns the column number of the last character for the current token.int
Returns the line number of the last character for current token.int
Returns the end offset of the current token (in the translated source), exclusive.int
Returns the start offset of the current token (in the translated source), inclusive.Returns the token document for the tokens being built.Returns a string made up of characters from the token mark up to to the current buffer position.Returns a string made up of characters from the token mark up to to the current buffer position.char
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 Details
-
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
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
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
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
Returns a string made up of characters from the token mark up to to the current buffer position. -
getTokenImageCs
Returns a string made up of characters from the token mark up to to the current buffer position. -
appendSuffix
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
Returns the token document for the tokens being built. Having it here is the most convenient place for the time being.
-