1
/* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 4.1 */
2
/* JavaCCOptions:STATIC=false */
3
package org.apache.lucene.queryParser.standard.parser;
6
* An implementation of interface CharStream, where the stream is assumed to
7
* contain only ASCII characters (with java-like unicode escape processing).
10
public class JavaCharStream
12
/** Whether parser is static. */
13
public static final boolean staticFlag = false;
14
static final int hexval(char c) throws java.io.IOException {
58
throw new java.io.IOException(); // Should never come here
61
/** Position in buffer. */
62
public int bufpos = -1;
66
protected int bufline[];
67
protected int bufcolumn[];
69
protected int column = 0;
70
protected int line = 1;
72
protected boolean prevCharIsCR = false;
73
protected boolean prevCharIsLF = false;
75
protected java.io.Reader inputStream;
77
protected char[] nextCharBuf;
78
protected char[] buffer;
79
protected int maxNextCharInd = 0;
80
protected int nextCharInd = -1;
81
protected int inBuf = 0;
82
protected int tabSize = 8;
84
protected void setTabSize(int i) { tabSize = i; }
85
protected int getTabSize(int i) { return tabSize; }
87
protected void ExpandBuff(boolean wrapAround)
89
char[] newbuffer = new char[bufsize + 2048];
90
int newbufline[] = new int[bufsize + 2048];
91
int newbufcolumn[] = new int[bufsize + 2048];
97
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
98
System.arraycopy(buffer, 0, newbuffer,
99
bufsize - tokenBegin, bufpos);
102
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
103
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
104
bufline = newbufline;
106
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
107
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
108
bufcolumn = newbufcolumn;
110
bufpos += (bufsize - tokenBegin);
114
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
117
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
118
bufline = newbufline;
120
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
121
bufcolumn = newbufcolumn;
123
bufpos -= tokenBegin;
128
throw new Error(t.getMessage());
131
available = (bufsize += 2048);
135
protected void FillBuff() throws java.io.IOException
138
if (maxNextCharInd == 4096)
139
maxNextCharInd = nextCharInd = 0;
142
if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
143
4096 - maxNextCharInd)) == -1)
146
throw new java.io.IOException();
152
catch(java.io.IOException e) {
160
bufline[bufpos] = line;
161
bufcolumn[bufpos] = column;
167
protected char ReadByte() throws java.io.IOException
169
if (++nextCharInd >= maxNextCharInd)
172
return nextCharBuf[nextCharInd];
175
/** @return starting character for token. */
176
public char BeginToken() throws java.io.IOException
182
if (++bufpos == bufsize)
186
return buffer[bufpos];
195
protected void AdjustBuffSize()
197
if (available == bufsize)
199
if (tokenBegin > 2048)
202
available = tokenBegin;
207
else if (available > tokenBegin)
209
else if ((tokenBegin - available) < 2048)
212
available = tokenBegin;
215
protected void UpdateLineColumn(char c)
221
prevCharIsLF = false;
222
line += (column = 1);
224
else if (prevCharIsCR)
226
prevCharIsCR = false;
232
line += (column = 1);
245
column += (tabSize - (column % tabSize));
251
bufline[bufpos] = line;
252
bufcolumn[bufpos] = column;
255
/** Read a character. */
256
public char readChar() throws java.io.IOException
262
if (++bufpos == bufsize)
265
return buffer[bufpos];
270
if (++bufpos == available)
273
if ((buffer[bufpos] = c = ReadByte()) == '\\')
277
int backSlashCnt = 1;
279
for (;;) // Read all the backslashes
281
if (++bufpos == available)
286
if ((buffer[bufpos] = c = ReadByte()) != '\\')
289
// found a non-backslash char.
290
if ((c == 'u') && ((backSlashCnt & 1) == 1))
293
bufpos = bufsize - 1;
298
backup(backSlashCnt);
302
catch(java.io.IOException e)
304
if (backSlashCnt > 1)
305
backup(backSlashCnt-1);
314
// Here, we have seen an odd number of backslash's followed by a 'u'
317
while ((c = ReadByte()) == 'u')
320
buffer[bufpos] = c = (char)(hexval(c) << 12 |
321
hexval(ReadByte()) << 8 |
322
hexval(ReadByte()) << 4 |
327
catch(java.io.IOException e)
329
throw new Error("Invalid escape character at line " + line +
330
" column " + column + ".");
333
if (backSlashCnt == 1)
337
backup(backSlashCnt - 1);
353
public int getColumn() {
354
return bufcolumn[bufpos];
362
public int getLine() {
363
return bufline[bufpos];
366
/** Get end column. */
367
public int getEndColumn() {
368
return bufcolumn[bufpos];
372
public int getEndLine() {
373
return bufline[bufpos];
376
/** @return column of token start */
377
public int getBeginColumn() {
378
return bufcolumn[tokenBegin];
381
/** @return line number of token start */
382
public int getBeginLine() {
383
return bufline[tokenBegin];
387
public void backup(int amount) {
390
if ((bufpos -= amount) < 0)
395
public JavaCharStream(java.io.Reader dstream,
396
int startline, int startcolumn, int buffersize)
398
inputStream = dstream;
400
column = startcolumn - 1;
402
available = bufsize = buffersize;
403
buffer = new char[buffersize];
404
bufline = new int[buffersize];
405
bufcolumn = new int[buffersize];
406
nextCharBuf = new char[4096];
410
public JavaCharStream(java.io.Reader dstream,
411
int startline, int startcolumn)
413
this(dstream, startline, startcolumn, 4096);
417
public JavaCharStream(java.io.Reader dstream)
419
this(dstream, 1, 1, 4096);
422
public void ReInit(java.io.Reader dstream,
423
int startline, int startcolumn, int buffersize)
425
inputStream = dstream;
427
column = startcolumn - 1;
429
if (buffer == null || buffersize != buffer.length)
431
available = bufsize = buffersize;
432
buffer = new char[buffersize];
433
bufline = new int[buffersize];
434
bufcolumn = new int[buffersize];
435
nextCharBuf = new char[4096];
437
prevCharIsLF = prevCharIsCR = false;
438
tokenBegin = inBuf = maxNextCharInd = 0;
439
nextCharInd = bufpos = -1;
443
public void ReInit(java.io.Reader dstream,
444
int startline, int startcolumn)
446
ReInit(dstream, startline, startcolumn, 4096);
450
public void ReInit(java.io.Reader dstream)
452
ReInit(dstream, 1, 1, 4096);
455
public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
456
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
458
this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
462
public JavaCharStream(java.io.InputStream dstream, int startline,
463
int startcolumn, int buffersize)
465
this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
469
public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
470
int startcolumn) throws java.io.UnsupportedEncodingException
472
this(dstream, encoding, startline, startcolumn, 4096);
476
public JavaCharStream(java.io.InputStream dstream, int startline,
479
this(dstream, startline, startcolumn, 4096);
483
public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
485
this(dstream, encoding, 1, 1, 4096);
489
public JavaCharStream(java.io.InputStream dstream)
491
this(dstream, 1, 1, 4096);
495
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
496
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
498
ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
502
public void ReInit(java.io.InputStream dstream, int startline,
503
int startcolumn, int buffersize)
505
ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
508
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
509
int startcolumn) throws java.io.UnsupportedEncodingException
511
ReInit(dstream, encoding, startline, startcolumn, 4096);
514
public void ReInit(java.io.InputStream dstream, int startline,
517
ReInit(dstream, startline, startcolumn, 4096);
520
public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
522
ReInit(dstream, encoding, 1, 1, 4096);
526
public void ReInit(java.io.InputStream dstream)
528
ReInit(dstream, 1, 1, 4096);
531
/** @return token image as String */
532
public String GetImage()
534
if (bufpos >= tokenBegin)
535
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
537
return new String(buffer, tokenBegin, bufsize - tokenBegin) +
538
new String(buffer, 0, bufpos + 1);
541
/** @return suffix */
542
public char[] GetSuffix(int len)
544
char[] ret = new char[len];
546
if ((bufpos + 1) >= len)
547
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
550
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
552
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
558
/** Set buffers back to null when finished. */
568
* Method to adjust line and column numbers for the start of a token.
570
public void adjustBeginLineColumn(int newLine, int newCol)
572
int start = tokenBegin;
575
if (bufpos >= tokenBegin)
577
len = bufpos - tokenBegin + inBuf + 1;
581
len = bufsize - tokenBegin + bufpos + 1 + inBuf;
584
int i = 0, j = 0, k = 0;
585
int nextColDiff = 0, columnDiff = 0;
588
bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
590
bufline[j] = newLine;
591
nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
592
bufcolumn[j] = newCol + columnDiff;
593
columnDiff = nextColDiff;
599
bufline[j] = newLine++;
600
bufcolumn[j] = newCol + columnDiff;
604
if (bufline[j = start % bufsize] != bufline[++start % bufsize])
605
bufline[j] = newLine++;
607
bufline[j] = newLine;
612
column = bufcolumn[j];
616
/* JavaCC - OriginalChecksum=f19c73b8f7faf94cc4a581e7b2933cc6 (do not edit this line) */