001/* Generated By:JavaCC: Do not edit this line. GMLParserTokenManager.java */ 002/* 003 * Copyright 2006 - 2012 004 * Julien Baudry <julien.baudry@graphstream-project.org> 005 * Antoine Dutot <antoine.dutot@graphstream-project.org> 006 * Yoann Pigné <yoann.pigne@graphstream-project.org> 007 * Guilhelm Savin <guilhelm.savin@graphstream-project.org> 008 * 009 * This file is part of GraphStream <http://graphstream-project.org>. 010 * 011 * GraphStream is a library whose purpose is to handle static or dynamic 012 * graph, create them from scratch, file or any source and display them. 013 * 014 * This program is free software distributed under the terms of two licenses, the 015 * CeCILL-C license that fits European law, and the GNU Lesser General Public 016 * License. You can use, modify and/ or redistribute the software under the terms 017 * of the CeCILL-C license as circulated by CEA, CNRS and INRIA at the following 018 * URL <http://www.cecill.info> or under the terms of the GNU LGPL as published by 019 * the Free Software Foundation, either version 3 of the License, or (at your 020 * option) any later version. 021 * 022 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 023 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 024 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 025 * 026 * You should have received a copy of the GNU Lesser General Public License 027 * along with this program. If not, see <http://www.gnu.org/licenses/>. 028 * 029 * The fact that you are presently reading this means that you have had 030 * knowledge of the CeCILL-C and LGPL licenses and that you accept their terms. 031 */ 032package org.graphstream.stream.file.gml; 033 034import org.graphstream.util.parser.SimpleCharStream; 035import org.graphstream.util.parser.Token; 036import org.graphstream.util.parser.TokenMgrError; 037 038/** Token Manager. */ 039public class GMLParserTokenManager implements GMLParserConstants { 040 041 /** Debug output. */ 042 public java.io.PrintStream debugStream = System.out; 043 044 /** Set debug output. */ 045 public void setDebugStream(java.io.PrintStream ds) { 046 debugStream = ds; 047 } 048 049 private final int jjStopStringLiteralDfa_0(int pos, long active0) { 050 switch (pos) { 051 case 0: 052 if ((active0 & 0x3000L) != 0L) { 053 jjmatchedKind = 14; 054 return 11; 055 } 056 return -1; 057 case 1: 058 if ((active0 & 0x3000L) != 0L) { 059 jjmatchedKind = 14; 060 jjmatchedPos = 1; 061 return 11; 062 } 063 return -1; 064 case 2: 065 if ((active0 & 0x3000L) != 0L) { 066 jjmatchedKind = 14; 067 jjmatchedPos = 2; 068 return 11; 069 } 070 return -1; 071 case 3: 072 if ((active0 & 0x3000L) != 0L) { 073 jjmatchedKind = 14; 074 jjmatchedPos = 3; 075 return 11; 076 } 077 return -1; 078 case 4: 079 if ((active0 & 0x1000L) != 0L) 080 return 11; 081 if ((active0 & 0x2000L) != 0L) { 082 jjmatchedKind = 14; 083 jjmatchedPos = 4; 084 return 11; 085 } 086 return -1; 087 case 5: 088 if ((active0 & 0x2000L) != 0L) { 089 jjmatchedKind = 14; 090 jjmatchedPos = 5; 091 return 11; 092 } 093 return -1; 094 default: 095 return -1; 096 } 097 } 098 099 private final int jjStartNfa_0(int pos, long active0) { 100 return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); 101 } 102 103 private int jjStopAtPos(int pos, int kind) { 104 jjmatchedKind = kind; 105 jjmatchedPos = pos; 106 return pos + 1; 107 } 108 109 private int jjMoveStringLiteralDfa0_0() { 110 switch (curChar) { 111 case 91: 112 return jjStopAtPos(0, 8); 113 case 93: 114 return jjStopAtPos(0, 9); 115 case 68: 116 case 100: 117 return jjMoveStringLiteralDfa1_0(0x2000L); 118 case 71: 119 case 103: 120 return jjMoveStringLiteralDfa1_0(0x1000L); 121 default: 122 return jjMoveNfa_0(0, 0); 123 } 124 } 125 126 private int jjMoveStringLiteralDfa1_0(long active0) { 127 try { 128 curChar = input_stream.readChar(); 129 } catch (java.io.IOException e) { 130 jjStopStringLiteralDfa_0(0, active0); 131 return 1; 132 } 133 switch (curChar) { 134 case 73: 135 case 105: 136 return jjMoveStringLiteralDfa2_0(active0, 0x2000L); 137 case 82: 138 case 114: 139 return jjMoveStringLiteralDfa2_0(active0, 0x1000L); 140 default: 141 break; 142 } 143 return jjStartNfa_0(0, active0); 144 } 145 146 private int jjMoveStringLiteralDfa2_0(long old0, long active0) { 147 if (((active0 &= old0)) == 0L) 148 return jjStartNfa_0(0, old0); 149 try { 150 curChar = input_stream.readChar(); 151 } catch (java.io.IOException e) { 152 jjStopStringLiteralDfa_0(1, active0); 153 return 2; 154 } 155 switch (curChar) { 156 case 65: 157 case 97: 158 return jjMoveStringLiteralDfa3_0(active0, 0x1000L); 159 case 71: 160 case 103: 161 return jjMoveStringLiteralDfa3_0(active0, 0x2000L); 162 default: 163 break; 164 } 165 return jjStartNfa_0(1, active0); 166 } 167 168 private int jjMoveStringLiteralDfa3_0(long old0, long active0) { 169 if (((active0 &= old0)) == 0L) 170 return jjStartNfa_0(1, old0); 171 try { 172 curChar = input_stream.readChar(); 173 } catch (java.io.IOException e) { 174 jjStopStringLiteralDfa_0(2, active0); 175 return 3; 176 } 177 switch (curChar) { 178 case 80: 179 case 112: 180 return jjMoveStringLiteralDfa4_0(active0, 0x1000L); 181 case 82: 182 case 114: 183 return jjMoveStringLiteralDfa4_0(active0, 0x2000L); 184 default: 185 break; 186 } 187 return jjStartNfa_0(2, active0); 188 } 189 190 private int jjMoveStringLiteralDfa4_0(long old0, long active0) { 191 if (((active0 &= old0)) == 0L) 192 return jjStartNfa_0(2, old0); 193 try { 194 curChar = input_stream.readChar(); 195 } catch (java.io.IOException e) { 196 jjStopStringLiteralDfa_0(3, active0); 197 return 4; 198 } 199 switch (curChar) { 200 case 65: 201 case 97: 202 return jjMoveStringLiteralDfa5_0(active0, 0x2000L); 203 case 72: 204 case 104: 205 if ((active0 & 0x1000L) != 0L) 206 return jjStartNfaWithStates_0(4, 12, 11); 207 break; 208 default: 209 break; 210 } 211 return jjStartNfa_0(3, active0); 212 } 213 214 private int jjMoveStringLiteralDfa5_0(long old0, long active0) { 215 if (((active0 &= old0)) == 0L) 216 return jjStartNfa_0(3, old0); 217 try { 218 curChar = input_stream.readChar(); 219 } catch (java.io.IOException e) { 220 jjStopStringLiteralDfa_0(4, active0); 221 return 5; 222 } 223 switch (curChar) { 224 case 80: 225 case 112: 226 return jjMoveStringLiteralDfa6_0(active0, 0x2000L); 227 default: 228 break; 229 } 230 return jjStartNfa_0(4, active0); 231 } 232 233 private int jjMoveStringLiteralDfa6_0(long old0, long active0) { 234 if (((active0 &= old0)) == 0L) 235 return jjStartNfa_0(4, old0); 236 try { 237 curChar = input_stream.readChar(); 238 } catch (java.io.IOException e) { 239 jjStopStringLiteralDfa_0(5, active0); 240 return 6; 241 } 242 switch (curChar) { 243 case 72: 244 case 104: 245 if ((active0 & 0x2000L) != 0L) 246 return jjStartNfaWithStates_0(6, 13, 11); 247 break; 248 default: 249 break; 250 } 251 return jjStartNfa_0(5, active0); 252 } 253 254 private int jjStartNfaWithStates_0(int pos, int kind, int state) { 255 jjmatchedKind = kind; 256 jjmatchedPos = pos; 257 try { 258 curChar = input_stream.readChar(); 259 } catch (java.io.IOException e) { 260 return pos + 1; 261 } 262 return jjMoveNfa_0(state, pos + 1); 263 } 264 265 static final long[] jjbitVec0 = { 0x0L, 0x0L, 0xffffffffffffffffL, 266 0xffffffffffffffffL }; 267 268 private int jjMoveNfa_0(int startState, int curPos) { 269 int startsAt = 0; 270 jjnewStateCnt = 15; 271 int i = 1; 272 jjstateSet[0] = startState; 273 int kind = 0x7fffffff; 274 for (;;) { 275 if (++jjround == 0x7fffffff) 276 ReInitRounds(); 277 if (curChar < 64) { 278 long l = 1L << curChar; 279 do { 280 switch (jjstateSet[--i]) { 281 case 0: 282 if ((0x3ff000000000000L & l) != 0L) { 283 if (kind > 10) 284 kind = 10; 285 jjCheckNAddTwoStates(1, 2); 286 } else if ((0x280000000000L & l) != 0L) { 287 if (kind > 14) 288 kind = 14; 289 jjCheckNAdd(11); 290 } else if (curChar == 35) 291 jjCheckNAddTwoStates(13, 14); 292 else if (curChar == 39) 293 jjCheckNAddTwoStates(8, 9); 294 else if (curChar == 34) 295 jjCheckNAddTwoStates(5, 6); 296 if ((0x280000000000L & l) != 0L) 297 jjCheckNAdd(1); 298 break; 299 case 1: 300 if ((0x3ff000000000000L & l) == 0L) 301 break; 302 if (kind > 10) 303 kind = 10; 304 jjCheckNAddTwoStates(1, 2); 305 break; 306 case 2: 307 if (curChar == 46) 308 jjCheckNAdd(3); 309 break; 310 case 3: 311 if ((0x3ff000000000000L & l) == 0L) 312 break; 313 if (kind > 10) 314 kind = 10; 315 jjCheckNAdd(3); 316 break; 317 case 4: 318 if (curChar == 34) 319 jjCheckNAddTwoStates(5, 6); 320 break; 321 case 5: 322 if ((0xfffffffbffffffffL & l) != 0L) 323 jjCheckNAddTwoStates(5, 6); 324 break; 325 case 6: 326 if (curChar == 34 && kind > 11) 327 kind = 11; 328 break; 329 case 7: 330 if (curChar == 39) 331 jjCheckNAddTwoStates(8, 9); 332 break; 333 case 8: 334 if ((0xffffff7fffffffffL & l) != 0L) 335 jjCheckNAddTwoStates(8, 9); 336 break; 337 case 9: 338 if (curChar == 39 && kind > 11) 339 kind = 11; 340 break; 341 case 10: 342 if ((0x280000000000L & l) == 0L) 343 break; 344 if (kind > 14) 345 kind = 14; 346 jjCheckNAdd(11); 347 break; 348 case 11: 349 if ((0x3ff600000000000L & l) == 0L) 350 break; 351 if (kind > 14) 352 kind = 14; 353 jjCheckNAdd(11); 354 break; 355 case 12: 356 if (curChar == 35) 357 jjCheckNAddTwoStates(13, 14); 358 break; 359 case 13: 360 if ((0xffffffffffffdbffL & l) != 0L) 361 jjCheckNAddTwoStates(13, 14); 362 break; 363 case 14: 364 if ((0x2400L & l) != 0L && kind > 15) 365 kind = 15; 366 break; 367 default: 368 break; 369 } 370 } while (i != startsAt); 371 } else if (curChar < 128) { 372 long l = 1L << (curChar & 077); 373 do { 374 switch (jjstateSet[--i]) { 375 case 0: 376 if ((0x7fffffe07fffffeL & l) == 0L) 377 break; 378 if (kind > 14) 379 kind = 14; 380 jjCheckNAdd(11); 381 break; 382 case 5: 383 jjAddStates(0, 1); 384 break; 385 case 8: 386 jjAddStates(2, 3); 387 break; 388 case 11: 389 if ((0x7fffffe87fffffeL & l) == 0L) 390 break; 391 if (kind > 14) 392 kind = 14; 393 jjCheckNAdd(11); 394 break; 395 case 13: 396 jjAddStates(4, 5); 397 break; 398 default: 399 break; 400 } 401 } while (i != startsAt); 402 } else { 403 int i2 = (curChar & 0xff) >> 6; 404 long l2 = 1L << (curChar & 077); 405 do { 406 switch (jjstateSet[--i]) { 407 case 5: 408 if ((jjbitVec0[i2] & l2) != 0L) 409 jjAddStates(0, 1); 410 break; 411 case 8: 412 if ((jjbitVec0[i2] & l2) != 0L) 413 jjAddStates(2, 3); 414 break; 415 case 13: 416 if ((jjbitVec0[i2] & l2) != 0L) 417 jjAddStates(4, 5); 418 break; 419 default: 420 break; 421 } 422 } while (i != startsAt); 423 } 424 if (kind != 0x7fffffff) { 425 jjmatchedKind = kind; 426 jjmatchedPos = curPos; 427 kind = 0x7fffffff; 428 } 429 ++curPos; 430 if ((i = jjnewStateCnt) == (startsAt = 15 - (jjnewStateCnt = startsAt))) 431 return curPos; 432 try { 433 curChar = input_stream.readChar(); 434 } catch (java.io.IOException e) { 435 return curPos; 436 } 437 } 438 } 439 440 static final int[] jjnextStates = { 5, 6, 8, 9, 13, 14, }; 441 442 /** Token literal values. */ 443 public static final String[] jjstrLiteralImages = { "", null, null, null, 444 null, null, null, null, "\133", "\135", null, null, null, null, 445 null, null, }; 446 447 /** Lexer state names. */ 448 public static final String[] lexStateNames = { "DEFAULT", }; 449 static final long[] jjtoToken = { 0xff01L, }; 450 static final long[] jjtoSkip = { 0x1eL, }; 451 protected SimpleCharStream input_stream; 452 private final int[] jjrounds = new int[15]; 453 private final int[] jjstateSet = new int[30]; 454 protected char curChar; 455 456 /** Constructor. */ 457 public GMLParserTokenManager(SimpleCharStream stream) { 458 if (SimpleCharStream.staticFlag) 459 throw new Error( 460 "ERROR: Cannot use a static CharStream class with a non-static lexical analyzer."); 461 input_stream = stream; 462 } 463 464 /** Constructor. */ 465 public GMLParserTokenManager(SimpleCharStream stream, int lexState) { 466 this(stream); 467 SwitchTo(lexState); 468 } 469 470 /** Reinitialise parser. */ 471 public void ReInit(SimpleCharStream stream) { 472 jjmatchedPos = jjnewStateCnt = 0; 473 curLexState = defaultLexState; 474 input_stream = stream; 475 ReInitRounds(); 476 } 477 478 private void ReInitRounds() { 479 int i; 480 jjround = 0x80000001; 481 for (i = 15; i-- > 0;) 482 jjrounds[i] = 0x80000000; 483 } 484 485 /** Reinitialise parser. */ 486 public void ReInit(SimpleCharStream stream, int lexState) { 487 ReInit(stream); 488 SwitchTo(lexState); 489 } 490 491 /** Switch to specified lex state. */ 492 public void SwitchTo(int lexState) { 493 if (lexState >= 1 || lexState < 0) 494 throw new TokenMgrError("Error: Ignoring invalid lexical state : " 495 + lexState + ". State unchanged.", 496 TokenMgrError.INVALID_LEXICAL_STATE); 497 else 498 curLexState = lexState; 499 } 500 501 protected Token jjFillToken() { 502 final Token t; 503 final String curTokenImage; 504 final int beginLine; 505 final int endLine; 506 final int beginColumn; 507 final int endColumn; 508 String im = jjstrLiteralImages[jjmatchedKind]; 509 curTokenImage = (im == null) ? input_stream.GetImage() : im; 510 beginLine = input_stream.getBeginLine(); 511 beginColumn = input_stream.getBeginColumn(); 512 endLine = input_stream.getEndLine(); 513 endColumn = input_stream.getEndColumn(); 514 t = Token.newToken(jjmatchedKind, curTokenImage); 515 516 t.beginLine = beginLine; 517 t.endLine = endLine; 518 t.beginColumn = beginColumn; 519 t.endColumn = endColumn; 520 521 return t; 522 } 523 524 int curLexState = 0; 525 int defaultLexState = 0; 526 int jjnewStateCnt; 527 int jjround; 528 int jjmatchedPos; 529 int jjmatchedKind; 530 531 /** Get the next Token. */ 532 public Token getNextToken() { 533 Token matchedToken; 534 int curPos = 0; 535 536 EOFLoop: for (;;) { 537 try { 538 curChar = input_stream.BeginToken(); 539 } catch (java.io.IOException e) { 540 jjmatchedKind = 0; 541 matchedToken = jjFillToken(); 542 return matchedToken; 543 } 544 545 try { 546 input_stream.backup(0); 547 while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L) 548 curChar = input_stream.BeginToken(); 549 } catch (java.io.IOException e1) { 550 continue EOFLoop; 551 } 552 jjmatchedKind = 0x7fffffff; 553 jjmatchedPos = 0; 554 curPos = jjMoveStringLiteralDfa0_0(); 555 if (jjmatchedKind != 0x7fffffff) { 556 if (jjmatchedPos + 1 < curPos) 557 input_stream.backup(curPos - jjmatchedPos - 1); 558 if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L) { 559 matchedToken = jjFillToken(); 560 return matchedToken; 561 } else { 562 continue EOFLoop; 563 } 564 } 565 int error_line = input_stream.getEndLine(); 566 int error_column = input_stream.getEndColumn(); 567 String error_after = null; 568 boolean EOFSeen = false; 569 try { 570 input_stream.readChar(); 571 input_stream.backup(1); 572 } catch (java.io.IOException e1) { 573 EOFSeen = true; 574 error_after = curPos <= 1 ? "" : input_stream.GetImage(); 575 if (curChar == '\n' || curChar == '\r') { 576 error_line++; 577 error_column = 0; 578 } else 579 error_column++; 580 } 581 if (!EOFSeen) { 582 input_stream.backup(1); 583 error_after = curPos <= 1 ? "" : input_stream.GetImage(); 584 } 585 throw new TokenMgrError(EOFSeen, curLexState, error_line, 586 error_column, error_after, curChar, 587 TokenMgrError.LEXICAL_ERROR); 588 } 589 } 590 591 private void jjCheckNAdd(int state) { 592 if (jjrounds[state] != jjround) { 593 jjstateSet[jjnewStateCnt++] = state; 594 jjrounds[state] = jjround; 595 } 596 } 597 598 private void jjAddStates(int start, int end) { 599 do { 600 jjstateSet[jjnewStateCnt++] = jjnextStates[start]; 601 } while (start++ != end); 602 } 603 604 private void jjCheckNAddTwoStates(int state1, int state2) { 605 jjCheckNAdd(state1); 606 jjCheckNAdd(state2); 607 } 608 609}