Source code: org/apache/derby/impl/sql/compile/CharStream.java
1 /*
2
3 Derby - Class org.apache.derby.impl.sql.compile.CharStream
4
5 Copyright 2000, 2004 The Apache Software Foundation or its licensors, as applicable.
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18
19 */
20
21 package org.apache.derby.impl.sql.compile;
22
23 /**
24 * This interface describes a character stream that maintains line and
25 * column number positions of the characters. It also has the capability
26 * to backup the stream to some extent. An implementation of this
27 * interface is used in the TokenManager implementation generated by
28 * JavaCCParser.
29 *
30 * All the methods except backup can be implemented in any fashion. backup
31 * needs to be implemented correctly for the correct operation of the lexer.
32 * Rest of the methods are all used to get information like line number,
33 * column number and the String that constitutes a token and are not used
34 * by the lexer. Hence their implementation won't affect the generated lexer's
35 * operation.
36 */
37
38 public interface CharStream {
39
40 /**
41 * Returns the next character from the selected input. The method
42 * of selecting the input is the responsibility of the class
43 * implementing this interface. Can throw any java.io.IOException.
44 */
45 char readChar() throws java.io.IOException;
46
47 /**
48 * Returns the column position of the character last read.
49 * @deprecated
50 * @see #getEndColumn
51 */
52 int getColumn();
53
54 /**
55 * Returns the line number of the character last read.
56 * @deprecated
57 * @see #getEndLine
58 */
59 int getLine();
60
61 /**
62 * Returns the column number of the last character for current token (being
63 * matched after the last call to BeginTOken).
64 */
65 int getEndColumn();
66
67 /**
68 * Returns the line number of the last character for current token (being
69 * matched after the last call to BeginTOken).
70 */
71 int getEndLine();
72
73 /**
74 * Returns the column number of the first character for current token (being
75 * matched after the last call to BeginTOken).
76 */
77 int getBeginColumn();
78
79 /**
80 * Returns the line number of the first character for current token (being
81 * matched after the last call to BeginTOken).
82 */
83 int getBeginLine();
84
85 /**
86 * Backs up the input stream by amount steps. Lexer calls this method if it
87 * had already read some characters, but could not use them to match a
88 * (longer) token. So, they will be used again as the prefix of the next
89 * token and it is the implemetation's responsibility to do this right.
90 */
91 void backup(int amount);
92
93 /**
94 * Returns the next character that marks the beginning of the next token.
95 * All characters must remain in the buffer between two successive calls
96 * to this method to implement backup correctly.
97 */
98 char BeginToken() throws java.io.IOException;
99
100 /**
101 * Returns a string made up of characters from the marked token beginning
102 * to the current buffer position. Implementations have the choice of returning
103 * anything that they want to. For example, for efficiency, one might decide
104 * to just return null, which is a valid implementation.
105 */
106 String GetImage();
107
108 /**
109 * Returns an array of characters that make up the suffix of length 'len' for
110 * the currently matched token. This is used to build up the matched string
111 * for use in actions in the case of MORE. A simple and inefficient
112 * implementation of this is as follows :
113 *
114 * {
115 * String t = GetImage();
116 * return t.substring(t.length() - len, t.length()).toCharArray();
117 * }
118 */
119 char[] GetSuffix(int len);
120
121 /**
122 * The lexer calls this function to indicate that it is done with the stream
123 * and hence implementations can free any resources held by this class.
124 * Again, the body of this function can be just empty and it will not
125 * affect the lexer's operation.
126 */
127 void Done();
128
129
130 // This method was added to support ability to get the input
131 // between two tokens.
132 abstract int getBeginOffset();
133
134 // This method was added to support ability to get the input
135 // between two tokens.
136 abstract int getEndOffset();
137
138 // These methods were added to support re-initialization of CharStreams
139 abstract void ReInit(java.io.Reader dstream,
140 int startline, int startcolumn, int buffersize);
141
142 abstract void ReInit(java.io.Reader dstream, int startline, int startcolumn);
143
144 abstract void ReInit(java.io.InputStream dstream, int startline,
145 int startcolumn, int buffersize);
146
147 abstract void ReInit(java.io.InputStream dstream, int startline,
148 int startcolumn);
149
150 }