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