1 2 12 package com.versant.core.jdo.tools.ant; 13 14 15 import java.io.*; 16 import java.util.ArrayList ; 17 import java.util.Iterator ; 18 19 36 public class SQLScriptParser { 37 38 39 final public static int YYEOF = -1; 40 41 42 final private static int YY_BUFFERSIZE = 16384; 43 44 45 final public static int YYINITIAL = 0; 46 final public static int COMMENT = 1; 47 48 51 final private static char[] yycmap = { 52 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 13, 0, 4, 13, 0, 0, 53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 54 4, 10, 6, 10, 8, 10, 10, 12, 9, 9, 11, 19, 9, 20, 17, 21, 55 16, 16, 7, 7, 7, 7, 7, 7, 7, 7, 9, 1, 10, 10, 10, 10, 56 10, 0, 15, 0, 0, 18, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 57 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 14, 9, 10, 5, 58 10, 0, 15, 0, 0, 18, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 59 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 10, 0, 60 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 68 }; 69 70 73 final private static int yy_rowMap [] = { 74 0, 22, 44, 66, 88, 110, 66, 132, 154, 66, 75 66, 176, 198, 220, 242, 264, 286, 308, 330, 44, 76 352, 374, 154, 176, 66, 66, 396, 418, 440, 66, 77 462, 484, 308, 66, 66, 506, 176, 528, 550, 66, 78 572, 594, 506, 616, 550, 528, 66, 638 79 }; 80 81 84 final private static String yy_packed0 = 85 "\1\3\1\4\1\5\1\3\1\6\2\7\1\10\1\11" + 86 "\1\12\1\13\1\12\1\14\1\6\1\3\1\15\1\10" + 87 "\1\16\1\3\1\13\1\17\1\20\13\21\1\22\11\21" + 88 "\1\23\1\3\1\0\2\3\1\0\1\3\1\0\1\3" + 89 "\6\0\3\3\1\0\1\3\31\0\1\3\1\0\1\3" + 90 "\1\24\1\0\1\3\1\0\1\3\6\0\3\3\1\0" + 91 "\1\3\7\0\1\6\10\0\1\6\17\0\1\10\10\0" + 92 "\1\10\1\25\1\26\12\0\1\27\10\0\1\27\5\0" + 93 "\14\30\1\31\1\32\1\33\7\30\1\3\1\0\2\3" + 94 "\1\0\1\3\1\0\1\3\4\0\1\34\1\0\3\3" + 95 "\1\0\1\3\12\0\1\25\10\0\1\25\31\0\1\35" + 96 "\14\0\1\36\12\0\13\21\1\37\11\21\1\40\13\21" + 97 "\1\41\11\21\1\42\13\21\1\43\11\21\1\40\7\0" + 98 "\1\25\10\0\1\25\1\0\1\26\26\0\2\44\1\0" + 99 "\14\30\1\45\1\32\1\33\7\30\14\46\1\47\1\50" + 100 "\1\51\1\46\1\52\5\46\15\35\1\0\10\35\13\21" + 101 "\1\37\11\21\1\0\13\21\1\0\11\21\1\40\7\0" + 102 "\1\53\10\0\1\53\5\0\14\46\1\47\1\50\1\51" + 103 "\1\46\1\54\5\46\14\55\1\47\1\0\2\55\1\0" + 104 "\5\55\14\46\1\56\1\50\1\51\1\46\1\54\5\46" + 105 "\14\54\1\57\1\50\1\60\1\54\1\52\21\54\1\0" + 106 "\1\50\1\60\24\54\1\50\1\60\7\54"; 107 108 111 final private static int yytrans [] = yy_unpack(); 112 113 114 115 final private static int YY_UNKNOWN_ERROR = 0; 116 final private static int YY_ILLEGAL_STATE = 1; 117 final private static int YY_NO_MATCH = 2; 118 final private static int YY_PUSHBACK_2BIG = 3; 119 120 121 final private static String YY_ERROR_MSG[] = { 122 "Unkown internal scanner error", 123 "Internal error: unknown state", 124 "Error: could not match input", 125 "Error: pushback value was too large" 126 }; 127 128 131 private final static byte YY_ATTRIBUTE[] = { 132 1, 1, 1, 9, 1, 1, 9, 1, 1, 9, 9, 1, 1, 1, 1, 1, 133 1, 1, 1, 1, 1, 0, 1, 0, 9, 9, 0, 0, 1, 9, 0, 0, 134 0, 9, 9, 0, 1, 0, 1, 9, 0, 0, 1, 0, 0, 1, 9, 0 135 }; 136 137 138 private java.io.Reader yy_reader; 139 140 141 private int yy_state; 142 143 144 private int yy_lexical_state = YYINITIAL; 145 146 148 private char yy_buffer[] = new char[YY_BUFFERSIZE]; 149 150 151 private int yy_markedPos; 152 153 154 private int yy_pushbackPos; 155 156 157 private int yy_currentPos; 158 159 160 private int yy_startRead; 161 162 164 private int yy_endRead; 165 166 167 private int yyline; 168 169 170 private int yychar; 171 172 176 private int yycolumn; 177 178 181 private boolean yy_atBOL = true; 182 183 184 private boolean yy_atEOF; 185 186 187 private int lastToken; 188 private int nextState = YYINITIAL; 189 private StringBuffer commentBuffer = new StringBuffer (); 190 private int commentNestCount = 0; 191 private int commentStartLine = 0; 192 private int commentStartChar = 0; 193 194 198 public Token getNextToken(boolean returnComments, boolean returnWhiteSpace) throws IOException { 199 Token t = getNextToken(); 200 while (t != null && ((!returnWhiteSpace && t.isWhiteSpace()) || (!returnComments && t.isComment()))) { 201 t = getNextToken(); 202 } 203 return (t); 204 } 205 206 public SQLScriptParser() { 207 } 208 209 217 public static void main(String [] args) { 218 String sql = 219 "123456789 ;-- kdlfhjkl; sdfghjdl;fkhkdfjghl fghldfkklh flhkdfhj \n" + 220 " lkh"+ 221 "CREATE TABLE temp_abstract1_a (\n" + 222 " ';;;;;\\n'" + 223 " abstract1_id INTEGER NOT NULL, /* <pk> */\n" + 224 " abs1 VARCHAR(25), /* abs1 */\n" + 225 " jdo_class INTEGER NOT NULL, /* <class-id> */\n" + 226 " jdo_version SMALLINT NOT NULL, /* <opt-lock> */\n" + 227 " abs2 VARCHAR(190), /* Abstract2.abs2 */\n" + 228 " conc1 VARCHAR(190), /* Concrete1.conc1 */\n" + 229 " conc2 VARCHAR(190) /* Concrete2.conc2 */\n" + 230 ");\n" + 231 "INSERT INTO temp_abstract1_a (abstract1_id, abs1, jdo_class, jdo_version, abs2, conc1, conc2) \n" + 232 "SELECT abstract1_id, \n" + 233 " CAST(abs1 AS VARCHAR(25)), \n" + 234 " jdo_class, \n" + 235 " jdo_version, \n" + 236 " abs2, \n" + 237 " conc1, \n" + 238 " conc2\n" + 239 " FROM abstract1;\n" + 240 "DROP TABLE abstract1;\n" + 241 "CREATE TABLE abstract1 (\n" + 242 " abstract1_id INTEGER NOT NULL, /* <pk> */\n" + 243 " abs1 VARCHAR(25), /* abs1 */\n" + 244 " jdo_class INTEGER NOT NULL, /* <class-id> */\n" + 245 " jdo_version SMALLINT NOT NULL, /* <opt-lock> */\n" + 246 " abs2 VARCHAR(190), /* Abstract2.abs2 */\n" + 247 " conc1 VARCHAR(190), /* Concrete1.conc1 */\n" + 248 " conc2 VARCHAR(190), /* Concrete2.conc2 */\n" + 249 " CONSTRAINT pk_abstract1 PRIMARY KEY (abstract1_id)\n" + 250 ");\n" + 251 "INSERT INTO abstract1 (abstract1_id, abs1, jdo_class, jdo_version, abs2, conc1, conc2) \n" + 252 "SELECT abstract1_id, \n" + 253 " abs1, \n" + 254 " jdo_class, \n" + 255 " jdo_version, \n" + 256 " abs2, \n" + 257 " conc1, \n" + 258 " conc2\n" + 259 260 " FROM temp_abstract1_a;\n" + 261 "DROP TABLE temp_abstract1_a;\n" + 262 "\n" + 263 "ALTER TABLE emp_super_person3 ADD CONSTRAINT ref_emp_super_person3_person FOREIGN KEY (person_id) REFERENCES person(person_id);\n" + 264 "\n" + 265 "ALTER TABLE person3_person ADD CONSTRAINT ref_person3_person_person FOREIGN KEY (person_id) REFERENCES person(person_id);\n" + 266 ""; 267 268 try { 269 SQLScriptParser shredder = new SQLScriptParser(); 270 ArrayList list = shredder.parse(sql, true); 271 for (Iterator iter = list.iterator(); iter.hasNext();) { 272 SQLScriptPart scriptPart = (SQLScriptPart) iter.next(); 273 System.out.println("start = " + scriptPart.getStart()); 274 System.out.println("end = " + scriptPart.getEnd()); 275 System.out.println(scriptPart.getSql()); 276 } 277 278 279 } catch (IOException e) { 280 System.out.println(e.getMessage()); 281 } 282 } 283 284 public ArrayList parse(String sql, boolean eraseNewLine) throws IOException { 285 StringReader in = new StringReader(sql+ "\n;"); 286 return parse(in, eraseNewLine); 287 } 288 289 private ArrayList parse(Reader sql, boolean eraseNewLine) throws IOException { 290 SQLScriptParser shredder = new SQLScriptParser(sql); 291 Token t; 292 boolean first = true; 293 ArrayList list = new ArrayList (); 294 SQLScriptPart part = new SQLScriptPart(); 295 while ((t = shredder.getNextToken()) != null) { 296 297 switch (t.getID()) { 298 case Token.WHITE_SPACE: 299 if (!first) { 300 if (eraseNewLine) { 301 part.addSql(' '); 302 } else { 303 part.addSql(t.getContents()); 304 } 305 } 306 break; 307 308 case Token.COMMENT_END_OF_LINE: 309 case Token.COMMENT_TRADITIONAL: 310 break; 311 312 case Token.RESERVED_WORD: 313 if (!first) { 314 list.add(part); 315 part = new SQLScriptPart(); 316 first = true; 317 } 318 break; 319 320 default: 321 if (first) { 322 part.setStart(t.getCharBegin()); 323 first = false; 324 } 325 part.addSql(t.getContents()); 326 part.setEnd(t.getCharEnd()); 327 break; 328 } 329 } 330 331 332 return list; 333 } 334 335 338 public static class SQLScriptPart { 339 private int start; 340 private int end; 341 private StringBuffer sql = new StringBuffer (); 342 343 public int getEnd() { 344 return end; 345 } 346 347 public void setEnd(int end) { 348 this.end = end; 349 } 350 351 public String getSql() { 352 return sql.toString().trim(); 353 } 354 355 public void addSql(String sql) { 356 this.sql.append(sql); 357 } 358 359 public void addSql(char sql) { 360 this.sql.append(sql); 361 } 362 363 public int getStart() { 364 return start; 365 } 366 367 public void setStart(int start) { 368 this.start = start; 369 } 370 } 371 372 380 public static class Token { 381 384 public static final int UNDEFINED_STATE = -1; 385 386 392 public static final int INITIAL_STATE = 0; 393 396 public final static int RESERVED_WORD = 0x100; 397 398 401 public final static int IDENTIFIER = 0x200; 402 403 406 public final static int LITERAL_STRING = 0x300; 407 410 public final static int LITERAL_BIT_STRING = 0x310; 411 414 public final static int LITERAL_INTEGER = 0x320; 415 418 public final static int LITERAL_FLOAT = 0x330; 419 420 423 public final static int SEPARATOR = 0x400; 424 425 428 public final static int DOT_SEPARATOR = 0x410; 429 430 433 public final static int OPERATOR = 0x500; 434 435 438 public final static int COMMENT_TRADITIONAL = 0xD00; 439 440 443 public final static int COMMENT_END_OF_LINE = 0xD10; 444 445 448 public final static int WHITE_SPACE = 0xE00; 449 450 453 public final static int ERROR = 0xF00; 454 457 public final static int ERROR_UNCLOSED_COMMENT = 0xF02; 458 461 public final static int ERROR_UNCLOSED_STRING = 0xF03; 462 465 public final static int ERROR_UNCLOSED_BIT_STRING = 0xF04; 466 469 public final static int ERROR_BAD_BIT_STRING = 0xF05; 470 471 private int ID; 472 private String contents; 473 private int lineNumber; 474 private int charBegin; 475 private int charEnd; 476 private int state; 477 478 488 public Token(int ID, String contents, int lineNumber, int charBegin, int charEnd) { 489 this(ID, contents, lineNumber, charBegin, charEnd, Token.UNDEFINED_STATE); 490 } 491 492 503 public Token(int ID, String contents, int lineNumber, int charBegin, int charEnd, int state) { 504 this.ID = ID; 505 this.contents = new String (contents); 506 this.lineNumber = lineNumber; 507 this.charBegin = charBegin; 508 this.charEnd = charEnd; 509 this.state = state; 510 } 511 512 521 public int getState() { 522 return state; 523 } 524 525 530 public int getID() { 531 return ID; 532 } 533 534 539 public String getContents() { 540 return (new String (contents)); 541 } 542 543 548 public int getLineNumber() { 549 return lineNumber; 550 } 551 552 557 public int getCharBegin() { 558 return charBegin; 559 } 560 561 566 public int getCharEnd() { 567 return charEnd; 568 } 569 570 577 public boolean isReservedWord() { 578 return ((ID >> 8) == 0x1); 579 } 580 581 588 public boolean isIdentifier() { 589 return ((ID >> 8) == 0x2); 590 } 591 592 599 public boolean isLiteral() { 600 return ((ID >> 8) == 0x3); 601 } 602 603 610 public boolean isSeparator() { 611 return ((ID >> 8) == 0x4); 612 } 613 614 621 public boolean isOperator() { 622 return ((ID >> 8) == 0x5); 623 } 624 625 630 public boolean isComment() { 631 return ((ID >> 8) == 0xD); 632 } 633 634 640 public boolean isWhiteSpace() { 641 return ((ID >> 8) == 0xE); 642 } 643 644 650 public boolean isError() { 651 return ((ID >> 8) == 0xF); 652 } 653 654 661 public String getDescription() { 662 if (isReservedWord()) { 663 return ("reservedWord"); 664 } else if (isIdentifier()) { 665 return ("identifier"); 666 } else if (isLiteral()) { 667 return ("literal"); 668 } else if (isSeparator()) { 669 return ("separator"); 670 } else if (isOperator()) { 671 return ("operator"); 672 } else if (isComment()) { 673 return ("comment"); 674 } else if (isWhiteSpace()) { 675 return ("whitespace"); 676 } else if (isError()) { 677 return ("error"); 678 } else { 679 return ("unknown"); 680 } 681 } 682 683 688 public String errorString() { 689 String s; 690 if (isError()) { 691 s = "Error on line " + lineNumber + ": "; 692 switch (ID) { 693 case ERROR: 694 s += "Unexpected token: " + contents; 695 break; 696 case ERROR_UNCLOSED_COMMENT: 697 s += "Unclosed comment: " + contents; 698 break; 699 case ERROR_UNCLOSED_STRING: 700 s += "Unclosed string literal: " + contents; 701 break; 702 case ERROR_UNCLOSED_BIT_STRING: 703 s += "Unclosed bit-string literal: " + contents; 704 break; 705 case ERROR_BAD_BIT_STRING: 706 s += "Bit-strings can only contain 0 and 1: " + contents; 707 break; 708 } 709 710 } else { 711 s = null; 712 } 713 return (s); 714 } 715 716 723 public String toString() { 724 return ("Token #" + Integer.toHexString(ID) + ": " + getDescription() + " Line " + 725 lineNumber + " from " + charBegin + " to " + charEnd + " : " + contents); 726 } 727 } 728 729 730 744 public void reset(java.io.Reader reader, int yyline, int yychar, int yycolumn) throws IOException { 745 yyreset(reader); 746 this.yyline = yyline; 747 this.yychar = yychar; 748 this.yycolumn = yycolumn; 749 } 750 751 public void setReader(java.io.Reader in) { 752 this.yy_reader = in; 753 } 754 755 756 762 public SQLScriptParser(java.io.Reader in) { 763 this.yy_reader = in; 764 } 765 766 772 public SQLScriptParser(java.io.InputStream in) { 773 this(new java.io.InputStreamReader (in)); 774 } 775 776 781 private static int[] yy_unpack() { 782 int[] trans = new int[660]; 783 int offset = 0; 784 offset = yy_unpack(yy_packed0, offset, trans); 785 return trans; 786 } 787 788 794 private static int yy_unpack(String packed, int offset, int[] trans) { 795 int i = 0; 796 int j = offset; 797 int l = packed.length(); 798 while (i < l) { 799 int count = packed.charAt(i++); 800 int value = packed.charAt(i++); 801 value--; 802 do trans[j++] = value; while (--count > 0); 803 } 804 return j; 805 } 806 807 808 815 private boolean yy_refill() throws java.io.IOException { 816 817 818 if (yy_startRead > 0) { 819 System.arraycopy(yy_buffer, yy_startRead, 820 yy_buffer, 0, 821 yy_endRead - yy_startRead); 822 823 824 yy_endRead -= yy_startRead; 825 yy_currentPos -= yy_startRead; 826 yy_markedPos -= yy_startRead; 827 yy_pushbackPos -= yy_startRead; 828 yy_startRead = 0; 829 } 830 831 832 if (yy_currentPos >= yy_buffer.length) { 833 834 char newBuffer[] = new char[yy_currentPos * 2]; 835 System.arraycopy(yy_buffer, 0, newBuffer, 0, yy_buffer.length); 836 yy_buffer = newBuffer; 837 } 838 839 840 int numRead = yy_reader.read(yy_buffer, yy_endRead, 841 yy_buffer.length - yy_endRead); 842 843 if (numRead < 0) { 844 return true; 845 } else { 846 yy_endRead += numRead; 847 return false; 848 } 849 } 850 851 852 855 final public void yyclose() throws java.io.IOException { 856 yy_atEOF = true; 857 yy_endRead = yy_startRead; 858 859 if (yy_reader != null) 860 yy_reader.close(); 861 } 862 863 864 874 final public void yyreset(java.io.Reader reader) throws java.io.IOException { 875 yyclose(); 876 yy_reader = reader; 877 yy_atBOL = true; 878 yy_atEOF = false; 879 yy_endRead = yy_startRead = 0; 880 yy_currentPos = yy_markedPos = yy_pushbackPos = 0; 881 yyline = yychar = yycolumn = 0; 882 yy_lexical_state = YYINITIAL; 883 } 884 885 886 889 final public int yystate() { 890 return yy_lexical_state; 891 } 892 893 894 899 final public void yybegin(int newState) { 900 yy_lexical_state = newState; 901 } 902 903 904 907 final public String yytext() { 908 return new String (yy_buffer, yy_startRead, yy_markedPos - yy_startRead); 909 } 910 911 912 923 final public char yycharat(int pos) { 924 return yy_buffer[yy_startRead + pos]; 925 } 926 927 928 931 final public int yylength() { 932 return yy_markedPos - yy_startRead; 933 } 934 935 936 950 private void yy_ScanError(int errorCode) { 951 String message; 952 try { 953 message = YY_ERROR_MSG[errorCode]; 954 } catch (ArrayIndexOutOfBoundsException e) { 955 message = YY_ERROR_MSG[YY_UNKNOWN_ERROR]; 956 } 957 958 throw new Error (message); 959 } 960 961 962 970 private void yypushback(int number) { 971 if (number > yylength()) 972 yy_ScanError(YY_PUSHBACK_2BIG); 973 974 yy_markedPos -= number; 975 } 976 977 978 985 public Token getNextToken() throws java.io.IOException { 986 int yy_input; 987 int yy_action; 988 989 int yy_currentPos_l; 991 int yy_startRead_l; 992 int yy_markedPos_l; 993 int yy_endRead_l = yy_endRead; 994 char[] yy_buffer_l = yy_buffer; 995 char[] yycmap_l = yycmap; 996 997 int[] yytrans_l = yytrans; 998 int[] yy_rowMap_l = yy_rowMap; 999 byte[] yy_attr_l = YY_ATTRIBUTE; 1000 1001 while (true) { 1002 yy_markedPos_l = yy_markedPos; 1003 1004 yychar += yy_markedPos_l - yy_startRead; 1005 1006 boolean yy_r = false; 1007 for (yy_currentPos_l = yy_startRead; yy_currentPos_l < yy_markedPos_l; 1008 yy_currentPos_l++) { 1009 switch (yy_buffer_l[yy_currentPos_l]) { 1010 case '\u000B': 1011 case '\u000C': 1012 case '\u0085': 1013 case '\u2028': 1014 case '\u2029': 1015 yyline++; 1016 yy_r = false; 1017 break; 1018 case '\r': 1019 yyline++; 1020 yy_r = true; 1021 break; 1022 case '\n': 1023 if (yy_r) 1024 yy_r = false; 1025 else { 1026 yyline++; 1027 } 1028 break; 1029 default: 1030 yy_r = false; 1031 } 1032 } 1033 1034 if (yy_r) { 1035 boolean yy_peek; 1037 if (yy_markedPos_l < yy_endRead_l) 1038 yy_peek = yy_buffer_l[yy_markedPos_l] == '\n'; 1039 else if (yy_atEOF) 1040 yy_peek = false; 1041 else { 1042 boolean eof = yy_refill(); 1043 yy_markedPos_l = yy_markedPos; 1044 yy_buffer_l = yy_buffer; 1045 if (eof) 1046 yy_peek = false; 1047 else 1048 yy_peek = yy_buffer_l[yy_markedPos_l] == '\n'; 1049 } 1050 if (yy_peek) yyline--; 1051 } 1052 yy_action = -1; 1053 1054 yy_startRead_l = yy_currentPos_l = yy_currentPos = 1055 yy_startRead = yy_markedPos_l; 1056 1057 yy_state = yy_lexical_state; 1058 1059 1060 yy_forAction: { 1061 while (true) { 1062 1063 if (yy_currentPos_l < yy_endRead_l) 1064 yy_input = yy_buffer_l[yy_currentPos_l++]; 1065 else if (yy_atEOF) { 1066 yy_input = YYEOF; 1067 break yy_forAction; 1068 } else { 1069 yy_currentPos = yy_currentPos_l; 1071 yy_markedPos = yy_markedPos_l; 1072 boolean eof = yy_refill(); 1073 yy_currentPos_l = yy_currentPos; 1075 yy_markedPos_l = yy_markedPos; 1076 yy_buffer_l = yy_buffer; 1077 yy_endRead_l = yy_endRead; 1078 if (eof) { 1079 yy_input = YYEOF; 1080 break yy_forAction; 1081 } else { 1082 yy_input = yy_buffer_l[yy_currentPos_l++]; 1083 } 1084 } 1085 int yy_next = yytrans_l[yy_rowMap_l[yy_state] + yycmap_l[yy_input]]; 1086 if (yy_next == -1) break yy_forAction; 1087 yy_state = yy_next; 1088 1089 int yy_attributes = yy_attr_l[yy_state]; 1090 if ((yy_attributes & 1) == 1) { 1091 yy_action = yy_state; 1092 yy_markedPos_l = yy_currentPos_l; 1093 if ((yy_attributes & 8) == 8) break yy_forAction; 1094 } 1095 1096 } 1097 } 1098 1099 yy_markedPos = yy_markedPos_l; 1101 1102 switch (yy_action) { 1103 1104 case 6: 1105 case 11: 1106 case 17: 1107 { 1108 nextState = YYINITIAL; 1109 lastToken = Token.ERROR; 1110 String text = yytext(); 1111 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1112 yybegin(nextState); 1113 return (t); 1114 } 1115 case 49: 1116 break; 1117 case 46: 1118 { 1119 nextState = YYINITIAL; 1120 lastToken = Token.LITERAL_BIT_STRING; 1121 String text = yytext(); 1122 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1123 yybegin(nextState); 1124 return (t); 1125 } 1126 case 50: 1127 break; 1128 case 8: 1129 case 10: 1130 case 14: 1131 case 15: 1132 { 1133 nextState = YYINITIAL; 1134 lastToken = Token.OPERATOR; 1135 String text = yytext(); 1136 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1137 yybegin(nextState); 1138 return (t); 1139 } 1140 case 51: 1141 break; 1142 case 25: 1143 { 1144 nextState = YYINITIAL; 1145 lastToken = Token.ERROR_UNCLOSED_STRING; 1146 String text = yytext(); 1147 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1148 yybegin(nextState); 1149 return (t); 1150 } 1151 case 52: 1152 break; 1153 case 38: 1154 case 45: 1155 { 1156 nextState = YYINITIAL; 1157 lastToken = Token.ERROR_UNCLOSED_BIT_STRING; 1158 String text = yytext(); 1159 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1160 yybegin(nextState); 1161 return (t); 1162 } 1163 case 53: 1164 break; 1165 case 34: 1166 { 1167 nextState = COMMENT; 1168 commentBuffer.append(yytext()); 1169 commentNestCount++; 1170 yybegin(nextState); 1171 } 1172 case 54: 1173 break; 1174 case 9: 1175 case 13: 1176 case 22: 1177 { 1178 nextState = YYINITIAL; 1179 lastToken = Token.SEPARATOR; 1180 String text = yytext(); 1181 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1182 yybegin(nextState); 1183 return (t); 1184 } 1185 case 55: 1186 break; 1187 case 2: 1188 case 4: 1189 case 12: 1190 { 1191 nextState = YYINITIAL; 1192 lastToken = Token.IDENTIFIER; 1193 String text = yytext(); 1194 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1195 yybegin(nextState); 1196 return (t); 1197 } 1198 case 56: 1199 break; 1200 case 3: 1201 case 19: 1202 { 1203 nextState = YYINITIAL; 1204 lastToken = Token.RESERVED_WORD; 1205 String text = yytext(); 1206 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1207 yybegin(nextState); 1208 return (t); 1209 } 1210 case 57: 1211 break; 1212 case 18: 1213 case 33: 1214 { 1215 commentNestCount--; 1216 commentBuffer.append(yytext()); 1217 if (commentNestCount == 0) { 1218 nextState = YYINITIAL; 1219 lastToken = Token.COMMENT_TRADITIONAL; 1220 Token t = (new Token(lastToken, commentBuffer.toString(), commentStartLine, commentStartChar, commentStartChar + commentBuffer.length(), nextState)); 1221 yybegin(nextState); 1222 return (t); 1223 } 1224 } 1225 case 58: 1226 break; 1227 case 20: 1228 case 42: 1229 { 1230 nextState = YYINITIAL; 1231 lastToken = Token.LITERAL_FLOAT; 1232 String text = yytext(); 1233 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1234 yybegin(nextState); 1235 return (t); 1236 } 1237 case 59: 1238 break; 1239 case 24: 1240 case 36: 1241 { 1242 nextState = YYINITIAL; 1243 lastToken = Token.LITERAL_STRING; 1244 String text = yytext(); 1245 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1246 yybegin(nextState); 1247 return (t); 1248 } 1249 case 60: 1250 break; 1251 case 29: 1252 { 1253 nextState = COMMENT; 1254 commentBuffer.setLength(0); 1255 commentBuffer.append(yytext()); 1256 commentNestCount = 1; 1257 commentStartLine = yyline; 1258 commentStartChar = yychar; 1259 yybegin(nextState); 1260 } 1261 case 61: 1262 break; 1263 case 28: 1264 { 1265 nextState = YYINITIAL; 1266 lastToken = Token.COMMENT_END_OF_LINE; 1267 String text = yytext(); 1268 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1269 yybegin(nextState); 1270 return (t); 1271 } 1272 case 62: 1273 break; 1274 case 39: 1275 { 1276 nextState = YYINITIAL; 1277 lastToken = Token.ERROR_BAD_BIT_STRING; 1278 String text = yytext(); 1279 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1280 yybegin(nextState); 1281 return (t); 1282 } 1283 case 63: 1284 break; 1285 case 1: 1286 case 16: 1287 { 1288 nextState = COMMENT; 1289 commentBuffer.append(yytext()); 1290 yybegin(nextState); 1291 } 1292 case 64: 1293 break; 1294 case 0: 1295 case 5: 1296 { 1297 nextState = YYINITIAL; 1298 lastToken = Token.WHITE_SPACE; 1299 String text = yytext(); 1300 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1301 yybegin(nextState); 1302 return (t); 1303 } 1304 case 65: 1305 break; 1306 case 7: 1307 { 1308 nextState = YYINITIAL; 1309 lastToken = Token.LITERAL_INTEGER; 1310 String text = yytext(); 1311 Token t = (new Token(lastToken, text, yyline, yychar, yychar + text.length(), nextState)); 1312 yybegin(nextState); 1313 return (t); 1314 } 1315 case 66: 1316 break; 1317 default: 1318 if (yy_input == YYEOF && yy_startRead == yy_currentPos) { 1319 yy_atEOF = true; 1320 switch (yy_lexical_state) { 1321 case COMMENT: 1322 { 1323 nextState = YYINITIAL; 1324 lastToken = Token.ERROR_UNCLOSED_COMMENT; 1325 Token t = (new Token(lastToken, commentBuffer.toString(), commentStartLine, commentStartChar, commentStartChar + commentBuffer.length(), nextState)); 1326 yybegin(nextState); 1327 return (t); 1328 } 1329 case 49: 1330 break; 1331 default: 1332 return null; 1333 } 1334 } else { 1335 yy_ScanError(YY_NO_MATCH); 1336 } 1337 } 1338 } 1339 } 1340 1341 1342} 1343 1344 | Popular Tags |