| 1 |
/** |
| 2 |
* This interface describes a character stream that maintains line and |
| 3 |
* column number positions of the characters. It also has the capability |
| 4 |
* to backup the stream to some extent. An implementation of this |
| 5 |
* interface is used in the TokenManager implementation generated by |
| 6 |
* JavaCCParser. |
| 7 |
* |
| 8 |
* All the methods except backup can be implemented in any fashion. backup |
| 9 |
* needs to be implemented correctly for the correct operation of the lexer. |
| 10 |
* Rest of the methods are all used to get information like line number, |
| 11 |
* column number and the String that constitutes a token and are not used |
| 12 |
* by the lexer. Hence their implementation won't affect the generated lexer's |
| 13 |
* operation. |
| 14 |
*/ |
| 15 |
|
| 16 |
#if SUPPORT_CLASS_VISIBILITY_PUBLIC |
| 17 |
public |
| 18 |
#fi |
| 19 |
interface CharStream { |
| 20 |
|
| 21 |
/** |
| 22 |
* Returns the next character from the selected input. The method |
| 23 |
* of selecting the input is the responsibility of the class |
| 24 |
* implementing this interface. Can throw any java.io.IOException. |
| 25 |
*/ |
| 26 |
char readChar() throws java.io.IOException; |
| 27 |
|
| 28 |
#if GENERATE_ANNOTATIONS |
| 29 |
@Deprecated |
| 30 |
#fi |
| 31 |
/** |
| 32 |
* Returns the column position of the character last read. |
| 33 |
* @deprecated |
| 34 |
* @see #getEndColumn |
| 35 |
*/ |
| 36 |
int getColumn(); |
| 37 |
|
| 38 |
#if GENERATE_ANNOTATIONS |
| 39 |
@Deprecated |
| 40 |
#fi |
| 41 |
/** |
| 42 |
* Returns the line number of the character last read. |
| 43 |
* @deprecated |
| 44 |
* @see #getEndLine |
| 45 |
*/ |
| 46 |
int getLine(); |
| 47 |
|
| 48 |
/** |
| 49 |
* Returns the column number of the last character for current token (being |
| 50 |
* matched after the last call to BeginTOken). |
| 51 |
*/ |
| 52 |
int getEndColumn(); |
| 53 |
|
| 54 |
/** |
| 55 |
* Returns the line number of the last character for current token (being |
| 56 |
* matched after the last call to BeginTOken). |
| 57 |
*/ |
| 58 |
int getEndLine(); |
| 59 |
|
| 60 |
/** |
| 61 |
* Returns the column number of the first character for current token (being |
| 62 |
* matched after the last call to BeginTOken). |
| 63 |
*/ |
| 64 |
int getBeginColumn(); |
| 65 |
|
| 66 |
/** |
| 67 |
* Returns the line number of the first character for current token (being |
| 68 |
* matched after the last call to BeginTOken). |
| 69 |
*/ |
| 70 |
int getBeginLine(); |
| 71 |
|
| 72 |
/** |
| 73 |
* Backs up the input stream by amount steps. Lexer calls this method if it |
| 74 |
* had already read some characters, but could not use them to match a |
| 75 |
* (longer) token. So, they will be used again as the prefix of the next |
| 76 |
* token and it is the implemetation's responsibility to do this right. |
| 77 |
*/ |
| 78 |
void backup(int amount); |
| 79 |
|
| 80 |
/** |
| 81 |
* Returns the next character that marks the beginning of the next token. |
| 82 |
* All characters must remain in the buffer between two successive calls |
| 83 |
* to this method to implement backup correctly. |
| 84 |
*/ |
| 85 |
char BeginToken() throws java.io.IOException; |
| 86 |
|
| 87 |
/** |
| 88 |
* Returns a string made up of characters from the marked token beginning |
| 89 |
* to the current buffer position. Implementations have the choice of returning |
| 90 |
* anything that they want to. For example, for efficiency, one might decide |
| 91 |
* to just return null, which is a valid implementation. |
| 92 |
*/ |
| 93 |
String GetImage(); |
| 94 |
|
| 95 |
/** |
| 96 |
* Returns an array of characters that make up the suffix of length 'len' for |
| 97 |
* the currently matched token. This is used to build up the matched string |
| 98 |
* for use in actions in the case of MORE. A simple and inefficient |
| 99 |
* implementation of this is as follows : |
| 100 |
* |
| 101 |
* { |
| 102 |
* String t = GetImage(); |
| 103 |
* return t.substring(t.length() - len, t.length()).toCharArray(); |
| 104 |
* } |
| 105 |
*/ |
| 106 |
char[] GetSuffix(int len); |
| 107 |
|
| 108 |
/** |
| 109 |
* The lexer calls this function to indicate that it is done with the stream |
| 110 |
* and hence implementations can free any resources held by this class. |
| 111 |
* Again, the body of this function can be just empty and it will not |
| 112 |
* affect the lexer's operation. |
| 113 |
*/ |
| 114 |
void Done(); |
| 115 |
|
| 116 |
} |