KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > CharStream


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.CharStream
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 /**
25  * This interface describes a character stream that maintains line and
26  * column number positions of the characters. It also has the capability
27  * to backup the stream to some extent. An implementation of this
28  * interface is used in the TokenManager implementation generated by
29  * JavaCCParser.
30  *
31  * All the methods except backup can be implemented in any fashion. backup
32  * needs to be implemented correctly for the correct operation of the lexer.
33  * Rest of the methods are all used to get information like line number,
34  * column number and the String that constitutes a token and are not used
35  * by the lexer. Hence their implementation won't affect the generated lexer's
36  * operation.
37  */

38
39 public interface CharStream {
40
41   /**
42    * Returns the next character from the selected input. The method
43    * of selecting the input is the responsibility of the class
44    * implementing this interface. Can throw any java.io.IOException.
45    */

46   char readChar() throws java.io.IOException JavaDoc;
47
48   /**
49    * Returns the column position of the character last read.
50    * @deprecated
51    * @see #getEndColumn
52    */

53   int getColumn();
54
55   /**
56    * Returns the line number of the character last read.
57    * @deprecated
58    * @see #getEndLine
59    */

60   int getLine();
61
62   /**
63    * Returns the column number of the last character for current token (being
64    * matched after the last call to BeginTOken).
65    */

66   int getEndColumn();
67
68   /**
69    * Returns the line number of the last character for current token (being
70    * matched after the last call to BeginTOken).
71    */

72   int getEndLine();
73
74   /**
75    * Returns the column number of the first character for current token (being
76    * matched after the last call to BeginTOken).
77    */

78   int getBeginColumn();
79
80   /**
81    * Returns the line number of the first character for current token (being
82    * matched after the last call to BeginTOken).
83    */

84   int getBeginLine();
85
86   /**
87    * Backs up the input stream by amount steps. Lexer calls this method if it
88    * had already read some characters, but could not use them to match a
89    * (longer) token. So, they will be used again as the prefix of the next
90    * token and it is the implemetation's responsibility to do this right.
91    */

92   void backup(int amount);
93
94   /**
95    * Returns the next character that marks the beginning of the next token.
96    * All characters must remain in the buffer between two successive calls
97    * to this method to implement backup correctly.
98    */

99   char BeginToken() throws java.io.IOException JavaDoc;
100
101   /**
102    * Returns a string made up of characters from the marked token beginning
103    * to the current buffer position. Implementations have the choice of returning
104    * anything that they want to. For example, for efficiency, one might decide
105    * to just return null, which is a valid implementation.
106    */

107   String JavaDoc GetImage();
108
109   /**
110    * Returns an array of characters that make up the suffix of length 'len' for
111    * the currently matched token. This is used to build up the matched string
112    * for use in actions in the case of MORE. A simple and inefficient
113    * implementation of this is as follows :
114    *
115    * {
116    * String t = GetImage();
117    * return t.substring(t.length() - len, t.length()).toCharArray();
118    * }
119    */

120   char[] GetSuffix(int len);
121
122   /**
123    * The lexer calls this function to indicate that it is done with the stream
124    * and hence implementations can free any resources held by this class.
125    * Again, the body of this function can be just empty and it will not
126    * affect the lexer's operation.
127    */

128   void Done();
129
130
131   // This method was added to support ability to get the input
132
// between two tokens.
133
abstract int getBeginOffset();
134
135   // This method was added to support ability to get the input
136
// between two tokens.
137
abstract int getEndOffset();
138
139   // These methods were added to support re-initialization of CharStreams
140
abstract void ReInit(java.io.Reader JavaDoc dstream,
141                         int startline, int startcolumn, int buffersize);
142
143   abstract void ReInit(java.io.Reader JavaDoc dstream, int startline, int startcolumn);
144
145   abstract void ReInit(java.io.InputStream JavaDoc dstream, int startline,
146                         int startcolumn, int buffersize);
147
148   abstract void ReInit(java.io.InputStream JavaDoc dstream, int startline,
149                         int startcolumn);
150
151 }
152
Popular Tags