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