1) Fixed issue #776.
[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                                                 return TokenName.QUESTION;
1657                                         case ':':
1658                                                 if (getNextChar(':'))
1659                                                         return TokenName.PAAMAYIM_NEKUDOTAYIM;
1660                                                 return TokenName.COLON;
1661                                         case '@':
1662                                                 return TokenName.OP_AT;
1663                                         case '\'':
1664                                                 consumeStringConstant();
1665                                                 return TokenName.STRINGSINGLEQUOTE;
1666                                         case '"':
1667                                                 // if (tokenizeStrings) {
1668                                                 consumeStringLiteral();
1669                                                 return TokenName.STRINGDOUBLEQUOTE;
1670                                                 // }
1671                                                 // return TokenName.EncapsedString2;
1672                                         case '`':
1673                                                 // if (tokenizeStrings) {
1674                                                 consumeStringInterpolated();
1675                                                 return TokenName.STRINGINTERPOLATED;
1676                                                 // }
1677                                                 // return TokenName.EncapsedString0;
1678                                         case '#':
1679                                         case '/': {
1680                                                 char startChar = currentCharacter;
1681                                                 if (getNextChar('=') && startChar == '/') {
1682                                                         return TokenName.DIVIDE_EQUAL;
1683                                                 }
1684                                                 int test;
1685                                                 if ((startChar == '#')
1686                                                                 || (test = getNextChar('/', '*')) == 0) {
1687                                                         // line comment
1688                                                         this.lastCommentLinePosition = this.currentPosition;
1689                                                         int endPositionForLineComment = 0;
1690                                                         try { // get the next char
1691                                                                 currentCharacter = source[currentPosition++];
1692                                                                 // if (((currentCharacter =
1693                                                                 // source[currentPosition++])
1694                                                                 // == '\\')
1695                                                                 // && (source[currentPosition] == 'u')) {
1696                                                                 // //-------------unicode traitement
1697                                                                 // ------------
1698                                                                 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1699                                                                 // currentPosition++;
1700                                                                 // while (source[currentPosition] == 'u') {
1701                                                                 // currentPosition++;
1702                                                                 // }
1703                                                                 // if ((c1 =
1704                                                                 // Character.getNumericValue(source[currentPosition++]))
1705                                                                 // > 15
1706                                                                 // || c1 < 0
1707                                                                 // || (c2 =
1708                                                                 // Character.getNumericValue(source[currentPosition++]))
1709                                                                 // > 15
1710                                                                 // || c2 < 0
1711                                                                 // || (c3 =
1712                                                                 // Character.getNumericValue(source[currentPosition++]))
1713                                                                 // > 15
1714                                                                 // || c3 < 0
1715                                                                 // || (c4 =
1716                                                                 // Character.getNumericValue(source[currentPosition++]))
1717                                                                 // > 15
1718                                                                 // || c4 < 0) {
1719                                                                 // throw new
1720                                                                 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1721                                                                 // } else {
1722                                                                 // currentCharacter =
1723                                                                 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
1724                                                                 // c4);
1725                                                                 // }
1726                                                                 // }
1727                                                                 // handle the \\u case manually into comment
1728                                                                 // if (currentCharacter == '\\') {
1729                                                                 // if (source[currentPosition] == '\\')
1730                                                                 // currentPosition++;
1731                                                                 // } //jump over the \\
1732                                                                 boolean isUnicode = false;
1733                                                                 while (currentCharacter != '\r'
1734                                                                                 && currentCharacter != '\n') {
1735                                                                         this.lastCommentLinePosition = this.currentPosition;
1736                                                                         if (currentCharacter == '?') {
1737                                                                                 if (getNextChar('>')) {
1738                                                                                         // ?> breaks line comments
1739                                                                                         startPosition = currentPosition - 2;
1740                                                                                         phpMode = false;
1741                                                                                         return TokenName.INLINE_HTML;
1742                                                                                 }
1743                                                                         }
1744                                                                         // get the next char
1745                                                                         isUnicode = false;
1746                                                                         currentCharacter = source[currentPosition++];
1747                                                                         // if (((currentCharacter =
1748                                                                         // source[currentPosition++])
1749                                                                         // == '\\')
1750                                                                         // && (source[currentPosition] == 'u')) {
1751                                                                         // isUnicode = true;
1752                                                                         // //-------------unicode traitement
1753                                                                         // ------------
1754                                                                         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1755                                                                         // currentPosition++;
1756                                                                         // while (source[currentPosition] == 'u') {
1757                                                                         // currentPosition++;
1758                                                                         // }
1759                                                                         // if ((c1 =
1760                                                                         // Character.getNumericValue(source[currentPosition++]))
1761                                                                         // > 15
1762                                                                         // || c1 < 0
1763                                                                         // || (c2 =
1764                                                                         // Character.getNumericValue(
1765                                                                         // source[currentPosition++]))
1766                                                                         // > 15
1767                                                                         // || c2 < 0
1768                                                                         // || (c3 =
1769                                                                         // Character.getNumericValue(
1770                                                                         // source[currentPosition++]))
1771                                                                         // > 15
1772                                                                         // || c3 < 0
1773                                                                         // || (c4 =
1774                                                                         // Character.getNumericValue(
1775                                                                         // source[currentPosition++]))
1776                                                                         // > 15
1777                                                                         // || c4 < 0) {
1778                                                                         // throw new
1779                                                                         // InvalidInputException(INVALID_UNICODE_ESCAPE);
1780                                                                         // } else {
1781                                                                         // currentCharacter =
1782                                                                         // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
1783                                                                         // c4);
1784                                                                         // }
1785                                                                         // }
1786                                                                         // handle the \\u case manually into comment
1787                                                                         // if (currentCharacter == '\\') {
1788                                                                         // if (source[currentPosition] == '\\')
1789                                                                         // currentPosition++;
1790                                                                         // } //jump over the \\
1791                                                                 }
1792                                                                 if (isUnicode) {
1793                                                                         endPositionForLineComment = currentPosition - 6;
1794                                                                 } else {
1795                                                                         endPositionForLineComment = currentPosition - 1;
1796                                                                 }
1797                                                                 // recordComment(false);
1798                                                                 recordComment(TokenName.COMMENT_LINE);
1799                                                                 if (this.taskTags != null)
1800                                                                         checkTaskTag(this.startPosition,
1801                                                                                         this.currentPosition);
1802                                                                 if ((currentCharacter == '\r')
1803                                                                                 || (currentCharacter == '\n')) {
1804                                                                         checkNonExternalizeString();
1805                                                                         if (recordLineSeparator) {
1806                                                                                 if (isUnicode) {
1807                                                                                         pushUnicodeLineSeparator();
1808                                                                                 } else {
1809                                                                                         pushLineSeparator();
1810                                                                                 }
1811                                                                         } else {
1812                                                                                 currentLine = null;
1813                                                                         }
1814                                                                 }
1815                                                                 if (tokenizeComments) {
1816                                                                         if (!isUnicode) {
1817                                                                                 currentPosition = endPositionForLineComment;
1818                                                                                 // reset one character behind
1819                                                                         }
1820                                                                         return TokenName.COMMENT_LINE;
1821                                                                 }
1822                                                         } catch (IndexOutOfBoundsException e) { // an eof
1823                                                                                                                                         // will them
1824                                                                 // be generated
1825                                                                 if (tokenizeComments) {
1826                                                                         currentPosition--;
1827                                                                         // reset one character behind
1828                                                                         return TokenName.COMMENT_LINE;
1829                                                                 }
1830                                                         }
1831                                                         break;
1832                                                 }
1833                                                 if (test > 0) {
1834                                                         // traditional and annotation comment
1835                                                         boolean isJavadoc = false, star = false;
1836                                                         // consume next character
1837                                                         unicodeAsBackSlash = false;
1838                                                         currentCharacter = source[currentPosition++];
1839                                                         // if (((currentCharacter =
1840                                                         // source[currentPosition++]) ==
1841                                                         // '\\')
1842                                                         // && (source[currentPosition] == 'u')) {
1843                                                         // getNextUnicodeChar();
1844                                                         // } else {
1845                                                         // if (withoutUnicodePtr != 0) {
1846                                                         // withoutUnicodeBuffer[++withoutUnicodePtr] =
1847                                                         // currentCharacter;
1848                                                         // }
1849                                                         // }
1850                                                         if (currentCharacter == '*') {
1851                                                                 isJavadoc = true;
1852                                                                 star = true;
1853                                                         }
1854                                                         if ((currentCharacter == '\r')
1855                                                                         || (currentCharacter == '\n')) {
1856                                                                 checkNonExternalizeString();
1857                                                                 if (recordLineSeparator) {
1858                                                                         pushLineSeparator();
1859                                                                 } else {
1860                                                                         currentLine = null;
1861                                                                 }
1862                                                         }
1863                                                         try { // get the next char
1864                                                                 currentCharacter = source[currentPosition++];
1865                                                                 // if (((currentCharacter =
1866                                                                 // source[currentPosition++])
1867                                                                 // == '\\')
1868                                                                 // && (source[currentPosition] == 'u')) {
1869                                                                 // //-------------unicode traitement
1870                                                                 // ------------
1871                                                                 // getNextUnicodeChar();
1872                                                                 // }
1873                                                                 // handle the \\u case manually into comment
1874                                                                 // if (currentCharacter == '\\') {
1875                                                                 // if (source[currentPosition] == '\\')
1876                                                                 // currentPosition++;
1877                                                                 // //jump over the \\
1878                                                                 // }
1879                                                                 // empty comment is not a javadoc /**/
1880                                                                 if (currentCharacter == '/') {
1881                                                                         isJavadoc = false;
1882                                                                 }
1883                                                                 // loop until end of comment */
1884                                                                 while ((currentCharacter != '/') || (!star)) {
1885                                                                         if ((currentCharacter == '\r')
1886                                                                                         || (currentCharacter == '\n')) {
1887                                                                                 checkNonExternalizeString();
1888                                                                                 if (recordLineSeparator) {
1889                                                                                         pushLineSeparator();
1890                                                                                 } else {
1891                                                                                         currentLine = null;
1892                                                                                 }
1893                                                                         }
1894                                                                         star = currentCharacter == '*';
1895                                                                         // get next char
1896                                                                         currentCharacter = source[currentPosition++];
1897                                                                         // if (((currentCharacter =
1898                                                                         // source[currentPosition++])
1899                                                                         // == '\\')
1900                                                                         // && (source[currentPosition] == 'u')) {
1901                                                                         // //-------------unicode traitement
1902                                                                         // ------------
1903                                                                         // getNextUnicodeChar();
1904                                                                         // }
1905                                                                         // handle the \\u case manually into comment
1906                                                                         // if (currentCharacter == '\\') {
1907                                                                         // if (source[currentPosition] == '\\')
1908                                                                         // currentPosition++;
1909                                                                         // } //jump over the \\
1910                                                                 }
1911                                                                 // recordComment(isJavadoc);
1912                                                                 if (isJavadoc) {
1913                                                                         recordComment(TokenName.COMMENT_PHPDOC);
1914                                                                 } else {
1915                                                                         recordComment(TokenName.COMMENT_BLOCK);
1916                                                                 }
1917
1918                                                                 if (tokenizeComments) {
1919                                                                         if (isJavadoc)
1920                                                                                 return TokenName.COMMENT_PHPDOC;
1921                                                                         return TokenName.COMMENT_BLOCK;
1922                                                                 }
1923
1924                                                                 if (this.taskTags != null) {
1925                                                                         checkTaskTag(this.startPosition,
1926                                                                                         this.currentPosition);
1927                                                                 }
1928                                                         } catch (IndexOutOfBoundsException e) {
1929                                                                 // reset end position for error reporting
1930                                                                 currentPosition -= 2;
1931                                                                 throw new InvalidInputException(
1932                                                                                 UNTERMINATED_COMMENT);
1933                                                         }
1934                                                         break;
1935                                                 }
1936                                                 return TokenName.DIVIDE;
1937                                         }
1938                                         case '\u001a':
1939                                                 if (atEnd())
1940                                                         return TokenName.EOF;
1941                                                 // the atEnd may not be <currentPosition ==
1942                                                 // source.length> if
1943                                                 // source is only some part of a real (external) stream
1944                                                 throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$
1945                                         default:
1946                                                 if (currentCharacter == '$') {
1947                                                         int oldPosition = currentPosition;
1948                                                         try {
1949                                                                 currentCharacter = source[currentPosition++];
1950                                                                 if (isPHPIdentifierStart(currentCharacter)) {
1951                                                                         return scanIdentifierOrKeyword(true);
1952                                                                 } else {
1953                                                                         currentPosition = oldPosition;
1954                                                                         return TokenName.DOLLAR;
1955                                                                 }
1956                                                         } catch (IndexOutOfBoundsException e) {
1957                                                                 currentPosition = oldPosition;
1958                                                                 return TokenName.DOLLAR;
1959                                                         }
1960                                                 }
1961                                                 
1962                                                 if (isPHPIdentifierStart(currentCharacter)) {
1963                                                         return scanIdentifierOrKeyword(false);
1964                                                 }
1965                                                 
1966                                                 if (Character.isDigit(currentCharacter)) {
1967                                                         return scanNumber(false);
1968                                                 }
1969                                                 
1970                                                 return TokenName.ERROR;
1971                                         }
1972                                 }
1973                         } // -----------------end switch while try--------------------
1974                         catch (IndexOutOfBoundsException e) {
1975                         }
1976                 }
1977                 return TokenName.EOF;
1978         }
1979
1980         /**
1981          * @return
1982          * @throws InvalidInputException
1983          */
1984         private TokenName getInlinedHTMLToken(int start) throws InvalidInputException {
1985                 boolean phpShortTag = false; // true, if <?= detected
1986                 if (currentPosition > source.length) {
1987                         currentPosition = source.length;
1988                         return TokenName.EOF;
1989                 }
1990                 startPosition = start;
1991                 try {
1992                         while (!phpMode) {
1993                                 currentCharacter = source[currentPosition++];
1994                                 if (currentCharacter == '<') {
1995                                         if (getNextChar('?')) {
1996                                                 currentCharacter = source[currentPosition++];
1997                                                 if ((currentCharacter != 'P')
1998                                                                 && (currentCharacter != 'p')) {
1999                                                         if (currentCharacter != '=') { // <?=
2000                                                                 currentPosition--;
2001                                                                 phpShortTag = false;
2002                                                         } else {
2003                                                                 phpShortTag = true;
2004                                                         }
2005                                                         // <?
2006                                                         if (ignorePHPOneLiner) { // for CodeFormatter
2007                                                                 if (lookAheadLinePHPTag() == TokenName.INLINE_HTML) {
2008                                                                         phpMode = true;
2009                                                                         if (phpShortTag) {
2010                                                                                 fFillerToken = TokenName.ECHO_INVISIBLE;
2011                                                                         }
2012                                                                         return TokenName.INLINE_HTML;
2013                                                                 }
2014                                                         } else {
2015                                                                 boolean foundXML = false;
2016                                                                 if (getNextChar('X', 'x') >= 0) {
2017                                                                         if (getNextChar('M', 'm') >= 0) {
2018                                                                                 if (getNextChar('L', 'l') >= 0) {
2019                                                                                         foundXML = true;
2020                                                                                 }
2021                                                                         }
2022                                                                 }
2023                                                                 if (!foundXML) {
2024                                                                         phpMode = true;
2025                                                                 }
2026                                                                 if (phpShortTag) {
2027                                                                         fFillerToken = TokenName.ECHO_INVISIBLE;
2028                                                                 }
2029                                                                 return TokenName.INLINE_HTML;
2030                                                         }
2031                                                 } else {
2032                                                         if (getNextChar('H', 'h') >= 0) {
2033                                                                 if (getNextChar('P', 'p') >= 0) {
2034                                                                         // <?PHP <?php
2035                                                                         if (ignorePHPOneLiner) {
2036                                                                                 if (lookAheadLinePHPTag() == TokenName.INLINE_HTML) {
2037                                                                                         phpMode = true;
2038                                                                                         return TokenName.INLINE_HTML;
2039                                                                                 }
2040                                                                         } else {
2041                                                                                 phpMode = true;
2042                                                                                 return TokenName.INLINE_HTML;
2043                                                                         }
2044                                                                 }
2045                                                         }
2046                                                         // }
2047                                                 }
2048                                         }
2049                                 }
2050                                 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
2051                                         if (recordLineSeparator) {
2052                                                 pushLineSeparator();
2053                                         } else {
2054                                                 currentLine = null;
2055                                         }
2056                                 }
2057                         } // -----------------while--------------------
2058                         phpMode = true;
2059                         return TokenName.INLINE_HTML;
2060                 } // -----------------try--------------------
2061                 catch (IndexOutOfBoundsException e) {
2062                         startPosition = start;
2063                         currentPosition--;
2064                 }
2065                 phpMode = true;
2066                 return TokenName.INLINE_HTML;
2067         }
2068
2069         /**
2070          * check if the PHP is only in this line (for CodeFormatter)
2071          *
2072          * @return
2073          */
2074         private TokenName lookAheadLinePHPTag() {
2075                 int currentPositionInLine = currentPosition;
2076                 char previousCharInLine = ' ';
2077                 char currentCharInLine = ' ';
2078                 boolean singleQuotedStringActive = false;
2079                 boolean doubleQuotedStringActive = false;
2080
2081                 try {
2082                         // look ahead in this line
2083                         while (true) {
2084                                 previousCharInLine = currentCharInLine;
2085                                 currentCharInLine = source[currentPositionInLine++];
2086                                 switch (currentCharInLine) {
2087                                 case '>':
2088                                         if (previousCharInLine == '?') {
2089                                                 // update the scanner's current Position in the source
2090                                                 currentPosition = currentPositionInLine;
2091                                                 // use as "dummy" token
2092                                                 return TokenName.EOF;
2093                                         }
2094                                         break;
2095                                 case '\\':
2096                                         if (doubleQuotedStringActive) {
2097                                                 // ignore escaped characters in double quoted strings
2098                                                 previousCharInLine = currentCharInLine;
2099                                                 currentCharInLine = source[currentPositionInLine++];
2100                                         }
2101                                 case '\"':
2102                                         if (doubleQuotedStringActive) {
2103                                                 doubleQuotedStringActive = false;
2104                                         } else {
2105                                                 if (!singleQuotedStringActive) {
2106                                                         doubleQuotedStringActive = true;
2107                                                 }
2108                                         }
2109                                         break;
2110                                 case '\'':
2111                                         if (singleQuotedStringActive) {
2112                                                 if (previousCharInLine != '\\') {
2113                                                         singleQuotedStringActive = false;
2114                                                 }
2115                                         } else {
2116                                                 if (!doubleQuotedStringActive) {
2117                                                         singleQuotedStringActive = true;
2118                                                 }
2119                                         }
2120                                         break;
2121                                 case '\n':
2122                                         phpMode = true;
2123                                         return TokenName.INLINE_HTML;
2124                                 case '#':
2125                                         if (!singleQuotedStringActive && !doubleQuotedStringActive) {
2126                                                 phpMode = true;
2127                                                 return TokenName.INLINE_HTML;
2128                                         }
2129                                         break;
2130                                 case '/':
2131                                         if (previousCharInLine == '/' && !singleQuotedStringActive
2132                                                         && !doubleQuotedStringActive) {
2133                                                 phpMode = true;
2134                                                 return TokenName.INLINE_HTML;
2135                                         }
2136                                         break;
2137                                 case '*':
2138                                         if (previousCharInLine == '/' && !singleQuotedStringActive
2139                                                         && !doubleQuotedStringActive) {
2140                                                 phpMode = true;
2141                                                 return TokenName.INLINE_HTML;
2142                                         }
2143                                         break;
2144                                 }
2145                         }
2146                 } catch (IndexOutOfBoundsException e) {
2147                         phpMode = true;
2148                         currentPosition = currentPositionInLine - 1;
2149                         return TokenName.INLINE_HTML;
2150                 }
2151         }
2152
2153         // public final void getNextUnicodeChar()
2154         // throws IndexOutOfBoundsException, InvalidInputException {
2155         // //VOID
2156         // //handle the case of unicode.
2157         // //when a unicode appears then we must use a buffer that holds char
2158         // internal values
2159         // //At the end of this method currentCharacter holds the new visited char
2160         // //and currentPosition points right next after it
2161         //
2162         // //ALL getNextChar.... ARE OPTIMIZED COPIES
2163         //
2164         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
2165         // currentPosition++;
2166         // while (source[currentPosition] == 'u') {
2167         // currentPosition++;
2168         // unicodeSize++;
2169         // }
2170         //
2171         // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2172         // || c1 < 0
2173         // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
2174         // || c2 < 0
2175         // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
2176         // || c3 < 0
2177         // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
2178         // || c4 < 0) {
2179         // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2180         // } else {
2181         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2182         // //need the unicode buffer
2183         // if (withoutUnicodePtr == 0) {
2184         // //buffer all the entries that have been left aside....
2185         // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
2186         // System.arraycopy(
2187         // source,
2188         // startPosition,
2189         // withoutUnicodeBuffer,
2190         // 1,
2191         // withoutUnicodePtr);
2192         // }
2193         // //fill the buffer with the char
2194         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2195         // }
2196         // unicodeAsBackSlash = currentCharacter == '\\';
2197         // }
2198         /*
2199          * Tokenize a method body, assuming that curly brackets are properly
2200          * balanced.
2201          */
2202         public final void jumpOverMethodBody() {
2203                 this.wasAcr = false;
2204                 int found = 1;
2205                 try {
2206                         while (true) { // loop for jumping over comments
2207                                 // ---------Consume white space and handles
2208                                 // startPosition---------
2209                                 boolean isWhiteSpace;
2210                                 do {
2211                                         startPosition = currentPosition;
2212                                         currentCharacter = source[currentPosition++];
2213                                         // if (((currentCharacter = source[currentPosition++]) ==
2214                                         // '\\')
2215                                         // && (source[currentPosition] == 'u')) {
2216                                         // isWhiteSpace = jumpOverUnicodeWhiteSpace();
2217                                         // } else {
2218                                         if (recordLineSeparator
2219                                                         && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2220                                                 pushLineSeparator();
2221                                         isWhiteSpace = Character.isWhitespace(currentCharacter);
2222                                         // }
2223                                 } while (isWhiteSpace);
2224                                 // -------consume token until } is found---------
2225                                 switch (currentCharacter) {
2226                                 case '{':
2227                                         found++;
2228                                         break;
2229                                 case '}':
2230                                         found--;
2231                                         if (found == 0)
2232                                                 return;
2233                                         break;
2234                                 case '\'': {
2235                                         boolean test;
2236                                         test = getNextChar('\\');
2237                                         if (test) {
2238                                                 try {
2239                                                         scanDoubleQuotedEscapeCharacter();
2240                                                 } catch (InvalidInputException ex) {
2241                                                 }
2242                                                 ;
2243                                         } else {
2244                                                 // try { // consume next character
2245                                                 unicodeAsBackSlash = false;
2246                                                 currentCharacter = source[currentPosition++];
2247                                                 // if (((currentCharacter = source[currentPosition++])
2248                                                 // == '\\')
2249                                                 // && (source[currentPosition] == 'u')) {
2250                                                 // getNextUnicodeChar();
2251                                                 // } else {
2252                                                 if (withoutUnicodePtr != 0) {
2253                                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2254                                                 }
2255                                                 // }
2256                                                 // } catch (InvalidInputException ex) {
2257                                                 // };
2258                                         }
2259                                         getNextChar('\'');
2260                                         break;
2261                                 }
2262                                 case '"':
2263                                         try {
2264                                                 // try { // consume next character
2265                                                 unicodeAsBackSlash = false;
2266                                                 currentCharacter = source[currentPosition++];
2267                                                 // if (((currentCharacter = source[currentPosition++])
2268                                                 // == '\\')
2269                                                 // && (source[currentPosition] == 'u')) {
2270                                                 // getNextUnicodeChar();
2271                                                 // } else {
2272                                                 if (withoutUnicodePtr != 0) {
2273                                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2274                                                 }
2275                                                 // }
2276                                                 // } catch (InvalidInputException ex) {
2277                                                 // };
2278                                                 while (currentCharacter != '"') {
2279                                                         if (currentCharacter == '\r') {
2280                                                                 if (source[currentPosition] == '\n')
2281                                                                         currentPosition++;
2282                                                                 break;
2283                                                                 // the string cannot go further that the line
2284                                                         }
2285                                                         if (currentCharacter == '\n') {
2286                                                                 break;
2287                                                                 // the string cannot go further that the line
2288                                                         }
2289                                                         if (currentCharacter == '\\') {
2290                                                                 try {
2291                                                                         scanDoubleQuotedEscapeCharacter();
2292                                                                 } catch (InvalidInputException ex) {
2293                                                                 }
2294                                                                 ;
2295                                                         }
2296                                                         // try { // consume next character
2297                                                         unicodeAsBackSlash = false;
2298                                                         currentCharacter = source[currentPosition++];
2299                                                         // if (((currentCharacter =
2300                                                         // source[currentPosition++]) == '\\')
2301                                                         // && (source[currentPosition] == 'u')) {
2302                                                         // getNextUnicodeChar();
2303                                                         // } else {
2304                                                         if (withoutUnicodePtr != 0) {
2305                                                                 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2306                                                         }
2307                                                         // }
2308                                                         // } catch (InvalidInputException ex) {
2309                                                         // };
2310                                                 }
2311                                         } catch (IndexOutOfBoundsException e) {
2312                                                 return;
2313                                         }
2314                                         break;
2315                                 case '/': {
2316                                         int test;
2317                                         if ((test = getNextChar('/', '*')) == 0) {
2318                                                 // line comment
2319                                                 try {
2320                                                         // get the next char
2321                                                         currentCharacter = source[currentPosition++];
2322                                                         // if (((currentCharacter =
2323                                                         // source[currentPosition++]) ==
2324                                                         // '\\')
2325                                                         // && (source[currentPosition] == 'u')) {
2326                                                         // //-------------unicode traitement ------------
2327                                                         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2328                                                         // currentPosition++;
2329                                                         // while (source[currentPosition] == 'u') {
2330                                                         // currentPosition++;
2331                                                         // }
2332                                                         // if ((c1 =
2333                                                         // Character.getNumericValue(source[currentPosition++]))
2334                                                         // > 15
2335                                                         // || c1 < 0
2336                                                         // || (c2 =
2337                                                         // Character.getNumericValue(source[currentPosition++]))
2338                                                         // > 15
2339                                                         // || c2 < 0
2340                                                         // || (c3 =
2341                                                         // Character.getNumericValue(source[currentPosition++]))
2342                                                         // > 15
2343                                                         // || c3 < 0
2344                                                         // || (c4 =
2345                                                         // Character.getNumericValue(source[currentPosition++]))
2346                                                         // > 15
2347                                                         // || c4 < 0) {
2348                                                         // //error don't care of the value
2349                                                         // currentCharacter = 'A';
2350                                                         // } //something different from \n and \r
2351                                                         // else {
2352                                                         // currentCharacter =
2353                                                         // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2354                                                         // }
2355                                                         // }
2356                                                         while (currentCharacter != '\r'
2357                                                                         && currentCharacter != '\n') {
2358                                                                 // get the next char
2359                                                                 currentCharacter = source[currentPosition++];
2360                                                                 // if (((currentCharacter =
2361                                                                 // source[currentPosition++])
2362                                                                 // == '\\')
2363                                                                 // && (source[currentPosition] == 'u')) {
2364                                                                 // //-------------unicode traitement
2365                                                                 // ------------
2366                                                                 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2367                                                                 // currentPosition++;
2368                                                                 // while (source[currentPosition] == 'u') {
2369                                                                 // currentPosition++;
2370                                                                 // }
2371                                                                 // if ((c1 =
2372                                                                 // Character.getNumericValue(source[currentPosition++]))
2373                                                                 // > 15
2374                                                                 // || c1 < 0
2375                                                                 // || (c2 =
2376                                                                 // Character.getNumericValue(source[currentPosition++]))
2377                                                                 // > 15
2378                                                                 // || c2 < 0
2379                                                                 // || (c3 =
2380                                                                 // Character.getNumericValue(source[currentPosition++]))
2381                                                                 // > 15
2382                                                                 // || c3 < 0
2383                                                                 // || (c4 =
2384                                                                 // Character.getNumericValue(source[currentPosition++]))
2385                                                                 // > 15
2386                                                                 // || c4 < 0) {
2387                                                                 // //error don't care of the value
2388                                                                 // currentCharacter = 'A';
2389                                                                 // } //something different from \n and \r
2390                                                                 // else {
2391                                                                 // currentCharacter =
2392                                                                 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
2393                                                                 // c4);
2394                                                                 // }
2395                                                                 // }
2396                                                         }
2397                                                         if (recordLineSeparator
2398                                                                         && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2399                                                                 pushLineSeparator();
2400                                                 } catch (IndexOutOfBoundsException e) {
2401                                                 } // an eof will them be generated
2402                                                 break;
2403                                         }
2404                                         if (test > 0) {
2405                                                 // traditional and annotation comment
2406                                                 boolean star = false;
2407                                                 // try { // consume next character
2408                                                 unicodeAsBackSlash = false;
2409                                                 currentCharacter = source[currentPosition++];
2410                                                 // if (((currentCharacter = source[currentPosition++])
2411                                                 // == '\\')
2412                                                 // && (source[currentPosition] == 'u')) {
2413                                                 // getNextUnicodeChar();
2414                                                 // } else {
2415                                                 if (withoutUnicodePtr != 0) {
2416                                                         withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2417                                                 }
2418                                                 // };
2419                                                 // } catch (InvalidInputException ex) {
2420                                                 // };
2421                                                 if (currentCharacter == '*') {
2422                                                         star = true;
2423                                                 }
2424                                                 if (recordLineSeparator
2425                                                                 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2426                                                         pushLineSeparator();
2427                                                 try { // get the next char
2428                                                         currentCharacter = source[currentPosition++];
2429                                                         // if (((currentCharacter =
2430                                                         // source[currentPosition++]) ==
2431                                                         // '\\')
2432                                                         // && (source[currentPosition] == 'u')) {
2433                                                         // //-------------unicode traitement ------------
2434                                                         // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2435                                                         // currentPosition++;
2436                                                         // while (source[currentPosition] == 'u') {
2437                                                         // currentPosition++;
2438                                                         // }
2439                                                         // if ((c1 =
2440                                                         // Character.getNumericValue(source[currentPosition++]))
2441                                                         // > 15
2442                                                         // || c1 < 0
2443                                                         // || (c2 =
2444                                                         // Character.getNumericValue(source[currentPosition++]))
2445                                                         // > 15
2446                                                         // || c2 < 0
2447                                                         // || (c3 =
2448                                                         // Character.getNumericValue(source[currentPosition++]))
2449                                                         // > 15
2450                                                         // || c3 < 0
2451                                                         // || (c4 =
2452                                                         // Character.getNumericValue(source[currentPosition++]))
2453                                                         // > 15
2454                                                         // || c4 < 0) {
2455                                                         // //error don't care of the value
2456                                                         // currentCharacter = 'A';
2457                                                         // } //something different from * and /
2458                                                         // else {
2459                                                         // currentCharacter =
2460                                                         // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2461                                                         // }
2462                                                         // }
2463                                                         // loop until end of comment */
2464                                                         while ((currentCharacter != '/') || (!star)) {
2465                                                                 if (recordLineSeparator
2466                                                                                 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2467                                                                         pushLineSeparator();
2468                                                                 star = currentCharacter == '*';
2469                                                                 // get next char
2470                                                                 currentCharacter = source[currentPosition++];
2471                                                                 // if (((currentCharacter =
2472                                                                 // source[currentPosition++])
2473                                                                 // == '\\')
2474                                                                 // && (source[currentPosition] == 'u')) {
2475                                                                 // //-------------unicode traitement
2476                                                                 // ------------
2477                                                                 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2478                                                                 // currentPosition++;
2479                                                                 // while (source[currentPosition] == 'u') {
2480                                                                 // currentPosition++;
2481                                                                 // }
2482                                                                 // if ((c1 =
2483                                                                 // Character.getNumericValue(source[currentPosition++]))
2484                                                                 // > 15
2485                                                                 // || c1 < 0
2486                                                                 // || (c2 =
2487                                                                 // Character.getNumericValue(source[currentPosition++]))
2488                                                                 // > 15
2489                                                                 // || c2 < 0
2490                                                                 // || (c3 =
2491                                                                 // Character.getNumericValue(source[currentPosition++]))
2492                                                                 // > 15
2493                                                                 // || c3 < 0
2494                                                                 // || (c4 =
2495                                                                 // Character.getNumericValue(source[currentPosition++]))
2496                                                                 // > 15
2497                                                                 // || c4 < 0) {
2498                                                                 // //error don't care of the value
2499                                                                 // currentCharacter = 'A';
2500                                                                 // } //something different from * and /
2501                                                                 // else {
2502                                                                 // currentCharacter =
2503                                                                 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
2504                                                                 // c4);
2505                                                                 // }
2506                                                                 // }
2507                                                         }
2508                                                 } catch (IndexOutOfBoundsException e) {
2509                                                         return;
2510                                                 }
2511                                                 break;
2512                                         }
2513                                         break;
2514                                 }
2515                                 default:
2516                                         if (isPHPIdentOrVarStart(currentCharacter)) {
2517                                                 try {
2518                                                         scanIdentifierOrKeyword((currentCharacter == '$'));
2519                                                 } catch (InvalidInputException ex) {
2520                                                 }
2521                                                 ;
2522                                                 break;
2523                                         }
2524                                         if (ObviousIdentCharNatures[currentCharacter] == C_DIGIT) {
2525                                                 // if (Character.isDigit(currentCharacter)) {
2526                                                 try {
2527                                                         scanNumber(false);
2528                                                 } catch (InvalidInputException ex) {
2529                                                 }
2530                                                 ;
2531                                                 break;
2532                                         }
2533                                 }
2534                         }
2535                         // -----------------end switch while try--------------------
2536                 } catch (IndexOutOfBoundsException e) {
2537                 } catch (InvalidInputException e) {
2538                 }
2539                 return;
2540         }
2541
2542         // public final boolean jumpOverUnicodeWhiteSpace()
2543         // throws InvalidInputException {
2544         // //BOOLEAN
2545         // //handle the case of unicode. Jump over the next whiteSpace
2546         // //making startPosition pointing on the next available char
2547         // //On false, the currentCharacter is filled up with a potential
2548         // //correct char
2549         //
2550         // try {
2551         // this.wasAcr = false;
2552         // int c1, c2, c3, c4;
2553         // int unicodeSize = 6;
2554         // currentPosition++;
2555         // while (source[currentPosition] == 'u') {
2556         // currentPosition++;
2557         // unicodeSize++;
2558         // }
2559         //
2560         // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2561         // || c1 < 0)
2562         // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2563         // || c2 < 0)
2564         // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2565         // || c3 < 0)
2566         // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2567         // || c4 < 0)) {
2568         // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2569         // }
2570         //
2571         // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2572         // if (recordLineSeparator
2573         // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2574         // pushLineSeparator();
2575         // if (Character.isWhitespace(currentCharacter))
2576         // return true;
2577         //
2578         // //buffer the new char which is not a white space
2579         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2580         // //withoutUnicodePtr == 1 is true here
2581         // return false;
2582         // } catch (IndexOutOfBoundsException e) {
2583         // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2584         // }
2585         // }
2586         public final int[] getLineEnds() {
2587                 // return a bounded copy of this.lineEnds
2588                 int[] copy;
2589                 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0,
2590                                 linePtr + 1);
2591                 return copy;
2592         }
2593
2594         public char[] getSource() {
2595                 return this.source;
2596         }
2597
2598         public static boolean isIdentifierOrKeyword (TokenName token) {
2599                 return (token == TokenName.IDENTIFIER) || (token.compareTo (TokenName.KEYWORD) > 0);
2600         }
2601
2602         final char[] optimizedCurrentTokenSource1() {
2603                 // return always the same char[] build only once
2604                 // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2605                 char charOne = source[startPosition];
2606                 switch (charOne) {
2607                 case 'a':
2608                         return charArray_a;
2609                 case 'b':
2610                         return charArray_b;
2611                 case 'c':
2612                         return charArray_c;
2613                 case 'd':
2614                         return charArray_d;
2615                 case 'e':
2616                         return charArray_e;
2617                 case 'f':
2618                         return charArray_f;
2619                 case 'g':
2620                         return charArray_g;
2621                 case 'h':
2622                         return charArray_h;
2623                 case 'i':
2624                         return charArray_i;
2625                 case 'j':
2626                         return charArray_j;
2627                 case 'k':
2628                         return charArray_k;
2629                 case 'l':
2630                         return charArray_l;
2631                 case 'm':
2632                         return charArray_m;
2633                 case 'n':
2634                         return charArray_n;
2635                 case 'o':
2636                         return charArray_o;
2637                 case 'p':
2638                         return charArray_p;
2639                 case 'q':
2640                         return charArray_q;
2641                 case 'r':
2642                         return charArray_r;
2643                 case 's':
2644                         return charArray_s;
2645                 case 't':
2646                         return charArray_t;
2647                 case 'u':
2648                         return charArray_u;
2649                 case 'v':
2650                         return charArray_v;
2651                 case 'w':
2652                         return charArray_w;
2653                 case 'x':
2654                         return charArray_x;
2655                 case 'y':
2656                         return charArray_y;
2657                 case 'z':
2658                         return charArray_z;
2659                 default:
2660                         return new char[] { charOne };
2661                 }
2662         }
2663
2664         final char[] optimizedCurrentTokenSource2() {
2665                 char c0, c1;
2666                 c0 = source[startPosition];
2667                 c1 = source[startPosition + 1];
2668                 if (c0 == '$') {
2669                         // return always the same char[] build only once
2670                         // optimization at no speed cost of 99.5 % of the
2671                         // singleCharIdentifier
2672                         switch (c1) {
2673                         case 'a':
2674                                 return charArray_va;
2675                         case 'b':
2676                                 return charArray_vb;
2677                         case 'c':
2678                                 return charArray_vc;
2679                         case 'd':
2680                                 return charArray_vd;
2681                         case 'e':
2682                                 return charArray_ve;
2683                         case 'f':
2684                                 return charArray_vf;
2685                         case 'g':
2686                                 return charArray_vg;
2687                         case 'h':
2688                                 return charArray_vh;
2689                         case 'i':
2690                                 return charArray_vi;
2691                         case 'j':
2692                                 return charArray_vj;
2693                         case 'k':
2694                                 return charArray_vk;
2695                         case 'l':
2696                                 return charArray_vl;
2697                         case 'm':
2698                                 return charArray_vm;
2699                         case 'n':
2700                                 return charArray_vn;
2701                         case 'o':
2702                                 return charArray_vo;
2703                         case 'p':
2704                                 return charArray_vp;
2705                         case 'q':
2706                                 return charArray_vq;
2707                         case 'r':
2708                                 return charArray_vr;
2709                         case 's':
2710                                 return charArray_vs;
2711                         case 't':
2712                                 return charArray_vt;
2713                         case 'u':
2714                                 return charArray_vu;
2715                         case 'v':
2716                                 return charArray_vv;
2717                         case 'w':
2718                                 return charArray_vw;
2719                         case 'x':
2720                                 return charArray_vx;
2721                         case 'y':
2722                                 return charArray_vy;
2723                         case 'z':
2724                                 return charArray_vz;
2725                         }
2726                 }
2727                 // try to return the same char[] build only once
2728                 int hash = ((c0 << 6) + c1) % TableSize;
2729                 char[][] table = charArray_length[0][hash];
2730                 int i = newEntry2;
2731                 while (++i < InternalTableSize) {
2732                         char[] charArray = table[i];
2733                         if ((c0 == charArray[0]) && (c1 == charArray[1]))
2734                                 return charArray;
2735                 }
2736                 // ---------other side---------
2737                 i = -1;
2738                 int max = newEntry2;
2739                 while (++i <= max) {
2740                         char[] charArray = table[i];
2741                         if ((c0 == charArray[0]) && (c1 == charArray[1]))
2742                                 return charArray;
2743                 }
2744                 // --------add the entry-------
2745                 if (++max >= InternalTableSize)
2746                         max = 0;
2747                 char[] r;
2748                 table[max] = (r = new char[] { c0, c1 });
2749                 newEntry2 = max;
2750                 return r;
2751         }
2752
2753         final char[] optimizedCurrentTokenSource3() {
2754                 // try to return the same char[] build only once
2755                 char c0, c1, c2;
2756                 int hash = (((c0 = source[startPosition]) << 12)
2757                                 + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2758                                 % TableSize;
2759                 char[][] table = charArray_length[1][hash];
2760                 int i = newEntry3;
2761                 while (++i < InternalTableSize) {
2762                         char[] charArray = table[i];
2763                         if ((c0 == charArray[0]) && (c1 == charArray[1])
2764                                         && (c2 == charArray[2]))
2765                                 return charArray;
2766                 }
2767                 // ---------other side---------
2768                 i = -1;
2769                 int max = newEntry3;
2770                 while (++i <= max) {
2771                         char[] charArray = table[i];
2772                         if ((c0 == charArray[0]) && (c1 == charArray[1])
2773                                         && (c2 == charArray[2]))
2774                                 return charArray;
2775                 }
2776                 // --------add the entry-------
2777                 if (++max >= InternalTableSize)
2778                         max = 0;
2779                 char[] r;
2780                 table[max] = (r = new char[] { c0, c1, c2 });
2781                 newEntry3 = max;
2782                 return r;
2783         }
2784
2785         final char[] optimizedCurrentTokenSource4() {
2786                 // try to return the same char[] build only once
2787                 char c0, c1, c2, c3;
2788                 long hash = ((((long) (c0 = source[startPosition])) << 18)
2789                                 + ((c1 = source[startPosition + 1]) << 12)
2790                                 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2791                                 % TableSize;
2792                 char[][] table = charArray_length[2][(int) hash];
2793                 int i = newEntry4;
2794                 while (++i < InternalTableSize) {
2795                         char[] charArray = table[i];
2796                         if ((c0 == charArray[0]) && (c1 == charArray[1])
2797                                         && (c2 == charArray[2]) && (c3 == charArray[3]))
2798                                 return charArray;
2799                 }
2800                 // ---------other side---------
2801                 i = -1;
2802
2803                 int max = newEntry4;
2804                 while (++i <= max) {
2805                         char[] charArray = table[i];
2806                         if ((c0 == charArray[0]) && (c1 == charArray[1])
2807                                         && (c2 == charArray[2]) && (c3 == charArray[3]))
2808                                 return charArray;
2809                 }
2810                 // --------add the entry-------
2811                 if (++max >= InternalTableSize)
2812                         max = 0;
2813                 char[] r;
2814                 table[max] = (r = new char[] { c0, c1, c2, c3 });
2815                 newEntry4 = max;
2816                 return r;
2817         }
2818
2819         final char[] optimizedCurrentTokenSource5() {
2820                 // try to return the same char[] build only once
2821                 char c0, c1, c2, c3, c4;
2822                 long hash = ((((long) (c0 = source[startPosition])) << 24)
2823                                 + (((long) (c1 = source[startPosition + 1])) << 18)
2824                                 + ((c2 = source[startPosition + 2]) << 12)
2825                                 + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2826                                 % TableSize;
2827                 char[][] table = charArray_length[3][(int) hash];
2828                 int i = newEntry5;
2829                 while (++i < InternalTableSize) {
2830                         char[] charArray = table[i];
2831                         if ((c0 == charArray[0]) && (c1 == charArray[1])
2832                                         && (c2 == charArray[2]) && (c3 == charArray[3])
2833                                         && (c4 == charArray[4]))
2834                                 return charArray;
2835                 }
2836                 // ---------other side---------
2837                 i = -1;
2838                 int max = newEntry5;
2839                 while (++i <= max) {
2840                         char[] charArray = table[i];
2841                         if ((c0 == charArray[0]) && (c1 == charArray[1])
2842                                         && (c2 == charArray[2]) && (c3 == charArray[3])
2843                                         && (c4 == charArray[4]))
2844                                 return charArray;
2845                 }
2846                 // --------add the entry-------
2847                 if (++max >= InternalTableSize)
2848                         max = 0;
2849                 char[] r;
2850                 table[max] = (r = new char[] { c0, c1, c2, c3, c4 });
2851                 newEntry5 = max;
2852                 return r;
2853         }
2854
2855         final char[] optimizedCurrentTokenSource6() {
2856                 // try to return the same char[] build only once
2857                 char c0, c1, c2, c3, c4, c5;
2858                 long hash = ((((long) (c0 = source[startPosition])) << 32)
2859                                 + (((long) (c1 = source[startPosition + 1])) << 24)
2860                                 + (((long) (c2 = source[startPosition + 2])) << 18)
2861                                 + ((c3 = source[startPosition + 3]) << 12)
2862                                 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2863                                 % TableSize;
2864                 char[][] table = charArray_length[4][(int) hash];
2865                 int i = newEntry6;
2866                 while (++i < InternalTableSize) {
2867                         char[] charArray = table[i];
2868                         if ((c0 == charArray[0]) && (c1 == charArray[1])
2869                                         && (c2 == charArray[2]) && (c3 == charArray[3])
2870                                         && (c4 == charArray[4]) && (c5 == charArray[5]))
2871                                 return charArray;
2872                 }
2873                 // ---------other side---------
2874                 i = -1;
2875                 int max = newEntry6;
2876                 while (++i <= max) {
2877                         char[] charArray = table[i];
2878                         if ((c0 == charArray[0]) && (c1 == charArray[1])
2879                                         && (c2 == charArray[2]) && (c3 == charArray[3])
2880                                         && (c4 == charArray[4]) && (c5 == charArray[5]))
2881                                 return charArray;
2882                 }
2883                 // --------add the entry-------
2884                 if (++max >= InternalTableSize)
2885                         max = 0;
2886                 char[] r;
2887                 table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 });
2888                 newEntry6 = max;
2889                 return r;
2890         }
2891
2892         public final void pushLineSeparator() throws InvalidInputException {
2893                 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2894                 final int INCREMENT = 250;
2895                 if (this.checkNonExternalizedStringLiterals) {
2896                         // reinitialize the current line for non externalize strings purpose
2897                         currentLine = null;
2898                 }
2899                 // currentCharacter is at position currentPosition-1
2900                 // cr 000D
2901                 if (currentCharacter == '\r') {
2902                         int separatorPos = currentPosition - 1;
2903                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2904                                 return;
2905                         // System.out.println("CR-" + separatorPos);
2906                         try {
2907                                 lineEnds[++linePtr] = separatorPos;
2908                         } catch (IndexOutOfBoundsException e) {
2909                                 // linePtr value is correct
2910                                 int oldLength = lineEnds.length;
2911                                 int[] old = lineEnds;
2912                                 lineEnds = new int[oldLength + INCREMENT];
2913                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2914                                 lineEnds[linePtr] = separatorPos;
2915                         }
2916                         // look-ahead for merged cr+lf
2917                         try {
2918                                 if (source[currentPosition] == '\n') {
2919                                         // System.out.println("look-ahead LF-" + currentPosition);
2920                                         lineEnds[linePtr] = currentPosition;
2921                                         currentPosition++;
2922                                         wasAcr = false;
2923                                 } else {
2924                                         wasAcr = true;
2925                                 }
2926                         } catch (IndexOutOfBoundsException e) {
2927                                 wasAcr = true;
2928                         }
2929                 } else {
2930                         // lf 000A
2931                         if (currentCharacter == '\n') {
2932                                 // must merge eventual cr followed by lf
2933                                 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2934                                         // System.out.println("merge LF-" + (currentPosition - 1));
2935                                         lineEnds[linePtr] = currentPosition - 1;
2936                                 } else {
2937                                         int separatorPos = currentPosition - 1;
2938                                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2939                                                 return;
2940                                         // System.out.println("LF-" + separatorPos);
2941                                         try {
2942                                                 lineEnds[++linePtr] = separatorPos;
2943                                         } catch (IndexOutOfBoundsException e) {
2944                                                 // linePtr value is correct
2945                                                 int oldLength = lineEnds.length;
2946                                                 int[] old = lineEnds;
2947                                                 lineEnds = new int[oldLength + INCREMENT];
2948                                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2949                                                 lineEnds[linePtr] = separatorPos;
2950                                         }
2951                                 }
2952                                 wasAcr = false;
2953                         }
2954                 }
2955         }
2956
2957         public final void pushUnicodeLineSeparator() {
2958                 // isUnicode means that the \r or \n has been read as a unicode
2959                 // character
2960                 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2961                 final int INCREMENT = 250;
2962                 // currentCharacter is at position currentPosition-1
2963                 if (this.checkNonExternalizedStringLiterals) {
2964                         // reinitialize the current line for non externalize strings purpose
2965                         currentLine = null;
2966                 }
2967                 // cr 000D
2968                 if (currentCharacter == '\r') {
2969                         int separatorPos = currentPosition - 6;
2970                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2971                                 return;
2972                         // System.out.println("CR-" + separatorPos);
2973                         try {
2974                                 lineEnds[++linePtr] = separatorPos;
2975                         } catch (IndexOutOfBoundsException e) {
2976                                 // linePtr value is correct
2977                                 int oldLength = lineEnds.length;
2978                                 int[] old = lineEnds;
2979                                 lineEnds = new int[oldLength + INCREMENT];
2980                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2981                                 lineEnds[linePtr] = separatorPos;
2982                         }
2983                         // look-ahead for merged cr+lf
2984                         if (source[currentPosition] == '\n') {
2985                                 // System.out.println("look-ahead LF-" + currentPosition);
2986                                 lineEnds[linePtr] = currentPosition;
2987                                 currentPosition++;
2988                                 wasAcr = false;
2989                         } else {
2990                                 wasAcr = true;
2991                         }
2992                 } else {
2993                         // lf 000A
2994                         if (currentCharacter == '\n') {
2995                                 // must merge eventual cr followed by lf
2996                                 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2997                                         // System.out.println("merge LF-" + (currentPosition - 1));
2998                                         lineEnds[linePtr] = currentPosition - 6;
2999                                 } else {
3000                                         int separatorPos = currentPosition - 6;
3001                                         if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
3002                                                 return;
3003                                         // System.out.println("LF-" + separatorPos);
3004                                         try {
3005                                                 lineEnds[++linePtr] = separatorPos;
3006                                         } catch (IndexOutOfBoundsException e) {
3007                                                 // linePtr value is correct
3008                                                 int oldLength = lineEnds.length;
3009                                                 int[] old = lineEnds;
3010                                                 lineEnds = new int[oldLength + INCREMENT];
3011                                                 System.arraycopy(old, 0, lineEnds, 0, oldLength);
3012                                                 lineEnds[linePtr] = separatorPos;
3013                                         }
3014                                 }
3015                                 wasAcr = false;
3016                         }
3017                 }
3018         }
3019
3020         public void recordComment(TokenName token) {
3021                 // compute position
3022                 int stopPosition = this.currentPosition;
3023                 switch (token) {
3024                 case COMMENT_LINE:
3025                         stopPosition = -this.lastCommentLinePosition;
3026                         break;
3027                 case COMMENT_BLOCK:
3028                         stopPosition = -this.currentPosition;
3029                         break;
3030                 }
3031
3032                 // a new comment is recorded
3033                 int length = this.commentStops.length;
3034                 if (++this.commentPtr >= length) {
3035                         System.arraycopy(this.commentStops, 0,
3036                                         this.commentStops = new int[length + 30], 0, length);
3037                         // grows the positions buffers too
3038                         System.arraycopy(this.commentStarts, 0,
3039                                         this.commentStarts = new int[length + 30], 0, length);
3040                 }
3041                 this.commentStops[this.commentPtr] = stopPosition;
3042                 this.commentStarts[this.commentPtr] = this.startPosition;
3043         }
3044
3045         // public final void recordComment(boolean isJavadoc) {
3046         // // a new annotation comment is recorded
3047         // try {
3048         // commentStops[++commentPtr] = isJavadoc
3049         // ? currentPosition
3050         // : -currentPosition;
3051         // } catch (IndexOutOfBoundsException e) {
3052         // int oldStackLength = commentStops.length;
3053         // int[] oldStack = commentStops;
3054         // commentStops = new int[oldStackLength + 30];
3055         // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
3056         // commentStops[commentPtr] = isJavadoc ? currentPosition :
3057         // -currentPosition;
3058         // //grows the positions buffers too
3059         // int[] old = commentStarts;
3060         // commentStarts = new int[oldStackLength + 30];
3061         // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
3062         // }
3063         // //the buffer is of a correct size here
3064         // commentStarts[commentPtr] = startPosition;
3065         // }
3066         public void resetTo(int begin, int end) {
3067                 // reset the scanner to a given position where it may rescan again
3068                 diet = false;
3069                 initialPosition = startPosition = currentPosition = begin;
3070                 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
3071                 commentPtr = -1; // reset comment stack
3072         }
3073
3074         public final void scanSingleQuotedEscapeCharacter()
3075                         throws InvalidInputException {
3076                 // the string with "\\u" is a legal string of two chars \ and u
3077                 // thus we use a direct access to the source (for regular cases).
3078                 // if (unicodeAsBackSlash) {
3079                 // // consume next character
3080                 // unicodeAsBackSlash = false;
3081                 // if (((currentCharacter = source[currentPosition++]) == '\\')
3082                 // && (source[currentPosition] == 'u')) {
3083                 // getNextUnicodeChar();
3084                 // } else {
3085                 // if (withoutUnicodePtr != 0) {
3086                 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3087                 // }
3088                 // }
3089                 // } else
3090                 currentCharacter = source[currentPosition++];
3091                 switch (currentCharacter) {
3092                 case '\'':
3093                         currentCharacter = '\'';
3094                         break;
3095                 case '\\':
3096                         currentCharacter = '\\';
3097                         break;
3098                 default:
3099                         currentCharacter = '\\';
3100                         currentPosition--;
3101                 }
3102         }
3103
3104         public final void scanDoubleQuotedEscapeCharacter()
3105                         throws InvalidInputException {
3106                 currentCharacter = source[currentPosition++];
3107                 switch (currentCharacter) {
3108                 // case 'b' :
3109                 // currentCharacter = '\b';
3110                 // break;
3111                 case 't':
3112                         currentCharacter = '\t';
3113                         break;
3114                 case 'n':
3115                         currentCharacter = '\n';
3116                         break;
3117                 // case 'f' :
3118                 // currentCharacter = '\f';
3119                 // break;
3120                 case 'r':
3121                         currentCharacter = '\r';
3122                         break;
3123                 case '\"':
3124                         currentCharacter = '\"';
3125                         break;
3126                 case '\'':
3127                         currentCharacter = '\'';
3128                         break;
3129                 case '\\':
3130                         currentCharacter = '\\';
3131                         break;
3132                 case '$':
3133                         currentCharacter = '$';
3134                         break;
3135                 default:
3136                         // -----------octal escape--------------
3137                         // OctalDigit
3138                         // OctalDigit OctalDigit
3139                         // ZeroToThree OctalDigit OctalDigit
3140                         int number = Character.getNumericValue(currentCharacter);
3141                         if (number >= 0 && number <= 7) {
3142                                 boolean zeroToThreeNot = number > 3;
3143                                 if (Character
3144                                                 .isDigit(currentCharacter = source[currentPosition++])) {
3145                                         int digit = Character.getNumericValue(currentCharacter);
3146                                         if (digit >= 0 && digit <= 7) {
3147                                                 number = (number * 8) + digit;
3148                                                 if (Character
3149                                                                 .isDigit(currentCharacter = source[currentPosition++])) {
3150                                                         if (zeroToThreeNot) { // has read \NotZeroToThree
3151                                                                                                         // OctalDigit
3152                                                                 // Digit --> ignore last character
3153                                                                 currentPosition--;
3154                                                         } else {
3155                                                                 digit = Character
3156                                                                                 .getNumericValue(currentCharacter);
3157                                                                 if (digit >= 0 && digit <= 7) {
3158                                                                         // has read \ZeroToThree OctalDigit
3159                                                                         // OctalDigit
3160                                                                         number = (number * 8) + digit;
3161                                                                 } else { // has read \ZeroToThree OctalDigit
3162                                                                                         // NonOctalDigit
3163                                                                         // --> ignore last character
3164                                                                         currentPosition--;
3165                                                                 }
3166                                                         }
3167                                                 } else { // has read \OctalDigit NonDigit--> ignore
3168                                                                         // last
3169                                                         // character
3170                                                         currentPosition--;
3171                                                 }
3172                                         } else { // has read \OctalDigit NonOctalDigit--> ignore
3173                                                                 // last
3174                                                 // character
3175                                                 currentPosition--;
3176                                         }
3177                                 } else { // has read \OctalDigit --> ignore last character
3178                                         currentPosition--;
3179                                 }
3180                                 if (number > 255)
3181                                         throw new InvalidInputException(INVALID_ESCAPE);
3182                                 currentCharacter = (char) number;
3183                         }
3184                         // else
3185                         // throw new InvalidInputException(INVALID_ESCAPE);
3186                 }
3187         }
3188
3189         // public int scanIdentifierOrKeyword() throws InvalidInputException {
3190         // return scanIdentifierOrKeyword( false );
3191         // }
3192         public TokenName scanIdentifierOrKeyword(boolean isVariable)
3193                         throws InvalidInputException {
3194                 // test keywords
3195                 // first dispatch on the first char.
3196                 // then the length. If there are several
3197                 // keywords with the same length AND the same first char, then do another
3198                 // disptach on the second char :-)...cool....but fast !
3199                 useAssertAsAnIndentifier = false;
3200                 while (getNextCharAsJavaIdentifierPart()) {
3201                 }
3202                 ;
3203                 if (isVariable) {
3204                         // if (new String(getCurrentTokenSource()).equals("$this")) {
3205                         // return TokenName.this;
3206                         // }
3207                         return TokenName.VARIABLE;
3208                 }
3209                 int index, length;
3210                 char[] data;
3211                 char firstLetter;
3212                 // if (withoutUnicodePtr == 0)
3213                 // quick test on length == 1 but not on length > 12 while most
3214                 // identifier
3215                 // have a length which is <= 12...but there are lots of identifier with
3216                 // only one char....
3217                 // {
3218                 if ((length = currentPosition - startPosition) == 1)
3219                         return TokenName.IDENTIFIER;
3220                 // data = source;
3221                 data = new char[length];
3222                 index = startPosition;
3223                 for (int i = 0; i < length; i++) {
3224                         data[i] = Character.toLowerCase(source[index + i]);
3225                 }
3226                 index = 0;
3227                 // } else {
3228                 // if ((length = withoutUnicodePtr) == 1)
3229                 // return TokenName.Identifier;
3230                 // // data = withoutUnicodeBuffer;
3231                 // data = new char[withoutUnicodeBuffer.length];
3232                 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
3233                 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
3234                 // }
3235                 // index = 1;
3236                 // }
3237                 firstLetter = data[index];
3238                 switch (firstLetter) {
3239                 case '_':
3240                         switch (length) {
3241                         case 8:
3242                                 // __FILE__
3243                                 if ((data[++index] == '_') && (data[++index] == 'f')
3244                                                 && (data[++index] == 'i') && (data[++index] == 'l')
3245                                                 && (data[++index] == 'e') && (data[++index] == '_')
3246                                                 && (data[++index] == '_'))
3247                                         return TokenName.FILE;
3248                                 index = 0; // __LINE__
3249                                 if ((data[++index] == '_') && (data[++index] == 'l')
3250                                                 && (data[++index] == 'i') && (data[++index] == 'n')
3251                                                 && (data[++index] == 'e') && (data[++index] == '_')
3252                                                 && (data[++index] == '_'))
3253                                         return TokenName.LINE;
3254                                 break;
3255                         case 9:
3256                                 // __CLASS__
3257                                 if ((data[++index] == '_') && (data[++index] == 'c')
3258                                                 && (data[++index] == 'l') && (data[++index] == 'a')
3259                                                 && (data[++index] == 's') && (data[++index] == 's')
3260                                                 && (data[++index] == '_') && (data[++index] == '_'))
3261                                         return TokenName.CLASS_C;
3262                                 break;
3263                         case 11:
3264                                 // __METHOD__
3265                                 if ((data[++index] == '_') && (data[++index] == 'm')
3266                                                 && (data[++index] == 'e') && (data[++index] == 't')
3267                                                 && (data[++index] == 'h') && (data[++index] == 'o')
3268                                                 && (data[++index] == 'd') && (data[++index] == '_')
3269                                                 && (data[++index] == '_'))
3270                                         return TokenName.METHOD_C;
3271                                 break;
3272                         case 12:
3273                                 // __FUNCTION__
3274                                 if ((data[++index] == '_') && (data[++index] == 'f')
3275                                                 && (data[++index] == 'u') && (data[++index] == 'n')
3276                                                 && (data[++index] == 'c') && (data[++index] == 't')
3277                                                 && (data[++index] == 'i') && (data[++index] == 'o')
3278                                                 && (data[++index] == 'n') && (data[++index] == '_')
3279                                                 && (data[++index] == '_'))
3280                                         return TokenName.FUNC_C;
3281                                 break;
3282                         }
3283                         return TokenName.IDENTIFIER;
3284                 case 'a':
3285                         // as and array abstract
3286                         switch (length) {
3287                         case 2:
3288                                 // as
3289                                 if ((data[++index] == 's')) {
3290                                         return TokenName.AS;
3291                                 }
3292                                 return TokenName.IDENTIFIER;
3293                         case 3:
3294                                 // and
3295                                 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3296                                         return TokenName.OP_AND_OLD;
3297                                 }
3298                                 return TokenName.IDENTIFIER;
3299                         case 5:
3300                                 // array
3301                                 if ((data[++index] == 'r') && (data[++index] == 'r')
3302                                                 && (data[++index] == 'a') && (data[++index] == 'y'))
3303                                         return TokenName.ARRAY;
3304                                 return TokenName.IDENTIFIER;
3305                         case 8:
3306                                 if ((data[++index] == 'b') && (data[++index] == 's')
3307                                                 && (data[++index] == 't') && (data[++index] == 'r')
3308                                                 && (data[++index] == 'a') && (data[++index] == 'c')
3309                                                 && (data[++index] == 't'))
3310                                         return TokenName.ABSTRACT;
3311                                 return TokenName.IDENTIFIER;
3312                         }
3313                         return TokenName.IDENTIFIER;
3314                 case 'b':
3315                         // break
3316                         switch (length) {
3317                         case 5:
3318                                 if ((data[++index] == 'r') && (data[++index] == 'e')
3319                                                 && (data[++index] == 'a') && (data[++index] == 'k'))
3320                                         return TokenName.BREAK;
3321                                 return TokenName.IDENTIFIER;
3322                         }
3323                         return TokenName.IDENTIFIER;
3324                 case 'c':
3325                         // case catch class clone const continue
3326                         switch (length) {
3327                         case 4:
3328                                 if ((data[++index] == 'a') && (data[++index] == 's')
3329                                                 && (data[++index] == 'e'))
3330                                         return TokenName.CASE;
3331                                 return TokenName.IDENTIFIER;
3332                         case 5:
3333                                 if ((data[++index] == 'a') && (data[++index] == 't')
3334                                                 && (data[++index] == 'c') && (data[++index] == 'h'))
3335                                         return TokenName.CATCH;
3336                                 index = 0;
3337                                 if ((data[++index] == 'l') && (data[++index] == 'a')
3338                                                 && (data[++index] == 's') && (data[++index] == 's'))
3339                                         return TokenName.CLASS;
3340                                 index = 0;
3341                                 if ((data[++index] == 'l') && (data[++index] == 'o')
3342                                                 && (data[++index] == 'n') && (data[++index] == 'e'))
3343                                         return TokenName.CLONE;
3344                                 index = 0;
3345                                 if ((data[++index] == 'o') && (data[++index] == 'n')
3346                                                 && (data[++index] == 's') && (data[++index] == 't'))
3347                                         return TokenName.CONST;
3348                                 return TokenName.IDENTIFIER;
3349                         case 8:
3350                                 if ((data[++index] == 'o') && (data[++index] == 'n')
3351                                                 && (data[++index] == 't') && (data[++index] == 'i')
3352                                                 && (data[++index] == 'n') && (data[++index] == 'u')
3353                                                 && (data[++index] == 'e'))
3354                                         return TokenName.CONTINUE;
3355                                 return TokenName.IDENTIFIER;
3356                         }
3357                         return TokenName.IDENTIFIER;
3358                 case 'd':
3359                         // declare default do die
3360                         // TODO delete define ==> no keyword !
3361                         switch (length) {
3362                         case 2:
3363                                 if ((data[++index] == 'o'))
3364                                         return TokenName.DO;
3365                                 return TokenName.IDENTIFIER;
3366                                 // case 6 :
3367                                 // if ((data[++index] == 'e')
3368                                 // && (data[++index] == 'f')
3369                                 // && (data[++index] == 'i')
3370                                 // && (data[++index] == 'n')
3371                                 // && (data[++index] == 'e'))
3372                                 // return TokenName.define;
3373                                 // else
3374                                 // return TokenName.Identifier;
3375                         case 7:
3376                                 if ((data[++index] == 'e') && (data[++index] == 'c')
3377                                                 && (data[++index] == 'l') && (data[++index] == 'a')
3378                                                 && (data[++index] == 'r') && (data[++index] == 'e'))
3379                                         return TokenName.DECLARE;
3380                                 index = 0;
3381                                 if ((data[++index] == 'e') && (data[++index] == 'f')
3382                                                 && (data[++index] == 'a') && (data[++index] == 'u')
3383                                                 && (data[++index] == 'l') && (data[++index] == 't'))
3384                                         return TokenName.DEFAULT;
3385                                 return TokenName.IDENTIFIER;
3386                         }
3387                         return TokenName.IDENTIFIER;
3388                 case 'e':
3389                         // echo else exit elseif extends eval
3390                         switch (length) {
3391                         case 4:
3392                                 if ((data[++index] == 'c') && (data[++index] == 'h')
3393                                                 && (data[++index] == 'o'))
3394                                         return TokenName.ECHO;
3395                                 else if ((data[index] == 'l') && (data[++index] == 's')
3396                                                 && (data[++index] == 'e'))
3397                                         return TokenName.ELSE;
3398                                 else if ((data[index] == 'x') && (data[++index] == 'i')
3399                                                 && (data[++index] == 't'))
3400                                         return TokenName.EXIT;
3401                                 else if ((data[index] == 'v') && (data[++index] == 'a')
3402                                                 && (data[++index] == 'l'))
3403                                         return TokenName.EVAL;
3404                                 return TokenName.IDENTIFIER;
3405                         case 5:
3406                                 // endif empty
3407                                 if ((data[++index] == 'n') && (data[++index] == 'd')
3408                                                 && (data[++index] == 'i') && (data[++index] == 'f'))
3409                                         return TokenName.ENDIF;
3410                                 if ((data[index] == 'm') && (data[++index] == 'p')
3411                                                 && (data[++index] == 't') && (data[++index] == 'y'))
3412                                         return TokenName.EMPTY;
3413                                 return TokenName.IDENTIFIER;
3414                         case 6:
3415                                 // endfor
3416                                 if ((data[++index] == 'n') && (data[++index] == 'd')
3417                                                 && (data[++index] == 'f') && (data[++index] == 'o')
3418                                                 && (data[++index] == 'r'))
3419                                         return TokenName.ENDFOR;
3420                                 else if ((data[index] == 'l') && (data[++index] == 's')
3421                                                 && (data[++index] == 'e') && (data[++index] == 'i')
3422                                                 && (data[++index] == 'f'))
3423                                         return TokenName.ELSEIF;
3424                                 return TokenName.IDENTIFIER;
3425                         case 7:
3426                                 if ((data[++index] == 'x') && (data[++index] == 't')
3427                                                 && (data[++index] == 'e') && (data[++index] == 'n')
3428                                                 && (data[++index] == 'd') && (data[++index] == 's'))
3429                                         return TokenName.EXTENDS;
3430                                 return TokenName.IDENTIFIER;
3431                         case 8:
3432                                 // endwhile
3433                                 if ((data[++index] == 'n') && (data[++index] == 'd')
3434                                                 && (data[++index] == 'w') && (data[++index] == 'h')
3435                                                 && (data[++index] == 'i') && (data[++index] == 'l')
3436                                                 && (data[++index] == 'e'))
3437                                         return TokenName.ENDWHILE;
3438                                 return TokenName.IDENTIFIER;
3439                         case 9:
3440                                 // endswitch
3441                                 if ((data[++index] == 'n') && (data[++index] == 'd')
3442                                                 && (data[++index] == 's') && (data[++index] == 'w')
3443                                                 && (data[++index] == 'i') && (data[++index] == 't')
3444                                                 && (data[++index] == 'c') && (data[++index] == 'h'))
3445                                         return TokenName.ENDSWITCH;
3446                                 return TokenName.IDENTIFIER;
3447                         case 10:
3448                                 // enddeclare
3449                                 if ((data[++index] == 'n') && (data[++index] == 'd')
3450                                                 && (data[++index] == 'd') && (data[++index] == 'e')
3451                                                 && (data[++index] == 'c') && (data[++index] == 'l')
3452                                                 && (data[++index] == 'a') && (data[++index] == 'r')
3453                                                 && (data[++index] == 'e'))
3454                                         return TokenName.ENDDECLARE;
3455                                 index = 0;
3456                                 if ((data[++index] == 'n') // endforeach
3457                                                 && (data[++index] == 'd')
3458                                                 && (data[++index] == 'f')
3459                                                 && (data[++index] == 'o')
3460                                                 && (data[++index] == 'r')
3461                                                 && (data[++index] == 'e')
3462                                                 && (data[++index] == 'a')
3463                                                 && (data[++index] == 'c') && (data[++index] == 'h'))
3464                                         return TokenName.ENDFOREACH;
3465                                 return TokenName.IDENTIFIER;
3466                         }
3467                         return TokenName.IDENTIFIER;
3468                 case 'f':
3469                         // for false final function
3470                         switch (length) {
3471                         case 3:
3472                                 if ((data[++index] == 'o') && (data[++index] == 'r'))
3473                                         return TokenName.FOR;
3474                                 return TokenName.IDENTIFIER;
3475                         case 5:
3476                                 // if ((data[++index] == 'a') && (data[++index] == 'l')
3477                                 // && (data[++index] == 's') && (data[++index] == 'e'))
3478                                 // return TokenName.false;
3479                                 if ((data[++index] == 'i') && (data[++index] == 'n')
3480                                                 && (data[++index] == 'a') && (data[++index] == 'l'))
3481                                         return TokenName.FINAL;
3482                                 return TokenName.IDENTIFIER;
3483                         case 7:
3484                                 // foreach
3485                                 if ((data[++index] == 'o') && (data[++index] == 'r')
3486                                                 && (data[++index] == 'e') && (data[++index] == 'a')
3487                                                 && (data[++index] == 'c') && (data[++index] == 'h'))
3488                                         return TokenName.FOREACH;
3489                                 return TokenName.IDENTIFIER;
3490                         case 8:
3491                                 // function
3492                                 if ((data[++index] == 'u') && (data[++index] == 'n')
3493                                                 && (data[++index] == 'c') && (data[++index] == 't')
3494                                                 && (data[++index] == 'i') && (data[++index] == 'o')
3495                                                 && (data[++index] == 'n'))
3496                                         return TokenName.FUNCTION;
3497                                 return TokenName.IDENTIFIER;
3498                         }
3499                         return TokenName.IDENTIFIER;
3500                 case 'g':
3501                         // global 
3502                         if (length == 6) {
3503                                 if ((data[++index] == 'l') && (data[++index] == 'o')
3504                                                 && (data[++index] == 'b') && (data[++index] == 'a')
3505                                                 && (data[++index] == 'l')) {
3506                                         return TokenName.GLOBAL;
3507                                 }
3508                         } 
3509                         else if (length == 4) {  // goto
3510                 if ((data[++index] == 'o') && 
3511                     (data[++index] == 't') && 
3512                     (data[++index] == 'o')) {
3513                     return TokenName.GOTO;
3514                 }
3515                         }
3516                         return TokenName.IDENTIFIER;
3517                 case 'i':
3518                         // if int isset include include_once instanceof interface implements
3519                         switch (length) {
3520                         case 2:
3521                                 if (data[++index] == 'f')
3522                                         return TokenName.IF;
3523                                 return TokenName.IDENTIFIER;
3524                                 // case 3 :
3525                                 // if ((data[++index] == 'n') && (data[++index] == 't'))
3526                                 // return TokenName.int;
3527                                 // else
3528                                 // return TokenName.IDENTIFIER;
3529                         case 5:
3530                                 if ((data[++index] == 's') && (data[++index] == 's')
3531                                                 && (data[++index] == 'e') && (data[++index] == 't'))
3532                                         return TokenName.ISSET;
3533                                 return TokenName.IDENTIFIER;
3534                         case 7:
3535                                 if ((data[++index] == 'n') && (data[++index] == 'c')
3536                                                 && (data[++index] == 'l') && (data[++index] == 'u')
3537                                                 && (data[++index] == 'd') && (data[++index] == 'e'))
3538                                         return TokenName.INCLUDE;
3539                                 return TokenName.IDENTIFIER;
3540                         case 9:
3541                                 // interface
3542                                 if ((data[++index] == 'n') && (data[++index] == 't')
3543                                                 && (data[++index] == 'e') && (data[++index] == 'r')
3544                                                 && (data[++index] == 'f') && (data[++index] == 'a')
3545                                                 && (data[++index] == 'c') && (data[++index] == 'e'))
3546                                         return TokenName.INTERFACE;
3547                                 return TokenName.IDENTIFIER;
3548                         case 10:
3549                                 // instanceof implements
3550                                 if ((data[++index] == 'n') && (data[++index] == 's')
3551                                                 && (data[++index] == 't') && (data[++index] == 'a')
3552                                                 && (data[++index] == 'n') && (data[++index] == 'c')
3553                                                 && (data[++index] == 'e') && (data[++index] == 'o')
3554                                                 && (data[++index] == 'f'))
3555                                         return TokenName.INSTANCEOF;
3556                                 if ((data[index] == 'm') && (data[++index] == 'p')
3557                                                 && (data[++index] == 'l') && (data[++index] == 'e')
3558                                                 && (data[++index] == 'm') && (data[++index] == 'e')
3559                                                 && (data[++index] == 'n') && (data[++index] == 't')
3560                                                 && (data[++index] == 's'))
3561                                         return TokenName.IMPLEMENTS;
3562                                 return TokenName.IDENTIFIER;
3563                         case 12: // include_once
3564                                 if ((data[++index] == 'n') && (data[++index] == 'c')
3565                                                 && (data[++index] == 'l') && (data[++index] == 'u')
3566                                                 && (data[++index] == 'd') && (data[++index] == 'e')
3567                                                 && (data[++index] == '_') && (data[++index] == 'o')
3568                                                 && (data[++index] == 'n') && (data[++index] == 'c')
3569                                                 && (data[++index] == 'e'))
3570                                         return TokenName.INCLUDE_ONCE;
3571                                 return TokenName.IDENTIFIER;
3572                         }
3573                         return TokenName.IDENTIFIER;
3574                 case 'l':
3575                         // list
3576                         if (length == 4) {
3577                                 if ((data[++index] == 'i') && (data[++index] == 's')
3578                                                 && (data[++index] == 't')) {
3579                                         return TokenName.LIST;
3580                                 }
3581                         }
3582                         return TokenName.IDENTIFIER;
3583                 case 'n':
3584                         // new null namespace
3585                         switch (length) {
3586                         case 3:
3587                                 if ((data[++index] == 'e') && (data[++index] == 'w'))
3588                                         return TokenName.NEW;
3589                                 return TokenName.IDENTIFIER;
3590                                 // case 4 :
3591                                 // if ((data[++index] == 'u') && (data[++index] == 'l')
3592                                 // && (data[++index] == 'l'))
3593                                 // return TokenName.null;
3594                                 // else
3595                                 // return TokenName.IDENTIFIER;
3596                         case 9:
3597                 if ((data[++index] == 'a') && (data[++index] == 'm')
3598                         && (data[++index] == 'e') && (data[++index] == 's')
3599                         && (data[++index] == 'p') && (data[++index] == 'a')
3600                         && (data[++index] == 'c') && (data[++index] == 'e')) {
3601                     return TokenName.NAMESPACE;
3602                 }
3603                             return TokenName.IDENTIFIER;
3604                         }
3605                         return TokenName.IDENTIFIER;
3606                 case 'o':
3607                         // or old_function
3608                         if (length == 2) {
3609                                 if (data[++index] == 'r') {
3610                                         return TokenName.OP_OR_OLD;
3611                                 }
3612                         }
3613                         // if (length == 12) {
3614                         // if ((data[++index] == 'l')
3615                         // && (data[++index] == 'd')
3616                         // && (data[++index] == '_')
3617                         // && (data[++index] == 'f')
3618                         // && (data[++index] == 'u')
3619                         // && (data[++index] == 'n')
3620                         // && (data[++index] == 'c')
3621                         // && (data[++index] == 't')
3622                         // && (data[++index] == 'i')
3623                         // && (data[++index] == 'o')
3624                         // && (data[++index] == 'n')) {
3625                         // return TokenName.old_function;
3626                         // }
3627                         // }
3628                         return TokenName.IDENTIFIER;
3629                 case 'p':
3630                         // print public private protected
3631                         switch (length) {
3632                         case 5:
3633                                 if ((data[++index] == 'r') && (data[++index] == 'i')
3634                                                 && (data[++index] == 'n') && (data[++index] == 't')) {
3635                                         return TokenName.PRINT;
3636                                 }
3637                                 return TokenName.IDENTIFIER;
3638                         case 6:
3639                                 if ((data[++index] == 'u') && (data[++index] == 'b')
3640                                                 && (data[++index] == 'l') && (data[++index] == 'i')
3641                                                 && (data[++index] == 'c')) {
3642                                         return TokenName.PUBLIC;
3643                                 }
3644                                 return TokenName.IDENTIFIER;
3645                         case 7:
3646                                 if ((data[++index] == 'r') && (data[++index] == 'i')
3647                                                 && (data[++index] == 'v') && (data[++index] == 'a')
3648                                                 && (data[++index] == 't') && (data[++index] == 'e')) {
3649                                         return TokenName.PRIVATE;
3650                                 }
3651                                 return TokenName.IDENTIFIER;
3652                         case 9:
3653                                 if ((data[++index] == 'r') && (data[++index] == 'o')
3654                                                 && (data[++index] == 't') && (data[++index] == 'e')
3655                                                 && (data[++index] == 'c') && (data[++index] == 't')
3656                                                 && (data[++index] == 'e') && (data[++index] == 'd')) {
3657                                         return TokenName.PROTECTED;
3658                                 }
3659                                 return TokenName.IDENTIFIER;
3660                         }
3661                         return TokenName.IDENTIFIER;
3662                 case 'r':
3663                         // return require require_once
3664                         if (length == 6) {
3665                                 if ((data[++index] == 'e') && (data[++index] == 't')
3666                                                 && (data[++index] == 'u') && (data[++index] == 'r')
3667                                                 && (data[++index] == 'n')) {
3668                                         return TokenName.RETURN;
3669                                 }
3670                         } else if (length == 7) {
3671                                 if ((data[++index] == 'e') && (data[++index] == 'q')
3672                                                 && (data[++index] == 'u') && (data[++index] == 'i')
3673                                                 && (data[++index] == 'r') && (data[++index] == 'e')) {
3674                                         return TokenName.REQUIRE;
3675                                 }
3676                         } else if (length == 12) {
3677                                 if ((data[++index] == 'e') && (data[++index] == 'q')
3678                                                 && (data[++index] == 'u') && (data[++index] == 'i')
3679                                                 && (data[++index] == 'r') && (data[++index] == 'e')
3680                                                 && (data[++index] == '_') && (data[++index] == 'o')
3681                                                 && (data[++index] == 'n') && (data[++index] == 'c')
3682                                                 && (data[++index] == 'e')) {
3683                                         return TokenName.REQUIRE_ONCE;
3684                                 }
3685                         }
3686                         return TokenName.IDENTIFIER;
3687                 case 's':
3688                         // self static switch
3689                         switch (length) {
3690                         // case 4:
3691                         // if ((data[++index] == 'e') && (data[++index] == 'l') &&
3692                         // (data[++index]
3693                         // == 'f')) {
3694                         // return TokenName.self;
3695                         // }
3696                         // return TokenName.IDENTIFIER;
3697                         case 6:
3698                                 if (data[++index] == 't')
3699                                         if ((data[++index] == 'a') && (data[++index] == 't')
3700                                                         && (data[++index] == 'i') && (data[++index] == 'c')) {
3701                                                 return TokenName.STATIC;
3702                                         } else
3703                                                 return TokenName.IDENTIFIER;
3704                                 else if ((data[index] == 'w') && (data[++index] == 'i')
3705                                                 && (data[++index] == 't') && (data[++index] == 'c')
3706                                                 && (data[++index] == 'h'))
3707                                         return TokenName.SWITCH;
3708                         }
3709                         return TokenName.IDENTIFIER;
3710                 case 't':
3711                         // try true throw
3712                         switch (length) {
3713                         case 3:
3714                                 if ((data[++index] == 'r') && (data[++index] == 'y'))
3715                                         return TokenName.TRY;
3716                                 // case 4 :
3717                                 // if ((data[++index] == 'r') && (data[++index] == 'u')
3718                                 // && (data[++index] == 'e'))
3719                                 // return TokenName.true;
3720                                  else
3721                                          return TokenName.IDENTIFIER;
3722                         case 5:
3723                                 if ((data[++index] == 'h') && (data[++index] == 'r')
3724                                                 && (data[++index] == 'o') && (data[++index] == 'w'))
3725                                         return TokenName.THROW;
3726                         }
3727                         return TokenName.IDENTIFIER;
3728                 case 'u':
3729                         // use unset
3730                         switch (length) {
3731                         case 3:
3732                                 if ((data[++index] == 's') && (data[++index] == 'e'))
3733                                         return TokenName.USE;
3734                                 else
3735                                         return TokenName.IDENTIFIER;
3736                         case 5:
3737                                 if ((data[++index] == 'n') && (data[++index] == 's')
3738                                                 && (data[++index] == 'e') && (data[++index] == 't'))
3739                                         return TokenName.UNSET;
3740                         }
3741                         return TokenName.IDENTIFIER;
3742                 case 'v':
3743                         // var
3744                         switch (length) {
3745                         case 3:
3746                                 if ((data[++index] == 'a') && (data[++index] == 'r'))
3747                                         return TokenName.VAR;
3748                         }
3749                         return TokenName.IDENTIFIER;
3750                 case 'w':
3751                         // while
3752                         switch (length) {
3753                         case 5:
3754                                 if ((data[++index] == 'h') && (data[++index] == 'i')
3755                                                 && (data[++index] == 'l') && (data[++index] == 'e'))
3756                                         return TokenName.WHILE;
3757                                 // case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3758                                 // (data[++index]=='e') && (data[++index]=='f')&&
3759                                 // (data[++index]=='p'))
3760                                 // return TokenName.widefp ;
3761                                 // else
3762                                 // return TokenName.IDENTIFIER;
3763                         }
3764                         return TokenName.IDENTIFIER;
3765                 case 'x':
3766                         // xor
3767                         switch (length) {
3768                         case 3:
3769                                 if ((data[++index] == 'o') && (data[++index] == 'r'))
3770                                         return TokenName.OP_XOR_OLD;
3771                                 else
3772                                         return TokenName.IDENTIFIER;
3773                         }
3774                         return TokenName.IDENTIFIER;
3775                 }
3776                 return TokenName.IDENTIFIER;
3777         }
3778
3779         public TokenName scanNumber(boolean dotPrefix) throws InvalidInputException {
3780                 // when entering this method the currentCharacter is the firt
3781                 // digit of the number , i.e. it may be preceeded by a . when
3782                 // dotPrefix is true
3783                 boolean floating = dotPrefix;
3784                 if ((!dotPrefix) && (currentCharacter == '0')) {
3785                         if (getNextChar('x', 'X') >= 0) { // ----------hexa-----------------
3786                                 // force the first char of the hexa number do exist...
3787                                 // consume next character
3788                                 unicodeAsBackSlash = false;
3789                                 currentCharacter = source[currentPosition++];
3790                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
3791                                 // && (source[currentPosition] == 'u')) {
3792                                 // getNextUnicodeChar();
3793                                 // } else {
3794                                 // if (withoutUnicodePtr != 0) {
3795                                 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3796                                 // }
3797                                 // }
3798                                 if (Character.digit(currentCharacter, 16) == -1)
3799                                         throw new InvalidInputException(INVALID_HEXA);
3800                                 // ---end forcing--
3801                                 while (getNextCharAsDigit(16)) {
3802                                 }
3803                                 ;
3804                                 // if (getNextChar('l', 'L') >= 0)
3805                                 // return TokenName.LongLiteral;
3806                                 // else
3807                                 return TokenName.INTEGERLITERAL;
3808                         }
3809                         // there is x or X in the number
3810                         // potential octal ! ... some one may write 000099.0 ! thus 00100 <
3811                         // 00078.0 is true !!!!! crazy language
3812                         if (getNextCharAsDigit()) {
3813                                 // -------------potential octal-----------------
3814                                 while (getNextCharAsDigit()) {
3815                                 }
3816                                 ;
3817                                 // if (getNextChar('l', 'L') >= 0) {
3818                                 // return TokenName.LongLiteral;
3819                                 // }
3820                                 //
3821                                 // if (getNextChar('f', 'F') >= 0) {
3822                                 // return TokenName.FloatingPointLiteral;
3823                                 // }
3824                                 if (getNextChar('d', 'D') >= 0) {
3825                                         return TokenName.DOUBLELITERAL;
3826                                 } else { // make the distinction between octal and float ....
3827                                         if (getNextChar('.')) { // bingo ! ....
3828                                                 while (getNextCharAsDigit()) {
3829                                                 }
3830                                                 ;
3831                                                 if (getNextChar('e', 'E') >= 0) {
3832                                                         // consume next character
3833                                                         unicodeAsBackSlash = false;
3834                                                         currentCharacter = source[currentPosition++];
3835                                                         // if (((currentCharacter =
3836                                                         // source[currentPosition++]) == '\\')
3837                                                         // && (source[currentPosition] == 'u')) {
3838                                                         // getNextUnicodeChar();
3839                                                         // } else {
3840                                                         // if (withoutUnicodePtr != 0) {
3841                                                         // withoutUnicodeBuffer[++withoutUnicodePtr] =
3842                                                         // currentCharacter;
3843                                                         // }
3844                                                         // }
3845                                                         if ((currentCharacter == '-')
3846                                                                         || (currentCharacter == '+')) {
3847                                                                 // consume next character
3848                                                                 unicodeAsBackSlash = false;
3849                                                                 currentCharacter = source[currentPosition++];
3850                                                                 // if (((currentCharacter =
3851                                                                 // source[currentPosition++]) == '\\')
3852                                                                 // && (source[currentPosition] == 'u')) {
3853                                                                 // getNextUnicodeChar();
3854                                                                 // } else {
3855                                                                 // if (withoutUnicodePtr != 0) {
3856                                                                 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3857                                                                 // currentCharacter;
3858                                                                 // }
3859                                                                 // }
3860                                                         }
3861                                                         if (!Character.isDigit(currentCharacter))
3862                                                                 throw new InvalidInputException(INVALID_FLOAT);
3863                                                         while (getNextCharAsDigit()) {
3864                                                         }
3865                                                         ;
3866                                                 }
3867                                                 // if (getNextChar('f', 'F') >= 0)
3868                                                 // return TokenName.FloatingPointLiteral;
3869                                                 getNextChar('d', 'D'); // jump over potential d or D
3870                                                 return TokenName.DOUBLELITERAL;
3871                                         } else {
3872                                                 return TokenName.INTEGERLITERAL;
3873                                         }
3874                                 }
3875                         } else {
3876                                 /* carry on */
3877                         }
3878                 }
3879                 while (getNextCharAsDigit()) {
3880                 }
3881                 ;
3882                 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3883                 // return TokenName.LongLiteral;
3884                 if ((!dotPrefix) && (getNextChar('.'))) { // decimal part that can be
3885                                                                                                         // empty
3886                         while (getNextCharAsDigit()) {
3887                         }
3888                         ;
3889                         floating = true;
3890                 }
3891                 // if floating is true both exponant and suffix may be optional
3892                 if (getNextChar('e', 'E') >= 0) {
3893                         floating = true;
3894                         // consume next character
3895                         unicodeAsBackSlash = false;
3896                         currentCharacter = source[currentPosition++];
3897                         // if (((currentCharacter = source[currentPosition++]) == '\\')
3898                         // && (source[currentPosition] == 'u')) {
3899                         // getNextUnicodeChar();
3900                         // } else {
3901                         // if (withoutUnicodePtr != 0) {
3902                         // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3903                         // }
3904                         // }
3905                         if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
3906                                 // next
3907                                 // character
3908                                 unicodeAsBackSlash = false;
3909                                 currentCharacter = source[currentPosition++];
3910                                 // if (((currentCharacter = source[currentPosition++]) == '\\')
3911                                 // && (source[currentPosition] == 'u')) {
3912                                 // getNextUnicodeChar();
3913                                 // } else {
3914                                 // if (withoutUnicodePtr != 0) {
3915                                 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3916                                 // }
3917                                 // }
3918                         }
3919                         if (!Character.isDigit(currentCharacter))
3920                                 throw new InvalidInputException(INVALID_FLOAT);
3921                         while (getNextCharAsDigit()) {
3922                         }
3923                         ;
3924                 }
3925                 if (getNextChar('d', 'D') >= 0)
3926                         return TokenName.DOUBLELITERAL;
3927                 // if (getNextChar('f', 'F') >= 0)
3928                 // return TokenName.FloatingPointLiteral;
3929                 // the long flag has been tested before
3930                 return floating ? TokenName.DOUBLELITERAL : TokenName.INTEGERLITERAL;
3931         }
3932
3933         /**
3934          * Search the line number corresponding to a specific position
3935          *
3936          */
3937         public final int getLineNumber(int position) {
3938                 if (lineEnds == null)
3939                         return 1;
3940                 int length = linePtr + 1;
3941                 if (length == 0)
3942                         return 1;
3943                 int g = 0, d = length - 1;
3944                 int m = 0;
3945                 while (g <= d) {
3946                         m = (g + d) / 2;
3947                         if (position < lineEnds[m]) {
3948                                 d = m - 1;
3949                         } else if (position > lineEnds[m]) {
3950                                 g = m + 1;
3951                         } else {
3952                                 return m + 1;
3953                         }
3954                 }
3955                 if (position < lineEnds[m]) {
3956                         return m + 1;
3957                 }
3958                 return m + 2;
3959         }
3960
3961         public void setPHPMode(boolean mode) {
3962                 phpMode = mode;
3963         }
3964
3965         public final void setSource(char[] source) {
3966                 setSource(null, source);
3967         }
3968
3969         public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3970                 // the source-buffer is set to sourceString
3971                 this.compilationUnit = compilationUnit;
3972                 if (source == null) {
3973                         this.source = new char[0];
3974                 } else {
3975                         this.source = source;
3976                 }
3977                 startPosition = -1;
3978                 initialPosition = currentPosition = 0;
3979                 containsAssertKeyword = false;
3980                 withoutUnicodeBuffer = new char[this.source.length];
3981                 fFillerToken = TokenName.EOF;
3982                 // encapsedStringStack = new Stack();
3983         }
3984
3985         public String toString() {
3986                 if (startPosition == source.length)
3987                         return "EOF\n\n" + new String(source); //$NON-NLS-1$
3988                 if (currentPosition > source.length)
3989                         return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3990                 char front[] = new char[startPosition];
3991                 System.arraycopy(source, 0, front, 0, startPosition);
3992                 int middleLength = (currentPosition - 1) - startPosition + 1;
3993                 char middle[];
3994                 if (middleLength > -1) {
3995                         middle = new char[middleLength];
3996                         System.arraycopy(source, startPosition, middle, 0, middleLength);
3997                 } else {
3998                         middle = new char[0];
3999                 }
4000                 char end[] = new char[source.length - (currentPosition - 1)];
4001                 System.arraycopy(source, (currentPosition - 1) + 1, end, 0,
4002                                 source.length - (currentPosition - 1) - 1);
4003                 return new String(front)
4004                                 + "\n===============================\nStarts here -->" //$NON-NLS-1$
4005                                 + new String(middle)
4006                                 + "<-- Ends here\n===============================\n" //$NON-NLS-1$
4007                                 + new String(end);
4008         }
4009
4010         public final String toStringAction(TokenName act) {
4011                 switch (act) {
4012                 case ERROR:
4013                         return "ScannerError"; // + new String(getCurrentTokenSource()) +
4014                                                                         // ")";
4015                         // //$NON-NLS-1$
4016                 case INLINE_HTML:
4017                         return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4018                 case ECHO_INVISIBLE:
4019                         // 0-length token
4020                         return "";
4021                 case IDENTIFIER:
4022                         return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4023                 case VARIABLE:
4024                         return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4025                 case ABSTRACT:
4026                         return "abstract"; //$NON-NLS-1$
4027                 case OP_AND_OLD:
4028                         return "AND"; //$NON-NLS-1$
4029                 case ARRAY:
4030                         return "array"; //$NON-NLS-1$
4031                 case AS:
4032                         return "as"; //$NON-NLS-1$
4033                 case BREAK:
4034                         return "break"; //$NON-NLS-1$
4035                 case CASE:
4036                         return "case"; //$NON-NLS-1$
4037                 case CLASS:
4038                         return "class"; //$NON-NLS-1$
4039                 case CATCH:
4040                         return "catch"; //$NON-NLS-1$
4041                 case CLONE:
4042                         //$NON-NLS-1$
4043                         return "clone";
4044                 case CONST:
4045                         //$NON-NLS-1$
4046                         return "const";
4047                 case CONTINUE:
4048                         return "continue"; //$NON-NLS-1$
4049                 case DEFAULT:
4050                         return "default"; //$NON-NLS-1$
4051                         // case define :
4052                         // return "define"; //$NON-NLS-1$
4053                 case DO:
4054                         return "do"; //$NON-NLS-1$
4055                 case ECHO:
4056                         return "echo"; //$NON-NLS-1$
4057                 case ELSE:
4058                         return "else"; //$NON-NLS-1$
4059                 case ELSEIF:
4060                         return "elseif"; //$NON-NLS-1$
4061                 case ENDFOR:
4062                         return "endfor"; //$NON-NLS-1$
4063                 case ENDFOREACH:
4064                         return "endforeach"; //$NON-NLS-1$
4065                 case ENDIF:
4066                         return "endif"; //$NON-NLS-1$
4067                 case ENDSWITCH:
4068                         return "endswitch"; //$NON-NLS-1$
4069                 case ENDWHILE:
4070                         return "endwhile"; //$NON-NLS-1$
4071                 case EXIT:
4072                         return "exit";
4073                 case EXTENDS:
4074                         return "extends"; //$NON-NLS-1$
4075                         // case false :
4076                         // return "false"; //$NON-NLS-1$
4077                 case FINAL:
4078                         return "final"; //$NON-NLS-1$
4079                 case FOR:
4080                         return "for"; //$NON-NLS-1$
4081                 case FOREACH:
4082                         return "foreach"; //$NON-NLS-1$
4083                 case FUNCTION:
4084                         return "function"; //$NON-NLS-1$
4085                 case GLOBAL:
4086                         return "global"; //$NON-NLS-1$
4087                 case IF:
4088                         return "if"; //$NON-NLS-1$
4089                 case IMPLEMENTS:
4090                         return "implements"; //$NON-NLS-1$
4091                 case INCLUDE:
4092                         return "include"; //$NON-NLS-1$
4093                 case INCLUDE_ONCE:
4094                         return "include_once"; //$NON-NLS-1$
4095                 case INSTANCEOF:
4096                         return "instanceof"; //$NON-NLS-1$
4097                 case INTERFACE:
4098                         return "interface"; //$NON-NLS-1$
4099                 case ISSET:
4100                         return "isset"; //$NON-NLS-1$
4101                 case LIST:
4102                         return "list"; //$NON-NLS-1$
4103                 case NEW:
4104                         return "new"; //$NON-NLS-1$
4105                         // case null :
4106                         // return "null"; //$NON-NLS-1$
4107                 case OP_OR_OLD:
4108                         return "OR"; //$NON-NLS-1$
4109                 case PRINT:
4110                         return "print"; //$NON-NLS-1$
4111                 case PRIVATE:
4112                         return "private"; //$NON-NLS-1$
4113                 case PROTECTED:
4114                         return "protected"; //$NON-NLS-1$
4115                 case PUBLIC:
4116                         return "public"; //$NON-NLS-1$
4117                 case REQUIRE:
4118                         return "require"; //$NON-NLS-1$
4119                 case REQUIRE_ONCE:
4120                         return "require_once"; //$NON-NLS-1$
4121                 case RETURN:
4122                         return "return"; //$NON-NLS-1$
4123                         // case self:
4124                         // return "self"; //$NON-NLS-1$
4125                 case STATIC:
4126                         return "static"; //$NON-NLS-1$
4127                 case SWITCH:
4128                         return "switch"; //$NON-NLS-1$
4129                         // case true :
4130                         // return "true"; //$NON-NLS-1$
4131                 case UNSET:
4132                         return "unset"; //$NON-NLS-1$
4133                 case VAR:
4134                         return "var"; //$NON-NLS-1$
4135                 case WHILE:
4136                         return "while"; //$NON-NLS-1$
4137                 case OP_XOR_OLD:
4138                         return "XOR"; //$NON-NLS-1$
4139                         // case this :
4140                         // return "$this"; //$NON-NLS-1$
4141                 case INTEGERLITERAL:
4142                         return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4143                 case DOUBLELITERAL:
4144                         return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4145                 case STRINGDOUBLEQUOTE:
4146                         return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4147                 case STRINGSINGLEQUOTE:
4148                         return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4149                 case STRINGINTERPOLATED:
4150                         return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4151                 case ENCAPSEDSTRING0:
4152                         return "`"; //$NON-NLS-1$
4153                         // case EncapsedString1:
4154                         // return "\'"; //$NON-NLS-1$
4155                         // case EncapsedString2:
4156                         // return "\""; //$NON-NLS-1$
4157                 case STRING:
4158                         return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4159                 case HEREDOC:
4160                         return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4161                 case PLUS_PLUS:
4162                         return "++"; //$NON-NLS-1$
4163                 case MINUS_MINUS:
4164                         return "--"; //$NON-NLS-1$
4165                 case EQUAL_EQUAL:
4166                         return "=="; //$NON-NLS-1$
4167                 case EQUAL_EQUAL_EQUAL:
4168                         return "==="; //$NON-NLS-1$
4169                 case EQUAL_GREATER:
4170                         return "=>"; //$NON-NLS-1$
4171                 case LESS_EQUAL:
4172                         return "<="; //$NON-NLS-1$
4173                 case GREATER_EQUAL:
4174                         return ">="; //$NON-NLS-1$
4175                 case NOT_EQUAL:
4176                         return "!="; //$NON-NLS-1$
4177                 case NOT_EQUAL_EQUAL:
4178                         return "!=="; //$NON-NLS-1$
4179                 case LEFT_SHIFT:
4180                         return "<<"; //$NON-NLS-1$
4181                 case RIGHT_SHIFT:
4182                         return ">>"; //$NON-NLS-1$
4183                 case PLUS_EQUAL:
4184                         return "+="; //$NON-NLS-1$
4185                 case MINUS_EQUAL:
4186                         return "-="; //$NON-NLS-1$
4187                 case MULTIPLY_EQUAL:
4188                         return "*="; //$NON-NLS-1$
4189                 case DIVIDE_EQUAL:
4190                         return "/="; //$NON-NLS-1$
4191                 case AND_EQUAL:
4192                         return "&="; //$NON-NLS-1$
4193                 case OR_EQUAL:
4194                         return "|="; //$NON-NLS-1$
4195                 case XOR_EQUAL:
4196                         return "^="; //$NON-NLS-1$
4197                 case REMAINDER_EQUAL:
4198                         return "%="; //$NON-NLS-1$
4199                 case DOT_EQUAL:
4200                         return ".="; //$NON-NLS-1$
4201                 case LEFT_SHIFT_EQUAL:
4202                         return "<<="; //$NON-NLS-1$
4203                 case RIGHT_SHIFT_EQUAL:
4204                         return ">>="; //$NON-NLS-1$
4205                 case OR_OR:
4206                         return "||"; //$NON-NLS-1$
4207                 case AND_AND:
4208                         return "&&"; //$NON-NLS-1$
4209                 case PLUS:
4210                         return "+"; //$NON-NLS-1$
4211                 case MINUS:
4212                         return "-"; //$NON-NLS-1$
4213                 case MINUS_GREATER:
4214                         return "->";
4215                 case NOT:
4216                         return "!"; //$NON-NLS-1$
4217                 case REMAINDER:
4218                         return "%"; //$NON-NLS-1$
4219                 case OP_XOR:
4220                         return "^"; //$NON-NLS-1$
4221                 case OP_AND:
4222                         return "&"; //$NON-NLS-1$
4223                 case MULTIPLY:
4224                         return "*"; //$NON-NLS-1$
4225                 case OP_OR:
4226                         return "|"; //$NON-NLS-1$
4227                 case TWIDDLE:
4228                         return "~"; //$NON-NLS-1$
4229                 case TWIDDLE_EQUAL:
4230                         return "~="; //$NON-NLS-1$
4231                 case DIVIDE:
4232                         return "/"; //$NON-NLS-1$
4233                 case GREATER:
4234                         return ">"; //$NON-NLS-1$
4235                 case LESS:
4236                         return "<"; //$NON-NLS-1$
4237                 case LPAREN:
4238                         return "("; //$NON-NLS-1$
4239                 case RPAREN:
4240                         return ")"; //$NON-NLS-1$
4241                 case LBRACE:
4242                         return "{"; //$NON-NLS-1$
4243                 case RBRACE:
4244                         return "}"; //$NON-NLS-1$
4245                 case LBRACKET:
4246                         return "["; //$NON-NLS-1$
4247                 case RBRACKET:
4248                         return "]"; //$NON-NLS-1$
4249                 case SEMICOLON:
4250                         return ";"; //$NON-NLS-1$
4251                 case QUESTION:
4252                         return "?"; //$NON-NLS-1$
4253                 case COLON:
4254                         return ":"; //$NON-NLS-1$
4255                 case COMMA:
4256                         return ","; //$NON-NLS-1$
4257                 case DOT:
4258                         return "."; //$NON-NLS-1$
4259                 case EQUAL:
4260                         return "="; //$NON-NLS-1$
4261                 case OP_AT:
4262                         return "@";
4263                 case DOLLAR:
4264                         return "$";
4265                 case DOLLAR_LBRACE:
4266                         return "${";
4267                 case LBRACE_DOLLAR:
4268                         return "{$";
4269                 case EOF:
4270                         return "EOF"; //$NON-NLS-1$
4271                 case WHITESPACE:
4272                         return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4273                 case COMMENT_LINE:
4274                         return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4275                 case COMMENT_BLOCK:
4276                         return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4277                 case COMMENT_PHPDOC:
4278                         return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4279                         // case HTML :
4280                         // return "HTML(" + new String(getCurrentTokenSource()) + ")";
4281                         // //$NON-NLS-1$
4282                 case FILE:
4283                         return "__FILE__"; //$NON-NLS-1$
4284                 case LINE:
4285                         return "__LINE__"; //$NON-NLS-1$
4286                 case CLASS_C:
4287                         return "__CLASS__"; //$NON-NLS-1$
4288                 case METHOD_C:
4289                         return "__METHOD__"; //$NON-NLS-1$
4290                 case FUNC_C:
4291                         return "__FUNCTION__"; //$NON-NLS-1
4292                 case BOOLCAST:
4293                         return "( bool )"; //$NON-NLS-1$
4294                 case INTCAST:
4295                         return "( int )"; //$NON-NLS-1$
4296                 case DOUBLECAST:
4297                         return "( double )"; //$NON-NLS-1$
4298                 case OBJECTCAST:
4299                         return "( object )"; //$NON-NLS-1$
4300                 case STRINGCAST:
4301                         return "( string )"; //$NON-NLS-1$
4302         case NAMESPACE:
4303             return "( namespace )"; //$NON-NLS-1$
4304                 default:
4305                         return "token not handled (" + (act.toString ()) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
4306                 }
4307         }
4308
4309         public Scanner() {
4310                 this(false, false);
4311         }
4312
4313         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
4314                 this(tokenizeComments, tokenizeWhiteSpace, false);
4315         }
4316
4317         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
4318                         boolean checkNonExternalizedStringLiterals) {
4319                 this(tokenizeComments, tokenizeWhiteSpace,
4320                                 checkNonExternalizedStringLiterals, false);
4321         }
4322
4323         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
4324                         boolean checkNonExternalizedStringLiterals, boolean assertMode) {
4325                 this(tokenizeComments, tokenizeWhiteSpace,
4326                                 checkNonExternalizedStringLiterals, assertMode, false, null,
4327                                 null, true);
4328         }
4329
4330         public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
4331                         boolean checkNonExternalizedStringLiterals, boolean assertMode,
4332                         boolean tokenizeStrings, char[][] taskTags,
4333                         char[][] taskPriorities, boolean isTaskCaseSensitive) {
4334                 this.eofPosition = Integer.MAX_VALUE;
4335                 this.tokenizeComments = tokenizeComments;
4336                 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4337                 this.tokenizeStrings = tokenizeStrings;
4338                 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4339                 // this.assertMode = assertMode;
4340                 // this.encapsedStringStack = null;
4341                 this.taskTags = taskTags;
4342                 this.taskPriorities = taskPriorities;
4343         }
4344
4345         private void checkNonExternalizeString() throws InvalidInputException {
4346                 if (currentLine == null)
4347                         return;
4348                 parseTags(currentLine);
4349         }
4350
4351         private void parseTags(NLSLine line) throws InvalidInputException {
4352                 String s = new String(getCurrentTokenSource());
4353                 int pos = s.indexOf(TAG_PREFIX);
4354                 int lineLength = line.size();
4355                 while (pos != -1) {
4356                         int start = pos + TAG_PREFIX_LENGTH;
4357                         int end = s.indexOf(TAG_POSTFIX, start);
4358                         String index = s.substring(start, end);
4359                         int i = 0;
4360                         try {
4361                                 i = Integer.parseInt(index) - 1;
4362                                 // Tags are one based not zero based.
4363                         } catch (NumberFormatException e) {
4364                                 i = -1; // we don't want to consider this as a valid NLS tag
4365                         }
4366                         if (line.exists(i)) {
4367                                 line.set(i, null);
4368                         }
4369                         pos = s.indexOf(TAG_PREFIX, start);
4370                 }
4371                 this.nonNLSStrings = new StringLiteral[lineLength];
4372                 int nonNLSCounter = 0;
4373                 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4374                         StringLiteral literal = (StringLiteral) iterator.next();
4375                         if (literal != null) {
4376                                 this.nonNLSStrings[nonNLSCounter++] = literal;
4377                         }
4378                 }
4379                 if (nonNLSCounter == 0) {
4380                         this.nonNLSStrings = null;
4381                         currentLine = null;
4382                         return;
4383                 }
4384                 this.wasNonExternalizedStringLiteral = true;
4385                 if (nonNLSCounter != lineLength) {
4386                         System.arraycopy(this.nonNLSStrings, 0,
4387                                         (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0,
4388                                         nonNLSCounter);
4389                 }
4390                 currentLine = null;
4391         }
4392
4393         public final void scanEscapeCharacter() throws InvalidInputException {
4394                 // the string with "\\u" is a legal string of two chars \ and u
4395                 // thus we use a direct access to the source (for regular cases).
4396                 if (unicodeAsBackSlash) {
4397                         // consume next character
4398                         unicodeAsBackSlash = false;
4399                         // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4400                         // (source[currentPosition] == 'u')) {
4401                         // getNextUnicodeChar();
4402                         // } else {
4403                         if (withoutUnicodePtr != 0) {
4404                                 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4405                                 // }
4406                         }
4407                 } else
4408                         currentCharacter = source[currentPosition++];
4409                 switch (currentCharacter) {
4410                 case 'b':
4411                         currentCharacter = '\b';
4412                         break;
4413                 case 't':
4414                         currentCharacter = '\t';
4415                         break;
4416                 case 'n':
4417                         currentCharacter = '\n';
4418                         break;
4419                 case 'f':
4420                         currentCharacter = '\f';
4421                         break;
4422                 case 'r':
4423                         currentCharacter = '\r';
4424                         break;
4425                 case '\"':
4426                         currentCharacter = '\"';
4427                         break;
4428                 case '\'':
4429                         currentCharacter = '\'';
4430                         break;
4431                 case '\\':
4432                         currentCharacter = '\\';
4433                         break;
4434                 default:
4435                         // -----------octal escape--------------
4436                         // OctalDigit
4437                         // OctalDigit OctalDigit
4438                         // ZeroToThree OctalDigit OctalDigit
4439                         int number = Character.getNumericValue(currentCharacter);
4440                         if (number >= 0 && number <= 7) {
4441                                 boolean zeroToThreeNot = number > 3;
4442                                 if (Character
4443                                                 .isDigit(currentCharacter = source[currentPosition++])) {
4444                                         int digit = Character.getNumericValue(currentCharacter);
4445                                         if (digit >= 0 && digit <= 7) {
4446                                                 number = (number * 8) + digit;
4447                                                 if (Character
4448                                                                 .isDigit(currentCharacter = source[currentPosition++])) {
4449                                                         if (zeroToThreeNot) { // has read \NotZeroToThree
4450                                                                                                         // OctalDigit
4451                                                                 // Digit --> ignore last character
4452                                                                 currentPosition--;
4453                                                         } else {
4454                                                                 digit = Character
4455                                                                                 .getNumericValue(currentCharacter);
4456                                                                 if (digit >= 0 && digit <= 7) { // has read
4457                                                                                                                                 // \ZeroToThree
4458                                                                         // OctalDigit OctalDigit
4459                                                                         number = (number * 8) + digit;
4460                                                                 } else { // has read \ZeroToThree OctalDigit
4461                                                                                         // NonOctalDigit
4462                                                                         // --> ignore last character
4463                                                                         currentPosition--;
4464                                                                 }
4465                                                         }
4466                                                 } else { // has read \OctalDigit NonDigit--> ignore
4467                                                                         // last
4468                                                         // character
4469                                                         currentPosition--;
4470                                                 }
4471                                         } else { // has read \OctalDigit NonOctalDigit--> ignore
4472                                                                 // last
4473                                                 // character
4474                                                 currentPosition--;
4475                                         }
4476                                 } else { // has read \OctalDigit --> ignore last character
4477                                         currentPosition--;
4478                                 }
4479                                 if (number > 255)
4480                                         throw new InvalidInputException(INVALID_ESCAPE);
4481                                 currentCharacter = (char) number;
4482                         } else
4483                                 throw new InvalidInputException(INVALID_ESCAPE);
4484                 }
4485         }
4486
4487         // chech presence of task: tags
4488         // TODO (frederic) see if we need to take unicode characters into account...
4489         public void checkTaskTag(int commentStart, int commentEnd) {
4490                 char[] src = this.source;
4491
4492                 // only look for newer task: tags
4493                 if (this.foundTaskCount > 0
4494                                 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4495                         return;
4496                 }
4497                 int foundTaskIndex = this.foundTaskCount;
4498                 char previous = src[commentStart + 1]; // should be '*' or '/'
4499                 nextChar: for (int i = commentStart + 2; i < commentEnd
4500                                 && i < this.eofPosition; i++) {
4501                         char[] tag = null;
4502                         char[] priority = null;
4503                         // check for tag occurrence only if not ambiguous with javadoc tag
4504                         if (previous != '@') {
4505                                 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4506                                         tag = this.taskTags[itag];
4507                                         int tagLength = tag.length;
4508                                         if (tagLength == 0)
4509                                                 continue nextTag;
4510
4511                                         // ensure tag is not leaded with letter if tag starts with a
4512                                         // letter
4513                                         if (Scanner.isPHPIdentifierStart(tag[0])) {
4514                                                 if (Scanner.isPHPIdentifierPart(previous)) {
4515                                                         continue nextTag;
4516                                                 }
4517                                         }
4518
4519                                         for (int t = 0; t < tagLength; t++) {
4520                                                 char sc, tc;
4521                                                 int x = i + t;
4522                                                 if (x >= this.eofPosition || x >= commentEnd)
4523                                                         continue nextTag;
4524                                                 if ((sc = src[i + t]) != (tc = tag[t])) { // case
4525                                                                                                                                         // sensitive
4526                                                                                                                                         // check
4527                                                         if (this.isTaskCaseSensitive
4528                                                                         || (Character.toLowerCase(sc) != Character
4529                                                                                         .toLowerCase(tc))) { // case
4530                                                                 // insensitive
4531                                                                 // check
4532                                                                 continue nextTag;
4533                                                         }
4534                                                 }
4535                                         }
4536                                         // ensure tag is not followed with letter if tag finishes
4537                                         // with a
4538                                         // letter
4539                                         if (i + tagLength < commentEnd
4540                                                         && Scanner.isPHPIdentifierPart(src[i + tagLength
4541                                                                         - 1])) {
4542                                                 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4543                                                         continue nextTag;
4544                                         }
4545                                         if (this.foundTaskTags == null) {
4546                                                 this.foundTaskTags = new char[5][];
4547                                                 this.foundTaskMessages = new char[5][];
4548                                                 this.foundTaskPriorities = new char[5][];
4549                                                 this.foundTaskPositions = new int[5][];
4550                                         } else if (this.foundTaskCount == this.foundTaskTags.length) {
4551                                                 System
4552                                                                 .arraycopy(
4553                                                                                 this.foundTaskTags,
4554                                                                                 0,
4555                                                                                 this.foundTaskTags = new char[this.foundTaskCount * 2][],
4556                                                                                 0, this.foundTaskCount);
4557                                                 System
4558                                                                 .arraycopy(
4559                                                                                 this.foundTaskMessages,
4560                                                                                 0,
4561                                                                                 this.foundTaskMessages = new char[this.foundTaskCount * 2][],
4562                                                                                 0, this.foundTaskCount);
4563                                                 System
4564                                                                 .arraycopy(
4565                                                                                 this.foundTaskPriorities,
4566                                                                                 0,
4567                                                                                 this.foundTaskPriorities = new char[this.foundTaskCount * 2][],
4568                                                                                 0, this.foundTaskCount);
4569                                                 System
4570                                                                 .arraycopy(
4571                                                                                 this.foundTaskPositions,
4572                                                                                 0,
4573                                                                                 this.foundTaskPositions = new int[this.foundTaskCount * 2][],
4574                                                                                 0, this.foundTaskCount);
4575                                         }
4576
4577                                         priority = this.taskPriorities != null
4578                                                         && itag < this.taskPriorities.length ? this.taskPriorities[itag]
4579                                                         : null;
4580
4581                                         this.foundTaskTags[this.foundTaskCount] = tag;
4582                                         this.foundTaskPriorities[this.foundTaskCount] = priority;
4583                                         this.foundTaskPositions[this.foundTaskCount] = new int[] {
4584                                                         i, i + tagLength - 1 };
4585                                         this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4586                                         this.foundTaskCount++;
4587                                         i += tagLength - 1; // will be incremented when looping
4588                                         break nextTag;
4589                                 }
4590                         }
4591                         previous = src[i];
4592                 }
4593                 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4594                         // retrieve message start and end positions
4595                         int msgStart = this.foundTaskPositions[i][0]
4596                                         + this.foundTaskTags[i].length;
4597                         int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1
4598                                         : commentEnd - 1;
4599                         // at most beginning of next task
4600                         if (max_value < msgStart) {
4601                                 max_value = msgStart; // would only occur if tag is before
4602                                                                                 // EOF.
4603                         }
4604                         int end = -1;
4605                         char c;
4606                         for (int j = msgStart; j < max_value; j++) {
4607                                 if ((c = src[j]) == '\n' || c == '\r') {
4608                                         end = j - 1;
4609                                         break;
4610                                 }
4611                         }
4612                         if (end == -1) {
4613                                 for (int j = max_value; j > msgStart; j--) {
4614                                         if ((c = src[j]) == '*') {
4615                                                 end = j - 1;
4616                                                 break;
4617                                         }
4618                                 }
4619                                 if (end == -1)
4620                                         end = max_value;
4621                         }
4622                         if (msgStart == end)
4623                                 continue; // empty
4624                         // trim the message
4625                         while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4626                                 end--;
4627                         while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4628                                 msgStart++;
4629                         // update the end position of the task
4630                         this.foundTaskPositions[i][1] = end;
4631                         // get the message source
4632                         final int messageLength = end - msgStart + 1;
4633                         char[] message = new char[messageLength];
4634                         System.arraycopy(src, msgStart, message, 0, messageLength);
4635                         this.foundTaskMessages[i] = message;
4636                 }
4637         }
4638
4639         // chech presence of task: tags
4640         // public void checkTaskTag(int commentStart, int commentEnd) {
4641         // // only look for newer task: tags
4642         // if (this.foundTaskCount > 0 &&
4643         // this.foundTaskPositions[this.foundTaskCount
4644         // - 1][0] >= commentStart) {
4645         // return;
4646         // }
4647         // int foundTaskIndex = this.foundTaskCount;
4648         // nextChar: for (int i = commentStart; i < commentEnd && i <
4649         // this.eofPosition; i++) {
4650         // char[] tag = null;
4651         // char[] priority = null;
4652         // // check for tag occurrence
4653         // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4654         // tag = this.taskTags[itag];
4655         // priority = this.taskPriorities != null && itag <
4656         // this.taskPriorities.length
4657         // ? this.taskPriorities[itag] : null;
4658         // int tagLength = tag.length;
4659         // for (int t = 0; t < tagLength; t++) {
4660         // if (this.source[i + t] != tag[t])
4661         // continue nextTag;
4662         // }
4663         // if (this.foundTaskTags == null) {
4664         // this.foundTaskTags = new char[5][];
4665         // this.foundTaskMessages = new char[5][];
4666         // this.foundTaskPriorities = new char[5][];
4667         // this.foundTaskPositions = new int[5][];
4668         // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4669         // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new
4670         // char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4671         // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new
4672         // char[this.foundTaskCount * 2][], 0,
4673         // this.foundTaskCount);
4674         // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities =
4675         // new char[this.foundTaskCount * 2][], 0,
4676         // this.foundTaskCount);
4677         // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions =
4678         // new
4679         // int[this.foundTaskCount * 2][], 0,
4680         // this.foundTaskCount);
4681         // }
4682         // this.foundTaskTags[this.foundTaskCount] = tag;
4683         // this.foundTaskPriorities[this.foundTaskCount] = priority;
4684         // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i +
4685         // tagLength
4686         // - 1 };
4687         // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4688         // this.foundTaskCount++;
4689         // i += tagLength - 1; // will be incremented when looping
4690         // }
4691         // }
4692         // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4693         // // retrieve message start and end positions
4694         // int msgStart = this.foundTaskPositions[i][0] +
4695         // this.foundTaskTags[i].length;
4696         // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i +
4697         // 1][0] - 1 : commentEnd - 1;
4698         // // at most beginning of next task
4699         // if (max_value < msgStart)
4700         // max_value = msgStart; // would only occur if tag is before EOF.
4701         // int end = -1;
4702         // char c;
4703         // for (int j = msgStart; j < max_value; j++) {
4704         // if ((c = this.source[j]) == '\n' || c == '\r') {
4705         // end = j - 1;
4706         // break;
4707         // }
4708         // }
4709         // if (end == -1) {
4710         // for (int j = max_value; j > msgStart; j--) {
4711         // if ((c = this.source[j]) == '*') {
4712         // end = j - 1;
4713         // break;
4714         // }
4715         // }
4716         // if (end == -1)
4717         // end = max_value;
4718         // }
4719         // if (msgStart == end)
4720         // continue; // empty
4721         // // trim the message
4722         // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4723         // end--;
4724         // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4725         // msgStart++;
4726         // // update the end position of the task
4727         // this.foundTaskPositions[i][1] = end;
4728         // // get the message source
4729         // final int messageLength = end - msgStart + 1;
4730         // char[] message = new char[messageLength];
4731         // System.arraycopy(source, msgStart, message, 0, messageLength);
4732         // this.foundTaskMessages[i] = message;
4733         // }
4734         // }
4735 }
4736