KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > text > syntax > javacc > lib > CharStream


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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

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

43     abstract public char readChar() throws java.io.IOException JavaDoc;
44
45     /**
46      * Returns the column position of the character last read.
47      * @deprecated
48      * @see #getEndColumn
49      */

50     abstract public int getColumn();
51
52     /**
53      * Returns the line number of the character last read.
54      * @deprecated
55      * @see #getEndLine
56      */

57     abstract public int getLine();
58
59     /**
60      * Returns the column number of the last character for current token (being
61      * matched after the last call to BeginTOken).
62      */

63     abstract public int getEndColumn();
64
65     /**
66      * Returns the line number of the last character for current token (being
67      * matched after the last call to BeginTOken).
68      */

69     abstract public int getEndLine();
70
71     /**
72      * Returns the column number of the first character for current token (being
73      * matched after the last call to BeginTOken).
74      */

75     abstract public int getBeginColumn();
76
77     /**
78      * Returns the line number of the first character for current token (being
79      * matched after the last call to BeginTOken).
80      */

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

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

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

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

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

125     abstract public void Done();
126
127 }
128
Popular Tags