KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > core > syntax > deprecated > ELSyntax


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.core.syntax.deprecated;
21
22 import org.netbeans.modules.web.core.syntax.*;
23 import org.netbeans.editor.Syntax;
24 import org.netbeans.editor.TokenID;
25
26 /**
27 * Lexical analyzer for the plain text.
28 *
29 * @deprecated Use {@link ELLexer} instead.
30 *
31 * @author Petr Pisl
32 */

33
34 public class ELSyntax extends Syntax {
35
36     /* Internal states used internally by analyzer. There
37     * can be any number of them declared by the analyzer.
38     * They are usually numbered starting from zero but they don't
39     * have to. The only reserved value is -1 which is reserved
40     * for the INIT state - the initial internal state of the analyzer.
41     */

42     
43     private static final int ISI_IDENTIFIER = 2;
44     private static final int ISI_CHAR = 3; // inside char constant
45
private static final int ISI_CHAR_A_BSLASH = 4; // inside char constant after backslash
46
private static final int ISI_STRING = 5; // inside a string " ... "
47
private static final int ISI_STRING_A_BSLASH = 6; // inside string "..." constant after backslash
48
private static final int ISI_CHAR_STRING = 7; // inside a string '...'
49
private static final int ISI_CHAR_STRING_A_BSLASH = 8; // inside string '...'contant after backslash
50
private static final int ISA_ZERO = 9; // after '0'
51
private static final int ISI_INT = 10; // integer number
52
private static final int ISI_OCTAL = 11; // octal number
53
private static final int ISI_DOUBLE = 12; // double number
54
private static final int ISI_DOUBLE_EXP = 13; // double number
55
private static final int ISI_HEX = 14; // hex number
56
private static final int ISA_DOT = 15; // after '.'
57
private static final int ISI_WHITESPACE = 16; // inside white space
58
private static final int ISA_EQ = 17; // after '='
59
private static final int ISA_GT = 18; // after '>'
60
private static final int ISA_LT = 19; // after '<'
61
//private static final int ISA_PLUS = 20; // after '+'
62
//private static final int ISA_MINUS = 21; // after '-'
63
//private static final int ISA_STAR = 22; // after '*'
64
private static final int ISA_PIPE = 23; // after '|'
65
private static final int ISA_AND = 24; // after '&'
66
private static final int ISA_EXCLAMATION = 25; // after '!'
67
private static final int ISI_BRACKET = 26; // after '['
68
private static final int ISI_BRACKET_A_WHITESPACE = 27;
69     private static final int ISI_BRACKET_A_IDENTIFIER = 28;
70     private static final int ISI_BRACKET_ISA_EQ = 29;
71     private static final int ISI_BRACKET_ISA_GT = 30;
72     private static final int ISI_BRACKET_ISA_LT =31;
73     private static final int ISI_BRACKET_ISA_PIPE = 32; // after '|'
74
private static final int ISI_BRACKET_ISA_AND = 33; // after '&'
75
private static final int ISI_BRACKET_ISA_ZERO = 34; // after '0'
76
private static final int ISI_BRACKET_ISA_DOT = 35; // after '.'
77
private static final int ISI_BRACKET_ISI_INT = 36; // after '.'
78
private static final int ISI_BRACKET_ISI_OCTAL = 37; // octal number
79
private static final int ISI_BRACKET_ISI_DOUBLE = 38; // double number
80
private static final int ISI_BRACKET_ISI_DOUBLE_EXP = 39; // double number
81
private static final int ISI_BRACKET_ISI_HEX = 40; // hex number
82
private static final int ISI_DOULE_EXP_ISA_SIGN = 41;
83     private static final int ISI_BRACKET_ISI_DOULE_EXP_ISA_SIGN = 42;
84     //private static final int ISA_PERCENT = 24; // after '%'
85

86
87     public ELSyntax() {
88         tokenContextPath = ELTokenContext.contextPath;
89     }
90
91     /** This is core function of analyzer and it returns one of following numbers:
92     * a) token number of next token from scanned text
93     * b) EOL when end of line was found in scanned buffer
94     * c) EOT when there is no more chars available in scanned buffer.
95     *
96     * The function scans the active character and does one or more
97     * of the following actions:
98     * 1. change internal analyzer state (state = new-state)
99     * 2. return token ID (return token-ID)
100     * 3. adjust current position to signal different end of token;
101     * the character that offset points to is not included in the token
102     */

103     protected TokenID parseToken() {
104         // The main loop that reads characters one by one follows
105
while (offset < stopOffset) {
106             char ch = buffer[offset]; // get the current character
107
// - System.out.print(ch);
108
switch (state) { // switch by the current internal state
109
case INIT:
110         // - System.out.print(" INIT (");
111
switch (ch) {
112             case '"':
113             // - System.out.print(" state->ISI_STRING ");
114
state = ISI_STRING;
115             break;
116             case '\'':
117             // - System.out.print(" state->ISI_CHAR ");
118
state = ISI_CHAR;
119             break;
120             case '/':
121             offset++;
122             return ELTokenContext.DIV;
123             case '=':
124             state = ISA_EQ;
125             break;
126             case '>':
127             state = ISA_GT;
128             break;
129             case '<':
130             state = ISA_LT;
131             break;
132            case '+':
133             offset++;
134             return ELTokenContext.PLUS;
135             case '-':
136             offset++;
137             return ELTokenContext.MINUS;
138             case '*':
139             offset++;
140             return ELTokenContext.MUL;
141             case '|':
142             state = ISA_PIPE;
143             break;
144             case '&':
145             state = ISA_AND;
146             break;
147             case '[':
148             //state = ISI_BRACKET;
149
offset++;
150             return ELTokenContext.LBRACKET;
151             //break;
152
case ']':
153             offset++;
154             return ELTokenContext.RBRACKET;
155             case '%':
156             offset++;
157             return ELTokenContext.MOD;
158             case ':':
159             //state = ISA_COLON;
160
//break;
161
offset++;
162             return ELTokenContext.COLON;
163             case '!':
164             state = ISA_EXCLAMATION;
165             break;
166             case '(':
167             offset++;
168             return ELTokenContext.LPAREN;
169             case ')':
170             offset++;
171             return ELTokenContext.RPAREN;
172                 case ',':
173             offset++;
174             return ELTokenContext.COMMA;
175             case '?':
176             offset++;
177             return ELTokenContext.QUESTION;
178             case '\n':
179             offset++;
180             // - System.out.print("r=EOL )");
181
return ELTokenContext.EOL;
182             case '0':
183             state = ISA_ZERO;
184             break;
185             case '.':
186             state = ISA_DOT;
187             break;
188             default:
189             // Check for whitespace
190
if (Character.isWhitespace(ch)) {
191                 state = ISI_WHITESPACE;
192                 break;
193             }
194             
195             // check whether it can be identifier
196
if (Character.isJavaIdentifierStart(ch)){
197                 // - System.out.print(" state->ISI_IDENTIFIER ");
198
state = ISI_IDENTIFIER;
199                 break;
200             }
201             // Check for digit
202
if (Character.isDigit(ch)) {
203                 state = ISI_INT;
204                 break;
205             }
206             // - System.out.print(" r=INVALID_CHAR )");
207
offset++;
208             return ELTokenContext.INVALID_CHAR;
209             //break;
210
}
211         // - System.out.print(")");
212
break;
213         
214             
215         case ISI_WHITESPACE: // white space
216
if (!Character.isWhitespace(ch)) {
217                     state = INIT;
218                     return ELTokenContext.WHITESPACE;
219                 }
220                 break;
221         
222        case ISI_BRACKET:
223         switch (ch){
224             case ']':
225             state = INIT;
226             //offset++;
227
return ELTokenContext.IDENTIFIER;
228             case '"':
229             offset++;
230             return ELTokenContext.LBRACKET;
231             case '\'':
232             offset++;
233             return ELTokenContext.LBRACKET;
234             case '/':
235             offset++;
236             return ELTokenContext.DIV;
237             case '+':
238             offset++;
239             return ELTokenContext.PLUS;
240             case '-':
241             offset++;
242             return ELTokenContext.MINUS;
243             case '*':
244             offset++;
245             return ELTokenContext.MUL;
246             case '[':
247             offset++;
248             return ELTokenContext.LBRACKET;
249             case '%':
250             offset++;
251             return ELTokenContext.MOD;
252             case ':':
253             offset++;
254             return ELTokenContext.COLON;
255             case '(':
256             offset++;
257             return ELTokenContext.LPAREN;
258             case ')':
259             offset++;
260             return ELTokenContext.RPAREN;
261             case ',':
262             offset++;
263             return ELTokenContext.COMMA;
264             case '?':
265             offset++;
266             return ELTokenContext.QUESTION;
267             case '=':
268             state = ISI_BRACKET_ISA_EQ;
269             break;
270             case '>':
271             state = ISI_BRACKET_ISA_GT;
272             break;
273             case '<':
274             state = ISI_BRACKET_ISA_LT;
275             break;
276             case '|':
277             state = ISI_BRACKET_ISA_PIPE;
278             break;
279             case '&':
280             state = ISI_BRACKET_ISA_AND;
281             break;
282             case '0':
283             state = ISI_BRACKET_ISA_ZERO;
284             break;
285             case '.':
286             state = ISI_BRACKET_ISA_DOT;
287             break;
288             default :
289             // Check for whitespace
290
if (Character.isWhitespace(ch)) {
291                 state = ISI_BRACKET_A_WHITESPACE;
292                 break;
293             }
294             if (Character.isJavaIdentifierStart(ch)){
295                 // - System.out.print(" state->ISI_IDENTIFIER ");
296
state = ISI_BRACKET_A_IDENTIFIER;
297                 break;
298             }
299             // Check for digit
300
if (Character.isDigit(ch)) {
301                 state = ISI_BRACKET_ISI_INT;
302                 break;
303             }
304             // - System.out.print(" r=INVALID_CHAR )");
305
offset++;
306             return ELTokenContext.INVALID_CHAR;
307             //break;
308
}
309         break;
310            
311         case ISI_BRACKET_A_WHITESPACE:
312         if (!Character.isWhitespace(ch)) {
313                     state = ISI_BRACKET;
314                     return ELTokenContext.WHITESPACE;
315                 }
316         break;
317         
318         case ISI_BRACKET_ISA_EQ:
319         case ISA_EQ:
320                 switch (ch) {
321                 case '=':
322                     offset++;
323                     return ELTokenContext.EQ_EQ;
324                 default:
325             state = (state == ISI_BRACKET_ISA_EQ) ? ISI_BRACKET : INIT;
326             offset--;
327                     //return ELTokenContext.INVALID_CHAR;
328
}
329                 break;
330         
331         case ISI_BRACKET_ISA_GT:
332         case ISA_GT:
333                 switch (ch) {
334                 case '=':
335                     offset++;
336                     return ELTokenContext.GT_EQ;
337                 default:
338                     state = (state == ISI_BRACKET_ISA_GT) ? ISI_BRACKET : INIT;
339                     return ELTokenContext.GT;
340                 }
341                 //break;
342
case ISI_BRACKET_ISA_LT:
343             case ISA_LT:
344                 switch (ch) {
345                 case '=':
346                     offset++;
347                     return ELTokenContext.LT_EQ;
348                 default:
349                     state = (state == ISI_BRACKET_ISA_LT) ? ISI_BRACKET : INIT;
350                     return ELTokenContext.LT;
351                 }
352                 //break;
353
case ISI_BRACKET_ISA_PIPE:
354         case ISA_PIPE:
355         switch (ch) {
356         case '|':
357             offset++;
358             state = INIT;
359             return ELTokenContext.OR_OR;
360         default:
361             state = (state == ISI_BRACKET_ISA_PIPE) ? ISI_BRACKET : INIT;
362             offset--;
363         }
364         break;
365         case ISI_BRACKET_ISA_AND:
366         case ISA_AND:
367                 switch (ch) {
368                 case '&':
369                     offset++;
370                     state = INIT;
371                     return ELTokenContext.AND_AND;
372                 default:
373                     state = (state == ISI_BRACKET_ISA_AND) ? ISI_BRACKET : INIT;
374                     offset--;
375                 }
376                 break;
377         case ISA_EXCLAMATION:
378                 switch (ch) {
379                 case '=':
380                     offset++;
381                     state = INIT;
382                     return ELTokenContext.NOT_EQ;
383                 default:
384                     state = INIT;
385                     return ELTokenContext.NOT;
386                 }
387         case ISI_STRING:
388         // - System.out.print(" ISI_STRING (");
389
switch (ch) {
390             case '\\':
391             // - System.out.print(" state->ISI_STRING_A_BSLASH");
392
state = ISI_STRING_A_BSLASH;
393             break;
394             case '\n':
395             state = INIT;
396             // - System.out.print(" state->INIT r=STRING_LITERAL )");
397
return ELTokenContext.STRING_LITERAL;
398             case '"': // NOI18N
399
offset++;
400             state = INIT;
401             // - System.out.print(" state->INIT r=STRING_LITERAL )");
402
return ELTokenContext.STRING_LITERAL;
403             }
404         // - System.out.print(")");
405
break;
406         case ISI_STRING_A_BSLASH:
407         // - System.out.print(" ISI_STRING_A_BSLASH (");
408
//switch (ch){
409
// case '"':
410
state = ISI_STRING;
411             // - System.out.print(" state->INIT ");
412
// - System.out.print(")");
413
break;
414          case ISI_BRACKET_A_IDENTIFIER:
415          case ISI_IDENTIFIER:
416          // - System.out.print(" ISI_IDENTIFIER (");
417
if (!(Character.isJavaIdentifierPart(ch))){
418              switch (state){
419              case ISI_IDENTIFIER:
420                 state = INIT; break;
421              case ISI_BRACKET_A_IDENTIFIER:
422                 state = ISI_BRACKET;
423                 break;
424              }
425              // - System.out.print(" state->INIT ");
426

427              TokenID tid = matchKeyword(buffer, tokenOffset, offset - tokenOffset);
428              if (tid == null){
429              if (ch == ':'){
430                  // - System.out.print(" r=TAG_LIB_PREFIX) ");
431
tid = ELTokenContext.TAG_LIB_PREFIX;
432              }
433              else{
434                  tid = ELTokenContext.IDENTIFIER;
435                  // - System.out.print(" r=IDENTIFIER)");
436
}
437              }
438              else {
439              // - System.out.println(" r=KEYWORDS )");
440
}
441             return tid;
442          }
443         // - System.out.print(")");
444
break;
445         
446         case ISI_CHAR:
447         // - System.out.print(" ISI_CHAR (");
448
switch (ch) {
449                 case '\\':
450             // - System.out.print(" state->ISI_CHAR_A_BSLASH )");
451
state = ISI_CHAR_A_BSLASH;
452                     break;
453         case '\n':
454                     state = INIT;
455             // - System.out.print(" state->INIT r=CHAR_LITERAL )");
456
return ELTokenContext.CHAR_LITERAL;
457                 case '\'':
458                     offset++;
459                     state = INIT;
460             // - System.out.print(" state->INIT r=CHAR_LITERAL )");
461
return ELTokenContext.CHAR_LITERAL;
462         default :
463             
464             if (buffer[offset-1] != '\'' && buffer[offset-1] != '\\'){
465             // - System.out.print(" state->ISI_CHAR_STRING ");
466
state = ISI_CHAR_STRING;
467             }
468             
469                 }
470         // - System.out.print(")");
471
break;
472
473             case ISI_CHAR_A_BSLASH:
474                 switch (ch) {
475                 case '\'':
476                 case '\\':
477                     break;
478                 default:
479                     offset--;
480                     break;
481                 }
482                 state = ISI_CHAR;
483                 break;
484         
485          case ISI_CHAR_STRING:
486         // - System.out.print(" ISI_CHAR_STRING (");
487
switch (ch) {
488                 case '\\':
489             // - System.out.print(" state->ISI_CHAR_A_BSLASH )");
490
state = ISI_CHAR_STRING_A_BSLASH;
491                     break;
492         case '\n':
493                     state = INIT;
494             // - System.out.print(" state->INIT r=STRING_LITERAL )");
495
return ELTokenContext.STRING_LITERAL;
496                 case '\'':
497                     offset++;
498                     state = INIT;
499             // - System.out.print(" state->INIT r=STRING_LITERAL )");
500
return ELTokenContext.STRING_LITERAL;
501                 }
502         // - System.out.print(")");
503
break;
504         
505             case ISI_CHAR_STRING_A_BSLASH:
506                 switch (ch) {
507                 case '\'':
508                 case '\\':
509                     break;
510                 default:
511                     offset--;
512                     break;
513                 }
514                 state = ISI_CHAR_STRING;
515                 break;
516         
517         case ISI_BRACKET_ISA_ZERO:
518         case ISA_ZERO:
519                 switch (ch) {
520                 case '.':
521             state = (state == ISI_BRACKET_ISA_ZERO) ? ISI_BRACKET_ISI_DOUBLE : ISI_DOUBLE;
522                     break;
523                 case 'x':
524                 case 'X':
525             state = (state == ISI_BRACKET_ISA_ZERO) ? ISI_BRACKET_ISI_HEX : ISI_HEX;
526                     break;
527                 case 'l':
528                 case 'L':
529                     offset++;
530                     state = (state == ISI_BRACKET_ISA_ZERO) ? ISI_BRACKET : INIT;
531                     return ELTokenContext.LONG_LITERAL;
532                 case 'f':
533                 case 'F':
534                     offset++;
535                     state = (state == ISI_BRACKET_ISA_ZERO) ? ISI_BRACKET : INIT;
536                     return ELTokenContext.FLOAT_LITERAL;
537                 case 'd':
538                 case 'D':
539                     offset++;
540                     state = (state == ISI_BRACKET_ISA_ZERO) ? ISI_BRACKET : INIT;
541                     return ELTokenContext.DOUBLE_LITERAL;
542                 case '8': // it's error to have '8' and '9' in octal number
543
case '9':
544                     state = (state == ISI_BRACKET_ISA_ZERO) ? ISI_BRACKET : INIT;
545                     offset++;
546                     return ELTokenContext.INVALID_OCTAL_LITERAL;
547                 case 'e':
548                 case 'E':
549             state = (state == ISI_BRACKET_ISA_ZERO) ? ISI_BRACKET_ISI_DOUBLE_EXP : ISI_DOUBLE_EXP;
550                     break;
551                 default:
552                     if (Character.isDigit(ch)) { // '8' and '9' already handled
553
state = (state == ISI_BRACKET_ISA_ZERO) ? ISI_BRACKET_ISI_OCTAL : ISI_OCTAL;
554                         break;
555                     }
556                     state = (state == ISI_BRACKET_ISA_ZERO) ? ISI_BRACKET : INIT;
557                     return ELTokenContext.INT_LITERAL;
558                 }
559                 break;
560         
561         case ISI_BRACKET_ISI_INT:
562         case ISI_INT:
563                 switch (ch) {
564                 case 'l':
565                 case 'L':
566                     offset++;
567                     state = (state == ISI_BRACKET_ISI_INT) ? ISI_BRACKET : INIT;
568                     return ELTokenContext.LONG_LITERAL;
569                 case '.':
570             state = (state == ISI_BRACKET_ISI_INT) ? ISI_BRACKET_ISI_DOUBLE : ISI_DOUBLE;
571                     break;
572                 case 'f':
573                 case 'F':
574                     offset++;
575                     state = (state == ISI_BRACKET_ISI_INT) ? ISI_BRACKET : INIT;
576                     return ELTokenContext.FLOAT_LITERAL;
577                 case 'd':
578                 case 'D':
579                     offset++;
580                     state = (state == ISI_BRACKET_ISI_INT) ? ISI_BRACKET : INIT;
581                     return ELTokenContext.DOUBLE_LITERAL;
582                 case 'e':
583                 case 'E':
584                     state = ISI_DOUBLE_EXP;
585                     break;
586                 default:
587                     if (!(ch >= '0' && ch <= '9')) {
588                         state = (state == ISI_BRACKET_ISI_INT) ? ISI_BRACKET : INIT;
589                         return ELTokenContext.INT_LITERAL;
590                     }
591                 }
592                 break;
593         
594         case ISI_BRACKET_ISI_OCTAL:
595             case ISI_OCTAL:
596                 if (!(ch >= '0' && ch <= '7')) {
597                     state = (state == ISI_BRACKET_ISI_OCTAL) ? ISI_BRACKET : INIT;
598                     return ELTokenContext.OCTAL_LITERAL;
599                 }
600                 break;
601         
602         case ISI_BRACKET_ISI_DOUBLE:
603             case ISI_DOUBLE:
604                 switch (ch) {
605                 case 'f':
606                 case 'F':
607                     offset++;
608                     state = (state == ISI_BRACKET_ISI_DOUBLE) ? ISI_BRACKET : INIT;
609                     return ELTokenContext.FLOAT_LITERAL;
610                 case 'd':
611                 case 'D':
612                     offset++;
613                     state = (state == ISI_BRACKET_ISI_DOUBLE) ? ISI_BRACKET : INIT;
614                     return ELTokenContext.DOUBLE_LITERAL;
615                 case 'e':
616                 case 'E':
617             state = (state == ISI_BRACKET_ISI_DOUBLE) ? ISI_BRACKET_ISI_DOUBLE_EXP : ISI_DOUBLE_EXP;
618                     break;
619                 default:
620                     if (!((ch >= '0' && ch <= '9')
621                             || ch == '.')) {
622                         state = (state == ISI_BRACKET_ISI_DOUBLE) ? ISI_BRACKET : INIT;
623                         return ELTokenContext.DOUBLE_LITERAL;
624                     }
625                 }
626                 break;
627         
628         case ISI_DOUBLE_EXP:
629             case ISI_BRACKET_ISI_DOUBLE_EXP:
630                 switch (ch) {
631                 case 'f':
632                 case 'F':
633                     offset++;
634                     state = (state == ISI_BRACKET_ISI_DOUBLE_EXP) ? ISI_BRACKET : INIT;
635                     return ELTokenContext.FLOAT_LITERAL;
636                 case 'd':
637                 case 'D':
638                     offset++;
639                     state = (state == ISI_BRACKET_ISI_DOUBLE_EXP) ? ISI_BRACKET : INIT;
640                     return ELTokenContext.DOUBLE_LITERAL;
641         case '-':
642         case '+':
643             state = ISI_DOULE_EXP_ISA_SIGN;
644             break;
645                 default:
646                     if (!Character.isDigit(ch)){
647                             //|| ch == '-' || ch == '+')) {
648
state = (state == ISI_BRACKET_ISI_DOUBLE_EXP) ? ISI_BRACKET : INIT;
649                         return ELTokenContext.DOUBLE_LITERAL;
650                     }
651                 }
652                 break;
653         
654         case ISI_DOULE_EXP_ISA_SIGN:
655         case ISI_BRACKET_ISI_DOULE_EXP_ISA_SIGN:
656         if (!Character.isDigit(ch)){
657             state = (state == ISI_BRACKET_ISI_DOULE_EXP_ISA_SIGN) ? ISI_BRACKET : INIT;
658             return ELTokenContext.DOUBLE_LITERAL;
659         }
660         break;
661         
662         case ISI_BRACKET_ISI_HEX:
663             case ISI_HEX:
664                 if (!((ch >= 'a' && ch <= 'f')
665                         || (ch >= 'A' && ch <= 'F')
666                         || Character.isDigit(ch))
667                    ) {
668                     state = (state == ISI_BRACKET_ISI_HEX) ? ISI_BRACKET : INIT;
669                     return ELTokenContext.HEX_LITERAL;
670                 }
671                 break;
672         
673         case ISI_BRACKET_ISA_DOT:
674             case ISA_DOT:
675                 if (Character.isDigit(ch)) {
676                     state = (state == ISI_BRACKET_ISA_DOT) ? ISI_BRACKET_ISI_DOUBLE : ISI_DOUBLE;
677
678                 } else { // only single dot
679
state = (state == ISI_BRACKET_ISA_DOT) ? ISI_BRACKET : INIT;
680                     return ELTokenContext.DOT;
681                 }
682                 break;
683         
684             } // end of switch(state)
685

686             offset++; // move to the next char
687
}
688
689         /* At this state there's no more text in the scanned buffer.
690         * The caller will decide either to stop scanning at all
691         * or to relocate scanning and provide next buffer with characters.
692         * The lastBuffer variable indicates whether the scanning will
693         * stop (true) or the caller will provide another buffer
694         * to continue on (false) and call relocate() to continue on the given buffer.
695         * If this is the last buffer, the analyzer must ensure
696         * that for all internal states there will be some token ID returned.
697         * The easiest way how to ensure that all the internal states will
698         * be covered is to copy all the internal state constants and
699         * put them after the switch() and provide the code that will return
700         * appropriate token ID.
701         *
702         * When there are no more characters available in the buffer
703         * and the buffer is not the last one the analyzer can still
704         * decide to return the token ID even if it doesn't know whether
705         * the token is complete or not. This is possible in this simple
706         * implementation for example because it doesn't matter whether
707         * it returns the text all together or broken into several pieces.
708         * The advantage of such aproach is that the preScan value
709         * is minimized which avoids the additional increasing of the buffer
710         * by preScan characters, but on the other hand it can become
711         * problematic if the token should be forwarded for some further
712         * processing. For example it could seem handy to return incomplete
713         * token for java block comments but it could become difficult
714         * if we would want to analyzer these comment tokens additionally
715         * by the HTML analyzer for example.
716         */

717
718         // Normally the following block would be done only for lastBuffer == true
719
// but in this case it can always be done
720
if (lastBuffer){
721         switch (state) {
722         case ISI_WHITESPACE:
723             state = INIT;
724             return ELTokenContext.WHITESPACE;
725         case ISI_IDENTIFIER:
726             state = INIT;
727             TokenID kwd = matchKeyword(buffer, tokenOffset, offset - tokenOffset);
728             return (kwd != null) ? kwd : ELTokenContext.IDENTIFIER;
729         case ISI_STRING:
730         case ISI_STRING_A_BSLASH:
731             return ELTokenContext.STRING_LITERAL; // hold the state
732
case ISI_CHAR:
733         case ISI_CHAR_A_BSLASH:
734             return ELTokenContext.CHAR_LITERAL;
735         case ISI_CHAR_STRING :
736         case ISI_CHAR_STRING_A_BSLASH :
737             return ELTokenContext.STRING_LITERAL;
738         case ISA_ZERO:
739         case ISI_INT:
740             state = INIT;
741             return ELTokenContext.INT_LITERAL;
742         case ISI_OCTAL:
743             state = INIT;
744             return ELTokenContext.OCTAL_LITERAL;
745         case ISI_DOUBLE:
746         case ISI_DOUBLE_EXP:
747         case ISI_DOULE_EXP_ISA_SIGN:
748         case ISI_BRACKET_ISI_DOULE_EXP_ISA_SIGN:
749                     state = INIT;
750                 return ELTokenContext.DOUBLE_LITERAL;
751         case ISI_HEX:
752             state = INIT;
753             return ELTokenContext.HEX_LITERAL;
754         case ISA_DOT:
755             state = INIT;
756             return ELTokenContext.DOT;
757         case ISA_EQ:
758             state = INIT;
759             return ELTokenContext.EQ_EQ;
760         case ISA_GT:
761             state = INIT;
762             return ELTokenContext.GT;
763         case ISA_LT:
764             state = INIT;
765             return ELTokenContext.LT;
766         case ISA_PIPE:
767             state = INIT;
768             return ELTokenContext.OR_OR;
769         case ISA_AND:
770             state = INIT;
771             return ELTokenContext.AND_AND;
772         case ISA_EXCLAMATION:
773             state = INIT;
774             return ELTokenContext.NOT;
775         case ISI_BRACKET:
776         case ISI_BRACKET_A_IDENTIFIER:
777             state = INIT;
778             return ELTokenContext.IDENTIFIER;
779         case ISI_BRACKET_A_WHITESPACE:
780             state = ISI_BRACKET;
781             return ELTokenContext.WHITESPACE;
782         case ISI_BRACKET_ISA_EQ:
783             state = ISI_BRACKET;
784             return ELTokenContext.EQ_EQ;
785         case ISI_BRACKET_ISA_GT:
786             state = ISI_BRACKET;
787             return ELTokenContext.GT_EQ;
788         case ISI_BRACKET_ISA_LT:
789             state = ISI_BRACKET;
790             return ELTokenContext.LT_EQ;
791         case ISI_BRACKET_ISA_AND:
792             state = ISI_BRACKET;
793             return ELTokenContext.AND_AND;
794         case ISI_BRACKET_ISA_PIPE:
795             state = ISI_BRACKET;
796             return ELTokenContext.OR_OR;
797         case ISI_BRACKET_ISA_DOT:
798             state = ISI_BRACKET;
799             return ELTokenContext.DOT;
800         case ISI_BRACKET_ISA_ZERO:
801         case ISI_BRACKET_ISI_INT:
802             state = ISI_BRACKET;
803             return ELTokenContext.INT_LITERAL;
804         
805             
806         }
807     }
808         
809         return null;
810     }
811     
812     
813     public static TokenID matchKeyword(char[] buffer, int offset, int len) {
814         if (len > 10)
815             return null;
816         if (len <= 1)
817             return null;
818         switch (buffer[offset++]) {
819             case 'a':
820         if (len <= 2) return null;
821         return (len == 3
822                         && buffer[offset++] == 'n'
823                         && buffer[offset++] == 'd')
824                         ? ELTokenContext.AND_KEYWORD : null;
825         case 'd':
826         if (len <= 2) return null;
827         return (len == 3
828                         && buffer[offset++] == 'i'
829                         && buffer[offset++] == 'v')
830                         ? ELTokenContext.DIV_KEYWORD : null;
831         case 'e':
832         switch (buffer[offset++]) {
833             case 'q':
834             return (len == 2) ? ELTokenContext.EQ_KEYWORD : null;
835             case 'm':
836             return (len == 5
837                         && buffer[offset++] == 'p'
838             && buffer[offset++] == 't'
839                         && buffer[offset++] == 'y')
840                         ? ELTokenContext.EMPTY_KEYWORD : null;
841             default:
842             return null;
843         }
844         case 'f':
845         return (len == 5
846             && buffer[offset++] == 'a'
847             && buffer[offset++] == 'l'
848             && buffer[offset++] == 's'
849             && buffer[offset++] == 'e')
850             ? ELTokenContext.FALSE_KEYWORD : null;
851         case 'g':
852         switch (buffer[offset++]){
853             case 'e':
854             return (len == 2) ? ELTokenContext.GE_KEYWORD : null;
855             case 't':
856             return (len == 2) ? ELTokenContext.GT_KEYWORD : null;
857             default:
858             return null;
859         }
860         case 'l':
861         switch (buffer[offset++]){
862             case 'e':
863             return (len == 2) ? ELTokenContext.LE_KEYWORD : null;
864             case 't':
865             return (len == 2) ? ELTokenContext.LT_KEYWORD : null;
866             default:
867             return null;
868         }
869         case 'i':
870         if (len <= 9) return null;
871         return (len == 10
872                         && buffer[offset++] == 'n'
873             && buffer[offset++] == 's'
874             && buffer[offset++] == 't'
875             && buffer[offset++] == 'a'
876             && buffer[offset++] == 'n'
877             && buffer[offset++] == 'c'
878             && buffer[offset++] == 'e'
879             && buffer[offset++] == 'o'
880                         && buffer[offset++] == 'f')
881                         ? ELTokenContext.INSTANCEOF_KEYWORD : null;
882         case 'm':
883         if (len <= 2) return null;
884         return (len == 3
885                         && buffer[offset++] == 'o'
886                         && buffer[offset++] == 'd')
887                         ? ELTokenContext.MOD_KEYWORD : null;
888         case 'n':
889         switch (buffer[offset++]){
890             case 'e':
891             return (len == 2) ? ELTokenContext.NE_KEYWORD : null;
892             case 'o':
893             return (len == 3
894                 && buffer[offset++] == 't')
895                 ? ELTokenContext.NOT_KEYWORD : null;
896             case 'u':
897             return (len == 4
898                 && buffer[offset++] == 'l'
899                 && buffer[offset++] == 'l')
900                 ? ELTokenContext.NULL_KEYWORD : null;
901             default:
902             return null;
903         }
904         case 'o':
905         return (len == 2
906             && buffer[offset++] == 'r')
907             ? ELTokenContext.OR_KEYWORD : null;
908         case 't':
909         return (len == 4
910             && buffer[offset++] == 'r'
911             && buffer[offset++] == 'u'
912             && buffer[offset++] == 'e')
913             ? ELTokenContext.TRUE_KEYWORD : null;
914
915         default :
916         return null;
917     }
918     }
919     
920     public String JavaDoc getStateName(int stateNumber) {
921     switch (stateNumber){
922         case ISI_IDENTIFIER : return "jsp_el_ISI_IDENTIFIER"; //NOI18N
923
case ISI_CHAR : return "el_ISI_CHAR"; //NOI18N
924
case ISI_CHAR_A_BSLASH : return "el_ISI_CHAR_A_BSLASH"; //NOI18N
925
case ISI_STRING : return "el_ISI_STRING"; //NOI18N
926
case ISI_STRING_A_BSLASH : return "el_ISI_STRING_A_BSLASH"; //NOI18N
927
case ISI_CHAR_STRING : return "el_ISI_CHAR_STRING"; //NOI18N
928
case ISI_CHAR_STRING_A_BSLASH : return "el_ISI_CHAR_STRING_A_BSLASH";//NOI18N
929
case ISA_ZERO : return "el_ISA_ZERO"; //NOI18N
930
case ISI_INT : return "el_ISI_INT"; //NOI18N
931
case ISI_OCTAL : return "el_ISI_OCTAL"; //NOI18N
932
case ISI_DOUBLE : return "el_ISI_DOUBLE"; //NOI18N
933
case ISI_DOUBLE_EXP : return "el_ISI_DOUBLE_EXP"; //NOI18N
934
case ISI_HEX : return "el_ISI_HEX"; //NOI18N
935
case ISA_DOT : return "el_ISA_DOT"; //NOI18N
936
case ISI_WHITESPACE : return "el_ISI_WHITESPACE"; //NOI18N
937
case ISA_EQ : return "el_ISA_EQ"; //NOI18N
938
case ISA_GT : return "el_ISA_GT"; //NOI18N
939
case ISA_LT : return "el_ISA_LT"; //NOI18N
940
case ISA_PIPE : return "el_ISA_PIPE"; //NOI18N
941
case ISA_AND : return "el_ISA_AND"; //NOI18N
942
case ISA_EXCLAMATION : return "el_ISA_EXCLAMATION"; //NOI18N
943
case ISI_BRACKET : return "el_ISI_BRACKET"; //NOI18N
944
case ISI_BRACKET_A_WHITESPACE: return "el_ISI_BRACKET_A_WHITSPACE";//NOI18N
945
case ISI_BRACKET_ISA_EQ : return "el_ISI_BRACKET_ISA_EQ"; //NOI18N
946
case ISI_BRACKET_ISA_GT : return "el_ISI_BRACKET_ISA_GT"; //NOI18N
947
case ISI_BRACKET_ISA_LT : return "el_ISI_BRACKET_ISA_LT"; //NOI18N
948
case ISI_BRACKET_ISA_AND : return "el_ISI_BRACKET_ISA_AND"; //NOI18N
949
case ISI_BRACKET_ISA_PIPE : return "el_ISI_BRACKET_ISA_PIPE"; //NOI18N
950
case ISI_BRACKET_ISI_INT : return "el_ISI_BRACKET_ISI_INT"; //NOI18N
951
case ISI_BRACKET_ISI_OCTAL : return "el_ISI_BRACKET_ISI_OCTAL"; //NOI18N
952
case ISI_BRACKET_ISI_DOUBLE : return "el_ISI_BRACKET_ISI_DOUBLE"; //NOI18N
953
case ISI_BRACKET_ISI_DOUBLE_EXP: return "el_ISI_BRACKET_ISI_DOUBLE_EXP";//NOI18N
954
case ISI_BRACKET_ISI_HEX : return "el_ISI_BRACKET_ISI_HEX"; //NOI18N
955
case ISI_BRACKET_ISI_DOULE_EXP_ISA_SIGN : return "el_ISI_BRACKET_ISI_DOULE_EXP_ISA_SIGN";
956         case ISI_DOULE_EXP_ISA_SIGN : return "el_ISI_DOULE_EXP_ISA_SIGN";
957         default:
958                 return super.getStateName(stateNumber);
959     }
960     }
961     
962 }
963
Popular Tags