Debian Codegraph @

Source/Parser/FunctionalJAVACC/CharStream.h

raw
1 /* Generated By:JavaCC: Do not edit this line. CharStream.h Version 6.0 */
2 /* JavaCCOptions:STATIC=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
3 #ifndef CHARSTREAM_H
4 #define CHARSTREAM_H
5 #include "JavaCC.h"
6
7 #ifndef INITIAL_BUFFER_SIZE
8 #define INITIAL_BUFFER_SIZE 4096
9 #endif
10
11 namespace Konclude {
12 namespace Parser {
13 namespace FunctionalJAVACC {
14
15 /**
16 * This class describes a character stream that maintains line and
17 * column number positions of the characters. It also has the capability
18 * to backup the stream to some extent. An implementation of this
19 * class is used in the TokenManager implementation generated by
20 * JavaCCParser.
21 *
22 * All the methods except backup can be implemented in any fashion. backup
23 * needs to be implemented correctly for the correct operation of the lexer.
24 * Rest of the methods are all used to get information like line number,
25 * column number and the string that constitutes a token and are not used
26 * by the lexer. Hence their implementation won't affect the generated lexer's
27 * operation.
28 */
29
30
31 class CharStream {
32 public:
33 void setTabSize(int i) { tabSize = i; }
34 int getTabSize(int i) { return tabSize; }
35 virtual int getColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
36 virtual int getLine() { return trackLineColumn ? bufline[bufpos] : -1; }
37 virtual int getEndColumn() { return trackLineColumn ? bufcolumn[bufpos] : -1; }
38 virtual int getEndLine() { return trackLineColumn ? bufline[bufpos] : -1; }
39 virtual int getBeginColumn() { return trackLineColumn ? bufcolumn[tokenBegin] : -1; }
40 virtual int getBeginLine() { return trackLineColumn ? bufline[tokenBegin] : -1; }
41
42 virtual bool getTrackLineColumn() { return trackLineColumn; }
43 virtual void setTrackLineColumn(bool val) { trackLineColumn = val; }
44
45 /**
46 * Backs up the input stream by amount steps. Lexer calls this method if it
47 * had already read some characters, but could not use them to match a
48 * (longer) token. So, they will be used again as the prefix of the next
49 * token and it is the implemetation's responsibility to do this right.
50 */
51 virtual inline void backup(int amount) {
52 inBuf += amount;
53 bufpos -= amount;
54 if (bufpos < 0) {
55 bufpos += bufsize;
56 }
57 }
58
59 /**
60 * Returns the next character that marks the beginning of the next token.
61 * All characters must remain in the buffer between two successive calls
62 * to this method to implement backup correctly.
63 */
64 virtual inline JAVACC_CHAR_TYPE BeginToken() {
65 tokenBegin = -1;
66 JAVACC_CHAR_TYPE c = readChar();
67 tokenBegin = bufpos;
68 return c;
69 }
70
71
72 /**
73 * Returns the next character from the selected input. The method
74 * of selecting the input is the responsibility of the class
75 * implementing this class.
76 */
77 virtual inline JAVACC_CHAR_TYPE readChar() {
78 if (inBuf > 0) {
79 --inBuf;
80 ++bufpos;
81 if (bufpos == bufsize) {
82 bufpos = 0;
83 }
84
85 return buffer[bufpos];
86 }
87
88 ++bufpos;
89 if (bufpos >= maxNextCharInd) {
90 FillBuff();
91 }
92
93 JAVACC_CHAR_TYPE c = buffer[bufpos];
94
95 if (trackLineColumn) {
96 UpdateLineColumn(c);
97 }
98
99 return c;
100 }
101
102
103 virtual void ExpandBuff(bool wrapAround);
104 virtual void FillBuff();
105
106 /**
107 * Returns a string made up of characters from the marked token beginning
108 * to the current buffer position. Implementations can return
109 * anything that they want to. For example, for efficiency, one might decide
110 * to just return NULL, which is a valid implementation.
111 */
112 virtual JAVACC_STRING_TYPE GetImage() {
113 if (bufpos >= tokenBegin)
114 return JAVACC_STRING_TYPE(buffer + tokenBegin, bufpos - tokenBegin + 1);
115 else
116 return JAVACC_STRING_TYPE(buffer + tokenBegin, bufsize - tokenBegin)
117 .append(buffer, bufpos + 1);
118 }
119
120 /**
121 * Returns an array of characters that make up the suffix of length 'len' for
122 * the currently matched token. This is used to build up the matched string
123 * for use in actions in the case of MORE. A simple and inefficient
124 * implementation of this is as follows :
125 */
126 virtual JAVACC_STRING_TYPE GetSuffix(int len) {
127 if ((bufpos + 1) >= len) {
128 return JAVACC_STRING_TYPE(buffer + bufpos - len + 1, len);
129 }
130 return JAVACC_STRING_TYPE(buffer + bufsize - (len - bufpos - 1), len - bufpos - 1)
131 .append(buffer, bufpos + 1);
132 }
133
134 /**
135 * The lexer calls this function to indicate that it is done with the stream
136 * and hence implementations can free any resources held by this class.
137 */
138 virtual void DeleteBuffers();
139
140 virtual ~CharStream() {
141 if (deleteStream) {
142 delete inputStream;
143 }
144 DeleteBuffers();
145 }
146
147 bool endOfInput() {
148 return inBuf == 0 && bufpos + 1 >= maxNextCharInd &&
149 inputStream->endOfInput();
150 }
151
152 CharStream(const JAVACC_CHAR_TYPE *buf, int sz, int startline,
153 int startcolumn, int buffersize) :
154 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
155 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
156 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
157 inBuf(0),tabSize(8), trackLineColumn(true) {
158 ReInit(JAVACC_STRING_TYPE(buf, sz), startline, startcolumn, buffersize);
159 }
160
161 CharStream(const JAVACC_CHAR_TYPE *buf, int sz, int startline, int startcolumn) :
162 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
163 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
164 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
165 inBuf(0),tabSize(8), trackLineColumn(true) {
166 ReInit(JAVACC_STRING_TYPE(buf, sz), startline, startcolumn, INITIAL_BUFFER_SIZE);
167 }
168
169 CharStream(const JAVACC_STRING_TYPE& str, int startline,
170 int startcolumn, int buffersize) :
171 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
172 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
173 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
174 inBuf(0),tabSize(8), trackLineColumn(true) {
175 ReInit(str, startline, startcolumn, buffersize);
176 }
177
178 CharStream(const JAVACC_STRING_TYPE& str, int startline, int startcolumn) :
179 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
180 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
181 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
182 inBuf(0) ,tabSize(8), trackLineColumn(true){
183 ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
184 }
185
186 CharStream(ReaderStream *input_stream, int startline,
187 int startcolumn, int buffersize) :
188 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
189 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
190 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
191 inBuf(0),tabSize(8), trackLineColumn(true) {
192 ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
193 }
194
195 CharStream(ReaderStream *input_stream, int startline, int startcolumn) :
196 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
197 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
198 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
199 inBuf(0),tabSize(8), trackLineColumn(true) {
200 ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
201 }
202
203 CharStream(ReaderStream *input_stream) :
204 bufline(NULL), bufcolumn(NULL), inputStream(NULL), deleteStream(false),
205 buffer(NULL), bufpos(0), bufsize(0), tokenBegin(0), column(0), line(0),
206 prevCharIsCR (false), prevCharIsLF (false), available(0), maxNextCharInd(0),
207 inBuf(0),tabSize(8), trackLineColumn(true) {
208 ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
209 }
210
211 virtual void ReInit(ReaderStream *input_stream, int startline, int startcolumn,
212 int buffersize);
213
214 virtual void ReInit(ReaderStream *input_stream, int startline,
215 int startcolumn) {
216 ReInit(input_stream, startline, startcolumn, INITIAL_BUFFER_SIZE);
217 }
218
219 virtual void ReInit(ReaderStream *input_stream) {
220 ReInit(input_stream, 1, 1, INITIAL_BUFFER_SIZE);
221 }
222
223 virtual void ReInit(const JAVACC_STRING_TYPE& str, int startline,
224 int startcolumn, int buffersize);
225
226 virtual void ReInit(const JAVACC_STRING_TYPE& str, int startline,
227 int startcolumn) {
228 ReInit(str, startline, startcolumn, INITIAL_BUFFER_SIZE);
229 }
230
231 virtual void adjustBeginLineColumn(int newLine, int newCol);
232
233 protected:
234 virtual void UpdateLineColumn(JAVACC_CHAR_TYPE c);
235
236 int *bufline;
237 int *bufcolumn;
238 ReaderStream *inputStream;
239 bool deleteStream;
240 JAVACC_CHAR_TYPE * buffer;
241 int bufpos;
242 int bufsize;
243 int tokenBegin;
244 int column;
245 int line;
246 bool prevCharIsCR ;
247 bool prevCharIsLF ;
248 int available;
249 int maxNextCharInd;
250 int inBuf ;
251 int tabSize ;
252 bool trackLineColumn;
253 };
254
255 }
256 }
257 }
258 #endif
259 /* JavaCC - OriginalChecksum=d6c3255521401b0bb10012ce9bd724db (do not edit this line) */