001: package net.sourceforge.squirrel_sql.plugins.syntax.netbeans;
002:
003: import net.sourceforge.squirrel_sql.client.session.ISession;
004: import net.sourceforge.squirrel_sql.client.session.SQLTokenListener;
005: import net.sourceforge.squirrel_sql.client.session.ISyntaxHighlightTokenMatcher;
006: import net.sourceforge.squirrel_sql.client.session.parser.ParserEventsAdapter;
007: import net.sourceforge.squirrel_sql.client.session.parser.kernel.ErrorInfo;
008: import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
009: import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
010: import org.netbeans.editor.Syntax;
011: import org.netbeans.editor.TokenID;
012:
013: import java.util.Arrays;
014: import java.util.Vector;
015:
016: /**
017: * Syntax analyzes for SQL source files.
018: */
019:
020: public class SQLSyntax extends Syntax {
021: /** Logger for this class. */
022: @SuppressWarnings("unused")
023: private static ILogger s_log = LoggerController
024: .createLogger(SQLSyntax.class);
025:
026: // Internal states
027: private static final int ISI_WHITESPACE = 2; // inside white space
028: private static final int ISI_LINE_COMMENT = 4; // inside line comment //
029: private static final int ISI_BLOCK_COMMENT = 5; // inside block comment /* ... */
030: private static final int ISI_STRING = 6; // inside string constant
031: private static final int ISI_STRING_A_BSLASH = 7; // inside string constant after backslash
032: private static final int ISI_CHAR = 8; // inside char constant
033: private static final int ISI_CHAR_A_BSLASH = 9; // inside char constant after backslash
034: private static final int ISI_IDENTIFIER = 10; // inside identifier
035: private static final int ISA_MINUS = 11; // slash char
036: private static final int ISA_EQ = 12; // after '='
037: private static final int ISA_GT = 13; // after '>'
038: private static final int ISA_GTGT = 14; // after '>>'
039: private static final int ISA_GTGTGT = 15; // after '>>>'
040: private static final int ISA_LT = 16; // after '<'
041: private static final int ISA_LTLT = 17; // after '<<'
042: private static final int ISA_PLUS = 18; // after '+'
043: private static final int ISA_SLASH = 19; // after '-'
044: private static final int ISA_STAR = 20; // after '*'
045: private static final int ISA_STAR_I_BLOCK_COMMENT = 21; // after '*'
046: private static final int ISA_PIPE = 22; // after '|'
047: private static final int ISA_PERCENT = 23; // after '%'
048: private static final int ISA_AND = 24; // after '&'
049: private static final int ISA_XOR = 25; // after '^'
050: private static final int ISA_EXCLAMATION = 26; // after '!'
051: private static final int ISA_ZERO = 27; // after '0'
052: private static final int ISI_INT = 28; // integer number
053: private static final int ISI_OCTAL = 29; // octal number
054: private static final int ISI_DOUBLE = 30; // double number
055: private static final int ISI_DOUBLE_EXP = 31; // double number
056: private static final int ISI_HEX = 32; // hex number
057: private static final int ISA_DOT = 33; // after '.'
058:
059: private ISession _sess;
060: private NetbeansSQLEditorPane _editorPane;
061: private NetbeansPropertiesWrapper _props;
062: private Vector<ErrorInfo> _currentErrorInfos = new Vector<ErrorInfo>();
063: private boolean _parsingInitialized;
064:
065: private ISyntaxHighlightTokenMatcher _tokenMatcher;
066:
067: public SQLSyntax(ISession sess, NetbeansSQLEditorPane editorPane,
068: NetbeansPropertiesWrapper props) {
069: _sess = sess;
070: _editorPane = editorPane;
071: _props = props;
072: tokenContextPath = SQLTokenContext.contextPath;
073:
074: _tokenMatcher = props.getSyntaxHighlightTokenMatcher(_sess,
075: _editorPane);
076: }
077:
078: private void initParsing() {
079: if (false == _parsingInitialized
080: && null != _props.getParserEventsProcessor(_editorPane
081: .getSqlEntryPanelIdentifier(), _sess)) {
082: _parsingInitialized = true;
083: _props.getParserEventsProcessor(
084: _editorPane.getSqlEntryPanelIdentifier(), _sess)
085: .addParserEventsListener(new ParserEventsAdapter() {
086: public void errorsFound(ErrorInfo[] errorInfos) {
087: onErrorsFound(errorInfos);
088: }
089: });
090: }
091: }
092:
093: private void onErrorsFound(ErrorInfo[] errorInfos) {
094: boolean errorsChanged = false;
095: if (_currentErrorInfos.size() == errorInfos.length) {
096: for (int i = 0; i < errorInfos.length; i++) {
097: if (false == errorInfos[i].equals(_currentErrorInfos
098: .get(i))) {
099: errorsChanged = true;
100: break;
101: }
102: }
103: } else {
104: errorsChanged = true;
105: }
106:
107: if (errorsChanged) {
108: _currentErrorInfos.clear();
109: _currentErrorInfos.addAll(Arrays.asList(errorInfos));
110: _editorPane.repaint();
111:
112: }
113: }
114:
115: protected TokenID parseToken() {
116: initParsing();
117:
118: char actChar;
119:
120: while (offset < stopOffset) {
121: actChar = buffer[offset];
122:
123: switch (state) {
124: case INIT:
125:
126: switch (actChar) {
127: case '\'': // NOI18N
128: state = ISI_STRING;
129: break;
130: case '-':
131: state = ISA_MINUS;
132: break;
133: case '=':
134: state = ISA_EQ;
135: break;
136: case '>':
137: state = ISA_GT;
138: break;
139: case '<':
140: state = ISA_LT;
141: break;
142: case '+':
143: state = ISA_PLUS;
144: break;
145: case '/':
146: state = ISA_SLASH;
147: break;
148: case '*':
149: state = ISA_STAR;
150: break;
151: case '|':
152: state = ISA_PIPE;
153: break;
154: case '%':
155: state = ISA_PERCENT;
156: break;
157: case '&':
158: state = ISA_AND;
159: break;
160: case '^':
161: state = ISA_XOR;
162: break;
163: case '~':
164: offset++;
165: return SQLTokenContext.NEG;
166: case '!':
167: state = ISA_EXCLAMATION;
168: break;
169: case '0':
170: state = ISA_ZERO;
171: break;
172: case '.':
173: state = ISA_DOT;
174: break;
175: case ',':
176: offset++;
177: return SQLTokenContext.COMMA;
178: case ';':
179: offset++;
180: return SQLTokenContext.SEMICOLON;
181: case ':':
182: offset++;
183: return SQLTokenContext.COLON;
184: case '?':
185: offset++;
186: return SQLTokenContext.QUESTION;
187: case '(':
188: offset++;
189: return SQLTokenContext.LPAREN;
190: case ')':
191: offset++;
192: return SQLTokenContext.RPAREN;
193: case '[':
194: offset++;
195: return SQLTokenContext.LBRACKET;
196: case ']':
197: offset++;
198: return SQLTokenContext.RBRACKET;
199: case '{':
200: offset++;
201: return SQLTokenContext.LBRACE;
202: case '}':
203: offset++;
204: return SQLTokenContext.RBRACE;
205: case '@': // 1.5 "@ident" annotation // NOI18N
206: offset++;
207: return SQLTokenContext.ANNOTATION;
208:
209: default:
210: // Check for whitespace
211: if (Character.isWhitespace(actChar)) {
212: state = ISI_WHITESPACE;
213: break;
214: }
215:
216: // Check for digit
217: if (Character.isDigit(actChar)) {
218: state = ISI_INT;
219: break;
220: }
221:
222: // Check for identifier
223: if (Character.isJavaIdentifierStart(actChar)) {
224: state = ISI_IDENTIFIER;
225: break;
226: }
227:
228: offset++;
229: return SQLTokenContext.INVALID_CHAR;
230: }
231: break;
232:
233: case ISI_WHITESPACE: // white space
234: if (!Character.isWhitespace(actChar)) {
235: state = INIT;
236: return SQLTokenContext.WHITESPACE;
237: }
238: break;
239:
240: case ISI_LINE_COMMENT:
241: switch (actChar) {
242: case '\n':
243: state = INIT;
244: return SQLTokenContext.LINE_COMMENT;
245: }
246: break;
247:
248: case ISI_BLOCK_COMMENT:
249: switch (actChar) {
250: case '*':
251: state = ISA_STAR_I_BLOCK_COMMENT;
252: break;
253: }
254: break;
255:
256: case ISI_STRING:
257: switch (actChar) {
258: case '\\':
259: state = ISI_STRING_A_BSLASH;
260: break;
261: case '\n':
262: state = INIT;
263: supposedTokenID = SQLTokenContext.STRING_LITERAL;
264: //!!! return SQLTokenContext.INCOMPLETE_STRING_LITERAL;
265: return supposedTokenID;
266: case '\'': // NOI18N
267: offset++;
268: state = INIT;
269: return SQLTokenContext.STRING_LITERAL;
270: }
271: break;
272:
273: case ISI_STRING_A_BSLASH:
274: switch (actChar) {
275: case '\'': // NOI18N
276: case '\\':
277: break;
278: default:
279: offset--;
280: break;
281: }
282: state = ISI_STRING;
283: break;
284:
285: case ISI_CHAR:
286: switch (actChar) {
287: case '\\':
288: state = ISI_CHAR_A_BSLASH;
289: break;
290: case '\n':
291: state = INIT;
292: supposedTokenID = SQLTokenContext.CHAR_LITERAL;
293: // !!! return SQLTokenContext.INCOMPLETE_CHAR_LITERAL;
294: return supposedTokenID;
295: case '\'':
296: offset++;
297: state = INIT;
298: return SQLTokenContext.CHAR_LITERAL;
299: }
300: break;
301:
302: case ISI_CHAR_A_BSLASH:
303: switch (actChar) {
304: case '\'':
305: case '\\':
306: break;
307: default:
308: offset--;
309: break;
310: }
311: state = ISI_CHAR;
312: break;
313:
314: case ISI_IDENTIFIER:
315: if (!(Character.isJavaIdentifierPart(actChar))) {
316: state = INIT;
317: return findMatchingTokenID();
318: }
319: break;
320:
321: case ISA_MINUS:
322: switch (actChar) {
323: case '-':
324: state = ISI_LINE_COMMENT;
325: break;
326: default:
327: state = INIT;
328: return SQLTokenContext.MINUS;
329: }
330: break;
331:
332: case ISA_SLASH:
333: switch (actChar) {
334: case '=':
335: offset++;
336: state = INIT;
337: return SQLTokenContext.DIV_EQ;
338: case '*':
339: state = ISI_BLOCK_COMMENT;
340: break;
341: default:
342: state = INIT;
343: return SQLTokenContext.DIV;
344: }
345: break;
346:
347: case ISA_EQ:
348: switch (actChar) {
349: case '=':
350: offset++;
351: return SQLTokenContext.EQ_EQ;
352: default:
353: state = INIT;
354: return SQLTokenContext.EQ;
355: }
356: // break;
357:
358: case ISA_GT:
359: switch (actChar) {
360: case '>':
361: state = ISA_GTGT;
362: break;
363: case '=':
364: offset++;
365: return SQLTokenContext.GT_EQ;
366: default:
367: state = INIT;
368: return SQLTokenContext.GT;
369: }
370: break;
371:
372: case ISA_GTGT:
373: switch (actChar) {
374: case '>':
375: state = ISA_GTGTGT;
376: break;
377: case '=':
378: offset++;
379: return SQLTokenContext.RSSHIFT_EQ;
380: default:
381: state = INIT;
382: return SQLTokenContext.RSSHIFT;
383: }
384: break;
385:
386: case ISA_GTGTGT:
387: switch (actChar) {
388: case '=':
389: offset++;
390: return SQLTokenContext.RUSHIFT_EQ;
391: default:
392: state = INIT;
393: return SQLTokenContext.RUSHIFT;
394: }
395: // break;
396:
397: case ISA_LT:
398: switch (actChar) {
399: case '<':
400: state = ISA_LTLT;
401: break;
402: case '=':
403: offset++;
404: return SQLTokenContext.LT_EQ;
405: default:
406: state = INIT;
407: return SQLTokenContext.LT;
408: }
409: break;
410:
411: case ISA_LTLT:
412: switch (actChar) {
413: case '<':
414: state = INIT;
415: offset++;
416: return SQLTokenContext.INVALID_OPERATOR;
417: case '=':
418: offset++;
419: return SQLTokenContext.LSHIFT_EQ;
420: default:
421: state = INIT;
422: return SQLTokenContext.LSHIFT;
423: }
424:
425: case ISA_PLUS:
426: switch (actChar) {
427: case '+':
428: offset++;
429: return SQLTokenContext.PLUS_PLUS;
430: case '=':
431: offset++;
432: return SQLTokenContext.PLUS_EQ;
433: default:
434: state = INIT;
435: return SQLTokenContext.PLUS;
436: }
437:
438: // case ISA_SLASH:
439: // switch (actChar)
440: // {
441: // case '-':
442: // offset++;
443: // return SQLTokenContext.MINUS_MINUS;
444: // case '=':
445: // offset++;
446: // return SQLTokenContext.MINUS_EQ;
447: // default:
448: // state = INIT;
449: // return SQLTokenContext.MINUS;
450: // }
451:
452: case ISA_STAR:
453: switch (actChar) {
454: case '=':
455: offset++;
456: return SQLTokenContext.MUL_EQ;
457: case '/':
458: offset++;
459: state = INIT;
460: return SQLTokenContext.INVALID_COMMENT_END; // '*/' outside comment
461: default:
462: state = INIT;
463: return SQLTokenContext.MUL;
464: }
465:
466: case ISA_STAR_I_BLOCK_COMMENT:
467: switch (actChar) {
468: case '/':
469: offset++;
470: state = INIT;
471: return SQLTokenContext.BLOCK_COMMENT;
472: default:
473: offset--;
474: state = ISI_BLOCK_COMMENT;
475: break;
476: }
477: break;
478:
479: case ISA_PIPE:
480: switch (actChar) {
481: case '=':
482: offset++;
483: state = INIT;
484: return SQLTokenContext.OR_EQ;
485: case '|':
486: offset++;
487: state = INIT;
488: return SQLTokenContext.OR_OR;
489: default:
490: state = INIT;
491: return SQLTokenContext.OR;
492: }
493: // break;
494:
495: case ISA_PERCENT:
496: switch (actChar) {
497: case '=':
498: offset++;
499: state = INIT;
500: return SQLTokenContext.MOD_EQ;
501: default:
502: state = INIT;
503: return SQLTokenContext.MOD;
504: }
505: // break;
506:
507: case ISA_AND:
508: switch (actChar) {
509: case '=':
510: offset++;
511: state = INIT;
512: return SQLTokenContext.AND_EQ;
513: case '&':
514: offset++;
515: state = INIT;
516: return SQLTokenContext.AND_AND;
517: default:
518: state = INIT;
519: return SQLTokenContext.AND;
520: }
521: // break;
522:
523: case ISA_XOR:
524: switch (actChar) {
525: case '=':
526: offset++;
527: state = INIT;
528: return SQLTokenContext.XOR_EQ;
529: default:
530: state = INIT;
531: return SQLTokenContext.XOR;
532: }
533: // break;
534:
535: case ISA_EXCLAMATION:
536: switch (actChar) {
537: case '=':
538: offset++;
539: state = INIT;
540: return SQLTokenContext.NOT_EQ;
541: default:
542: state = INIT;
543: return SQLTokenContext.NOT;
544: }
545: // break;
546:
547: case ISA_ZERO:
548: switch (actChar) {
549: case '.':
550: state = ISI_DOUBLE;
551: break;
552: case 'x':
553: case 'X':
554: state = ISI_HEX;
555: break;
556: case 'l':
557: case 'L':
558: offset++;
559: state = INIT;
560: return SQLTokenContext.LONG_LITERAL;
561: case 'f':
562: case 'F':
563: offset++;
564: state = INIT;
565: return SQLTokenContext.FLOAT_LITERAL;
566: case 'd':
567: case 'D':
568: offset++;
569: state = INIT;
570: return SQLTokenContext.DOUBLE_LITERAL;
571: case '8': // it's error to have '8' and '9' in octal number
572: case '9':
573: state = INIT;
574: offset++;
575: return SQLTokenContext.INVALID_OCTAL_LITERAL;
576: case 'e':
577: case 'E':
578: state = ISI_DOUBLE_EXP;
579: break;
580: default:
581: if (Character.isDigit(actChar)) { // '8' and '9' already handled
582: state = ISI_OCTAL;
583: break;
584: }
585: state = INIT;
586: return SQLTokenContext.INT_LITERAL;
587: }
588: break;
589:
590: case ISI_INT:
591: switch (actChar) {
592: case 'l':
593: case 'L':
594: offset++;
595: state = INIT;
596: return SQLTokenContext.LONG_LITERAL;
597: case '.':
598: state = ISI_DOUBLE;
599: break;
600: case 'f':
601: case 'F':
602: offset++;
603: state = INIT;
604: return SQLTokenContext.FLOAT_LITERAL;
605: case 'd':
606: case 'D':
607: offset++;
608: state = INIT;
609: return SQLTokenContext.DOUBLE_LITERAL;
610: case 'e':
611: case 'E':
612: state = ISI_DOUBLE_EXP;
613: break;
614: default:
615: if (!(actChar >= '0' && actChar <= '9')) {
616: state = INIT;
617: return SQLTokenContext.INT_LITERAL;
618: }
619: }
620: break;
621:
622: case ISI_OCTAL:
623: if (!(actChar >= '0' && actChar <= '7')) {
624:
625: state = INIT;
626: return SQLTokenContext.OCTAL_LITERAL;
627: }
628: break;
629:
630: case ISI_DOUBLE:
631: switch (actChar) {
632: case 'f':
633: case 'F':
634: offset++;
635: state = INIT;
636: return SQLTokenContext.FLOAT_LITERAL;
637: case 'd':
638: case 'D':
639: offset++;
640: state = INIT;
641: return SQLTokenContext.DOUBLE_LITERAL;
642: case 'e':
643: case 'E':
644: state = ISI_DOUBLE_EXP;
645: break;
646: default:
647: if (!((actChar >= '0' && actChar <= '9') || actChar == '.')) {
648:
649: state = INIT;
650: return SQLTokenContext.DOUBLE_LITERAL;
651: }
652: }
653: break;
654:
655: case ISI_DOUBLE_EXP:
656: switch (actChar) {
657: case 'f':
658: case 'F':
659: offset++;
660: state = INIT;
661: return SQLTokenContext.FLOAT_LITERAL;
662: case 'd':
663: case 'D':
664: offset++;
665: state = INIT;
666: return SQLTokenContext.DOUBLE_LITERAL;
667: default:
668: if (!(Character.isDigit(actChar) || actChar == '-' || actChar == '+')) {
669: state = INIT;
670: return SQLTokenContext.DOUBLE_LITERAL;
671: }
672: }
673: break;
674:
675: case ISI_HEX:
676: if (!((actChar >= 'a' && actChar <= 'f')
677: || (actChar >= 'A' && actChar <= 'F') || Character
678: .isDigit(actChar))) {
679:
680: state = INIT;
681: return SQLTokenContext.HEX_LITERAL;
682: }
683: break;
684:
685: case ISA_DOT:
686: if (Character.isDigit(actChar)) {
687: state = ISI_DOUBLE;
688: } else if (actChar == '.' && offset + 1 < stopOffset
689: && buffer[offset + 1] == '.') {
690: offset += 2;
691: state = INIT;
692: return SQLTokenContext.ELLIPSIS;
693: } else { // only single dot
694: state = INIT;
695: return SQLTokenContext.DOT;
696: }
697: break;
698:
699: } // end of switch(state)
700:
701: offset++;
702: } // end of while(offset...)
703:
704: /** At this stage there's no more text in the scanned buffer.
705: * Scanner first checks whether this is completely the last
706: * available buffer.
707: */
708:
709: if (lastBuffer) {
710: switch (state) {
711: case ISI_WHITESPACE:
712: state = INIT;
713: return SQLTokenContext.WHITESPACE;
714: case ISI_IDENTIFIER:
715: state = INIT;
716: return findMatchingTokenID();
717: case ISI_LINE_COMMENT:
718: return SQLTokenContext.LINE_COMMENT; // stay in line-comment state
719: case ISI_BLOCK_COMMENT:
720: case ISA_STAR_I_BLOCK_COMMENT:
721: return SQLTokenContext.BLOCK_COMMENT; // stay in block-comment state
722: case ISI_STRING:
723: case ISI_STRING_A_BSLASH:
724: return SQLTokenContext.STRING_LITERAL; // hold the state
725: case ISI_CHAR:
726: case ISI_CHAR_A_BSLASH:
727: return SQLTokenContext.CHAR_LITERAL; // hold the state
728: case ISA_ZERO:
729: case ISI_INT:
730: state = INIT;
731: return SQLTokenContext.INT_LITERAL;
732: case ISI_OCTAL:
733: state = INIT;
734: return SQLTokenContext.OCTAL_LITERAL;
735: case ISI_DOUBLE:
736: case ISI_DOUBLE_EXP:
737: state = INIT;
738: return SQLTokenContext.DOUBLE_LITERAL;
739: case ISI_HEX:
740: state = INIT;
741: return SQLTokenContext.HEX_LITERAL;
742: case ISA_DOT:
743: state = INIT;
744: return SQLTokenContext.DOT;
745: case ISA_MINUS:
746: state = INIT;
747: return SQLTokenContext.LINE_COMMENT;
748: case ISA_SLASH:
749: state = INIT;
750: return SQLTokenContext.DIV;
751: case ISA_EQ:
752: state = INIT;
753: return SQLTokenContext.EQ;
754: case ISA_GT:
755: state = INIT;
756: return SQLTokenContext.GT;
757: case ISA_GTGT:
758: state = INIT;
759: return SQLTokenContext.RSSHIFT;
760: case ISA_GTGTGT:
761: state = INIT;
762: return SQLTokenContext.RUSHIFT;
763: case ISA_LT:
764: state = INIT;
765: return SQLTokenContext.LT;
766: case ISA_LTLT:
767: state = INIT;
768: return SQLTokenContext.LSHIFT;
769: case ISA_PLUS:
770: state = INIT;
771: return SQLTokenContext.PLUS;
772: // case ISA_SLASH:
773: // state = INIT;
774: // return SQLTokenContext.MINUS;
775: case ISA_STAR:
776: state = INIT;
777: return SQLTokenContext.MUL;
778: case ISA_PIPE:
779: state = INIT;
780: return SQLTokenContext.OR;
781: case ISA_PERCENT:
782: state = INIT;
783: return SQLTokenContext.MOD;
784: case ISA_AND:
785: state = INIT;
786: return SQLTokenContext.AND;
787: case ISA_XOR:
788: state = INIT;
789: return SQLTokenContext.XOR;
790: case ISA_EXCLAMATION:
791: state = INIT;
792: return SQLTokenContext.NOT;
793: }
794: }
795:
796: /* At this stage there's no more text in the scanned buffer, but
797: * this buffer is not the last so the scan will continue on another buffer.
798: * The scanner tries to minimize the amount of characters
799: * that will be prescanned in the next buffer by returning the token
800: * where possible.
801: */
802:
803: switch (state) {
804: case ISI_WHITESPACE:
805: return SQLTokenContext.WHITESPACE;
806: }
807:
808: return null; // nothing found
809: }
810:
811: private TokenID findMatchingTokenID() {
812: TokenID tid = matchError(buffer, tokenOffset, offset
813: - tokenOffset);
814: tid = (tid != null) ? tid : matchKeyword(buffer, tokenOffset,
815: offset - tokenOffset);
816: tid = (tid != null) ? tid : matchTable(buffer, tokenOffset,
817: offset - tokenOffset);
818: tid = (tid != null) ? tid : matchFunction(buffer, tokenOffset,
819: offset - tokenOffset);
820: tid = (tid != null) ? tid : matchDataType(buffer, tokenOffset,
821: offset - tokenOffset);
822: tid = (tid != null) ? tid : matchStatementSeparator(buffer,
823: tokenOffset, offset - tokenOffset);
824: tid = (tid != null) ? tid : matchColumn(buffer, tokenOffset,
825: offset - tokenOffset);
826: return (tid != null) ? tid : SQLTokenContext.IDENTIFIER;
827: }
828:
829: public String getStateName(int stateNumber) {
830: switch (stateNumber) {
831: case ISI_WHITESPACE:
832: return "ISI_WHITESPACE"; // NOI18N
833: case ISI_LINE_COMMENT:
834: return "ISI_LINE_COMMENT"; // NOI18N
835: case ISI_BLOCK_COMMENT:
836: return "ISI_BLOCK_COMMENT"; // NOI18N
837: case ISI_STRING:
838: return "ISI_STRING"; // NOI18N
839: case ISI_STRING_A_BSLASH:
840: return "ISI_STRING_A_BSLASH"; // NOI18N
841: case ISI_CHAR:
842: return "ISI_CHAR"; // NOI18N
843: case ISI_CHAR_A_BSLASH:
844: return "ISI_CHAR_A_BSLASH"; // NOI18N
845: case ISI_IDENTIFIER:
846: return "ISI_IDENTIFIER"; // NOI18N
847: case ISA_MINUS:
848: return "ISA_MINUS"; // NOI18N
849: case ISA_EQ:
850: return "ISA_EQ"; // NOI18N
851: case ISA_GT:
852: return "ISA_GT"; // NOI18N
853: case ISA_GTGT:
854: return "ISA_GTGT"; // NOI18N
855: case ISA_GTGTGT:
856: return "ISA_GTGTGT"; // NOI18N
857: case ISA_LT:
858: return "ISA_LT"; // NOI18N
859: case ISA_LTLT:
860: return "ISA_LTLT"; // NOI18N
861: case ISA_PLUS:
862: return "ISA_PLUS"; // NOI18N
863: case ISA_SLASH:
864: return "ISA_SLASH"; // NOI18N
865: case ISA_STAR:
866: return "ISA_STAR"; // NOI18N
867: case ISA_STAR_I_BLOCK_COMMENT:
868: return "ISA_STAR_I_BLOCK_COMMENT"; // NOI18N
869: case ISA_PIPE:
870: return "ISA_PIPE"; // NOI18N
871: case ISA_PERCENT:
872: return "ISA_PERCENT"; // NOI18N
873: case ISA_AND:
874: return "ISA_AND"; // NOI18N
875: case ISA_XOR:
876: return "ISA_XOR"; // NOI18N
877: case ISA_EXCLAMATION:
878: return "ISA_EXCLAMATION"; // NOI18N
879: case ISA_ZERO:
880: return "ISA_ZERO"; // NOI18N
881: case ISI_INT:
882: return "ISI_INT"; // NOI18N
883: case ISI_OCTAL:
884: return "ISI_OCTAL"; // NOI18N
885: case ISI_DOUBLE:
886: return "ISI_DOUBLE"; // NOI18N
887: case ISI_DOUBLE_EXP:
888: return "ISI_DOUBLE_EXP"; // NOI18N
889: case ISI_HEX:
890: return "ISI_HEX"; // NOI18N
891: case ISA_DOT:
892: return "ISA_DOT"; // NOI18N
893:
894: default:
895: return super .getStateName(stateNumber);
896: }
897: }
898:
899: private TokenID matchTable(char[] buffer, int offset, int len) {
900:
901: if (_tokenMatcher.isTable(buffer, offset, len)) {
902: return SQLTokenContext.TABLE;
903: }
904: return null;
905: }
906:
907: private TokenID matchFunction(char[] buffer, int offset, int len) {
908: if (_tokenMatcher.isFunction(buffer, offset, len)) {
909: return SQLTokenContext.FUNCTION;
910: }
911: return null;
912: }
913:
914: private TokenID matchDataType(char[] buffer, int offset, int len) {
915:
916: if (_tokenMatcher.isDataType(buffer, offset, len)) {
917: return SQLTokenContext.DATA_TYPE;
918: }
919: return null;
920: }
921:
922: private TokenID matchStatementSeparator(char[] buffer, int offset,
923: int len) {
924: if (_tokenMatcher.isStatementSeparator(buffer, offset, len)) {
925: return SQLTokenContext.STATEMENT_SEPARATOR;
926: }
927: return null;
928: }
929:
930: private TokenID matchColumn(char[] buffer, int offset, int len) {
931: if (_tokenMatcher.isColumn(buffer, offset, len)) {
932: return SQLTokenContext.COLUMN;
933: }
934: return null;
935: }
936:
937: private TokenID matchKeyword(char[] buffer, int offset, int len) {
938: if (_tokenMatcher.isKeyword(buffer, offset, len)) {
939: return SQLTokenContext.PACKAGE;
940: }
941: return null;
942: }
943:
944: private TokenID matchError(char[] buffer, int offset, int len) {
945:
946: // System.out.println("####################################################");
947: // int s = Math.max(0,offset -10);
948: // System.out.print(new String(buffer, s, offset-s));
949: // System.out.print(">" + new String(buffer, offset,len) + "<");
950: // System.out.println(new String(buffer, offset + len, Math.min(offset + len + 10, buffer.length -(offset + len) )));
951:
952: /////////////////////////////////////////////////////////////////////////////////
953: // This formula can be found in the API Doc for
954: // methode relocate() of class org.netbeans.editor.Syntax.
955: // See the description of the last parameter 'stopPosition'.
956: //
957: // relocate() is always called before the parseTocken() method of this class.
958: int absolutePosition = stopPosition + offset - stopOffset;
959: //
960: ////////////////////////////////////////////////////////////////////////////////
961:
962: for (int i = 0; i < _currentErrorInfos.size(); i++) {
963: ErrorInfo errInf = _currentErrorInfos.elementAt(i);
964:
965: // byte[] bytes = _editorPane.getText().getBytes();
966: // System.out.println("*********************************************** " + absolutePosition);
967: // System.out.print(new String(bytes, 0, errInf.beginPos));
968: // System.out.print(">" + new String(bytes, errInf.beginPos, errInf.endPos + 1 - errInf.beginPos) + "<");
969: // System.out.println(new String(bytes, errInf.endPos +1 , bytes.length-(errInf.endPos + 1)));
970:
971: if (absolutePosition <= errInf.beginPos
972: && errInf.endPos <= absolutePosition + len) {
973: return SQLTokenContext.ERROR;
974: }
975:
976: if (absolutePosition == errInf.beginPos) {
977: // Example:
978: // ALTER TABLE kvpos ADD CONSTRAINT kv_kvpos FOREIGN KEY (kvid) kv(kvid)
979: // -------------------------------------------------------------^ ("References" expected)
980: //
981: // kv will not be marked with the condition above, because
982: // errInf.endPos <= absolutePosition + len
983: // is never true.
984:
985: return SQLTokenContext.ERROR;
986: }
987: }
988: return null;
989: }
990:
991: public void addSQLTokenListener(SQLTokenListener tl) {
992: _tokenMatcher.addSQLTokenListener(tl);
993: }
994:
995: public void removeSQLTokenListener(SQLTokenListener tl) {
996: _tokenMatcher.removeSQLTokenListener(tl);
997: }
998: }
|