aboutsummaryrefslogtreecommitdiff
path: root/src/monkey/seaspider/org/gnunet/seaspider/parser/SimpleCharStream.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/monkey/seaspider/org/gnunet/seaspider/parser/SimpleCharStream.java')
-rw-r--r--src/monkey/seaspider/org/gnunet/seaspider/parser/SimpleCharStream.java470
1 files changed, 470 insertions, 0 deletions
diff --git a/src/monkey/seaspider/org/gnunet/seaspider/parser/SimpleCharStream.java b/src/monkey/seaspider/org/gnunet/seaspider/parser/SimpleCharStream.java
new file mode 100644
index 000000000..8f115d519
--- /dev/null
+++ b/src/monkey/seaspider/org/gnunet/seaspider/parser/SimpleCharStream.java
@@ -0,0 +1,470 @@
1package org.gnunet.seaspider.parser;
2/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */
3/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
4/**
5 * An implementation of interface CharStream, where the stream is assumed to
6 * contain only ASCII characters (without unicode processing).
7 */
8
9public class SimpleCharStream
10{
11/** Whether parser is static. */
12 public static final boolean staticFlag = false;
13 int bufsize;
14 int available;
15 int tokenBegin;
16/** Position in buffer. */
17 public int bufpos = -1;
18 protected int bufline[];
19 protected int bufcolumn[];
20
21 protected int column = 0;
22 protected int line = 1;
23
24 protected boolean prevCharIsCR = false;
25 protected boolean prevCharIsLF = false;
26
27 protected java.io.Reader inputStream;
28
29 protected char[] buffer;
30 protected int maxNextCharInd = 0;
31 protected int inBuf = 0;
32 protected int tabSize = 8;
33
34 protected void setTabSize(int i) { tabSize = i; }
35 protected int getTabSize(int i) { return tabSize; }
36
37
38 protected void ExpandBuff(boolean wrapAround)
39 {
40 char[] newbuffer = new char[bufsize + 2048];
41 int newbufline[] = new int[bufsize + 2048];
42 int newbufcolumn[] = new int[bufsize + 2048];
43
44 try
45 {
46 if (wrapAround)
47 {
48 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
49 System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
50 buffer = newbuffer;
51
52 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
53 System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
54 bufline = newbufline;
55
56 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
57 System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
58 bufcolumn = newbufcolumn;
59
60 maxNextCharInd = (bufpos += (bufsize - tokenBegin));
61 }
62 else
63 {
64 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
65 buffer = newbuffer;
66
67 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
68 bufline = newbufline;
69
70 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
71 bufcolumn = newbufcolumn;
72
73 maxNextCharInd = (bufpos -= tokenBegin);
74 }
75 }
76 catch (Throwable t)
77 {
78 throw new Error(t.getMessage());
79 }
80
81
82 bufsize += 2048;
83 available = bufsize;
84 tokenBegin = 0;
85 }
86
87 protected void FillBuff() throws java.io.IOException
88 {
89 if (maxNextCharInd == available)
90 {
91 if (available == bufsize)
92 {
93 if (tokenBegin > 2048)
94 {
95 bufpos = maxNextCharInd = 0;
96 available = tokenBegin;
97 }
98 else if (tokenBegin < 0)
99 bufpos = maxNextCharInd = 0;
100 else
101 ExpandBuff(false);
102 }
103 else if (available > tokenBegin)
104 available = bufsize;
105 else if ((tokenBegin - available) < 2048)
106 ExpandBuff(true);
107 else
108 available = tokenBegin;
109 }
110
111 int i;
112 try {
113 if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1)
114 {
115 inputStream.close();
116 throw new java.io.IOException();
117 }
118 else
119 maxNextCharInd += i;
120 return;
121 }
122 catch(java.io.IOException e) {
123 --bufpos;
124 backup(0);
125 if (tokenBegin == -1)
126 tokenBegin = bufpos;
127 throw e;
128 }
129 }
130
131/** Start. */
132 public char BeginToken() throws java.io.IOException
133 {
134 tokenBegin = -1;
135 char c = readChar();
136 tokenBegin = bufpos;
137
138 return c;
139 }
140
141 protected void UpdateLineColumn(char c)
142 {
143 column++;
144
145 if (prevCharIsLF)
146 {
147 prevCharIsLF = false;
148 line += (column = 1);
149 }
150 else if (prevCharIsCR)
151 {
152 prevCharIsCR = false;
153 if (c == '\n')
154 {
155 prevCharIsLF = true;
156 }
157 else
158 line += (column = 1);
159 }
160
161 switch (c)
162 {
163 case '\r' :
164 prevCharIsCR = true;
165 break;
166 case '\n' :
167 prevCharIsLF = true;
168 break;
169 case '\t' :
170 column--;
171 column += (tabSize - (column % tabSize));
172 break;
173 default :
174 break;
175 }
176
177 bufline[bufpos] = line;
178 bufcolumn[bufpos] = column;
179 }
180
181/** Read a character. */
182 public char readChar() throws java.io.IOException
183 {
184 if (inBuf > 0)
185 {
186 --inBuf;
187
188 if (++bufpos == bufsize)
189 bufpos = 0;
190
191 return buffer[bufpos];
192 }
193
194 if (++bufpos >= maxNextCharInd)
195 FillBuff();
196
197 char c = buffer[bufpos];
198
199 UpdateLineColumn(c);
200 return c;
201 }
202
203 @Deprecated
204 /**
205 * @deprecated
206 * @see #getEndColumn
207 */
208
209 public int getColumn() {
210 return bufcolumn[bufpos];
211 }
212
213 @Deprecated
214 /**
215 * @deprecated
216 * @see #getEndLine
217 */
218
219 public int getLine() {
220 return bufline[bufpos];
221 }
222
223 /** Get token end column number. */
224 public int getEndColumn() {
225 return bufcolumn[bufpos];
226 }
227
228 /** Get token end line number. */
229 public int getEndLine() {
230 return bufline[bufpos];
231 }
232
233 /** Get token beginning column number. */
234 public int getBeginColumn() {
235 return bufcolumn[tokenBegin];
236 }
237
238 /** Get token beginning line number. */
239 public int getBeginLine() {
240 return bufline[tokenBegin];
241 }
242
243/** Backup a number of characters. */
244 public void backup(int amount) {
245
246 inBuf += amount;
247 if ((bufpos -= amount) < 0)
248 bufpos += bufsize;
249 }
250
251 /** Constructor. */
252 public SimpleCharStream(java.io.Reader dstream, int startline,
253 int startcolumn, int buffersize)
254 {
255 inputStream = dstream;
256 line = startline;
257 column = startcolumn - 1;
258
259 available = bufsize = buffersize;
260 buffer = new char[buffersize];
261 bufline = new int[buffersize];
262 bufcolumn = new int[buffersize];
263 }
264
265 /** Constructor. */
266 public SimpleCharStream(java.io.Reader dstream, int startline,
267 int startcolumn)
268 {
269 this(dstream, startline, startcolumn, 4096);
270 }
271
272 /** Constructor. */
273 public SimpleCharStream(java.io.Reader dstream)
274 {
275 this(dstream, 1, 1, 4096);
276 }
277
278 /** Reinitialise. */
279 public void ReInit(java.io.Reader dstream, int startline,
280 int startcolumn, int buffersize)
281 {
282 inputStream = dstream;
283 line = startline;
284 column = startcolumn - 1;
285
286 if (buffer == null || buffersize != buffer.length)
287 {
288 available = bufsize = buffersize;
289 buffer = new char[buffersize];
290 bufline = new int[buffersize];
291 bufcolumn = new int[buffersize];
292 }
293 prevCharIsLF = prevCharIsCR = false;
294 tokenBegin = inBuf = maxNextCharInd = 0;
295 bufpos = -1;
296 }
297
298 /** Reinitialise. */
299 public void ReInit(java.io.Reader dstream, int startline,
300 int startcolumn)
301 {
302 ReInit(dstream, startline, startcolumn, 4096);
303 }
304
305 /** Reinitialise. */
306 public void ReInit(java.io.Reader dstream)
307 {
308 ReInit(dstream, 1, 1, 4096);
309 }
310 /** Constructor. */
311 public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
312 int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
313 {
314 this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
315 }
316
317 /** Constructor. */
318 public SimpleCharStream(java.io.InputStream dstream, int startline,
319 int startcolumn, int buffersize)
320 {
321 this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
322 }
323
324 /** Constructor. */
325 public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
326 int startcolumn) throws java.io.UnsupportedEncodingException
327 {
328 this(dstream, encoding, startline, startcolumn, 4096);
329 }
330
331 /** Constructor. */
332 public SimpleCharStream(java.io.InputStream dstream, int startline,
333 int startcolumn)
334 {
335 this(dstream, startline, startcolumn, 4096);
336 }
337
338 /** Constructor. */
339 public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
340 {
341 this(dstream, encoding, 1, 1, 4096);
342 }
343
344 /** Constructor. */
345 public SimpleCharStream(java.io.InputStream dstream)
346 {
347 this(dstream, 1, 1, 4096);
348 }
349
350 /** Reinitialise. */
351 public void ReInit(java.io.InputStream dstream, String encoding, int startline,
352 int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
353 {
354 ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
355 }
356
357 /** Reinitialise. */
358 public void ReInit(java.io.InputStream dstream, int startline,
359 int startcolumn, int buffersize)
360 {
361 ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
362 }
363
364 /** Reinitialise. */
365 public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
366 {
367 ReInit(dstream, encoding, 1, 1, 4096);
368 }
369
370 /** Reinitialise. */
371 public void ReInit(java.io.InputStream dstream)
372 {
373 ReInit(dstream, 1, 1, 4096);
374 }
375 /** Reinitialise. */
376 public void ReInit(java.io.InputStream dstream, String encoding, int startline,
377 int startcolumn) throws java.io.UnsupportedEncodingException
378 {
379 ReInit(dstream, encoding, startline, startcolumn, 4096);
380 }
381 /** Reinitialise. */
382 public void ReInit(java.io.InputStream dstream, int startline,
383 int startcolumn)
384 {
385 ReInit(dstream, startline, startcolumn, 4096);
386 }
387 /** Get token literal value. */
388 public String GetImage()
389 {
390 if (bufpos >= tokenBegin)
391 return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
392 else
393 return new String(buffer, tokenBegin, bufsize - tokenBegin) +
394 new String(buffer, 0, bufpos + 1);
395 }
396
397 /** Get the suffix. */
398 public char[] GetSuffix(int len)
399 {
400 char[] ret = new char[len];
401
402 if ((bufpos + 1) >= len)
403 System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
404 else
405 {
406 System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
407 len - bufpos - 1);
408 System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
409 }
410
411 return ret;
412 }
413
414 /** Reset buffer when finished. */
415 public void Done()
416 {
417 buffer = null;
418 bufline = null;
419 bufcolumn = null;
420 }
421
422 /**
423 * Method to adjust line and column numbers for the start of a token.
424 */
425 public void adjustBeginLineColumn(int newLine, int newCol)
426 {
427 int start = tokenBegin;
428 int len;
429
430 if (bufpos >= tokenBegin)
431 {
432 len = bufpos - tokenBegin + inBuf + 1;
433 }
434 else
435 {
436 len = bufsize - tokenBegin + bufpos + 1 + inBuf;
437 }
438
439 int i = 0, j = 0, k = 0;
440 int nextColDiff = 0, columnDiff = 0;
441
442 while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
443 {
444 bufline[j] = newLine;
445 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
446 bufcolumn[j] = newCol + columnDiff;
447 columnDiff = nextColDiff;
448 i++;
449 }
450
451 if (i < len)
452 {
453 bufline[j] = newLine++;
454 bufcolumn[j] = newCol + columnDiff;
455
456 while (i++ < len)
457 {
458 if (bufline[j = start % bufsize] != bufline[++start % bufsize])
459 bufline[j] = newLine++;
460 else
461 bufline[j] = newLine;
462 }
463 }
464
465 line = bufline[j];
466 column = bufcolumn[j];
467 }
468
469}
470/* JavaCC - OriginalChecksum=b0bce35239226f00f9dd0fa14ab3ad17 (do not edit this line) */