1 | /* Generated by: ParserGeneratorCC: Do not edit this line. CharStream.java Version 1.1 */ |
---|---|
2 | /* ParserGeneratorCCOptions:SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ |
3 | /* |
4 | * Copyright (C) 2007-2010 JĂșlio Vilmar Gesser. |
5 | * Copyright (C) 2011, 2013-2020 The JavaParser Team. |
6 | * |
7 | * This file is part of JavaParser. |
8 | * |
9 | * JavaParser can be used either under the terms of |
10 | * a) the GNU Lesser General Public License as published by |
11 | * the Free Software Foundation, either version 3 of the License, or |
12 | * (at your option) any later version. |
13 | * b) the terms of the Apache License |
14 | * |
15 | * You should have received a copy of both licenses in LICENCE.LGPL and |
16 | * LICENCE.APACHE. Please refer to those files for details. |
17 | * |
18 | * JavaParser is distributed in the hope that it will be useful, |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | * GNU Lesser General Public License for more details. |
22 | */ |
23 | package com.github.javaparser; |
24 | |
25 | /** |
26 | * This interface describes a character stream that maintains line and |
27 | * column number positions of the characters. It also has the capability |
28 | * to backup the stream to some extent. An implementation of this |
29 | * interface is used in the TokenManager implementation generated by |
30 | * JavaCCParser. |
31 | * |
32 | * All the methods except backup can be implemented in any fashion. backup |
33 | * needs to be implemented correctly for the correct operation of the lexer. |
34 | * Rest of the methods are all used to get information like line number, |
35 | * column number and the String that constitutes a token and are not used |
36 | * by the lexer. Hence their implementation won't affect the generated lexer's |
37 | * operation. |
38 | */ |
39 | |
40 | public |
41 | interface CharStream { |
42 | /** |
43 | * Get the next character from the selected input. The method |
44 | * of selecting the input is the responsibility of the class |
45 | * implementing this interface. |
46 | * @return the next character from the selected input |
47 | * @throws java.io.IOException on IO error |
48 | */ |
49 | char readChar() throws java.io.IOException; |
50 | |
51 | /** |
52 | * @return the column number of the first character for current token (being |
53 | * matched after the last call to beginToken). |
54 | */ |
55 | int getBeginColumn(); |
56 | |
57 | /** |
58 | * @return the line number of the first character for current token (being |
59 | * matched after the last call to BeginToken). |
60 | */ |
61 | int getBeginLine(); |
62 | |
63 | /** |
64 | * @return the column number of the last character for current token (being |
65 | * matched after the last call to BeginToken). |
66 | */ |
67 | int getEndColumn(); |
68 | |
69 | /** |
70 | * @return the line number of the last character for current token (being |
71 | * matched after the last call to BeginToken). |
72 | */ |
73 | int getEndLine(); |
74 | |
75 | /** |
76 | * Backs up the input stream by amount steps. Lexer calls this method if it |
77 | * had already read some characters, but could not use them to match a |
78 | * (longer) token. So, they will be used again as the prefix of the next |
79 | * token and it is the implemetation's responsibility to do this right. |
80 | * @param amount Number of chars to back up. |
81 | */ |
82 | void backup(int amount); |
83 | |
84 | /** |
85 | * @return the next character that marks the beginning of the next token. |
86 | * All characters must remain in the buffer between two successive calls |
87 | * to this method to implement backup correctly. |
88 | */ |
89 | char beginToken() throws java.io.IOException; |
90 | |
91 | /** |
92 | * @return a string made up of characters from the marked token beginning |
93 | * to the current buffer position. Implementations have the choice of returning |
94 | * anything that they want to. For example, for efficiency, one might decide |
95 | * to just return null, which is a valid implementation. |
96 | */ |
97 | String getImage(); |
98 | |
99 | /** |
100 | * @return an array of characters that make up the suffix of length 'len' for |
101 | * the currently matched token. This is used to build up the matched string |
102 | * for use in actions in the case of MORE. A simple and inefficient |
103 | * implementation of this is as follows: |
104 | * <pre> |
105 | * { |
106 | * String t = getImage(); |
107 | * return t.substring(t.length() - len, t.length()).toCharArray(); |
108 | * } |
109 | * </pre> |
110 | */ |
111 | char[] getSuffix(int len); |
112 | |
113 | /** |
114 | * The lexer calls this function to indicate that it is done with the stream |
115 | * and hence implementations can free any resources held by this class. |
116 | * Again, the body of this function can be just empty and it will not |
117 | * affect the lexer's operation. |
118 | */ |
119 | void done(); |
120 | |
121 | // Getters and setters |
122 | |
123 | /** |
124 | * @return Current tab size. |
125 | */ |
126 | int getTabSize(); |
127 | |
128 | /** |
129 | * Set the tab size to use. |
130 | * @param i spaces per tab |
131 | */ |
132 | void setTabSize(int i); |
133 | |
134 | /** |
135 | * @return <code>true</code> if line number and column numbers should be tracked. |
136 | */ |
137 | boolean isTrackLineColumn(); |
138 | |
139 | /** |
140 | * Enable or disable line number and column number tracking. |
141 | * @param trackLineColumn <code>true</code> to track it, <code>false</code> to not do it. |
142 | */ |
143 | void setTrackLineColumn(boolean trackLineColumn); |
144 | } |
145 | /* ParserGeneratorCC - OriginalChecksum=c86955422d7cadb0ccefa69b833b0cc2 (do not edit this line) */ |
146 |
Members