Class CharStream


  • public final class CharStream
    extends Object
    PMD flavour of character streams used by JavaCC parsers.
    • Method Detail

      • readChar

        public char readChar()
                      throws EOFException
        Returns the next character from the input. After a backup(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
        Calls readChar() 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 to readChar() 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.