bugfix 1412408
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Scanner.java
1 /***********************************************************************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others. All rights reserved. This program and the
3  * accompanying materials are made available under the terms of the Common Public License v0.5 which accompanies this distribution,
4  * and is available at http://www.eclipse.org/legal/cpl-v05.html
5  *
6  * Contributors: IBM Corporation - initial API and implementation
7  **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
9
10 import java.util.ArrayList;
11 import java.util.Iterator;
12 import java.util.List;
13
14 import net.sourceforge.phpdt.core.compiler.CharOperation;
15 import net.sourceforge.phpdt.core.compiler.IScanner;
16 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
17 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
18 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral;
19 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
20
21 public class Scanner implements IScanner, ITerminalSymbols {
22         /*
23          * APIs ares - getNextToken() which return the current type of the token (this
24          * value is not memorized by the scanner) - getCurrentTokenSource() which
25          * provides with the token "REAL" source (aka all unicode have been
26          * transformed into a correct char) - sourceStart gives the position into the
27          * stream - currentPosition-1 gives the sourceEnd position into the stream
28          */
29         // 1.4 feature
30         // private boolean assertMode;
31         public boolean useAssertAsAnIndentifier = false;
32
33         // flag indicating if processed source contains occurrences of keyword assert
34         public boolean containsAssertKeyword = false;
35
36         public boolean recordLineSeparator;
37
38         public boolean ignorePHPOneLiner = false;
39
40         public boolean phpMode = false;
41
42         /**
43          * This token is set to TokenNameecho if a short tag block begins (i.e. >?= ... )
44          * Directly after the "=" character the getNextToken() method returns TokenNameINLINE_HTML
45          * In the next call to the getNextToken() method the value of fFillerToken (==TokenNameecho) is returned
46          *
47          */
48         int fFillerToken = TokenNameEOF;
49
50         public char currentCharacter;
51
52         public int startPosition;
53
54         public int currentPosition;
55
56         public int initialPosition, eofPosition;
57
58         // after this position eof are generated instead of real token from the
59         // source
60         public boolean tokenizeComments;
61
62         public boolean tokenizeWhiteSpace;
63
64         public boolean tokenizeStrings;
65
66         // source should be viewed as a window (aka a part)
67         // of a entire very large stream
68         public char source[];
69
70         // unicode support
71         public char[] withoutUnicodeBuffer;
72
73         public int withoutUnicodePtr;
74
75         // when == 0 ==> no unicode in the current token
76         public boolean unicodeAsBackSlash = false;
77
78         public boolean scanningFloatLiteral = false;
79
80         // support for /** comments
81         public int[] commentStops = new int[10];
82
83         public int[] commentStarts = new int[10];
84
85         public int commentPtr = -1; // no comment test with commentPtr value -1
86
87         protected int lastCommentLinePosition = -1;
88
89         // diet parsing support - jump over some method body when requested
90         public boolean diet = false;
91
92         // support for the poor-line-debuggers ....
93         // remember the position of the cr/lf
94         public int[] lineEnds = new int[250];
95
96         public int linePtr = -1;
97
98         public boolean wasAcr = false;
99
100         public static final String END_OF_SOURCE = "End_Of_Source"; //$NON-NLS-1$
101
102         public static final String INVALID_HEXA = "Invalid_Hexa_Literal"; //$NON-NLS-1$
103
104         public static final String INVALID_OCTAL = "Invalid_Octal_Literal"; //$NON-NLS-1$
105
106         public static final String INVALID_CHARACTER_CONSTANT = "Invalid_Character_Constant"; //$NON-NLS-1$
107
108         public static final String INVALID_ESCAPE = "Invalid_Escape"; //$NON-NLS-1$
109
110         public static final String INVALID_INPUT = "Invalid_Input"; //$NON-NLS-1$
111
112         public static final String INVALID_UNICODE_ESCAPE = "Invalid_Unicode_Escape"; //$NON-NLS-1$
113
114         public static final String INVALID_FLOAT = "Invalid_Float_Literal"; //$NON-NLS-1$
115
116         public static final String NULL_SOURCE_STRING = "Null_Source_String"; //$NON-NLS-1$
117
118         public static final String UNTERMINATED_STRING = "Unterminated_String"; //$NON-NLS-1$
119
120         public static final String UNTERMINATED_COMMENT = "Unterminated_Comment"; //$NON-NLS-1$
121
122         public static final String INVALID_CHAR_IN_STRING = "Invalid_Char_In_String"; //$NON-NLS-1$
123
124         // ----------------optimized identifier managment------------------
125         static final char[] charArray_a = new char[] { 'a' }, charArray_b = new char[] { 'b' }, charArray_c = new char[] { 'c' },
126                         charArray_d = new char[] { 'd' }, charArray_e = new char[] { 'e' }, charArray_f = new char[] { 'f' },
127                         charArray_g = new char[] { 'g' }, charArray_h = new char[] { 'h' }, charArray_i = new char[] { 'i' },
128                         charArray_j = new char[] { 'j' }, charArray_k = new char[] { 'k' }, charArray_l = new char[] { 'l' },
129                         charArray_m = new char[] { 'm' }, charArray_n = new char[] { 'n' }, charArray_o = new char[] { 'o' },
130                         charArray_p = new char[] { 'p' }, charArray_q = new char[] { 'q' }, charArray_r = new char[] { 'r' },
131                         charArray_s = new char[] { 's' }, charArray_t = new char[] { 't' }, charArray_u = new char[] { 'u' },
132                         charArray_v = new char[] { 'v' }, charArray_w = new char[] { 'w' }, charArray_x = new char[] { 'x' },
133                         charArray_y = new char[] { 'y' }, charArray_z = new char[] { 'z' };
134
135         static final char[] charArray_va = new char[] { '$', 'a' }, charArray_vb = new char[] { '$', 'b' }, charArray_vc = new char[] {
136                         '$', 'c' }, charArray_vd = new char[] { '$', 'd' }, charArray_ve = new char[] { '$', 'e' }, charArray_vf = new char[] { '$',
137                         'f' }, charArray_vg = new char[] { '$', 'g' }, charArray_vh = new char[] { '$', 'h' },
138                         charArray_vi = new char[] { '$', 'i' }, charArray_vj = new char[] { '$', 'j' }, charArray_vk = new char[] { '$', 'k' },
139                         charArray_vl = new char[] { '$', 'l' }, charArray_vm = new char[] { '$', 'm' }, charArray_vn = new char[] { '$', 'n' },
140                         charArray_vo = new char[] { '$', 'o' }, charArray_vp = new char[] { '$', 'p' }, charArray_vq = new char[] { '$', 'q' },
141                         charArray_vr = new char[] { '$', 'r' }, charArray_vs = new char[] { '$', 's' }, charArray_vt = new char[] { '$', 't' },
142                         charArray_vu = new char[] { '$', 'u' }, charArray_vv = new char[] { '$', 'v' }, charArray_vw = new char[] { '$', 'w' },
143                         charArray_vx = new char[] { '$', 'x' }, charArray_vy = new char[] { '$', 'y' }, charArray_vz = new char[] { '$', 'z' };
144
145         public final static int MAX_OBVIOUS = 256;
146
147         static final int[] ObviousIdentCharNatures = new int[MAX_OBVIOUS];
148
149         public final static int C_DOLLAR = 8;
150
151         public final static int C_LETTER = 4;
152
153         public final static int C_DIGIT = 3;
154
155         public final static int C_SEPARATOR = 2;
156
157         public final static int C_SPACE = 1;
158         static {
159                 for (int i = '0'; i <= '9'; i++)
160                         ObviousIdentCharNatures[i] = C_DIGIT;
161
162                 for (int i = 'a'; i <= 'z'; i++)
163                         ObviousIdentCharNatures[i] = C_LETTER;
164                 for (int i = 'A'; i <= 'Z'; i++)
165                         ObviousIdentCharNatures[i] = C_LETTER;
166                 ObviousIdentCharNatures['_'] = C_LETTER;
167                 for (int i = 127; i <= 255; i++)
168                         ObviousIdentCharNatures[i] = C_LETTER;
169
170                 ObviousIdentCharNatures['$'] = C_DOLLAR;
171
172                 ObviousIdentCharNatures[10] = C_SPACE; // \ u000a: LINE FEED
173                 ObviousIdentCharNatures[12] = C_SPACE; // \ u000c: FORM FEED
174                 ObviousIdentCharNatures[13] = C_SPACE; // \ u000d: CARRIAGE RETURN
175                 ObviousIdentCharNatures[32] = C_SPACE; // \ u0020: SPACE
176                 ObviousIdentCharNatures[9] = C_SPACE; // \ u0009: HORIZONTAL TABULATION
177
178                 ObviousIdentCharNatures['.'] = C_SEPARATOR;
179                 ObviousIdentCharNatures[':'] = C_SEPARATOR;
180                 ObviousIdentCharNatures[';'] = C_SEPARATOR;
181                 ObviousIdentCharNatures[','] = C_SEPARATOR;
182                 ObviousIdentCharNatures['['] = C_SEPARATOR;
183                 ObviousIdentCharNatures[']'] = C_SEPARATOR;
184                 ObviousIdentCharNatures['('] = C_SEPARATOR;
185                 ObviousIdentCharNatures[')'] = C_SEPARATOR;
186                 ObviousIdentCharNatures['{'] = C_SEPARATOR;
187                 ObviousIdentCharNatures['}'] = C_SEPARATOR;
188                 ObviousIdentCharNatures['+'] = C_SEPARATOR;
189                 ObviousIdentCharNatures['-'] = C_SEPARATOR;
190                 ObviousIdentCharNatures['*'] = C_SEPARATOR;
191                 ObviousIdentCharNatures['/'] = C_SEPARATOR;
192                 ObviousIdentCharNatures['='] = C_SEPARATOR;
193                 ObviousIdentCharNatures['&'] = C_SEPARATOR;
194                 ObviousIdentCharNatures['|'] = C_SEPARATOR;
195                 ObviousIdentCharNatures['?'] = C_SEPARATOR;
196                 ObviousIdentCharNatures['<'] = C_SEPARATOR;
197                 ObviousIdentCharNatures['>'] = C_SEPARATOR;
198                 ObviousIdentCharNatures['!'] = C_SEPARATOR;
199                 ObviousIdentCharNatures['%'] = C_SEPARATOR;
200                 ObviousIdentCharNatures['^'] = C_SEPARATOR;
201                 ObviousIdentCharNatures['~'] = C_SEPARATOR;
202                 ObviousIdentCharNatures['"'] = C_SEPARATOR;
203                 ObviousIdentCharNatures['\''] = C_SEPARATOR;
204         }
205
206         static final char[] initCharArray = new char[] { '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' };
207
208         static final int TableSize = 30, InternalTableSize = 6;
209
210         // 30*6 = 180 entries
211         public static final int OptimizedLength = 6;
212
213         public/* static */
214         final char[][][][] charArray_length = new char[OptimizedLength][TableSize][InternalTableSize][];
215
216         // support for detecting non-externalized string literals
217         int currentLineNr = -1;
218
219         int previousLineNr = -1;
220
221         NLSLine currentLine = null;
222
223         List lines = new ArrayList();
224
225         public static final String TAG_PREFIX = "//$NON-NLS-"; //$NON-NLS-1$
226
227         public static final int TAG_PREFIX_LENGTH = TAG_PREFIX.length();
228
229         public static final String TAG_POSTFIX = "$"; //$NON-NLS-1$
230
231         public static final int TAG_POSTFIX_LENGTH = TAG_POSTFIX.length();
232
233         public StringLiteral[] nonNLSStrings = null;
234
235         public boolean checkNonExternalizedStringLiterals = true;
236
237         public boolean wasNonExternalizedStringLiteral = false;
238
239         /* static */{
240                 for (int i = 0; i < 6; i++) {
241                         for (int j = 0; j < TableSize; j++) {
242                                 for (int k = 0; k < InternalTableSize; k++) {
243                                         charArray_length[i][j][k] = initCharArray;
244                                 }
245                         }
246                 }
247         }
248
249         static int newEntry2 = 0, newEntry3 = 0, newEntry4 = 0, newEntry5 = 0, newEntry6 = 0;
250
251         public static final int RoundBracket = 0;
252
253         public static final int SquareBracket = 1;
254
255         public static final int CurlyBracket = 2;
256
257         public static final int BracketKinds = 3;
258
259         // task tag support
260         public char[][] foundTaskTags = null;
261
262         public char[][] foundTaskMessages;
263
264         public char[][] foundTaskPriorities = null;
265
266         public int[][] foundTaskPositions;
267
268         public int foundTaskCount = 0;
269
270         public char[][] taskTags = null;
271
272         public char[][] taskPriorities = null;
273
274         public boolean isTaskCaseSensitive = true;
275
276         public static final boolean DEBUG = false;
277
278         public static final boolean TRACE = false;
279
280         public ICompilationUnit compilationUnit = null;
281
282         /**
283          * Determines if the specified character is permissible as the first character
284          * in a PHP identifier or variable
285          *
286          * The '$' character for PHP variables is regarded as a correct first
287          * character !
288          *
289          */
290         public static boolean isPHPIdentOrVarStart(char ch) {
291                 if (ch < MAX_OBVIOUS) {
292                         return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DOLLAR;
293                 }
294                 return false;
295                 // return Character.isLetter(ch) || (ch == '$') || (ch == '_') || (0x7F <=
296                 // ch && ch <= 0xFF);
297         }
298
299         /**
300          * Determines if the specified character is permissible as the first character
301          * in a PHP identifier.
302          *
303          * The '$' character for PHP variables isn't regarded as the first character !
304          */
305         public static boolean isPHPIdentifierStart(char ch) {
306                 if (ch < MAX_OBVIOUS) {
307                         return ObviousIdentCharNatures[ch] == C_LETTER;
308                 }
309                 return false;
310                 // return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <=
311                 // 0xFF);
312         }
313
314         /**
315          * Determines if the specified character may be part of a PHP identifier as
316          * other than the first character
317          */
318         public static boolean isPHPIdentifierPart(char ch) {
319                 if (ch < MAX_OBVIOUS) {
320                         return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DIGIT;
321                 }
322                 return false;
323                 // return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch
324                 // <= 0xFF);
325         }
326
327         public static boolean isSQLIdentifierPart(char ch) {
328                 if (ch < MAX_OBVIOUS) {
329                         return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DIGIT;
330                 }
331                 return false;
332         }
333
334         public final boolean atEnd() {
335                 // This code is not relevant if source is
336                 // Only a part of the real stream input
337                 return source.length == currentPosition;
338         }
339
340         public char[] getCurrentIdentifierSource() {
341                 // return the token REAL source (aka unicodes are precomputed)
342                 char[] result;
343                 // if (withoutUnicodePtr != 0)
344                 // //0 is used as a fast test flag so the real first char is in position 1
345                 // System.arraycopy(
346                 // withoutUnicodeBuffer,
347                 // 1,
348                 // result = new char[withoutUnicodePtr],
349                 // 0,
350                 // withoutUnicodePtr);
351                 // else {
352                 int length = currentPosition - startPosition;
353                 switch (length) { // see OptimizedLength
354                 case 1:
355                         return optimizedCurrentTokenSource1();
356                 case 2:
357                         return optimizedCurrentTokenSource2();
358                 case 3:
359                         return optimizedCurrentTokenSource3();
360                 case 4:
361                         return optimizedCurrentTokenSource4();
362                 case 5:
363                         return optimizedCurrentTokenSource5();
364                 case 6:
365                         return optimizedCurrentTokenSource6();
366                 }
367                 // no optimization
368                 System.arraycopy(source, startPosition, result = new char[length], 0, length);
369                 // }
370                 return result;
371         }
372
373         public int getCurrentTokenEndPosition() {
374                 return this.currentPosition - 1;
375         }
376
377         public final char[] getCurrentTokenSource() {
378                 // Return the token REAL source (aka unicodes are precomputed)
379                 char[] result;
380                 // if (withoutUnicodePtr != 0)
381                 // // 0 is used as a fast test flag so the real first char is in position 1
382                 // System.arraycopy(
383                 // withoutUnicodeBuffer,
384                 // 1,
385                 // result = new char[withoutUnicodePtr],
386                 // 0,
387                 // withoutUnicodePtr);
388                 // else {
389                 int length;
390                 System.arraycopy(source, startPosition, result = new char[length = currentPosition - startPosition], 0, length);
391                 // }
392                 return result;
393         }
394
395         public final char[] getCurrentTokenSource(int startPos) {
396                 // Return the token REAL source (aka unicodes are precomputed)
397                 char[] result;
398                 // if (withoutUnicodePtr != 0)
399                 // // 0 is used as a fast test flag so the real first char is in position 1
400                 // System.arraycopy(
401                 // withoutUnicodeBuffer,
402                 // 1,
403                 // result = new char[withoutUnicodePtr],
404                 // 0,
405                 // withoutUnicodePtr);
406                 // else {
407                 int length;
408                 System.arraycopy(source, startPos, result = new char[length = currentPosition - startPos], 0, length);
409                 // }
410                 return result;
411         }
412
413         public final char[] getCurrentTokenSourceString() {
414                 // return the token REAL source (aka unicodes are precomputed).
415                 // REMOVE the two " that are at the beginning and the end.
416                 char[] result;
417                 if (withoutUnicodePtr != 0)
418                         // 0 is used as a fast test flag so the real first char is in position 1
419                         System.arraycopy(withoutUnicodeBuffer, 2,
420                         // 2 is 1 (real start) + 1 (to jump over the ")
421                                         result = new char[withoutUnicodePtr - 2], 0, withoutUnicodePtr - 2);
422                 else {
423                         int length;
424                         System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length);
425                 }
426                 return result;
427         }
428
429         public final boolean equalsCurrentTokenSource(char[] word) {
430                 if (word.length != currentPosition - startPosition) {
431                         return false;
432                 }
433                 for (int i = 0; i < word.length; i++) {
434                         if (word[i] != source[startPosition + i]) {
435                                 return false;
436                         }
437                 }
438                 return true;
439         }
440
441         public final char[] getRawTokenSourceEnd() {
442                 int length = this.eofPosition - this.currentPosition - 1;
443                 char[] sourceEnd = new char[length];
444                 System.arraycopy(this.source, this.currentPosition, sourceEnd, 0, length);
445                 return sourceEnd;
446         }
447
448         public int getCurrentTokenStartPosition() {
449                 return this.startPosition;
450         }
451
452         public final String getCurrentStringLiteral() {
453                 char[] result = getCurrentStringLiteralSource();
454                 return new String(result);
455         }
456
457         public final char[] getCurrentStringLiteralSource() {
458                 // Return the token REAL source (aka unicodes are precomputed)
459                 if (startPosition + 1 >= currentPosition) {
460                         return new char[0];
461                 }
462                 char[] result;
463                 int length;
464                 System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length);
465                 // }
466                 return result;
467         }
468
469         public final char[] getCurrentStringLiteralSource(int startPos) {
470                 // Return the token REAL source (aka unicodes are precomputed)
471                 char[] result;
472                 int length;
473                 System.arraycopy(source, startPos + 1, result = new char[length = currentPosition - startPos - 2], 0, length);
474                 // }
475                 return result;
476         }
477
478         /*
479          * Search the source position corresponding to the end of a given line number
480          *
481          * Line numbers are 1-based, and relative to the scanner initialPosition.
482          * Character positions are 0-based.
483          *
484          * In case the given line number is inconsistent, answers -1.
485          */
486         public final int getLineEnd(int lineNumber) {
487                 if (lineEnds == null)
488                         return -1;
489                 if (lineNumber >= lineEnds.length)
490                         return -1;
491                 if (lineNumber <= 0)
492                         return -1;
493                 if (lineNumber == lineEnds.length - 1)
494                         return eofPosition;
495                 return lineEnds[lineNumber - 1];
496                 // next line start one character behind the lineEnd of the previous line
497         }
498
499         /**
500          * Search the source position corresponding to the beginning of a given line
501          * number
502          *
503          * Line numbers are 1-based, and relative to the scanner initialPosition.
504          * Character positions are 0-based.
505          *
506          * e.g. getLineStart(1) --> 0 i.e. first line starts at character 0.
507          *
508          * In case the given line number is inconsistent, answers -1.
509          */
510         public final int getLineStart(int lineNumber) {
511                 if (lineEnds == null)
512                         return -1;
513                 if (lineNumber >= lineEnds.length)
514                         return -1;
515                 if (lineNumber <= 0)
516                         return -1;
517                 if (lineNumber == 1)
518                         return initialPosition;
519                 return lineEnds[lineNumber - 2] + 1;
520                 // next line start one character behind the lineEnd of the previous line
521         }
522
523         public final boolean getNextChar(char testedChar) {
524                 // BOOLEAN
525                 // handle the case of unicode.
526                 // when a unicode appears then we must use a buffer that holds char
527                 // internal values
528                 // At the end of this method currentCharacter holds the new visited char
529                 // and currentPosition points right next after it
530                 // Both previous lines are true if the currentCharacter is == to the
531                 // testedChar
532                 // On false, no side effect has occured.
533                 // ALL getNextChar.... ARE OPTIMIZED COPIES
534                 int temp = currentPosition;
535                 try {
536                         currentCharacter = source[currentPosition++];
537                         // if (((currentCharacter = source[currentPosition++]) == '\\')
538                         // && (source[currentPosition] == 'u')) {
539                         // //-------------unicode traitement ------------
540                         // int c1, c2, c3, c4;
541                         // int unicodeSize = 6;
542                         // currentPosition++;
543                         // while (source[currentPosition] == 'u') {
544                         // currentPosition++;
545                         // unicodeSize++;
546                         // }
547                         //
548                         // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
549                         // || c1 < 0)
550                         // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
551                         // || c2 < 0)
552                         // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
553                         // || c3 < 0)
554                         // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
555                         // || c4 < 0)) {
556                         // currentPosition = temp;
557                         // return false;
558                         // }
559                         //
560                         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
561                         // if (currentCharacter != testedChar) {
562                         // currentPosition = temp;
563                         // return false;
564                         // }
565                         // unicodeAsBackSlash = currentCharacter == '\\';
566                         //
567                         // //need the unicode buffer
568                         // if (withoutUnicodePtr == 0) {
569                         // //buffer all the entries that have been left aside....
570                         // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
571                         // System.arraycopy(
572                         // source,
573                         // startPosition,
574                         // withoutUnicodeBuffer,
575                         // 1,
576                         // withoutUnicodePtr);
577                         // }
578                         // //fill the buffer with the char
579                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
580                         // return true;
581                         //
582                         // } //-------------end unicode traitement--------------
583                         // else {
584                         if (currentCharacter != testedChar) {
585                                 currentPosition = temp;
586                                 return false;
587                         }
588                         unicodeAsBackSlash = false;
589                         // if (withoutUnicodePtr != 0)
590                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
591                         return true;
592                         // }
593                 } catch (IndexOutOfBoundsException e) {
594                         unicodeAsBackSlash = false;
595                         currentPosition = temp;
596                         return false;
597                 }
598         }
599
600         public final int getNextChar(char testedChar1, char testedChar2) {
601                 // INT 0 : testChar1 \\\\///\\\\ 1 : testedChar2 \\\\///\\\\ -1 : others
602                 // test can be done with (x==0) for the first and (x>0) for the second
603                 // handle the case of unicode.
604                 // when a unicode appears then we must use a buffer that holds char
605                 // internal values
606                 // At the end of this method currentCharacter holds the new visited char
607                 // and currentPosition points right next after it
608                 // Both previous lines are true if the currentCharacter is == to the
609                 // testedChar1/2
610                 // On false, no side effect has occured.
611                 // ALL getNextChar.... ARE OPTIMIZED COPIES
612                 int temp = currentPosition;
613                 try {
614                         int result;
615                         currentCharacter = source[currentPosition++];
616                         // if (((currentCharacter = source[currentPosition++]) == '\\')
617                         // && (source[currentPosition] == 'u')) {
618                         // //-------------unicode traitement ------------
619                         // int c1, c2, c3, c4;
620                         // int unicodeSize = 6;
621                         // currentPosition++;
622                         // while (source[currentPosition] == 'u') {
623                         // currentPosition++;
624                         // unicodeSize++;
625                         // }
626                         //
627                         // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
628                         // || c1 < 0)
629                         // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
630                         // || c2 < 0)
631                         // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
632                         // || c3 < 0)
633                         // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
634                         // || c4 < 0)) {
635                         // currentPosition = temp;
636                         // return 2;
637                         // }
638                         //
639                         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
640                         // if (currentCharacter == testedChar1)
641                         // result = 0;
642                         // else if (currentCharacter == testedChar2)
643                         // result = 1;
644                         // else {
645                         // currentPosition = temp;
646                         // return -1;
647                         // }
648                         //
649                         // //need the unicode buffer
650                         // if (withoutUnicodePtr == 0) {
651                         // //buffer all the entries that have been left aside....
652                         // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
653                         // System.arraycopy(
654                         // source,
655                         // startPosition,
656                         // withoutUnicodeBuffer,
657                         // 1,
658                         // withoutUnicodePtr);
659                         // }
660                         // //fill the buffer with the char
661                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
662                         // return result;
663                         // } //-------------end unicode traitement--------------
664                         // else {
665                         if (currentCharacter == testedChar1)
666                                 result = 0;
667                         else if (currentCharacter == testedChar2)
668                                 result = 1;
669                         else {
670                                 currentPosition = temp;
671                                 return -1;
672                         }
673                         // if (withoutUnicodePtr != 0)
674                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
675                         return result;
676                         // }
677                 } catch (IndexOutOfBoundsException e) {
678                         currentPosition = temp;
679                         return -1;
680                 }
681         }
682
683         public final boolean getNextCharAsDigit() {
684                 // BOOLEAN
685                 // handle the case of unicode.
686                 // when a unicode appears then we must use a buffer that holds char
687                 // internal values
688                 // At the end of this method currentCharacter holds the new visited char
689                 // and currentPosition points right next after it
690                 // Both previous lines are true if the currentCharacter is a digit
691                 // On false, no side effect has occured.
692                 // ALL getNextChar.... ARE OPTIMIZED COPIES
693                 int temp = currentPosition;
694                 try {
695                         currentCharacter = source[currentPosition++];
696                         // if (((currentCharacter = source[currentPosition++]) == '\\')
697                         // && (source[currentPosition] == 'u')) {
698                         // //-------------unicode traitement ------------
699                         // int c1, c2, c3, c4;
700                         // int unicodeSize = 6;
701                         // currentPosition++;
702                         // while (source[currentPosition] == 'u') {
703                         // currentPosition++;
704                         // unicodeSize++;
705                         // }
706                         //
707                         // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
708                         // || c1 < 0)
709                         // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
710                         // || c2 < 0)
711                         // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
712                         // || c3 < 0)
713                         // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
714                         // || c4 < 0)) {
715                         // currentPosition = temp;
716                         // return false;
717                         // }
718                         //
719                         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
720                         // if (!Character.isDigit(currentCharacter)) {
721                         // currentPosition = temp;
722                         // return false;
723                         // }
724                         //
725                         // //need the unicode buffer
726                         // if (withoutUnicodePtr == 0) {
727                         // //buffer all the entries that have been left aside....
728                         // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
729                         // System.arraycopy(
730                         // source,
731                         // startPosition,
732                         // withoutUnicodeBuffer,
733                         // 1,
734                         // withoutUnicodePtr);
735                         // }
736                         // //fill the buffer with the char
737                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
738                         // return true;
739                         // } //-------------end unicode traitement--------------
740                         // else {
741                         if (!Character.isDigit(currentCharacter)) {
742                                 currentPosition = temp;
743                                 return false;
744                         }
745                         // if (withoutUnicodePtr != 0)
746                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
747                         return true;
748                         // }
749                 } catch (IndexOutOfBoundsException e) {
750                         currentPosition = temp;
751                         return false;
752                 }
753         }
754
755         public final boolean getNextCharAsDigit(int radix) {
756                 // BOOLEAN
757                 // handle the case of unicode.
758                 // when a unicode appears then we must use a buffer that holds char
759                 // internal values
760                 // At the end of this method currentCharacter holds the new visited char
761                 // and currentPosition points right next after it
762                 // Both previous lines are true if the currentCharacter is a digit base on
763                 // radix
764                 // On false, no side effect has occured.
765                 // ALL getNextChar.... ARE OPTIMIZED COPIES
766                 int temp = currentPosition;
767                 try {
768                         currentCharacter = source[currentPosition++];
769                         // if (((currentCharacter = source[currentPosition++]) == '\\')
770                         // && (source[currentPosition] == 'u')) {
771                         // //-------------unicode traitement ------------
772                         // int c1, c2, c3, c4;
773                         // int unicodeSize = 6;
774                         // currentPosition++;
775                         // while (source[currentPosition] == 'u') {
776                         // currentPosition++;
777                         // unicodeSize++;
778                         // }
779                         //
780                         // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
781                         // || c1 < 0)
782                         // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
783                         // || c2 < 0)
784                         // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
785                         // || c3 < 0)
786                         // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
787                         // || c4 < 0)) {
788                         // currentPosition = temp;
789                         // return false;
790                         // }
791                         //
792                         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
793                         // if (Character.digit(currentCharacter, radix) == -1) {
794                         // currentPosition = temp;
795                         // return false;
796                         // }
797                         //
798                         // //need the unicode buffer
799                         // if (withoutUnicodePtr == 0) {
800                         // //buffer all the entries that have been left aside....
801                         // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
802                         // System.arraycopy(
803                         // source,
804                         // startPosition,
805                         // withoutUnicodeBuffer,
806                         // 1,
807                         // withoutUnicodePtr);
808                         // }
809                         // //fill the buffer with the char
810                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
811                         // return true;
812                         // } //-------------end unicode traitement--------------
813                         // else {
814                         if (Character.digit(currentCharacter, radix) == -1) {
815                                 currentPosition = temp;
816                                 return false;
817                         }
818                         // if (withoutUnicodePtr != 0)
819                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
820                         return true;
821                         // }
822                 } catch (IndexOutOfBoundsException e) {
823                         currentPosition = temp;
824                         return false;
825                 }
826         }
827
828         public boolean getNextCharAsJavaIdentifierPart() {
829                 // BOOLEAN
830                 // handle the case of unicode.
831                 // when a unicode appears then we must use a buffer that holds char
832                 // internal values
833                 // At the end of this method currentCharacter holds the new visited char
834                 // and currentPosition points right next after it
835                 // Both previous lines are true if the currentCharacter is a
836                 // JavaIdentifierPart
837                 // On false, no side effect has occured.
838                 // ALL getNextChar.... ARE OPTIMIZED COPIES
839                 int temp = currentPosition;
840                 try {
841                         currentCharacter = source[currentPosition++];
842                         // if (((currentCharacter = source[currentPosition++]) == '\\')
843                         // && (source[currentPosition] == 'u')) {
844                         // //-------------unicode traitement ------------
845                         // int c1, c2, c3, c4;
846                         // int unicodeSize = 6;
847                         // currentPosition++;
848                         // while (source[currentPosition] == 'u') {
849                         // currentPosition++;
850                         // unicodeSize++;
851                         // }
852                         //
853                         // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
854                         // || c1 < 0)
855                         // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
856                         // || c2 < 0)
857                         // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
858                         // || c3 < 0)
859                         // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
860                         // || c4 < 0)) {
861                         // currentPosition = temp;
862                         // return false;
863                         // }
864                         //
865                         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
866                         // if (!isPHPIdentifierPart(currentCharacter)) {
867                         // currentPosition = temp;
868                         // return false;
869                         // }
870                         //
871                         // //need the unicode buffer
872                         // if (withoutUnicodePtr == 0) {
873                         // //buffer all the entries that have been left aside....
874                         // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
875                         // System.arraycopy(
876                         // source,
877                         // startPosition,
878                         // withoutUnicodeBuffer,
879                         // 1,
880                         // withoutUnicodePtr);
881                         // }
882                         // //fill the buffer with the char
883                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
884                         // return true;
885                         // } //-------------end unicode traitement--------------
886                         // else {
887                         if (!isPHPIdentifierPart(currentCharacter)) {
888                                 currentPosition = temp;
889                                 return false;
890                         }
891                         // if (withoutUnicodePtr != 0)
892                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
893                         return true;
894                         // }
895                 } catch (IndexOutOfBoundsException e) {
896                         currentPosition = temp;
897                         return false;
898                 }
899         }
900
901         public int getCastOrParen() {
902                 int tempPosition = currentPosition;
903                 char tempCharacter = currentCharacter;
904                 int tempToken = TokenNameLPAREN;
905                 boolean found = false;
906                 StringBuffer buf = new StringBuffer();
907                 try {
908                         do {
909                                 currentCharacter = source[currentPosition++];
910                         } while (currentCharacter == ' ' || currentCharacter == '\t');
911                         while (ObviousIdentCharNatures[currentCharacter] == C_LETTER) {
912                                 // while((currentCharacter >= 'a' && currentCharacter <= 'z') ||
913                                 // (currentCharacter >= 'A' && currentCharacter <= 'Z')) {
914                                 buf.append(currentCharacter);
915                                 currentCharacter = source[currentPosition++];
916                         }
917                         if (buf.length() >= 3 && buf.length() <= 7) {
918                                 char[] data = buf.toString().toCharArray();
919                                 int index = 0;
920                                 switch (data.length) {
921                                 case 3:
922                                         // int
923                                         if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
924                                                 found = true;
925                                                 tempToken = TokenNameintCAST;
926                                         }
927                                         break;
928                                 case 4:
929                                         // bool real
930                                         if ((data[index] == 'b') && (data[++index] == 'o') && (data[++index] == 'o') && (data[++index] == 'l')) {
931                                                 found = true;
932                                                 tempToken = TokenNameboolCAST;
933                                         } else {
934                                                 index = 0;
935                                                 if ((data[index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'l')) {
936                                                         found = true;
937                                                         tempToken = TokenNamedoubleCAST;
938                                                 }
939                                         }
940                                         break;
941                                 case 5:
942                                         // array unset float
943                                         if ((data[index] == 'a') && (data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a')
944                                                         && (data[++index] == 'y')) {
945                                                 found = true;
946                                                 tempToken = TokenNamearrayCAST;
947                                         } else {
948                                                 index = 0;
949                                                 if ((data[index] == 'u') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e')
950                                                                 && (data[++index] == 't')) {
951                                                         found = true;
952                                                         tempToken = TokenNameunsetCAST;
953                                                 } else {
954                                                         index = 0;
955                                                         if ((data[index] == 'f') && (data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'a')
956                                                                         && (data[++index] == 't')) {
957                                                                 found = true;
958                                                                 tempToken = TokenNamedoubleCAST;
959                                                         }
960                                                 }
961                                         }
962                                         break;
963                                 case 6:
964                                         // object string double
965                                         if ((data[index] == 'o') && (data[++index] == 'b') && (data[++index] == 'j') && (data[++index] == 'e')
966                                                         && (data[++index] == 'c') && (data[++index] == 't')) {
967                                                 found = true;
968                                                 tempToken = TokenNameobjectCAST;
969                                         } else {
970                                                 index = 0;
971                                                 if ((data[index] == 's') && (data[++index] == 't') && (data[++index] == 'r') && (data[++index] == 'i')
972                                                                 && (data[++index] == 'n') && (data[++index] == 'g')) {
973                                                         found = true;
974                                                         tempToken = TokenNamestringCAST;
975                                                 } else {
976                                                         index = 0;
977                                                         if ((data[index] == 'd') && (data[++index] == 'o') && (data[++index] == 'u') && (data[++index] == 'b')
978                                                                         && (data[++index] == 'l') && (data[++index] == 'e')) {
979                                                                 found = true;
980                                                                 tempToken = TokenNamedoubleCAST;
981                                                         }
982                                                 }
983                                         }
984                                         break;
985                                 case 7:
986                                         // boolean integer
987                                         if ((data[index] == 'b') && (data[++index] == 'o') && (data[++index] == 'o') && (data[++index] == 'l')
988                                                         && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'n')) {
989                                                 found = true;
990                                                 tempToken = TokenNameboolCAST;
991                                         } else {
992                                                 index = 0;
993                                                 if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e')
994                                                                 && (data[++index] == 'g') && (data[++index] == 'e') && (data[++index] == 'r')) {
995                                                         found = true;
996                                                         tempToken = TokenNameintCAST;
997                                                 }
998                                         }
999                                         break;
1000                                 }
1001                                 if (found) {
1002                                         while (currentCharacter == ' ' || currentCharacter == '\t') {
1003                                                 currentCharacter = source[currentPosition++];
1004                                         }
1005                                         if (currentCharacter == ')') {
1006                                                 return tempToken;
1007                                         }
1008                                 }
1009                         }
1010                 } catch (IndexOutOfBoundsException e) {
1011                 }
1012                 currentCharacter = tempCharacter;
1013                 currentPosition = tempPosition;
1014                 return TokenNameLPAREN;
1015         }
1016
1017         public void consumeStringInterpolated() throws InvalidInputException {
1018                 try {
1019                         // consume next character
1020                         unicodeAsBackSlash = false;
1021                         currentCharacter = source[currentPosition++];
1022                         // if (((currentCharacter = source[currentPosition++]) == '\\')
1023                         // && (source[currentPosition] == 'u')) {
1024                         // getNextUnicodeChar();
1025                         // } else {
1026                         // if (withoutUnicodePtr != 0) {
1027                         // withoutUnicodeBuffer[++withoutUnicodePtr] =
1028                         // currentCharacter;
1029                         // }
1030                         // }
1031                         while (currentCharacter != '`') {
1032                                 /** ** in PHP \r and \n are valid in string literals *** */
1033                                 // if ((currentCharacter == '\n')
1034                                 // || (currentCharacter == '\r')) {
1035                                 // // relocate if finding another quote fairly close: thus unicode
1036                                 // '/u000D' will be fully consumed
1037                                 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1038                                 // if (currentPosition + lookAhead == source.length)
1039                                 // break;
1040                                 // if (source[currentPosition + lookAhead] == '\n')
1041                                 // break;
1042                                 // if (source[currentPosition + lookAhead] == '\"') {
1043                                 // currentPosition += lookAhead + 1;
1044                                 // break;
1045                                 // }
1046                                 // }
1047                                 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1048                                 // }
1049                                 if (currentCharacter == '\\') {
1050                                         int escapeSize = currentPosition;
1051                                         boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1052                                         // scanEscapeCharacter make a side effect on this value and we need
1053                                         // the previous value few lines down this one
1054                                         scanDoubleQuotedEscapeCharacter();
1055                                         escapeSize = currentPosition - escapeSize;
1056                                         if (withoutUnicodePtr == 0) {
1057                                                 // buffer all the entries that have been left aside....
1058                                                 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1059                                                 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1060                                                 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1061                                         } else { // overwrite the / in the buffer
1062                                                 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1063                                                 if (backSlashAsUnicodeInString) { // there are TWO \ in the stream
1064                                                         // where only one is correct
1065                                                         withoutUnicodePtr--;
1066                                                 }
1067                                         }
1068                                 } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1069                                         if (recordLineSeparator) {
1070                                                 pushLineSeparator();
1071                                         }
1072                                 }
1073                                 // consume next character
1074                                 unicodeAsBackSlash = false;
1075                                 currentCharacter = source[currentPosition++];
1076                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
1077                                 // && (source[currentPosition] == 'u')) {
1078                                 // getNextUnicodeChar();
1079                                 // } else {
1080                                 if (withoutUnicodePtr != 0) {
1081                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1082                                 }
1083                                 // }
1084                         }
1085                 } catch (IndexOutOfBoundsException e) {
1086                         // reset end position for error reporting
1087                         currentPosition -= 2;
1088                         throw new InvalidInputException(UNTERMINATED_STRING);
1089                 } catch (InvalidInputException e) {
1090                         if (e.getMessage().equals(INVALID_ESCAPE)) {
1091                                 // relocate if finding another quote fairly close: thus unicode
1092                                 // '/u000D' will be fully consumed
1093                                 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1094                                         if (currentPosition + lookAhead == source.length)
1095                                                 break;
1096                                         if (source[currentPosition + lookAhead] == '\n')
1097                                                 break;
1098                                         if (source[currentPosition + lookAhead] == '`') {
1099                                                 currentPosition += lookAhead + 1;
1100                                                 break;
1101                                         }
1102                                 }
1103                         }
1104                         throw e; // rethrow
1105                 }
1106                 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1107                         // //$NON-NLS-?$ where ? is an
1108                         // int.
1109                         if (currentLine == null) {
1110                                 currentLine = new NLSLine();
1111                                 lines.add(currentLine);
1112                         }
1113                         currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1114                 }
1115         }
1116
1117         public void consumeStringConstant() throws InvalidInputException {
1118                 try {
1119                         // consume next character
1120                         unicodeAsBackSlash = false;
1121                         currentCharacter = source[currentPosition++];
1122                         // if (((currentCharacter = source[currentPosition++]) == '\\')
1123                         // && (source[currentPosition] == 'u')) {
1124                         // getNextUnicodeChar();
1125                         // } else {
1126                         // if (withoutUnicodePtr != 0) {
1127                         // withoutUnicodeBuffer[++withoutUnicodePtr] =
1128                         // currentCharacter;
1129                         // }
1130                         // }
1131                         while (currentCharacter != '\'') {
1132                                 /** ** in PHP \r and \n are valid in string literals *** */
1133                                 // if ((currentCharacter == '\n')
1134                                 // || (currentCharacter == '\r')) {
1135                                 // // relocate if finding another quote fairly close: thus unicode
1136                                 // '/u000D' will be fully consumed
1137                                 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1138                                 // if (currentPosition + lookAhead == source.length)
1139                                 // break;
1140                                 // if (source[currentPosition + lookAhead] == '\n')
1141                                 // break;
1142                                 // if (source[currentPosition + lookAhead] == '\"') {
1143                                 // currentPosition += lookAhead + 1;
1144                                 // break;
1145                                 // }
1146                                 // }
1147                                 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1148                                 // }
1149                                 if (currentCharacter == '\\') {
1150                                         int escapeSize = currentPosition;
1151                                         boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1152                                         // scanEscapeCharacter make a side effect on this value and we need
1153                                         // the previous value few lines down this one
1154                                         scanSingleQuotedEscapeCharacter();
1155                                         escapeSize = currentPosition - escapeSize;
1156                                         if (withoutUnicodePtr == 0) {
1157                                                 // buffer all the entries that have been left aside....
1158                                                 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1159                                                 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1160                                                 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1161                                         } else { // overwrite the / in the buffer
1162                                                 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1163                                                 if (backSlashAsUnicodeInString) { // there are TWO \ in the stream
1164                                                         // where only one is correct
1165                                                         withoutUnicodePtr--;
1166                                                 }
1167                                         }
1168                                 } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1169                                         if (recordLineSeparator) {
1170                                                 pushLineSeparator();
1171                                         }
1172                                 }
1173                                 // consume next character
1174                                 unicodeAsBackSlash = false;
1175                                 currentCharacter = source[currentPosition++];
1176                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
1177                                 // && (source[currentPosition] == 'u')) {
1178                                 // getNextUnicodeChar();
1179                                 // } else {
1180                                 if (withoutUnicodePtr != 0) {
1181                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1182                                 }
1183                                 // }
1184                         }
1185                 } catch (IndexOutOfBoundsException e) {
1186                         // reset end position for error reporting
1187                         currentPosition -= 2;
1188                         throw new InvalidInputException(UNTERMINATED_STRING);
1189                 } catch (InvalidInputException e) {
1190                         if (e.getMessage().equals(INVALID_ESCAPE)) {
1191                                 // relocate if finding another quote fairly close: thus unicode
1192                                 // '/u000D' will be fully consumed
1193                                 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1194                                         if (currentPosition + lookAhead == source.length)
1195                                                 break;
1196                                         if (source[currentPosition + lookAhead] == '\n')
1197                                                 break;
1198                                         if (source[currentPosition + lookAhead] == '\'') {
1199                                                 currentPosition += lookAhead + 1;
1200                                                 break;
1201                                         }
1202                                 }
1203                         }
1204                         throw e; // rethrow
1205                 }
1206                 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1207                         // //$NON-NLS-?$ where ? is an
1208                         // int.
1209                         if (currentLine == null) {
1210                                 currentLine = new NLSLine();
1211                                 lines.add(currentLine);
1212                         }
1213                         currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1214                 }
1215         }
1216
1217         public void consumeStringLiteral() throws InvalidInputException {
1218                 try {
1219                         int openDollarBrace = 0;
1220                         // consume next character
1221                         unicodeAsBackSlash = false;
1222                         currentCharacter = source[currentPosition++];
1223                         while (currentCharacter != '"' || openDollarBrace>0) {
1224                                 /** ** in PHP \r and \n are valid in string literals *** */
1225                                 if (currentCharacter == '\\') {
1226                                         int escapeSize = currentPosition;
1227                                         boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1228                                         // scanEscapeCharacter make a side effect on this value and we need
1229                                         // the previous value few lines down this one
1230                                         scanDoubleQuotedEscapeCharacter();
1231                                         escapeSize = currentPosition - escapeSize;
1232                                         if (withoutUnicodePtr == 0) {
1233                                                 // buffer all the entries that have been left aside....
1234                                                 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1235                                                 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1236                                                 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1237                                         } else { // overwrite the / in the buffer
1238                                                 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1239                                                 if (backSlashAsUnicodeInString) { // there are TWO \ in the stream
1240                                                         // where only one is correct
1241                                                         withoutUnicodePtr--;
1242                                                 }
1243                                         }
1244                                 } else if (currentCharacter == '$' && source[currentPosition] == '{') {
1245                                         openDollarBrace++;
1246                                 } else if (currentCharacter == '{' && source[currentPosition] == '$') {
1247                                         openDollarBrace++;
1248                                 } else if (currentCharacter == '}') {
1249                                         openDollarBrace--;
1250                                 } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1251                                         if (recordLineSeparator) {
1252                                                 pushLineSeparator();
1253                                         }
1254                                 }
1255                                 // consume next character
1256                                 unicodeAsBackSlash = false;
1257                                 currentCharacter = source[currentPosition++];
1258                                 if (withoutUnicodePtr != 0) {
1259                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1260                                 }
1261                         }
1262                 } catch (IndexOutOfBoundsException e) {
1263                         // reset end position for error reporting
1264                         currentPosition -= 2;
1265                         throw new InvalidInputException(UNTERMINATED_STRING);
1266                 } catch (InvalidInputException e) {
1267                         if (e.getMessage().equals(INVALID_ESCAPE)) {
1268                                 // relocate if finding another quote fairly close: thus unicode
1269                                 // '/u000D' will be fully consumed
1270                                 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1271                                         if (currentPosition + lookAhead == source.length)
1272                                                 break;
1273                                         if (source[currentPosition + lookAhead] == '\n')
1274                                                 break;
1275                                         if (source[currentPosition + lookAhead] == '\"') {
1276                                                 currentPosition += lookAhead + 1;
1277                                                 break;
1278                                         }
1279                                 }
1280                         }
1281                         throw e; // rethrow
1282                 }
1283                 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1284                         // //$NON-NLS-?$ where ? is an
1285                         // int.
1286                         if (currentLine == null) {
1287                                 currentLine = new NLSLine();
1288                                 lines.add(currentLine);
1289                         }
1290                         currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1291                 }
1292         }
1293
1294         public int getNextToken() throws InvalidInputException {
1295                 if (!phpMode) {
1296                         return getInlinedHTMLToken(currentPosition);
1297                 } else {
1298                         if (fFillerToken != TokenNameEOF) {
1299                                 int tempToken;
1300                                 startPosition = currentPosition;
1301                                 tempToken = fFillerToken;
1302                                 fFillerToken = TokenNameEOF;
1303                                 return tempToken;
1304                         }
1305                         this.wasAcr = false;
1306                         if (diet) {
1307                                 jumpOverMethodBody();
1308                                 diet = false;
1309                                 return currentPosition > source.length ? TokenNameEOF : TokenNameRBRACE;
1310                         }
1311                         try {
1312                                 while (true) {
1313                                         withoutUnicodePtr = 0;
1314                                         // ---------Consume white space and handles startPosition---------
1315                                         int whiteStart = currentPosition;
1316                                         startPosition = currentPosition;
1317                                         currentCharacter = source[currentPosition++];
1318
1319                                         while ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) {
1320                                                 startPosition = currentPosition;
1321                                                 currentCharacter = source[currentPosition++];
1322                                                 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1323                                                         checkNonExternalizeString();
1324                                                         if (recordLineSeparator) {
1325                                                                 pushLineSeparator();
1326                                                         } else {
1327                                                                 currentLine = null;
1328                                                         }
1329                                                 }
1330                                         }
1331                                         if (tokenizeWhiteSpace && (whiteStart != currentPosition - 1)) {
1332                                                 // reposition scanner in case we are interested by spaces as tokens
1333                                                 currentPosition--;
1334                                                 startPosition = whiteStart;
1335                                                 return TokenNameWHITESPACE;
1336                                         }
1337                                         // little trick to get out in the middle of a source compuation
1338                                         if (currentPosition > eofPosition)
1339                                                 return TokenNameEOF;
1340                                         // ---------Identify the next token-------------
1341                                         switch (currentCharacter) {
1342                                         case '(':
1343                                                 return getCastOrParen();
1344                                         case ')':
1345                                                 return TokenNameRPAREN;
1346                                         case '{':
1347                                                 return TokenNameLBRACE;
1348                                         case '}':
1349                                                 return TokenNameRBRACE;
1350                                         case '[':
1351                                                 return TokenNameLBRACKET;
1352                                         case ']':
1353                                                 return TokenNameRBRACKET;
1354                                         case ';':
1355                                                 return TokenNameSEMICOLON;
1356                                         case ',':
1357                                                 return TokenNameCOMMA;
1358                                         case '.':
1359                                                 if (getNextChar('='))
1360                                                         return TokenNameDOT_EQUAL;
1361                                                 if (getNextCharAsDigit())
1362                                                         return scanNumber(true);
1363                                                 return TokenNameDOT;
1364                                         case '+': {
1365                                                 int test;
1366                                                 if ((test = getNextChar('+', '=')) == 0)
1367                                                         return TokenNamePLUS_PLUS;
1368                                                 if (test > 0)
1369                                                         return TokenNamePLUS_EQUAL;
1370                                                 return TokenNamePLUS;
1371                                         }
1372                                         case '-': {
1373                                                 int test;
1374                                                 if ((test = getNextChar('-', '=')) == 0)
1375                                                         return TokenNameMINUS_MINUS;
1376                                                 if (test > 0)
1377                                                         return TokenNameMINUS_EQUAL;
1378                                                 if (getNextChar('>'))
1379                                                         return TokenNameMINUS_GREATER;
1380                                                 return TokenNameMINUS;
1381                                         }
1382                                         case '~':
1383                                                 if (getNextChar('='))
1384                                                         return TokenNameTWIDDLE_EQUAL;
1385                                                 return TokenNameTWIDDLE;
1386                                         case '!':
1387                                                 if (getNextChar('=')) {
1388                                                         if (getNextChar('=')) {
1389                                                                 return TokenNameNOT_EQUAL_EQUAL;
1390                                                         }
1391                                                         return TokenNameNOT_EQUAL;
1392                                                 }
1393                                                 return TokenNameNOT;
1394                                         case '*':
1395                                                 if (getNextChar('='))
1396                                                         return TokenNameMULTIPLY_EQUAL;
1397                                                 return TokenNameMULTIPLY;
1398                                         case '%':
1399                                                 if (getNextChar('='))
1400                                                         return TokenNameREMAINDER_EQUAL;
1401                                                 return TokenNameREMAINDER;
1402                                         case '<': {
1403                                                 int oldPosition = currentPosition;
1404                                                 try {
1405                                                         currentCharacter = source[currentPosition++];
1406                                                 } catch (IndexOutOfBoundsException e) {
1407                                                         currentPosition = oldPosition;
1408                                                         return TokenNameLESS;
1409                                                 }
1410                                                 switch (currentCharacter) {
1411                                                 case '=':
1412                                                         return TokenNameLESS_EQUAL;
1413                                                 case '>':
1414                                                         return TokenNameNOT_EQUAL;
1415                                                 case '<':
1416                                                         if (getNextChar('='))
1417                                                                 return TokenNameLEFT_SHIFT_EQUAL;
1418                                                         if (getNextChar('<')) {
1419                                                                 currentCharacter = source[currentPosition++];
1420                                                                 while (Character.isWhitespace(currentCharacter)) {
1421                                                                         currentCharacter = source[currentPosition++];
1422                                                                 }
1423                                                                 int heredocStart = currentPosition - 1;
1424                                                                 int heredocLength = 0;
1425                                                                 if (isPHPIdentifierStart(currentCharacter)) {
1426                                                                         currentCharacter = source[currentPosition++];
1427                                                                 } else {
1428                                                                         return TokenNameERROR;
1429                                                                 }
1430                                                                 while (isPHPIdentifierPart(currentCharacter)) {
1431                                                                         currentCharacter = source[currentPosition++];
1432                                                                 }
1433                                                                 heredocLength = currentPosition - heredocStart - 1;
1434                                                                 // heredoc end-tag determination
1435                                                                 boolean endTag = true;
1436                                                                 char ch;
1437                                                                 do {
1438                                                                         ch = source[currentPosition++];
1439                                                                         if (ch == '\r' || ch == '\n') {
1440                                                                                 if (recordLineSeparator) {
1441                                                                                         pushLineSeparator();
1442                                                                                 } else {
1443                                                                                         currentLine = null;
1444                                                                                 }
1445                                                                                 for (int i = 0; i < heredocLength; i++) {
1446                                                                                         if (source[currentPosition + i] != source[heredocStart + i]) {
1447                                                                                                 endTag = false;
1448                                                                                                 break;
1449                                                                                         }
1450                                                                                 }
1451                                                                                 if (endTag) {
1452                                                                                         currentPosition += heredocLength - 1;
1453                                                                                         currentCharacter = source[currentPosition++];
1454                                                                                         break; // do...while loop
1455                                                                                 } else {
1456                                                                                         endTag = true;
1457                                                                                 }
1458                                                                         }
1459                                                                 } while (true);
1460                                                                 return TokenNameHEREDOC;
1461                                                         }
1462                                                         return TokenNameLEFT_SHIFT;
1463                                                 }
1464                                                 currentPosition = oldPosition;
1465                                                 return TokenNameLESS;
1466                                         }
1467                                         case '>': {
1468                                                 int test;
1469                                                 if ((test = getNextChar('=', '>')) == 0)
1470                                                         return TokenNameGREATER_EQUAL;
1471                                                 if (test > 0) {
1472                                                         if ((test = getNextChar('=', '>')) == 0)
1473                                                                 return TokenNameRIGHT_SHIFT_EQUAL;
1474                                                         return TokenNameRIGHT_SHIFT;
1475                                                 }
1476                                                 return TokenNameGREATER;
1477                                         }
1478                                         case '=':
1479                                                 if (getNextChar('=')) {
1480                                                         if (getNextChar('=')) {
1481                                                                 return TokenNameEQUAL_EQUAL_EQUAL;
1482                                                         }
1483                                                         return TokenNameEQUAL_EQUAL;
1484                                                 }
1485                                                 if (getNextChar('>'))
1486                                                         return TokenNameEQUAL_GREATER;
1487                                                 return TokenNameEQUAL;
1488                                         case '&': {
1489                                                 int test;
1490                                                 if ((test = getNextChar('&', '=')) == 0)
1491                                                         return TokenNameAND_AND;
1492                                                 if (test > 0)
1493                                                         return TokenNameAND_EQUAL;
1494                                                 return TokenNameAND;
1495                                         }
1496                                         case '|': {
1497                                                 int test;
1498                                                 if ((test = getNextChar('|', '=')) == 0)
1499                                                         return TokenNameOR_OR;
1500                                                 if (test > 0)
1501                                                         return TokenNameOR_EQUAL;
1502                                                 return TokenNameOR;
1503                                         }
1504                                         case '^':
1505                                                 if (getNextChar('='))
1506                                                         return TokenNameXOR_EQUAL;
1507                                                 return TokenNameXOR;
1508                                         case '?':
1509                                                 if (getNextChar('>')) {
1510                                                         phpMode = false;
1511                                                         if (currentPosition == source.length) {
1512                                                                 phpMode = true;
1513                                                                 return TokenNameINLINE_HTML;
1514                                                         }
1515                                                         return getInlinedHTMLToken(currentPosition - 2);
1516                                                 }
1517                                                 return TokenNameQUESTION;
1518                                         case ':':
1519                                                 if (getNextChar(':'))
1520                                                         return TokenNamePAAMAYIM_NEKUDOTAYIM;
1521                                                 return TokenNameCOLON;
1522                                         case '@':
1523                                                 return TokenNameAT;
1524                                         case '\'':
1525                                                 consumeStringConstant();
1526                                                 return TokenNameStringSingleQuote;
1527                                         case '"':
1528                                                 // if (tokenizeStrings) {
1529                                                 consumeStringLiteral();
1530                                                 return TokenNameStringDoubleQuote;
1531                                         // }
1532                                         // return TokenNameEncapsedString2;
1533                                         case '`':
1534                                                 // if (tokenizeStrings) {
1535                                                 consumeStringInterpolated();
1536                                                 return TokenNameStringInterpolated;
1537                                         // }
1538                                         // return TokenNameEncapsedString0;
1539                                         case '#':
1540                                         case '/': {
1541                                                 char startChar = currentCharacter;
1542                                                 if (getNextChar('=') && startChar == '/') {
1543                                                         return TokenNameDIVIDE_EQUAL;
1544                                                 }
1545                                                 int test;
1546                                                 if ((startChar == '#') || (test = getNextChar('/', '*')) == 0) {
1547                                                         // line comment
1548                                                         this.lastCommentLinePosition = this.currentPosition;
1549                                                         int endPositionForLineComment = 0;
1550                                                         try { // get the next char
1551                                                                 currentCharacter = source[currentPosition++];
1552                                                                 // if (((currentCharacter = source[currentPosition++])
1553                                                                 // == '\\')
1554                                                                 // && (source[currentPosition] == 'u')) {
1555                                                                 // //-------------unicode traitement ------------
1556                                                                 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1557                                                                 // currentPosition++;
1558                                                                 // while (source[currentPosition] == 'u') {
1559                                                                 // currentPosition++;
1560                                                                 // }
1561                                                                 // if ((c1 =
1562                                                                 // Character.getNumericValue(source[currentPosition++]))
1563                                                                 // > 15
1564                                                                 // || c1 < 0
1565                                                                 // || (c2 =
1566                                                                 // Character.getNumericValue(source[currentPosition++]))
1567                                                                 // > 15
1568                                                                 // || c2 < 0
1569                                                                 // || (c3 =
1570                                                                 // Character.getNumericValue(source[currentPosition++]))
1571                                                                 // > 15
1572                                                                 // || c3 < 0
1573                                                                 // || (c4 =
1574                                                                 // Character.getNumericValue(source[currentPosition++]))
1575                                                                 // > 15
1576                                                                 // || c4 < 0) {
1577                                                                 // throw new
1578                                                                 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1579                                                                 // } else {
1580                                                                 // currentCharacter =
1581                                                                 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1582                                                                 // }
1583                                                                 // }
1584                                                                 // handle the \\u case manually into comment
1585                                                                 // if (currentCharacter == '\\') {
1586                                                                 // if (source[currentPosition] == '\\')
1587                                                                 // currentPosition++;
1588                                                                 // } //jump over the \\
1589                                                                 boolean isUnicode = false;
1590                                                                 while (currentCharacter != '\r' && currentCharacter != '\n') {
1591                                                                         this.lastCommentLinePosition = this.currentPosition;
1592                                                                         if (currentCharacter == '?') {
1593                                                                                 if (getNextChar('>')) {
1594                                                                                         // ?> breaks line comments
1595                                                                                         startPosition = currentPosition - 2;
1596                                                                                         phpMode = false;
1597                                                                                         return TokenNameINLINE_HTML;
1598                                                                                 }
1599                                                                         }
1600                                                                         // get the next char
1601                                                                         isUnicode = false;
1602                                                                         currentCharacter = source[currentPosition++];
1603                                                                         // if (((currentCharacter = source[currentPosition++])
1604                                                                         // == '\\')
1605                                                                         // && (source[currentPosition] == 'u')) {
1606                                                                         // isUnicode = true;
1607                                                                         // //-------------unicode traitement ------------
1608                                                                         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1609                                                                         // currentPosition++;
1610                                                                         // while (source[currentPosition] == 'u') {
1611                                                                         // currentPosition++;
1612                                                                         // }
1613                                                                         // if ((c1 =
1614                                                                         // Character.getNumericValue(source[currentPosition++]))
1615                                                                         // > 15
1616                                                                         // || c1 < 0
1617                                                                         // || (c2 =
1618                                                                         // Character.getNumericValue(
1619                                                                         // source[currentPosition++]))
1620                                                                         // > 15
1621                                                                         // || c2 < 0
1622                                                                         // || (c3 =
1623                                                                         // Character.getNumericValue(
1624                                                                         // source[currentPosition++]))
1625                                                                         // > 15
1626                                                                         // || c3 < 0
1627                                                                         // || (c4 =
1628                                                                         // Character.getNumericValue(
1629                                                                         // source[currentPosition++]))
1630                                                                         // > 15
1631                                                                         // || c4 < 0) {
1632                                                                         // throw new
1633                                                                         // InvalidInputException(INVALID_UNICODE_ESCAPE);
1634                                                                         // } else {
1635                                                                         // currentCharacter =
1636                                                                         // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1637                                                                         // }
1638                                                                         // }
1639                                                                         // handle the \\u case manually into comment
1640                                                                         // if (currentCharacter == '\\') {
1641                                                                         // if (source[currentPosition] == '\\')
1642                                                                         // currentPosition++;
1643                                                                         // } //jump over the \\
1644                                                                 }
1645                                                                 if (isUnicode) {
1646                                                                         endPositionForLineComment = currentPosition - 6;
1647                                                                 } else {
1648                                                                         endPositionForLineComment = currentPosition - 1;
1649                                                                 }
1650                                                                 // recordComment(false);
1651                                                                 recordComment(TokenNameCOMMENT_LINE);
1652                                                                 if (this.taskTags != null)
1653                                                                         checkTaskTag(this.startPosition, this.currentPosition);
1654                                                                 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1655                                                                         checkNonExternalizeString();
1656                                                                         if (recordLineSeparator) {
1657                                                                                 if (isUnicode) {
1658                                                                                         pushUnicodeLineSeparator();
1659                                                                                 } else {
1660                                                                                         pushLineSeparator();
1661                                                                                 }
1662                                                                         } else {
1663                                                                                 currentLine = null;
1664                                                                         }
1665                                                                 }
1666                                                                 if (tokenizeComments) {
1667                                                                         if (!isUnicode) {
1668                                                                                 currentPosition = endPositionForLineComment;
1669                                                                                 // reset one character behind
1670                                                                         }
1671                                                                         return TokenNameCOMMENT_LINE;
1672                                                                 }
1673                                                         } catch (IndexOutOfBoundsException e) { // an eof will them
1674                                                                 // be generated
1675                                                                 if (tokenizeComments) {
1676                                                                         currentPosition--;
1677                                                                         // reset one character behind
1678                                                                         return TokenNameCOMMENT_LINE;
1679                                                                 }
1680                                                         }
1681                                                         break;
1682                                                 }
1683                                                 if (test > 0) {
1684                                                         // traditional and annotation comment
1685                                                         boolean isJavadoc = false, star = false;
1686                                                         // consume next character
1687                                                         unicodeAsBackSlash = false;
1688                                                         currentCharacter = source[currentPosition++];
1689                                                         // if (((currentCharacter = source[currentPosition++]) ==
1690                                                         // '\\')
1691                                                         // && (source[currentPosition] == 'u')) {
1692                                                         // getNextUnicodeChar();
1693                                                         // } else {
1694                                                         // if (withoutUnicodePtr != 0) {
1695                                                         // withoutUnicodeBuffer[++withoutUnicodePtr] =
1696                                                         // currentCharacter;
1697                                                         // }
1698                                                         // }
1699                                                         if (currentCharacter == '*') {
1700                                                                 isJavadoc = true;
1701                                                                 star = true;
1702                                                         }
1703                                                         if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1704                                                                 checkNonExternalizeString();
1705                                                                 if (recordLineSeparator) {
1706                                                                         pushLineSeparator();
1707                                                                 } else {
1708                                                                         currentLine = null;
1709                                                                 }
1710                                                         }
1711                                                         try { // get the next char
1712                                                                 currentCharacter = source[currentPosition++];
1713                                                                 // if (((currentCharacter = source[currentPosition++])
1714                                                                 // == '\\')
1715                                                                 // && (source[currentPosition] == 'u')) {
1716                                                                 // //-------------unicode traitement ------------
1717                                                                 // getNextUnicodeChar();
1718                                                                 // }
1719                                                                 // handle the \\u case manually into comment
1720                                                                 // if (currentCharacter == '\\') {
1721                                                                 // if (source[currentPosition] == '\\')
1722                                                                 // currentPosition++;
1723                                                                 // //jump over the \\
1724                                                                 // }
1725                                                                 // empty comment is not a javadoc /**/
1726                                                                 if (currentCharacter == '/') {
1727                                                                         isJavadoc = false;
1728                                                                 }
1729                                                                 // loop until end of comment */
1730                                                                 while ((currentCharacter != '/') || (!star)) {
1731                                                                         if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1732                                                                                 checkNonExternalizeString();
1733                                                                                 if (recordLineSeparator) {
1734                                                                                         pushLineSeparator();
1735                                                                                 } else {
1736                                                                                         currentLine = null;
1737                                                                                 }
1738                                                                         }
1739                                                                         star = currentCharacter == '*';
1740                                                                         // get next char
1741                                                                         currentCharacter = source[currentPosition++];
1742                                                                         // if (((currentCharacter = source[currentPosition++])
1743                                                                         // == '\\')
1744                                                                         // && (source[currentPosition] == 'u')) {
1745                                                                         // //-------------unicode traitement ------------
1746                                                                         // getNextUnicodeChar();
1747                                                                         // }
1748                                                                         // handle the \\u case manually into comment
1749                                                                         // if (currentCharacter == '\\') {
1750                                                                         // if (source[currentPosition] == '\\')
1751                                                                         // currentPosition++;
1752                                                                         // } //jump over the \\
1753                                                                 }
1754                                                                 // recordComment(isJavadoc);
1755                                                                 if (isJavadoc) {
1756                                                                         recordComment(TokenNameCOMMENT_PHPDOC);
1757                                                                 } else {
1758                                                                         recordComment(TokenNameCOMMENT_BLOCK);
1759                                                                 }
1760
1761                                                                 if (tokenizeComments) {
1762                                                                         if (isJavadoc)
1763                                                                                 return TokenNameCOMMENT_PHPDOC;
1764                                                                         return TokenNameCOMMENT_BLOCK;
1765                                                                 }
1766
1767                                                                 if (this.taskTags != null) {
1768                                                                         checkTaskTag(this.startPosition, this.currentPosition);
1769                                                                 }
1770                                                         } catch (IndexOutOfBoundsException e) {
1771                                                                 // reset end position for error reporting
1772                                                                 currentPosition -= 2;
1773                                                                 throw new InvalidInputException(UNTERMINATED_COMMENT);
1774                                                         }
1775                                                         break;
1776                                                 }
1777                                                 return TokenNameDIVIDE;
1778                                         }
1779                                         case '\u001a':
1780                                                 if (atEnd())
1781                                                         return TokenNameEOF;
1782                                                 // the atEnd may not be <currentPosition == source.length> if
1783                                                 // source is only some part of a real (external) stream
1784                                                 throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$
1785                                         default:
1786                                                 if (currentCharacter == '$') {
1787                                                         int oldPosition = currentPosition;
1788                                                         try {
1789                                                                 currentCharacter = source[currentPosition++];
1790                                                                 if (isPHPIdentifierStart(currentCharacter)) {
1791                                                                         return scanIdentifierOrKeyword(true);
1792                                                                 } else {
1793                                                                         currentPosition = oldPosition;
1794                                                                         return TokenNameDOLLAR;
1795                                                                 }
1796                                                         } catch (IndexOutOfBoundsException e) {
1797                                                                 currentPosition = oldPosition;
1798                                                                 return TokenNameDOLLAR;
1799                                                         }
1800                                                 }
1801                                                 if (isPHPIdentifierStart(currentCharacter))
1802                                                         return scanIdentifierOrKeyword(false);
1803                                                 if (Character.isDigit(currentCharacter))
1804                                                         return scanNumber(false);
1805                                                 return TokenNameERROR;
1806                                         }
1807                                 }
1808                         } // -----------------end switch while try--------------------
1809                         catch (IndexOutOfBoundsException e) {
1810                         }
1811                 }
1812                 return TokenNameEOF;
1813         }
1814
1815         /**
1816          * @return
1817          * @throws InvalidInputException
1818          */
1819         private int getInlinedHTMLToken(int start) throws InvalidInputException {
1820                 boolean phpShortTag = false; // true, if <?= detected
1821                 if (currentPosition > source.length) {
1822                         currentPosition = source.length;
1823                         return TokenNameEOF;
1824                 }
1825                 startPosition = start;
1826                 try {
1827                         while (!phpMode) {
1828                                 currentCharacter = source[currentPosition++];
1829                                 if (currentCharacter == '<') {
1830                                         if (getNextChar('?')) {
1831                                                 currentCharacter = source[currentPosition++];
1832                                                 if ((currentCharacter != 'P') && (currentCharacter != 'p')) {
1833                                                         if (currentCharacter != '=') { // <?=
1834                                                                 currentPosition--;
1835                                                                 phpShortTag = false;
1836                                                         } else {
1837                                                                 phpShortTag = true;
1838                                                         }
1839                                                         // <?
1840                                                         if (ignorePHPOneLiner) { // for CodeFormatter
1841                                                                 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1842                                                                         phpMode = true;
1843                                                                         if (phpShortTag) {
1844                                                                                 fFillerToken = TokenNameECHO_INVISIBLE;
1845                                                                         }
1846                                                                         return TokenNameINLINE_HTML;
1847                                                                 }
1848                                                         } else {
1849                                                                 boolean foundXML=false;
1850                                                                 if (getNextChar('X','x')>=0) {
1851                                                                         if (getNextChar('M','m')>=0) {
1852                                                                                 if (getNextChar('L','l')>=0) {
1853                                                                                         foundXML=true;
1854                                                                                 }
1855                                                                         }
1856                                                                 }
1857                                                                 if (!foundXML) {
1858                                                                         phpMode = true;
1859                                                                 }
1860                                                                 if (phpShortTag) {
1861                                                                         fFillerToken = TokenNameECHO_INVISIBLE;
1862                                                                 }
1863                                                                 return TokenNameINLINE_HTML;
1864                                                         }
1865                                                 } else {
1866                                                         if (getNextChar('H', 'h') >= 0) {
1867                                                                 if (getNextChar('P', 'p') >= 0) {
1868                                                                         // <?PHP <?php
1869                                                                         if (ignorePHPOneLiner) {
1870                                                                                 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1871                                                                                         phpMode = true;
1872                                                                                         return TokenNameINLINE_HTML;
1873                                                                                 }
1874                                                                         } else {
1875                                                                                 phpMode = true;
1876                                                                                 return TokenNameINLINE_HTML;
1877                                                                         }
1878                                                                 }
1879                                                         }
1880                                                         // }
1881                                                 }
1882                                         }
1883                                 }
1884                                 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1885                                         if (recordLineSeparator) {
1886                                                 pushLineSeparator();
1887                                         } else {
1888                                                 currentLine = null;
1889                                         }
1890                                 }
1891                         } // -----------------while--------------------
1892                         phpMode = true;
1893                         return TokenNameINLINE_HTML;
1894                 } // -----------------try--------------------
1895                 catch (IndexOutOfBoundsException e) {
1896                         startPosition = start;
1897                         currentPosition--;
1898                 }
1899                 phpMode = true;
1900                 return TokenNameINLINE_HTML;
1901         }
1902
1903         /**
1904          * check if the PHP is only in this line (for CodeFormatter)
1905          *
1906          * @return
1907          */
1908         private int lookAheadLinePHPTag() {
1909                 int currentPositionInLine = currentPosition;
1910                 char previousCharInLine = ' ';
1911                 char currentCharInLine = ' ';
1912                 boolean singleQuotedStringActive = false;
1913                 boolean doubleQuotedStringActive = false;
1914
1915                 try {
1916                         // look ahead in this line
1917                         while (true) {
1918                                 previousCharInLine = currentCharInLine;
1919                                 currentCharInLine = source[currentPositionInLine++];
1920                                 switch (currentCharInLine) {
1921                                 case '>':
1922                                         if (previousCharInLine == '?') {
1923                                                 // update the scanner's current Position in the source
1924                                                 currentPosition = currentPositionInLine;
1925                                                 // use as "dummy" token
1926                                                 return TokenNameEOF;
1927                                         }
1928                                         break;
1929                                 case '\\':
1930                                         if (doubleQuotedStringActive) {
1931                                                 // ignore escaped characters in double quoted strings
1932                                                 previousCharInLine = currentCharInLine;
1933                                                 currentCharInLine = source[currentPositionInLine++];
1934                                         }
1935                                 case '\"':
1936                                         if (doubleQuotedStringActive) {
1937                                                 doubleQuotedStringActive = false;
1938                                         } else {
1939                                                 if (!singleQuotedStringActive) {
1940                                                         doubleQuotedStringActive = true;
1941                                                 }
1942                                         }
1943                                         break;
1944                                 case '\'':
1945                                         if (singleQuotedStringActive) {
1946                                                 if (previousCharInLine != '\\') {
1947                                                         singleQuotedStringActive = false;
1948                                                 }
1949                                         } else {
1950                                                 if (!doubleQuotedStringActive) {
1951                                                         singleQuotedStringActive = true;
1952                                                 }
1953                                         }
1954                                         break;
1955                                 case '\n':
1956                                         phpMode = true;
1957                                         return TokenNameINLINE_HTML;
1958                                 case '#':
1959                                         if (!singleQuotedStringActive && !doubleQuotedStringActive) {
1960                                                 phpMode = true;
1961                                                 return TokenNameINLINE_HTML;
1962                                         }
1963                                         break;
1964                                 case '/':
1965                                         if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1966                                                 phpMode = true;
1967                                                 return TokenNameINLINE_HTML;
1968                                         }
1969                                         break;
1970                                 case '*':
1971                                         if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1972                                                 phpMode = true;
1973                                                 return TokenNameINLINE_HTML;
1974                                         }
1975                                         break;
1976                                 }
1977                         }
1978                 } catch (IndexOutOfBoundsException e) {
1979                         phpMode = true;
1980                         currentPosition = currentPositionInLine;
1981                         return TokenNameINLINE_HTML;
1982                 }
1983         }
1984
1985         // public final void getNextUnicodeChar()
1986         // throws IndexOutOfBoundsException, InvalidInputException {
1987         // //VOID
1988         // //handle the case of unicode.
1989         // //when a unicode appears then we must use a buffer that holds char
1990         // internal values
1991         // //At the end of this method currentCharacter holds the new visited char
1992         // //and currentPosition points right next after it
1993         //
1994         // //ALL getNextChar.... ARE OPTIMIZED COPIES
1995         //
1996         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
1997         // currentPosition++;
1998         // while (source[currentPosition] == 'u') {
1999         // currentPosition++;
2000         // unicodeSize++;
2001         // }
2002         //
2003         // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2004         // || c1 < 0
2005         // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
2006         // || c2 < 0
2007         // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
2008         // || c3 < 0
2009         // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
2010         // || c4 < 0) {
2011         // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2012         // } else {
2013         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2014         // //need the unicode buffer
2015         // if (withoutUnicodePtr == 0) {
2016         // //buffer all the entries that have been left aside....
2017         // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
2018         // System.arraycopy(
2019         // source,
2020         // startPosition,
2021         // withoutUnicodeBuffer,
2022         // 1,
2023         // withoutUnicodePtr);
2024         // }
2025         // //fill the buffer with the char
2026         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2027         // }
2028         // unicodeAsBackSlash = currentCharacter == '\\';
2029         // }
2030         /*
2031          * Tokenize a method body, assuming that curly brackets are properly balanced.
2032          */
2033         public final void jumpOverMethodBody() {
2034                 this.wasAcr = false;
2035                 int found = 1;
2036                 try {
2037                         while (true) { // loop for jumping over comments
2038                                 // ---------Consume white space and handles startPosition---------
2039                                 boolean isWhiteSpace;
2040                                 do {
2041                                         startPosition = currentPosition;
2042                                         currentCharacter = source[currentPosition++];
2043                                         // if (((currentCharacter = source[currentPosition++]) == '\\')
2044                                         // && (source[currentPosition] == 'u')) {
2045                                         // isWhiteSpace = jumpOverUnicodeWhiteSpace();
2046                                         // } else {
2047                                         if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2048                                                 pushLineSeparator();
2049                                         isWhiteSpace = Character.isWhitespace(currentCharacter);
2050                                         // }
2051                                 } while (isWhiteSpace);
2052                                 // -------consume token until } is found---------
2053                                 switch (currentCharacter) {
2054                                 case '{':
2055                                         found++;
2056                                         break;
2057                                 case '}':
2058                                         found--;
2059                                         if (found == 0)
2060                                                 return;
2061                                         break;
2062                                 case '\'': {
2063                                         boolean test;
2064                                         test = getNextChar('\\');
2065                                         if (test) {
2066                                                 try {
2067                                                         scanDoubleQuotedEscapeCharacter();
2068                                                 } catch (InvalidInputException ex) {
2069                                                 }
2070                                                 ;
2071                                         } else {
2072                                                 // try { // consume next character
2073                                                 unicodeAsBackSlash = false;
2074                                                 currentCharacter = source[currentPosition++];
2075                                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
2076                                                 // && (source[currentPosition] == 'u')) {
2077                                                 // getNextUnicodeChar();
2078                                                 // } else {
2079                                                 if (withoutUnicodePtr != 0) {
2080                                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2081                                                 }
2082                                                 // }
2083                                                 // } catch (InvalidInputException ex) {
2084                                                 // };
2085                                         }
2086                                         getNextChar('\'');
2087                                         break;
2088                                 }
2089                                 case '"':
2090                                         try {
2091                                                 // try { // consume next character
2092                                                 unicodeAsBackSlash = false;
2093                                                 currentCharacter = source[currentPosition++];
2094                                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
2095                                                 // && (source[currentPosition] == 'u')) {
2096                                                 // getNextUnicodeChar();
2097                                                 // } else {
2098                                                 if (withoutUnicodePtr != 0) {
2099                                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2100                                                 }
2101                                                 // }
2102                                                 // } catch (InvalidInputException ex) {
2103                                                 // };
2104                                                 while (currentCharacter != '"') {
2105                                                         if (currentCharacter == '\r') {
2106                                                                 if (source[currentPosition] == '\n')
2107                                                                         currentPosition++;
2108                                                                 break;
2109                                                                 // the string cannot go further that the line
2110                                                         }
2111                                                         if (currentCharacter == '\n') {
2112                                                                 break;
2113                                                                 // the string cannot go further that the line
2114                                                         }
2115                                                         if (currentCharacter == '\\') {
2116                                                                 try {
2117                                                                         scanDoubleQuotedEscapeCharacter();
2118                                                                 } catch (InvalidInputException ex) {
2119                                                                 }
2120                                                                 ;
2121                                                         }
2122                                                         // try { // consume next character
2123                                                         unicodeAsBackSlash = false;
2124                                                         currentCharacter = source[currentPosition++];
2125                                                         // if (((currentCharacter = source[currentPosition++]) == '\\')
2126                                                         // && (source[currentPosition] == 'u')) {
2127                                                         // getNextUnicodeChar();
2128                                                         // } else {
2129                                                         if (withoutUnicodePtr != 0) {
2130                                                                 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2131                                                         }
2132                                                         // }
2133                                                         // } catch (InvalidInputException ex) {
2134                                                         // };
2135                                                 }
2136                                         } catch (IndexOutOfBoundsException e) {
2137                                                 return;
2138                                         }
2139                                         break;
2140                                 case '/': {
2141                                         int test;
2142                                         if ((test = getNextChar('/', '*')) == 0) {
2143                                                 // line comment
2144                                                 try {
2145                                                         // get the next char
2146                                                         currentCharacter = source[currentPosition++];
2147                                                         // if (((currentCharacter = source[currentPosition++]) ==
2148                                                         // '\\')
2149                                                         // && (source[currentPosition] == 'u')) {
2150                                                         // //-------------unicode traitement ------------
2151                                                         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2152                                                         // currentPosition++;
2153                                                         // while (source[currentPosition] == 'u') {
2154                                                         // currentPosition++;
2155                                                         // }
2156                                                         // if ((c1 =
2157                                                         // Character.getNumericValue(source[currentPosition++]))
2158                                                         // > 15
2159                                                         // || c1 < 0
2160                                                         // || (c2 =
2161                                                         // Character.getNumericValue(source[currentPosition++]))
2162                                                         // > 15
2163                                                         // || c2 < 0
2164                                                         // || (c3 =
2165                                                         // Character.getNumericValue(source[currentPosition++]))
2166                                                         // > 15
2167                                                         // || c3 < 0
2168                                                         // || (c4 =
2169                                                         // Character.getNumericValue(source[currentPosition++]))
2170                                                         // > 15
2171                                                         // || c4 < 0) {
2172                                                         // //error don't care of the value
2173                                                         // currentCharacter = 'A';
2174                                                         // } //something different from \n and \r
2175                                                         // else {
2176                                                         // currentCharacter =
2177                                                         // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2178                                                         // }
2179                                                         // }
2180                                                         while (currentCharacter != '\r' && currentCharacter != '\n') {
2181                                                                 // get the next char
2182                                                                 currentCharacter = source[currentPosition++];
2183                                                                 // if (((currentCharacter = source[currentPosition++])
2184                                                                 // == '\\')
2185                                                                 // && (source[currentPosition] == 'u')) {
2186                                                                 // //-------------unicode traitement ------------
2187                                                                 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2188                                                                 // currentPosition++;
2189                                                                 // while (source[currentPosition] == 'u') {
2190                                                                 // currentPosition++;
2191                                                                 // }
2192                                                                 // if ((c1 =
2193                                                                 // Character.getNumericValue(source[currentPosition++]))
2194                                                                 // > 15
2195                                                                 // || c1 < 0
2196                                                                 // || (c2 =
2197                                                                 // Character.getNumericValue(source[currentPosition++]))
2198                                                                 // > 15
2199                                                                 // || c2 < 0
2200                                                                 // || (c3 =
2201                                                                 // Character.getNumericValue(source[currentPosition++]))
2202                                                                 // > 15
2203                                                                 // || c3 < 0
2204                                                                 // || (c4 =
2205                                                                 // Character.getNumericValue(source[currentPosition++]))
2206                                                                 // > 15
2207                                                                 // || c4 < 0) {
2208                                                                 // //error don't care of the value
2209                                                                 // currentCharacter = 'A';
2210                                                                 // } //something different from \n and \r
2211                                                                 // else {
2212                                                                 // currentCharacter =
2213                                                                 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2214                                                                 // }
2215                                                                 // }
2216                                                         }
2217                                                         if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2218                                                                 pushLineSeparator();
2219                                                 } catch (IndexOutOfBoundsException e) {
2220                                                 } // an eof will them be generated
2221                                                 break;
2222                                         }
2223                                         if (test > 0) {
2224                                                 // traditional and annotation comment
2225                                                 boolean star = false;
2226                                                 // try { // consume next character
2227                                                 unicodeAsBackSlash = false;
2228                                                 currentCharacter = source[currentPosition++];
2229                                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
2230                                                 // && (source[currentPosition] == 'u')) {
2231                                                 // getNextUnicodeChar();
2232                                                 // } else {
2233                                                 if (withoutUnicodePtr != 0) {
2234                                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2235                                                 }
2236                                                 // };
2237                                                 // } catch (InvalidInputException ex) {
2238                                                 // };
2239                                                 if (currentCharacter == '*') {
2240                                                         star = true;
2241                                                 }
2242                                                 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2243                                                         pushLineSeparator();
2244                                                 try { // get the next char
2245                                                         currentCharacter = source[currentPosition++];
2246                                                         // if (((currentCharacter = source[currentPosition++]) ==
2247                                                         // '\\')
2248                                                         // && (source[currentPosition] == 'u')) {
2249                                                         // //-------------unicode traitement ------------
2250                                                         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2251                                                         // currentPosition++;
2252                                                         // while (source[currentPosition] == 'u') {
2253                                                         // currentPosition++;
2254                                                         // }
2255                                                         // if ((c1 =
2256                                                         // Character.getNumericValue(source[currentPosition++]))
2257                                                         // > 15
2258                                                         // || c1 < 0
2259                                                         // || (c2 =
2260                                                         // Character.getNumericValue(source[currentPosition++]))
2261                                                         // > 15
2262                                                         // || c2 < 0
2263                                                         // || (c3 =
2264                                                         // Character.getNumericValue(source[currentPosition++]))
2265                                                         // > 15
2266                                                         // || c3 < 0
2267                                                         // || (c4 =
2268                                                         // Character.getNumericValue(source[currentPosition++]))
2269                                                         // > 15
2270                                                         // || c4 < 0) {
2271                                                         // //error don't care of the value
2272                                                         // currentCharacter = 'A';
2273                                                         // } //something different from * and /
2274                                                         // else {
2275                                                         // currentCharacter =
2276                                                         // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2277                                                         // }
2278                                                         // }
2279                                                         // loop until end of comment */
2280                                                         while ((currentCharacter != '/') || (!star)) {
2281                                                                 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2282                                                                         pushLineSeparator();
2283                                                                 star = currentCharacter == '*';
2284                                                                 // get next char
2285                                                                 currentCharacter = source[currentPosition++];
2286                                                                 // if (((currentCharacter = source[currentPosition++])
2287                                                                 // == '\\')
2288                                                                 // && (source[currentPosition] == 'u')) {
2289                                                                 // //-------------unicode traitement ------------
2290                                                                 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2291                                                                 // currentPosition++;
2292                                                                 // while (source[currentPosition] == 'u') {
2293                                                                 // currentPosition++;
2294                                                                 // }
2295                                                                 // if ((c1 =
2296                                                                 // Character.getNumericValue(source[currentPosition++]))
2297                                                                 // > 15
2298                                                                 // || c1 < 0
2299                                                                 // || (c2 =
2300                                                                 // Character.getNumericValue(source[currentPosition++]))
2301                                                                 // > 15
2302                                                                 // || c2 < 0
2303                                                                 // || (c3 =
2304                                                                 // Character.getNumericValue(source[currentPosition++]))
2305                                                                 // > 15
2306                                                                 // || c3 < 0
2307                                                                 // || (c4 =
2308                                                                 // Character.getNumericValue(source[currentPosition++]))
2309                                                                 // > 15
2310                                                                 // || c4 < 0) {
2311                                                                 // //error don't care of the value
2312                                                                 // currentCharacter = 'A';
2313                                                                 // } //something different from * and /
2314                                                                 // else {
2315                                                                 // currentCharacter =
2316                                                                 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2317                                                                 // }
2318                                                                 // }
2319                                                         }
2320                                                 } catch (IndexOutOfBoundsException e) {
2321                                                         return;
2322                                                 }
2323                                                 break;
2324                                         }
2325                                         break;
2326                                 }
2327                                 default:
2328                                         if (isPHPIdentOrVarStart(currentCharacter)) {
2329                                                 try {
2330                                                         scanIdentifierOrKeyword((currentCharacter == '$'));
2331                                                 } catch (InvalidInputException ex) {
2332                                                 }
2333                                                 ;
2334                                                 break;
2335                                         }
2336                                         if (ObviousIdentCharNatures[currentCharacter] == C_DIGIT) {
2337                                                 // if (Character.isDigit(currentCharacter)) {
2338                                                 try {
2339                                                         scanNumber(false);
2340                                                 } catch (InvalidInputException ex) {
2341                                                 }
2342                                                 ;
2343                                                 break;
2344                                         }
2345                                 }
2346                         }
2347                         // -----------------end switch while try--------------------
2348                 } catch (IndexOutOfBoundsException e) {
2349                 } catch (InvalidInputException e) {
2350                 }
2351                 return;
2352         }
2353
2354         // public final boolean jumpOverUnicodeWhiteSpace()
2355         // throws InvalidInputException {
2356         // //BOOLEAN
2357         // //handle the case of unicode. Jump over the next whiteSpace
2358         // //making startPosition pointing on the next available char
2359         // //On false, the currentCharacter is filled up with a potential
2360         // //correct char
2361         //
2362         // try {
2363         // this.wasAcr = false;
2364         // int c1, c2, c3, c4;
2365         // int unicodeSize = 6;
2366         // currentPosition++;
2367         // while (source[currentPosition] == 'u') {
2368         // currentPosition++;
2369         // unicodeSize++;
2370         // }
2371         //
2372         // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2373         // || c1 < 0)
2374         // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2375         // || c2 < 0)
2376         // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2377         // || c3 < 0)
2378         // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2379         // || c4 < 0)) {
2380         // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2381         // }
2382         //
2383         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2384         // if (recordLineSeparator
2385         // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2386         // pushLineSeparator();
2387         // if (Character.isWhitespace(currentCharacter))
2388         // return true;
2389         //
2390         // //buffer the new char which is not a white space
2391         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2392         // //withoutUnicodePtr == 1 is true here
2393         // return false;
2394         // } catch (IndexOutOfBoundsException e) {
2395         // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2396         // }
2397         // }
2398         public final int[] getLineEnds() {
2399                 // return a bounded copy of this.lineEnds
2400                 int[] copy;
2401                 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0, linePtr + 1);
2402                 return copy;
2403         }
2404
2405         public char[] getSource() {
2406                 return this.source;
2407         }
2408
2409         public static boolean isIdentifierOrKeyword(int token) {
2410                 return (token == TokenNameIdentifier) || (token > TokenNameKEYWORD);
2411         }
2412
2413         final char[] optimizedCurrentTokenSource1() {
2414                 // return always the same char[] build only once
2415                 // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2416                 char charOne = source[startPosition];
2417                 switch (charOne) {
2418                 case 'a':
2419                         return charArray_a;
2420                 case 'b':
2421                         return charArray_b;
2422                 case 'c':
2423                         return charArray_c;
2424                 case 'd':
2425                         return charArray_d;
2426                 case 'e':
2427                         return charArray_e;
2428                 case 'f':
2429                         return charArray_f;
2430                 case 'g':
2431                         return charArray_g;
2432                 case 'h':
2433                         return charArray_h;
2434                 case 'i':
2435                         return charArray_i;
2436                 case 'j':
2437                         return charArray_j;
2438                 case 'k':
2439                         return charArray_k;
2440                 case 'l':
2441                         return charArray_l;
2442                 case 'm':
2443                         return charArray_m;
2444                 case 'n':
2445                         return charArray_n;
2446                 case 'o':
2447                         return charArray_o;
2448                 case 'p':
2449                         return charArray_p;
2450                 case 'q':
2451                         return charArray_q;
2452                 case 'r':
2453                         return charArray_r;
2454                 case 's':
2455                         return charArray_s;
2456                 case 't':
2457                         return charArray_t;
2458                 case 'u':
2459                         return charArray_u;
2460                 case 'v':
2461                         return charArray_v;
2462                 case 'w':
2463                         return charArray_w;
2464                 case 'x':
2465                         return charArray_x;
2466                 case 'y':
2467                         return charArray_y;
2468                 case 'z':
2469                         return charArray_z;
2470                 default:
2471                         return new char[] { charOne };
2472                 }
2473         }
2474
2475         final char[] optimizedCurrentTokenSource2() {
2476                 char c0, c1;
2477                 c0 = source[startPosition];
2478                 c1 = source[startPosition + 1];
2479                 if (c0 == '$') {
2480                         // return always the same char[] build only once
2481                         // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2482                         switch (c1) {
2483                         case 'a':
2484                                 return charArray_va;
2485                         case 'b':
2486                                 return charArray_vb;
2487                         case 'c':
2488                                 return charArray_vc;
2489                         case 'd':
2490                                 return charArray_vd;
2491                         case 'e':
2492                                 return charArray_ve;
2493                         case 'f':
2494                                 return charArray_vf;
2495                         case 'g':
2496                                 return charArray_vg;
2497                         case 'h':
2498                                 return charArray_vh;
2499                         case 'i':
2500                                 return charArray_vi;
2501                         case 'j':
2502                                 return charArray_vj;
2503                         case 'k':
2504                                 return charArray_vk;
2505                         case 'l':
2506                                 return charArray_vl;
2507                         case 'm':
2508                                 return charArray_vm;
2509                         case 'n':
2510                                 return charArray_vn;
2511                         case 'o':
2512                                 return charArray_vo;
2513                         case 'p':
2514                                 return charArray_vp;
2515                         case 'q':
2516                                 return charArray_vq;
2517                         case 'r':
2518                                 return charArray_vr;
2519                         case 's':
2520                                 return charArray_vs;
2521                         case 't':
2522                                 return charArray_vt;
2523                         case 'u':
2524                                 return charArray_vu;
2525                         case 'v':
2526                                 return charArray_vv;
2527                         case 'w':
2528                                 return charArray_vw;
2529                         case 'x':
2530                                 return charArray_vx;
2531                         case 'y':
2532                                 return charArray_vy;
2533                         case 'z':
2534                                 return charArray_vz;
2535                         }
2536                 }
2537                 // try to return the same char[] build only once
2538                 int hash = ((c0 << 6) + c1) % TableSize;
2539                 char[][] table = charArray_length[0][hash];
2540                 int i = newEntry2;
2541                 while (++i < InternalTableSize) {
2542                         char[] charArray = table[i];
2543                         if ((c0 == charArray[0]) && (c1 == charArray[1]))
2544                                 return charArray;
2545                 }
2546                 // ---------other side---------
2547                 i = -1;
2548                 int max = newEntry2;
2549                 while (++i <= max) {
2550                         char[] charArray = table[i];
2551                         if ((c0 == charArray[0]) && (c1 == charArray[1]))
2552                                 return charArray;
2553                 }
2554                 // --------add the entry-------
2555                 if (++max >= InternalTableSize)
2556                         max = 0;
2557                 char[] r;
2558                 table[max] = (r = new char[] { c0, c1 });
2559                 newEntry2 = max;
2560                 return r;
2561         }
2562
2563         final char[] optimizedCurrentTokenSource3() {
2564                 // try to return the same char[] build only once
2565                 char c0, c1, c2;
2566                 int hash = (((c0 = source[startPosition]) << 12) + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2567                                 % TableSize;
2568                 char[][] table = charArray_length[1][hash];
2569                 int i = newEntry3;
2570                 while (++i < InternalTableSize) {
2571                         char[] charArray = table[i];
2572                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2573                                 return charArray;
2574                 }
2575                 // ---------other side---------
2576                 i = -1;
2577                 int max = newEntry3;
2578                 while (++i <= max) {
2579                         char[] charArray = table[i];
2580                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2581                                 return charArray;
2582                 }
2583                 // --------add the entry-------
2584                 if (++max >= InternalTableSize)
2585                         max = 0;
2586                 char[] r;
2587                 table[max] = (r = new char[] { c0, c1, c2 });
2588                 newEntry3 = max;
2589                 return r;
2590         }
2591
2592         final char[] optimizedCurrentTokenSource4() {
2593                 // try to return the same char[] build only once
2594                 char c0, c1, c2, c3;
2595                 long hash = ((((long) (c0 = source[startPosition])) << 18) + ((c1 = source[startPosition + 1]) << 12)
2596                                 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2597                                 % TableSize;
2598                 char[][] table = charArray_length[2][(int) hash];
2599                 int i = newEntry4;
2600                 while (++i < InternalTableSize) {
2601                         char[] charArray = table[i];
2602                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2603                                 return charArray;
2604                 }
2605                 // ---------other side---------
2606                 i = -1;
2607                 int max = newEntry4;
2608                 while (++i <= max) {
2609                         char[] charArray = table[i];
2610                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2611                                 return charArray;
2612                 }
2613                 // --------add the entry-------
2614                 if (++max >= InternalTableSize)
2615                         max = 0;
2616                 char[] r;
2617                 table[max] = (r = new char[] { c0, c1, c2, c3 });
2618                 newEntry4 = max;
2619                 return r;
2620         }
2621
2622         final char[] optimizedCurrentTokenSource5() {
2623                 // try to return the same char[] build only once
2624                 char c0, c1, c2, c3, c4;
2625                 long hash = ((((long) (c0 = source[startPosition])) << 24) + (((long) (c1 = source[startPosition + 1])) << 18)
2626                                 + ((c2 = source[startPosition + 2]) << 12) + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2627                                 % TableSize;
2628                 char[][] table = charArray_length[3][(int) hash];
2629                 int i = newEntry5;
2630                 while (++i < InternalTableSize) {
2631                         char[] charArray = table[i];
2632                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2633                                 return charArray;
2634                 }
2635                 // ---------other side---------
2636                 i = -1;
2637                 int max = newEntry5;
2638                 while (++i <= max) {
2639                         char[] charArray = table[i];
2640                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2641                                 return charArray;
2642                 }
2643                 // --------add the entry-------
2644                 if (++max >= InternalTableSize)
2645                         max = 0;
2646                 char[] r;
2647                 table[max] = (r = new char[] { c0, c1, c2, c3, c4 });
2648                 newEntry5 = max;
2649                 return r;
2650         }
2651
2652         final char[] optimizedCurrentTokenSource6() {
2653                 // try to return the same char[] build only once
2654                 char c0, c1, c2, c3, c4, c5;
2655                 long hash = ((((long) (c0 = source[startPosition])) << 32) + (((long) (c1 = source[startPosition + 1])) << 24)
2656                                 + (((long) (c2 = source[startPosition + 2])) << 18) + ((c3 = source[startPosition + 3]) << 12)
2657                                 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2658                                 % TableSize;
2659                 char[][] table = charArray_length[4][(int) hash];
2660                 int i = newEntry6;
2661                 while (++i < InternalTableSize) {
2662                         char[] charArray = table[i];
2663                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2664                                         && (c5 == charArray[5]))
2665                                 return charArray;
2666                 }
2667                 // ---------other side---------
2668                 i = -1;
2669                 int max = newEntry6;
2670                 while (++i <= max) {
2671                         char[] charArray = table[i];
2672                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2673                                         && (c5 == charArray[5]))
2674                                 return charArray;
2675                 }
2676                 // --------add the entry-------
2677                 if (++max >= InternalTableSize)
2678                         max = 0;
2679                 char[] r;
2680                 table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 });
2681                 newEntry6 = max;
2682                 return r;
2683         }
2684
2685         public final void pushLineSeparator() throws InvalidInputException {
2686                 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2687                 final int INCREMENT = 250;
2688                 if (this.checkNonExternalizedStringLiterals) {
2689                         // reinitialize the current line for non externalize strings purpose
2690                         currentLine = null;
2691                 }
2692                 // currentCharacter is at position currentPosition-1
2693                 // cr 000D
2694                 if (currentCharacter == '\r') {
2695                         int separatorPos = currentPosition - 1;
2696                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2697                                 return;
2698                         // System.out.println("CR-" + separatorPos);
2699                         try {
2700                                 lineEnds[++linePtr] = separatorPos;
2701                         } catch (IndexOutOfBoundsException e) {
2702                                 // linePtr value is correct
2703                                 int oldLength = lineEnds.length;
2704                                 int[] old = lineEnds;
2705                                 lineEnds = new int[oldLength + INCREMENT];
2706                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2707                                 lineEnds[linePtr] = separatorPos;
2708                         }
2709                         // look-ahead for merged cr+lf
2710                         try {
2711                                 if (source[currentPosition] == '\n') {
2712                                         // System.out.println("look-ahead LF-" + currentPosition);
2713                                         lineEnds[linePtr] = currentPosition;
2714                                         currentPosition++;
2715                                         wasAcr = false;
2716                                 } else {
2717                                         wasAcr = true;
2718                                 }
2719                         } catch (IndexOutOfBoundsException e) {
2720                                 wasAcr = true;
2721                         }
2722                 } else {
2723                         // lf 000A
2724                         if (currentCharacter == '\n') {
2725                                 // must merge eventual cr followed by lf
2726                                 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2727                                         // System.out.println("merge LF-" + (currentPosition - 1));
2728                                         lineEnds[linePtr] = currentPosition - 1;
2729                                 } else {
2730                                         int separatorPos = currentPosition - 1;
2731                                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2732                                                 return;
2733                                         // System.out.println("LF-" + separatorPos);
2734                                         try {
2735                                                 lineEnds[++linePtr] = separatorPos;
2736                                         } catch (IndexOutOfBoundsException e) {
2737                                                 // linePtr value is correct
2738                                                 int oldLength = lineEnds.length;
2739                                                 int[] old = lineEnds;
2740                                                 lineEnds = new int[oldLength + INCREMENT];
2741                                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2742                                                 lineEnds[linePtr] = separatorPos;
2743                                         }
2744                                 }
2745                                 wasAcr = false;
2746                         }
2747                 }
2748         }
2749
2750         public final void pushUnicodeLineSeparator() {
2751                 // isUnicode means that the \r or \n has been read as a unicode character
2752                 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2753                 final int INCREMENT = 250;
2754                 // currentCharacter is at position currentPosition-1
2755                 if (this.checkNonExternalizedStringLiterals) {
2756                         // reinitialize the current line for non externalize strings purpose
2757                         currentLine = null;
2758                 }
2759                 // cr 000D
2760                 if (currentCharacter == '\r') {
2761                         int separatorPos = currentPosition - 6;
2762                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2763                                 return;
2764                         // System.out.println("CR-" + separatorPos);
2765                         try {
2766                                 lineEnds[++linePtr] = separatorPos;
2767                         } catch (IndexOutOfBoundsException e) {
2768                                 // linePtr value is correct
2769                                 int oldLength = lineEnds.length;
2770                                 int[] old = lineEnds;
2771                                 lineEnds = new int[oldLength + INCREMENT];
2772                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2773                                 lineEnds[linePtr] = separatorPos;
2774                         }
2775                         // look-ahead for merged cr+lf
2776                         if (source[currentPosition] == '\n') {
2777                                 // System.out.println("look-ahead LF-" + currentPosition);
2778                                 lineEnds[linePtr] = currentPosition;
2779                                 currentPosition++;
2780                                 wasAcr = false;
2781                         } else {
2782                                 wasAcr = true;
2783                         }
2784                 } else {
2785                         // lf 000A
2786                         if (currentCharacter == '\n') {
2787                                 // must merge eventual cr followed by lf
2788                                 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2789                                         // System.out.println("merge LF-" + (currentPosition - 1));
2790                                         lineEnds[linePtr] = currentPosition - 6;
2791                                 } else {
2792                                         int separatorPos = currentPosition - 6;
2793                                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2794                                                 return;
2795                                         // System.out.println("LF-" + separatorPos);
2796                                         try {
2797                                                 lineEnds[++linePtr] = separatorPos;
2798                                         } catch (IndexOutOfBoundsException e) {
2799                                                 // linePtr value is correct
2800                                                 int oldLength = lineEnds.length;
2801                                                 int[] old = lineEnds;
2802                                                 lineEnds = new int[oldLength + INCREMENT];
2803                                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2804                                                 lineEnds[linePtr] = separatorPos;
2805                                         }
2806                                 }
2807                                 wasAcr = false;
2808                         }
2809                 }
2810         }
2811
2812         public void recordComment(int token) {
2813                 // compute position
2814                 int stopPosition = this.currentPosition;
2815                 switch (token) {
2816                 case TokenNameCOMMENT_LINE:
2817                         stopPosition = -this.lastCommentLinePosition;
2818                         break;
2819                 case TokenNameCOMMENT_BLOCK:
2820                         stopPosition = -this.currentPosition;
2821                         break;
2822                 }
2823
2824                 // a new comment is recorded
2825                 int length = this.commentStops.length;
2826                 if (++this.commentPtr >= length) {
2827                         System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length);
2828                         // grows the positions buffers too
2829                         System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length);
2830                 }
2831                 this.commentStops[this.commentPtr] = stopPosition;
2832                 this.commentStarts[this.commentPtr] = this.startPosition;
2833         }
2834
2835         // public final void recordComment(boolean isJavadoc) {
2836         // // a new annotation comment is recorded
2837         // try {
2838         // commentStops[++commentPtr] = isJavadoc
2839         // ? currentPosition
2840         // : -currentPosition;
2841         // } catch (IndexOutOfBoundsException e) {
2842         // int oldStackLength = commentStops.length;
2843         // int[] oldStack = commentStops;
2844         // commentStops = new int[oldStackLength + 30];
2845         // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
2846         // commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition;
2847         // //grows the positions buffers too
2848         // int[] old = commentStarts;
2849         // commentStarts = new int[oldStackLength + 30];
2850         // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
2851         // }
2852         // //the buffer is of a correct size here
2853         // commentStarts[commentPtr] = startPosition;
2854         // }
2855         public void resetTo(int begin, int end) {
2856                 // reset the scanner to a given position where it may rescan again
2857                 diet = false;
2858                 initialPosition = startPosition = currentPosition = begin;
2859                 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
2860                 commentPtr = -1; // reset comment stack
2861         }
2862
2863         public final void scanSingleQuotedEscapeCharacter() throws InvalidInputException {
2864                 // the string with "\\u" is a legal string of two chars \ and u
2865                 // thus we use a direct access to the source (for regular cases).
2866                 // if (unicodeAsBackSlash) {
2867                 // // consume next character
2868                 // unicodeAsBackSlash = false;
2869                 // if (((currentCharacter = source[currentPosition++]) == '\\')
2870                 // && (source[currentPosition] == 'u')) {
2871                 // getNextUnicodeChar();
2872                 // } else {
2873                 // if (withoutUnicodePtr != 0) {
2874                 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2875                 // }
2876                 // }
2877                 // } else
2878                 currentCharacter = source[currentPosition++];
2879                 switch (currentCharacter) {
2880                 case '\'':
2881                         currentCharacter = '\'';
2882                         break;
2883                 case '\\':
2884                         currentCharacter = '\\';
2885                         break;
2886                 default:
2887                         currentCharacter = '\\';
2888                         currentPosition--;
2889                 }
2890         }
2891
2892         public final void scanDoubleQuotedEscapeCharacter() throws InvalidInputException {
2893                 currentCharacter = source[currentPosition++];
2894                 switch (currentCharacter) {
2895                 // case 'b' :
2896                 // currentCharacter = '\b';
2897                 // break;
2898                 case 't':
2899                         currentCharacter = '\t';
2900                         break;
2901                 case 'n':
2902                         currentCharacter = '\n';
2903                         break;
2904                 // case 'f' :
2905                 // currentCharacter = '\f';
2906                 // break;
2907                 case 'r':
2908                         currentCharacter = '\r';
2909                         break;
2910                 case '\"':
2911                         currentCharacter = '\"';
2912                         break;
2913                 case '\'':
2914                         currentCharacter = '\'';
2915                         break;
2916                 case '\\':
2917                         currentCharacter = '\\';
2918                         break;
2919                 case '$':
2920                         currentCharacter = '$';
2921                         break;
2922                 default:
2923                         // -----------octal escape--------------
2924                         // OctalDigit
2925                         // OctalDigit OctalDigit
2926                         // ZeroToThree OctalDigit OctalDigit
2927                         int number = Character.getNumericValue(currentCharacter);
2928                         if (number >= 0 && number <= 7) {
2929                                 boolean zeroToThreeNot = number > 3;
2930                                 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2931                                         int digit = Character.getNumericValue(currentCharacter);
2932                                         if (digit >= 0 && digit <= 7) {
2933                                                 number = (number * 8) + digit;
2934                                                 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2935                                                         if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
2936                                                                 // Digit --> ignore last character
2937                                                                 currentPosition--;
2938                                                         } else {
2939                                                                 digit = Character.getNumericValue(currentCharacter);
2940                                                                 if (digit >= 0 && digit <= 7) {
2941                                                                         // has read \ZeroToThree OctalDigit OctalDigit
2942                                                                         number = (number * 8) + digit;
2943                                                                 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
2944                                                                         // --> ignore last character
2945                                                                         currentPosition--;
2946                                                                 }
2947                                                         }
2948                                                 } else { // has read \OctalDigit NonDigit--> ignore last
2949                                                         // character
2950                                                         currentPosition--;
2951                                                 }
2952                                         } else { // has read \OctalDigit NonOctalDigit--> ignore last
2953                                                 // character
2954                                                 currentPosition--;
2955                                         }
2956                                 } else { // has read \OctalDigit --> ignore last character
2957                                         currentPosition--;
2958                                 }
2959                                 if (number > 255)
2960                                         throw new InvalidInputException(INVALID_ESCAPE);
2961                                 currentCharacter = (char) number;
2962                         }
2963                 // else
2964                 // throw new InvalidInputException(INVALID_ESCAPE);
2965                 }
2966         }
2967
2968         // public int scanIdentifierOrKeyword() throws InvalidInputException {
2969         // return scanIdentifierOrKeyword( false );
2970         // }
2971         public int scanIdentifierOrKeyword(boolean isVariable) throws InvalidInputException {
2972                 // test keywords
2973                 // first dispatch on the first char.
2974                 // then the length. If there are several
2975                 // keywors with the same length AND the same first char, then do another
2976                 // disptach on the second char :-)...cool....but fast !
2977                 useAssertAsAnIndentifier = false;
2978                 while (getNextCharAsJavaIdentifierPart()) {
2979                 }
2980                 ;
2981                 if (isVariable) {
2982                         // if (new String(getCurrentTokenSource()).equals("$this")) {
2983                         // return TokenNamethis;
2984                         // }
2985                         return TokenNameVariable;
2986                 }
2987                 int index, length;
2988                 char[] data;
2989                 char firstLetter;
2990                 // if (withoutUnicodePtr == 0)
2991                 // quick test on length == 1 but not on length > 12 while most identifier
2992                 // have a length which is <= 12...but there are lots of identifier with
2993                 // only one char....
2994                 // {
2995                 if ((length = currentPosition - startPosition) == 1)
2996                         return TokenNameIdentifier;
2997                 // data = source;
2998                 data = new char[length];
2999                 index = startPosition;
3000                 for (int i = 0; i < length; i++) {
3001                         data[i] = Character.toLowerCase(source[index + i]);
3002                 }
3003                 index = 0;
3004                 // } else {
3005                 // if ((length = withoutUnicodePtr) == 1)
3006                 // return TokenNameIdentifier;
3007                 // // data = withoutUnicodeBuffer;
3008                 // data = new char[withoutUnicodeBuffer.length];
3009                 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
3010                 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
3011                 // }
3012                 // index = 1;
3013                 // }
3014                 firstLetter = data[index];
3015                 switch (firstLetter) {
3016                 case '_':
3017                         switch (length) {
3018                         case 8:
3019                                 // __FILE__
3020                                 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'i') && (data[++index] == 'l')
3021                                                 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3022                                         return TokenNameFILE;
3023                                 index = 0; // __LINE__
3024                                 if ((data[++index] == '_') && (data[++index] == 'l') && (data[++index] == 'i') && (data[++index] == 'n')
3025                                                 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3026                                         return TokenNameLINE;
3027                                 break;
3028                         case 9:
3029                                 // __CLASS__
3030                                 if ((data[++index] == '_') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3031                                                 && (data[++index] == 's') && (data[++index] == 's') && (data[++index] == '_') && (data[++index] == '_'))
3032                                         return TokenNameCLASS_C;
3033                                 break;
3034                         case 11:
3035                                 // __METHOD__
3036                                 if ((data[++index] == '_') && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 't')
3037                                                 && (data[++index] == 'h') && (data[++index] == 'o') && (data[++index] == 'd') && (data[++index] == '_')
3038                                                 && (data[++index] == '_'))
3039                                         return TokenNameMETHOD_C;
3040                                 break;
3041                         case 12:
3042                                 // __FUNCTION__
3043                                 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'u') && (data[++index] == 'n')
3044                                                 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'o')
3045                                                 && (data[++index] == 'n') && (data[++index] == '_') && (data[++index] == '_'))
3046                                         return TokenNameFUNC_C;
3047                                 break;
3048                         }
3049                         return TokenNameIdentifier;
3050                 case 'a':
3051                         // as and array abstract
3052                         switch (length) {
3053                         case 2:
3054                                 // as
3055                                 if ((data[++index] == 's')) {
3056                                         return TokenNameas;
3057                                 } else {
3058                                         return TokenNameIdentifier;
3059                                 }
3060                         case 3:
3061                                 // and
3062                                 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3063                                         return TokenNameand;
3064                                 } else {
3065                                         return TokenNameIdentifier;
3066                                 }
3067                         case 5:
3068                                 // array
3069                                 if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y'))
3070                                         return TokenNamearray;
3071                                 else
3072                                         return TokenNameIdentifier;
3073                         case 8:
3074                                 if ((data[++index] == 'b') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'r')
3075                                                 && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 't'))
3076                                         return TokenNameabstract;
3077                                 else
3078                                         return TokenNameIdentifier;
3079                         default:
3080                                 return TokenNameIdentifier;
3081                         }
3082                 case 'b':
3083                         // break
3084                         switch (length) {
3085                         case 5:
3086                                 if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k'))
3087                                         return TokenNamebreak;
3088                                 else
3089                                         return TokenNameIdentifier;
3090                         default:
3091                                 return TokenNameIdentifier;
3092                         }
3093                 case 'c':
3094                         // case catch class clone const continue
3095                         switch (length) {
3096                         case 4:
3097                                 if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e'))
3098                                         return TokenNamecase;
3099                                 else
3100                                         return TokenNameIdentifier;
3101                         case 5:
3102                                 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3103                                         return TokenNamecatch;
3104                                 index = 0;
3105                                 if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's'))
3106                                         return TokenNameclass;
3107                                 index = 0;
3108                                 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 'e'))
3109                                         return TokenNameclone;
3110                                 index = 0;
3111                                 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't'))
3112                                         return TokenNameconst;
3113                                 else
3114                                         return TokenNameIdentifier;
3115                         case 8:
3116                                 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'i')
3117                                                 && (data[++index] == 'n') && (data[++index] == 'u') && (data[++index] == 'e'))
3118                                         return TokenNamecontinue;
3119                                 else
3120                                         return TokenNameIdentifier;
3121                         default:
3122                                 return TokenNameIdentifier;
3123                         }
3124                 case 'd':
3125                         // declare default do die
3126                         // TODO delete define ==> no keyword !
3127                         switch (length) {
3128                         case 2:
3129                                 if ((data[++index] == 'o'))
3130                                         return TokenNamedo;
3131                                 else
3132                                         return TokenNameIdentifier;
3133                         // case 6 :
3134                         // if ((data[++index] == 'e')
3135                         // && (data[++index] == 'f')
3136                         // && (data[++index] == 'i')
3137                         // && (data[++index] == 'n')
3138                         // && (data[++index] == 'e'))
3139                         // return TokenNamedefine;
3140                         // else
3141                         // return TokenNameIdentifier;
3142                         case 7:
3143                                 if ((data[++index] == 'e') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3144                                                 && (data[++index] == 'r') && (data[++index] == 'e'))
3145                                         return TokenNamedeclare;
3146                                 index = 0;
3147                                 if ((data[++index] == 'e') && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'u')
3148                                                 && (data[++index] == 'l') && (data[++index] == 't'))
3149                                         return TokenNamedefault;
3150                                 else
3151                                         return TokenNameIdentifier;
3152                         default:
3153                                 return TokenNameIdentifier;
3154                         }
3155                 case 'e':
3156                         // echo else exit elseif extends eval
3157                         switch (length) {
3158                         case 4:
3159                                 if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o'))
3160                                         return TokenNameecho;
3161                                 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e'))
3162                                         return TokenNameelse;
3163                                 else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't'))
3164                                         return TokenNameexit;
3165                                 else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l'))
3166                                         return TokenNameeval;
3167                                 else
3168                                         return TokenNameIdentifier;
3169                         case 5:
3170                                 // endif empty
3171                                 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f'))
3172                                         return TokenNameendif;
3173                                 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 't') && (data[++index] == 'y'))
3174                                         return TokenNameempty;
3175                                 else
3176                                         return TokenNameIdentifier;
3177                         case 6:
3178                                 // endfor
3179                                 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o')
3180                                                 && (data[++index] == 'r'))
3181                                         return TokenNameendfor;
3182                                 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 'i')
3183                                                 && (data[++index] == 'f'))
3184                                         return TokenNameelseif;
3185                                 else
3186                                         return TokenNameIdentifier;
3187                         case 7:
3188                                 if ((data[++index] == 'x') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'n')
3189                                                 && (data[++index] == 'd') && (data[++index] == 's'))
3190                                         return TokenNameextends;
3191                                 else
3192                                         return TokenNameIdentifier;
3193                         case 8:
3194                                 // endwhile
3195                                 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'w') && (data[++index] == 'h')
3196                                                 && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3197                                         return TokenNameendwhile;
3198                                 else
3199                                         return TokenNameIdentifier;
3200                         case 9:
3201                                 // endswitch
3202                                 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 's') && (data[++index] == 'w')
3203                                                 && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3204                                         return TokenNameendswitch;
3205                                 else
3206                                         return TokenNameIdentifier;
3207                         case 10:
3208                                 // enddeclare
3209                                 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'd') && (data[++index] == 'e')
3210                                                 && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 'r')
3211                                                 && (data[++index] == 'e'))
3212                                         return TokenNameenddeclare;
3213                                 index = 0;
3214                                 if ((data[++index] == 'n') // endforeach
3215                                                 && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r')
3216                                                 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'h'))
3217                                         return TokenNameendforeach;
3218                                 else
3219                                         return TokenNameIdentifier;
3220                         default:
3221                                 return TokenNameIdentifier;
3222                         }
3223                 case 'f':
3224                         // for false final function
3225                         switch (length) {
3226                         case 3:
3227                                 if ((data[++index] == 'o') && (data[++index] == 'r'))
3228                                         return TokenNamefor;
3229                                 else
3230                                         return TokenNameIdentifier;
3231                         case 5:
3232                                 // if ((data[++index] == 'a') && (data[++index] == 'l')
3233                                 // && (data[++index] == 's') && (data[++index] == 'e'))
3234                                 // return TokenNamefalse;
3235                                 if ((data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 'a') && (data[++index] == 'l'))
3236                                         return TokenNamefinal;
3237                                 else
3238                                         return TokenNameIdentifier;
3239                         case 7:
3240                                 // foreach
3241                                 if ((data[++index] == 'o') && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a')
3242                                                 && (data[++index] == 'c') && (data[++index] == 'h'))
3243                                         return TokenNameforeach;
3244                                 else
3245                                         return TokenNameIdentifier;
3246                         case 8:
3247                                 // function
3248                                 if ((data[++index] == 'u') && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 't')
3249                                                 && (data[++index] == 'i') && (data[++index] == 'o') && (data[++index] == 'n'))
3250                                         return TokenNamefunction;
3251                                 else
3252                                         return TokenNameIdentifier;
3253                         default:
3254                                 return TokenNameIdentifier;
3255                         }
3256                 case 'g':
3257                         // global
3258                         if (length == 6) {
3259                                 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'b') && (data[++index] == 'a')
3260                                                 && (data[++index] == 'l')) {
3261                                         return TokenNameglobal;
3262                                 }
3263                         }
3264                         return TokenNameIdentifier;
3265                 case 'i':
3266                         // if int isset include include_once instanceof interface implements
3267                         switch (length) {
3268                         case 2:
3269                                 if (data[++index] == 'f')
3270                                         return TokenNameif;
3271                                 else
3272                                         return TokenNameIdentifier;
3273                         // case 3 :
3274                         // if ((data[++index] == 'n') && (data[++index] == 't'))
3275                         // return TokenNameint;
3276                         // else
3277                         // return TokenNameIdentifier;
3278                         case 5:
3279                                 if ((data[++index] == 's') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3280                                         return TokenNameisset;
3281                                 else
3282                                         return TokenNameIdentifier;
3283                         case 7:
3284                                 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3285                                                 && (data[++index] == 'd') && (data[++index] == 'e'))
3286                                         return TokenNameinclude;
3287                                 else
3288                                         return TokenNameIdentifier;
3289                         case 9:
3290                                 // interface
3291                                 if ((data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'r')
3292                                                 && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'e'))
3293                                         return TokenNameinterface;
3294                                 else
3295                                         return TokenNameIdentifier;
3296                         case 10:
3297                                 // instanceof
3298                                 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'a')
3299                                                 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e') && (data[++index] == 'o')
3300                                                 && (data[++index] == 'f'))
3301                                         return TokenNameinstanceof;
3302                                 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 'l') && (data[++index] == 'e')
3303                                                 && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 'n') && (data[++index] == 't')
3304                                                 && (data[++index] == 's'))
3305                                         return TokenNameimplements;
3306                                 else
3307                                         return TokenNameIdentifier;
3308                         case 12:
3309                                 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3310                                                 && (data[++index] == 'd') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3311                                                 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e'))
3312                                         return TokenNameinclude_once;
3313                                 else
3314                                         return TokenNameIdentifier;
3315                         default:
3316                                 return TokenNameIdentifier;
3317                         }
3318                 case 'l':
3319                         // list
3320                         if (length == 4) {
3321                                 if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) {
3322                                         return TokenNamelist;
3323                                 }
3324                         }
3325                         return TokenNameIdentifier;
3326                 case 'n':
3327                         // new null
3328                         switch (length) {
3329                         case 3:
3330                                 if ((data[++index] == 'e') && (data[++index] == 'w'))
3331                                         return TokenNamenew;
3332                                 else
3333                                         return TokenNameIdentifier;
3334                         // case 4 :
3335                         // if ((data[++index] == 'u') && (data[++index] == 'l')
3336                         // && (data[++index] == 'l'))
3337                         // return TokenNamenull;
3338                         // else
3339                         // return TokenNameIdentifier;
3340                         default:
3341                                 return TokenNameIdentifier;
3342                         }
3343                 case 'o':
3344                         // or old_function
3345                         if (length == 2) {
3346                                 if (data[++index] == 'r') {
3347                                         return TokenNameor;
3348                                 }
3349                         }
3350                         // if (length == 12) {
3351                         // if ((data[++index] == 'l')
3352                         // && (data[++index] == 'd')
3353                         // && (data[++index] == '_')
3354                         // && (data[++index] == 'f')
3355                         // && (data[++index] == 'u')
3356                         // && (data[++index] == 'n')
3357                         // && (data[++index] == 'c')
3358                         // && (data[++index] == 't')
3359                         // && (data[++index] == 'i')
3360                         // && (data[++index] == 'o')
3361                         // && (data[++index] == 'n')) {
3362                         // return TokenNameold_function;
3363                         // }
3364                         // }
3365                         return TokenNameIdentifier;
3366                 case 'p':
3367                         // print public private protected
3368                         switch (length) {
3369                         case 5:
3370                                 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
3371                                         return TokenNameprint;
3372                                 } else
3373                                         return TokenNameIdentifier;
3374                         case 6:
3375                                 if ((data[++index] == 'u') && (data[++index] == 'b') && (data[++index] == 'l') && (data[++index] == 'i')
3376                                                 && (data[++index] == 'c')) {
3377                                         return TokenNamepublic;
3378                                 } else
3379                                         return TokenNameIdentifier;
3380                         case 7:
3381                                 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'v') && (data[++index] == 'a')
3382                                                 && (data[++index] == 't') && (data[++index] == 'e')) {
3383                                         return TokenNameprivate;
3384                                 } else
3385                                         return TokenNameIdentifier;
3386                         case 9:
3387                                 if ((data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 't') && (data[++index] == 'e')
3388                                                 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'd')) {
3389                                         return TokenNameprotected;
3390                                 } else
3391                                         return TokenNameIdentifier;
3392                         }
3393                         return TokenNameIdentifier;
3394                 case 'r':
3395                         // return require require_once
3396                         if (length == 6) {
3397                                 if ((data[++index] == 'e') && (data[++index] == 't') && (data[++index] == 'u') && (data[++index] == 'r')
3398                                                 && (data[++index] == 'n')) {
3399                                         return TokenNamereturn;
3400                                 }
3401                         } else if (length == 7) {
3402                                 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3403                                                 && (data[++index] == 'r') && (data[++index] == 'e')) {
3404                                         return TokenNamerequire;
3405                                 }
3406                         } else if (length == 12) {
3407                                 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3408                                                 && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3409                                                 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e')) {
3410                                         return TokenNamerequire_once;
3411                                 }
3412                         } else
3413                                 return TokenNameIdentifier;
3414                 case 's':
3415                         // self static switch
3416                         switch (length) {
3417                         // case 4:
3418                         // if ((data[++index] == 'e') && (data[++index] == 'l') && (data[++index]
3419                         // == 'f')) {
3420                         // return TokenNameself;
3421                         // }
3422                         // return TokenNameIdentifier;
3423                         case 6:
3424                                 if (data[++index] == 't')
3425                                         if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) {
3426                                                 return TokenNamestatic;
3427                                         } else
3428                                                 return TokenNameIdentifier;
3429                                 else if ((data[index] == 'w') && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c')
3430                                                 && (data[++index] == 'h'))
3431                                         return TokenNameswitch;
3432                                 else
3433                                         return TokenNameIdentifier;
3434                         default:
3435                                 return TokenNameIdentifier;
3436                         }
3437                 case 't':
3438                         // try true throw
3439                         switch (length) {
3440                         case 3:
3441                                 if ((data[++index] == 'r') && (data[++index] == 'y'))
3442                                         return TokenNametry;
3443                                 else
3444                                         return TokenNameIdentifier;
3445                         // case 4 :
3446                         // if ((data[++index] == 'r') && (data[++index] == 'u')
3447                         // && (data[++index] == 'e'))
3448                         // return TokenNametrue;
3449                         // else
3450                         // return TokenNameIdentifier;
3451                         case 5:
3452                                 if ((data[++index] == 'h') && (data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 'w'))
3453                                         return TokenNamethrow;
3454                                 else
3455                                         return TokenNameIdentifier;
3456                         default:
3457                                 return TokenNameIdentifier;
3458                         }
3459                 case 'u':
3460                         // use unset
3461                         switch (length) {
3462                         case 3:
3463                                 if ((data[++index] == 's') && (data[++index] == 'e'))
3464                                         return TokenNameuse;
3465                                 else
3466                                         return TokenNameIdentifier;
3467                         case 5:
3468                                 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3469                                         return TokenNameunset;
3470                                 else
3471                                         return TokenNameIdentifier;
3472                         default:
3473                                 return TokenNameIdentifier;
3474                         }
3475                 case 'v':
3476                         // var
3477                         switch (length) {
3478                         case 3:
3479                                 if ((data[++index] == 'a') && (data[++index] == 'r'))
3480                                         return TokenNamevar;
3481                                 else
3482                                         return TokenNameIdentifier;
3483                         default:
3484                                 return TokenNameIdentifier;
3485                         }
3486                 case 'w':
3487                         // while
3488                         switch (length) {
3489                         case 5:
3490                                 if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3491                                         return TokenNamewhile;
3492                                 else
3493                                         return TokenNameIdentifier;
3494                         // case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3495                         // (data[++index]=='e') && (data[++index]=='f')&&
3496                         // (data[++index]=='p'))
3497                         // return TokenNamewidefp ;
3498                         // else
3499                         // return TokenNameIdentifier;
3500                         default:
3501                                 return TokenNameIdentifier;
3502                         }
3503                 case 'x':
3504                         // xor
3505                         switch (length) {
3506                         case 3:
3507                                 if ((data[++index] == 'o') && (data[++index] == 'r'))
3508                                         return TokenNamexor;
3509                                 else
3510                                         return TokenNameIdentifier;
3511                         default:
3512                                 return TokenNameIdentifier;
3513                         }
3514                 default:
3515                         return TokenNameIdentifier;
3516                 }
3517         }
3518
3519         public int scanNumber(boolean dotPrefix) throws InvalidInputException {
3520                 // when entering this method the currentCharacter is the firt
3521                 // digit of the number , i.e. it may be preceeded by a . when
3522                 // dotPrefix is true
3523                 boolean floating = dotPrefix;
3524                 if ((!dotPrefix) && (currentCharacter == '0')) {
3525                         if (getNextChar('x', 'X') >= 0) { // ----------hexa-----------------
3526                                 // force the first char of the hexa number do exist...
3527                                 // consume next character
3528                                 unicodeAsBackSlash = false;
3529                                 currentCharacter = source[currentPosition++];
3530                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
3531                                 // && (source[currentPosition] == 'u')) {
3532                                 // getNextUnicodeChar();
3533                                 // } else {
3534                                 // if (withoutUnicodePtr != 0) {
3535                                 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3536                                 // }
3537                                 // }
3538                                 if (Character.digit(currentCharacter, 16) == -1)
3539                                         throw new InvalidInputException(INVALID_HEXA);
3540                                 // ---end forcing--
3541                                 while (getNextCharAsDigit(16)) {
3542                                 }
3543                                 ;
3544                                 // if (getNextChar('l', 'L') >= 0)
3545                                 // return TokenNameLongLiteral;
3546                                 // else
3547                                 return TokenNameIntegerLiteral;
3548                         }
3549                         // there is x or X in the number
3550                         // potential octal ! ... some one may write 000099.0 ! thus 00100 <
3551                         // 00078.0 is true !!!!! crazy language
3552                         if (getNextCharAsDigit()) {
3553                                 // -------------potential octal-----------------
3554                                 while (getNextCharAsDigit()) {
3555                                 }
3556                                 ;
3557                                 // if (getNextChar('l', 'L') >= 0) {
3558                                 // return TokenNameLongLiteral;
3559                                 // }
3560                                 //
3561                                 // if (getNextChar('f', 'F') >= 0) {
3562                                 // return TokenNameFloatingPointLiteral;
3563                                 // }
3564                                 if (getNextChar('d', 'D') >= 0) {
3565                                         return TokenNameDoubleLiteral;
3566                                 } else { // make the distinction between octal and float ....
3567                                         if (getNextChar('.')) { // bingo ! ....
3568                                                 while (getNextCharAsDigit()) {
3569                                                 }
3570                                                 ;
3571                                                 if (getNextChar('e', 'E') >= 0) {
3572                                                         // consume next character
3573                                                         unicodeAsBackSlash = false;
3574                                                         currentCharacter = source[currentPosition++];
3575                                                         // if (((currentCharacter = source[currentPosition++]) == '\\')
3576                                                         // && (source[currentPosition] == 'u')) {
3577                                                         // getNextUnicodeChar();
3578                                                         // } else {
3579                                                         // if (withoutUnicodePtr != 0) {
3580                                                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3581                                                         // }
3582                                                         // }
3583                                                         if ((currentCharacter == '-') || (currentCharacter == '+')) {
3584                                                                 // consume next character
3585                                                                 unicodeAsBackSlash = false;
3586                                                                 currentCharacter = source[currentPosition++];
3587                                                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
3588                                                                 // && (source[currentPosition] == 'u')) {
3589                                                                 // getNextUnicodeChar();
3590                                                                 // } else {
3591                                                                 // if (withoutUnicodePtr != 0) {
3592                                                                 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3593                                                                 // currentCharacter;
3594                                                                 // }
3595                                                                 // }
3596                                                         }
3597                                                         if (!Character.isDigit(currentCharacter))
3598                                                                 throw new InvalidInputException(INVALID_FLOAT);
3599                                                         while (getNextCharAsDigit()) {
3600                                                         }
3601                                                         ;
3602                                                 }
3603                                                 // if (getNextChar('f', 'F') >= 0)
3604                                                 // return TokenNameFloatingPointLiteral;
3605                                                 getNextChar('d', 'D'); // jump over potential d or D
3606                                                 return TokenNameDoubleLiteral;
3607                                         } else {
3608                                                 return TokenNameIntegerLiteral;
3609                                         }
3610                                 }
3611                         } else {
3612                                 /* carry on */
3613                         }
3614                 }
3615                 while (getNextCharAsDigit()) {
3616                 }
3617                 ;
3618                 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3619                 // return TokenNameLongLiteral;
3620                 if ((!dotPrefix) && (getNextChar('.'))) { // decimal part that can be empty
3621                         while (getNextCharAsDigit()) {
3622                         }
3623                         ;
3624                         floating = true;
3625                 }
3626                 // if floating is true both exponant and suffix may be optional
3627                 if (getNextChar('e', 'E') >= 0) {
3628                         floating = true;
3629                         // consume next character
3630                         unicodeAsBackSlash = false;
3631                         currentCharacter = source[currentPosition++];
3632                         // if (((currentCharacter = source[currentPosition++]) == '\\')
3633                         // && (source[currentPosition] == 'u')) {
3634                         // getNextUnicodeChar();
3635                         // } else {
3636                         // if (withoutUnicodePtr != 0) {
3637                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3638                         // }
3639                         // }
3640                         if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
3641                                 // next
3642                                 // character
3643                                 unicodeAsBackSlash = false;
3644                                 currentCharacter = source[currentPosition++];
3645                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
3646                                 // && (source[currentPosition] == 'u')) {
3647                                 // getNextUnicodeChar();
3648                                 // } else {
3649                                 // if (withoutUnicodePtr != 0) {
3650                                 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3651                                 // }
3652                                 // }
3653                         }
3654                         if (!Character.isDigit(currentCharacter))
3655                                 throw new InvalidInputException(INVALID_FLOAT);
3656                         while (getNextCharAsDigit()) {
3657                         }
3658                         ;
3659                 }
3660                 if (getNextChar('d', 'D') >= 0)
3661                         return TokenNameDoubleLiteral;
3662                 // if (getNextChar('f', 'F') >= 0)
3663                 // return TokenNameFloatingPointLiteral;
3664                 // the long flag has been tested before
3665                 return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral;
3666         }
3667
3668         /**
3669          * Search the line number corresponding to a specific position
3670          *
3671          */
3672         public final int getLineNumber(int position) {
3673                 if (lineEnds == null)
3674                         return 1;
3675                 int length = linePtr + 1;
3676                 if (length == 0)
3677                         return 1;
3678                 int g = 0, d = length - 1;
3679                 int m = 0;
3680                 while (g <= d) {
3681                         m = (g + d) / 2;
3682                         if (position < lineEnds[m]) {
3683                                 d = m - 1;
3684                         } else if (position > lineEnds[m]) {
3685                                 g = m + 1;
3686                         } else {
3687                                 return m + 1;
3688                         }
3689                 }
3690                 if (position < lineEnds[m]) {
3691                         return m + 1;
3692                 }
3693                 return m + 2;
3694         }
3695
3696         public void setPHPMode(boolean mode) {
3697                 phpMode = mode;
3698         }
3699
3700         public final void setSource(char[] source) {
3701                 setSource(null, source);
3702         }
3703
3704         public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3705                 // the source-buffer is set to sourceString
3706                 this.compilationUnit = compilationUnit;
3707                 if (source == null) {
3708                         this.source = new char[0];
3709                 } else {
3710                         this.source = source;
3711                 }
3712                 startPosition = -1;
3713                 initialPosition = currentPosition = 0;
3714                 containsAssertKeyword = false;
3715                 withoutUnicodeBuffer = new char[this.source.length];
3716                 fFillerToken = TokenNameEOF;
3717                 // encapsedStringStack = new Stack();
3718         }
3719
3720         public String toString() {
3721                 if (startPosition == source.length)
3722                         return "EOF\n\n" + new String(source); //$NON-NLS-1$
3723                 if (currentPosition > source.length)
3724                         return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3725                 char front[] = new char[startPosition];
3726                 System.arraycopy(source, 0, front, 0, startPosition);
3727                 int middleLength = (currentPosition - 1) - startPosition + 1;
3728                 char middle[];
3729                 if (middleLength > -1) {
3730                         middle = new char[middleLength];
3731                         System.arraycopy(source, startPosition, middle, 0, middleLength);
3732                 } else {
3733                         middle = new char[0];
3734                 }
3735                 char end[] = new char[source.length - (currentPosition - 1)];
3736                 System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - (currentPosition - 1) - 1);
3737                 return new String(front) + "\n===============================\nStarts here -->" //$NON-NLS-1$
3738                                 + new String(middle) + "<-- Ends here\n===============================\n" //$NON-NLS-1$
3739                                 + new String(end);
3740         }
3741
3742         public final String toStringAction(int act) {
3743                 switch (act) {
3744                 case TokenNameERROR:
3745                         return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
3746                 // //$NON-NLS-1$
3747                 case TokenNameINLINE_HTML:
3748                         return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3749                 case    TokenNameECHO_INVISIBLE:
3750                         //0-length token
3751                         return "";
3752                 case TokenNameIdentifier:
3753                         return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3754                 case TokenNameVariable:
3755                         return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3756                 case TokenNameabstract:
3757                         return "abstract"; //$NON-NLS-1$
3758                 case TokenNameand:
3759                         return "AND"; //$NON-NLS-1$
3760                 case TokenNamearray:
3761                         return "array"; //$NON-NLS-1$
3762                 case TokenNameas:
3763                         return "as"; //$NON-NLS-1$
3764                 case TokenNamebreak:
3765                         return "break"; //$NON-NLS-1$
3766                 case TokenNamecase:
3767                         return "case"; //$NON-NLS-1$
3768                 case TokenNameclass:
3769                         return "class"; //$NON-NLS-1$
3770                 case TokenNamecatch:
3771                         return "catch"; //$NON-NLS-1$
3772                 case TokenNameclone:
3773                         //$NON-NLS-1$
3774                         return "clone";
3775                 case TokenNameconst:
3776                         //$NON-NLS-1$
3777                         return "const";
3778                 case TokenNamecontinue:
3779                         return "continue"; //$NON-NLS-1$
3780                 case TokenNamedefault:
3781                         return "default"; //$NON-NLS-1$
3782                 // case TokenNamedefine :
3783                 // return "define"; //$NON-NLS-1$
3784                 case TokenNamedo:
3785                         return "do"; //$NON-NLS-1$
3786                 case TokenNameecho:
3787                         return "echo"; //$NON-NLS-1$
3788                 case TokenNameelse:
3789                         return "else"; //$NON-NLS-1$
3790                 case TokenNameelseif:
3791                         return "elseif"; //$NON-NLS-1$
3792                 case TokenNameendfor:
3793                         return "endfor"; //$NON-NLS-1$
3794                 case TokenNameendforeach:
3795                         return "endforeach"; //$NON-NLS-1$
3796                 case TokenNameendif:
3797                         return "endif"; //$NON-NLS-1$
3798                 case TokenNameendswitch:
3799                         return "endswitch"; //$NON-NLS-1$
3800                 case TokenNameendwhile:
3801                         return "endwhile"; //$NON-NLS-1$
3802                 case TokenNameexit:
3803                         return "exit";
3804                 case TokenNameextends:
3805                         return "extends"; //$NON-NLS-1$
3806                 // case TokenNamefalse :
3807                 // return "false"; //$NON-NLS-1$
3808                 case TokenNamefinal:
3809                         return "final"; //$NON-NLS-1$
3810                 case TokenNamefor:
3811                         return "for"; //$NON-NLS-1$
3812                 case TokenNameforeach:
3813                         return "foreach"; //$NON-NLS-1$
3814                 case TokenNamefunction:
3815                         return "function"; //$NON-NLS-1$
3816                 case TokenNameglobal:
3817                         return "global"; //$NON-NLS-1$
3818                 case TokenNameif:
3819                         return "if"; //$NON-NLS-1$
3820                 case TokenNameimplements:
3821                         return "implements"; //$NON-NLS-1$
3822                 case TokenNameinclude:
3823                         return "include"; //$NON-NLS-1$
3824                 case TokenNameinclude_once:
3825                         return "include_once"; //$NON-NLS-1$
3826                 case TokenNameinstanceof:
3827                         return "instanceof"; //$NON-NLS-1$
3828                 case TokenNameinterface:
3829                         return "interface"; //$NON-NLS-1$
3830                 case TokenNameisset:
3831                         return "isset"; //$NON-NLS-1$
3832                 case TokenNamelist:
3833                         return "list"; //$NON-NLS-1$
3834                 case TokenNamenew:
3835                         return "new"; //$NON-NLS-1$
3836                 // case TokenNamenull :
3837                 // return "null"; //$NON-NLS-1$
3838                 case TokenNameor:
3839                         return "OR"; //$NON-NLS-1$
3840                 case TokenNameprint:
3841                         return "print"; //$NON-NLS-1$
3842                 case TokenNameprivate:
3843                         return "private"; //$NON-NLS-1$
3844                 case TokenNameprotected:
3845                         return "protected"; //$NON-NLS-1$
3846                 case TokenNamepublic:
3847                         return "public"; //$NON-NLS-1$
3848                 case TokenNamerequire:
3849                         return "require"; //$NON-NLS-1$
3850                 case TokenNamerequire_once:
3851                         return "require_once"; //$NON-NLS-1$
3852                 case TokenNamereturn:
3853                         return "return"; //$NON-NLS-1$
3854                         // case TokenNameself:
3855                         // return "self"; //$NON-NLS-1$
3856                 case TokenNamestatic:
3857                         return "static"; //$NON-NLS-1$
3858                 case TokenNameswitch:
3859                         return "switch"; //$NON-NLS-1$
3860                 // case TokenNametrue :
3861                 // return "true"; //$NON-NLS-1$
3862                 case TokenNameunset:
3863                         return "unset"; //$NON-NLS-1$
3864                 case TokenNamevar:
3865                         return "var"; //$NON-NLS-1$
3866                 case TokenNamewhile:
3867                         return "while"; //$NON-NLS-1$
3868                 case TokenNamexor:
3869                         return "XOR"; //$NON-NLS-1$
3870                 // case TokenNamethis :
3871                 // return "$this"; //$NON-NLS-1$
3872                 case TokenNameIntegerLiteral:
3873                         return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3874                 case TokenNameDoubleLiteral:
3875                         return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3876                 case TokenNameStringDoubleQuote:
3877                         return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3878                 case TokenNameStringSingleQuote:
3879                         return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3880                 case TokenNameStringInterpolated:
3881                         return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3882                 case TokenNameEncapsedString0:
3883                         return "`"; //$NON-NLS-1$
3884                 // case TokenNameEncapsedString1:
3885                 // return "\'"; //$NON-NLS-1$
3886                 // case TokenNameEncapsedString2:
3887                 // return "\""; //$NON-NLS-1$
3888                 case TokenNameSTRING:
3889                         return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3890                 case TokenNameHEREDOC:
3891                         return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3892                 case TokenNamePLUS_PLUS:
3893                         return "++"; //$NON-NLS-1$
3894                 case TokenNameMINUS_MINUS:
3895                         return "--"; //$NON-NLS-1$
3896                 case TokenNameEQUAL_EQUAL:
3897                         return "=="; //$NON-NLS-1$
3898                 case TokenNameEQUAL_EQUAL_EQUAL:
3899                         return "==="; //$NON-NLS-1$
3900                 case TokenNameEQUAL_GREATER:
3901                         return "=>"; //$NON-NLS-1$
3902                 case TokenNameLESS_EQUAL:
3903                         return "<="; //$NON-NLS-1$
3904                 case TokenNameGREATER_EQUAL:
3905                         return ">="; //$NON-NLS-1$
3906                 case TokenNameNOT_EQUAL:
3907                         return "!="; //$NON-NLS-1$
3908                 case TokenNameNOT_EQUAL_EQUAL:
3909                         return "!=="; //$NON-NLS-1$
3910                 case TokenNameLEFT_SHIFT:
3911                         return "<<"; //$NON-NLS-1$
3912                 case TokenNameRIGHT_SHIFT:
3913                         return ">>"; //$NON-NLS-1$
3914                 case TokenNamePLUS_EQUAL:
3915                         return "+="; //$NON-NLS-1$
3916                 case TokenNameMINUS_EQUAL:
3917                         return "-="; //$NON-NLS-1$
3918                 case TokenNameMULTIPLY_EQUAL:
3919                         return "*="; //$NON-NLS-1$
3920                 case TokenNameDIVIDE_EQUAL:
3921                         return "/="; //$NON-NLS-1$
3922                 case TokenNameAND_EQUAL:
3923                         return "&="; //$NON-NLS-1$
3924                 case TokenNameOR_EQUAL:
3925                         return "|="; //$NON-NLS-1$
3926                 case TokenNameXOR_EQUAL:
3927                         return "^="; //$NON-NLS-1$
3928                 case TokenNameREMAINDER_EQUAL:
3929                         return "%="; //$NON-NLS-1$
3930                 case TokenNameDOT_EQUAL:
3931                         return ".="; //$NON-NLS-1$
3932                 case TokenNameLEFT_SHIFT_EQUAL:
3933                         return "<<="; //$NON-NLS-1$
3934                 case TokenNameRIGHT_SHIFT_EQUAL:
3935                         return ">>="; //$NON-NLS-1$
3936                 case TokenNameOR_OR:
3937                         return "||"; //$NON-NLS-1$
3938                 case TokenNameAND_AND:
3939                         return "&&"; //$NON-NLS-1$
3940                 case TokenNamePLUS:
3941                         return "+"; //$NON-NLS-1$
3942                 case TokenNameMINUS:
3943                         return "-"; //$NON-NLS-1$
3944                 case TokenNameMINUS_GREATER:
3945                         return "->";
3946                 case TokenNameNOT:
3947                         return "!"; //$NON-NLS-1$
3948                 case TokenNameREMAINDER:
3949                         return "%"; //$NON-NLS-1$
3950                 case TokenNameXOR:
3951                         return "^"; //$NON-NLS-1$
3952                 case TokenNameAND:
3953                         return "&"; //$NON-NLS-1$
3954                 case TokenNameMULTIPLY:
3955                         return "*"; //$NON-NLS-1$
3956                 case TokenNameOR:
3957                         return "|"; //$NON-NLS-1$
3958                 case TokenNameTWIDDLE:
3959                         return "~"; //$NON-NLS-1$
3960                 case TokenNameTWIDDLE_EQUAL:
3961                         return "~="; //$NON-NLS-1$
3962                 case TokenNameDIVIDE:
3963                         return "/"; //$NON-NLS-1$
3964                 case TokenNameGREATER:
3965                         return ">"; //$NON-NLS-1$
3966                 case TokenNameLESS:
3967                         return "<"; //$NON-NLS-1$
3968                 case TokenNameLPAREN:
3969                         return "("; //$NON-NLS-1$
3970                 case TokenNameRPAREN:
3971                         return ")"; //$NON-NLS-1$
3972                 case TokenNameLBRACE:
3973                         return "{"; //$NON-NLS-1$
3974                 case TokenNameRBRACE:
3975                         return "}"; //$NON-NLS-1$
3976                 case TokenNameLBRACKET:
3977                         return "["; //$NON-NLS-1$
3978                 case TokenNameRBRACKET:
3979                         return "]"; //$NON-NLS-1$
3980                 case TokenNameSEMICOLON:
3981                         return ";"; //$NON-NLS-1$
3982                 case TokenNameQUESTION:
3983                         return "?"; //$NON-NLS-1$
3984                 case TokenNameCOLON:
3985                         return ":"; //$NON-NLS-1$
3986                 case TokenNameCOMMA:
3987                         return ","; //$NON-NLS-1$
3988                 case TokenNameDOT:
3989                         return "."; //$NON-NLS-1$
3990                 case TokenNameEQUAL:
3991                         return "="; //$NON-NLS-1$
3992                 case TokenNameAT:
3993                         return "@";
3994                 case TokenNameDOLLAR:
3995                         return "$";
3996                 case TokenNameDOLLAR_LBRACE:
3997                         return "${";
3998                 case TokenNameLBRACE_DOLLAR:
3999                         return "{$";
4000                 case TokenNameEOF:
4001                         return "EOF"; //$NON-NLS-1$
4002                 case TokenNameWHITESPACE:
4003                         return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4004                 case TokenNameCOMMENT_LINE:
4005                         return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4006                 case TokenNameCOMMENT_BLOCK:
4007                         return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4008                 case TokenNameCOMMENT_PHPDOC:
4009                         return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4010                 // case TokenNameHTML :
4011                 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
4012                 // //$NON-NLS-1$
4013                 case TokenNameFILE:
4014                         return "__FILE__"; //$NON-NLS-1$
4015                 case TokenNameLINE:
4016                         return "__LINE__"; //$NON-NLS-1$
4017                 case TokenNameCLASS_C:
4018                         return "__CLASS__"; //$NON-NLS-1$
4019                 case TokenNameMETHOD_C:
4020                         return "__METHOD__"; //$NON-NLS-1$
4021                 case TokenNameFUNC_C:
4022                         return "__FUNCTION__"; //$NON-NLS-1
4023                 case TokenNameboolCAST:
4024                         return "( bool )"; //$NON-NLS-1$
4025                 case TokenNameintCAST:
4026                         return "( int )"; //$NON-NLS-1$
4027                 case TokenNamedoubleCAST:
4028                         return "( double )"; //$NON-NLS-1$
4029                 case TokenNameobjectCAST:
4030                         return "( object )"; //$NON-NLS-1$
4031                 case TokenNamestringCAST:
4032                         return "( string )"; //$NON-NLS-1$
4033                 default:
4034                         return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
4035                 }
4036         }
4037
4038         public Scanner() {
4039                 this(false, false);
4040         }
4041
4042         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
4043                 this(tokenizeComments, tokenizeWhiteSpace, false);
4044         }
4045
4046         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals) {
4047                 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, false);
4048         }
4049
4050         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4051                         boolean assertMode) {
4052                 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, assertMode, false, null, null, true);
4053         }
4054
4055         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4056                         boolean assertMode, boolean tokenizeStrings, char[][] taskTags, char[][] taskPriorities, boolean isTaskCaseSensitive) {
4057                 this.eofPosition = Integer.MAX_VALUE;
4058                 this.tokenizeComments = tokenizeComments;
4059                 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4060                 this.tokenizeStrings = tokenizeStrings;
4061                 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4062                 // this.assertMode = assertMode;
4063                 // this.encapsedStringStack = null;
4064                 this.taskTags = taskTags;
4065                 this.taskPriorities = taskPriorities;
4066         }
4067
4068         private void checkNonExternalizeString() throws InvalidInputException {
4069                 if (currentLine == null)
4070                         return;
4071                 parseTags(currentLine);
4072         }
4073
4074         private void parseTags(NLSLine line) throws InvalidInputException {
4075                 String s = new String(getCurrentTokenSource());
4076                 int pos = s.indexOf(TAG_PREFIX);
4077                 int lineLength = line.size();
4078                 while (pos != -1) {
4079                         int start = pos + TAG_PREFIX_LENGTH;
4080                         int end = s.indexOf(TAG_POSTFIX, start);
4081                         String index = s.substring(start, end);
4082                         int i = 0;
4083                         try {
4084                                 i = Integer.parseInt(index) - 1;
4085                                 // Tags are one based not zero based.
4086                         } catch (NumberFormatException e) {
4087                                 i = -1; // we don't want to consider this as a valid NLS tag
4088                         }
4089                         if (line.exists(i)) {
4090                                 line.set(i, null);
4091                         }
4092                         pos = s.indexOf(TAG_PREFIX, start);
4093                 }
4094                 this.nonNLSStrings = new StringLiteral[lineLength];
4095                 int nonNLSCounter = 0;
4096                 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4097                         StringLiteral literal = (StringLiteral) iterator.next();
4098                         if (literal != null) {
4099                                 this.nonNLSStrings[nonNLSCounter++] = literal;
4100                         }
4101                 }
4102                 if (nonNLSCounter == 0) {
4103                         this.nonNLSStrings = null;
4104                         currentLine = null;
4105                         return;
4106                 }
4107                 this.wasNonExternalizedStringLiteral = true;
4108                 if (nonNLSCounter != lineLength) {
4109                         System.arraycopy(this.nonNLSStrings, 0, (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, nonNLSCounter);
4110                 }
4111                 currentLine = null;
4112         }
4113
4114         public final void scanEscapeCharacter() throws InvalidInputException {
4115                 // the string with "\\u" is a legal string of two chars \ and u
4116                 // thus we use a direct access to the source (for regular cases).
4117                 if (unicodeAsBackSlash) {
4118                         // consume next character
4119                         unicodeAsBackSlash = false;
4120                         // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4121                         // (source[currentPosition] == 'u')) {
4122                         // getNextUnicodeChar();
4123                         // } else {
4124                         if (withoutUnicodePtr != 0) {
4125                                 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4126                                 // }
4127                         }
4128                 } else
4129                         currentCharacter = source[currentPosition++];
4130                 switch (currentCharacter) {
4131                 case 'b':
4132                         currentCharacter = '\b';
4133                         break;
4134                 case 't':
4135                         currentCharacter = '\t';
4136                         break;
4137                 case 'n':
4138                         currentCharacter = '\n';
4139                         break;
4140                 case 'f':
4141                         currentCharacter = '\f';
4142                         break;
4143                 case 'r':
4144                         currentCharacter = '\r';
4145                         break;
4146                 case '\"':
4147                         currentCharacter = '\"';
4148                         break;
4149                 case '\'':
4150                         currentCharacter = '\'';
4151                         break;
4152                 case '\\':
4153                         currentCharacter = '\\';
4154                         break;
4155                 default:
4156                         // -----------octal escape--------------
4157                         // OctalDigit
4158                         // OctalDigit OctalDigit
4159                         // ZeroToThree OctalDigit OctalDigit
4160                         int number = Character.getNumericValue(currentCharacter);
4161                         if (number >= 0 && number <= 7) {
4162                                 boolean zeroToThreeNot = number > 3;
4163                                 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4164                                         int digit = Character.getNumericValue(currentCharacter);
4165                                         if (digit >= 0 && digit <= 7) {
4166                                                 number = (number * 8) + digit;
4167                                                 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4168                                                         if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
4169                                                                 // Digit --> ignore last character
4170                                                                 currentPosition--;
4171                                                         } else {
4172                                                                 digit = Character.getNumericValue(currentCharacter);
4173                                                                 if (digit >= 0 && digit <= 7) { // has read \ZeroToThree
4174                                                                         // OctalDigit OctalDigit
4175                                                                         number = (number * 8) + digit;
4176                                                                 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
4177                                                                         // --> ignore last character
4178                                                                         currentPosition--;
4179                                                                 }
4180                                                         }
4181                                                 } else { // has read \OctalDigit NonDigit--> ignore last
4182                                                         // character
4183                                                         currentPosition--;
4184                                                 }
4185                                         } else { // has read \OctalDigit NonOctalDigit--> ignore last
4186                                                 // character
4187                                                 currentPosition--;
4188                                         }
4189                                 } else { // has read \OctalDigit --> ignore last character
4190                                         currentPosition--;
4191                                 }
4192                                 if (number > 255)
4193                                         throw new InvalidInputException(INVALID_ESCAPE);
4194                                 currentCharacter = (char) number;
4195                         } else
4196                                 throw new InvalidInputException(INVALID_ESCAPE);
4197                 }
4198         }
4199
4200         // chech presence of task: tags
4201         // TODO (frederic) see if we need to take unicode characters into account...
4202         public void checkTaskTag(int commentStart, int commentEnd) {
4203                 char[] src = this.source;
4204
4205                 // only look for newer task: tags
4206                 if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4207                         return;
4208                 }
4209                 int foundTaskIndex = this.foundTaskCount;
4210                 char previous = src[commentStart + 1]; // should be '*' or '/'
4211                 nextChar: for (int i = commentStart + 2; i < commentEnd && i < this.eofPosition; i++) {
4212                         char[] tag = null;
4213                         char[] priority = null;
4214                         // check for tag occurrence only if not ambiguous with javadoc tag
4215                         if (previous != '@') {
4216                                 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4217                                         tag = this.taskTags[itag];
4218                                         int tagLength = tag.length;
4219                                         if (tagLength == 0)
4220                                                 continue nextTag;
4221
4222                                         // ensure tag is not leaded with letter if tag starts with a letter
4223                                         if (Scanner.isPHPIdentifierStart(tag[0])) {
4224                                                 if (Scanner.isPHPIdentifierPart(previous)) {
4225                                                         continue nextTag;
4226                                                 }
4227                                         }
4228
4229                                         for (int t = 0; t < tagLength; t++) {
4230                                                 char sc, tc;
4231                                                 int x = i + t;
4232                                                 if (x >= this.eofPosition || x >= commentEnd)
4233                                                         continue nextTag;
4234                                                 if ((sc = src[i + t]) != (tc = tag[t])) { // case sensitive check
4235                                                         if (this.isTaskCaseSensitive || (Character.toLowerCase(sc) != Character.toLowerCase(tc))) { // case
4236                                                                 // insensitive
4237                                                                 // check
4238                                                                 continue nextTag;
4239                                                         }
4240                                                 }
4241                                         }
4242                                         // ensure tag is not followed with letter if tag finishes with a
4243                                         // letter
4244                                         if (i + tagLength < commentEnd && Scanner.isPHPIdentifierPart(src[i + tagLength - 1])) {
4245                                                 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4246                                                         continue nextTag;
4247                                         }
4248                                         if (this.foundTaskTags == null) {
4249                                                 this.foundTaskTags = new char[5][];
4250                                                 this.foundTaskMessages = new char[5][];
4251                                                 this.foundTaskPriorities = new char[5][];
4252                                                 this.foundTaskPositions = new int[5][];
4253                                         } else if (this.foundTaskCount == this.foundTaskTags.length) {
4254                                                 System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0,
4255                                                                 this.foundTaskCount);
4256                                                 System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4257                                                                 this.foundTaskCount);
4258                                                 System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4259                                                                 this.foundTaskCount);
4260                                                 System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4261                                                                 this.foundTaskCount);
4262                                         }
4263
4264                                         priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4265
4266                                         this.foundTaskTags[this.foundTaskCount] = tag;
4267                                         this.foundTaskPriorities[this.foundTaskCount] = priority;
4268                                         this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4269                                         this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4270                                         this.foundTaskCount++;
4271                                         i += tagLength - 1; // will be incremented when looping
4272                                         break nextTag;
4273                                 }
4274                         }
4275                         previous = src[i];
4276                 }
4277                 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4278                         // retrieve message start and end positions
4279                         int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4280                         int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4281                         // at most beginning of next task
4282                         if (max_value < msgStart) {
4283                                 max_value = msgStart; // would only occur if tag is before EOF.
4284                         }
4285                         int end = -1;
4286                         char c;
4287                         for (int j = msgStart; j < max_value; j++) {
4288                                 if ((c = src[j]) == '\n' || c == '\r') {
4289                                         end = j - 1;
4290                                         break;
4291                                 }
4292                         }
4293                         if (end == -1) {
4294                                 for (int j = max_value; j > msgStart; j--) {
4295                                         if ((c = src[j]) == '*') {
4296                                                 end = j - 1;
4297                                                 break;
4298                                         }
4299                                 }
4300                                 if (end == -1)
4301                                         end = max_value;
4302                         }
4303                         if (msgStart == end)
4304                                 continue; // empty
4305                         // trim the message
4306                         while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4307                                 end--;
4308                         while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4309                                 msgStart++;
4310                         // update the end position of the task
4311                         this.foundTaskPositions[i][1] = end;
4312                         // get the message source
4313                         final int messageLength = end - msgStart + 1;
4314                         char[] message = new char[messageLength];
4315                         System.arraycopy(src, msgStart, message, 0, messageLength);
4316                         this.foundTaskMessages[i] = message;
4317                 }
4318         }
4319
4320         // chech presence of task: tags
4321         // public void checkTaskTag(int commentStart, int commentEnd) {
4322         // // only look for newer task: tags
4323         // if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount
4324         // - 1][0] >= commentStart) {
4325         // return;
4326         // }
4327         // int foundTaskIndex = this.foundTaskCount;
4328         // nextChar: for (int i = commentStart; i < commentEnd && i <
4329         // this.eofPosition; i++) {
4330         // char[] tag = null;
4331         // char[] priority = null;
4332         // // check for tag occurrence
4333         // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4334         // tag = this.taskTags[itag];
4335         // priority = this.taskPriorities != null && itag < this.taskPriorities.length
4336         // ? this.taskPriorities[itag] : null;
4337         // int tagLength = tag.length;
4338         // for (int t = 0; t < tagLength; t++) {
4339         // if (this.source[i + t] != tag[t])
4340         // continue nextTag;
4341         // }
4342         // if (this.foundTaskTags == null) {
4343         // this.foundTaskTags = new char[5][];
4344         // this.foundTaskMessages = new char[5][];
4345         // this.foundTaskPriorities = new char[5][];
4346         // this.foundTaskPositions = new int[5][];
4347         // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4348         // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new
4349         // char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4350         // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new
4351         // char[this.foundTaskCount * 2][], 0,
4352         // this.foundTaskCount);
4353         // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities =
4354         // new char[this.foundTaskCount * 2][], 0,
4355         // this.foundTaskCount);
4356         // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new
4357         // int[this.foundTaskCount * 2][], 0,
4358         // this.foundTaskCount);
4359         // }
4360         // this.foundTaskTags[this.foundTaskCount] = tag;
4361         // this.foundTaskPriorities[this.foundTaskCount] = priority;
4362         // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength
4363         // - 1 };
4364         // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4365         // this.foundTaskCount++;
4366         // i += tagLength - 1; // will be incremented when looping
4367         // }
4368         // }
4369         // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4370         // // retrieve message start and end positions
4371         // int msgStart = this.foundTaskPositions[i][0] +
4372         // this.foundTaskTags[i].length;
4373         // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i +
4374         // 1][0] - 1 : commentEnd - 1;
4375         // // at most beginning of next task
4376         // if (max_value < msgStart)
4377         // max_value = msgStart; // would only occur if tag is before EOF.
4378         // int end = -1;
4379         // char c;
4380         // for (int j = msgStart; j < max_value; j++) {
4381         // if ((c = this.source[j]) == '\n' || c == '\r') {
4382         // end = j - 1;
4383         // break;
4384         // }
4385         // }
4386         // if (end == -1) {
4387         // for (int j = max_value; j > msgStart; j--) {
4388         // if ((c = this.source[j]) == '*') {
4389         // end = j - 1;
4390         // break;
4391         // }
4392         // }
4393         // if (end == -1)
4394         // end = max_value;
4395         // }
4396         // if (msgStart == end)
4397         // continue; // empty
4398         // // trim the message
4399         // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4400         // end--;
4401         // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4402         // msgStart++;
4403         // // update the end position of the task
4404         // this.foundTaskPositions[i][1] = end;
4405         // // get the message source
4406         // final int messageLength = end - msgStart + 1;
4407         // char[] message = new char[messageLength];
4408         // System.arraycopy(source, msgStart, message, 0, messageLength);
4409         // this.foundTaskMessages[i] = message;
4410         // }
4411         // }
4412 }