01: /* Generated By:JavaCC: Do not edit this line. CharStream.java Version 3.0 */
02: package org.apache.lucene.queryParser.surround.parser;
03:
04: /**
05: * This interface describes a character stream that maintains line and
06: * column number positions of the characters. It also has the capability
07: * to backup the stream to some extent. An implementation of this
08: * interface is used in the TokenManager implementation generated by
09: * JavaCCParser.
10: *
11: * All the methods except backup can be implemented in any fashion. backup
12: * needs to be implemented correctly for the correct operation of the lexer.
13: * Rest of the methods are all used to get information like line number,
14: * column number and the String that constitutes a token and are not used
15: * by the lexer. Hence their implementation won't affect the generated lexer's
16: * operation.
17: */
18:
19: public 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: /**
29: * Returns the column number of the last character for current token (being
30: * matched after the last call to BeginTOken).
31: */
32: int getEndColumn();
33:
34: /**
35: * Returns the line number of the last character for current token (being
36: * matched after the last call to BeginTOken).
37: */
38: int getEndLine();
39:
40: /**
41: * Returns the column number of the first character for current token (being
42: * matched after the last call to BeginTOken).
43: */
44: int getBeginColumn();
45:
46: /**
47: * Returns the line number of the first character for current token (being
48: * matched after the last call to BeginTOken).
49: */
50: int getBeginLine();
51:
52: /**
53: * Backs up the input stream by amount steps. Lexer calls this method if it
54: * had already read some characters, but could not use them to match a
55: * (longer) token. So, they will be used again as the prefix of the next
56: * token and it is the implemetation's responsibility to do this right.
57: */
58: void backup(int amount);
59:
60: /**
61: * Returns the next character that marks the beginning of the next token.
62: * All characters must remain in the buffer between two successive calls
63: * to this method to implement backup correctly.
64: */
65: char BeginToken() throws java.io.IOException;
66:
67: /**
68: * Returns a string made up of characters from the marked token beginning
69: * to the current buffer position. Implementations have the choice of returning
70: * anything that they want to. For example, for efficiency, one might decide
71: * to just return null, which is a valid implementation.
72: */
73: String GetImage();
74:
75: /**
76: * Returns an array of characters that make up the suffix of length 'len' for
77: * the currently matched token. This is used to build up the matched string
78: * for use in actions in the case of MORE. A simple and inefficient
79: * implementation of this is as follows :
80: *
81: * {
82: * String t = GetImage();
83: * return t.substring(t.length() - len, t.length()).toCharArray();
84: * }
85: */
86: char[] GetSuffix(int len);
87:
88: /**
89: * The lexer calls this function to indicate that it is done with the stream
90: * and hence implementations can free any resources held by this class.
91: * Again, the body of this function can be just empty and it will not
92: * affect the lexer's operation.
93: */
94: void Done();
95:
96: }
|