1 2 3 21 22 package org.netbeans.lib.java.parser; 23 24 import java.io.*; 25 import java.util.ArrayList ; 26 27 28 34 final class UnicodeEscapes extends FilterReader { 35 36 37 final public static int YYEOF = -1; 38 39 40 final private static int YY_BUFFERSIZE = 16384; 41 42 43 final public static int DIGITS = 1; 44 final public static int YYINITIAL = 0; 45 46 49 final private static String yycmap_packed = 50 "\12\0\1\0\45\0\12\1\7\0\6\1\25\0\1\2\4\0\6\1"+ 51 "\16\0\1\3\uff8a\0"; 52 53 56 final private static char [] yycmap = yy_unpack_cmap(yycmap_packed); 57 58 59 60 final private static int YY_UNKNOWN_ERROR = 0; 61 final private static int YY_ILLEGAL_STATE = 1; 62 final private static int YY_NO_MATCH = 2; 63 final private static int YY_PUSHBACK_2BIG = 3; 64 65 66 final private static String YY_ERROR_MSG[] = { 67 "Unkown internal scanner error", 68 "Internal error: unknown state", 69 "Error: could not match input", 70 "Error: pushback value was too large" 71 }; 72 73 74 private java.io.Reader yy_reader; 75 76 77 private int yy_state; 78 79 80 private int yy_lexical_state = YYINITIAL; 81 82 84 private char yy_buffer[] = new char[YY_BUFFERSIZE]; 85 86 87 private int yy_markedPos; 88 89 90 private int yy_pushbackPos; 91 92 93 private int yy_currentPos; 94 95 96 private int yy_startRead; 97 98 100 private int yy_endRead; 101 102 103 private int yyline; 104 105 106 private int yychar; 107 108 112 private int yycolumn; 113 114 117 private boolean yy_atBOL = true; 118 119 120 private boolean yy_atEOF; 121 122 123 private char lastToken[]=null; 124 125 private int escapeOffset = 0; 126 private ArrayList escapes = new ArrayList (); 127 private int escapesIndex = -1; 128 private int nextEscapePosition = -1; 129 private int currentEscapeDispl = 0; 130 131 private char value() { 132 char r=0; 133 String token = yytext(); 134 135 for (int k = token.length()-4; k < token.length(); k++) { 136 int c = token.charAt(k); 137 if (c >= 'a') 138 c-= 'a'-10; 139 else if (c >= 'A') 140 c-= 'A'-10; 141 else 142 c-= '0'; 143 r <<= 4; 144 r += c; 145 } 146 return r; 147 } 148 149 int convertPosition(int position) { 150 if (escapes.isEmpty()) 151 return position; 152 for (;;) { 153 if (position <= nextEscapePosition) 154 return position+currentEscapeDispl; 155 if (nextEscapePosition != -1) 156 currentEscapeDispl=((Integer )escapes.get(++escapesIndex)).intValue(); 157 if (escapes.size()<=escapesIndex+1) { 158 nextEscapePosition = -1; 159 return position+currentEscapeDispl; 160 } 161 nextEscapePosition=((Integer )escapes.get(++escapesIndex)).intValue(); 162 } 163 } 164 165 public int read(char cbuf[], int off, int len) throws IOException { 166 int tokenLen; 167 168 if (lastToken==null) { 170 lastToken = yylex(); 171 } 172 tokenLen = lastToken.length; 173 if (tokenLen==0) 174 return -1; 175 if (len>=tokenLen) { 176 System.arraycopy(lastToken,0,cbuf,off,tokenLen); 177 lastToken=null; 178 return tokenLen; 179 } 180 char token[]=new char[lastToken.length-len]; 181 System.arraycopy(lastToken,0,cbuf,off,len); 182 System.arraycopy(lastToken,len,token,0,token.length); 183 lastToken=token; 184 return len; 185 } 186 187 public boolean markSupported() { 188 return false; 189 } 190 191 public boolean ready() throws IOException { 192 return lastToken!=null || (!yy_atEOF && (yy_currentPos < yy_endRead || yy_reader.ready())); 193 } 194 195 196 197 203 UnicodeEscapes(java.io.Reader in) { 204 super(in); 205 this.yy_reader = in; 206 } 207 208 214 UnicodeEscapes(java.io.InputStream in) { 215 this(new java.io.InputStreamReader (in)); 216 } 217 218 224 private static char [] yy_unpack_cmap(String packed) { 225 char [] map = new char[0x10000]; 226 int i = 0; 227 int j = 0; 228 while (i < 26) { 229 int count = packed.charAt(i++); 230 char value = packed.charAt(i++); 231 do map[j++] = value; while (--count > 0); 232 } 233 return map; 234 } 235 236 237 244 private boolean yy_refill() throws java.io.IOException { 245 246 247 if (yy_startRead > 0) { 248 System.arraycopy(yy_buffer, yy_startRead, 249 yy_buffer, 0, 250 yy_endRead-yy_startRead); 251 252 253 yy_endRead-= yy_startRead; 254 yy_currentPos-= yy_startRead; 255 yy_markedPos-= yy_startRead; 256 yy_pushbackPos-= yy_startRead; 257 yy_startRead = 0; 258 } 259 260 261 if (yy_currentPos >= yy_buffer.length) { 262 263 char newBuffer[] = new char[yy_currentPos*2]; 264 System.arraycopy(yy_buffer, 0, newBuffer, 0, yy_buffer.length); 265 yy_buffer = newBuffer; 266 } 267 268 269 int numRead = yy_reader.read(yy_buffer, yy_endRead, 270 yy_buffer.length-yy_endRead); 271 272 if (numRead < 0) { 273 return true; 274 } 275 else { 276 yy_endRead+= numRead; 277 return false; 278 } 279 } 280 281 282 285 final public void yyclose() throws java.io.IOException { 286 yy_atEOF = true; 287 yy_endRead = yy_startRead; 288 289 if (yy_reader != null) 290 yy_reader.close(); 291 } 292 293 294 304 final public void yyreset(java.io.Reader reader) throws java.io.IOException { 305 yyclose(); 306 yy_reader = reader; 307 yy_atBOL = true; 308 yy_atEOF = false; 309 yy_endRead = yy_startRead = 0; 310 yy_currentPos = yy_markedPos = yy_pushbackPos = 0; 311 yyline = yychar = yycolumn = 0; 312 yy_lexical_state = YYINITIAL; 313 } 314 315 316 319 final public int yystate() { 320 return yy_lexical_state; 321 } 322 323 324 329 final public void yybegin(int newState) { 330 yy_lexical_state = newState; 331 } 332 333 334 337 final public String yytext() { 338 return new String ( yy_buffer, yy_startRead, yy_markedPos-yy_startRead ); 339 } 340 341 342 353 final public char yycharat(int pos) { 354 return yy_buffer[yy_startRead+pos]; 355 } 356 357 358 361 final public int yylength() { 362 return yy_markedPos-yy_startRead; 363 } 364 365 366 380 private void yy_ScanError(int errorCode) { 381 String message; 382 try { 383 message = YY_ERROR_MSG[errorCode]; 384 } 385 catch (ArrayIndexOutOfBoundsException e) { 386 message = YY_ERROR_MSG[YY_UNKNOWN_ERROR]; 387 } 388 389 throw new Error (message); 390 } 391 392 393 401 private void yypushback(int number) { 402 if ( number > yylength() ) 403 yy_ScanError(YY_PUSHBACK_2BIG); 404 405 yy_markedPos -= number; 406 } 407 408 409 416 public char[] yylex() throws java.io.IOException { 417 int yy_input; 418 int yy_action; 419 420 int yy_currentPos_l; 422 int yy_startRead_l; 423 int yy_markedPos_l; 424 int yy_endRead_l = yy_endRead; 425 char [] yy_buffer_l = yy_buffer; 426 char [] yycmap_l = yycmap; 427 428 429 while (true) { 430 yy_markedPos_l = yy_markedPos; 431 432 yychar+= yy_markedPos_l-yy_startRead; 433 434 yy_action = -1; 435 436 yy_startRead_l = yy_currentPos_l = yy_currentPos = 437 yy_startRead = yy_markedPos_l; 438 439 yy_state = yy_lexical_state; 440 441 442 yy_forAction: { 443 while (true) { 444 445 if (yy_currentPos_l < yy_endRead_l) 446 yy_input = yy_buffer_l[yy_currentPos_l++]; 447 else if (yy_atEOF) { 448 yy_input = YYEOF; 449 break yy_forAction; 450 } 451 else { 452 yy_currentPos = yy_currentPos_l; 454 yy_markedPos = yy_markedPos_l; 455 boolean eof = yy_refill(); 456 yy_currentPos_l = yy_currentPos; 458 yy_markedPos_l = yy_markedPos; 459 yy_buffer_l = yy_buffer; 460 yy_endRead_l = yy_endRead; 461 if (eof) { 462 yy_input = YYEOF; 463 break yy_forAction; 464 } 465 else { 466 yy_input = yy_buffer_l[yy_currentPos_l++]; 467 } 468 } 469 yy_input = yycmap_l[yy_input]; 470 471 boolean yy_isFinal = false; 472 boolean yy_noLookAhead = false; 473 474 yy_forNext: { switch (yy_state) { 475 case 0: 476 switch (yy_input) { 477 case 2: yy_isFinal = true; yy_state = 3; break yy_forNext; 478 default: yy_isFinal = true; yy_state = 2; break yy_forNext; 479 } 480 481 case 1: 482 switch (yy_input) { 483 case 1: yy_isFinal = true; yy_state = 5; break yy_forNext; 484 case 3: yy_isFinal = true; yy_state = 6; break yy_forNext; 485 default: yy_isFinal = true; yy_noLookAhead = true; yy_state = 4; break yy_forNext; 486 } 487 488 case 2: 489 switch (yy_input) { 490 case 2: break yy_forAction; 491 default: yy_isFinal = true; yy_state = 2; break yy_forNext; 492 } 493 494 case 3: 495 switch (yy_input) { 496 case 2: yy_isFinal = true; yy_state = 7; break yy_forNext; 497 case 3: yy_isFinal = true; yy_noLookAhead = true; yy_state = 8; break yy_forNext; 498 default: break yy_forAction; 499 } 500 501 case 5: 502 switch (yy_input) { 503 case 1: yy_state = 9; break yy_forNext; 504 default: break yy_forAction; 505 } 506 507 case 6: 508 switch (yy_input) { 509 case 1: yy_state = 10; break yy_forNext; 510 case 3: yy_state = 11; break yy_forNext; 511 default: break yy_forAction; 512 } 513 514 case 7: 515 switch (yy_input) { 516 case 2: yy_isFinal = true; yy_state = 3; break yy_forNext; 517 default: break yy_forAction; 518 } 519 520 case 9: 521 switch (yy_input) { 522 case 1: yy_state = 12; break yy_forNext; 523 default: break yy_forAction; 524 } 525 526 case 10: 527 switch (yy_input) { 528 case 1: yy_state = 9; break yy_forNext; 529 default: break yy_forAction; 530 } 531 532 case 11: 533 switch (yy_input) { 534 case 1: yy_state = 10; break yy_forNext; 535 case 3: yy_state = 11; break yy_forNext; 536 default: break yy_forAction; 537 } 538 539 case 12: 540 switch (yy_input) { 541 case 1: yy_isFinal = true; yy_noLookAhead = true; yy_state = 13; break yy_forNext; 542 default: break yy_forAction; 543 } 544 545 default: 546 yy_ScanError(YY_ILLEGAL_STATE); 547 break; 548 } } 549 550 if ( yy_isFinal ) { 551 yy_action = yy_state; 552 yy_markedPos_l = yy_currentPos_l; 553 if ( yy_noLookAhead ) break yy_forAction; 554 } 555 556 } 557 } 558 559 yy_markedPos = yy_markedPos_l; 561 562 switch (yy_action) { 563 564 case 13: 565 { yybegin(YYINITIAL); 566 escapeOffset+=yylength()-1; 567 escapes.add(new Integer (escapeOffset)); 568 return new char[]{value()}; 569 } 570 case 15: break; 571 case 4: 572 case 5: 573 case 6: 574 { throw new Error ("incorrect Unicode escape"); } 575 case 16: break; 576 case 8: 577 { yybegin(DIGITS); 578 escapes.add(new Integer (yychar-escapeOffset)); 579 escapeOffset+=yylength(); 580 } 581 case 17: break; 582 case 3: 583 case 7: 584 { return yytext().toCharArray(); } 585 case 18: break; 586 case 2: 587 { return yytext().toCharArray(); } 588 case 19: break; 589 default: 590 if (yy_input == YYEOF && yy_startRead == yy_currentPos) { 591 yy_atEOF = true; 592 switch (yy_lexical_state) { 593 case DIGITS: 594 { throw new Error ("EOF in Unicode escape"); } 595 case 15: break; 596 case YYINITIAL: 597 { return new char[0]; } 598 case 16: break; 599 default: 600 return null; 601 } 602 } 603 else { 604 yy_ScanError(YY_NO_MATCH); 605 } 606 } 607 } 608 } 609 610 611 } 612 | Popular Tags |