1
/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 7.0 */
2
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
3
package dk.aau.cs.TCTL.CTLParsing;
6
* An implementation of interface CharStream, where the stream is assumed to
7
* contain only ASCII characters (without unicode processing).
10
public class SimpleCharStream
12
/** Whether parser is static. */
13
public static final boolean staticFlag = false;
17
/** Position in buffer. */
18
public int bufpos = -1;
19
protected int bufline[];
20
protected int bufcolumn[];
22
protected int column = 0;
23
protected int line = 1;
25
protected boolean prevCharIsCR = false;
26
protected boolean prevCharIsLF = false;
28
protected java.io.Reader inputStream;
30
protected char[] buffer;
31
protected int maxNextCharInd = 0;
32
protected int inBuf = 0;
33
protected int tabSize = 1;
34
protected boolean trackLineColumn = true;
36
public void setTabSize(int i) { tabSize = i; }
37
public int getTabSize() { return tabSize; }
41
protected void ExpandBuff(boolean wrapAround)
43
char[] newbuffer = new char[bufsize + 2048];
44
int newbufline[] = new int[bufsize + 2048];
45
int newbufcolumn[] = new int[bufsize + 2048];
51
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
52
System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
55
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
56
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
59
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
60
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
61
bufcolumn = newbufcolumn;
63
maxNextCharInd = (bufpos += (bufsize - tokenBegin));
67
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
70
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
73
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
74
bufcolumn = newbufcolumn;
76
maxNextCharInd = (bufpos -= tokenBegin);
81
throw new Error(t.getMessage());
90
protected void FillBuff() throws java.io.IOException
92
if (maxNextCharInd == available)
94
if (available == bufsize)
96
if (tokenBegin > 2048)
98
bufpos = maxNextCharInd = 0;
99
available = tokenBegin;
101
else if (tokenBegin < 0)
102
bufpos = maxNextCharInd = 0;
106
else if (available > tokenBegin)
108
else if ((tokenBegin - available) < 2048)
111
available = tokenBegin;
116
if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1)
119
throw new java.io.IOException();
125
catch(java.io.IOException e) {
128
if (tokenBegin == -1)
135
public char BeginToken() throws java.io.IOException
144
protected void UpdateLineColumn(char c)
150
prevCharIsLF = false;
151
line += (column = 1);
153
else if (prevCharIsCR)
155
prevCharIsCR = false;
161
line += (column = 1);
174
column += (tabSize - (column % tabSize));
180
bufline[bufpos] = line;
181
bufcolumn[bufpos] = column;
184
/** Read a character. */
185
public char readChar() throws java.io.IOException
191
if (++bufpos == bufsize)
194
return buffer[bufpos];
197
if (++bufpos >= maxNextCharInd)
200
char c = buffer[bufpos];
212
public int getColumn() {
213
return bufcolumn[bufpos];
222
public int getLine() {
223
return bufline[bufpos];
226
/** Get token end column number. */
227
public int getEndColumn() {
228
return bufcolumn[bufpos];
231
/** Get token end line number. */
232
public int getEndLine() {
233
return bufline[bufpos];
236
/** Get token beginning column number. */
237
public int getBeginColumn() {
238
return bufcolumn[tokenBegin];
241
/** Get token beginning line number. */
242
public int getBeginLine() {
243
return bufline[tokenBegin];
246
/** Backup a number of characters. */
247
public void backup(int amount) {
250
if ((bufpos -= amount) < 0)
255
public SimpleCharStream(java.io.Reader dstream, int startline,
256
int startcolumn, int buffersize)
258
inputStream = dstream;
260
column = startcolumn - 1;
262
available = bufsize = buffersize;
263
buffer = new char[buffersize];
264
bufline = new int[buffersize];
265
bufcolumn = new int[buffersize];
269
public SimpleCharStream(java.io.Reader dstream, int startline,
272
this(dstream, startline, startcolumn, 4096);
276
public SimpleCharStream(java.io.Reader dstream)
278
this(dstream, 1, 1, 4096);
282
public void ReInit(java.io.Reader dstream, int startline,
283
int startcolumn, int buffersize)
285
inputStream = dstream;
287
column = startcolumn - 1;
289
if (buffer == null || buffersize != buffer.length)
291
available = bufsize = buffersize;
292
buffer = new char[buffersize];
293
bufline = new int[buffersize];
294
bufcolumn = new int[buffersize];
296
prevCharIsLF = prevCharIsCR = false;
297
tokenBegin = inBuf = maxNextCharInd = 0;
302
public void ReInit(java.io.Reader dstream, int startline,
305
ReInit(dstream, startline, startcolumn, 4096);
309
public void ReInit(java.io.Reader dstream)
311
ReInit(dstream, 1, 1, 4096);
314
public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
315
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
317
this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
321
public SimpleCharStream(java.io.InputStream dstream, int startline,
322
int startcolumn, int buffersize)
324
this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
328
public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
329
int startcolumn) throws java.io.UnsupportedEncodingException
331
this(dstream, encoding, startline, startcolumn, 4096);
335
public SimpleCharStream(java.io.InputStream dstream, int startline,
338
this(dstream, startline, startcolumn, 4096);
342
public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
344
this(dstream, encoding, 1, 1, 4096);
348
public SimpleCharStream(java.io.InputStream dstream)
350
this(dstream, 1, 1, 4096);
354
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
355
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
357
ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
361
public void ReInit(java.io.InputStream dstream, int startline,
362
int startcolumn, int buffersize)
364
ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
368
public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
370
ReInit(dstream, encoding, 1, 1, 4096);
374
public void ReInit(java.io.InputStream dstream)
376
ReInit(dstream, 1, 1, 4096);
379
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
380
int startcolumn) throws java.io.UnsupportedEncodingException
382
ReInit(dstream, encoding, startline, startcolumn, 4096);
385
public void ReInit(java.io.InputStream dstream, int startline,
388
ReInit(dstream, startline, startcolumn, 4096);
390
/** Get token literal value. */
391
public String GetImage()
393
if (bufpos >= tokenBegin)
394
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
396
return new String(buffer, tokenBegin, bufsize - tokenBegin) +
397
new String(buffer, 0, bufpos + 1);
400
/** Get the suffix. */
401
public char[] GetSuffix(int len)
403
char[] ret = new char[len];
405
if ((bufpos + 1) >= len)
406
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
409
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
411
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
417
/** Reset buffer when finished. */
426
* Method to adjust line and column numbers for the start of a token.
428
public void adjustBeginLineColumn(int newLine, int newCol)
430
int start = tokenBegin;
433
if (bufpos >= tokenBegin)
435
len = bufpos - tokenBegin + inBuf + 1;
439
len = bufsize - tokenBegin + bufpos + 1 + inBuf;
442
int i = 0, j = 0, k = 0;
443
int nextColDiff = 0, columnDiff = 0;
445
while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
447
bufline[j] = newLine;
448
nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
449
bufcolumn[j] = newCol + columnDiff;
450
columnDiff = nextColDiff;
456
bufline[j] = newLine++;
457
bufcolumn[j] = newCol + columnDiff;
461
if (bufline[j = start % bufsize] != bufline[++start % bufsize])
462
bufline[j] = newLine++;
464
bufline[j] = newLine;
469
column = bufcolumn[j];
471
boolean getTrackLineColumn() { return trackLineColumn; }
472
void setTrackLineColumn(boolean tlc) { trackLineColumn = tlc; }
474
/* JavaCC - OriginalChecksum=3bfee23fa238f42634d20b3466c7eaef (do not edit this line) */