new SF update site
[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                         boolean openDollarBrace = false;
1220                         // consume next character
1221                         unicodeAsBackSlash = false;
1222                         currentCharacter = source[currentPosition++];
1223                         while (currentCharacter != '"' || openDollarBrace) {
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 = true;
1246                                 } else if (currentCharacter == '{' && source[currentPosition] == '$') {
1247                                         openDollarBrace = true;
1248                                 } else if (currentCharacter == '}') {
1249                                         openDollarBrace = false;
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                                                                 phpMode = true;
1850                                                                 if (phpShortTag) {
1851                                                                         fFillerToken = TokenNameECHO_INVISIBLE;
1852                                                                 }
1853                                                                 return TokenNameINLINE_HTML;
1854                                                         }
1855                                                 } else {
1856                                                         int test = getNextChar('H', 'h');
1857                                                         if (test >= 0) {
1858                                                                 test = getNextChar('P', 'p');
1859                                                                 if (test >= 0) {
1860                                                                         // <?PHP <?php
1861                                                                         if (ignorePHPOneLiner) {
1862                                                                                 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1863                                                                                         phpMode = true;
1864                                                                                         return TokenNameINLINE_HTML;
1865                                                                                 }
1866                                                                         } else {
1867                                                                                 phpMode = true;
1868                                                                                 return TokenNameINLINE_HTML;
1869                                                                         }
1870                                                                 }
1871                                                         }
1872                                                         // }
1873                                                 }
1874                                         }
1875                                 }
1876                                 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1877                                         if (recordLineSeparator) {
1878                                                 pushLineSeparator();
1879                                         } else {
1880                                                 currentLine = null;
1881                                         }
1882                                 }
1883                         } // -----------------while--------------------
1884                         phpMode = true;
1885                         return TokenNameINLINE_HTML;
1886                 } // -----------------try--------------------
1887                 catch (IndexOutOfBoundsException e) {
1888                         startPosition = start;
1889                         currentPosition--;
1890                 }
1891                 phpMode = true;
1892                 return TokenNameINLINE_HTML;
1893         }
1894
1895         /**
1896          * check if the PHP is only in this line (for CodeFormatter)
1897          *
1898          * @return
1899          */
1900         private int lookAheadLinePHPTag() {
1901                 int currentPositionInLine = currentPosition;
1902                 char previousCharInLine = ' ';
1903                 char currentCharInLine = ' ';
1904                 boolean singleQuotedStringActive = false;
1905                 boolean doubleQuotedStringActive = false;
1906
1907                 try {
1908                         // look ahead in this line
1909                         while (true) {
1910                                 previousCharInLine = currentCharInLine;
1911                                 currentCharInLine = source[currentPositionInLine++];
1912                                 switch (currentCharInLine) {
1913                                 case '>':
1914                                         if (previousCharInLine == '?') {
1915                                                 // update the scanner's current Position in the source
1916                                                 currentPosition = currentPositionInLine;
1917                                                 // use as "dummy" token
1918                                                 return TokenNameEOF;
1919                                         }
1920                                         break;
1921                                 case '\\':
1922                                         if (doubleQuotedStringActive) {
1923                                                 // ignore escaped characters in double quoted strings
1924                                                 previousCharInLine = currentCharInLine;
1925                                                 currentCharInLine = source[currentPositionInLine++];
1926                                         }
1927                                 case '\"':
1928                                         if (doubleQuotedStringActive) {
1929                                                 doubleQuotedStringActive = false;
1930                                         } else {
1931                                                 if (!singleQuotedStringActive) {
1932                                                         doubleQuotedStringActive = true;
1933                                                 }
1934                                         }
1935                                         break;
1936                                 case '\'':
1937                                         if (singleQuotedStringActive) {
1938                                                 if (previousCharInLine != '\\') {
1939                                                         singleQuotedStringActive = false;
1940                                                 }
1941                                         } else {
1942                                                 if (!doubleQuotedStringActive) {
1943                                                         singleQuotedStringActive = true;
1944                                                 }
1945                                         }
1946                                         break;
1947                                 case '\n':
1948                                         phpMode = true;
1949                                         return TokenNameINLINE_HTML;
1950                                 case '#':
1951                                         if (!singleQuotedStringActive && !doubleQuotedStringActive) {
1952                                                 phpMode = true;
1953                                                 return TokenNameINLINE_HTML;
1954                                         }
1955                                         break;
1956                                 case '/':
1957                                         if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1958                                                 phpMode = true;
1959                                                 return TokenNameINLINE_HTML;
1960                                         }
1961                                         break;
1962                                 case '*':
1963                                         if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1964                                                 phpMode = true;
1965                                                 return TokenNameINLINE_HTML;
1966                                         }
1967                                         break;
1968                                 }
1969                         }
1970                 } catch (IndexOutOfBoundsException e) {
1971                         phpMode = true;
1972                         currentPosition = currentPositionInLine;
1973                         return TokenNameINLINE_HTML;
1974                 }
1975         }
1976
1977         // public final void getNextUnicodeChar()
1978         // throws IndexOutOfBoundsException, InvalidInputException {
1979         // //VOID
1980         // //handle the case of unicode.
1981         // //when a unicode appears then we must use a buffer that holds char
1982         // internal values
1983         // //At the end of this method currentCharacter holds the new visited char
1984         // //and currentPosition points right next after it
1985         //
1986         // //ALL getNextChar.... ARE OPTIMIZED COPIES
1987         //
1988         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
1989         // currentPosition++;
1990         // while (source[currentPosition] == 'u') {
1991         // currentPosition++;
1992         // unicodeSize++;
1993         // }
1994         //
1995         // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
1996         // || c1 < 0
1997         // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
1998         // || c2 < 0
1999         // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
2000         // || c3 < 0
2001         // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
2002         // || c4 < 0) {
2003         // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2004         // } else {
2005         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2006         // //need the unicode buffer
2007         // if (withoutUnicodePtr == 0) {
2008         // //buffer all the entries that have been left aside....
2009         // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
2010         // System.arraycopy(
2011         // source,
2012         // startPosition,
2013         // withoutUnicodeBuffer,
2014         // 1,
2015         // withoutUnicodePtr);
2016         // }
2017         // //fill the buffer with the char
2018         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2019         // }
2020         // unicodeAsBackSlash = currentCharacter == '\\';
2021         // }
2022         /*
2023          * Tokenize a method body, assuming that curly brackets are properly balanced.
2024          */
2025         public final void jumpOverMethodBody() {
2026                 this.wasAcr = false;
2027                 int found = 1;
2028                 try {
2029                         while (true) { // loop for jumping over comments
2030                                 // ---------Consume white space and handles startPosition---------
2031                                 boolean isWhiteSpace;
2032                                 do {
2033                                         startPosition = currentPosition;
2034                                         currentCharacter = source[currentPosition++];
2035                                         // if (((currentCharacter = source[currentPosition++]) == '\\')
2036                                         // && (source[currentPosition] == 'u')) {
2037                                         // isWhiteSpace = jumpOverUnicodeWhiteSpace();
2038                                         // } else {
2039                                         if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2040                                                 pushLineSeparator();
2041                                         isWhiteSpace = Character.isWhitespace(currentCharacter);
2042                                         // }
2043                                 } while (isWhiteSpace);
2044                                 // -------consume token until } is found---------
2045                                 switch (currentCharacter) {
2046                                 case '{':
2047                                         found++;
2048                                         break;
2049                                 case '}':
2050                                         found--;
2051                                         if (found == 0)
2052                                                 return;
2053                                         break;
2054                                 case '\'': {
2055                                         boolean test;
2056                                         test = getNextChar('\\');
2057                                         if (test) {
2058                                                 try {
2059                                                         scanDoubleQuotedEscapeCharacter();
2060                                                 } catch (InvalidInputException ex) {
2061                                                 }
2062                                                 ;
2063                                         } else {
2064                                                 // try { // consume next character
2065                                                 unicodeAsBackSlash = false;
2066                                                 currentCharacter = source[currentPosition++];
2067                                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
2068                                                 // && (source[currentPosition] == 'u')) {
2069                                                 // getNextUnicodeChar();
2070                                                 // } else {
2071                                                 if (withoutUnicodePtr != 0) {
2072                                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2073                                                 }
2074                                                 // }
2075                                                 // } catch (InvalidInputException ex) {
2076                                                 // };
2077                                         }
2078                                         getNextChar('\'');
2079                                         break;
2080                                 }
2081                                 case '"':
2082                                         try {
2083                                                 // try { // consume next character
2084                                                 unicodeAsBackSlash = false;
2085                                                 currentCharacter = source[currentPosition++];
2086                                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
2087                                                 // && (source[currentPosition] == 'u')) {
2088                                                 // getNextUnicodeChar();
2089                                                 // } else {
2090                                                 if (withoutUnicodePtr != 0) {
2091                                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2092                                                 }
2093                                                 // }
2094                                                 // } catch (InvalidInputException ex) {
2095                                                 // };
2096                                                 while (currentCharacter != '"') {
2097                                                         if (currentCharacter == '\r') {
2098                                                                 if (source[currentPosition] == '\n')
2099                                                                         currentPosition++;
2100                                                                 break;
2101                                                                 // the string cannot go further that the line
2102                                                         }
2103                                                         if (currentCharacter == '\n') {
2104                                                                 break;
2105                                                                 // the string cannot go further that the line
2106                                                         }
2107                                                         if (currentCharacter == '\\') {
2108                                                                 try {
2109                                                                         scanDoubleQuotedEscapeCharacter();
2110                                                                 } catch (InvalidInputException ex) {
2111                                                                 }
2112                                                                 ;
2113                                                         }
2114                                                         // try { // consume next character
2115                                                         unicodeAsBackSlash = false;
2116                                                         currentCharacter = source[currentPosition++];
2117                                                         // if (((currentCharacter = source[currentPosition++]) == '\\')
2118                                                         // && (source[currentPosition] == 'u')) {
2119                                                         // getNextUnicodeChar();
2120                                                         // } else {
2121                                                         if (withoutUnicodePtr != 0) {
2122                                                                 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2123                                                         }
2124                                                         // }
2125                                                         // } catch (InvalidInputException ex) {
2126                                                         // };
2127                                                 }
2128                                         } catch (IndexOutOfBoundsException e) {
2129                                                 return;
2130                                         }
2131                                         break;
2132                                 case '/': {
2133                                         int test;
2134                                         if ((test = getNextChar('/', '*')) == 0) {
2135                                                 // line comment
2136                                                 try {
2137                                                         // get the next char
2138                                                         currentCharacter = source[currentPosition++];
2139                                                         // if (((currentCharacter = source[currentPosition++]) ==
2140                                                         // '\\')
2141                                                         // && (source[currentPosition] == 'u')) {
2142                                                         // //-------------unicode traitement ------------
2143                                                         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2144                                                         // currentPosition++;
2145                                                         // while (source[currentPosition] == 'u') {
2146                                                         // currentPosition++;
2147                                                         // }
2148                                                         // if ((c1 =
2149                                                         // Character.getNumericValue(source[currentPosition++]))
2150                                                         // > 15
2151                                                         // || c1 < 0
2152                                                         // || (c2 =
2153                                                         // Character.getNumericValue(source[currentPosition++]))
2154                                                         // > 15
2155                                                         // || c2 < 0
2156                                                         // || (c3 =
2157                                                         // Character.getNumericValue(source[currentPosition++]))
2158                                                         // > 15
2159                                                         // || c3 < 0
2160                                                         // || (c4 =
2161                                                         // Character.getNumericValue(source[currentPosition++]))
2162                                                         // > 15
2163                                                         // || c4 < 0) {
2164                                                         // //error don't care of the value
2165                                                         // currentCharacter = 'A';
2166                                                         // } //something different from \n and \r
2167                                                         // else {
2168                                                         // currentCharacter =
2169                                                         // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2170                                                         // }
2171                                                         // }
2172                                                         while (currentCharacter != '\r' && currentCharacter != '\n') {
2173                                                                 // get the next char
2174                                                                 currentCharacter = source[currentPosition++];
2175                                                                 // if (((currentCharacter = source[currentPosition++])
2176                                                                 // == '\\')
2177                                                                 // && (source[currentPosition] == 'u')) {
2178                                                                 // //-------------unicode traitement ------------
2179                                                                 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2180                                                                 // currentPosition++;
2181                                                                 // while (source[currentPosition] == 'u') {
2182                                                                 // currentPosition++;
2183                                                                 // }
2184                                                                 // if ((c1 =
2185                                                                 // Character.getNumericValue(source[currentPosition++]))
2186                                                                 // > 15
2187                                                                 // || c1 < 0
2188                                                                 // || (c2 =
2189                                                                 // Character.getNumericValue(source[currentPosition++]))
2190                                                                 // > 15
2191                                                                 // || c2 < 0
2192                                                                 // || (c3 =
2193                                                                 // Character.getNumericValue(source[currentPosition++]))
2194                                                                 // > 15
2195                                                                 // || c3 < 0
2196                                                                 // || (c4 =
2197                                                                 // Character.getNumericValue(source[currentPosition++]))
2198                                                                 // > 15
2199                                                                 // || c4 < 0) {
2200                                                                 // //error don't care of the value
2201                                                                 // currentCharacter = 'A';
2202                                                                 // } //something different from \n and \r
2203                                                                 // else {
2204                                                                 // currentCharacter =
2205                                                                 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2206                                                                 // }
2207                                                                 // }
2208                                                         }
2209                                                         if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2210                                                                 pushLineSeparator();
2211                                                 } catch (IndexOutOfBoundsException e) {
2212                                                 } // an eof will them be generated
2213                                                 break;
2214                                         }
2215                                         if (test > 0) {
2216                                                 // traditional and annotation comment
2217                                                 boolean star = false;
2218                                                 // try { // consume next character
2219                                                 unicodeAsBackSlash = false;
2220                                                 currentCharacter = source[currentPosition++];
2221                                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
2222                                                 // && (source[currentPosition] == 'u')) {
2223                                                 // getNextUnicodeChar();
2224                                                 // } else {
2225                                                 if (withoutUnicodePtr != 0) {
2226                                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2227                                                 }
2228                                                 // };
2229                                                 // } catch (InvalidInputException ex) {
2230                                                 // };
2231                                                 if (currentCharacter == '*') {
2232                                                         star = true;
2233                                                 }
2234                                                 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2235                                                         pushLineSeparator();
2236                                                 try { // get the next char
2237                                                         currentCharacter = source[currentPosition++];
2238                                                         // if (((currentCharacter = source[currentPosition++]) ==
2239                                                         // '\\')
2240                                                         // && (source[currentPosition] == 'u')) {
2241                                                         // //-------------unicode traitement ------------
2242                                                         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2243                                                         // currentPosition++;
2244                                                         // while (source[currentPosition] == 'u') {
2245                                                         // currentPosition++;
2246                                                         // }
2247                                                         // if ((c1 =
2248                                                         // Character.getNumericValue(source[currentPosition++]))
2249                                                         // > 15
2250                                                         // || c1 < 0
2251                                                         // || (c2 =
2252                                                         // Character.getNumericValue(source[currentPosition++]))
2253                                                         // > 15
2254                                                         // || c2 < 0
2255                                                         // || (c3 =
2256                                                         // Character.getNumericValue(source[currentPosition++]))
2257                                                         // > 15
2258                                                         // || c3 < 0
2259                                                         // || (c4 =
2260                                                         // Character.getNumericValue(source[currentPosition++]))
2261                                                         // > 15
2262                                                         // || c4 < 0) {
2263                                                         // //error don't care of the value
2264                                                         // currentCharacter = 'A';
2265                                                         // } //something different from * and /
2266                                                         // else {
2267                                                         // currentCharacter =
2268                                                         // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2269                                                         // }
2270                                                         // }
2271                                                         // loop until end of comment */
2272                                                         while ((currentCharacter != '/') || (!star)) {
2273                                                                 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2274                                                                         pushLineSeparator();
2275                                                                 star = currentCharacter == '*';
2276                                                                 // get next char
2277                                                                 currentCharacter = source[currentPosition++];
2278                                                                 // if (((currentCharacter = source[currentPosition++])
2279                                                                 // == '\\')
2280                                                                 // && (source[currentPosition] == 'u')) {
2281                                                                 // //-------------unicode traitement ------------
2282                                                                 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2283                                                                 // currentPosition++;
2284                                                                 // while (source[currentPosition] == 'u') {
2285                                                                 // currentPosition++;
2286                                                                 // }
2287                                                                 // if ((c1 =
2288                                                                 // Character.getNumericValue(source[currentPosition++]))
2289                                                                 // > 15
2290                                                                 // || c1 < 0
2291                                                                 // || (c2 =
2292                                                                 // Character.getNumericValue(source[currentPosition++]))
2293                                                                 // > 15
2294                                                                 // || c2 < 0
2295                                                                 // || (c3 =
2296                                                                 // Character.getNumericValue(source[currentPosition++]))
2297                                                                 // > 15
2298                                                                 // || c3 < 0
2299                                                                 // || (c4 =
2300                                                                 // Character.getNumericValue(source[currentPosition++]))
2301                                                                 // > 15
2302                                                                 // || c4 < 0) {
2303                                                                 // //error don't care of the value
2304                                                                 // currentCharacter = 'A';
2305                                                                 // } //something different from * and /
2306                                                                 // else {
2307                                                                 // currentCharacter =
2308                                                                 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2309                                                                 // }
2310                                                                 // }
2311                                                         }
2312                                                 } catch (IndexOutOfBoundsException e) {
2313                                                         return;
2314                                                 }
2315                                                 break;
2316                                         }
2317                                         break;
2318                                 }
2319                                 default:
2320                                         if (isPHPIdentOrVarStart(currentCharacter)) {
2321                                                 try {
2322                                                         scanIdentifierOrKeyword((currentCharacter == '$'));
2323                                                 } catch (InvalidInputException ex) {
2324                                                 }
2325                                                 ;
2326                                                 break;
2327                                         }
2328                                         if (ObviousIdentCharNatures[currentCharacter] == C_DIGIT) {
2329                                                 // if (Character.isDigit(currentCharacter)) {
2330                                                 try {
2331                                                         scanNumber(false);
2332                                                 } catch (InvalidInputException ex) {
2333                                                 }
2334                                                 ;
2335                                                 break;
2336                                         }
2337                                 }
2338                         }
2339                         // -----------------end switch while try--------------------
2340                 } catch (IndexOutOfBoundsException e) {
2341                 } catch (InvalidInputException e) {
2342                 }
2343                 return;
2344         }
2345
2346         // public final boolean jumpOverUnicodeWhiteSpace()
2347         // throws InvalidInputException {
2348         // //BOOLEAN
2349         // //handle the case of unicode. Jump over the next whiteSpace
2350         // //making startPosition pointing on the next available char
2351         // //On false, the currentCharacter is filled up with a potential
2352         // //correct char
2353         //
2354         // try {
2355         // this.wasAcr = false;
2356         // int c1, c2, c3, c4;
2357         // int unicodeSize = 6;
2358         // currentPosition++;
2359         // while (source[currentPosition] == 'u') {
2360         // currentPosition++;
2361         // unicodeSize++;
2362         // }
2363         //
2364         // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2365         // || c1 < 0)
2366         // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2367         // || c2 < 0)
2368         // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2369         // || c3 < 0)
2370         // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2371         // || c4 < 0)) {
2372         // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2373         // }
2374         //
2375         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2376         // if (recordLineSeparator
2377         // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2378         // pushLineSeparator();
2379         // if (Character.isWhitespace(currentCharacter))
2380         // return true;
2381         //
2382         // //buffer the new char which is not a white space
2383         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2384         // //withoutUnicodePtr == 1 is true here
2385         // return false;
2386         // } catch (IndexOutOfBoundsException e) {
2387         // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2388         // }
2389         // }
2390         public final int[] getLineEnds() {
2391                 // return a bounded copy of this.lineEnds
2392                 int[] copy;
2393                 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0, linePtr + 1);
2394                 return copy;
2395         }
2396
2397         public char[] getSource() {
2398                 return this.source;
2399         }
2400
2401         public static boolean isIdentifierOrKeyword(int token) {
2402                 return (token == TokenNameIdentifier) || (token > TokenNameKEYWORD);
2403         }
2404
2405         final char[] optimizedCurrentTokenSource1() {
2406                 // return always the same char[] build only once
2407                 // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2408                 char charOne = source[startPosition];
2409                 switch (charOne) {
2410                 case 'a':
2411                         return charArray_a;
2412                 case 'b':
2413                         return charArray_b;
2414                 case 'c':
2415                         return charArray_c;
2416                 case 'd':
2417                         return charArray_d;
2418                 case 'e':
2419                         return charArray_e;
2420                 case 'f':
2421                         return charArray_f;
2422                 case 'g':
2423                         return charArray_g;
2424                 case 'h':
2425                         return charArray_h;
2426                 case 'i':
2427                         return charArray_i;
2428                 case 'j':
2429                         return charArray_j;
2430                 case 'k':
2431                         return charArray_k;
2432                 case 'l':
2433                         return charArray_l;
2434                 case 'm':
2435                         return charArray_m;
2436                 case 'n':
2437                         return charArray_n;
2438                 case 'o':
2439                         return charArray_o;
2440                 case 'p':
2441                         return charArray_p;
2442                 case 'q':
2443                         return charArray_q;
2444                 case 'r':
2445                         return charArray_r;
2446                 case 's':
2447                         return charArray_s;
2448                 case 't':
2449                         return charArray_t;
2450                 case 'u':
2451                         return charArray_u;
2452                 case 'v':
2453                         return charArray_v;
2454                 case 'w':
2455                         return charArray_w;
2456                 case 'x':
2457                         return charArray_x;
2458                 case 'y':
2459                         return charArray_y;
2460                 case 'z':
2461                         return charArray_z;
2462                 default:
2463                         return new char[] { charOne };
2464                 }
2465         }
2466
2467         final char[] optimizedCurrentTokenSource2() {
2468                 char c0, c1;
2469                 c0 = source[startPosition];
2470                 c1 = source[startPosition + 1];
2471                 if (c0 == '$') {
2472                         // return always the same char[] build only once
2473                         // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2474                         switch (c1) {
2475                         case 'a':
2476                                 return charArray_va;
2477                         case 'b':
2478                                 return charArray_vb;
2479                         case 'c':
2480                                 return charArray_vc;
2481                         case 'd':
2482                                 return charArray_vd;
2483                         case 'e':
2484                                 return charArray_ve;
2485                         case 'f':
2486                                 return charArray_vf;
2487                         case 'g':
2488                                 return charArray_vg;
2489                         case 'h':
2490                                 return charArray_vh;
2491                         case 'i':
2492                                 return charArray_vi;
2493                         case 'j':
2494                                 return charArray_vj;
2495                         case 'k':
2496                                 return charArray_vk;
2497                         case 'l':
2498                                 return charArray_vl;
2499                         case 'm':
2500                                 return charArray_vm;
2501                         case 'n':
2502                                 return charArray_vn;
2503                         case 'o':
2504                                 return charArray_vo;
2505                         case 'p':
2506                                 return charArray_vp;
2507                         case 'q':
2508                                 return charArray_vq;
2509                         case 'r':
2510                                 return charArray_vr;
2511                         case 's':
2512                                 return charArray_vs;
2513                         case 't':
2514                                 return charArray_vt;
2515                         case 'u':
2516                                 return charArray_vu;
2517                         case 'v':
2518                                 return charArray_vv;
2519                         case 'w':
2520                                 return charArray_vw;
2521                         case 'x':
2522                                 return charArray_vx;
2523                         case 'y':
2524                                 return charArray_vy;
2525                         case 'z':
2526                                 return charArray_vz;
2527                         }
2528                 }
2529                 // try to return the same char[] build only once
2530                 int hash = ((c0 << 6) + c1) % TableSize;
2531                 char[][] table = charArray_length[0][hash];
2532                 int i = newEntry2;
2533                 while (++i < InternalTableSize) {
2534                         char[] charArray = table[i];
2535                         if ((c0 == charArray[0]) && (c1 == charArray[1]))
2536                                 return charArray;
2537                 }
2538                 // ---------other side---------
2539                 i = -1;
2540                 int max = newEntry2;
2541                 while (++i <= max) {
2542                         char[] charArray = table[i];
2543                         if ((c0 == charArray[0]) && (c1 == charArray[1]))
2544                                 return charArray;
2545                 }
2546                 // --------add the entry-------
2547                 if (++max >= InternalTableSize)
2548                         max = 0;
2549                 char[] r;
2550                 table[max] = (r = new char[] { c0, c1 });
2551                 newEntry2 = max;
2552                 return r;
2553         }
2554
2555         final char[] optimizedCurrentTokenSource3() {
2556                 // try to return the same char[] build only once
2557                 char c0, c1, c2;
2558                 int hash = (((c0 = source[startPosition]) << 12) + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2559                                 % TableSize;
2560                 char[][] table = charArray_length[1][hash];
2561                 int i = newEntry3;
2562                 while (++i < InternalTableSize) {
2563                         char[] charArray = table[i];
2564                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2565                                 return charArray;
2566                 }
2567                 // ---------other side---------
2568                 i = -1;
2569                 int max = newEntry3;
2570                 while (++i <= max) {
2571                         char[] charArray = table[i];
2572                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2573                                 return charArray;
2574                 }
2575                 // --------add the entry-------
2576                 if (++max >= InternalTableSize)
2577                         max = 0;
2578                 char[] r;
2579                 table[max] = (r = new char[] { c0, c1, c2 });
2580                 newEntry3 = max;
2581                 return r;
2582         }
2583
2584         final char[] optimizedCurrentTokenSource4() {
2585                 // try to return the same char[] build only once
2586                 char c0, c1, c2, c3;
2587                 long hash = ((((long) (c0 = source[startPosition])) << 18) + ((c1 = source[startPosition + 1]) << 12)
2588                                 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2589                                 % TableSize;
2590                 char[][] table = charArray_length[2][(int) hash];
2591                 int i = newEntry4;
2592                 while (++i < InternalTableSize) {
2593                         char[] charArray = table[i];
2594                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2595                                 return charArray;
2596                 }
2597                 // ---------other side---------
2598                 i = -1;
2599                 int max = newEntry4;
2600                 while (++i <= max) {
2601                         char[] charArray = table[i];
2602                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2603                                 return charArray;
2604                 }
2605                 // --------add the entry-------
2606                 if (++max >= InternalTableSize)
2607                         max = 0;
2608                 char[] r;
2609                 table[max] = (r = new char[] { c0, c1, c2, c3 });
2610                 newEntry4 = max;
2611                 return r;
2612         }
2613
2614         final char[] optimizedCurrentTokenSource5() {
2615                 // try to return the same char[] build only once
2616                 char c0, c1, c2, c3, c4;
2617                 long hash = ((((long) (c0 = source[startPosition])) << 24) + (((long) (c1 = source[startPosition + 1])) << 18)
2618                                 + ((c2 = source[startPosition + 2]) << 12) + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2619                                 % TableSize;
2620                 char[][] table = charArray_length[3][(int) hash];
2621                 int i = newEntry5;
2622                 while (++i < InternalTableSize) {
2623                         char[] charArray = table[i];
2624                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2625                                 return charArray;
2626                 }
2627                 // ---------other side---------
2628                 i = -1;
2629                 int max = newEntry5;
2630                 while (++i <= max) {
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                 // --------add the entry-------
2636                 if (++max >= InternalTableSize)
2637                         max = 0;
2638                 char[] r;
2639                 table[max] = (r = new char[] { c0, c1, c2, c3, c4 });
2640                 newEntry5 = max;
2641                 return r;
2642         }
2643
2644         final char[] optimizedCurrentTokenSource6() {
2645                 // try to return the same char[] build only once
2646                 char c0, c1, c2, c3, c4, c5;
2647                 long hash = ((((long) (c0 = source[startPosition])) << 32) + (((long) (c1 = source[startPosition + 1])) << 24)
2648                                 + (((long) (c2 = source[startPosition + 2])) << 18) + ((c3 = source[startPosition + 3]) << 12)
2649                                 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2650                                 % TableSize;
2651                 char[][] table = charArray_length[4][(int) hash];
2652                 int i = newEntry6;
2653                 while (++i < InternalTableSize) {
2654                         char[] charArray = table[i];
2655                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2656                                         && (c5 == charArray[5]))
2657                                 return charArray;
2658                 }
2659                 // ---------other side---------
2660                 i = -1;
2661                 int max = newEntry6;
2662                 while (++i <= max) {
2663                         char[] charArray = table[i];
2664                         if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2665                                         && (c5 == charArray[5]))
2666                                 return charArray;
2667                 }
2668                 // --------add the entry-------
2669                 if (++max >= InternalTableSize)
2670                         max = 0;
2671                 char[] r;
2672                 table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 });
2673                 newEntry6 = max;
2674                 return r;
2675         }
2676
2677         public final void pushLineSeparator() throws InvalidInputException {
2678                 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2679                 final int INCREMENT = 250;
2680                 if (this.checkNonExternalizedStringLiterals) {
2681                         // reinitialize the current line for non externalize strings purpose
2682                         currentLine = null;
2683                 }
2684                 // currentCharacter is at position currentPosition-1
2685                 // cr 000D
2686                 if (currentCharacter == '\r') {
2687                         int separatorPos = currentPosition - 1;
2688                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2689                                 return;
2690                         // System.out.println("CR-" + separatorPos);
2691                         try {
2692                                 lineEnds[++linePtr] = separatorPos;
2693                         } catch (IndexOutOfBoundsException e) {
2694                                 // linePtr value is correct
2695                                 int oldLength = lineEnds.length;
2696                                 int[] old = lineEnds;
2697                                 lineEnds = new int[oldLength + INCREMENT];
2698                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2699                                 lineEnds[linePtr] = separatorPos;
2700                         }
2701                         // look-ahead for merged cr+lf
2702                         try {
2703                                 if (source[currentPosition] == '\n') {
2704                                         // System.out.println("look-ahead LF-" + currentPosition);
2705                                         lineEnds[linePtr] = currentPosition;
2706                                         currentPosition++;
2707                                         wasAcr = false;
2708                                 } else {
2709                                         wasAcr = true;
2710                                 }
2711                         } catch (IndexOutOfBoundsException e) {
2712                                 wasAcr = true;
2713                         }
2714                 } else {
2715                         // lf 000A
2716                         if (currentCharacter == '\n') {
2717                                 // must merge eventual cr followed by lf
2718                                 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2719                                         // System.out.println("merge LF-" + (currentPosition - 1));
2720                                         lineEnds[linePtr] = currentPosition - 1;
2721                                 } else {
2722                                         int separatorPos = currentPosition - 1;
2723                                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2724                                                 return;
2725                                         // System.out.println("LF-" + separatorPos);
2726                                         try {
2727                                                 lineEnds[++linePtr] = separatorPos;
2728                                         } catch (IndexOutOfBoundsException e) {
2729                                                 // linePtr value is correct
2730                                                 int oldLength = lineEnds.length;
2731                                                 int[] old = lineEnds;
2732                                                 lineEnds = new int[oldLength + INCREMENT];
2733                                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2734                                                 lineEnds[linePtr] = separatorPos;
2735                                         }
2736                                 }
2737                                 wasAcr = false;
2738                         }
2739                 }
2740         }
2741
2742         public final void pushUnicodeLineSeparator() {
2743                 // isUnicode means that the \r or \n has been read as a unicode character
2744                 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2745                 final int INCREMENT = 250;
2746                 // currentCharacter is at position currentPosition-1
2747                 if (this.checkNonExternalizedStringLiterals) {
2748                         // reinitialize the current line for non externalize strings purpose
2749                         currentLine = null;
2750                 }
2751                 // cr 000D
2752                 if (currentCharacter == '\r') {
2753                         int separatorPos = currentPosition - 6;
2754                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2755                                 return;
2756                         // System.out.println("CR-" + separatorPos);
2757                         try {
2758                                 lineEnds[++linePtr] = separatorPos;
2759                         } catch (IndexOutOfBoundsException e) {
2760                                 // linePtr value is correct
2761                                 int oldLength = lineEnds.length;
2762                                 int[] old = lineEnds;
2763                                 lineEnds = new int[oldLength + INCREMENT];
2764                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2765                                 lineEnds[linePtr] = separatorPos;
2766                         }
2767                         // look-ahead for merged cr+lf
2768                         if (source[currentPosition] == '\n') {
2769                                 // System.out.println("look-ahead LF-" + currentPosition);
2770                                 lineEnds[linePtr] = currentPosition;
2771                                 currentPosition++;
2772                                 wasAcr = false;
2773                         } else {
2774                                 wasAcr = true;
2775                         }
2776                 } else {
2777                         // lf 000A
2778                         if (currentCharacter == '\n') {
2779                                 // must merge eventual cr followed by lf
2780                                 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2781                                         // System.out.println("merge LF-" + (currentPosition - 1));
2782                                         lineEnds[linePtr] = currentPosition - 6;
2783                                 } else {
2784                                         int separatorPos = currentPosition - 6;
2785                                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2786                                                 return;
2787                                         // System.out.println("LF-" + separatorPos);
2788                                         try {
2789                                                 lineEnds[++linePtr] = separatorPos;
2790                                         } catch (IndexOutOfBoundsException e) {
2791                                                 // linePtr value is correct
2792                                                 int oldLength = lineEnds.length;
2793                                                 int[] old = lineEnds;
2794                                                 lineEnds = new int[oldLength + INCREMENT];
2795                                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2796                                                 lineEnds[linePtr] = separatorPos;
2797                                         }
2798                                 }
2799                                 wasAcr = false;
2800                         }
2801                 }
2802         }
2803
2804         public void recordComment(int token) {
2805                 // compute position
2806                 int stopPosition = this.currentPosition;
2807                 switch (token) {
2808                 case TokenNameCOMMENT_LINE:
2809                         stopPosition = -this.lastCommentLinePosition;
2810                         break;
2811                 case TokenNameCOMMENT_BLOCK:
2812                         stopPosition = -this.currentPosition;
2813                         break;
2814                 }
2815
2816                 // a new comment is recorded
2817                 int length = this.commentStops.length;
2818                 if (++this.commentPtr >= length) {
2819                         System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length);
2820                         // grows the positions buffers too
2821                         System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length);
2822                 }
2823                 this.commentStops[this.commentPtr] = stopPosition;
2824                 this.commentStarts[this.commentPtr] = this.startPosition;
2825         }
2826
2827         // public final void recordComment(boolean isJavadoc) {
2828         // // a new annotation comment is recorded
2829         // try {
2830         // commentStops[++commentPtr] = isJavadoc
2831         // ? currentPosition
2832         // : -currentPosition;
2833         // } catch (IndexOutOfBoundsException e) {
2834         // int oldStackLength = commentStops.length;
2835         // int[] oldStack = commentStops;
2836         // commentStops = new int[oldStackLength + 30];
2837         // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
2838         // commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition;
2839         // //grows the positions buffers too
2840         // int[] old = commentStarts;
2841         // commentStarts = new int[oldStackLength + 30];
2842         // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
2843         // }
2844         // //the buffer is of a correct size here
2845         // commentStarts[commentPtr] = startPosition;
2846         // }
2847         public void resetTo(int begin, int end) {
2848                 // reset the scanner to a given position where it may rescan again
2849                 diet = false;
2850                 initialPosition = startPosition = currentPosition = begin;
2851                 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
2852                 commentPtr = -1; // reset comment stack
2853         }
2854
2855         public final void scanSingleQuotedEscapeCharacter() throws InvalidInputException {
2856                 // the string with "\\u" is a legal string of two chars \ and u
2857                 // thus we use a direct access to the source (for regular cases).
2858                 // if (unicodeAsBackSlash) {
2859                 // // consume next character
2860                 // unicodeAsBackSlash = false;
2861                 // if (((currentCharacter = source[currentPosition++]) == '\\')
2862                 // && (source[currentPosition] == 'u')) {
2863                 // getNextUnicodeChar();
2864                 // } else {
2865                 // if (withoutUnicodePtr != 0) {
2866                 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2867                 // }
2868                 // }
2869                 // } else
2870                 currentCharacter = source[currentPosition++];
2871                 switch (currentCharacter) {
2872                 case '\'':
2873                         currentCharacter = '\'';
2874                         break;
2875                 case '\\':
2876                         currentCharacter = '\\';
2877                         break;
2878                 default:
2879                         currentCharacter = '\\';
2880                         currentPosition--;
2881                 }
2882         }
2883
2884         public final void scanDoubleQuotedEscapeCharacter() throws InvalidInputException {
2885                 currentCharacter = source[currentPosition++];
2886                 switch (currentCharacter) {
2887                 // case 'b' :
2888                 // currentCharacter = '\b';
2889                 // break;
2890                 case 't':
2891                         currentCharacter = '\t';
2892                         break;
2893                 case 'n':
2894                         currentCharacter = '\n';
2895                         break;
2896                 // case 'f' :
2897                 // currentCharacter = '\f';
2898                 // break;
2899                 case 'r':
2900                         currentCharacter = '\r';
2901                         break;
2902                 case '\"':
2903                         currentCharacter = '\"';
2904                         break;
2905                 case '\'':
2906                         currentCharacter = '\'';
2907                         break;
2908                 case '\\':
2909                         currentCharacter = '\\';
2910                         break;
2911                 case '$':
2912                         currentCharacter = '$';
2913                         break;
2914                 default:
2915                         // -----------octal escape--------------
2916                         // OctalDigit
2917                         // OctalDigit OctalDigit
2918                         // ZeroToThree OctalDigit OctalDigit
2919                         int number = Character.getNumericValue(currentCharacter);
2920                         if (number >= 0 && number <= 7) {
2921                                 boolean zeroToThreeNot = number > 3;
2922                                 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2923                                         int digit = Character.getNumericValue(currentCharacter);
2924                                         if (digit >= 0 && digit <= 7) {
2925                                                 number = (number * 8) + digit;
2926                                                 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2927                                                         if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
2928                                                                 // Digit --> ignore last character
2929                                                                 currentPosition--;
2930                                                         } else {
2931                                                                 digit = Character.getNumericValue(currentCharacter);
2932                                                                 if (digit >= 0 && digit <= 7) {
2933                                                                         // has read \ZeroToThree OctalDigit OctalDigit
2934                                                                         number = (number * 8) + digit;
2935                                                                 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
2936                                                                         // --> ignore last character
2937                                                                         currentPosition--;
2938                                                                 }
2939                                                         }
2940                                                 } else { // has read \OctalDigit NonDigit--> ignore last
2941                                                         // character
2942                                                         currentPosition--;
2943                                                 }
2944                                         } else { // has read \OctalDigit NonOctalDigit--> ignore last
2945                                                 // character
2946                                                 currentPosition--;
2947                                         }
2948                                 } else { // has read \OctalDigit --> ignore last character
2949                                         currentPosition--;
2950                                 }
2951                                 if (number > 255)
2952                                         throw new InvalidInputException(INVALID_ESCAPE);
2953                                 currentCharacter = (char) number;
2954                         }
2955                 // else
2956                 // throw new InvalidInputException(INVALID_ESCAPE);
2957                 }
2958         }
2959
2960         // public int scanIdentifierOrKeyword() throws InvalidInputException {
2961         // return scanIdentifierOrKeyword( false );
2962         // }
2963         public int scanIdentifierOrKeyword(boolean isVariable) throws InvalidInputException {
2964                 // test keywords
2965                 // first dispatch on the first char.
2966                 // then the length. If there are several
2967                 // keywors with the same length AND the same first char, then do another
2968                 // disptach on the second char :-)...cool....but fast !
2969                 useAssertAsAnIndentifier = false;
2970                 while (getNextCharAsJavaIdentifierPart()) {
2971                 }
2972                 ;
2973                 if (isVariable) {
2974                         // if (new String(getCurrentTokenSource()).equals("$this")) {
2975                         // return TokenNamethis;
2976                         // }
2977                         return TokenNameVariable;
2978                 }
2979                 int index, length;
2980                 char[] data;
2981                 char firstLetter;
2982                 // if (withoutUnicodePtr == 0)
2983                 // quick test on length == 1 but not on length > 12 while most identifier
2984                 // have a length which is <= 12...but there are lots of identifier with
2985                 // only one char....
2986                 // {
2987                 if ((length = currentPosition - startPosition) == 1)
2988                         return TokenNameIdentifier;
2989                 // data = source;
2990                 data = new char[length];
2991                 index = startPosition;
2992                 for (int i = 0; i < length; i++) {
2993                         data[i] = Character.toLowerCase(source[index + i]);
2994                 }
2995                 index = 0;
2996                 // } else {
2997                 // if ((length = withoutUnicodePtr) == 1)
2998                 // return TokenNameIdentifier;
2999                 // // data = withoutUnicodeBuffer;
3000                 // data = new char[withoutUnicodeBuffer.length];
3001                 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
3002                 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
3003                 // }
3004                 // index = 1;
3005                 // }
3006                 firstLetter = data[index];
3007                 switch (firstLetter) {
3008                 case '_':
3009                         switch (length) {
3010                         case 8:
3011                                 // __FILE__
3012                                 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'i') && (data[++index] == 'l')
3013                                                 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3014                                         return TokenNameFILE;
3015                                 index = 0; // __LINE__
3016                                 if ((data[++index] == '_') && (data[++index] == 'l') && (data[++index] == 'i') && (data[++index] == 'n')
3017                                                 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3018                                         return TokenNameLINE;
3019                                 break;
3020                         case 9:
3021                                 // __CLASS__
3022                                 if ((data[++index] == '_') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3023                                                 && (data[++index] == 's') && (data[++index] == 's') && (data[++index] == '_') && (data[++index] == '_'))
3024                                         return TokenNameCLASS_C;
3025                                 break;
3026                         case 11:
3027                                 // __METHOD__
3028                                 if ((data[++index] == '_') && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 't')
3029                                                 && (data[++index] == 'h') && (data[++index] == 'o') && (data[++index] == 'd') && (data[++index] == '_')
3030                                                 && (data[++index] == '_'))
3031                                         return TokenNameMETHOD_C;
3032                                 break;
3033                         case 12:
3034                                 // __FUNCTION__
3035                                 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'u') && (data[++index] == 'n')
3036                                                 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'o')
3037                                                 && (data[++index] == 'n') && (data[++index] == '_') && (data[++index] == '_'))
3038                                         return TokenNameFUNC_C;
3039                                 break;
3040                         }
3041                         return TokenNameIdentifier;
3042                 case 'a':
3043                         // as and array abstract
3044                         switch (length) {
3045                         case 2:
3046                                 // as
3047                                 if ((data[++index] == 's')) {
3048                                         return TokenNameas;
3049                                 } else {
3050                                         return TokenNameIdentifier;
3051                                 }
3052                         case 3:
3053                                 // and
3054                                 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3055                                         return TokenNameand;
3056                                 } else {
3057                                         return TokenNameIdentifier;
3058                                 }
3059                         case 5:
3060                                 // array
3061                                 if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y'))
3062                                         return TokenNamearray;
3063                                 else
3064                                         return TokenNameIdentifier;
3065                         case 8:
3066                                 if ((data[++index] == 'b') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'r')
3067                                                 && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 't'))
3068                                         return TokenNameabstract;
3069                                 else
3070                                         return TokenNameIdentifier;
3071                         default:
3072                                 return TokenNameIdentifier;
3073                         }
3074                 case 'b':
3075                         // break
3076                         switch (length) {
3077                         case 5:
3078                                 if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k'))
3079                                         return TokenNamebreak;
3080                                 else
3081                                         return TokenNameIdentifier;
3082                         default:
3083                                 return TokenNameIdentifier;
3084                         }
3085                 case 'c':
3086                         // case catch class clone const continue
3087                         switch (length) {
3088                         case 4:
3089                                 if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e'))
3090                                         return TokenNamecase;
3091                                 else
3092                                         return TokenNameIdentifier;
3093                         case 5:
3094                                 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3095                                         return TokenNamecatch;
3096                                 index = 0;
3097                                 if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's'))
3098                                         return TokenNameclass;
3099                                 index = 0;
3100                                 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 'e'))
3101                                         return TokenNameclone;
3102                                 index = 0;
3103                                 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't'))
3104                                         return TokenNameconst;
3105                                 else
3106                                         return TokenNameIdentifier;
3107                         case 8:
3108                                 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'i')
3109                                                 && (data[++index] == 'n') && (data[++index] == 'u') && (data[++index] == 'e'))
3110                                         return TokenNamecontinue;
3111                                 else
3112                                         return TokenNameIdentifier;
3113                         default:
3114                                 return TokenNameIdentifier;
3115                         }
3116                 case 'd':
3117                         // declare default do die
3118                         // TODO delete define ==> no keyword !
3119                         switch (length) {
3120                         case 2:
3121                                 if ((data[++index] == 'o'))
3122                                         return TokenNamedo;
3123                                 else
3124                                         return TokenNameIdentifier;
3125                         // case 6 :
3126                         // if ((data[++index] == 'e')
3127                         // && (data[++index] == 'f')
3128                         // && (data[++index] == 'i')
3129                         // && (data[++index] == 'n')
3130                         // && (data[++index] == 'e'))
3131                         // return TokenNamedefine;
3132                         // else
3133                         // return TokenNameIdentifier;
3134                         case 7:
3135                                 if ((data[++index] == 'e') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3136                                                 && (data[++index] == 'r') && (data[++index] == 'e'))
3137                                         return TokenNamedeclare;
3138                                 index = 0;
3139                                 if ((data[++index] == 'e') && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'u')
3140                                                 && (data[++index] == 'l') && (data[++index] == 't'))
3141                                         return TokenNamedefault;
3142                                 else
3143                                         return TokenNameIdentifier;
3144                         default:
3145                                 return TokenNameIdentifier;
3146                         }
3147                 case 'e':
3148                         // echo else exit elseif extends eval
3149                         switch (length) {
3150                         case 4:
3151                                 if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o'))
3152                                         return TokenNameecho;
3153                                 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e'))
3154                                         return TokenNameelse;
3155                                 else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't'))
3156                                         return TokenNameexit;
3157                                 else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l'))
3158                                         return TokenNameeval;
3159                                 else
3160                                         return TokenNameIdentifier;
3161                         case 5:
3162                                 // endif empty
3163                                 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f'))
3164                                         return TokenNameendif;
3165                                 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 't') && (data[++index] == 'y'))
3166                                         return TokenNameempty;
3167                                 else
3168                                         return TokenNameIdentifier;
3169                         case 6:
3170                                 // endfor
3171                                 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o')
3172                                                 && (data[++index] == 'r'))
3173                                         return TokenNameendfor;
3174                                 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 'i')
3175                                                 && (data[++index] == 'f'))
3176                                         return TokenNameelseif;
3177                                 else
3178                                         return TokenNameIdentifier;
3179                         case 7:
3180                                 if ((data[++index] == 'x') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'n')
3181                                                 && (data[++index] == 'd') && (data[++index] == 's'))
3182                                         return TokenNameextends;
3183                                 else
3184                                         return TokenNameIdentifier;
3185                         case 8:
3186                                 // endwhile
3187                                 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'w') && (data[++index] == 'h')
3188                                                 && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3189                                         return TokenNameendwhile;
3190                                 else
3191                                         return TokenNameIdentifier;
3192                         case 9:
3193                                 // endswitch
3194                                 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 's') && (data[++index] == 'w')
3195                                                 && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3196                                         return TokenNameendswitch;
3197                                 else
3198                                         return TokenNameIdentifier;
3199                         case 10:
3200                                 // enddeclare
3201                                 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'd') && (data[++index] == 'e')
3202                                                 && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 'r')
3203                                                 && (data[++index] == 'e'))
3204                                         return TokenNameenddeclare;
3205                                 index = 0;
3206                                 if ((data[++index] == 'n') // endforeach
3207                                                 && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r')
3208                                                 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'h'))
3209                                         return TokenNameendforeach;
3210                                 else
3211                                         return TokenNameIdentifier;
3212                         default:
3213                                 return TokenNameIdentifier;
3214                         }
3215                 case 'f':
3216                         // for false final function
3217                         switch (length) {
3218                         case 3:
3219                                 if ((data[++index] == 'o') && (data[++index] == 'r'))
3220                                         return TokenNamefor;
3221                                 else
3222                                         return TokenNameIdentifier;
3223                         case 5:
3224                                 // if ((data[++index] == 'a') && (data[++index] == 'l')
3225                                 // && (data[++index] == 's') && (data[++index] == 'e'))
3226                                 // return TokenNamefalse;
3227                                 if ((data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 'a') && (data[++index] == 'l'))
3228                                         return TokenNamefinal;
3229                                 else
3230                                         return TokenNameIdentifier;
3231                         case 7:
3232                                 // foreach
3233                                 if ((data[++index] == 'o') && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a')
3234                                                 && (data[++index] == 'c') && (data[++index] == 'h'))
3235                                         return TokenNameforeach;
3236                                 else
3237                                         return TokenNameIdentifier;
3238                         case 8:
3239                                 // function
3240                                 if ((data[++index] == 'u') && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 't')
3241                                                 && (data[++index] == 'i') && (data[++index] == 'o') && (data[++index] == 'n'))
3242                                         return TokenNamefunction;
3243                                 else
3244                                         return TokenNameIdentifier;
3245                         default:
3246                                 return TokenNameIdentifier;
3247                         }
3248                 case 'g':
3249                         // global
3250                         if (length == 6) {
3251                                 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'b') && (data[++index] == 'a')
3252                                                 && (data[++index] == 'l')) {
3253                                         return TokenNameglobal;
3254                                 }
3255                         }
3256                         return TokenNameIdentifier;
3257                 case 'i':
3258                         // if int isset include include_once instanceof interface implements
3259                         switch (length) {
3260                         case 2:
3261                                 if (data[++index] == 'f')
3262                                         return TokenNameif;
3263                                 else
3264                                         return TokenNameIdentifier;
3265                         // case 3 :
3266                         // if ((data[++index] == 'n') && (data[++index] == 't'))
3267                         // return TokenNameint;
3268                         // else
3269                         // return TokenNameIdentifier;
3270                         case 5:
3271                                 if ((data[++index] == 's') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3272                                         return TokenNameisset;
3273                                 else
3274                                         return TokenNameIdentifier;
3275                         case 7:
3276                                 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3277                                                 && (data[++index] == 'd') && (data[++index] == 'e'))
3278                                         return TokenNameinclude;
3279                                 else
3280                                         return TokenNameIdentifier;
3281                         case 9:
3282                                 // interface
3283                                 if ((data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'r')
3284                                                 && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'e'))
3285                                         return TokenNameinterface;
3286                                 else
3287                                         return TokenNameIdentifier;
3288                         case 10:
3289                                 // instanceof
3290                                 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'a')
3291                                                 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e') && (data[++index] == 'o')
3292                                                 && (data[++index] == 'f'))
3293                                         return TokenNameinstanceof;
3294                                 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 'l') && (data[++index] == 'e')
3295                                                 && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 'n') && (data[++index] == 't')
3296                                                 && (data[++index] == 's'))
3297                                         return TokenNameimplements;
3298                                 else
3299                                         return TokenNameIdentifier;
3300                         case 12:
3301                                 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3302                                                 && (data[++index] == 'd') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3303                                                 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e'))
3304                                         return TokenNameinclude_once;
3305                                 else
3306                                         return TokenNameIdentifier;
3307                         default:
3308                                 return TokenNameIdentifier;
3309                         }
3310                 case 'l':
3311                         // list
3312                         if (length == 4) {
3313                                 if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) {
3314                                         return TokenNamelist;
3315                                 }
3316                         }
3317                         return TokenNameIdentifier;
3318                 case 'n':
3319                         // new null
3320                         switch (length) {
3321                         case 3:
3322                                 if ((data[++index] == 'e') && (data[++index] == 'w'))
3323                                         return TokenNamenew;
3324                                 else
3325                                         return TokenNameIdentifier;
3326                         // case 4 :
3327                         // if ((data[++index] == 'u') && (data[++index] == 'l')
3328                         // && (data[++index] == 'l'))
3329                         // return TokenNamenull;
3330                         // else
3331                         // return TokenNameIdentifier;
3332                         default:
3333                                 return TokenNameIdentifier;
3334                         }
3335                 case 'o':
3336                         // or old_function
3337                         if (length == 2) {
3338                                 if (data[++index] == 'r') {
3339                                         return TokenNameor;
3340                                 }
3341                         }
3342                         // if (length == 12) {
3343                         // if ((data[++index] == 'l')
3344                         // && (data[++index] == 'd')
3345                         // && (data[++index] == '_')
3346                         // && (data[++index] == 'f')
3347                         // && (data[++index] == 'u')
3348                         // && (data[++index] == 'n')
3349                         // && (data[++index] == 'c')
3350                         // && (data[++index] == 't')
3351                         // && (data[++index] == 'i')
3352                         // && (data[++index] == 'o')
3353                         // && (data[++index] == 'n')) {
3354                         // return TokenNameold_function;
3355                         // }
3356                         // }
3357                         return TokenNameIdentifier;
3358                 case 'p':
3359                         // print public private protected
3360                         switch (length) {
3361                         case 5:
3362                                 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
3363                                         return TokenNameprint;
3364                                 } else
3365                                         return TokenNameIdentifier;
3366                         case 6:
3367                                 if ((data[++index] == 'u') && (data[++index] == 'b') && (data[++index] == 'l') && (data[++index] == 'i')
3368                                                 && (data[++index] == 'c')) {
3369                                         return TokenNamepublic;
3370                                 } else
3371                                         return TokenNameIdentifier;
3372                         case 7:
3373                                 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'v') && (data[++index] == 'a')
3374                                                 && (data[++index] == 't') && (data[++index] == 'e')) {
3375                                         return TokenNameprivate;
3376                                 } else
3377                                         return TokenNameIdentifier;
3378                         case 9:
3379                                 if ((data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 't') && (data[++index] == 'e')
3380                                                 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'd')) {
3381                                         return TokenNameprotected;
3382                                 } else
3383                                         return TokenNameIdentifier;
3384                         }
3385                         return TokenNameIdentifier;
3386                 case 'r':
3387                         // return require require_once
3388                         if (length == 6) {
3389                                 if ((data[++index] == 'e') && (data[++index] == 't') && (data[++index] == 'u') && (data[++index] == 'r')
3390                                                 && (data[++index] == 'n')) {
3391                                         return TokenNamereturn;
3392                                 }
3393                         } else if (length == 7) {
3394                                 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3395                                                 && (data[++index] == 'r') && (data[++index] == 'e')) {
3396                                         return TokenNamerequire;
3397                                 }
3398                         } else if (length == 12) {
3399                                 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3400                                                 && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3401                                                 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e')) {
3402                                         return TokenNamerequire_once;
3403                                 }
3404                         } else
3405                                 return TokenNameIdentifier;
3406                 case 's':
3407                         // self static switch
3408                         switch (length) {
3409                         // case 4:
3410                         // if ((data[++index] == 'e') && (data[++index] == 'l') && (data[++index]
3411                         // == 'f')) {
3412                         // return TokenNameself;
3413                         // }
3414                         // return TokenNameIdentifier;
3415                         case 6:
3416                                 if (data[++index] == 't')
3417                                         if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) {
3418                                                 return TokenNamestatic;
3419                                         } else
3420                                                 return TokenNameIdentifier;
3421                                 else if ((data[index] == 'w') && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c')
3422                                                 && (data[++index] == 'h'))
3423                                         return TokenNameswitch;
3424                                 else
3425                                         return TokenNameIdentifier;
3426                         default:
3427                                 return TokenNameIdentifier;
3428                         }
3429                 case 't':
3430                         // try true throw
3431                         switch (length) {
3432                         case 3:
3433                                 if ((data[++index] == 'r') && (data[++index] == 'y'))
3434                                         return TokenNametry;
3435                                 else
3436                                         return TokenNameIdentifier;
3437                         // case 4 :
3438                         // if ((data[++index] == 'r') && (data[++index] == 'u')
3439                         // && (data[++index] == 'e'))
3440                         // return TokenNametrue;
3441                         // else
3442                         // return TokenNameIdentifier;
3443                         case 5:
3444                                 if ((data[++index] == 'h') && (data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 'w'))
3445                                         return TokenNamethrow;
3446                                 else
3447                                         return TokenNameIdentifier;
3448                         default:
3449                                 return TokenNameIdentifier;
3450                         }
3451                 case 'u':
3452                         // use unset
3453                         switch (length) {
3454                         case 3:
3455                                 if ((data[++index] == 's') && (data[++index] == 'e'))
3456                                         return TokenNameuse;
3457                                 else
3458                                         return TokenNameIdentifier;
3459                         case 5:
3460                                 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3461                                         return TokenNameunset;
3462                                 else
3463                                         return TokenNameIdentifier;
3464                         default:
3465                                 return TokenNameIdentifier;
3466                         }
3467                 case 'v':
3468                         // var
3469                         switch (length) {
3470                         case 3:
3471                                 if ((data[++index] == 'a') && (data[++index] == 'r'))
3472                                         return TokenNamevar;
3473                                 else
3474                                         return TokenNameIdentifier;
3475                         default:
3476                                 return TokenNameIdentifier;
3477                         }
3478                 case 'w':
3479                         // while
3480                         switch (length) {
3481                         case 5:
3482                                 if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3483                                         return TokenNamewhile;
3484                                 else
3485                                         return TokenNameIdentifier;
3486                         // case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3487                         // (data[++index]=='e') && (data[++index]=='f')&&
3488                         // (data[++index]=='p'))
3489                         // return TokenNamewidefp ;
3490                         // else
3491                         // return TokenNameIdentifier;
3492                         default:
3493                                 return TokenNameIdentifier;
3494                         }
3495                 case 'x':
3496                         // xor
3497                         switch (length) {
3498                         case 3:
3499                                 if ((data[++index] == 'o') && (data[++index] == 'r'))
3500                                         return TokenNamexor;
3501                                 else
3502                                         return TokenNameIdentifier;
3503                         default:
3504                                 return TokenNameIdentifier;
3505                         }
3506                 default:
3507                         return TokenNameIdentifier;
3508                 }
3509         }
3510
3511         public int scanNumber(boolean dotPrefix) throws InvalidInputException {
3512                 // when entering this method the currentCharacter is the firt
3513                 // digit of the number , i.e. it may be preceeded by a . when
3514                 // dotPrefix is true
3515                 boolean floating = dotPrefix;
3516                 if ((!dotPrefix) && (currentCharacter == '0')) {
3517                         if (getNextChar('x', 'X') >= 0) { // ----------hexa-----------------
3518                                 // force the first char of the hexa number do exist...
3519                                 // consume next character
3520                                 unicodeAsBackSlash = false;
3521                                 currentCharacter = source[currentPosition++];
3522                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
3523                                 // && (source[currentPosition] == 'u')) {
3524                                 // getNextUnicodeChar();
3525                                 // } else {
3526                                 // if (withoutUnicodePtr != 0) {
3527                                 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3528                                 // }
3529                                 // }
3530                                 if (Character.digit(currentCharacter, 16) == -1)
3531                                         throw new InvalidInputException(INVALID_HEXA);
3532                                 // ---end forcing--
3533                                 while (getNextCharAsDigit(16)) {
3534                                 }
3535                                 ;
3536                                 // if (getNextChar('l', 'L') >= 0)
3537                                 // return TokenNameLongLiteral;
3538                                 // else
3539                                 return TokenNameIntegerLiteral;
3540                         }
3541                         // there is x or X in the number
3542                         // potential octal ! ... some one may write 000099.0 ! thus 00100 <
3543                         // 00078.0 is true !!!!! crazy language
3544                         if (getNextCharAsDigit()) {
3545                                 // -------------potential octal-----------------
3546                                 while (getNextCharAsDigit()) {
3547                                 }
3548                                 ;
3549                                 // if (getNextChar('l', 'L') >= 0) {
3550                                 // return TokenNameLongLiteral;
3551                                 // }
3552                                 //
3553                                 // if (getNextChar('f', 'F') >= 0) {
3554                                 // return TokenNameFloatingPointLiteral;
3555                                 // }
3556                                 if (getNextChar('d', 'D') >= 0) {
3557                                         return TokenNameDoubleLiteral;
3558                                 } else { // make the distinction between octal and float ....
3559                                         if (getNextChar('.')) { // bingo ! ....
3560                                                 while (getNextCharAsDigit()) {
3561                                                 }
3562                                                 ;
3563                                                 if (getNextChar('e', 'E') >= 0) {
3564                                                         // consume next character
3565                                                         unicodeAsBackSlash = false;
3566                                                         currentCharacter = source[currentPosition++];
3567                                                         // if (((currentCharacter = source[currentPosition++]) == '\\')
3568                                                         // && (source[currentPosition] == 'u')) {
3569                                                         // getNextUnicodeChar();
3570                                                         // } else {
3571                                                         // if (withoutUnicodePtr != 0) {
3572                                                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3573                                                         // }
3574                                                         // }
3575                                                         if ((currentCharacter == '-') || (currentCharacter == '+')) {
3576                                                                 // consume next character
3577                                                                 unicodeAsBackSlash = false;
3578                                                                 currentCharacter = source[currentPosition++];
3579                                                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
3580                                                                 // && (source[currentPosition] == 'u')) {
3581                                                                 // getNextUnicodeChar();
3582                                                                 // } else {
3583                                                                 // if (withoutUnicodePtr != 0) {
3584                                                                 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3585                                                                 // currentCharacter;
3586                                                                 // }
3587                                                                 // }
3588                                                         }
3589                                                         if (!Character.isDigit(currentCharacter))
3590                                                                 throw new InvalidInputException(INVALID_FLOAT);
3591                                                         while (getNextCharAsDigit()) {
3592                                                         }
3593                                                         ;
3594                                                 }
3595                                                 // if (getNextChar('f', 'F') >= 0)
3596                                                 // return TokenNameFloatingPointLiteral;
3597                                                 getNextChar('d', 'D'); // jump over potential d or D
3598                                                 return TokenNameDoubleLiteral;
3599                                         } else {
3600                                                 return TokenNameIntegerLiteral;
3601                                         }
3602                                 }
3603                         } else {
3604                                 /* carry on */
3605                         }
3606                 }
3607                 while (getNextCharAsDigit()) {
3608                 }
3609                 ;
3610                 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3611                 // return TokenNameLongLiteral;
3612                 if ((!dotPrefix) && (getNextChar('.'))) { // decimal part that can be empty
3613                         while (getNextCharAsDigit()) {
3614                         }
3615                         ;
3616                         floating = true;
3617                 }
3618                 // if floating is true both exponant and suffix may be optional
3619                 if (getNextChar('e', 'E') >= 0) {
3620                         floating = true;
3621                         // consume next character
3622                         unicodeAsBackSlash = false;
3623                         currentCharacter = source[currentPosition++];
3624                         // if (((currentCharacter = source[currentPosition++]) == '\\')
3625                         // && (source[currentPosition] == 'u')) {
3626                         // getNextUnicodeChar();
3627                         // } else {
3628                         // if (withoutUnicodePtr != 0) {
3629                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3630                         // }
3631                         // }
3632                         if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
3633                                 // next
3634                                 // character
3635                                 unicodeAsBackSlash = false;
3636                                 currentCharacter = source[currentPosition++];
3637                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
3638                                 // && (source[currentPosition] == 'u')) {
3639                                 // getNextUnicodeChar();
3640                                 // } else {
3641                                 // if (withoutUnicodePtr != 0) {
3642                                 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3643                                 // }
3644                                 // }
3645                         }
3646                         if (!Character.isDigit(currentCharacter))
3647                                 throw new InvalidInputException(INVALID_FLOAT);
3648                         while (getNextCharAsDigit()) {
3649                         }
3650                         ;
3651                 }
3652                 if (getNextChar('d', 'D') >= 0)
3653                         return TokenNameDoubleLiteral;
3654                 // if (getNextChar('f', 'F') >= 0)
3655                 // return TokenNameFloatingPointLiteral;
3656                 // the long flag has been tested before
3657                 return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral;
3658         }
3659
3660         /**
3661          * Search the line number corresponding to a specific position
3662          *
3663          */
3664         public final int getLineNumber(int position) {
3665                 if (lineEnds == null)
3666                         return 1;
3667                 int length = linePtr + 1;
3668                 if (length == 0)
3669                         return 1;
3670                 int g = 0, d = length - 1;
3671                 int m = 0;
3672                 while (g <= d) {
3673                         m = (g + d) / 2;
3674                         if (position < lineEnds[m]) {
3675                                 d = m - 1;
3676                         } else if (position > lineEnds[m]) {
3677                                 g = m + 1;
3678                         } else {
3679                                 return m + 1;
3680                         }
3681                 }
3682                 if (position < lineEnds[m]) {
3683                         return m + 1;
3684                 }
3685                 return m + 2;
3686         }
3687
3688         public void setPHPMode(boolean mode) {
3689                 phpMode = mode;
3690         }
3691
3692         public final void setSource(char[] source) {
3693                 setSource(null, source);
3694         }
3695
3696         public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3697                 // the source-buffer is set to sourceString
3698                 this.compilationUnit = compilationUnit;
3699                 if (source == null) {
3700                         this.source = new char[0];
3701                 } else {
3702                         this.source = source;
3703                 }
3704                 startPosition = -1;
3705                 initialPosition = currentPosition = 0;
3706                 containsAssertKeyword = false;
3707                 withoutUnicodeBuffer = new char[this.source.length];
3708                 fFillerToken = TokenNameEOF;
3709                 // encapsedStringStack = new Stack();
3710         }
3711
3712         public String toString() {
3713                 if (startPosition == source.length)
3714                         return "EOF\n\n" + new String(source); //$NON-NLS-1$
3715                 if (currentPosition > source.length)
3716                         return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3717                 char front[] = new char[startPosition];
3718                 System.arraycopy(source, 0, front, 0, startPosition);
3719                 int middleLength = (currentPosition - 1) - startPosition + 1;
3720                 char middle[];
3721                 if (middleLength > -1) {
3722                         middle = new char[middleLength];
3723                         System.arraycopy(source, startPosition, middle, 0, middleLength);
3724                 } else {
3725                         middle = new char[0];
3726                 }
3727                 char end[] = new char[source.length - (currentPosition - 1)];
3728                 System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - (currentPosition - 1) - 1);
3729                 return new String(front) + "\n===============================\nStarts here -->" //$NON-NLS-1$
3730                                 + new String(middle) + "<-- Ends here\n===============================\n" //$NON-NLS-1$
3731                                 + new String(end);
3732         }
3733
3734         public final String toStringAction(int act) {
3735                 switch (act) {
3736                 case TokenNameERROR:
3737                         return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
3738                 // //$NON-NLS-1$
3739                 case TokenNameINLINE_HTML:
3740                         return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3741                 case    TokenNameECHO_INVISIBLE:
3742                         //0-length token
3743                         return "";
3744                 case TokenNameIdentifier:
3745                         return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3746                 case TokenNameVariable:
3747                         return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3748                 case TokenNameabstract:
3749                         return "abstract"; //$NON-NLS-1$
3750                 case TokenNameand:
3751                         return "AND"; //$NON-NLS-1$
3752                 case TokenNamearray:
3753                         return "array"; //$NON-NLS-1$
3754                 case TokenNameas:
3755                         return "as"; //$NON-NLS-1$
3756                 case TokenNamebreak:
3757                         return "break"; //$NON-NLS-1$
3758                 case TokenNamecase:
3759                         return "case"; //$NON-NLS-1$
3760                 case TokenNameclass:
3761                         return "class"; //$NON-NLS-1$
3762                 case TokenNamecatch:
3763                         return "catch"; //$NON-NLS-1$
3764                 case TokenNameclone:
3765                         //$NON-NLS-1$
3766                         return "clone";
3767                 case TokenNameconst:
3768                         //$NON-NLS-1$
3769                         return "const";
3770                 case TokenNamecontinue:
3771                         return "continue"; //$NON-NLS-1$
3772                 case TokenNamedefault:
3773                         return "default"; //$NON-NLS-1$
3774                 // case TokenNamedefine :
3775                 // return "define"; //$NON-NLS-1$
3776                 case TokenNamedo:
3777                         return "do"; //$NON-NLS-1$
3778                 case TokenNameecho:
3779                         return "echo"; //$NON-NLS-1$
3780                 case TokenNameelse:
3781                         return "else"; //$NON-NLS-1$
3782                 case TokenNameelseif:
3783                         return "elseif"; //$NON-NLS-1$
3784                 case TokenNameendfor:
3785                         return "endfor"; //$NON-NLS-1$
3786                 case TokenNameendforeach:
3787                         return "endforeach"; //$NON-NLS-1$
3788                 case TokenNameendif:
3789                         return "endif"; //$NON-NLS-1$
3790                 case TokenNameendswitch:
3791                         return "endswitch"; //$NON-NLS-1$
3792                 case TokenNameendwhile:
3793                         return "endwhile"; //$NON-NLS-1$
3794                 case TokenNameexit:
3795                         return "exit";
3796                 case TokenNameextends:
3797                         return "extends"; //$NON-NLS-1$
3798                 // case TokenNamefalse :
3799                 // return "false"; //$NON-NLS-1$
3800                 case TokenNamefinal:
3801                         return "final"; //$NON-NLS-1$
3802                 case TokenNamefor:
3803                         return "for"; //$NON-NLS-1$
3804                 case TokenNameforeach:
3805                         return "foreach"; //$NON-NLS-1$
3806                 case TokenNamefunction:
3807                         return "function"; //$NON-NLS-1$
3808                 case TokenNameglobal:
3809                         return "global"; //$NON-NLS-1$
3810                 case TokenNameif:
3811                         return "if"; //$NON-NLS-1$
3812                 case TokenNameimplements:
3813                         return "implements"; //$NON-NLS-1$
3814                 case TokenNameinclude:
3815                         return "include"; //$NON-NLS-1$
3816                 case TokenNameinclude_once:
3817                         return "include_once"; //$NON-NLS-1$
3818                 case TokenNameinstanceof:
3819                         return "instanceof"; //$NON-NLS-1$
3820                 case TokenNameinterface:
3821                         return "interface"; //$NON-NLS-1$
3822                 case TokenNameisset:
3823                         return "isset"; //$NON-NLS-1$
3824                 case TokenNamelist:
3825                         return "list"; //$NON-NLS-1$
3826                 case TokenNamenew:
3827                         return "new"; //$NON-NLS-1$
3828                 // case TokenNamenull :
3829                 // return "null"; //$NON-NLS-1$
3830                 case TokenNameor:
3831                         return "OR"; //$NON-NLS-1$
3832                 case TokenNameprint:
3833                         return "print"; //$NON-NLS-1$
3834                 case TokenNameprivate:
3835                         return "private"; //$NON-NLS-1$
3836                 case TokenNameprotected:
3837                         return "protected"; //$NON-NLS-1$
3838                 case TokenNamepublic:
3839                         return "public"; //$NON-NLS-1$
3840                 case TokenNamerequire:
3841                         return "require"; //$NON-NLS-1$
3842                 case TokenNamerequire_once:
3843                         return "require_once"; //$NON-NLS-1$
3844                 case TokenNamereturn:
3845                         return "return"; //$NON-NLS-1$
3846                         // case TokenNameself:
3847                         // return "self"; //$NON-NLS-1$
3848                 case TokenNamestatic:
3849                         return "static"; //$NON-NLS-1$
3850                 case TokenNameswitch:
3851                         return "switch"; //$NON-NLS-1$
3852                 // case TokenNametrue :
3853                 // return "true"; //$NON-NLS-1$
3854                 case TokenNameunset:
3855                         return "unset"; //$NON-NLS-1$
3856                 case TokenNamevar:
3857                         return "var"; //$NON-NLS-1$
3858                 case TokenNamewhile:
3859                         return "while"; //$NON-NLS-1$
3860                 case TokenNamexor:
3861                         return "XOR"; //$NON-NLS-1$
3862                 // case TokenNamethis :
3863                 // return "$this"; //$NON-NLS-1$
3864                 case TokenNameIntegerLiteral:
3865                         return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3866                 case TokenNameDoubleLiteral:
3867                         return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3868                 case TokenNameStringDoubleQuote:
3869                         return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3870                 case TokenNameStringSingleQuote:
3871                         return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3872                 case TokenNameStringInterpolated:
3873                         return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3874                 case TokenNameEncapsedString0:
3875                         return "`"; //$NON-NLS-1$
3876                 // case TokenNameEncapsedString1:
3877                 // return "\'"; //$NON-NLS-1$
3878                 // case TokenNameEncapsedString2:
3879                 // return "\""; //$NON-NLS-1$
3880                 case TokenNameSTRING:
3881                         return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3882                 case TokenNameHEREDOC:
3883                         return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3884                 case TokenNamePLUS_PLUS:
3885                         return "++"; //$NON-NLS-1$
3886                 case TokenNameMINUS_MINUS:
3887                         return "--"; //$NON-NLS-1$
3888                 case TokenNameEQUAL_EQUAL:
3889                         return "=="; //$NON-NLS-1$
3890                 case TokenNameEQUAL_EQUAL_EQUAL:
3891                         return "==="; //$NON-NLS-1$
3892                 case TokenNameEQUAL_GREATER:
3893                         return "=>"; //$NON-NLS-1$
3894                 case TokenNameLESS_EQUAL:
3895                         return "<="; //$NON-NLS-1$
3896                 case TokenNameGREATER_EQUAL:
3897                         return ">="; //$NON-NLS-1$
3898                 case TokenNameNOT_EQUAL:
3899                         return "!="; //$NON-NLS-1$
3900                 case TokenNameNOT_EQUAL_EQUAL:
3901                         return "!=="; //$NON-NLS-1$
3902                 case TokenNameLEFT_SHIFT:
3903                         return "<<"; //$NON-NLS-1$
3904                 case TokenNameRIGHT_SHIFT:
3905                         return ">>"; //$NON-NLS-1$
3906                 case TokenNamePLUS_EQUAL:
3907                         return "+="; //$NON-NLS-1$
3908                 case TokenNameMINUS_EQUAL:
3909                         return "-="; //$NON-NLS-1$
3910                 case TokenNameMULTIPLY_EQUAL:
3911                         return "*="; //$NON-NLS-1$
3912                 case TokenNameDIVIDE_EQUAL:
3913                         return "/="; //$NON-NLS-1$
3914                 case TokenNameAND_EQUAL:
3915                         return "&="; //$NON-NLS-1$
3916                 case TokenNameOR_EQUAL:
3917                         return "|="; //$NON-NLS-1$
3918                 case TokenNameXOR_EQUAL:
3919                         return "^="; //$NON-NLS-1$
3920                 case TokenNameREMAINDER_EQUAL:
3921                         return "%="; //$NON-NLS-1$
3922                 case TokenNameDOT_EQUAL:
3923                         return ".="; //$NON-NLS-1$
3924                 case TokenNameLEFT_SHIFT_EQUAL:
3925                         return "<<="; //$NON-NLS-1$
3926                 case TokenNameRIGHT_SHIFT_EQUAL:
3927                         return ">>="; //$NON-NLS-1$
3928                 case TokenNameOR_OR:
3929                         return "||"; //$NON-NLS-1$
3930                 case TokenNameAND_AND:
3931                         return "&&"; //$NON-NLS-1$
3932                 case TokenNamePLUS:
3933                         return "+"; //$NON-NLS-1$
3934                 case TokenNameMINUS:
3935                         return "-"; //$NON-NLS-1$
3936                 case TokenNameMINUS_GREATER:
3937                         return "->";
3938                 case TokenNameNOT:
3939                         return "!"; //$NON-NLS-1$
3940                 case TokenNameREMAINDER:
3941                         return "%"; //$NON-NLS-1$
3942                 case TokenNameXOR:
3943                         return "^"; //$NON-NLS-1$
3944                 case TokenNameAND:
3945                         return "&"; //$NON-NLS-1$
3946                 case TokenNameMULTIPLY:
3947                         return "*"; //$NON-NLS-1$
3948                 case TokenNameOR:
3949                         return "|"; //$NON-NLS-1$
3950                 case TokenNameTWIDDLE:
3951                         return "~"; //$NON-NLS-1$
3952                 case TokenNameTWIDDLE_EQUAL:
3953                         return "~="; //$NON-NLS-1$
3954                 case TokenNameDIVIDE:
3955                         return "/"; //$NON-NLS-1$
3956                 case TokenNameGREATER:
3957                         return ">"; //$NON-NLS-1$
3958                 case TokenNameLESS:
3959                         return "<"; //$NON-NLS-1$
3960                 case TokenNameLPAREN:
3961                         return "("; //$NON-NLS-1$
3962                 case TokenNameRPAREN:
3963                         return ")"; //$NON-NLS-1$
3964                 case TokenNameLBRACE:
3965                         return "{"; //$NON-NLS-1$
3966                 case TokenNameRBRACE:
3967                         return "}"; //$NON-NLS-1$
3968                 case TokenNameLBRACKET:
3969                         return "["; //$NON-NLS-1$
3970                 case TokenNameRBRACKET:
3971                         return "]"; //$NON-NLS-1$
3972                 case TokenNameSEMICOLON:
3973                         return ";"; //$NON-NLS-1$
3974                 case TokenNameQUESTION:
3975                         return "?"; //$NON-NLS-1$
3976                 case TokenNameCOLON:
3977                         return ":"; //$NON-NLS-1$
3978                 case TokenNameCOMMA:
3979                         return ","; //$NON-NLS-1$
3980                 case TokenNameDOT:
3981                         return "."; //$NON-NLS-1$
3982                 case TokenNameEQUAL:
3983                         return "="; //$NON-NLS-1$
3984                 case TokenNameAT:
3985                         return "@";
3986                 case TokenNameDOLLAR:
3987                         return "$";
3988                 case TokenNameDOLLAR_LBRACE:
3989                         return "${";
3990                 case TokenNameLBRACE_DOLLAR:
3991                         return "{$";
3992                 case TokenNameEOF:
3993                         return "EOF"; //$NON-NLS-1$
3994                 case TokenNameWHITESPACE:
3995                         return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3996                 case TokenNameCOMMENT_LINE:
3997                         return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3998                 case TokenNameCOMMENT_BLOCK:
3999                         return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4000                 case TokenNameCOMMENT_PHPDOC:
4001                         return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4002                 // case TokenNameHTML :
4003                 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
4004                 // //$NON-NLS-1$
4005                 case TokenNameFILE:
4006                         return "__FILE__"; //$NON-NLS-1$
4007                 case TokenNameLINE:
4008                         return "__LINE__"; //$NON-NLS-1$
4009                 case TokenNameCLASS_C:
4010                         return "__CLASS__"; //$NON-NLS-1$
4011                 case TokenNameMETHOD_C:
4012                         return "__METHOD__"; //$NON-NLS-1$
4013                 case TokenNameFUNC_C:
4014                         return "__FUNCTION__"; //$NON-NLS-1
4015                 case TokenNameboolCAST:
4016                         return "( bool )"; //$NON-NLS-1$
4017                 case TokenNameintCAST:
4018                         return "( int )"; //$NON-NLS-1$
4019                 case TokenNamedoubleCAST:
4020                         return "( double )"; //$NON-NLS-1$
4021                 case TokenNameobjectCAST:
4022                         return "( object )"; //$NON-NLS-1$
4023                 case TokenNamestringCAST:
4024                         return "( string )"; //$NON-NLS-1$
4025                 default:
4026                         return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
4027                 }
4028         }
4029
4030         public Scanner() {
4031                 this(false, false);
4032         }
4033
4034         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
4035                 this(tokenizeComments, tokenizeWhiteSpace, false);
4036         }
4037
4038         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals) {
4039                 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, false);
4040         }
4041
4042         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4043                         boolean assertMode) {
4044                 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, assertMode, false, null, null, true);
4045         }
4046
4047         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4048                         boolean assertMode, boolean tokenizeStrings, char[][] taskTags, char[][] taskPriorities, boolean isTaskCaseSensitive) {
4049                 this.eofPosition = Integer.MAX_VALUE;
4050                 this.tokenizeComments = tokenizeComments;
4051                 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4052                 this.tokenizeStrings = tokenizeStrings;
4053                 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4054                 // this.assertMode = assertMode;
4055                 // this.encapsedStringStack = null;
4056                 this.taskTags = taskTags;
4057                 this.taskPriorities = taskPriorities;
4058         }
4059
4060         private void checkNonExternalizeString() throws InvalidInputException {
4061                 if (currentLine == null)
4062                         return;
4063                 parseTags(currentLine);
4064         }
4065
4066         private void parseTags(NLSLine line) throws InvalidInputException {
4067                 String s = new String(getCurrentTokenSource());
4068                 int pos = s.indexOf(TAG_PREFIX);
4069                 int lineLength = line.size();
4070                 while (pos != -1) {
4071                         int start = pos + TAG_PREFIX_LENGTH;
4072                         int end = s.indexOf(TAG_POSTFIX, start);
4073                         String index = s.substring(start, end);
4074                         int i = 0;
4075                         try {
4076                                 i = Integer.parseInt(index) - 1;
4077                                 // Tags are one based not zero based.
4078                         } catch (NumberFormatException e) {
4079                                 i = -1; // we don't want to consider this as a valid NLS tag
4080                         }
4081                         if (line.exists(i)) {
4082                                 line.set(i, null);
4083                         }
4084                         pos = s.indexOf(TAG_PREFIX, start);
4085                 }
4086                 this.nonNLSStrings = new StringLiteral[lineLength];
4087                 int nonNLSCounter = 0;
4088                 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4089                         StringLiteral literal = (StringLiteral) iterator.next();
4090                         if (literal != null) {
4091                                 this.nonNLSStrings[nonNLSCounter++] = literal;
4092                         }
4093                 }
4094                 if (nonNLSCounter == 0) {
4095                         this.nonNLSStrings = null;
4096                         currentLine = null;
4097                         return;
4098                 }
4099                 this.wasNonExternalizedStringLiteral = true;
4100                 if (nonNLSCounter != lineLength) {
4101                         System.arraycopy(this.nonNLSStrings, 0, (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, nonNLSCounter);
4102                 }
4103                 currentLine = null;
4104         }
4105
4106         public final void scanEscapeCharacter() throws InvalidInputException {
4107                 // the string with "\\u" is a legal string of two chars \ and u
4108                 // thus we use a direct access to the source (for regular cases).
4109                 if (unicodeAsBackSlash) {
4110                         // consume next character
4111                         unicodeAsBackSlash = false;
4112                         // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4113                         // (source[currentPosition] == 'u')) {
4114                         // getNextUnicodeChar();
4115                         // } else {
4116                         if (withoutUnicodePtr != 0) {
4117                                 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4118                                 // }
4119                         }
4120                 } else
4121                         currentCharacter = source[currentPosition++];
4122                 switch (currentCharacter) {
4123                 case 'b':
4124                         currentCharacter = '\b';
4125                         break;
4126                 case 't':
4127                         currentCharacter = '\t';
4128                         break;
4129                 case 'n':
4130                         currentCharacter = '\n';
4131                         break;
4132                 case 'f':
4133                         currentCharacter = '\f';
4134                         break;
4135                 case 'r':
4136                         currentCharacter = '\r';
4137                         break;
4138                 case '\"':
4139                         currentCharacter = '\"';
4140                         break;
4141                 case '\'':
4142                         currentCharacter = '\'';
4143                         break;
4144                 case '\\':
4145                         currentCharacter = '\\';
4146                         break;
4147                 default:
4148                         // -----------octal escape--------------
4149                         // OctalDigit
4150                         // OctalDigit OctalDigit
4151                         // ZeroToThree OctalDigit OctalDigit
4152                         int number = Character.getNumericValue(currentCharacter);
4153                         if (number >= 0 && number <= 7) {
4154                                 boolean zeroToThreeNot = number > 3;
4155                                 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4156                                         int digit = Character.getNumericValue(currentCharacter);
4157                                         if (digit >= 0 && digit <= 7) {
4158                                                 number = (number * 8) + digit;
4159                                                 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4160                                                         if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
4161                                                                 // Digit --> ignore last character
4162                                                                 currentPosition--;
4163                                                         } else {
4164                                                                 digit = Character.getNumericValue(currentCharacter);
4165                                                                 if (digit >= 0 && digit <= 7) { // has read \ZeroToThree
4166                                                                         // OctalDigit OctalDigit
4167                                                                         number = (number * 8) + digit;
4168                                                                 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
4169                                                                         // --> ignore last character
4170                                                                         currentPosition--;
4171                                                                 }
4172                                                         }
4173                                                 } else { // has read \OctalDigit NonDigit--> ignore last
4174                                                         // character
4175                                                         currentPosition--;
4176                                                 }
4177                                         } else { // has read \OctalDigit NonOctalDigit--> ignore last
4178                                                 // character
4179                                                 currentPosition--;
4180                                         }
4181                                 } else { // has read \OctalDigit --> ignore last character
4182                                         currentPosition--;
4183                                 }
4184                                 if (number > 255)
4185                                         throw new InvalidInputException(INVALID_ESCAPE);
4186                                 currentCharacter = (char) number;
4187                         } else
4188                                 throw new InvalidInputException(INVALID_ESCAPE);
4189                 }
4190         }
4191
4192         // chech presence of task: tags
4193         // TODO (frederic) see if we need to take unicode characters into account...
4194         public void checkTaskTag(int commentStart, int commentEnd) {
4195                 char[] src = this.source;
4196
4197                 // only look for newer task: tags
4198                 if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4199                         return;
4200                 }
4201                 int foundTaskIndex = this.foundTaskCount;
4202                 char previous = src[commentStart + 1]; // should be '*' or '/'
4203                 nextChar: for (int i = commentStart + 2; i < commentEnd && i < this.eofPosition; i++) {
4204                         char[] tag = null;
4205                         char[] priority = null;
4206                         // check for tag occurrence only if not ambiguous with javadoc tag
4207                         if (previous != '@') {
4208                                 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4209                                         tag = this.taskTags[itag];
4210                                         int tagLength = tag.length;
4211                                         if (tagLength == 0)
4212                                                 continue nextTag;
4213
4214                                         // ensure tag is not leaded with letter if tag starts with a letter
4215                                         if (Scanner.isPHPIdentifierStart(tag[0])) {
4216                                                 if (Scanner.isPHPIdentifierPart(previous)) {
4217                                                         continue nextTag;
4218                                                 }
4219                                         }
4220
4221                                         for (int t = 0; t < tagLength; t++) {
4222                                                 char sc, tc;
4223                                                 int x = i + t;
4224                                                 if (x >= this.eofPosition || x >= commentEnd)
4225                                                         continue nextTag;
4226                                                 if ((sc = src[i + t]) != (tc = tag[t])) { // case sensitive check
4227                                                         if (this.isTaskCaseSensitive || (Character.toLowerCase(sc) != Character.toLowerCase(tc))) { // case
4228                                                                 // insensitive
4229                                                                 // check
4230                                                                 continue nextTag;
4231                                                         }
4232                                                 }
4233                                         }
4234                                         // ensure tag is not followed with letter if tag finishes with a
4235                                         // letter
4236                                         if (i + tagLength < commentEnd && Scanner.isPHPIdentifierPart(src[i + tagLength - 1])) {
4237                                                 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4238                                                         continue nextTag;
4239                                         }
4240                                         if (this.foundTaskTags == null) {
4241                                                 this.foundTaskTags = new char[5][];
4242                                                 this.foundTaskMessages = new char[5][];
4243                                                 this.foundTaskPriorities = new char[5][];
4244                                                 this.foundTaskPositions = new int[5][];
4245                                         } else if (this.foundTaskCount == this.foundTaskTags.length) {
4246                                                 System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0,
4247                                                                 this.foundTaskCount);
4248                                                 System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4249                                                                 this.foundTaskCount);
4250                                                 System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4251                                                                 this.foundTaskCount);
4252                                                 System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4253                                                                 this.foundTaskCount);
4254                                         }
4255
4256                                         priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4257
4258                                         this.foundTaskTags[this.foundTaskCount] = tag;
4259                                         this.foundTaskPriorities[this.foundTaskCount] = priority;
4260                                         this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4261                                         this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4262                                         this.foundTaskCount++;
4263                                         i += tagLength - 1; // will be incremented when looping
4264                                         break nextTag;
4265                                 }
4266                         }
4267                         previous = src[i];
4268                 }
4269                 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4270                         // retrieve message start and end positions
4271                         int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4272                         int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4273                         // at most beginning of next task
4274                         if (max_value < msgStart) {
4275                                 max_value = msgStart; // would only occur if tag is before EOF.
4276                         }
4277                         int end = -1;
4278                         char c;
4279                         for (int j = msgStart; j < max_value; j++) {
4280                                 if ((c = src[j]) == '\n' || c == '\r') {
4281                                         end = j - 1;
4282                                         break;
4283                                 }
4284                         }
4285                         if (end == -1) {
4286                                 for (int j = max_value; j > msgStart; j--) {
4287                                         if ((c = src[j]) == '*') {
4288                                                 end = j - 1;
4289                                                 break;
4290                                         }
4291                                 }
4292                                 if (end == -1)
4293                                         end = max_value;
4294                         }
4295                         if (msgStart == end)
4296                                 continue; // empty
4297                         // trim the message
4298                         while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4299                                 end--;
4300                         while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4301                                 msgStart++;
4302                         // update the end position of the task
4303                         this.foundTaskPositions[i][1] = end;
4304                         // get the message source
4305                         final int messageLength = end - msgStart + 1;
4306                         char[] message = new char[messageLength];
4307                         System.arraycopy(src, msgStart, message, 0, messageLength);
4308                         this.foundTaskMessages[i] = message;
4309                 }
4310         }
4311
4312         // chech presence of task: tags
4313         // public void checkTaskTag(int commentStart, int commentEnd) {
4314         // // only look for newer task: tags
4315         // if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount
4316         // - 1][0] >= commentStart) {
4317         // return;
4318         // }
4319         // int foundTaskIndex = this.foundTaskCount;
4320         // nextChar: for (int i = commentStart; i < commentEnd && i <
4321         // this.eofPosition; i++) {
4322         // char[] tag = null;
4323         // char[] priority = null;
4324         // // check for tag occurrence
4325         // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4326         // tag = this.taskTags[itag];
4327         // priority = this.taskPriorities != null && itag < this.taskPriorities.length
4328         // ? this.taskPriorities[itag] : null;
4329         // int tagLength = tag.length;
4330         // for (int t = 0; t < tagLength; t++) {
4331         // if (this.source[i + t] != tag[t])
4332         // continue nextTag;
4333         // }
4334         // if (this.foundTaskTags == null) {
4335         // this.foundTaskTags = new char[5][];
4336         // this.foundTaskMessages = new char[5][];
4337         // this.foundTaskPriorities = new char[5][];
4338         // this.foundTaskPositions = new int[5][];
4339         // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4340         // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new
4341         // char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4342         // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new
4343         // char[this.foundTaskCount * 2][], 0,
4344         // this.foundTaskCount);
4345         // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities =
4346         // new char[this.foundTaskCount * 2][], 0,
4347         // this.foundTaskCount);
4348         // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new
4349         // int[this.foundTaskCount * 2][], 0,
4350         // this.foundTaskCount);
4351         // }
4352         // this.foundTaskTags[this.foundTaskCount] = tag;
4353         // this.foundTaskPriorities[this.foundTaskCount] = priority;
4354         // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength
4355         // - 1 };
4356         // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4357         // this.foundTaskCount++;
4358         // i += tagLength - 1; // will be incremented when looping
4359         // }
4360         // }
4361         // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4362         // // retrieve message start and end positions
4363         // int msgStart = this.foundTaskPositions[i][0] +
4364         // this.foundTaskTags[i].length;
4365         // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i +
4366         // 1][0] - 1 : commentEnd - 1;
4367         // // at most beginning of next task
4368         // if (max_value < msgStart)
4369         // max_value = msgStart; // would only occur if tag is before EOF.
4370         // int end = -1;
4371         // char c;
4372         // for (int j = msgStart; j < max_value; j++) {
4373         // if ((c = this.source[j]) == '\n' || c == '\r') {
4374         // end = j - 1;
4375         // break;
4376         // }
4377         // }
4378         // if (end == -1) {
4379         // for (int j = max_value; j > msgStart; j--) {
4380         // if ((c = this.source[j]) == '*') {
4381         // end = j - 1;
4382         // break;
4383         // }
4384         // }
4385         // if (end == -1)
4386         // end = max_value;
4387         // }
4388         // if (msgStart == end)
4389         // continue; // empty
4390         // // trim the message
4391         // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4392         // end--;
4393         // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4394         // msgStart++;
4395         // // update the end position of the task
4396         // this.foundTaskPositions[i][1] = end;
4397         // // get the message source
4398         // final int messageLength = end - msgStart + 1;
4399         // char[] message = new char[messageLength];
4400         // System.arraycopy(source, msgStart, message, 0, messageLength);
4401         // this.foundTaskMessages[i] = message;
4402         // }
4403         // }
4404 }