001/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 6.0 */ 002/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ 003package org.dllearner.confparser; 004 005/** 006 * An implementation of interface CharStream, where the stream is assumed to 007 * contain only ASCII characters (without unicode processing). 008 */ 009 010public class SimpleCharStream 011{ 012/** Whether parser is static. */ 013 public static final boolean staticFlag = false; 014 int bufsize; 015 int available; 016 int tokenBegin; 017/** Position in buffer. */ 018 public int bufpos = -1; 019 protected int bufline[]; 020 protected int bufcolumn[]; 021 022 protected int column = 0; 023 protected int line = 1; 024 025 protected boolean prevCharIsCR = false; 026 protected boolean prevCharIsLF = false; 027 028 protected java.io.Reader inputStream; 029 030 protected char[] buffer; 031 protected int maxNextCharInd = 0; 032 protected int inBuf = 0; 033 protected int tabSize = 8; 034 protected boolean trackLineColumn = true; 035 036 public void setTabSize(int i) { tabSize = i; } 037 public int getTabSize() { return tabSize; } 038 039 040 protected void ExpandBuff(boolean wrapAround) 041 { 042 char[] newbuffer = new char[bufsize + 2048]; 043 int newbufline[] = new int[bufsize + 2048]; 044 int newbufcolumn[] = new int[bufsize + 2048]; 045 046 try 047 { 048 if (wrapAround) 049 { 050 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); 051 System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); 052 buffer = newbuffer; 053 054 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); 055 System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); 056 bufline = newbufline; 057 058 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); 059 System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); 060 bufcolumn = newbufcolumn; 061 062 maxNextCharInd = (bufpos += (bufsize - tokenBegin)); 063 } 064 else 065 { 066 System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); 067 buffer = newbuffer; 068 069 System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); 070 bufline = newbufline; 071 072 System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); 073 bufcolumn = newbufcolumn; 074 075 maxNextCharInd = (bufpos -= tokenBegin); 076 } 077 } 078 catch (Throwable t) 079 { 080 throw new Error(t.getMessage()); 081 } 082 083 084 bufsize += 2048; 085 available = bufsize; 086 tokenBegin = 0; 087 } 088 089 protected void FillBuff() throws java.io.IOException 090 { 091 if (maxNextCharInd == available) 092 { 093 if (available == bufsize) 094 { 095 if (tokenBegin > 2048) 096 { 097 bufpos = maxNextCharInd = 0; 098 available = tokenBegin; 099 } 100 else if (tokenBegin < 0) 101 bufpos = maxNextCharInd = 0; 102 else 103 ExpandBuff(false); 104 } 105 else if (available > tokenBegin) 106 available = bufsize; 107 else if ((tokenBegin - available) < 2048) 108 ExpandBuff(true); 109 else 110 available = tokenBegin; 111 } 112 113 int i; 114 try { 115 if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) 116 { 117 inputStream.close(); 118 throw new java.io.IOException(); 119 } 120 else 121 maxNextCharInd += i; 122 return; 123 } 124 catch(java.io.IOException e) { 125 --bufpos; 126 backup(0); 127 if (tokenBegin == -1) 128 tokenBegin = bufpos; 129 throw e; 130 } 131 } 132 133/** Start. */ 134 public char BeginToken() throws java.io.IOException 135 { 136 tokenBegin = -1; 137 char c = readChar(); 138 tokenBegin = bufpos; 139 140 return c; 141 } 142 143 protected void UpdateLineColumn(char c) 144 { 145 column++; 146 147 if (prevCharIsLF) 148 { 149 prevCharIsLF = false; 150 line += (column = 1); 151 } 152 else if (prevCharIsCR) 153 { 154 prevCharIsCR = false; 155 if (c == '\n') 156 { 157 prevCharIsLF = true; 158 } 159 else 160 line += (column = 1); 161 } 162 163 switch (c) 164 { 165 case '\r' : 166 prevCharIsCR = true; 167 break; 168 case '\n' : 169 prevCharIsLF = true; 170 break; 171 case '\t' : 172 column--; 173 column += (tabSize - (column % tabSize)); 174 break; 175 default : 176 break; 177 } 178 179 bufline[bufpos] = line; 180 bufcolumn[bufpos] = column; 181 } 182 183/** Read a character. */ 184 public char readChar() throws java.io.IOException 185 { 186 if (inBuf > 0) 187 { 188 --inBuf; 189 190 if (++bufpos == bufsize) 191 bufpos = 0; 192 193 return buffer[bufpos]; 194 } 195 196 if (++bufpos >= maxNextCharInd) 197 FillBuff(); 198 199 char c = buffer[bufpos]; 200 201 UpdateLineColumn(c); 202 return c; 203 } 204 205 @Deprecated 206 /** 207 * @deprecated 208 * @see #getEndColumn 209 */ 210 211 public int getColumn() { 212 return bufcolumn[bufpos]; 213 } 214 215 @Deprecated 216 /** 217 * @deprecated 218 * @see #getEndLine 219 */ 220 221 public int getLine() { 222 return bufline[bufpos]; 223 } 224 225 /** Get token end column number. */ 226 public int getEndColumn() { 227 return bufcolumn[bufpos]; 228 } 229 230 /** Get token end line number. */ 231 public int getEndLine() { 232 return bufline[bufpos]; 233 } 234 235 /** Get token beginning column number. */ 236 public int getBeginColumn() { 237 return bufcolumn[tokenBegin]; 238 } 239 240 /** Get token beginning line number. */ 241 public int getBeginLine() { 242 return bufline[tokenBegin]; 243 } 244 245/** Backup a number of characters. */ 246 public void backup(int amount) { 247 248 inBuf += amount; 249 if ((bufpos -= amount) < 0) 250 bufpos += bufsize; 251 } 252 253 /** Constructor. */ 254 public SimpleCharStream(java.io.Reader dstream, int startline, 255 int startcolumn, int buffersize) 256 { 257 inputStream = dstream; 258 line = startline; 259 column = startcolumn - 1; 260 261 available = bufsize = buffersize; 262 buffer = new char[buffersize]; 263 bufline = new int[buffersize]; 264 bufcolumn = new int[buffersize]; 265 } 266 267 /** Constructor. */ 268 public SimpleCharStream(java.io.Reader dstream, int startline, 269 int startcolumn) 270 { 271 this(dstream, startline, startcolumn, 4096); 272 } 273 274 /** Constructor. */ 275 public SimpleCharStream(java.io.Reader dstream) 276 { 277 this(dstream, 1, 1, 4096); 278 } 279 280 /** Reinitialise. */ 281 public void ReInit(java.io.Reader dstream, int startline, 282 int startcolumn, int buffersize) 283 { 284 inputStream = dstream; 285 line = startline; 286 column = startcolumn - 1; 287 288 if (buffer == null || buffersize != buffer.length) 289 { 290 available = bufsize = buffersize; 291 buffer = new char[buffersize]; 292 bufline = new int[buffersize]; 293 bufcolumn = new int[buffersize]; 294 } 295 prevCharIsLF = prevCharIsCR = false; 296 tokenBegin = inBuf = maxNextCharInd = 0; 297 bufpos = -1; 298 } 299 300 /** Reinitialise. */ 301 public void ReInit(java.io.Reader dstream, int startline, 302 int startcolumn) 303 { 304 ReInit(dstream, startline, startcolumn, 4096); 305 } 306 307 /** Reinitialise. */ 308 public void ReInit(java.io.Reader dstream) 309 { 310 ReInit(dstream, 1, 1, 4096); 311 } 312 /** Constructor. */ 313 public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, 314 int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException 315 { 316 this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); 317 } 318 319 /** Constructor. */ 320 public SimpleCharStream(java.io.InputStream dstream, int startline, 321 int startcolumn, int buffersize) 322 { 323 this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); 324 } 325 326 /** Constructor. */ 327 public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, 328 int startcolumn) throws java.io.UnsupportedEncodingException 329 { 330 this(dstream, encoding, startline, startcolumn, 4096); 331 } 332 333 /** Constructor. */ 334 public SimpleCharStream(java.io.InputStream dstream, int startline, 335 int startcolumn) 336 { 337 this(dstream, startline, startcolumn, 4096); 338 } 339 340 /** Constructor. */ 341 public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException 342 { 343 this(dstream, encoding, 1, 1, 4096); 344 } 345 346 /** Constructor. */ 347 public SimpleCharStream(java.io.InputStream dstream) 348 { 349 this(dstream, 1, 1, 4096); 350 } 351 352 /** Reinitialise. */ 353 public void ReInit(java.io.InputStream dstream, String encoding, int startline, 354 int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException 355 { 356 ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); 357 } 358 359 /** Reinitialise. */ 360 public void ReInit(java.io.InputStream dstream, int startline, 361 int startcolumn, int buffersize) 362 { 363 ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); 364 } 365 366 /** Reinitialise. */ 367 public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException 368 { 369 ReInit(dstream, encoding, 1, 1, 4096); 370 } 371 372 /** Reinitialise. */ 373 public void ReInit(java.io.InputStream dstream) 374 { 375 ReInit(dstream, 1, 1, 4096); 376 } 377 /** Reinitialise. */ 378 public void ReInit(java.io.InputStream dstream, String encoding, int startline, 379 int startcolumn) throws java.io.UnsupportedEncodingException 380 { 381 ReInit(dstream, encoding, startline, startcolumn, 4096); 382 } 383 /** Reinitialise. */ 384 public void ReInit(java.io.InputStream dstream, int startline, 385 int startcolumn) 386 { 387 ReInit(dstream, startline, startcolumn, 4096); 388 } 389 /** Get token literal value. */ 390 public String GetImage() 391 { 392 if (bufpos >= tokenBegin) 393 return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); 394 else 395 return new String(buffer, tokenBegin, bufsize - tokenBegin) + 396 new String(buffer, 0, bufpos + 1); 397 } 398 399 /** Get the suffix. */ 400 public char[] GetSuffix(int len) 401 { 402 char[] ret = new char[len]; 403 404 if ((bufpos + 1) >= len) 405 System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); 406 else 407 { 408 System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, 409 len - bufpos - 1); 410 System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); 411 } 412 413 return ret; 414 } 415 416 /** Reset buffer when finished. */ 417 public void Done() 418 { 419 buffer = null; 420 bufline = null; 421 bufcolumn = null; 422 } 423 424 /** 425 * Method to adjust line and column numbers for the start of a token. 426 */ 427 public void adjustBeginLineColumn(int newLine, int newCol) 428 { 429 int start = tokenBegin; 430 int len; 431 432 if (bufpos >= tokenBegin) 433 { 434 len = bufpos - tokenBegin + inBuf + 1; 435 } 436 else 437 { 438 len = bufsize - tokenBegin + bufpos + 1 + inBuf; 439 } 440 441 int i = 0, j = 0, k = 0; 442 int nextColDiff = 0, columnDiff = 0; 443 444 while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) 445 { 446 bufline[j] = newLine; 447 nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; 448 bufcolumn[j] = newCol + columnDiff; 449 columnDiff = nextColDiff; 450 i++; 451 } 452 453 if (i < len) 454 { 455 bufline[j] = newLine++; 456 bufcolumn[j] = newCol + columnDiff; 457 458 while (i++ < len) 459 { 460 if (bufline[j = start % bufsize] != bufline[++start % bufsize]) 461 bufline[j] = newLine++; 462 else 463 bufline[j] = newLine; 464 } 465 } 466 467 line = bufline[j]; 468 column = bufcolumn[j]; 469 } 470 471 boolean getTrackLineColumn() { return trackLineColumn; } 472 void setTrackLineColumn(boolean tlc) { trackLineColumn = tlc; } 473} 474/* JavaCC - OriginalChecksum=72dc79ab408ef42133eec0fa6571e53c (do not edit this line) */