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