CharStream.java
001 /* Generated By:JavaCC: Do not edit this line. CharStream.java Version 4.1 */
002 /* JavaCCOptions:STATIC=true */
003 package net.sourceforge.pmd.lang.ast;
004 
005 /**
006  * This interface describes a character stream that maintains line and
007  * column number positions of the characters.  It also has the capability
008  * to backup the stream to some extent.  An implementation of this
009  * interface is used in the TokenManager implementation generated by
010  * JavaCCParser.
011  *
012  * All the methods except backup can be implemented in any fashion. backup
013  * needs to be implemented correctly for the correct operation of the lexer.
014  * Rest of the methods are all used to get information like line number,
015  * column number and the String that constitutes a token and are not used
016  * by the lexer. Hence their implementation won't affect the generated lexer's
017  * operation.
018  */
019 
020 public interface CharStream {
021 
022   /**
023    * Returns the next character from the selected input.  The method
024    * of selecting the input is the responsibility of the class
025    * implementing this interface.  Can throw any java.io.IOException.
026    */
027   char readChar() throws java.io.IOException;
028 
029   /**
030    * Returns the column position of the character last read.
031    @deprecated
032    @see #getEndColumn
033    */
034   int getColumn();
035 
036   /**
037    * Returns the line number of the character last read.
038    @deprecated
039    @see #getEndLine
040    */
041   int getLine();
042 
043   /**
044    * Returns the column number of the last character for current token (being
045    * matched after the last call to BeginTOken).
046    */
047   int getEndColumn();
048 
049   /**
050    * Returns the line number of the last character for current token (being
051    * matched after the last call to BeginTOken).
052    */
053   int getEndLine();
054 
055   /**
056    * Returns the column number of the first character for current token (being
057    * matched after the last call to BeginTOken).
058    */
059   int getBeginColumn();
060 
061   /**
062    * Returns the line number of the first character for current token (being
063    * matched after the last call to BeginTOken).
064    */
065   int getBeginLine();
066 
067   /**
068    * Backs up the input stream by amount steps. Lexer calls this method if it
069    * had already read some characters, but could not use them to match a
070    * (longer) token. So, they will be used again as the prefix of the next
071    * token and it is the implemetation's responsibility to do this right.
072    */
073   void backup(int amount);
074 
075   /**
076    * Returns the next character that marks the beginning of the next token.
077    * All characters must remain in the buffer between two successive calls
078    * to this method to implement backup correctly.
079    */
080   char BeginToken() throws java.io.IOException;
081 
082   /**
083    * Returns a string made up of characters from the marked token beginning
084    * to the current buffer position. Implementations have the choice of returning
085    * anything that they want to. For example, for efficiency, one might decide
086    * to just return null, which is a valid implementation.
087    */
088   String GetImage();
089 
090   /**
091    * Returns an array of characters that make up the suffix of length 'len' for
092    * the currently matched token. This is used to build up the matched string
093    * for use in actions in the case of MORE. A simple and inefficient
094    * implementation of this is as follows :
095    *
096    *   {
097    *      String t = GetImage();
098    *      return t.substring(t.length() - len, t.length()).toCharArray();
099    *   }
100    */
101   char[] GetSuffix(int len);
102 
103   /**
104    * The lexer calls this function to indicate that it is done with the stream
105    * and hence implementations can free any resources held by this class.
106    * Again, the body of this function can be just empty and it will not
107    * affect the lexer's operation.
108    */
109   void Done();
110 
111 }
112 /* JavaCC - OriginalChecksum=0c387fa4d138cb757cb48b36d8bfec55 (do not edit this line) */