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