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
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
11 import java.util.Iterator;
12 import java.util.List;
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;
21 public class Scanner implements IScanner, ITerminalSymbols {
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
31 // private boolean assertMode;
32 public boolean useAssertAsAnIndentifier = false;
34 // flag indicating if processed source contains occurrences of keyword
36 public boolean containsAssertKeyword = false;
38 public boolean recordLineSeparator;
40 public boolean ignorePHPOneLiner = false;
42 public boolean phpMode = false;
45 * This token is set to TokenName.echo if a short tag block begins (i.e.
46 * >?= ... ) Directly after the "=" character the
47 * getNextToken() method returns TokenName.INLINE_HTML In the next call to
48 * the getNextToken() method the value of fFillerToken (==TokenName.echo) is
52 TokenName fFillerToken = TokenName.EOF;
54 public char currentCharacter;
56 public int startPosition;
58 public int currentPosition;
60 public int initialPosition, eofPosition;
62 // after this position eof are generated instead of real token from the
64 public boolean tokenizeComments;
66 public boolean tokenizeWhiteSpace;
68 public boolean tokenizeStrings;
70 // source should be viewed as a window (aka a part)
71 // of a entire very large stream
75 public char[] withoutUnicodeBuffer;
77 public int withoutUnicodePtr;
79 // when == 0 ==> no unicode in the current token
80 public boolean unicodeAsBackSlash = false;
82 public boolean scanningFloatLiteral = false;
84 // support for /** comments
85 public int[] commentStops = new int[10];
87 public int[] commentStarts = new int[10];
89 public int commentPtr = -1; // no comment test with commentPtr value -1
91 protected int lastCommentLinePosition = -1;
93 // diet parsing support - jump over some method body when requested
94 public boolean diet = false;
96 // support for the poor-line-debuggers ....
97 // remember the position of the cr/lf
98 public int[] lineEnds = new int[250];
100 public int linePtr = -1;
102 public boolean wasAcr = false;
104 public static final String END_OF_SOURCE = "End_Of_Source"; //$NON-NLS-1$
106 public static final String INVALID_HEXA = "Invalid_Hexa_Literal"; //$NON-NLS-1$
108 public static final String INVALID_OCTAL = "Invalid_Octal_Literal"; //$NON-NLS-1$
110 public static final String INVALID_CHARACTER_CONSTANT = "Invalid_Character_Constant"; //$NON-NLS-1$
112 public static final String INVALID_ESCAPE = "Invalid_Escape"; //$NON-NLS-1$
114 public static final String INVALID_INPUT = "Invalid_Input"; //$NON-NLS-1$
116 public static final String INVALID_UNICODE_ESCAPE = "Invalid_Unicode_Escape"; //$NON-NLS-1$
118 public static final String INVALID_FLOAT = "Invalid_Float_Literal"; //$NON-NLS-1$
120 public static final String NULL_SOURCE_STRING = "Null_Source_String"; //$NON-NLS-1$
122 public static final String UNTERMINATED_STRING = "Unterminated_String"; //$NON-NLS-1$
124 public static final String UNTERMINATED_COMMENT = "Unterminated_Comment"; //$NON-NLS-1$
126 public static final String INVALID_CHAR_IN_STRING = "Invalid_Char_In_String"; //$NON-NLS-1$
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' };
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' };
163 public final static int MAX_OBVIOUS = 256;
165 static final int[] ObviousIdentCharNatures = new int[MAX_OBVIOUS];
167 public final static int C_DOLLAR = 8;
169 public final static int C_LETTER = 4;
171 public final static int C_DIGIT = 3;
173 public final static int C_SEPARATOR = 2;
175 public final static int C_SPACE = 1;
177 for (int i = '0'; i <= '9'; i++)
178 ObviousIdentCharNatures[i] = C_DIGIT;
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;
188 ObviousIdentCharNatures['$'] = C_DOLLAR;
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
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;
225 static final char[] initCharArray = new char[] { '\u0000', '\u0000',
226 '\u0000', '\u0000', '\u0000', '\u0000' };
228 static final int TableSize = 30, InternalTableSize = 6;
230 // 30*6 = 180 entries
231 public static final int OptimizedLength = 6;
234 final char[][][][] charArray_length = new char[OptimizedLength][TableSize][InternalTableSize][];
236 // support for detecting non-externalized string literals
237 int currentLineNr = -1;
239 int previousLineNr = -1;
241 NLSLine currentLine = null;
243 List lines = new ArrayList();
245 public static final String TAG_PREFIX = "//$NON-NLS-"; //$NON-NLS-1$
247 public static final int TAG_PREFIX_LENGTH = TAG_PREFIX.length();
249 public static final String TAG_POSTFIX = "$"; //$NON-NLS-1$
251 public static final int TAG_POSTFIX_LENGTH = TAG_POSTFIX.length();
253 public StringLiteral[] nonNLSStrings = null;
255 public boolean checkNonExternalizedStringLiterals = true;
257 public boolean wasNonExternalizedStringLiteral = false;
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;
269 static int newEntry2 = 0, newEntry3 = 0, newEntry4 = 0, newEntry5 = 0,
272 public static final int RoundBracket = 0;
274 public static final int SquareBracket = 1;
276 public static final int CurlyBracket = 2;
278 public static final int BracketKinds = 3;
281 public char[][] foundTaskTags = null;
283 public char[][] foundTaskMessages;
285 public char[][] foundTaskPriorities = null;
287 public int[][] foundTaskPositions;
289 public int foundTaskCount = 0;
291 public char[][] taskTags = null;
293 public char[][] taskPriorities = null;
295 public boolean isTaskCaseSensitive = true;
297 public static final boolean DEBUG = false;
299 public static final boolean TRACE = false;
301 public ICompilationUnit compilationUnit = null;
304 * Determines if the specified character is permissible as the first
305 * character in a PHP identifier or variable
307 * The '$' character for PHP variables is regarded as a correct first
311 public static boolean isPHPIdentOrVarStart(char ch) {
312 if (ch < MAX_OBVIOUS) {
313 return ObviousIdentCharNatures[ch] == C_LETTER
314 || ObviousIdentCharNatures[ch] == C_DOLLAR;
317 // return Character.isLetter(ch) || (ch == '$') || (ch == '_') || (0x7F
319 // ch && ch <= 0xFF);
323 * Determines if the specified character is permissible as the first
324 * character in a PHP identifier.
326 * The '$' character for PHP variables isn't regarded as the first character !
328 public static boolean isPHPIdentifierStart(char ch) {
329 if (ch < MAX_OBVIOUS) {
330 return ObviousIdentCharNatures[ch] == C_LETTER;
333 // return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <=
338 * Determines if the specified character may be part of a PHP identifier as
339 * other than the first character
341 public static boolean isPHPIdentifierPart(char ch) {
342 if (ch < MAX_OBVIOUS) {
343 return ObviousIdentCharNatures[ch] == C_LETTER
344 || ObviousIdentCharNatures[ch] == C_DIGIT;
347 // return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch &&
352 // public static boolean isSQLIdentifierPart(char ch) {
353 // if (ch < MAX_OBVIOUS) {
354 // return ObviousIdentCharNatures[ch] == C_LETTER
355 // || ObviousIdentCharNatures[ch] == C_DIGIT;
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;
366 public char[] getCurrentIdentifierSource() {
367 // return the token REAL source (aka unicodes are precomputed)
369 // if (withoutUnicodePtr != 0)
370 // //0 is used as a fast test flag so the real first char is in position
373 // withoutUnicodeBuffer,
375 // result = new char[withoutUnicodePtr],
377 // withoutUnicodePtr);
379 int length = currentPosition - startPosition;
380 switch (length) { // see OptimizedLength
382 return optimizedCurrentTokenSource1();
384 return optimizedCurrentTokenSource2();
386 return optimizedCurrentTokenSource3();
388 return optimizedCurrentTokenSource4();
390 return optimizedCurrentTokenSource5();
392 return optimizedCurrentTokenSource6();
395 System.arraycopy(source, startPosition, result = new char[length], 0,
401 public int getCurrentTokenEndPosition() {
402 return this.currentPosition - 1;
405 public final char[] getCurrentTokenSource() {
406 // Return the token REAL source (aka unicodes are precomputed)
408 // if (withoutUnicodePtr != 0)
409 // // 0 is used as a fast test flag so the real first char is in
412 // withoutUnicodeBuffer,
414 // result = new char[withoutUnicodePtr],
416 // withoutUnicodePtr);
419 System.arraycopy(source, startPosition,
420 result = new char[length = currentPosition - startPosition], 0,
426 public final char[] getCurrentTokenSource(int startPos) {
427 // Return the token REAL source (aka unicodes are precomputed)
429 // if (withoutUnicodePtr != 0)
430 // // 0 is used as a fast test flag so the real first char is in
433 // withoutUnicodeBuffer,
435 // result = new char[withoutUnicodePtr],
437 // withoutUnicodePtr);
440 System.arraycopy(source, startPos,
441 result = new char[length = currentPosition - startPos], 0,
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.
451 if (withoutUnicodePtr != 0)
452 // 0 is used as a fast test flag so the real first char is in
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);
460 System.arraycopy(source, startPosition + 1,
461 result = new char[length = currentPosition - startPosition
467 public final boolean equalsCurrentTokenSource(char[] word) {
468 if (word.length != currentPosition - startPosition) {
471 for (int i = 0; i < word.length; i++) {
472 if (word[i] != source[startPosition + i]) {
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,
487 public int getCurrentTokenStartPosition() {
488 return this.startPosition;
491 // public final String getCurrentStringLiteral() {
492 // char[] result = getCurrentStringLiteralSource();
493 // return new String(result);
496 public final char[] getCurrentStringLiteralSource() {
497 // Return the token REAL source (aka unicodes are precomputed)
498 if (startPosition + 1 >= currentPosition) {
504 .arraycopy(source, startPosition + 1,
505 result = new char[length = currentPosition
506 - startPosition - 2], 0, length);
511 // public final char[] getCurrentStringLiteralSource(int startPos) {
512 // // Return the token REAL source (aka unicodes are precomputed)
515 // System.arraycopy(source, startPos + 1,
516 // result = new char[length = currentPosition - startPos - 2], 0,
523 * Search the source position corresponding to the end of a given line
526 * Line numbers are 1-based, and relative to the scanner initialPosition.
527 * Character positions are 0-based.
529 * In case the given line number is inconsistent, answers -1.
531 public final int getLineEnd(int lineNumber) {
532 if (lineEnds == null)
534 if (lineNumber >= lineEnds.length)
538 if (lineNumber == lineEnds.length - 1)
540 return lineEnds[lineNumber - 1];
541 // next line start one character behind the lineEnd of the previous line
545 * Search the source position corresponding to the beginning of a given line
548 * Line numbers are 1-based, and relative to the scanner initialPosition.
549 * Character positions are 0-based.
551 * e.g. getLineStart(1) --> 0 i.e. first line starts at character 0.
553 * In case the given line number is inconsistent, answers -1.
555 public final int getLineStart(int lineNumber) {
556 if (lineEnds == null)
558 if (lineNumber >= lineEnds.length)
563 return initialPosition;
564 return lineEnds[lineNumber - 2] + 1;
565 // next line start one character behind the lineEnd of the previous line
568 public final boolean getNextChar(char testedChar) {
570 // handle the case of unicode.
571 // when a unicode appears then we must use a buffer that holds char
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
577 // On false, no side effect has occured.
578 // ALL getNextChar.... ARE OPTIMIZED COPIES
579 int temp = currentPosition;
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++;
593 // if (((c1 = Character.getNumericValue(source[currentPosition++]))
596 // || ((c2 = Character.getNumericValue(source[currentPosition++])) >
599 // || ((c3 = Character.getNumericValue(source[currentPosition++])) >
602 // || ((c4 = Character.getNumericValue(source[currentPosition++])) >
605 // currentPosition = temp;
609 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
610 // if (currentCharacter != testedChar) {
611 // currentPosition = temp;
614 // unicodeAsBackSlash = currentCharacter == '\\';
616 // //need the unicode buffer
617 // if (withoutUnicodePtr == 0) {
618 // //buffer all the entries that have been left aside....
619 // withoutUnicodePtr = currentPosition - unicodeSize -
624 // withoutUnicodeBuffer,
626 // withoutUnicodePtr);
628 // //fill the buffer with the char
629 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
632 // } //-------------end unicode traitement--------------
634 if (currentCharacter != testedChar) {
635 currentPosition = temp;
638 unicodeAsBackSlash = false;
639 // if (withoutUnicodePtr != 0)
640 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
643 } catch (IndexOutOfBoundsException e) {
644 unicodeAsBackSlash = false;
645 currentPosition = temp;
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
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
660 // On false, no side effect has occured.
661 // ALL getNextChar.... ARE OPTIMIZED COPIES
662 int temp = currentPosition;
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++;
677 // if (((c1 = Character.getNumericValue(source[currentPosition++]))
680 // || ((c2 = Character.getNumericValue(source[currentPosition++])) >
683 // || ((c3 = Character.getNumericValue(source[currentPosition++])) >
686 // || ((c4 = Character.getNumericValue(source[currentPosition++])) >
689 // currentPosition = temp;
693 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
694 // if (currentCharacter == testedChar1)
696 // else if (currentCharacter == testedChar2)
699 // currentPosition = temp;
703 // //need the unicode buffer
704 // if (withoutUnicodePtr == 0) {
705 // //buffer all the entries that have been left aside....
706 // withoutUnicodePtr = currentPosition - unicodeSize -
711 // withoutUnicodeBuffer,
713 // withoutUnicodePtr);
715 // //fill the buffer with the char
716 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
718 // } //-------------end unicode traitement--------------
720 if (currentCharacter == testedChar1)
722 else if (currentCharacter == testedChar2)
725 currentPosition = temp;
728 // if (withoutUnicodePtr != 0)
729 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
732 } catch (IndexOutOfBoundsException e) {
733 currentPosition = temp;
738 public final boolean getNextCharAsDigit() {
740 // handle the case of unicode.
741 // when a unicode appears then we must use a buffer that holds char
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;
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++;
762 // if (((c1 = Character.getNumericValue(source[currentPosition++]))
765 // || ((c2 = Character.getNumericValue(source[currentPosition++])) >
768 // || ((c3 = Character.getNumericValue(source[currentPosition++])) >
771 // || ((c4 = Character.getNumericValue(source[currentPosition++])) >
774 // currentPosition = temp;
778 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
779 // if (!Character.isDigit(currentCharacter)) {
780 // currentPosition = temp;
784 // //need the unicode buffer
785 // if (withoutUnicodePtr == 0) {
786 // //buffer all the entries that have been left aside....
787 // withoutUnicodePtr = currentPosition - unicodeSize -
792 // withoutUnicodeBuffer,
794 // withoutUnicodePtr);
796 // //fill the buffer with the char
797 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
799 // } //-------------end unicode traitement--------------
801 if (!Character.isDigit(currentCharacter)) {
802 currentPosition = temp;
805 // if (withoutUnicodePtr != 0)
806 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
809 } catch (IndexOutOfBoundsException e) {
810 currentPosition = temp;
815 public final boolean getNextCharAsDigit(int radix) {
817 // handle the case of unicode.
818 // when a unicode appears then we must use a buffer that holds char
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
825 // On false, no side effect has occured.
826 // ALL getNextChar.... ARE OPTIMIZED COPIES
827 int temp = currentPosition;
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++;
841 // if (((c1 = Character.getNumericValue(source[currentPosition++]))
844 // || ((c2 = Character.getNumericValue(source[currentPosition++])) >
847 // || ((c3 = Character.getNumericValue(source[currentPosition++])) >
850 // || ((c4 = Character.getNumericValue(source[currentPosition++])) >
853 // currentPosition = temp;
857 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
858 // if (Character.digit(currentCharacter, radix) == -1) {
859 // currentPosition = temp;
863 // //need the unicode buffer
864 // if (withoutUnicodePtr == 0) {
865 // //buffer all the entries that have been left aside....
866 // withoutUnicodePtr = currentPosition - unicodeSize -
871 // withoutUnicodeBuffer,
873 // withoutUnicodePtr);
875 // //fill the buffer with the char
876 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
878 // } //-------------end unicode traitement--------------
880 if (Character.digit(currentCharacter, radix) == -1) {
881 currentPosition = temp;
884 // if (withoutUnicodePtr != 0)
885 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
888 } catch (IndexOutOfBoundsException e) {
889 currentPosition = temp;
894 public boolean getNextCharAsJavaIdentifierPart() {
896 // handle the case of unicode.
897 // when a unicode appears then we must use a buffer that holds char
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;
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++;
919 // if (((c1 = Character.getNumericValue(source[currentPosition++]))
922 // || ((c2 = Character.getNumericValue(source[currentPosition++])) >
925 // || ((c3 = Character.getNumericValue(source[currentPosition++])) >
928 // || ((c4 = Character.getNumericValue(source[currentPosition++])) >
931 // currentPosition = temp;
935 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
936 // if (!isPHPIdentifierPart(currentCharacter)) {
937 // currentPosition = temp;
941 // //need the unicode buffer
942 // if (withoutUnicodePtr == 0) {
943 // //buffer all the entries that have been left aside....
944 // withoutUnicodePtr = currentPosition - unicodeSize -
949 // withoutUnicodeBuffer,
951 // withoutUnicodePtr);
953 // //fill the buffer with the char
954 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
956 // } //-------------end unicode traitement--------------
958 if (!isPHPIdentifierPart(currentCharacter)) {
959 currentPosition = temp;
962 // if (withoutUnicodePtr != 0)
963 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
966 } catch (IndexOutOfBoundsException e) {
967 currentPosition = temp;
972 public TokenName getCastOrParen() {
973 int tempPosition = currentPosition;
974 char tempCharacter = currentCharacter;
975 TokenName tempToken = TokenName.LPAREN;
976 boolean found = false;
977 StringBuffer buf = new StringBuffer();
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++];
988 if (buf.length() >= 3 && buf.length() <= 7) {
989 char[] data = buf.toString().toCharArray();
991 switch (data.length) {
994 if ((data[index] == 'i') && (data[++index] == 'n')
995 && (data[++index] == 't')) {
997 tempToken = TokenName.INTCAST;
1002 if ((data[index] == 'b') && (data[++index] == 'o')
1003 && (data[++index] == 'o') && (data[++index] == 'l')) {
1005 tempToken = TokenName.BOOLCAST;
1008 if ((data[index] == 'r') && (data[++index] == 'e')
1009 && (data[++index] == 'a')
1010 && (data[++index] == 'l')) {
1012 tempToken = TokenName.DOUBLECAST;
1017 // array unset float
1018 if ((data[index] == 'a') && (data[++index] == 'r')
1019 && (data[++index] == 'r') && (data[++index] == 'a')
1020 && (data[++index] == 'y')) {
1022 tempToken = TokenName.ARRAYCAST;
1025 if ((data[index] == 'u') && (data[++index] == 'n')
1026 && (data[++index] == 's')
1027 && (data[++index] == 'e')
1028 && (data[++index] == 't')) {
1030 tempToken = TokenName.UNSETCAST;
1033 if ((data[index] == 'f') && (data[++index] == 'l')
1034 && (data[++index] == 'o')
1035 && (data[++index] == 'a')
1036 && (data[++index] == 't')) {
1038 tempToken = TokenName.DOUBLECAST;
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')) {
1049 tempToken = TokenName.OBJECTCAST;
1052 if ((data[index] == 's') && (data[++index] == 't')
1053 && (data[++index] == 'r')
1054 && (data[++index] == 'i')
1055 && (data[++index] == 'n')
1056 && (data[++index] == 'g')) {
1058 tempToken = TokenName.STRINGCAST;
1061 if ((data[index] == 'd') && (data[++index] == 'o')
1062 && (data[++index] == 'u')
1063 && (data[++index] == 'b')
1064 && (data[++index] == 'l')
1065 && (data[++index] == 'e')) {
1067 tempToken = TokenName.DOUBLECAST;
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')) {
1079 tempToken = TokenName.BOOLCAST;
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')) {
1089 tempToken = TokenName.INTCAST;
1095 while (currentCharacter == ' ' || currentCharacter == '\t') {
1096 currentCharacter = source[currentPosition++];
1098 if (currentCharacter == ')') {
1103 } catch (IndexOutOfBoundsException e) {
1105 currentCharacter = tempCharacter;
1106 currentPosition = tempPosition;
1107 return TokenName.LPAREN;
1110 public void consumeStringInterpolated() throws InvalidInputException {
1112 // consume next character
1113 unicodeAsBackSlash = false;
1114 currentCharacter = source[currentPosition++];
1115 // if (((currentCharacter = source[currentPosition++]) == '\\')
1116 // && (source[currentPosition] == 'u')) {
1117 // getNextUnicodeChar();
1119 // if (withoutUnicodePtr != 0) {
1120 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1121 // currentCharacter;
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
1130 // '/u000D' will be fully consumed
1131 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1132 // if (currentPosition + lookAhead == source.length)
1134 // if (source[currentPosition + lookAhead] == '\n')
1136 // if (source[currentPosition + lookAhead] == '\"') {
1137 // currentPosition += lookAhead + 1;
1141 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1143 if (currentCharacter == '\\') {
1144 int escapeSize = currentPosition;
1145 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1146 // scanEscapeCharacter make a side effect on this value and
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
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 \
1162 // where only one is correct
1163 withoutUnicodePtr--;
1166 } else if ((currentCharacter == '\r')
1167 || (currentCharacter == '\n')) {
1168 if (recordLineSeparator) {
1169 pushLineSeparator();
1172 // consume next character
1173 unicodeAsBackSlash = false;
1174 currentCharacter = source[currentPosition++];
1175 // if (((currentCharacter = source[currentPosition++]) == '\\')
1176 // && (source[currentPosition] == 'u')) {
1177 // getNextUnicodeChar();
1179 if (withoutUnicodePtr != 0) {
1180 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
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)
1195 if (source[currentPosition + lookAhead] == '\n')
1197 if (source[currentPosition + lookAhead] == '`') {
1198 currentPosition += lookAhead + 1;
1205 if (checkNonExternalizedStringLiterals) { // check for presence of NLS
1207 // //$NON-NLS-?$ where ? is an
1209 if (currentLine == null) {
1210 currentLine = new NLSLine();
1211 lines.add(currentLine);
1213 currentLine.add(new StringLiteral(getCurrentTokenSourceString(),
1214 startPosition, currentPosition - 1));
1218 public void consumeStringConstant() throws InvalidInputException {
1220 // consume next character
1221 unicodeAsBackSlash = false;
1222 currentCharacter = source[currentPosition++];
1223 // if (((currentCharacter = source[currentPosition++]) == '\\')
1224 // && (source[currentPosition] == 'u')) {
1225 // getNextUnicodeChar();
1227 // if (withoutUnicodePtr != 0) {
1228 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1229 // currentCharacter;
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
1238 // '/u000D' will be fully consumed
1239 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1240 // if (currentPosition + lookAhead == source.length)
1242 // if (source[currentPosition + lookAhead] == '\n')
1244 // if (source[currentPosition + lookAhead] == '\"') {
1245 // currentPosition += lookAhead + 1;
1249 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1251 if (currentCharacter == '\\') {
1252 int escapeSize = currentPosition;
1253 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1254 // scanEscapeCharacter make a side effect on this value and
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
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 \
1270 // where only one is correct
1271 withoutUnicodePtr--;
1274 } else if ((currentCharacter == '\r')
1275 || (currentCharacter == '\n')) {
1276 if (recordLineSeparator) {
1277 pushLineSeparator();
1280 // consume next character
1281 unicodeAsBackSlash = false;
1282 currentCharacter = source[currentPosition++];
1283 // if (((currentCharacter = source[currentPosition++]) == '\\')
1284 // && (source[currentPosition] == 'u')) {
1285 // getNextUnicodeChar();
1287 if (withoutUnicodePtr != 0) {
1288 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
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)
1303 if (source[currentPosition + lookAhead] == '\n')
1305 if (source[currentPosition + lookAhead] == '\'') {
1306 currentPosition += lookAhead + 1;
1313 if (checkNonExternalizedStringLiterals) { // check for presence of NLS
1315 // //$NON-NLS-?$ where ? is an
1317 if (currentLine == null) {
1318 currentLine = new NLSLine();
1319 lines.add(currentLine);
1321 currentLine.add(new StringLiteral(getCurrentTokenSourceString(),
1322 startPosition, currentPosition - 1));
1326 public void consumeStringLiteral() throws InvalidInputException {
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
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
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 \
1353 // where only one is correct
1354 withoutUnicodePtr--;
1357 } else if (currentCharacter == '$'
1358 && source[currentPosition] == '{') {
1360 } else if (currentCharacter == '{'
1361 && source[currentPosition] == '$') {
1363 } else if (currentCharacter == '}') {
1365 } else if ((currentCharacter == '\r')
1366 || (currentCharacter == '\n')) {
1367 if (recordLineSeparator) {
1368 pushLineSeparator();
1371 // consume next character
1372 unicodeAsBackSlash = false;
1373 currentCharacter = source[currentPosition++];
1374 if (withoutUnicodePtr != 0) {
1375 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
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)
1389 if (source[currentPosition + lookAhead] == '\n')
1391 if (source[currentPosition + lookAhead] == '\"') {
1392 currentPosition += lookAhead + 1;
1399 if (checkNonExternalizedStringLiterals) { // check for presence of NLS
1401 // //$NON-NLS-?$ where ? is an
1403 if (currentLine == null) {
1404 currentLine = new NLSLine();
1405 lines.add(currentLine);
1407 currentLine.add(new StringLiteral(getCurrentTokenSourceString(),
1408 startPosition, currentPosition - 1));
1412 public TokenName getNextToken() throws InvalidInputException {
1414 return getInlinedHTMLToken(currentPosition);
1416 if (fFillerToken != TokenName.EOF) {
1417 TokenName tempToken;
1418 startPosition = currentPosition;
1419 tempToken = fFillerToken;
1420 fFillerToken = TokenName.EOF;
1423 this.wasAcr = false;
1425 jumpOverMethodBody();
1427 return currentPosition > source.length ? TokenName.EOF
1432 withoutUnicodePtr = 0;
1433 // ---------Consume white space and handles
1434 // startPosition---------
1435 int whiteStart = currentPosition;
1436 startPosition = currentPosition;
1437 currentCharacter = source[currentPosition++];
1439 while ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) {
1440 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1441 checkNonExternalizeString();
1443 if (recordLineSeparator) {
1444 pushLineSeparator();
1449 startPosition = currentPosition;
1450 currentCharacter = source[currentPosition++];
1453 if (tokenizeWhiteSpace && (whiteStart != currentPosition - 1)) {
1454 // reposition scanner in case we are interested by
1457 startPosition = whiteStart;
1458 return TokenName.WHITESPACE;
1460 // little trick to get out in the middle of a source
1462 if (currentPosition > eofPosition)
1463 return TokenName.EOF;
1464 // ---------Identify the next token-------------
1465 switch (currentCharacter) {
1467 return getCastOrParen();
1469 return TokenName.RPAREN;
1471 return TokenName.LBRACE;
1473 return TokenName.RBRACE;
1475 return TokenName.LBRACKET;
1477 return TokenName.RBRACKET;
1479 return TokenName.SEMICOLON;
1481 return TokenName.COMMA;
1483 if (getNextChar('='))
1484 return TokenName.DOT_EQUAL;
1485 if (getNextCharAsDigit())
1486 return scanNumber(true);
1487 return TokenName.DOT;
1489 return TokenName.BACKSLASH;
1492 if ((test = getNextChar('+', '=')) == 0)
1493 return TokenName.PLUS_PLUS;
1495 return TokenName.PLUS_EQUAL;
1496 return TokenName.PLUS;
1500 if ((test = getNextChar('-', '=')) == 0)
1501 return TokenName.MINUS_MINUS;
1503 return TokenName.MINUS_EQUAL;
1504 if (getNextChar('>'))
1505 return TokenName.MINUS_GREATER;
1506 return TokenName.MINUS;
1509 if (getNextChar('='))
1510 return TokenName.TWIDDLE_EQUAL;
1511 return TokenName.TWIDDLE;
1513 if (getNextChar('=')) {
1514 if (getNextChar('=')) {
1515 return TokenName.NOT_EQUAL_EQUAL;
1517 return TokenName.NOT_EQUAL;
1519 return TokenName.NOT;
1521 if (getNextChar('='))
1522 return TokenName.MULTIPLY_EQUAL;
1523 return TokenName.MULTIPLY;
1525 if (getNextChar('='))
1526 return TokenName.REMAINDER_EQUAL;
1527 return TokenName.REMAINDER;
1529 int oldPosition = currentPosition;
1531 currentCharacter = source[currentPosition++];
1532 } catch (IndexOutOfBoundsException e) {
1533 currentPosition = oldPosition;
1534 return TokenName.LESS;
1536 switch (currentCharacter) {
1538 return TokenName.LESS_EQUAL;
1540 return TokenName.NOT_EQUAL;
1542 if (getNextChar('='))
1543 return TokenName.LEFT_SHIFT_EQUAL;
1544 if (getNextChar('<')) {
1545 currentCharacter = source[currentPosition++];
1546 while (Character.isWhitespace(currentCharacter)) {
1547 currentCharacter = source[currentPosition++];
1549 int heredocStart = currentPosition - 1;
1550 int heredocLength = 0;
1551 if (isPHPIdentifierStart(currentCharacter)) {
1552 currentCharacter = source[currentPosition++];
1554 return TokenName.ERROR;
1556 while (isPHPIdentifierPart(currentCharacter)) {
1557 currentCharacter = source[currentPosition++];
1559 heredocLength = currentPosition - heredocStart
1561 // heredoc end-tag determination
1562 boolean endTag = true;
1565 ch = source[currentPosition++];
1566 if (ch == '\r' || ch == '\n') {
1567 if (recordLineSeparator) {
1568 pushLineSeparator();
1572 for (int i = 0; i < heredocLength; i++) {
1573 if (source[currentPosition + i] != source[heredocStart
1580 currentPosition += heredocLength - 1;
1581 currentCharacter = source[currentPosition++];
1582 break; // do...while loop
1588 return TokenName.HEREDOC;
1590 return TokenName.LEFT_SHIFT;
1592 currentPosition = oldPosition;
1593 return TokenName.LESS;
1597 if ((test = getNextChar('=', '>')) == 0)
1598 return TokenName.GREATER_EQUAL;
1600 if ((test = getNextChar('=', '>')) == 0)
1601 return TokenName.RIGHT_SHIFT_EQUAL;
1602 return TokenName.RIGHT_SHIFT;
1604 return TokenName.GREATER;
1607 if (getNextChar('=')) {
1608 if (getNextChar('=')) {
1609 return TokenName.EQUAL_EQUAL_EQUAL;
1611 return TokenName.EQUAL_EQUAL;
1613 if (getNextChar('>'))
1614 return TokenName.EQUAL_GREATER;
1615 return TokenName.EQUAL;
1618 if ((test = getNextChar('&', '=')) == 0)
1619 return TokenName.AND_AND;
1621 return TokenName.AND_EQUAL;
1622 return TokenName.OP_AND;
1626 if ((test = getNextChar('|', '=')) == 0)
1627 return TokenName.OR_OR;
1629 return TokenName.OR_EQUAL;
1630 return TokenName.OP_OR;
1633 if (getNextChar('='))
1634 return TokenName.XOR_EQUAL;
1635 return TokenName.OP_XOR;
1637 if (getNextChar('>')) {
1639 if (currentPosition == source.length) {
1641 return TokenName.INLINE_HTML;
1643 return getInlinedHTMLToken(currentPosition - 2);
1645 return TokenName.QUESTION;
1647 if (getNextChar(':'))
1648 return TokenName.PAAMAYIM_NEKUDOTAYIM;
1649 return TokenName.COLON;
1651 return TokenName.OP_AT;
1653 consumeStringConstant();
1654 return TokenName.STRINGSINGLEQUOTE;
1656 // if (tokenizeStrings) {
1657 consumeStringLiteral();
1658 return TokenName.STRINGDOUBLEQUOTE;
1660 // return TokenName.EncapsedString2;
1662 // if (tokenizeStrings) {
1663 consumeStringInterpolated();
1664 return TokenName.STRINGINTERPOLATED;
1666 // return TokenName.EncapsedString0;
1669 char startChar = currentCharacter;
1670 if (getNextChar('=') && startChar == '/') {
1671 return TokenName.DIVIDE_EQUAL;
1674 if ((startChar == '#')
1675 || (test = getNextChar('/', '*')) == 0) {
1677 this.lastCommentLinePosition = this.currentPosition;
1678 int endPositionForLineComment = 0;
1679 try { // get the next char
1680 currentCharacter = source[currentPosition++];
1681 // if (((currentCharacter =
1682 // source[currentPosition++])
1684 // && (source[currentPosition] == 'u')) {
1685 // //-------------unicode traitement
1687 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1688 // currentPosition++;
1689 // while (source[currentPosition] == 'u') {
1690 // currentPosition++;
1693 // Character.getNumericValue(source[currentPosition++]))
1697 // Character.getNumericValue(source[currentPosition++]))
1701 // Character.getNumericValue(source[currentPosition++]))
1705 // Character.getNumericValue(source[currentPosition++]))
1709 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1711 // currentCharacter =
1712 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
1716 // handle the \\u case manually into comment
1717 // if (currentCharacter == '\\') {
1718 // if (source[currentPosition] == '\\')
1719 // currentPosition++;
1720 // } //jump over the \\
1721 boolean isUnicode = false;
1722 while (currentCharacter != '\r'
1723 && currentCharacter != '\n') {
1724 this.lastCommentLinePosition = this.currentPosition;
1725 if (currentCharacter == '?') {
1726 if (getNextChar('>')) {
1727 // ?> breaks line comments
1728 startPosition = currentPosition - 2;
1730 return TokenName.INLINE_HTML;
1733 // get the next char
1735 currentCharacter = source[currentPosition++];
1736 // if (((currentCharacter =
1737 // source[currentPosition++])
1739 // && (source[currentPosition] == 'u')) {
1740 // isUnicode = true;
1741 // //-------------unicode traitement
1743 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1744 // currentPosition++;
1745 // while (source[currentPosition] == 'u') {
1746 // currentPosition++;
1749 // Character.getNumericValue(source[currentPosition++]))
1753 // Character.getNumericValue(
1754 // source[currentPosition++]))
1758 // Character.getNumericValue(
1759 // source[currentPosition++]))
1763 // Character.getNumericValue(
1764 // source[currentPosition++]))
1768 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1770 // currentCharacter =
1771 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
1775 // handle the \\u case manually into comment
1776 // if (currentCharacter == '\\') {
1777 // if (source[currentPosition] == '\\')
1778 // currentPosition++;
1779 // } //jump over the \\
1782 endPositionForLineComment = currentPosition - 6;
1784 endPositionForLineComment = currentPosition - 1;
1786 // recordComment(false);
1787 recordComment(TokenName.COMMENT_LINE);
1788 if (this.taskTags != null)
1789 checkTaskTag(this.startPosition,
1790 this.currentPosition);
1791 if ((currentCharacter == '\r')
1792 || (currentCharacter == '\n')) {
1793 checkNonExternalizeString();
1794 if (recordLineSeparator) {
1796 pushUnicodeLineSeparator();
1798 pushLineSeparator();
1804 if (tokenizeComments) {
1806 currentPosition = endPositionForLineComment;
1807 // reset one character behind
1809 return TokenName.COMMENT_LINE;
1811 } catch (IndexOutOfBoundsException e) { // an eof
1814 if (tokenizeComments) {
1816 // reset one character behind
1817 return TokenName.COMMENT_LINE;
1823 // traditional and annotation comment
1824 boolean isJavadoc = false, star = false;
1825 // consume next character
1826 unicodeAsBackSlash = false;
1827 currentCharacter = source[currentPosition++];
1828 // if (((currentCharacter =
1829 // source[currentPosition++]) ==
1831 // && (source[currentPosition] == 'u')) {
1832 // getNextUnicodeChar();
1834 // if (withoutUnicodePtr != 0) {
1835 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1836 // currentCharacter;
1839 if (currentCharacter == '*') {
1843 if ((currentCharacter == '\r')
1844 || (currentCharacter == '\n')) {
1845 checkNonExternalizeString();
1846 if (recordLineSeparator) {
1847 pushLineSeparator();
1852 try { // get the next char
1853 currentCharacter = source[currentPosition++];
1854 // if (((currentCharacter =
1855 // source[currentPosition++])
1857 // && (source[currentPosition] == 'u')) {
1858 // //-------------unicode traitement
1860 // getNextUnicodeChar();
1862 // handle the \\u case manually into comment
1863 // if (currentCharacter == '\\') {
1864 // if (source[currentPosition] == '\\')
1865 // currentPosition++;
1866 // //jump over the \\
1868 // empty comment is not a javadoc /**/
1869 if (currentCharacter == '/') {
1872 // loop until end of comment */
1873 while ((currentCharacter != '/') || (!star)) {
1874 if ((currentCharacter == '\r')
1875 || (currentCharacter == '\n')) {
1876 checkNonExternalizeString();
1877 if (recordLineSeparator) {
1878 pushLineSeparator();
1883 star = currentCharacter == '*';
1885 currentCharacter = source[currentPosition++];
1886 // if (((currentCharacter =
1887 // source[currentPosition++])
1889 // && (source[currentPosition] == 'u')) {
1890 // //-------------unicode traitement
1892 // getNextUnicodeChar();
1894 // handle the \\u case manually into comment
1895 // if (currentCharacter == '\\') {
1896 // if (source[currentPosition] == '\\')
1897 // currentPosition++;
1898 // } //jump over the \\
1900 // recordComment(isJavadoc);
1902 recordComment(TokenName.COMMENT_PHPDOC);
1904 recordComment(TokenName.COMMENT_BLOCK);
1907 if (tokenizeComments) {
1909 return TokenName.COMMENT_PHPDOC;
1910 return TokenName.COMMENT_BLOCK;
1913 if (this.taskTags != null) {
1914 checkTaskTag(this.startPosition,
1915 this.currentPosition);
1917 } catch (IndexOutOfBoundsException e) {
1918 // reset end position for error reporting
1919 currentPosition -= 2;
1920 throw new InvalidInputException(
1921 UNTERMINATED_COMMENT);
1925 return TokenName.DIVIDE;
1929 return TokenName.EOF;
1930 // the atEnd may not be <currentPosition ==
1931 // source.length> if
1932 // source is only some part of a real (external) stream
1933 throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$
1935 if (currentCharacter == '$') {
1936 int oldPosition = currentPosition;
1938 currentCharacter = source[currentPosition++];
1939 if (isPHPIdentifierStart(currentCharacter)) {
1940 return scanIdentifierOrKeyword(true);
1942 currentPosition = oldPosition;
1943 return TokenName.DOLLAR;
1945 } catch (IndexOutOfBoundsException e) {
1946 currentPosition = oldPosition;
1947 return TokenName.DOLLAR;
1951 if (isPHPIdentifierStart(currentCharacter)) {
1952 return scanIdentifierOrKeyword(false);
1955 if (Character.isDigit(currentCharacter)) {
1956 return scanNumber(false);
1959 return TokenName.ERROR;
1962 } // -----------------end switch while try--------------------
1963 catch (IndexOutOfBoundsException e) {
1966 return TokenName.EOF;
1971 * @throws InvalidInputException
1973 private TokenName getInlinedHTMLToken(int start) throws InvalidInputException {
1974 boolean phpShortTag = false; // true, if <?= detected
1975 if (currentPosition > source.length) {
1976 currentPosition = source.length;
1977 return TokenName.EOF;
1979 startPosition = start;
1982 currentCharacter = source[currentPosition++];
1983 if (currentCharacter == '<') {
1984 if (getNextChar('?')) {
1985 currentCharacter = source[currentPosition++];
1986 if ((currentCharacter != 'P')
1987 && (currentCharacter != 'p')) {
1988 if (currentCharacter != '=') { // <?=
1990 phpShortTag = false;
1995 if (ignorePHPOneLiner) { // for CodeFormatter
1996 if (lookAheadLinePHPTag() == TokenName.INLINE_HTML) {
1999 fFillerToken = TokenName.ECHO_INVISIBLE;
2001 return TokenName.INLINE_HTML;
2004 boolean foundXML = false;
2005 if (getNextChar('X', 'x') >= 0) {
2006 if (getNextChar('M', 'm') >= 0) {
2007 if (getNextChar('L', 'l') >= 0) {
2016 fFillerToken = TokenName.ECHO_INVISIBLE;
2018 return TokenName.INLINE_HTML;
2021 if (getNextChar('H', 'h') >= 0) {
2022 if (getNextChar('P', 'p') >= 0) {
2024 if (ignorePHPOneLiner) {
2025 if (lookAheadLinePHPTag() == TokenName.INLINE_HTML) {
2027 return TokenName.INLINE_HTML;
2031 return TokenName.INLINE_HTML;
2039 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
2040 if (recordLineSeparator) {
2041 pushLineSeparator();
2046 } // -----------------while--------------------
2048 return TokenName.INLINE_HTML;
2049 } // -----------------try--------------------
2050 catch (IndexOutOfBoundsException e) {
2051 startPosition = start;
2055 return TokenName.INLINE_HTML;
2059 * check if the PHP is only in this line (for CodeFormatter)
2063 private TokenName lookAheadLinePHPTag() {
2064 int currentPositionInLine = currentPosition;
2065 char previousCharInLine = ' ';
2066 char currentCharInLine = ' ';
2067 boolean singleQuotedStringActive = false;
2068 boolean doubleQuotedStringActive = false;
2071 // look ahead in this line
2073 previousCharInLine = currentCharInLine;
2074 currentCharInLine = source[currentPositionInLine++];
2075 switch (currentCharInLine) {
2077 if (previousCharInLine == '?') {
2078 // update the scanner's current Position in the source
2079 currentPosition = currentPositionInLine;
2080 // use as "dummy" token
2081 return TokenName.EOF;
2085 if (doubleQuotedStringActive) {
2086 // ignore escaped characters in double quoted strings
2087 previousCharInLine = currentCharInLine;
2088 currentCharInLine = source[currentPositionInLine++];
2091 if (doubleQuotedStringActive) {
2092 doubleQuotedStringActive = false;
2094 if (!singleQuotedStringActive) {
2095 doubleQuotedStringActive = true;
2100 if (singleQuotedStringActive) {
2101 if (previousCharInLine != '\\') {
2102 singleQuotedStringActive = false;
2105 if (!doubleQuotedStringActive) {
2106 singleQuotedStringActive = true;
2112 return TokenName.INLINE_HTML;
2114 if (!singleQuotedStringActive && !doubleQuotedStringActive) {
2116 return TokenName.INLINE_HTML;
2120 if (previousCharInLine == '/' && !singleQuotedStringActive
2121 && !doubleQuotedStringActive) {
2123 return TokenName.INLINE_HTML;
2127 if (previousCharInLine == '/' && !singleQuotedStringActive
2128 && !doubleQuotedStringActive) {
2130 return TokenName.INLINE_HTML;
2135 } catch (IndexOutOfBoundsException e) {
2137 currentPosition = currentPositionInLine - 1;
2138 return TokenName.INLINE_HTML;
2142 // public final void getNextUnicodeChar()
2143 // throws IndexOutOfBoundsException, InvalidInputException {
2145 // //handle the case of unicode.
2146 // //when a unicode appears then we must use a buffer that holds char
2148 // //At the end of this method currentCharacter holds the new visited char
2149 // //and currentPosition points right next after it
2151 // //ALL getNextChar.... ARE OPTIMIZED COPIES
2153 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
2154 // currentPosition++;
2155 // while (source[currentPosition] == 'u') {
2156 // currentPosition++;
2160 // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2162 // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
2164 // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
2166 // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
2168 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2170 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2171 // //need the unicode buffer
2172 // if (withoutUnicodePtr == 0) {
2173 // //buffer all the entries that have been left aside....
2174 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
2175 // System.arraycopy(
2178 // withoutUnicodeBuffer,
2180 // withoutUnicodePtr);
2182 // //fill the buffer with the char
2183 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2185 // unicodeAsBackSlash = currentCharacter == '\\';
2188 * Tokenize a method body, assuming that curly brackets are properly
2191 public final void jumpOverMethodBody() {
2192 this.wasAcr = false;
2195 while (true) { // loop for jumping over comments
2196 // ---------Consume white space and handles
2197 // startPosition---------
2198 boolean isWhiteSpace;
2200 startPosition = currentPosition;
2201 currentCharacter = source[currentPosition++];
2202 // if (((currentCharacter = source[currentPosition++]) ==
2204 // && (source[currentPosition] == 'u')) {
2205 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
2207 if (recordLineSeparator
2208 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2209 pushLineSeparator();
2210 isWhiteSpace = Character.isWhitespace(currentCharacter);
2212 } while (isWhiteSpace);
2213 // -------consume token until } is found---------
2214 switch (currentCharacter) {
2225 test = getNextChar('\\');
2228 scanDoubleQuotedEscapeCharacter();
2229 } catch (InvalidInputException ex) {
2233 // try { // consume next character
2234 unicodeAsBackSlash = false;
2235 currentCharacter = source[currentPosition++];
2236 // if (((currentCharacter = source[currentPosition++])
2238 // && (source[currentPosition] == 'u')) {
2239 // getNextUnicodeChar();
2241 if (withoutUnicodePtr != 0) {
2242 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2245 // } catch (InvalidInputException ex) {
2253 // try { // consume next character
2254 unicodeAsBackSlash = false;
2255 currentCharacter = source[currentPosition++];
2256 // if (((currentCharacter = source[currentPosition++])
2258 // && (source[currentPosition] == 'u')) {
2259 // getNextUnicodeChar();
2261 if (withoutUnicodePtr != 0) {
2262 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2265 // } catch (InvalidInputException ex) {
2267 while (currentCharacter != '"') {
2268 if (currentCharacter == '\r') {
2269 if (source[currentPosition] == '\n')
2272 // the string cannot go further that the line
2274 if (currentCharacter == '\n') {
2276 // the string cannot go further that the line
2278 if (currentCharacter == '\\') {
2280 scanDoubleQuotedEscapeCharacter();
2281 } catch (InvalidInputException ex) {
2285 // try { // consume next character
2286 unicodeAsBackSlash = false;
2287 currentCharacter = source[currentPosition++];
2288 // if (((currentCharacter =
2289 // source[currentPosition++]) == '\\')
2290 // && (source[currentPosition] == 'u')) {
2291 // getNextUnicodeChar();
2293 if (withoutUnicodePtr != 0) {
2294 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2297 // } catch (InvalidInputException ex) {
2300 } catch (IndexOutOfBoundsException e) {
2306 if ((test = getNextChar('/', '*')) == 0) {
2309 // get the next char
2310 currentCharacter = source[currentPosition++];
2311 // if (((currentCharacter =
2312 // source[currentPosition++]) ==
2314 // && (source[currentPosition] == 'u')) {
2315 // //-------------unicode traitement ------------
2316 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2317 // currentPosition++;
2318 // while (source[currentPosition] == 'u') {
2319 // currentPosition++;
2322 // Character.getNumericValue(source[currentPosition++]))
2326 // Character.getNumericValue(source[currentPosition++]))
2330 // Character.getNumericValue(source[currentPosition++]))
2334 // Character.getNumericValue(source[currentPosition++]))
2337 // //error don't care of the value
2338 // currentCharacter = 'A';
2339 // } //something different from \n and \r
2341 // currentCharacter =
2342 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2345 while (currentCharacter != '\r'
2346 && currentCharacter != '\n') {
2347 // get the next char
2348 currentCharacter = source[currentPosition++];
2349 // if (((currentCharacter =
2350 // source[currentPosition++])
2352 // && (source[currentPosition] == 'u')) {
2353 // //-------------unicode traitement
2355 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2356 // currentPosition++;
2357 // while (source[currentPosition] == 'u') {
2358 // currentPosition++;
2361 // Character.getNumericValue(source[currentPosition++]))
2365 // Character.getNumericValue(source[currentPosition++]))
2369 // Character.getNumericValue(source[currentPosition++]))
2373 // Character.getNumericValue(source[currentPosition++]))
2376 // //error don't care of the value
2377 // currentCharacter = 'A';
2378 // } //something different from \n and \r
2380 // currentCharacter =
2381 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
2386 if (recordLineSeparator
2387 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2388 pushLineSeparator();
2389 } catch (IndexOutOfBoundsException e) {
2390 } // an eof will them be generated
2394 // traditional and annotation comment
2395 boolean star = false;
2396 // try { // consume next character
2397 unicodeAsBackSlash = false;
2398 currentCharacter = source[currentPosition++];
2399 // if (((currentCharacter = source[currentPosition++])
2401 // && (source[currentPosition] == 'u')) {
2402 // getNextUnicodeChar();
2404 if (withoutUnicodePtr != 0) {
2405 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2408 // } catch (InvalidInputException ex) {
2410 if (currentCharacter == '*') {
2413 if (recordLineSeparator
2414 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2415 pushLineSeparator();
2416 try { // get the next char
2417 currentCharacter = source[currentPosition++];
2418 // if (((currentCharacter =
2419 // source[currentPosition++]) ==
2421 // && (source[currentPosition] == 'u')) {
2422 // //-------------unicode traitement ------------
2423 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2424 // currentPosition++;
2425 // while (source[currentPosition] == 'u') {
2426 // currentPosition++;
2429 // Character.getNumericValue(source[currentPosition++]))
2433 // Character.getNumericValue(source[currentPosition++]))
2437 // Character.getNumericValue(source[currentPosition++]))
2441 // Character.getNumericValue(source[currentPosition++]))
2444 // //error don't care of the value
2445 // currentCharacter = 'A';
2446 // } //something different from * and /
2448 // currentCharacter =
2449 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2452 // loop until end of comment */
2453 while ((currentCharacter != '/') || (!star)) {
2454 if (recordLineSeparator
2455 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2456 pushLineSeparator();
2457 star = currentCharacter == '*';
2459 currentCharacter = source[currentPosition++];
2460 // if (((currentCharacter =
2461 // source[currentPosition++])
2463 // && (source[currentPosition] == 'u')) {
2464 // //-------------unicode traitement
2466 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2467 // currentPosition++;
2468 // while (source[currentPosition] == 'u') {
2469 // currentPosition++;
2472 // Character.getNumericValue(source[currentPosition++]))
2476 // Character.getNumericValue(source[currentPosition++]))
2480 // Character.getNumericValue(source[currentPosition++]))
2484 // Character.getNumericValue(source[currentPosition++]))
2487 // //error don't care of the value
2488 // currentCharacter = 'A';
2489 // } //something different from * and /
2491 // currentCharacter =
2492 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
2497 } catch (IndexOutOfBoundsException e) {
2505 if (isPHPIdentOrVarStart(currentCharacter)) {
2507 scanIdentifierOrKeyword((currentCharacter == '$'));
2508 } catch (InvalidInputException ex) {
2513 if (ObviousIdentCharNatures[currentCharacter] == C_DIGIT) {
2514 // if (Character.isDigit(currentCharacter)) {
2517 } catch (InvalidInputException ex) {
2524 // -----------------end switch while try--------------------
2525 } catch (IndexOutOfBoundsException e) {
2526 } catch (InvalidInputException e) {
2531 // public final boolean jumpOverUnicodeWhiteSpace()
2532 // throws InvalidInputException {
2534 // //handle the case of unicode. Jump over the next whiteSpace
2535 // //making startPosition pointing on the next available char
2536 // //On false, the currentCharacter is filled up with a potential
2540 // this.wasAcr = false;
2541 // int c1, c2, c3, c4;
2542 // int unicodeSize = 6;
2543 // currentPosition++;
2544 // while (source[currentPosition] == 'u') {
2545 // currentPosition++;
2549 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2551 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2553 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2555 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2557 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2560 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2561 // if (recordLineSeparator
2562 // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2563 // pushLineSeparator();
2564 // if (Character.isWhitespace(currentCharacter))
2567 // //buffer the new char which is not a white space
2568 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2569 // //withoutUnicodePtr == 1 is true here
2571 // } catch (IndexOutOfBoundsException e) {
2572 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2575 public final int[] getLineEnds() {
2576 // return a bounded copy of this.lineEnds
2578 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0,
2583 public char[] getSource() {
2587 public static boolean isIdentifierOrKeyword (TokenName token) {
2588 return (token == TokenName.IDENTIFIER) || (token.compareTo (TokenName.KEYWORD) > 0);
2591 final char[] optimizedCurrentTokenSource1() {
2592 // return always the same char[] build only once
2593 // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2594 char charOne = source[startPosition];
2649 return new char[] { charOne };
2653 final char[] optimizedCurrentTokenSource2() {
2655 c0 = source[startPosition];
2656 c1 = source[startPosition + 1];
2658 // return always the same char[] build only once
2659 // optimization at no speed cost of 99.5 % of the
2660 // singleCharIdentifier
2663 return charArray_va;
2665 return charArray_vb;
2667 return charArray_vc;
2669 return charArray_vd;
2671 return charArray_ve;
2673 return charArray_vf;
2675 return charArray_vg;
2677 return charArray_vh;
2679 return charArray_vi;
2681 return charArray_vj;
2683 return charArray_vk;
2685 return charArray_vl;
2687 return charArray_vm;
2689 return charArray_vn;
2691 return charArray_vo;
2693 return charArray_vp;
2695 return charArray_vq;
2697 return charArray_vr;
2699 return charArray_vs;
2701 return charArray_vt;
2703 return charArray_vu;
2705 return charArray_vv;
2707 return charArray_vw;
2709 return charArray_vx;
2711 return charArray_vy;
2713 return charArray_vz;
2716 // try to return the same char[] build only once
2717 int hash = ((c0 << 6) + c1) % TableSize;
2718 char[][] table = charArray_length[0][hash];
2720 while (++i < InternalTableSize) {
2721 char[] charArray = table[i];
2722 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2725 // ---------other side---------
2727 int max = newEntry2;
2728 while (++i <= max) {
2729 char[] charArray = table[i];
2730 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2733 // --------add the entry-------
2734 if (++max >= InternalTableSize)
2737 table[max] = (r = new char[] { c0, c1 });
2742 final char[] optimizedCurrentTokenSource3() {
2743 // try to return the same char[] build only once
2745 int hash = (((c0 = source[startPosition]) << 12)
2746 + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2748 char[][] table = charArray_length[1][hash];
2750 while (++i < InternalTableSize) {
2751 char[] charArray = table[i];
2752 if ((c0 == charArray[0]) && (c1 == charArray[1])
2753 && (c2 == charArray[2]))
2756 // ---------other side---------
2758 int max = newEntry3;
2759 while (++i <= max) {
2760 char[] charArray = table[i];
2761 if ((c0 == charArray[0]) && (c1 == charArray[1])
2762 && (c2 == charArray[2]))
2765 // --------add the entry-------
2766 if (++max >= InternalTableSize)
2769 table[max] = (r = new char[] { c0, c1, c2 });
2774 final char[] optimizedCurrentTokenSource4() {
2775 // try to return the same char[] build only once
2776 char c0, c1, c2, c3;
2777 long hash = ((((long) (c0 = source[startPosition])) << 18)
2778 + ((c1 = source[startPosition + 1]) << 12)
2779 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2781 char[][] table = charArray_length[2][(int) hash];
2783 while (++i < InternalTableSize) {
2784 char[] charArray = table[i];
2785 if ((c0 == charArray[0]) && (c1 == charArray[1])
2786 && (c2 == charArray[2]) && (c3 == charArray[3]))
2789 // ---------other side---------
2791 int max = newEntry4;
2792 while (++i <= max) {
2793 char[] charArray = table[i];
2794 if ((c0 == charArray[0]) && (c1 == charArray[1])
2795 && (c2 == charArray[2]) && (c3 == charArray[3]))
2798 // --------add the entry-------
2799 if (++max >= InternalTableSize)
2802 table[max] = (r = new char[] { c0, c1, c2, c3 });
2807 final char[] optimizedCurrentTokenSource5() {
2808 // try to return the same char[] build only once
2809 char c0, c1, c2, c3, c4;
2810 long hash = ((((long) (c0 = source[startPosition])) << 24)
2811 + (((long) (c1 = source[startPosition + 1])) << 18)
2812 + ((c2 = source[startPosition + 2]) << 12)
2813 + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2815 char[][] table = charArray_length[3][(int) hash];
2817 while (++i < InternalTableSize) {
2818 char[] charArray = table[i];
2819 if ((c0 == charArray[0]) && (c1 == charArray[1])
2820 && (c2 == charArray[2]) && (c3 == charArray[3])
2821 && (c4 == charArray[4]))
2824 // ---------other side---------
2826 int max = newEntry5;
2827 while (++i <= max) {
2828 char[] charArray = table[i];
2829 if ((c0 == charArray[0]) && (c1 == charArray[1])
2830 && (c2 == charArray[2]) && (c3 == charArray[3])
2831 && (c4 == charArray[4]))
2834 // --------add the entry-------
2835 if (++max >= InternalTableSize)
2838 table[max] = (r = new char[] { c0, c1, c2, c3, c4 });
2843 final char[] optimizedCurrentTokenSource6() {
2844 // try to return the same char[] build only once
2845 char c0, c1, c2, c3, c4, c5;
2846 long hash = ((((long) (c0 = source[startPosition])) << 32)
2847 + (((long) (c1 = source[startPosition + 1])) << 24)
2848 + (((long) (c2 = source[startPosition + 2])) << 18)
2849 + ((c3 = source[startPosition + 3]) << 12)
2850 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2852 char[][] table = charArray_length[4][(int) hash];
2854 while (++i < InternalTableSize) {
2855 char[] charArray = table[i];
2856 if ((c0 == charArray[0]) && (c1 == charArray[1])
2857 && (c2 == charArray[2]) && (c3 == charArray[3])
2858 && (c4 == charArray[4]) && (c5 == charArray[5]))
2861 // ---------other side---------
2863 int max = newEntry6;
2864 while (++i <= max) {
2865 char[] charArray = table[i];
2866 if ((c0 == charArray[0]) && (c1 == charArray[1])
2867 && (c2 == charArray[2]) && (c3 == charArray[3])
2868 && (c4 == charArray[4]) && (c5 == charArray[5]))
2871 // --------add the entry-------
2872 if (++max >= InternalTableSize)
2875 table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 });
2880 public final void pushLineSeparator() throws InvalidInputException {
2881 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2882 final int INCREMENT = 250;
2883 if (this.checkNonExternalizedStringLiterals) {
2884 // reinitialize the current line for non externalize strings purpose
2887 // currentCharacter is at position currentPosition-1
2889 if (currentCharacter == '\r') {
2890 int separatorPos = currentPosition - 1;
2891 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2893 // System.out.println("CR-" + separatorPos);
2895 lineEnds[++linePtr] = separatorPos;
2896 } catch (IndexOutOfBoundsException e) {
2897 // linePtr value is correct
2898 int oldLength = lineEnds.length;
2899 int[] old = lineEnds;
2900 lineEnds = new int[oldLength + INCREMENT];
2901 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2902 lineEnds[linePtr] = separatorPos;
2904 // look-ahead for merged cr+lf
2906 if (source[currentPosition] == '\n') {
2907 // System.out.println("look-ahead LF-" + currentPosition);
2908 lineEnds[linePtr] = currentPosition;
2914 } catch (IndexOutOfBoundsException e) {
2919 if (currentCharacter == '\n') {
2920 // must merge eventual cr followed by lf
2921 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2922 // System.out.println("merge LF-" + (currentPosition - 1));
2923 lineEnds[linePtr] = currentPosition - 1;
2925 int separatorPos = currentPosition - 1;
2926 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2928 // System.out.println("LF-" + separatorPos);
2930 lineEnds[++linePtr] = separatorPos;
2931 } catch (IndexOutOfBoundsException e) {
2932 // linePtr value is correct
2933 int oldLength = lineEnds.length;
2934 int[] old = lineEnds;
2935 lineEnds = new int[oldLength + INCREMENT];
2936 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2937 lineEnds[linePtr] = separatorPos;
2945 public final void pushUnicodeLineSeparator() {
2946 // isUnicode means that the \r or \n has been read as a unicode
2948 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2949 final int INCREMENT = 250;
2950 // currentCharacter is at position currentPosition-1
2951 if (this.checkNonExternalizedStringLiterals) {
2952 // reinitialize the current line for non externalize strings purpose
2956 if (currentCharacter == '\r') {
2957 int separatorPos = currentPosition - 6;
2958 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2960 // System.out.println("CR-" + separatorPos);
2962 lineEnds[++linePtr] = separatorPos;
2963 } catch (IndexOutOfBoundsException e) {
2964 // linePtr value is correct
2965 int oldLength = lineEnds.length;
2966 int[] old = lineEnds;
2967 lineEnds = new int[oldLength + INCREMENT];
2968 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2969 lineEnds[linePtr] = separatorPos;
2971 // look-ahead for merged cr+lf
2972 if (source[currentPosition] == '\n') {
2973 // System.out.println("look-ahead LF-" + currentPosition);
2974 lineEnds[linePtr] = currentPosition;
2982 if (currentCharacter == '\n') {
2983 // must merge eventual cr followed by lf
2984 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2985 // System.out.println("merge LF-" + (currentPosition - 1));
2986 lineEnds[linePtr] = currentPosition - 6;
2988 int separatorPos = currentPosition - 6;
2989 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2991 // System.out.println("LF-" + separatorPos);
2993 lineEnds[++linePtr] = separatorPos;
2994 } catch (IndexOutOfBoundsException e) {
2995 // linePtr value is correct
2996 int oldLength = lineEnds.length;
2997 int[] old = lineEnds;
2998 lineEnds = new int[oldLength + INCREMENT];
2999 System.arraycopy(old, 0, lineEnds, 0, oldLength);
3000 lineEnds[linePtr] = separatorPos;
3008 public void recordComment(TokenName token) {
3010 int stopPosition = this.currentPosition;
3013 stopPosition = -this.lastCommentLinePosition;
3016 stopPosition = -this.currentPosition;
3020 // a new comment is recorded
3021 int length = this.commentStops.length;
3022 if (++this.commentPtr >= length) {
3023 System.arraycopy(this.commentStops, 0,
3024 this.commentStops = new int[length + 30], 0, length);
3025 // grows the positions buffers too
3026 System.arraycopy(this.commentStarts, 0,
3027 this.commentStarts = new int[length + 30], 0, length);
3029 this.commentStops[this.commentPtr] = stopPosition;
3030 this.commentStarts[this.commentPtr] = this.startPosition;
3033 // public final void recordComment(boolean isJavadoc) {
3034 // // a new annotation comment is recorded
3036 // commentStops[++commentPtr] = isJavadoc
3037 // ? currentPosition
3038 // : -currentPosition;
3039 // } catch (IndexOutOfBoundsException e) {
3040 // int oldStackLength = commentStops.length;
3041 // int[] oldStack = commentStops;
3042 // commentStops = new int[oldStackLength + 30];
3043 // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
3044 // commentStops[commentPtr] = isJavadoc ? currentPosition :
3045 // -currentPosition;
3046 // //grows the positions buffers too
3047 // int[] old = commentStarts;
3048 // commentStarts = new int[oldStackLength + 30];
3049 // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
3051 // //the buffer is of a correct size here
3052 // commentStarts[commentPtr] = startPosition;
3054 public void resetTo(int begin, int end) {
3055 // reset the scanner to a given position where it may rescan again
3057 initialPosition = startPosition = currentPosition = begin;
3058 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
3059 commentPtr = -1; // reset comment stack
3062 public final void scanSingleQuotedEscapeCharacter()
3063 throws InvalidInputException {
3064 // the string with "\\u" is a legal string of two chars \ and u
3065 // thus we use a direct access to the source (for regular cases).
3066 // if (unicodeAsBackSlash) {
3067 // // consume next character
3068 // unicodeAsBackSlash = false;
3069 // if (((currentCharacter = source[currentPosition++]) == '\\')
3070 // && (source[currentPosition] == 'u')) {
3071 // getNextUnicodeChar();
3073 // if (withoutUnicodePtr != 0) {
3074 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3078 currentCharacter = source[currentPosition++];
3079 switch (currentCharacter) {
3081 currentCharacter = '\'';
3084 currentCharacter = '\\';
3087 currentCharacter = '\\';
3092 public final void scanDoubleQuotedEscapeCharacter()
3093 throws InvalidInputException {
3094 currentCharacter = source[currentPosition++];
3095 switch (currentCharacter) {
3097 // currentCharacter = '\b';
3100 currentCharacter = '\t';
3103 currentCharacter = '\n';
3106 // currentCharacter = '\f';
3109 currentCharacter = '\r';
3112 currentCharacter = '\"';
3115 currentCharacter = '\'';
3118 currentCharacter = '\\';
3121 currentCharacter = '$';
3124 // -----------octal escape--------------
3126 // OctalDigit OctalDigit
3127 // ZeroToThree OctalDigit OctalDigit
3128 int number = Character.getNumericValue(currentCharacter);
3129 if (number >= 0 && number <= 7) {
3130 boolean zeroToThreeNot = number > 3;
3132 .isDigit(currentCharacter = source[currentPosition++])) {
3133 int digit = Character.getNumericValue(currentCharacter);
3134 if (digit >= 0 && digit <= 7) {
3135 number = (number * 8) + digit;
3137 .isDigit(currentCharacter = source[currentPosition++])) {
3138 if (zeroToThreeNot) { // has read \NotZeroToThree
3140 // Digit --> ignore last character
3144 .getNumericValue(currentCharacter);
3145 if (digit >= 0 && digit <= 7) {
3146 // has read \ZeroToThree OctalDigit
3148 number = (number * 8) + digit;
3149 } else { // has read \ZeroToThree OctalDigit
3151 // --> ignore last character
3155 } else { // has read \OctalDigit NonDigit--> ignore
3160 } else { // has read \OctalDigit NonOctalDigit--> ignore
3165 } else { // has read \OctalDigit --> ignore last character
3169 throw new InvalidInputException(INVALID_ESCAPE);
3170 currentCharacter = (char) number;
3173 // throw new InvalidInputException(INVALID_ESCAPE);
3177 // public int scanIdentifierOrKeyword() throws InvalidInputException {
3178 // return scanIdentifierOrKeyword( false );
3180 public TokenName scanIdentifierOrKeyword(boolean isVariable)
3181 throws InvalidInputException {
3183 // first dispatch on the first char.
3184 // then the length. If there are several
3185 // keywords with the same length AND the same first char, then do another
3186 // disptach on the second char :-)...cool....but fast !
3187 useAssertAsAnIndentifier = false;
3188 while (getNextCharAsJavaIdentifierPart()) {
3192 // if (new String(getCurrentTokenSource()).equals("$this")) {
3193 // return TokenName.this;
3195 return TokenName.VARIABLE;
3200 // if (withoutUnicodePtr == 0)
3201 // quick test on length == 1 but not on length > 12 while most
3203 // have a length which is <= 12...but there are lots of identifier with
3204 // only one char....
3206 if ((length = currentPosition - startPosition) == 1)
3207 return TokenName.IDENTIFIER;
3209 data = new char[length];
3210 index = startPosition;
3211 for (int i = 0; i < length; i++) {
3212 data[i] = Character.toLowerCase(source[index + i]);
3216 // if ((length = withoutUnicodePtr) == 1)
3217 // return TokenName.Identifier;
3218 // // data = withoutUnicodeBuffer;
3219 // data = new char[withoutUnicodeBuffer.length];
3220 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
3221 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
3225 firstLetter = data[index];
3226 switch (firstLetter) {
3231 if ((data[++index] == '_') && (data[++index] == 'f')
3232 && (data[++index] == 'i') && (data[++index] == 'l')
3233 && (data[++index] == 'e') && (data[++index] == '_')
3234 && (data[++index] == '_'))
3235 return TokenName.FILE;
3236 index = 0; // __LINE__
3237 if ((data[++index] == '_') && (data[++index] == 'l')
3238 && (data[++index] == 'i') && (data[++index] == 'n')
3239 && (data[++index] == 'e') && (data[++index] == '_')
3240 && (data[++index] == '_'))
3241 return TokenName.LINE;
3245 if ((data[++index] == '_') && (data[++index] == 'c')
3246 && (data[++index] == 'l') && (data[++index] == 'a')
3247 && (data[++index] == 's') && (data[++index] == 's')
3248 && (data[++index] == '_') && (data[++index] == '_'))
3249 return TokenName.CLASS_C;
3253 if ((data[++index] == '_') && (data[++index] == 'm')
3254 && (data[++index] == 'e') && (data[++index] == 't')
3255 && (data[++index] == 'h') && (data[++index] == 'o')
3256 && (data[++index] == 'd') && (data[++index] == '_')
3257 && (data[++index] == '_'))
3258 return TokenName.METHOD_C;
3262 if ((data[++index] == '_') && (data[++index] == 'f')
3263 && (data[++index] == 'u') && (data[++index] == 'n')
3264 && (data[++index] == 'c') && (data[++index] == 't')
3265 && (data[++index] == 'i') && (data[++index] == 'o')
3266 && (data[++index] == 'n') && (data[++index] == '_')
3267 && (data[++index] == '_'))
3268 return TokenName.FUNC_C;
3271 return TokenName.IDENTIFIER;
3273 // as and array abstract
3277 if ((data[++index] == 's')) {
3278 return TokenName.AS;
3280 return TokenName.IDENTIFIER;
3283 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3284 return TokenName.OP_AND_OLD;
3286 return TokenName.IDENTIFIER;
3289 if ((data[++index] == 'r') && (data[++index] == 'r')
3290 && (data[++index] == 'a') && (data[++index] == 'y'))
3291 return TokenName.ARRAY;
3292 return TokenName.IDENTIFIER;
3294 if ((data[++index] == 'b') && (data[++index] == 's')
3295 && (data[++index] == 't') && (data[++index] == 'r')
3296 && (data[++index] == 'a') && (data[++index] == 'c')
3297 && (data[++index] == 't'))
3298 return TokenName.ABSTRACT;
3299 return TokenName.IDENTIFIER;
3301 return TokenName.IDENTIFIER;
3306 if ((data[++index] == 'r') && (data[++index] == 'e')
3307 && (data[++index] == 'a') && (data[++index] == 'k'))
3308 return TokenName.BREAK;
3309 return TokenName.IDENTIFIER;
3311 return TokenName.IDENTIFIER;
3313 // case catch class clone const continue
3316 if ((data[++index] == 'a') && (data[++index] == 's')
3317 && (data[++index] == 'e'))
3318 return TokenName.CASE;
3319 return TokenName.IDENTIFIER;
3321 if ((data[++index] == 'a') && (data[++index] == 't')
3322 && (data[++index] == 'c') && (data[++index] == 'h'))
3323 return TokenName.CATCH;
3325 if ((data[++index] == 'l') && (data[++index] == 'a')
3326 && (data[++index] == 's') && (data[++index] == 's'))
3327 return TokenName.CLASS;
3329 if ((data[++index] == 'l') && (data[++index] == 'o')
3330 && (data[++index] == 'n') && (data[++index] == 'e'))
3331 return TokenName.CLONE;
3333 if ((data[++index] == 'o') && (data[++index] == 'n')
3334 && (data[++index] == 's') && (data[++index] == 't'))
3335 return TokenName.CONST;
3336 return TokenName.IDENTIFIER;
3338 if ((data[++index] == 'o') && (data[++index] == 'n')
3339 && (data[++index] == 't') && (data[++index] == 'i')
3340 && (data[++index] == 'n') && (data[++index] == 'u')
3341 && (data[++index] == 'e'))
3342 return TokenName.CONTINUE;
3343 return TokenName.IDENTIFIER;
3345 return TokenName.IDENTIFIER;
3347 // declare default do die
3348 // TODO delete define ==> no keyword !
3351 if ((data[++index] == 'o'))
3352 return TokenName.DO;
3353 return TokenName.IDENTIFIER;
3355 // if ((data[++index] == 'e')
3356 // && (data[++index] == 'f')
3357 // && (data[++index] == 'i')
3358 // && (data[++index] == 'n')
3359 // && (data[++index] == 'e'))
3360 // return TokenName.define;
3362 // return TokenName.Identifier;
3364 if ((data[++index] == 'e') && (data[++index] == 'c')
3365 && (data[++index] == 'l') && (data[++index] == 'a')
3366 && (data[++index] == 'r') && (data[++index] == 'e'))
3367 return TokenName.DECLARE;
3369 if ((data[++index] == 'e') && (data[++index] == 'f')
3370 && (data[++index] == 'a') && (data[++index] == 'u')
3371 && (data[++index] == 'l') && (data[++index] == 't'))
3372 return TokenName.DEFAULT;
3373 return TokenName.IDENTIFIER;
3375 return TokenName.IDENTIFIER;
3377 // echo else exit elseif extends eval
3380 if ((data[++index] == 'c') && (data[++index] == 'h')
3381 && (data[++index] == 'o'))
3382 return TokenName.ECHO;
3383 else if ((data[index] == 'l') && (data[++index] == 's')
3384 && (data[++index] == 'e'))
3385 return TokenName.ELSE;
3386 else if ((data[index] == 'x') && (data[++index] == 'i')
3387 && (data[++index] == 't'))
3388 return TokenName.EXIT;
3389 else if ((data[index] == 'v') && (data[++index] == 'a')
3390 && (data[++index] == 'l'))
3391 return TokenName.EVAL;
3392 return TokenName.IDENTIFIER;
3395 if ((data[++index] == 'n') && (data[++index] == 'd')
3396 && (data[++index] == 'i') && (data[++index] == 'f'))
3397 return TokenName.ENDIF;
3398 if ((data[index] == 'm') && (data[++index] == 'p')
3399 && (data[++index] == 't') && (data[++index] == 'y'))
3400 return TokenName.EMPTY;
3401 return TokenName.IDENTIFIER;
3404 if ((data[++index] == 'n') && (data[++index] == 'd')
3405 && (data[++index] == 'f') && (data[++index] == 'o')
3406 && (data[++index] == 'r'))
3407 return TokenName.ENDFOR;
3408 else if ((data[index] == 'l') && (data[++index] == 's')
3409 && (data[++index] == 'e') && (data[++index] == 'i')
3410 && (data[++index] == 'f'))
3411 return TokenName.ELSEIF;
3412 return TokenName.IDENTIFIER;
3414 if ((data[++index] == 'x') && (data[++index] == 't')
3415 && (data[++index] == 'e') && (data[++index] == 'n')
3416 && (data[++index] == 'd') && (data[++index] == 's'))
3417 return TokenName.EXTENDS;
3418 return TokenName.IDENTIFIER;
3421 if ((data[++index] == 'n') && (data[++index] == 'd')
3422 && (data[++index] == 'w') && (data[++index] == 'h')
3423 && (data[++index] == 'i') && (data[++index] == 'l')
3424 && (data[++index] == 'e'))
3425 return TokenName.ENDWHILE;
3426 return TokenName.IDENTIFIER;
3429 if ((data[++index] == 'n') && (data[++index] == 'd')
3430 && (data[++index] == 's') && (data[++index] == 'w')
3431 && (data[++index] == 'i') && (data[++index] == 't')
3432 && (data[++index] == 'c') && (data[++index] == 'h'))
3433 return TokenName.ENDSWITCH;
3434 return TokenName.IDENTIFIER;
3437 if ((data[++index] == 'n') && (data[++index] == 'd')
3438 && (data[++index] == 'd') && (data[++index] == 'e')
3439 && (data[++index] == 'c') && (data[++index] == 'l')
3440 && (data[++index] == 'a') && (data[++index] == 'r')
3441 && (data[++index] == 'e'))
3442 return TokenName.ENDDECLARE;
3444 if ((data[++index] == 'n') // endforeach
3445 && (data[++index] == 'd')
3446 && (data[++index] == 'f')
3447 && (data[++index] == 'o')
3448 && (data[++index] == 'r')
3449 && (data[++index] == 'e')
3450 && (data[++index] == 'a')
3451 && (data[++index] == 'c') && (data[++index] == 'h'))
3452 return TokenName.ENDFOREACH;
3453 return TokenName.IDENTIFIER;
3455 return TokenName.IDENTIFIER;
3457 // for false final function
3460 if ((data[++index] == 'o') && (data[++index] == 'r'))
3461 return TokenName.FOR;
3462 return TokenName.IDENTIFIER;
3464 // if ((data[++index] == 'a') && (data[++index] == 'l')
3465 // && (data[++index] == 's') && (data[++index] == 'e'))
3466 // return TokenName.false;
3467 if ((data[++index] == 'i') && (data[++index] == 'n')
3468 && (data[++index] == 'a') && (data[++index] == 'l'))
3469 return TokenName.FINAL;
3470 return TokenName.IDENTIFIER;
3473 if ((data[++index] == 'o') && (data[++index] == 'r')
3474 && (data[++index] == 'e') && (data[++index] == 'a')
3475 && (data[++index] == 'c') && (data[++index] == 'h'))
3476 return TokenName.FOREACH;
3477 return TokenName.IDENTIFIER;
3480 if ((data[++index] == 'u') && (data[++index] == 'n')
3481 && (data[++index] == 'c') && (data[++index] == 't')
3482 && (data[++index] == 'i') && (data[++index] == 'o')
3483 && (data[++index] == 'n'))
3484 return TokenName.FUNCTION;
3485 return TokenName.IDENTIFIER;
3487 return TokenName.IDENTIFIER;
3491 if ((data[++index] == 'l') && (data[++index] == 'o')
3492 && (data[++index] == 'b') && (data[++index] == 'a')
3493 && (data[++index] == 'l')) {
3494 return TokenName.GLOBAL;
3497 else if (length == 4) { // goto
3498 if ((data[++index] == 'o') &&
3499 (data[++index] == 't') &&
3500 (data[++index] == 'o')) {
3501 return TokenName.GOTO;
3504 return TokenName.IDENTIFIER;
3506 // if int isset include include_once instanceof interface implements
3509 if (data[++index] == 'f')
3510 return TokenName.IF;
3511 return TokenName.IDENTIFIER;
3513 // if ((data[++index] == 'n') && (data[++index] == 't'))
3514 // return TokenName.int;
3516 // return TokenName.IDENTIFIER;
3518 if ((data[++index] == 's') && (data[++index] == 's')
3519 && (data[++index] == 'e') && (data[++index] == 't'))
3520 return TokenName.ISSET;
3521 return TokenName.IDENTIFIER;
3523 if ((data[++index] == 'n') && (data[++index] == 'c')
3524 && (data[++index] == 'l') && (data[++index] == 'u')
3525 && (data[++index] == 'd') && (data[++index] == 'e'))
3526 return TokenName.INCLUDE;
3527 return TokenName.IDENTIFIER;
3530 if ((data[++index] == 'n') && (data[++index] == 't')
3531 && (data[++index] == 'e') && (data[++index] == 'r')
3532 && (data[++index] == 'f') && (data[++index] == 'a')
3533 && (data[++index] == 'c') && (data[++index] == 'e'))
3534 return TokenName.INTERFACE;
3535 return TokenName.IDENTIFIER;
3537 // instanceof implements
3538 if ((data[++index] == 'n') && (data[++index] == 's')
3539 && (data[++index] == 't') && (data[++index] == 'a')
3540 && (data[++index] == 'n') && (data[++index] == 'c')
3541 && (data[++index] == 'e') && (data[++index] == 'o')
3542 && (data[++index] == 'f'))
3543 return TokenName.INSTANCEOF;
3544 if ((data[index] == 'm') && (data[++index] == 'p')
3545 && (data[++index] == 'l') && (data[++index] == 'e')
3546 && (data[++index] == 'm') && (data[++index] == 'e')
3547 && (data[++index] == 'n') && (data[++index] == 't')
3548 && (data[++index] == 's'))
3549 return TokenName.IMPLEMENTS;
3550 return TokenName.IDENTIFIER;
3551 case 12: // include_once
3552 if ((data[++index] == 'n') && (data[++index] == 'c')
3553 && (data[++index] == 'l') && (data[++index] == 'u')
3554 && (data[++index] == 'd') && (data[++index] == 'e')
3555 && (data[++index] == '_') && (data[++index] == 'o')
3556 && (data[++index] == 'n') && (data[++index] == 'c')
3557 && (data[++index] == 'e'))
3558 return TokenName.INCLUDE_ONCE;
3559 return TokenName.IDENTIFIER;
3561 return TokenName.IDENTIFIER;
3565 if ((data[++index] == 'i') && (data[++index] == 's')
3566 && (data[++index] == 't')) {
3567 return TokenName.LIST;
3570 return TokenName.IDENTIFIER;
3572 // new null namespace
3575 if ((data[++index] == 'e') && (data[++index] == 'w'))
3576 return TokenName.NEW;
3577 return TokenName.IDENTIFIER;
3579 // if ((data[++index] == 'u') && (data[++index] == 'l')
3580 // && (data[++index] == 'l'))
3581 // return TokenName.null;
3583 // return TokenName.IDENTIFIER;
3585 if ((data[++index] == 'a') && (data[++index] == 'm')
3586 && (data[++index] == 'e') && (data[++index] == 's')
3587 && (data[++index] == 'p') && (data[++index] == 'a')
3588 && (data[++index] == 'c') && (data[++index] == 'e')) {
3589 return TokenName.NAMESPACE;
3591 return TokenName.IDENTIFIER;
3593 return TokenName.IDENTIFIER;
3597 if (data[++index] == 'r') {
3598 return TokenName.OP_OR_OLD;
3601 // if (length == 12) {
3602 // if ((data[++index] == 'l')
3603 // && (data[++index] == 'd')
3604 // && (data[++index] == '_')
3605 // && (data[++index] == 'f')
3606 // && (data[++index] == 'u')
3607 // && (data[++index] == 'n')
3608 // && (data[++index] == 'c')
3609 // && (data[++index] == 't')
3610 // && (data[++index] == 'i')
3611 // && (data[++index] == 'o')
3612 // && (data[++index] == 'n')) {
3613 // return TokenName.old_function;
3616 return TokenName.IDENTIFIER;
3618 // print public private protected
3621 if ((data[++index] == 'r') && (data[++index] == 'i')
3622 && (data[++index] == 'n') && (data[++index] == 't')) {
3623 return TokenName.PRINT;
3625 return TokenName.IDENTIFIER;
3627 if ((data[++index] == 'u') && (data[++index] == 'b')
3628 && (data[++index] == 'l') && (data[++index] == 'i')
3629 && (data[++index] == 'c')) {
3630 return TokenName.PUBLIC;
3632 return TokenName.IDENTIFIER;
3634 if ((data[++index] == 'r') && (data[++index] == 'i')
3635 && (data[++index] == 'v') && (data[++index] == 'a')
3636 && (data[++index] == 't') && (data[++index] == 'e')) {
3637 return TokenName.PRIVATE;
3639 return TokenName.IDENTIFIER;
3641 if ((data[++index] == 'r') && (data[++index] == 'o')
3642 && (data[++index] == 't') && (data[++index] == 'e')
3643 && (data[++index] == 'c') && (data[++index] == 't')
3644 && (data[++index] == 'e') && (data[++index] == 'd')) {
3645 return TokenName.PROTECTED;
3647 return TokenName.IDENTIFIER;
3649 return TokenName.IDENTIFIER;
3651 // return require require_once
3653 if ((data[++index] == 'e') && (data[++index] == 't')
3654 && (data[++index] == 'u') && (data[++index] == 'r')
3655 && (data[++index] == 'n')) {
3656 return TokenName.RETURN;
3658 } else if (length == 7) {
3659 if ((data[++index] == 'e') && (data[++index] == 'q')
3660 && (data[++index] == 'u') && (data[++index] == 'i')
3661 && (data[++index] == 'r') && (data[++index] == 'e')) {
3662 return TokenName.REQUIRE;
3664 } else if (length == 12) {
3665 if ((data[++index] == 'e') && (data[++index] == 'q')
3666 && (data[++index] == 'u') && (data[++index] == 'i')
3667 && (data[++index] == 'r') && (data[++index] == 'e')
3668 && (data[++index] == '_') && (data[++index] == 'o')
3669 && (data[++index] == 'n') && (data[++index] == 'c')
3670 && (data[++index] == 'e')) {
3671 return TokenName.REQUIRE_ONCE;
3674 return TokenName.IDENTIFIER;
3676 // self static switch
3679 // if ((data[++index] == 'e') && (data[++index] == 'l') &&
3682 // return TokenName.self;
3684 // return TokenName.IDENTIFIER;
3686 if (data[++index] == 't')
3687 if ((data[++index] == 'a') && (data[++index] == 't')
3688 && (data[++index] == 'i') && (data[++index] == 'c')) {
3689 return TokenName.STATIC;
3691 return TokenName.IDENTIFIER;
3692 else if ((data[index] == 'w') && (data[++index] == 'i')
3693 && (data[++index] == 't') && (data[++index] == 'c')
3694 && (data[++index] == 'h'))
3695 return TokenName.SWITCH;
3697 return TokenName.IDENTIFIER;
3702 if ((data[++index] == 'r') && (data[++index] == 'y'))
3703 return TokenName.TRY;
3705 // if ((data[++index] == 'r') && (data[++index] == 'u')
3706 // && (data[++index] == 'e'))
3707 // return TokenName.true;
3709 return TokenName.IDENTIFIER;
3711 if ((data[++index] == 'h') && (data[++index] == 'r')
3712 && (data[++index] == 'o') && (data[++index] == 'w'))
3713 return TokenName.THROW;
3715 return TokenName.IDENTIFIER;
3720 if ((data[++index] == 's') && (data[++index] == 'e'))
3721 return TokenName.USE;
3723 return TokenName.IDENTIFIER;
3725 if ((data[++index] == 'n') && (data[++index] == 's')
3726 && (data[++index] == 'e') && (data[++index] == 't'))
3727 return TokenName.UNSET;
3729 return TokenName.IDENTIFIER;
3734 if ((data[++index] == 'a') && (data[++index] == 'r'))
3735 return TokenName.VAR;
3737 return TokenName.IDENTIFIER;
3742 if ((data[++index] == 'h') && (data[++index] == 'i')
3743 && (data[++index] == 'l') && (data[++index] == 'e'))
3744 return TokenName.WHILE;
3745 // case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3746 // (data[++index]=='e') && (data[++index]=='f')&&
3747 // (data[++index]=='p'))
3748 // return TokenName.widefp ;
3750 // return TokenName.IDENTIFIER;
3752 return TokenName.IDENTIFIER;
3757 if ((data[++index] == 'o') && (data[++index] == 'r'))
3758 return TokenName.OP_XOR_OLD;
3760 return TokenName.IDENTIFIER;
3762 return TokenName.IDENTIFIER;
3764 return TokenName.IDENTIFIER;
3767 public TokenName scanNumber(boolean dotPrefix) throws InvalidInputException {
3768 // when entering this method the currentCharacter is the firt
3769 // digit of the number , i.e. it may be preceeded by a . when
3770 // dotPrefix is true
3771 boolean floating = dotPrefix;
3772 if ((!dotPrefix) && (currentCharacter == '0')) {
3773 if (getNextChar('x', 'X') >= 0) { // ----------hexa-----------------
3774 // force the first char of the hexa number do exist...
3775 // consume next character
3776 unicodeAsBackSlash = false;
3777 currentCharacter = source[currentPosition++];
3778 // if (((currentCharacter = source[currentPosition++]) == '\\')
3779 // && (source[currentPosition] == 'u')) {
3780 // getNextUnicodeChar();
3782 // if (withoutUnicodePtr != 0) {
3783 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3786 if (Character.digit(currentCharacter, 16) == -1)
3787 throw new InvalidInputException(INVALID_HEXA);
3789 while (getNextCharAsDigit(16)) {
3792 // if (getNextChar('l', 'L') >= 0)
3793 // return TokenName.LongLiteral;
3795 return TokenName.INTEGERLITERAL;
3797 // there is x or X in the number
3798 // potential octal ! ... some one may write 000099.0 ! thus 00100 <
3799 // 00078.0 is true !!!!! crazy language
3800 if (getNextCharAsDigit()) {
3801 // -------------potential octal-----------------
3802 while (getNextCharAsDigit()) {
3805 // if (getNextChar('l', 'L') >= 0) {
3806 // return TokenName.LongLiteral;
3809 // if (getNextChar('f', 'F') >= 0) {
3810 // return TokenName.FloatingPointLiteral;
3812 if (getNextChar('d', 'D') >= 0) {
3813 return TokenName.DOUBLELITERAL;
3814 } else { // make the distinction between octal and float ....
3815 if (getNextChar('.')) { // bingo ! ....
3816 while (getNextCharAsDigit()) {
3819 if (getNextChar('e', 'E') >= 0) {
3820 // consume next character
3821 unicodeAsBackSlash = false;
3822 currentCharacter = source[currentPosition++];
3823 // if (((currentCharacter =
3824 // source[currentPosition++]) == '\\')
3825 // && (source[currentPosition] == 'u')) {
3826 // getNextUnicodeChar();
3828 // if (withoutUnicodePtr != 0) {
3829 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3830 // currentCharacter;
3833 if ((currentCharacter == '-')
3834 || (currentCharacter == '+')) {
3835 // consume next character
3836 unicodeAsBackSlash = false;
3837 currentCharacter = source[currentPosition++];
3838 // if (((currentCharacter =
3839 // source[currentPosition++]) == '\\')
3840 // && (source[currentPosition] == 'u')) {
3841 // getNextUnicodeChar();
3843 // if (withoutUnicodePtr != 0) {
3844 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3845 // currentCharacter;
3849 if (!Character.isDigit(currentCharacter))
3850 throw new InvalidInputException(INVALID_FLOAT);
3851 while (getNextCharAsDigit()) {
3855 // if (getNextChar('f', 'F') >= 0)
3856 // return TokenName.FloatingPointLiteral;
3857 getNextChar('d', 'D'); // jump over potential d or D
3858 return TokenName.DOUBLELITERAL;
3860 return TokenName.INTEGERLITERAL;
3867 while (getNextCharAsDigit()) {
3870 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3871 // return TokenName.LongLiteral;
3872 if ((!dotPrefix) && (getNextChar('.'))) { // decimal part that can be
3874 while (getNextCharAsDigit()) {
3879 // if floating is true both exponant and suffix may be optional
3880 if (getNextChar('e', 'E') >= 0) {
3882 // consume next character
3883 unicodeAsBackSlash = false;
3884 currentCharacter = source[currentPosition++];
3885 // if (((currentCharacter = source[currentPosition++]) == '\\')
3886 // && (source[currentPosition] == 'u')) {
3887 // getNextUnicodeChar();
3889 // if (withoutUnicodePtr != 0) {
3890 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3893 if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
3896 unicodeAsBackSlash = false;
3897 currentCharacter = source[currentPosition++];
3898 // if (((currentCharacter = source[currentPosition++]) == '\\')
3899 // && (source[currentPosition] == 'u')) {
3900 // getNextUnicodeChar();
3902 // if (withoutUnicodePtr != 0) {
3903 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3907 if (!Character.isDigit(currentCharacter))
3908 throw new InvalidInputException(INVALID_FLOAT);
3909 while (getNextCharAsDigit()) {
3913 if (getNextChar('d', 'D') >= 0)
3914 return TokenName.DOUBLELITERAL;
3915 // if (getNextChar('f', 'F') >= 0)
3916 // return TokenName.FloatingPointLiteral;
3917 // the long flag has been tested before
3918 return floating ? TokenName.DOUBLELITERAL : TokenName.INTEGERLITERAL;
3922 * Search the line number corresponding to a specific position
3925 public final int getLineNumber(int position) {
3926 if (lineEnds == null)
3928 int length = linePtr + 1;
3931 int g = 0, d = length - 1;
3935 if (position < lineEnds[m]) {
3937 } else if (position > lineEnds[m]) {
3943 if (position < lineEnds[m]) {
3949 public void setPHPMode(boolean mode) {
3953 public final void setSource(char[] source) {
3954 setSource(null, source);
3957 public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3958 // the source-buffer is set to sourceString
3959 this.compilationUnit = compilationUnit;
3960 if (source == null) {
3961 this.source = new char[0];
3963 this.source = source;
3966 initialPosition = currentPosition = 0;
3967 containsAssertKeyword = false;
3968 withoutUnicodeBuffer = new char[this.source.length];
3969 fFillerToken = TokenName.EOF;
3970 // encapsedStringStack = new Stack();
3973 public String toString() {
3974 if (startPosition == source.length)
3975 return "EOF\n\n" + new String(source); //$NON-NLS-1$
3976 if (currentPosition > source.length)
3977 return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3978 char front[] = new char[startPosition];
3979 System.arraycopy(source, 0, front, 0, startPosition);
3980 int middleLength = (currentPosition - 1) - startPosition + 1;
3982 if (middleLength > -1) {
3983 middle = new char[middleLength];
3984 System.arraycopy(source, startPosition, middle, 0, middleLength);
3986 middle = new char[0];
3988 char end[] = new char[source.length - (currentPosition - 1)];
3989 System.arraycopy(source, (currentPosition - 1) + 1, end, 0,
3990 source.length - (currentPosition - 1) - 1);
3991 return new String(front)
3992 + "\n===============================\nStarts here -->" //$NON-NLS-1$
3993 + new String(middle)
3994 + "<-- Ends here\n===============================\n" //$NON-NLS-1$
3998 public final String toStringAction(TokenName act) {
4001 return "ScannerError"; // + new String(getCurrentTokenSource()) +
4005 return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4006 case ECHO_INVISIBLE:
4010 return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4012 return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4014 return "abstract"; //$NON-NLS-1$
4016 return "AND"; //$NON-NLS-1$
4018 return "array"; //$NON-NLS-1$
4020 return "as"; //$NON-NLS-1$
4022 return "break"; //$NON-NLS-1$
4024 return "case"; //$NON-NLS-1$
4026 return "class"; //$NON-NLS-1$
4028 return "catch"; //$NON-NLS-1$
4036 return "continue"; //$NON-NLS-1$
4038 return "default"; //$NON-NLS-1$
4040 // return "define"; //$NON-NLS-1$
4042 return "do"; //$NON-NLS-1$
4044 return "echo"; //$NON-NLS-1$
4046 return "else"; //$NON-NLS-1$
4048 return "elseif"; //$NON-NLS-1$
4050 return "endfor"; //$NON-NLS-1$
4052 return "endforeach"; //$NON-NLS-1$
4054 return "endif"; //$NON-NLS-1$
4056 return "endswitch"; //$NON-NLS-1$
4058 return "endwhile"; //$NON-NLS-1$
4062 return "extends"; //$NON-NLS-1$
4064 // return "false"; //$NON-NLS-1$
4066 return "final"; //$NON-NLS-1$
4068 return "for"; //$NON-NLS-1$
4070 return "foreach"; //$NON-NLS-1$
4072 return "function"; //$NON-NLS-1$
4074 return "global"; //$NON-NLS-1$
4076 return "if"; //$NON-NLS-1$
4078 return "implements"; //$NON-NLS-1$
4080 return "include"; //$NON-NLS-1$
4082 return "include_once"; //$NON-NLS-1$
4084 return "instanceof"; //$NON-NLS-1$
4086 return "interface"; //$NON-NLS-1$
4088 return "isset"; //$NON-NLS-1$
4090 return "list"; //$NON-NLS-1$
4092 return "new"; //$NON-NLS-1$
4094 // return "null"; //$NON-NLS-1$
4096 return "OR"; //$NON-NLS-1$
4098 return "print"; //$NON-NLS-1$
4100 return "private"; //$NON-NLS-1$
4102 return "protected"; //$NON-NLS-1$
4104 return "public"; //$NON-NLS-1$
4106 return "require"; //$NON-NLS-1$
4108 return "require_once"; //$NON-NLS-1$
4110 return "return"; //$NON-NLS-1$
4112 // return "self"; //$NON-NLS-1$
4114 return "static"; //$NON-NLS-1$
4116 return "switch"; //$NON-NLS-1$
4118 // return "true"; //$NON-NLS-1$
4120 return "unset"; //$NON-NLS-1$
4122 return "var"; //$NON-NLS-1$
4124 return "while"; //$NON-NLS-1$
4126 return "XOR"; //$NON-NLS-1$
4128 // return "$this"; //$NON-NLS-1$
4129 case INTEGERLITERAL:
4130 return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4132 return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4133 case STRINGDOUBLEQUOTE:
4134 return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4135 case STRINGSINGLEQUOTE:
4136 return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4137 case STRINGINTERPOLATED:
4138 return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4139 case ENCAPSEDSTRING0:
4140 return "`"; //$NON-NLS-1$
4141 // case EncapsedString1:
4142 // return "\'"; //$NON-NLS-1$
4143 // case EncapsedString2:
4144 // return "\""; //$NON-NLS-1$
4146 return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4148 return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4150 return "++"; //$NON-NLS-1$
4152 return "--"; //$NON-NLS-1$
4154 return "=="; //$NON-NLS-1$
4155 case EQUAL_EQUAL_EQUAL:
4156 return "==="; //$NON-NLS-1$
4158 return "=>"; //$NON-NLS-1$
4160 return "<="; //$NON-NLS-1$
4162 return ">="; //$NON-NLS-1$
4164 return "!="; //$NON-NLS-1$
4165 case NOT_EQUAL_EQUAL:
4166 return "!=="; //$NON-NLS-1$
4168 return "<<"; //$NON-NLS-1$
4170 return ">>"; //$NON-NLS-1$
4172 return "+="; //$NON-NLS-1$
4174 return "-="; //$NON-NLS-1$
4175 case MULTIPLY_EQUAL:
4176 return "*="; //$NON-NLS-1$
4178 return "/="; //$NON-NLS-1$
4180 return "&="; //$NON-NLS-1$
4182 return "|="; //$NON-NLS-1$
4184 return "^="; //$NON-NLS-1$
4185 case REMAINDER_EQUAL:
4186 return "%="; //$NON-NLS-1$
4188 return ".="; //$NON-NLS-1$
4189 case LEFT_SHIFT_EQUAL:
4190 return "<<="; //$NON-NLS-1$
4191 case RIGHT_SHIFT_EQUAL:
4192 return ">>="; //$NON-NLS-1$
4194 return "||"; //$NON-NLS-1$
4196 return "&&"; //$NON-NLS-1$
4198 return "+"; //$NON-NLS-1$
4200 return "-"; //$NON-NLS-1$
4204 return "!"; //$NON-NLS-1$
4206 return "%"; //$NON-NLS-1$
4208 return "^"; //$NON-NLS-1$
4210 return "&"; //$NON-NLS-1$
4212 return "*"; //$NON-NLS-1$
4214 return "|"; //$NON-NLS-1$
4216 return "~"; //$NON-NLS-1$
4218 return "~="; //$NON-NLS-1$
4220 return "/"; //$NON-NLS-1$
4222 return ">"; //$NON-NLS-1$
4224 return "<"; //$NON-NLS-1$
4226 return "("; //$NON-NLS-1$
4228 return ")"; //$NON-NLS-1$
4230 return "{"; //$NON-NLS-1$
4232 return "}"; //$NON-NLS-1$
4234 return "["; //$NON-NLS-1$
4236 return "]"; //$NON-NLS-1$
4238 return ";"; //$NON-NLS-1$
4240 return "?"; //$NON-NLS-1$
4242 return ":"; //$NON-NLS-1$
4244 return ","; //$NON-NLS-1$
4246 return "."; //$NON-NLS-1$
4248 return "="; //$NON-NLS-1$
4258 return "EOF"; //$NON-NLS-1$
4260 return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4262 return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4264 return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4265 case COMMENT_PHPDOC:
4266 return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4268 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
4271 return "__FILE__"; //$NON-NLS-1$
4273 return "__LINE__"; //$NON-NLS-1$
4275 return "__CLASS__"; //$NON-NLS-1$
4277 return "__METHOD__"; //$NON-NLS-1$
4279 return "__FUNCTION__"; //$NON-NLS-1
4281 return "( bool )"; //$NON-NLS-1$
4283 return "( int )"; //$NON-NLS-1$
4285 return "( double )"; //$NON-NLS-1$
4287 return "( object )"; //$NON-NLS-1$
4289 return "( string )"; //$NON-NLS-1$
4291 return "( namespace )"; //$NON-NLS-1$
4293 return "token not handled (" + (act.toString ()) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
4301 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
4302 this(tokenizeComments, tokenizeWhiteSpace, false);
4305 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
4306 boolean checkNonExternalizedStringLiterals) {
4307 this(tokenizeComments, tokenizeWhiteSpace,
4308 checkNonExternalizedStringLiterals, false);
4311 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
4312 boolean checkNonExternalizedStringLiterals, boolean assertMode) {
4313 this(tokenizeComments, tokenizeWhiteSpace,
4314 checkNonExternalizedStringLiterals, assertMode, false, null,
4318 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
4319 boolean checkNonExternalizedStringLiterals, boolean assertMode,
4320 boolean tokenizeStrings, char[][] taskTags,
4321 char[][] taskPriorities, boolean isTaskCaseSensitive) {
4322 this.eofPosition = Integer.MAX_VALUE;
4323 this.tokenizeComments = tokenizeComments;
4324 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4325 this.tokenizeStrings = tokenizeStrings;
4326 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4327 // this.assertMode = assertMode;
4328 // this.encapsedStringStack = null;
4329 this.taskTags = taskTags;
4330 this.taskPriorities = taskPriorities;
4333 private void checkNonExternalizeString() throws InvalidInputException {
4334 if (currentLine == null)
4336 parseTags(currentLine);
4339 private void parseTags(NLSLine line) throws InvalidInputException {
4340 String s = new String(getCurrentTokenSource());
4341 int pos = s.indexOf(TAG_PREFIX);
4342 int lineLength = line.size();
4344 int start = pos + TAG_PREFIX_LENGTH;
4345 int end = s.indexOf(TAG_POSTFIX, start);
4346 String index = s.substring(start, end);
4349 i = Integer.parseInt(index) - 1;
4350 // Tags are one based not zero based.
4351 } catch (NumberFormatException e) {
4352 i = -1; // we don't want to consider this as a valid NLS tag
4354 if (line.exists(i)) {
4357 pos = s.indexOf(TAG_PREFIX, start);
4359 this.nonNLSStrings = new StringLiteral[lineLength];
4360 int nonNLSCounter = 0;
4361 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4362 StringLiteral literal = (StringLiteral) iterator.next();
4363 if (literal != null) {
4364 this.nonNLSStrings[nonNLSCounter++] = literal;
4367 if (nonNLSCounter == 0) {
4368 this.nonNLSStrings = null;
4372 this.wasNonExternalizedStringLiteral = true;
4373 if (nonNLSCounter != lineLength) {
4374 System.arraycopy(this.nonNLSStrings, 0,
4375 (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0,
4381 public final void scanEscapeCharacter() throws InvalidInputException {
4382 // the string with "\\u" is a legal string of two chars \ and u
4383 // thus we use a direct access to the source (for regular cases).
4384 if (unicodeAsBackSlash) {
4385 // consume next character
4386 unicodeAsBackSlash = false;
4387 // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4388 // (source[currentPosition] == 'u')) {
4389 // getNextUnicodeChar();
4391 if (withoutUnicodePtr != 0) {
4392 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4396 currentCharacter = source[currentPosition++];
4397 switch (currentCharacter) {
4399 currentCharacter = '\b';
4402 currentCharacter = '\t';
4405 currentCharacter = '\n';
4408 currentCharacter = '\f';
4411 currentCharacter = '\r';
4414 currentCharacter = '\"';
4417 currentCharacter = '\'';
4420 currentCharacter = '\\';
4423 // -----------octal escape--------------
4425 // OctalDigit OctalDigit
4426 // ZeroToThree OctalDigit OctalDigit
4427 int number = Character.getNumericValue(currentCharacter);
4428 if (number >= 0 && number <= 7) {
4429 boolean zeroToThreeNot = number > 3;
4431 .isDigit(currentCharacter = source[currentPosition++])) {
4432 int digit = Character.getNumericValue(currentCharacter);
4433 if (digit >= 0 && digit <= 7) {
4434 number = (number * 8) + digit;
4436 .isDigit(currentCharacter = source[currentPosition++])) {
4437 if (zeroToThreeNot) { // has read \NotZeroToThree
4439 // Digit --> ignore last character
4443 .getNumericValue(currentCharacter);
4444 if (digit >= 0 && digit <= 7) { // has read
4446 // OctalDigit OctalDigit
4447 number = (number * 8) + digit;
4448 } else { // has read \ZeroToThree OctalDigit
4450 // --> ignore last character
4454 } else { // has read \OctalDigit NonDigit--> ignore
4459 } else { // has read \OctalDigit NonOctalDigit--> ignore
4464 } else { // has read \OctalDigit --> ignore last character
4468 throw new InvalidInputException(INVALID_ESCAPE);
4469 currentCharacter = (char) number;
4471 throw new InvalidInputException(INVALID_ESCAPE);
4475 // chech presence of task: tags
4476 // TODO (frederic) see if we need to take unicode characters into account...
4477 public void checkTaskTag(int commentStart, int commentEnd) {
4478 char[] src = this.source;
4480 // only look for newer task: tags
4481 if (this.foundTaskCount > 0
4482 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4485 int foundTaskIndex = this.foundTaskCount;
4486 char previous = src[commentStart + 1]; // should be '*' or '/'
4487 nextChar: for (int i = commentStart + 2; i < commentEnd
4488 && i < this.eofPosition; i++) {
4490 char[] priority = null;
4491 // check for tag occurrence only if not ambiguous with javadoc tag
4492 if (previous != '@') {
4493 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4494 tag = this.taskTags[itag];
4495 int tagLength = tag.length;
4499 // ensure tag is not leaded with letter if tag starts with a
4501 if (Scanner.isPHPIdentifierStart(tag[0])) {
4502 if (Scanner.isPHPIdentifierPart(previous)) {
4507 for (int t = 0; t < tagLength; t++) {
4510 if (x >= this.eofPosition || x >= commentEnd)
4512 if ((sc = src[i + t]) != (tc = tag[t])) { // case
4515 if (this.isTaskCaseSensitive
4516 || (Character.toLowerCase(sc) != Character
4517 .toLowerCase(tc))) { // case
4524 // ensure tag is not followed with letter if tag finishes
4527 if (i + tagLength < commentEnd
4528 && Scanner.isPHPIdentifierPart(src[i + tagLength
4530 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4533 if (this.foundTaskTags == null) {
4534 this.foundTaskTags = new char[5][];
4535 this.foundTaskMessages = new char[5][];
4536 this.foundTaskPriorities = new char[5][];
4537 this.foundTaskPositions = new int[5][];
4538 } else if (this.foundTaskCount == this.foundTaskTags.length) {
4543 this.foundTaskTags = new char[this.foundTaskCount * 2][],
4544 0, this.foundTaskCount);
4547 this.foundTaskMessages,
4549 this.foundTaskMessages = new char[this.foundTaskCount * 2][],
4550 0, this.foundTaskCount);
4553 this.foundTaskPriorities,
4555 this.foundTaskPriorities = new char[this.foundTaskCount * 2][],
4556 0, this.foundTaskCount);
4559 this.foundTaskPositions,
4561 this.foundTaskPositions = new int[this.foundTaskCount * 2][],
4562 0, this.foundTaskCount);
4565 priority = this.taskPriorities != null
4566 && itag < this.taskPriorities.length ? this.taskPriorities[itag]
4569 this.foundTaskTags[this.foundTaskCount] = tag;
4570 this.foundTaskPriorities[this.foundTaskCount] = priority;
4571 this.foundTaskPositions[this.foundTaskCount] = new int[] {
4572 i, i + tagLength - 1 };
4573 this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4574 this.foundTaskCount++;
4575 i += tagLength - 1; // will be incremented when looping
4581 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4582 // retrieve message start and end positions
4583 int msgStart = this.foundTaskPositions[i][0]
4584 + this.foundTaskTags[i].length;
4585 int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1
4587 // at most beginning of next task
4588 if (max_value < msgStart) {
4589 max_value = msgStart; // would only occur if tag is before
4594 for (int j = msgStart; j < max_value; j++) {
4595 if ((c = src[j]) == '\n' || c == '\r') {
4601 for (int j = max_value; j > msgStart; j--) {
4602 if ((c = src[j]) == '*') {
4610 if (msgStart == end)
4613 while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4615 while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4617 // update the end position of the task
4618 this.foundTaskPositions[i][1] = end;
4619 // get the message source
4620 final int messageLength = end - msgStart + 1;
4621 char[] message = new char[messageLength];
4622 System.arraycopy(src, msgStart, message, 0, messageLength);
4623 this.foundTaskMessages[i] = message;
4627 // chech presence of task: tags
4628 // public void checkTaskTag(int commentStart, int commentEnd) {
4629 // // only look for newer task: tags
4630 // if (this.foundTaskCount > 0 &&
4631 // this.foundTaskPositions[this.foundTaskCount
4632 // - 1][0] >= commentStart) {
4635 // int foundTaskIndex = this.foundTaskCount;
4636 // nextChar: for (int i = commentStart; i < commentEnd && i <
4637 // this.eofPosition; i++) {
4638 // char[] tag = null;
4639 // char[] priority = null;
4640 // // check for tag occurrence
4641 // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4642 // tag = this.taskTags[itag];
4643 // priority = this.taskPriorities != null && itag <
4644 // this.taskPriorities.length
4645 // ? this.taskPriorities[itag] : null;
4646 // int tagLength = tag.length;
4647 // for (int t = 0; t < tagLength; t++) {
4648 // if (this.source[i + t] != tag[t])
4649 // continue nextTag;
4651 // if (this.foundTaskTags == null) {
4652 // this.foundTaskTags = new char[5][];
4653 // this.foundTaskMessages = new char[5][];
4654 // this.foundTaskPriorities = new char[5][];
4655 // this.foundTaskPositions = new int[5][];
4656 // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4657 // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new
4658 // char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4659 // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new
4660 // char[this.foundTaskCount * 2][], 0,
4661 // this.foundTaskCount);
4662 // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities =
4663 // new char[this.foundTaskCount * 2][], 0,
4664 // this.foundTaskCount);
4665 // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions =
4667 // int[this.foundTaskCount * 2][], 0,
4668 // this.foundTaskCount);
4670 // this.foundTaskTags[this.foundTaskCount] = tag;
4671 // this.foundTaskPriorities[this.foundTaskCount] = priority;
4672 // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i +
4675 // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4676 // this.foundTaskCount++;
4677 // i += tagLength - 1; // will be incremented when looping
4680 // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4681 // // retrieve message start and end positions
4682 // int msgStart = this.foundTaskPositions[i][0] +
4683 // this.foundTaskTags[i].length;
4684 // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i +
4685 // 1][0] - 1 : commentEnd - 1;
4686 // // at most beginning of next task
4687 // if (max_value < msgStart)
4688 // max_value = msgStart; // would only occur if tag is before EOF.
4691 // for (int j = msgStart; j < max_value; j++) {
4692 // if ((c = this.source[j]) == '\n' || c == '\r') {
4698 // for (int j = max_value; j > msgStart; j--) {
4699 // if ((c = this.source[j]) == '*') {
4707 // if (msgStart == end)
4708 // continue; // empty
4709 // // trim the message
4710 // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4712 // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4714 // // update the end position of the task
4715 // this.foundTaskPositions[i][1] = end;
4716 // // get the message source
4717 // final int messageLength = end - msgStart + 1;
4718 // char[] message = new char[messageLength];
4719 // System.arraycopy(source, msgStart, message, 0, messageLength);
4720 // this.foundTaskMessages[i] = message;