Interface CharStream

  • All Known Implementing Classes:
    JavaCharStream, JavaCharStreamBase, SimpleCharStream

    public interface CharStream
    PMD flavour of character streams used by JavaCC parsers. TODO for when all JavaCC languages are aligned: * rename methods to match decent naming conventions * move to impl.javacc package
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      void backup​(int amount)
      Pushes a given number of already read chars into the buffer.
      char BeginToken()
      Calls readChar() and returns its value, marking its position as the beginning of the next token.
      int getBeginColumn()
      Deprecated.
      int getBeginLine()
      Deprecated.
      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.
      default int getEndOffset()
      Returns the end offset of the current token (in the original source), exclusive.
      String GetImage()
      Returns a string made up of characters from the token mark up to to the current buffer position.
      default int getStartOffset()
      Returns the start offset of the current token (in the original source), inclusive.
      char[] GetSuffix​(int len)
      Returns an array of characters that make up the suffix of length 'len' for the current token.
      default JavaccTokenDocument getTokenDocument()
      Returns the token document for the tokens being built.
      char readChar()
      Returns the next character from the input.
    • Method Detail

      • readChar

        char readChar()
               throws IOException
        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:
        IOException - If the underlying char stream throws
      • BeginToken

        char BeginToken()
                 throws IOException
        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:
        IOException
      • GetImage

        String GetImage()
        Returns a string made up of characters from the token mark up to to the current buffer position.
      • GetSuffix

        char[] GetSuffix​(int len)
        Returns an array of characters that make up the suffix of length 'len' for the current 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 = tokenImage();
         return t.substring(t.length() - len, t.length()).toCharArray();
         
        Parameters:
        len - Length of the returned array
        Returns:
        The suffix
        Throws:
        IndexOutOfBoundsException - If len is greater than the length of the current token
      • backup

        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 number of read chars
      • getBeginColumn

        @Deprecated
        int getBeginColumn()
        Deprecated.
      • getBeginLine

        @Deprecated
        int getBeginLine()
        Deprecated.
      • getEndColumn

        int getEndColumn()
        Returns the column number of the last character for the current token.
      • getEndLine

        int getEndLine()
        Returns the line number of the last character for current token.
      • getTokenDocument

        default JavaccTokenDocument getTokenDocument()
        Returns the token document for the tokens being built. Having it here is the most convenient place for the time being.
      • getStartOffset

        default int getStartOffset()
        Returns the start offset of the current token (in the original source), inclusive.
      • getEndOffset

        default int getEndOffset()
        Returns the end offset of the current token (in the original source), exclusive.