001/* The following code was generated by JFlex 1.6.1 */ 002 003/* 004This scanner resolves unicode escape sequences. 005 006 0073.3 of the Java Language Specification : 008 009UnicodeInputCharacter: 010 011 UnicodeEscape 012 013 RawInputCharacter 014 015 UnicodeEscape: 016 017 \ UnicodeMarker HexDigit HexDigit HexDigit HexDigit 018 019 UnicodeMarker: 020 021 u 022 023 UnicodeMarker u 024 025 RawInputCharacter: 026 027 any Unicode character 028 029 HexDigit: one of 030 031 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F 032 033only an even number of '\' is eligible to start a Unicode escape sequence 034 035We deal with invalid unicode escape sequences by just ignoring them (i.e. keep their characters) 036 037*/ 038package eu.cqse.check.framework.scanner; 039import java.io.*; 040import java.util.*; 041 042 043/** 044 * This class is a scanner generated by 045 * <a href="http://www.jflex.de/">JFlex</a> 1.6.1 046 * from the specification file <tt>/builds/cqse/teamscale/lib/eu.cqse.check/grammars/unicode.flex</tt> 047 */ 048public final class UnicodeEscapes extends FilterReader { 049 050 /** This character denotes the end of file */ 051 public static final int YYEOF = -1; 052 053 /** initial size of the lookahead buffer */ 054 private static final int ZZ_BUFFERSIZE = 16384; 055 056 /** lexical states */ 057 public static final int YYINITIAL = 0; 058 public static final int DIGITS = 2; 059 060 /** 061 * ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l 062 * ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l 063 * at the beginning of a line 064 * l is of the form l = 2*k, k a non negative integer 065 */ 066 private static final int ZZ_LEXSTATE[] = { 067 0, 0, 1, 1 068 }; 069 070 /** 071 * Translates characters to character classes 072 */ 073 private static final String ZZ_CMAP_PACKED = 074 "\60\0\12\2\7\0\6\2\25\0\1\3\4\0\6\2\16\0\1\1"+ 075 "\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uffff\0\uff9a\0"; 076 077 /** 078 * Translates characters to character classes 079 */ 080 private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED); 081 082 /** 083 * Translates DFA states to action switch labels. 084 */ 085 private static final int [] ZZ_ACTION = zzUnpackAction(); 086 087 private static final String ZZ_ACTION_PACKED_0 = 088 "\2\0\1\1\1\2\2\0\1\3\6\0\1\4\1\5"; 089 090 private static int [] zzUnpackAction() { 091 int [] result = new int[15]; 092 int offset = 0; 093 offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result); 094 return result; 095 } 096 097 private static int zzUnpackAction(String packed, int offset, int [] result) { 098 int i = 0; /* index in packed string */ 099 int j = offset; /* index in unpacked array */ 100 int l = packed.length(); 101 while (i < l) { 102 int count = packed.charAt(i++); 103 int value = packed.charAt(i++); 104 do result[j++] = value; while (--count > 0); 105 } 106 return j; 107 } 108 109 110 /** 111 * Translates a state to a row index in the transition table 112 */ 113 private static final int [] ZZ_ROWMAP = zzUnpackRowMap(); 114 115 private static final String ZZ_ROWMAP_PACKED_0 = 116 "\0\0\0\4\0\10\0\14\0\20\0\24\0\10\0\30"+ 117 "\0\34\0\40\0\44\0\50\0\54\0\10\0\10"; 118 119 private static int [] zzUnpackRowMap() { 120 int [] result = new int[15]; 121 int offset = 0; 122 offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result); 123 return result; 124 } 125 126 private static int zzUnpackRowMap(String packed, int offset, int [] result) { 127 int i = 0; /* index in packed string */ 128 int j = offset; /* index in unpacked array */ 129 int l = packed.length(); 130 while (i < l) { 131 int high = packed.charAt(i++) << 16; 132 result[j++] = high | packed.charAt(i++); 133 } 134 return j; 135 } 136 137 /** 138 * The transition table of the DFA 139 */ 140 private static final int [] ZZ_TRANS = zzUnpackTrans(); 141 142 private static final String ZZ_TRANS_PACKED_0 = 143 "\3\3\1\4\1\0\1\5\7\0\1\6\1\0\1\7"+ 144 "\1\0\1\5\1\10\2\0\1\6\1\11\3\0\1\12"+ 145 "\3\0\1\13\3\0\1\14\3\0\1\15\3\0\1\16"+ 146 "\3\0\1\17\1\0"; 147 148 private static int [] zzUnpackTrans() { 149 int [] result = new int[48]; 150 int offset = 0; 151 offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result); 152 return result; 153 } 154 155 private static int zzUnpackTrans(String packed, int offset, int [] result) { 156 int i = 0; /* index in packed string */ 157 int j = offset; /* index in unpacked array */ 158 int l = packed.length(); 159 while (i < l) { 160 int count = packed.charAt(i++); 161 int value = packed.charAt(i++); 162 value--; 163 do result[j++] = value; while (--count > 0); 164 } 165 return j; 166 } 167 168 169 /* error codes */ 170 private static final int ZZ_UNKNOWN_ERROR = 0; 171 private static final int ZZ_NO_MATCH = 1; 172 private static final int ZZ_PUSHBACK_2BIG = 2; 173 174 /* error messages for the codes above */ 175 private static final String ZZ_ERROR_MSG[] = { 176 "Unknown internal scanner error", 177 "Error: could not match input", 178 "Error: pushback value was too large" 179 }; 180 181 /** 182 * ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code> 183 */ 184 private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute(); 185 186 private static final String ZZ_ATTRIBUTE_PACKED_0 = 187 "\2\0\1\11\1\1\2\0\1\11\6\0\2\11"; 188 189 private static int [] zzUnpackAttribute() { 190 int [] result = new int[15]; 191 int offset = 0; 192 offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result); 193 return result; 194 } 195 196 private static int zzUnpackAttribute(String packed, int offset, int [] result) { 197 int i = 0; /* index in packed string */ 198 int j = offset; /* index in unpacked array */ 199 int l = packed.length(); 200 while (i < l) { 201 int count = packed.charAt(i++); 202 int value = packed.charAt(i++); 203 do result[j++] = value; while (--count > 0); 204 } 205 return j; 206 } 207 208 /** the input device */ 209 private java.io.Reader zzReader; 210 211 /** the current state of the DFA */ 212 private int zzState; 213 214 /** the current lexical state */ 215 private int zzLexicalState = YYINITIAL; 216 217 /** this buffer contains the current text to be matched and is 218 the source of the yytext() string */ 219 private char zzBuffer[] = new char[ZZ_BUFFERSIZE]; 220 221 /** the textposition at the last accepting state */ 222 private int zzMarkedPos; 223 224 /** the current text position in the buffer */ 225 private int zzCurrentPos; 226 227 /** startRead marks the beginning of the yytext() string in the buffer */ 228 private int zzStartRead; 229 230 /** endRead marks the last character in the buffer, that has been read 231 from input */ 232 private int zzEndRead; 233 234 /** number of newlines encountered up to the start of the matched text */ 235 private int yyline; 236 237 /** the number of characters up to the start of the matched text */ 238 private int yychar; 239 240 /** 241 * the number of characters from the last newline up to the start of the 242 * matched text 243 */ 244 private int yycolumn; 245 246 /** 247 * zzAtBOL == true <=> the scanner is currently at the beginning of a line 248 */ 249 private boolean zzAtBOL = true; 250 251 /** zzAtEOF == true <=> the scanner is at the EOF */ 252 private boolean zzAtEOF; 253 254 /** denotes if the user-EOF-code has already been executed */ 255 private boolean zzEOFDone; 256 257 /** 258 * The number of occupied positions in zzBuffer beyond zzEndRead. 259 * When a lead/high surrogate has been read from the input stream 260 * into the final zzBuffer position, this will have a value of 1; 261 * otherwise, it will have a value of 0. 262 */ 263 private int zzFinalHighSurrogate = 0; 264 265 /* user code: */ 266 private boolean even; 267 268 /** Stores the offsets of "fat" (i.e. unicode escaped characters) in the resulting stream. */ 269 private final List<Integer> fatCharacterOffsets = new ArrayList<Integer> (); 270 271 /** Stores the strings of "fat" (i.e. unicode escaped characters) in the resulting stream. */ 272 private final Map<Integer, String> fatCharacters = new HashMap<>(); 273 274 /** Marks the start position of a unicode escape sequence. */ 275 private void markUnicodeEscape () { 276 // to get the offset in the resulting stream, we have to account for previous 277 // "fat" characters, which are exactly 6-1 characters too wide 278 int offset = yychar - 5 * fatCharacterOffsets.size(); 279 fatCharacterOffsets.add(offset); 280 fatCharacters.put(offset, new String(zzBuffer, zzCurrentPos, 6)); 281 } 282 283 /** Returns the corrected offset (prior to removing unicode escapes) for an offset of the result stream. */ 284 /*package*/ int correctOffset (int offset) { 285 if (fatCharacterOffsets.isEmpty ()) { 286 return offset; 287 } 288 289 int index = Collections.binarySearch (fatCharacterOffsets, offset); 290 if (index < 0) { 291 index = -index -1; 292 } 293 294 // we have to compensate for all escapes before the insertion point 295 return offset + 5 * index; 296 } 297 298 /** Returns the corrected text (prior to removing unicode escapes). */ 299 /* package */ String correctText(String text, int offset) { 300 if (fatCharacterOffsets.isEmpty()) { 301 return text; 302 } 303 int first = Collections.binarySearch(fatCharacterOffsets, offset); 304 if (first < 0) { 305 first = -first - 1; 306 } 307 int last = Collections.binarySearch(fatCharacterOffsets, offset + text.length() - 1); 308 if (last < 0) { 309 last = -last - 2; 310 } 311 for (int i = last; i >= first; i--) { 312 StringBuffer newString = new StringBuffer(text); 313 int unicodeOffset = fatCharacterOffsets.get(i); 314 newString.insert(unicodeOffset - offset + 1, fatCharacters.get(unicodeOffset)); 315 newString.deleteCharAt(unicodeOffset - offset); 316 text = newString.toString(); 317 } 318 return text; 319 } 320 321 /** Resets the stored offsets. */ 322 /*package*/ void resetOffsets () { 323 fatCharacterOffsets.clear (); 324 } 325 326 private int value() { 327 int r = 0; 328 329 for (int k = zzMarkedPos-4; k < zzMarkedPos; k++) { 330 int c = zzBuffer[k]; 331 332 if (c >= 'a') 333 c-= 'a'-10; 334 else if (c >= 'A') 335 c-= 'A'-10; 336 else 337 c-= '0'; 338 339 r <<= 4; 340 r += c; 341 } 342 343 // adjustment for CR#4805: If the value would start a new line, we replace it by a space 344 // to preserve the whitespace meaning while staying in the same line 345 if (r == 0x000B || r == 0x000C || r == 0x0085 || r == 0x2028 || r == 0x2029) { 346 r = ' '; 347 } 348 349 return r; 350 } 351 352 public int read(char cbuf[], int off, int len) throws IOException { 353 for (int i = off; i < len + off; i++) { 354 int c = read(); 355 356 if (c < 0) { 357 // this fixes bug #936 358 // if no character was read and the end of the stream was 359 // reached this must be signaled so 360 if ((i - off) == 0) { 361 return -1; 362 } 363 return i - off; 364 365 } 366 cbuf[i] = (char) c; 367 } 368 return len; 369 } 370 371 public boolean markSupported() { 372 return false; 373 } 374 375 public boolean ready() throws IOException { 376 return zzReader.ready(); 377 } 378 379 380 381 /** 382 * Creates a new scanner 383 * 384 * @param in the java.io.Reader to read input from. 385 */ 386 public UnicodeEscapes(java.io.Reader in) { 387 super(in); 388 this.zzReader = in; 389 } 390 391 392 /** 393 * Unpacks the compressed character translation table. 394 * 395 * @param packed the packed character translation table 396 * @return the unpacked character translation table 397 */ 398 private static char [] zzUnpackCMap(String packed) { 399 char [] map = new char[0x110000]; 400 int i = 0; /* index in packed string */ 401 int j = 0; /* index in unpacked array */ 402 while (i < 54) { 403 int count = packed.charAt(i++); 404 char value = packed.charAt(i++); 405 do map[j++] = value; while (--count > 0); 406 } 407 return map; 408 } 409 410 411 /** 412 * Refills the input buffer. 413 * 414 * @return <code>false</code>, iff there was new input. 415 * 416 * @exception java.io.IOException if any I/O-Error occurs 417 */ 418 private boolean zzRefill() throws java.io.IOException { 419 420 /* first: make room (if you can) */ 421 if (zzStartRead > 0) { 422 zzEndRead += zzFinalHighSurrogate; 423 zzFinalHighSurrogate = 0; 424 System.arraycopy(zzBuffer, zzStartRead, 425 zzBuffer, 0, 426 zzEndRead-zzStartRead); 427 428 /* translate stored positions */ 429 zzEndRead-= zzStartRead; 430 zzCurrentPos-= zzStartRead; 431 zzMarkedPos-= zzStartRead; 432 zzStartRead = 0; 433 } 434 435 /* is the buffer big enough? */ 436 if (zzCurrentPos >= zzBuffer.length - zzFinalHighSurrogate) { 437 /* if not: blow it up */ 438 char newBuffer[] = new char[zzBuffer.length*2]; 439 System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length); 440 zzBuffer = newBuffer; 441 zzEndRead += zzFinalHighSurrogate; 442 zzFinalHighSurrogate = 0; 443 } 444 445 /* fill the buffer with new input */ 446 int requested = zzBuffer.length - zzEndRead; 447 int numRead = zzReader.read(zzBuffer, zzEndRead, requested); 448 449 /* not supposed to occur according to specification of java.io.Reader */ 450 if (numRead == 0) { 451 throw new java.io.IOException("Reader returned 0 characters. See JFlex examples for workaround."); 452 } 453 if (numRead > 0) { 454 zzEndRead += numRead; 455 /* If numRead == requested, we might have requested to few chars to 456 encode a full Unicode character. We assume that a Reader would 457 otherwise never return half characters. */ 458 if (numRead == requested) { 459 if (Character.isHighSurrogate(zzBuffer[zzEndRead - 1])) { 460 --zzEndRead; 461 zzFinalHighSurrogate = 1; 462 } 463 } 464 /* potentially more input available */ 465 return false; 466 } 467 468 /* numRead < 0 ==> end of stream */ 469 return true; 470 } 471 472 473 /** 474 * Closes the input stream. 475 */ 476 public final void yyclose() throws java.io.IOException { 477 zzAtEOF = true; /* indicate end of file */ 478 zzEndRead = zzStartRead; /* invalidate buffer */ 479 480 if (zzReader != null) 481 zzReader.close(); 482 } 483 484 485 /** 486 * Resets the scanner to read from a new input stream. 487 * Does not close the old reader. 488 * 489 * All internal variables are reset, the old input stream 490 * <b>cannot</b> be reused (internal buffer is discarded and lost). 491 * Lexical state is set to <tt>ZZ_INITIAL</tt>. 492 * 493 * Internal scan buffer is resized down to its initial length, if it has grown. 494 * 495 * @param reader the new input stream 496 */ 497 public final void yyreset(java.io.Reader reader) { 498 zzReader = reader; 499 zzAtBOL = true; 500 zzAtEOF = false; 501 zzEOFDone = false; 502 zzEndRead = zzStartRead = 0; 503 zzCurrentPos = zzMarkedPos = 0; 504 zzFinalHighSurrogate = 0; 505 yyline = yychar = yycolumn = 0; 506 zzLexicalState = YYINITIAL; 507 if (zzBuffer.length > ZZ_BUFFERSIZE) 508 zzBuffer = new char[ZZ_BUFFERSIZE]; 509 } 510 511 512 /** 513 * Returns the current lexical state. 514 */ 515 public final int yystate() { 516 return zzLexicalState; 517 } 518 519 520 /** 521 * Enters a new lexical state 522 * 523 * @param newState the new lexical state 524 */ 525 public final void yybegin(int newState) { 526 zzLexicalState = newState; 527 } 528 529 530 /** 531 * Returns the text matched by the current regular expression. 532 */ 533 public final String yytext() { 534 return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead ); 535 } 536 537 538 /** 539 * Returns the character at position <tt>pos</tt> from the 540 * matched text. 541 * 542 * It is equivalent to yytext().charAt(pos), but faster 543 * 544 * @param pos the position of the character to fetch. 545 * A value from 0 to yylength()-1. 546 * 547 * @return the character at position pos 548 */ 549 public final char yycharat(int pos) { 550 return zzBuffer[zzStartRead+pos]; 551 } 552 553 554 /** 555 * Returns the length of the matched text region. 556 */ 557 public final int yylength() { 558 return zzMarkedPos-zzStartRead; 559 } 560 561 562 /** 563 * Reports an error that occured while scanning. 564 * 565 * In a wellformed scanner (no or only correct usage of 566 * yypushback(int) and a match-all fallback rule) this method 567 * will only be called with things that "Can't Possibly Happen". 568 * If this method is called, something is seriously wrong 569 * (e.g. a JFlex bug producing a faulty scanner etc.). 570 * 571 * Usual syntax/scanner level error handling should be done 572 * in error fallback rules. 573 * 574 * @param errorCode the code of the errormessage to display 575 */ 576 private void zzScanError(int errorCode) { 577 String message; 578 try { 579 message = ZZ_ERROR_MSG[errorCode]; 580 } 581 catch (ArrayIndexOutOfBoundsException e) { 582 message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR]; 583 } 584 585 throw new Error(message); 586 } 587 588 589 /** 590 * Pushes the specified amount of characters back into the input stream. 591 * 592 * They will be read again by then next call of the scanning method 593 * 594 * @param number the number of characters to be read again. 595 * This number must not be greater than yylength()! 596 */ 597 public void yypushback(int number) { 598 if ( number > yylength() ) 599 zzScanError(ZZ_PUSHBACK_2BIG); 600 601 zzMarkedPos -= number; 602 } 603 604 605 /** 606 * Resumes scanning until the next regular expression is matched, 607 * the end of input is encountered or an I/O-Error occurs. 608 * 609 * @return the next token 610 * @exception java.io.IOException if any I/O-Error occurs 611 */ 612 public int read() throws java.io.IOException { 613 int zzInput; 614 int zzAction; 615 616 // cached fields: 617 int zzCurrentPosL; 618 int zzMarkedPosL; 619 int zzEndReadL = zzEndRead; 620 char [] zzBufferL = zzBuffer; 621 char [] zzCMapL = ZZ_CMAP; 622 623 int [] zzTransL = ZZ_TRANS; 624 int [] zzRowMapL = ZZ_ROWMAP; 625 int [] zzAttrL = ZZ_ATTRIBUTE; 626 627 while (true) { 628 zzMarkedPosL = zzMarkedPos; 629 630 yychar+= zzMarkedPosL-zzStartRead; 631 632 zzAction = -1; 633 634 zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL; 635 636 zzState = ZZ_LEXSTATE[zzLexicalState]; 637 638 // set up zzAction for empty match case: 639 int zzAttributes = zzAttrL[zzState]; 640 if ( (zzAttributes & 1) == 1 ) { 641 zzAction = zzState; 642 } 643 644 645 zzForAction: { 646 while (true) { 647 648 if (zzCurrentPosL < zzEndReadL) { 649 zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL, zzEndReadL); 650 zzCurrentPosL += Character.charCount(zzInput); 651 } 652 else if (zzAtEOF) { 653 zzInput = YYEOF; 654 break zzForAction; 655 } 656 else { 657 // store back cached positions 658 zzCurrentPos = zzCurrentPosL; 659 zzMarkedPos = zzMarkedPosL; 660 boolean eof = zzRefill(); 661 // get translated positions and possibly new buffer 662 zzCurrentPosL = zzCurrentPos; 663 zzMarkedPosL = zzMarkedPos; 664 zzBufferL = zzBuffer; 665 zzEndReadL = zzEndRead; 666 if (eof) { 667 zzInput = YYEOF; 668 break zzForAction; 669 } 670 else { 671 zzInput = Character.codePointAt(zzBufferL, zzCurrentPosL, zzEndReadL); 672 zzCurrentPosL += Character.charCount(zzInput); 673 } 674 } 675 int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ]; 676 if (zzNext == -1) break zzForAction; 677 zzState = zzNext; 678 679 zzAttributes = zzAttrL[zzState]; 680 if ( (zzAttributes & 1) == 1 ) { 681 zzAction = zzState; 682 zzMarkedPosL = zzCurrentPosL; 683 if ( (zzAttributes & 8) == 8 ) break zzForAction; 684 } 685 686 } 687 } 688 689 // store back cached position 690 zzMarkedPos = zzMarkedPosL; 691 692 if (zzInput == YYEOF && zzStartRead == zzCurrentPos) { 693 zzAtEOF = true; 694 switch (zzLexicalState) { 695 case YYINITIAL: { 696 return -1; 697 } 698 case 16: break; 699 default: 700 return YYEOF; 701 } 702 } 703 else { 704 switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) { 705 case 1: 706 { return zzBuffer[zzStartRead]; 707 } 708 case 6: break; 709 case 2: 710 { even = false; return '\\'; 711 } 712 case 7: break; 713 case 3: 714 // lookahead expression with fixed base length 715 zzMarkedPos = Character.offsetByCodePoints 716 (zzBufferL, zzStartRead, zzEndRead - zzStartRead, zzStartRead, 1); 717 { even = !even; return '\\'; 718 } 719 case 8: break; 720 case 4: 721 { yybegin(YYINITIAL); return value(); 722 } 723 case 9: break; 724 case 5: 725 // lookahead expression with fixed base length 726 zzMarkedPos = Character.offsetByCodePoints 727 (zzBufferL, zzStartRead, zzEndRead - zzStartRead, zzStartRead, 1); 728 { if (even) { 729 even = false; 730 return '\\'; 731 } 732 else { 733 markUnicodeEscape (); 734 yybegin(DIGITS); 735 } 736 } 737 case 10: break; 738 default: 739 zzScanError(ZZ_NO_MATCH); 740 } 741 } 742 } 743 } 744 745 746}