001/* This file was generated by SableCC (http://www.sablecc.org/). */ 002 003package org.anarres.graphviz.parser.lexer; 004 005import java.io.*; 006import org.anarres.graphviz.parser.node.*; 007 008@SuppressWarnings("nls") 009public class Lexer implements LexerInterface 010{ 011 protected Token token; 012 protected State state = State.INITIAL; 013 014 private PushbackReader in; 015 private int offset; 016 private int line; 017 private int pos; 018 private boolean cr; 019 private boolean eof; 020 private final StringBuilder text = new StringBuilder(); 021 022 @SuppressWarnings("unused") 023 protected void filter() throws LexerException, IOException 024 { 025 // Do nothing 026 } 027 028 public Lexer(@SuppressWarnings("hiding") PushbackReader in) 029 { 030 this.in = in; 031 } 032 033 public Token peek() throws LexerException, IOException 034 { 035 while(this.token == null) 036 { 037 this.token = getToken(); 038 filter(); 039 } 040 041 return this.token; 042 } 043 044 public Token next() throws LexerException, IOException 045 { 046 while(this.token == null) 047 { 048 this.token = getToken(); 049 filter(); 050 } 051 052 Token result = this.token; 053 this.token = null; 054 return result; 055 } 056 057 protected Token getToken() throws IOException, LexerException 058 { 059 int dfa_state = 0; 060 061 int start_offset = this.offset; 062 int start_pos = this.pos; 063 int start_line = this.line; 064 065 int accept_state = -1; 066 int accept_token = -1; 067 int accept_length = -1; 068 int accept_offset = -1; 069 int accept_pos = -1; 070 int accept_line = -1; 071 072 @SuppressWarnings("hiding") int[][][] gotoTable = Lexer.gotoTable[this.state.id()]; 073 @SuppressWarnings("hiding") int[] accept = Lexer.accept[this.state.id()]; 074 this.text.setLength(0); 075 076 while(true) 077 { 078 int c = getChar(); 079 080 if(c != -1) 081 { 082 switch(c) 083 { 084 case 10: 085 if(this.cr) 086 { 087 this.cr = false; 088 } 089 else 090 { 091 this.offset++; 092 this.line++; 093 this.pos = 0; 094 } 095 break; 096 case 13: 097 this.offset++; 098 this.line++; 099 this.pos = 0; 100 this.cr = true; 101 break; 102 default: 103 this.offset++; 104 this.pos++; 105 this.cr = false; 106 break; 107 } 108 109 this.text.append((char) c); 110 111 do 112 { 113 int oldState = (dfa_state < -1) ? (-2 -dfa_state) : dfa_state; 114 115 dfa_state = -1; 116 117 int[][] tmp1 = gotoTable[oldState]; 118 int low = 0; 119 int high = tmp1.length - 1; 120 121 while(low <= high) 122 { 123 int middle = (low + high) / 2; 124 int[] tmp2 = tmp1[middle]; 125 126 if(c < tmp2[0]) 127 { 128 high = middle - 1; 129 } 130 else if(c > tmp2[1]) 131 { 132 low = middle + 1; 133 } 134 else 135 { 136 dfa_state = tmp2[2]; 137 break; 138 } 139 } 140 }while(dfa_state < -1); 141 } 142 else 143 { 144 dfa_state = -1; 145 } 146 147 if(dfa_state >= 0) 148 { 149 if(accept[dfa_state] != -1) 150 { 151 accept_state = dfa_state; 152 accept_token = accept[dfa_state]; 153 accept_length = this.text.length(); 154 accept_offset = this.offset; 155 accept_pos = this.pos; 156 accept_line = this.line; 157 } 158 } 159 else 160 { 161 if(accept_state != -1) 162 { 163 switch(accept_token) 164 { 165 case 0: 166 { 167 @SuppressWarnings("hiding") Token token = new0( 168 start_offset, 169 start_line + 1, 170 start_pos + 1); 171 pushBack(accept_length); 172 this.offset = accept_offset; 173 this.pos = accept_pos; 174 this.line = accept_line; 175 return token; 176 } 177 case 1: 178 { 179 @SuppressWarnings("hiding") Token token = new1( 180 start_offset, 181 start_line + 1, 182 start_pos + 1); 183 pushBack(accept_length); 184 this.offset = accept_offset; 185 this.pos = accept_pos; 186 this.line = accept_line; 187 return token; 188 } 189 case 2: 190 { 191 @SuppressWarnings("hiding") Token token = new2( 192 start_offset, 193 start_line + 1, 194 start_pos + 1); 195 pushBack(accept_length); 196 this.offset = accept_offset; 197 this.pos = accept_pos; 198 this.line = accept_line; 199 return token; 200 } 201 case 3: 202 { 203 @SuppressWarnings("hiding") Token token = new3( 204 start_offset, 205 start_line + 1, 206 start_pos + 1); 207 pushBack(accept_length); 208 this.offset = accept_offset; 209 this.pos = accept_pos; 210 this.line = accept_line; 211 return token; 212 } 213 case 4: 214 { 215 @SuppressWarnings("hiding") Token token = new4( 216 start_offset, 217 start_line + 1, 218 start_pos + 1); 219 pushBack(accept_length); 220 this.offset = accept_offset; 221 this.pos = accept_pos; 222 this.line = accept_line; 223 return token; 224 } 225 case 5: 226 { 227 @SuppressWarnings("hiding") Token token = new5( 228 start_offset, 229 start_line + 1, 230 start_pos + 1); 231 pushBack(accept_length); 232 this.offset = accept_offset; 233 this.pos = accept_pos; 234 this.line = accept_line; 235 return token; 236 } 237 case 6: 238 { 239 @SuppressWarnings("hiding") Token token = new6( 240 start_offset, 241 start_line + 1, 242 start_pos + 1); 243 pushBack(accept_length); 244 this.offset = accept_offset; 245 this.pos = accept_pos; 246 this.line = accept_line; 247 return token; 248 } 249 case 7: 250 { 251 @SuppressWarnings("hiding") Token token = new7( 252 start_offset, 253 start_line + 1, 254 start_pos + 1); 255 pushBack(accept_length); 256 this.offset = accept_offset; 257 this.pos = accept_pos; 258 this.line = accept_line; 259 return token; 260 } 261 case 8: 262 { 263 @SuppressWarnings("hiding") Token token = new8( 264 start_offset, 265 start_line + 1, 266 start_pos + 1); 267 pushBack(accept_length); 268 this.offset = accept_offset; 269 this.pos = accept_pos; 270 this.line = accept_line; 271 return token; 272 } 273 case 9: 274 { 275 @SuppressWarnings("hiding") Token token = new9( 276 start_offset, 277 start_line + 1, 278 start_pos + 1); 279 pushBack(accept_length); 280 this.offset = accept_offset; 281 this.pos = accept_pos; 282 this.line = accept_line; 283 return token; 284 } 285 case 10: 286 { 287 @SuppressWarnings("hiding") Token token = new10( 288 start_offset, 289 start_line + 1, 290 start_pos + 1); 291 pushBack(accept_length); 292 this.offset = accept_offset; 293 this.pos = accept_pos; 294 this.line = accept_line; 295 return token; 296 } 297 case 11: 298 { 299 @SuppressWarnings("hiding") Token token = new11( 300 start_offset, 301 start_line + 1, 302 start_pos + 1); 303 pushBack(accept_length); 304 this.offset = accept_offset; 305 this.pos = accept_pos; 306 this.line = accept_line; 307 return token; 308 } 309 case 12: 310 { 311 @SuppressWarnings("hiding") Token token = new12( 312 start_offset, 313 start_line + 1, 314 start_pos + 1); 315 pushBack(accept_length); 316 this.offset = accept_offset; 317 this.pos = accept_pos; 318 this.line = accept_line; 319 return token; 320 } 321 case 13: 322 { 323 @SuppressWarnings("hiding") Token token = new13( 324 start_offset, 325 start_line + 1, 326 start_pos + 1); 327 pushBack(accept_length); 328 this.offset = accept_offset; 329 this.pos = accept_pos; 330 this.line = accept_line; 331 return token; 332 } 333 case 14: 334 { 335 @SuppressWarnings("hiding") Token token = new14( 336 start_offset, 337 start_line + 1, 338 start_pos + 1); 339 pushBack(accept_length); 340 this.offset = accept_offset; 341 this.pos = accept_pos; 342 this.line = accept_line; 343 return token; 344 } 345 case 15: 346 { 347 @SuppressWarnings("hiding") Token token = new15( 348 start_offset, 349 start_line + 1, 350 start_pos + 1); 351 pushBack(accept_length); 352 this.offset = accept_offset; 353 this.pos = accept_pos; 354 this.line = accept_line; 355 return token; 356 } 357 case 16: 358 { 359 @SuppressWarnings("hiding") Token token = new16( 360 getText(accept_length), 361 start_offset, 362 start_line + 1, 363 start_pos + 1); 364 pushBack(accept_length); 365 this.offset = accept_offset; 366 this.pos = accept_pos; 367 this.line = accept_line; 368 return token; 369 } 370 case 17: 371 { 372 @SuppressWarnings("hiding") Token token = new17( 373 getText(accept_length), 374 start_offset, 375 start_line + 1, 376 start_pos + 1); 377 pushBack(accept_length); 378 this.offset = accept_offset; 379 this.pos = accept_pos; 380 this.line = accept_line; 381 return token; 382 } 383 case 18: 384 { 385 @SuppressWarnings("hiding") Token token = new18( 386 getText(accept_length), 387 start_offset, 388 start_line + 1, 389 start_pos + 1); 390 pushBack(accept_length); 391 this.offset = accept_offset; 392 this.pos = accept_pos; 393 this.line = accept_line; 394 return token; 395 } 396 case 19: 397 { 398 @SuppressWarnings("hiding") Token token = new19( 399 getText(accept_length), 400 start_offset, 401 start_line + 1, 402 start_pos + 1); 403 pushBack(accept_length); 404 this.offset = accept_offset; 405 this.pos = accept_pos; 406 this.line = accept_line; 407 return token; 408 } 409 } 410 } 411 else 412 { 413 if(this.text.length() > 0) 414 { 415 throw new LexerException( 416 "[" + (start_line + 1) + "," + (start_pos + 1) + "]" + 417 " Unknown token: " + this.text); 418 } 419 420 @SuppressWarnings("hiding") EOF token = new EOF( 421 start_offset, 422 start_line + 1, 423 start_pos + 1); 424 return token; 425 } 426 } 427 } 428 } 429 430 Token new0(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokLbrace(offset, line, pos); } 431 Token new1(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokRbrace(offset, line, pos); } 432 Token new2(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokLsquare(offset, line, pos); } 433 Token new3(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokRsquare(offset, line, pos); } 434 Token new4(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokArrow(offset, line, pos); } 435 Token new5(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokLink(offset, line, pos); } 436 Token new6(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokEq(offset, line, pos); } 437 Token new7(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokSemi(offset, line, pos); } 438 Token new8(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokComma(offset, line, pos); } 439 Token new9(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TTokColon(offset, line, pos); } 440 Token new10(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKwStrict(offset, line, pos); } 441 Token new11(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKwGraph(offset, line, pos); } 442 Token new12(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKwDigraph(offset, line, pos); } 443 Token new13(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKwSubgraph(offset, line, pos); } 444 Token new14(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKwNode(offset, line, pos); } 445 Token new15(@SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TKwEdge(offset, line, pos); } 446 Token new16(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TLiteral(text, offset, line, pos); } 447 Token new17(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TStringLiteral(text, offset, line, pos); } 448 Token new18(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TBlank(text, offset, line, pos); } 449 Token new19(@SuppressWarnings("hiding") String text, @SuppressWarnings("hiding") int offset, @SuppressWarnings("hiding") int line, @SuppressWarnings("hiding") int pos) { return new TComment(text, offset, line, pos); } 450 451 private int getChar() throws IOException 452 { 453 if(this.eof) 454 { 455 return -1; 456 } 457 458 int result = this.in.read(); 459 460 if(result == -1) 461 { 462 this.eof = true; 463 } 464 465 return result; 466 } 467 468 private void pushBack(int acceptLength) throws IOException 469 { 470 int length = this.text.length(); 471 for(int i = length - 1; i >= acceptLength; i--) 472 { 473 this.eof = false; 474 475 this.in.unread(this.text.charAt(i)); 476 } 477 } 478 479 protected void unread(@SuppressWarnings("hiding") Token token) throws IOException 480 { 481 @SuppressWarnings("hiding") String text = token.getText(); 482 int length = text.length(); 483 484 for(int i = length - 1; i >= 0; i--) 485 { 486 this.eof = false; 487 488 this.in.unread(text.charAt(i)); 489 } 490 491 this.offset = token.getOffset(); 492 this.pos = token.getPos() - 1; 493 this.line = token.getLine() - 1; 494 } 495 496protected String getText(int acceptLength) { return text.substring(0, acceptLength); } 497 498 private static int[][][][] gotoTable; 499/* { 500 { // INITIAL 501 {{9, 9, 1}, {10, 10, 2}, {13, 13, 3}, {32, 32, 4}, {34, 34, 5}, {35, 35, 6}, {44, 44, 7}, {45, 45, 8}, {46, 46, 9}, {47, 47, 10}, {48, 57, 11}, {58, 58, 12}, {59, 59, 13}, {61, 61, 14}, {65, 90, 15}, {91, 91, 16}, {93, 93, 17}, {95, 95, 15}, {97, 99, 15}, {100, 100, 18}, {101, 101, 19}, {102, 102, 15}, {103, 103, 20}, {104, 109, 15}, {110, 110, 21}, {111, 114, 15}, {115, 115, 22}, {116, 122, 15}, {123, 123, 23}, {125, 125, 24}, }, 502 {{9, 32, -2}, }, 503 {{9, 32, -2}, }, 504 {{9, 9, 1}, {10, 10, 25}, {13, 32, -2}, }, 505 {{9, 32, -2}, }, 506 {{0, 9, 26}, {11, 12, 26}, {14, 33, 26}, {34, 34, 27}, {35, 91, 26}, {92, 92, 28}, {93, 65535, 26}, }, 507 {{0, 9, 29}, {10, 10, 30}, {11, 12, 29}, {13, 13, 31}, {14, 65535, 29}, }, 508 {}, 509 {{45, 45, 32}, {62, 62, 33}, }, 510 {{46, 46, 9}, {48, 57, 11}, {65, 90, 15}, {95, 95, 15}, {97, 122, 15}, }, 511 {{42, 42, 34}, {47, 47, 35}, }, 512 {{46, 122, -11}, }, 513 {}, 514 {}, 515 {}, 516 {{46, 122, -11}, }, 517 {}, 518 {}, 519 {{46, 95, -11}, {97, 104, 15}, {105, 105, 36}, {106, 122, 15}, }, 520 {{46, 95, -11}, {97, 99, 15}, {100, 100, 37}, {101, 122, 15}, }, 521 {{46, 95, -11}, {97, 113, 15}, {114, 114, 38}, {115, 122, 15}, }, 522 {{46, 95, -11}, {97, 110, 15}, {111, 111, 39}, {112, 122, 15}, }, 523 {{46, 95, -11}, {97, 115, 15}, {116, 116, 40}, {117, 117, 41}, {118, 122, 15}, }, 524 {}, 525 {}, 526 {{9, 32, -2}, }, 527 {{0, 65535, -7}, }, 528 {}, 529 {{34, 34, 42}, {39, 39, 43}, {63, 63, 44}, {92, 92, 45}, {97, 97, 46}, {98, 98, 47}, {102, 102, 48}, {108, 108, 49}, {110, 110, 50}, {114, 114, 51}, {116, 116, 52}, {118, 118, 53}, }, 530 {{0, 65535, -8}, }, 531 {}, 532 {{10, 10, 54}, }, 533 {}, 534 {}, 535 {{0, 41, 55}, {42, 42, 56}, {43, 65535, 55}, }, 536 {{0, 9, 57}, {10, 10, 58}, {11, 12, 57}, {13, 13, 59}, {14, 65535, 57}, }, 537 {{46, 95, -11}, {97, 102, 15}, {103, 103, 60}, {104, 122, 15}, }, 538 {{46, 102, -38}, {103, 103, 61}, {104, 122, 15}, }, 539 {{46, 95, -11}, {97, 97, 62}, {98, 122, 15}, }, 540 {{46, 99, -21}, {100, 100, 63}, {101, 122, 15}, }, 541 {{46, 113, -22}, {114, 114, 64}, {115, 122, 15}, }, 542 {{46, 95, -11}, {97, 97, 15}, {98, 98, 65}, {99, 122, 15}, }, 543 {{0, 65535, -7}, }, 544 {{0, 65535, -7}, }, 545 {{0, 65535, -7}, }, 546 {{0, 65535, -7}, }, 547 {{0, 65535, -7}, }, 548 {{0, 65535, -7}, }, 549 {{0, 65535, -7}, }, 550 {{0, 65535, -7}, }, 551 {{0, 65535, -7}, }, 552 {{0, 65535, -7}, }, 553 {{0, 65535, -7}, }, 554 {{0, 65535, -7}, }, 555 {}, 556 {{0, 65535, -36}, }, 557 {{0, 41, 66}, {42, 42, 56}, {43, 46, 66}, {47, 47, 67}, {48, 65535, 66}, }, 558 {{0, 65535, -37}, }, 559 {}, 560 {{10, 10, 68}, }, 561 {{46, 113, -22}, {114, 114, 69}, {115, 122, 15}, }, 562 {{46, 95, -11}, {97, 100, 15}, {101, 101, 70}, {102, 122, 15}, }, 563 {{46, 95, -11}, {97, 111, 15}, {112, 112, 71}, {113, 122, 15}, }, 564 {{46, 100, -63}, {101, 101, 72}, {102, 122, 15}, }, 565 {{46, 104, -20}, {105, 105, 73}, {106, 122, 15}, }, 566 {{46, 102, -38}, {103, 103, 74}, {104, 122, 15}, }, 567 {{0, 41, 75}, {42, 42, 76}, {43, 65535, 75}, }, 568 {}, 569 {}, 570 {{46, 95, -11}, {97, 97, 77}, {98, 122, 15}, }, 571 {{46, 122, -11}, }, 572 {{46, 95, -11}, {97, 103, 15}, {104, 104, 78}, {105, 122, 15}, }, 573 {{46, 122, -11}, }, 574 {{46, 95, -11}, {97, 98, 15}, {99, 99, 79}, {100, 122, 15}, }, 575 {{46, 113, -22}, {114, 114, 80}, {115, 122, 15}, }, 576 {{0, 65535, -68}, }, 577 {{0, 41, 66}, {42, 42, 76}, {43, 65535, -58}, }, 578 {{46, 111, -64}, {112, 112, 81}, {113, 122, 15}, }, 579 {{46, 122, -11}, }, 580 {{46, 115, -24}, {116, 116, 82}, {117, 122, 15}, }, 581 {{46, 95, -11}, {97, 97, 83}, {98, 122, 15}, }, 582 {{46, 103, -73}, {104, 104, 84}, {105, 122, 15}, }, 583 {{46, 122, -11}, }, 584 {{46, 111, -64}, {112, 112, 85}, {113, 122, 15}, }, 585 {{46, 122, -11}, }, 586 {{46, 103, -73}, {104, 104, 86}, {105, 122, 15}, }, 587 {{46, 122, -11}, }, 588 } 589 };*/ 590 591 private static int[][] accept; 592/* { 593 // INITIAL 594 {16, 18, 18, 18, 18, -1, 19, 8, -1, 16, -1, 16, 9, 7, 6, 16, 2, 3, 16, 16, 16, 16, 16, 0, 1, 18, -1, 17, -1, 19, 19, 19, 5, 4, -1, 19, 16, 16, 16, 16, 16, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 19, -1, -1, 19, 19, 19, 16, 16, 16, 16, 16, 16, -1, 19, 19, 16, 15, 16, 14, 16, 16, -1, -1, 16, 11, 16, 16, 16, 10, 16, 12, 16, 13, }, 595 596 };*/ 597 598 public static class State 599 { 600 public final static State INITIAL = new State(0); 601 602 private int id; 603 604 private State(@SuppressWarnings("hiding") int id) 605 { 606 this.id = id; 607 } 608 609 public int id() 610 { 611 return this.id; 612 } 613 } 614 615 static 616 { 617 try 618 { 619 DataInputStream s = new DataInputStream( 620 new BufferedInputStream( 621 Lexer.class.getResourceAsStream("lexer.dat"))); 622 623 // read gotoTable 624 int length = s.readInt(); 625 gotoTable = new int[length][][][]; 626 for(int i = 0; i < gotoTable.length; i++) 627 { 628 length = s.readInt(); 629 gotoTable[i] = new int[length][][]; 630 for(int j = 0; j < gotoTable[i].length; j++) 631 { 632 length = s.readInt(); 633 gotoTable[i][j] = new int[length][3]; 634 for(int k = 0; k < gotoTable[i][j].length; k++) 635 { 636 for(int l = 0; l < 3; l++) 637 { 638 gotoTable[i][j][k][l] = s.readInt(); 639 } 640 } 641 } 642 } 643 644 // read accept 645 length = s.readInt(); 646 accept = new int[length][]; 647 for(int i = 0; i < accept.length; i++) 648 { 649 length = s.readInt(); 650 accept[i] = new int[length]; 651 for(int j = 0; j < accept[i].length; j++) 652 { 653 accept[i][j] = s.readInt(); 654 } 655 } 656 657 s.close(); 658 } 659 catch(Exception e) 660 { 661 throw new RuntimeException("The file \"lexer.dat\" is either missing or corrupted."); 662 } 663 } 664}