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;
1114 public void consumeStringInterpolated() throws InvalidInputException {
1116 // consume next character
1117 unicodeAsBackSlash = false;
1118 currentCharacter = source[currentPosition++];
1119 // if (((currentCharacter = source[currentPosition++]) == '\\')
1120 // && (source[currentPosition] == 'u')) {
1121 // getNextUnicodeChar();
1123 // if (withoutUnicodePtr != 0) {
1124 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1125 // currentCharacter;
1128 while (currentCharacter != '`') {
1129 /** ** in PHP \r and \n are valid in string literals *** */
1130 // if ((currentCharacter == '\n')
1131 // || (currentCharacter == '\r')) {
1132 // // relocate if finding another quote fairly close: thus
1134 // '/u000D' will be fully consumed
1135 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1136 // if (currentPosition + lookAhead == source.length)
1138 // if (source[currentPosition + lookAhead] == '\n')
1140 // if (source[currentPosition + lookAhead] == '\"') {
1141 // currentPosition += lookAhead + 1;
1145 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1147 if (currentCharacter == '\\') {
1148 int escapeSize = currentPosition;
1149 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1150 // scanEscapeCharacter make a side effect on this value and
1152 // the previous value few lines down this one
1153 scanDoubleQuotedEscapeCharacter();
1154 escapeSize = currentPosition - escapeSize;
1155 if (withoutUnicodePtr == 0) {
1156 // buffer all the entries that have been left aside....
1157 withoutUnicodePtr = currentPosition - escapeSize - 1
1159 System.arraycopy(source, startPosition,
1160 withoutUnicodeBuffer, 1, withoutUnicodePtr);
1161 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1162 } else { // overwrite the / in the buffer
1163 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1164 if (backSlashAsUnicodeInString) { // there are TWO \
1166 // where only one is correct
1167 withoutUnicodePtr--;
1170 } else if ((currentCharacter == '\r')
1171 || (currentCharacter == '\n')) {
1172 if (recordLineSeparator) {
1173 pushLineSeparator();
1176 // consume next character
1177 unicodeAsBackSlash = false;
1178 currentCharacter = source[currentPosition++];
1179 // if (((currentCharacter = source[currentPosition++]) == '\\')
1180 // && (source[currentPosition] == 'u')) {
1181 // getNextUnicodeChar();
1183 if (withoutUnicodePtr != 0) {
1184 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1188 } catch (IndexOutOfBoundsException e) {
1189 // reset end position for error reporting
1190 currentPosition -= 2;
1191 throw new InvalidInputException(UNTERMINATED_STRING);
1192 } catch (InvalidInputException e) {
1193 if (e.getMessage().equals(INVALID_ESCAPE)) {
1194 // relocate if finding another quote fairly close: thus unicode
1195 // '/u000D' will be fully consumed
1196 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1197 if (currentPosition + lookAhead == source.length)
1199 if (source[currentPosition + lookAhead] == '\n')
1201 if (source[currentPosition + lookAhead] == '`') {
1202 currentPosition += lookAhead + 1;
1209 if (checkNonExternalizedStringLiterals) { // check for presence of NLS
1211 // //$NON-NLS-?$ where ? is an
1213 if (currentLine == null) {
1214 currentLine = new NLSLine();
1215 lines.add(currentLine);
1217 currentLine.add(new StringLiteral(getCurrentTokenSourceString(),
1218 startPosition, currentPosition - 1));
1222 public void consumeStringConstant() throws InvalidInputException {
1224 // consume next character
1225 unicodeAsBackSlash = false;
1226 currentCharacter = source[currentPosition++];
1227 // if (((currentCharacter = source[currentPosition++]) == '\\')
1228 // && (source[currentPosition] == 'u')) {
1229 // getNextUnicodeChar();
1231 // if (withoutUnicodePtr != 0) {
1232 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1233 // currentCharacter;
1236 while (currentCharacter != '\'') {
1237 /** ** in PHP \r and \n are valid in string literals *** */
1238 // if ((currentCharacter == '\n')
1239 // || (currentCharacter == '\r')) {
1240 // // relocate if finding another quote fairly close: thus
1242 // '/u000D' will be fully consumed
1243 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1244 // if (currentPosition + lookAhead == source.length)
1246 // if (source[currentPosition + lookAhead] == '\n')
1248 // if (source[currentPosition + lookAhead] == '\"') {
1249 // currentPosition += lookAhead + 1;
1253 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1255 if (currentCharacter == '\\') {
1256 int escapeSize = currentPosition;
1257 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1258 // scanEscapeCharacter make a side effect on this value and
1260 // the previous value few lines down this one
1261 scanSingleQuotedEscapeCharacter();
1262 escapeSize = currentPosition - escapeSize;
1263 if (withoutUnicodePtr == 0) {
1264 // buffer all the entries that have been left aside....
1265 withoutUnicodePtr = currentPosition - escapeSize - 1
1267 System.arraycopy(source, startPosition,
1268 withoutUnicodeBuffer, 1, withoutUnicodePtr);
1269 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1270 } else { // overwrite the / in the buffer
1271 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1272 if (backSlashAsUnicodeInString) { // there are TWO \
1274 // where only one is correct
1275 withoutUnicodePtr--;
1278 } else if ((currentCharacter == '\r')
1279 || (currentCharacter == '\n')) {
1280 if (recordLineSeparator) {
1281 pushLineSeparator();
1284 // consume next character
1285 unicodeAsBackSlash = false;
1286 currentCharacter = source[currentPosition++];
1287 // if (((currentCharacter = source[currentPosition++]) == '\\')
1288 // && (source[currentPosition] == 'u')) {
1289 // getNextUnicodeChar();
1291 if (withoutUnicodePtr != 0) {
1292 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1296 } catch (IndexOutOfBoundsException e) {
1297 // reset end position for error reporting
1298 currentPosition -= 2;
1299 throw new InvalidInputException(UNTERMINATED_STRING);
1300 } catch (InvalidInputException e) {
1301 if (e.getMessage().equals(INVALID_ESCAPE)) {
1302 // relocate if finding another quote fairly close: thus unicode
1303 // '/u000D' will be fully consumed
1304 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1305 if (currentPosition + lookAhead == source.length)
1307 if (source[currentPosition + lookAhead] == '\n')
1309 if (source[currentPosition + lookAhead] == '\'') {
1310 currentPosition += lookAhead + 1;
1317 if (checkNonExternalizedStringLiterals) { // check for presence of NLS
1319 // //$NON-NLS-?$ where ? is an
1321 if (currentLine == null) {
1322 currentLine = new NLSLine();
1323 lines.add(currentLine);
1325 currentLine.add(new StringLiteral(getCurrentTokenSourceString(),
1326 startPosition, currentPosition - 1));
1334 public void consumeStringLiteral() throws InvalidInputException {
1336 int openDollarBrace = 0;
1338 unicodeAsBackSlash = false;
1339 currentCharacter = source[currentPosition++]; // consume next character
1341 while (currentCharacter != '"' || // As long as the ending '"' isn't found, or
1342 openDollarBrace > 0) { // the last '}' isn't found
1343 if (currentCharacter == '\\') {
1344 int escapeSize = currentPosition;
1345 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1347 // scanEscapeCharacter make a side effect on this value and we need
1348 // the previous value few lines down this one
1349 scanDoubleQuotedEscapeCharacter ();
1350 escapeSize = currentPosition - escapeSize;
1352 if (withoutUnicodePtr == 0) { // buffer all the entries that have been left aside....
1353 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1354 System.arraycopy (source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1355 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1357 else { // overwrite the / in the buffer
1358 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1360 if (backSlashAsUnicodeInString) { // there are TWO \ in the stream where only one is correct
1361 withoutUnicodePtr--;
1365 else if (currentCharacter == '$' && source[currentPosition] == '{') { // If found '${'
1367 currentCharacter = source[currentPosition++]; // consume next character, or we count one open brace to much!
1369 else if (currentCharacter == '{' && source[currentPosition] == '$') { // If found '{$'
1372 else if (currentCharacter == '}') { // If found '}'
1375 else if ((currentCharacter == '\r') || (currentCharacter == '\n')) { // In PHP \r and \n are valid in string literals
1376 if (recordLineSeparator) {
1377 pushLineSeparator ();
1381 unicodeAsBackSlash = false;
1382 currentCharacter = source[currentPosition++]; // consume next character
1384 if (withoutUnicodePtr != 0) {
1385 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1388 } catch (IndexOutOfBoundsException e) {
1389 // reset end position for error reporting
1390 currentPosition -= 2;
1391 throw new InvalidInputException(UNTERMINATED_STRING);
1392 } catch (InvalidInputException e) {
1393 if (e.getMessage().equals(INVALID_ESCAPE)) {
1394 // relocate if finding another quote fairly close: thus unicode
1395 // '/u000D' will be fully consumed
1396 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1397 if (currentPosition + lookAhead == source.length)
1399 if (source[currentPosition + lookAhead] == '\n')
1401 if (source[currentPosition + lookAhead] == '\"') {
1402 currentPosition += lookAhead + 1;
1410 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1411 // $NON-NLS-?$ where ? is an int.
1412 if (currentLine == null) {
1413 currentLine = new NLSLine ();
1414 lines.add (currentLine);
1416 currentLine.add (new StringLiteral (getCurrentTokenSourceString (), startPosition, currentPosition - 1));
1423 public TokenName getNextToken() throws InvalidInputException {
1425 return getInlinedHTMLToken(currentPosition);
1427 if (fFillerToken != TokenName.EOF) {
1428 TokenName tempToken;
1429 startPosition = currentPosition;
1430 tempToken = fFillerToken;
1431 fFillerToken = TokenName.EOF;
1434 this.wasAcr = false;
1436 jumpOverMethodBody();
1438 return currentPosition > source.length ? TokenName.EOF
1443 withoutUnicodePtr = 0;
1444 // ---------Consume white space and handles
1445 // startPosition---------
1446 int whiteStart = currentPosition;
1447 startPosition = currentPosition;
1448 currentCharacter = source[currentPosition++];
1450 while ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) {
1451 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1452 checkNonExternalizeString();
1454 if (recordLineSeparator) {
1455 pushLineSeparator();
1460 startPosition = currentPosition;
1461 currentCharacter = source[currentPosition++];
1464 if (tokenizeWhiteSpace && (whiteStart != currentPosition - 1)) {
1465 // reposition scanner in case we are interested by
1468 startPosition = whiteStart;
1469 return TokenName.WHITESPACE;
1471 // little trick to get out in the middle of a source
1473 if (currentPosition > eofPosition)
1474 return TokenName.EOF;
1475 // ---------Identify the next token-------------
1476 switch (currentCharacter) {
1478 return getCastOrParen();
1480 return TokenName.RPAREN;
1482 return TokenName.LBRACE;
1484 return TokenName.RBRACE;
1486 return TokenName.LBRACKET;
1488 return TokenName.RBRACKET;
1490 return TokenName.SEMICOLON;
1492 return TokenName.COMMA;
1494 if (getNextChar('='))
1495 return TokenName.DOT_EQUAL;
1496 if (getNextCharAsDigit())
1497 return scanNumber(true);
1498 return TokenName.DOT;
1500 return TokenName.BACKSLASH;
1503 if ((test = getNextChar('+', '=')) == 0)
1504 return TokenName.PLUS_PLUS;
1506 return TokenName.PLUS_EQUAL;
1507 return TokenName.PLUS;
1511 if ((test = getNextChar('-', '=')) == 0)
1512 return TokenName.MINUS_MINUS;
1514 return TokenName.MINUS_EQUAL;
1515 if (getNextChar('>'))
1516 return TokenName.MINUS_GREATER;
1517 return TokenName.MINUS;
1520 if (getNextChar('='))
1521 return TokenName.TWIDDLE_EQUAL;
1522 return TokenName.TWIDDLE;
1524 if (getNextChar('=')) {
1525 if (getNextChar('=')) {
1526 return TokenName.NOT_EQUAL_EQUAL;
1528 return TokenName.NOT_EQUAL;
1530 return TokenName.NOT;
1532 if (getNextChar('='))
1533 return TokenName.MULTIPLY_EQUAL;
1534 return TokenName.MULTIPLY;
1536 if (getNextChar('='))
1537 return TokenName.REMAINDER_EQUAL;
1538 return TokenName.REMAINDER;
1540 int oldPosition = currentPosition;
1542 currentCharacter = source[currentPosition++];
1543 } catch (IndexOutOfBoundsException e) {
1544 currentPosition = oldPosition;
1545 return TokenName.LESS;
1547 switch (currentCharacter) {
1549 return TokenName.LESS_EQUAL;
1551 return TokenName.NOT_EQUAL;
1553 if (getNextChar('='))
1554 return TokenName.LEFT_SHIFT_EQUAL;
1555 if (getNextChar('<')) {
1556 currentCharacter = source[currentPosition++];
1557 while (Character.isWhitespace(currentCharacter)) {
1558 currentCharacter = source[currentPosition++];
1560 int heredocStart = currentPosition - 1;
1561 int heredocLength = 0;
1562 if (isPHPIdentifierStart(currentCharacter)) {
1563 currentCharacter = source[currentPosition++];
1565 return TokenName.ERROR;
1567 while (isPHPIdentifierPart(currentCharacter)) {
1568 currentCharacter = source[currentPosition++];
1570 heredocLength = currentPosition - heredocStart
1572 // heredoc end-tag determination
1573 boolean endTag = true;
1576 ch = source[currentPosition++];
1577 if (ch == '\r' || ch == '\n') {
1578 if (recordLineSeparator) {
1579 pushLineSeparator();
1583 for (int i = 0; i < heredocLength; i++) {
1584 if (source[currentPosition + i] != source[heredocStart
1591 currentPosition += heredocLength - 1;
1592 currentCharacter = source[currentPosition++];
1593 break; // do...while loop
1599 return TokenName.HEREDOC;
1601 return TokenName.LEFT_SHIFT;
1603 currentPosition = oldPosition;
1604 return TokenName.LESS;
1608 if ((test = getNextChar('=', '>')) == 0)
1609 return TokenName.GREATER_EQUAL;
1611 if ((test = getNextChar('=', '>')) == 0)
1612 return TokenName.RIGHT_SHIFT_EQUAL;
1613 return TokenName.RIGHT_SHIFT;
1615 return TokenName.GREATER;
1618 if (getNextChar('=')) {
1619 if (getNextChar('=')) {
1620 return TokenName.EQUAL_EQUAL_EQUAL;
1622 return TokenName.EQUAL_EQUAL;
1624 if (getNextChar('>'))
1625 return TokenName.EQUAL_GREATER;
1626 return TokenName.EQUAL;
1629 if ((test = getNextChar('&', '=')) == 0)
1630 return TokenName.AND_AND;
1632 return TokenName.AND_EQUAL;
1633 return TokenName.OP_AND;
1637 if ((test = getNextChar('|', '=')) == 0)
1638 return TokenName.OR_OR;
1640 return TokenName.OR_EQUAL;
1641 return TokenName.OP_OR;
1644 if (getNextChar('='))
1645 return TokenName.XOR_EQUAL;
1646 return TokenName.OP_XOR;
1648 if (getNextChar('>')) {
1650 if (currentPosition == source.length) {
1652 return TokenName.INLINE_HTML;
1654 return getInlinedHTMLToken(currentPosition - 2);
1656 return TokenName.QUESTION;
1658 if (getNextChar(':'))
1659 return TokenName.PAAMAYIM_NEKUDOTAYIM;
1660 return TokenName.COLON;
1662 return TokenName.OP_AT;
1664 consumeStringConstant();
1665 return TokenName.STRINGSINGLEQUOTE;
1667 // if (tokenizeStrings) {
1668 consumeStringLiteral();
1669 return TokenName.STRINGDOUBLEQUOTE;
1671 // return TokenName.EncapsedString2;
1673 // if (tokenizeStrings) {
1674 consumeStringInterpolated();
1675 return TokenName.STRINGINTERPOLATED;
1677 // return TokenName.EncapsedString0;
1680 char startChar = currentCharacter;
1681 if (getNextChar('=') && startChar == '/') {
1682 return TokenName.DIVIDE_EQUAL;
1685 if ((startChar == '#')
1686 || (test = getNextChar('/', '*')) == 0) {
1688 this.lastCommentLinePosition = this.currentPosition;
1689 int endPositionForLineComment = 0;
1690 try { // get the next char
1691 currentCharacter = source[currentPosition++];
1692 // if (((currentCharacter =
1693 // source[currentPosition++])
1695 // && (source[currentPosition] == 'u')) {
1696 // //-------------unicode traitement
1698 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1699 // currentPosition++;
1700 // while (source[currentPosition] == 'u') {
1701 // currentPosition++;
1704 // Character.getNumericValue(source[currentPosition++]))
1708 // Character.getNumericValue(source[currentPosition++]))
1712 // Character.getNumericValue(source[currentPosition++]))
1716 // Character.getNumericValue(source[currentPosition++]))
1720 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1722 // currentCharacter =
1723 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
1727 // handle the \\u case manually into comment
1728 // if (currentCharacter == '\\') {
1729 // if (source[currentPosition] == '\\')
1730 // currentPosition++;
1731 // } //jump over the \\
1732 boolean isUnicode = false;
1733 while (currentCharacter != '\r'
1734 && currentCharacter != '\n') {
1735 this.lastCommentLinePosition = this.currentPosition;
1736 if (currentCharacter == '?') {
1737 if (getNextChar('>')) {
1738 // ?> breaks line comments
1739 startPosition = currentPosition - 2;
1741 return TokenName.INLINE_HTML;
1744 // get the next char
1746 currentCharacter = source[currentPosition++];
1747 // if (((currentCharacter =
1748 // source[currentPosition++])
1750 // && (source[currentPosition] == 'u')) {
1751 // isUnicode = true;
1752 // //-------------unicode traitement
1754 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1755 // currentPosition++;
1756 // while (source[currentPosition] == 'u') {
1757 // currentPosition++;
1760 // Character.getNumericValue(source[currentPosition++]))
1764 // Character.getNumericValue(
1765 // source[currentPosition++]))
1769 // Character.getNumericValue(
1770 // source[currentPosition++]))
1774 // Character.getNumericValue(
1775 // source[currentPosition++]))
1779 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1781 // currentCharacter =
1782 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
1786 // handle the \\u case manually into comment
1787 // if (currentCharacter == '\\') {
1788 // if (source[currentPosition] == '\\')
1789 // currentPosition++;
1790 // } //jump over the \\
1793 endPositionForLineComment = currentPosition - 6;
1795 endPositionForLineComment = currentPosition - 1;
1797 // recordComment(false);
1798 recordComment(TokenName.COMMENT_LINE);
1799 if (this.taskTags != null)
1800 checkTaskTag(this.startPosition,
1801 this.currentPosition);
1802 if ((currentCharacter == '\r')
1803 || (currentCharacter == '\n')) {
1804 checkNonExternalizeString();
1805 if (recordLineSeparator) {
1807 pushUnicodeLineSeparator();
1809 pushLineSeparator();
1815 if (tokenizeComments) {
1817 currentPosition = endPositionForLineComment;
1818 // reset one character behind
1820 return TokenName.COMMENT_LINE;
1822 } catch (IndexOutOfBoundsException e) { // an eof
1825 if (tokenizeComments) {
1827 // reset one character behind
1828 return TokenName.COMMENT_LINE;
1834 // traditional and annotation comment
1835 boolean isJavadoc = false, star = false;
1836 // consume next character
1837 unicodeAsBackSlash = false;
1838 currentCharacter = source[currentPosition++];
1839 // if (((currentCharacter =
1840 // source[currentPosition++]) ==
1842 // && (source[currentPosition] == 'u')) {
1843 // getNextUnicodeChar();
1845 // if (withoutUnicodePtr != 0) {
1846 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1847 // currentCharacter;
1850 if (currentCharacter == '*') {
1854 if ((currentCharacter == '\r')
1855 || (currentCharacter == '\n')) {
1856 checkNonExternalizeString();
1857 if (recordLineSeparator) {
1858 pushLineSeparator();
1863 try { // get the next char
1864 currentCharacter = source[currentPosition++];
1865 // if (((currentCharacter =
1866 // source[currentPosition++])
1868 // && (source[currentPosition] == 'u')) {
1869 // //-------------unicode traitement
1871 // getNextUnicodeChar();
1873 // handle the \\u case manually into comment
1874 // if (currentCharacter == '\\') {
1875 // if (source[currentPosition] == '\\')
1876 // currentPosition++;
1877 // //jump over the \\
1879 // empty comment is not a javadoc /**/
1880 if (currentCharacter == '/') {
1883 // loop until end of comment */
1884 while ((currentCharacter != '/') || (!star)) {
1885 if ((currentCharacter == '\r')
1886 || (currentCharacter == '\n')) {
1887 checkNonExternalizeString();
1888 if (recordLineSeparator) {
1889 pushLineSeparator();
1894 star = currentCharacter == '*';
1896 currentCharacter = source[currentPosition++];
1897 // if (((currentCharacter =
1898 // source[currentPosition++])
1900 // && (source[currentPosition] == 'u')) {
1901 // //-------------unicode traitement
1903 // getNextUnicodeChar();
1905 // handle the \\u case manually into comment
1906 // if (currentCharacter == '\\') {
1907 // if (source[currentPosition] == '\\')
1908 // currentPosition++;
1909 // } //jump over the \\
1911 // recordComment(isJavadoc);
1913 recordComment(TokenName.COMMENT_PHPDOC);
1915 recordComment(TokenName.COMMENT_BLOCK);
1918 if (tokenizeComments) {
1920 return TokenName.COMMENT_PHPDOC;
1921 return TokenName.COMMENT_BLOCK;
1924 if (this.taskTags != null) {
1925 checkTaskTag(this.startPosition,
1926 this.currentPosition);
1928 } catch (IndexOutOfBoundsException e) {
1929 // reset end position for error reporting
1930 currentPosition -= 2;
1931 throw new InvalidInputException(
1932 UNTERMINATED_COMMENT);
1936 return TokenName.DIVIDE;
1940 return TokenName.EOF;
1941 // the atEnd may not be <currentPosition ==
1942 // source.length> if
1943 // source is only some part of a real (external) stream
1944 throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$
1946 if (currentCharacter == '$') {
1947 int oldPosition = currentPosition;
1949 currentCharacter = source[currentPosition++];
1950 if (isPHPIdentifierStart(currentCharacter)) {
1951 return scanIdentifierOrKeyword(true);
1953 currentPosition = oldPosition;
1954 return TokenName.DOLLAR;
1956 } catch (IndexOutOfBoundsException e) {
1957 currentPosition = oldPosition;
1958 return TokenName.DOLLAR;
1962 if (isPHPIdentifierStart(currentCharacter)) {
1963 return scanIdentifierOrKeyword(false);
1966 if (Character.isDigit(currentCharacter)) {
1967 return scanNumber(false);
1970 return TokenName.ERROR;
1973 } // -----------------end switch while try--------------------
1974 catch (IndexOutOfBoundsException e) {
1977 return TokenName.EOF;
1982 * @throws InvalidInputException
1984 private TokenName getInlinedHTMLToken(int start) throws InvalidInputException {
1985 boolean phpShortTag = false; // true, if <?= detected
1986 if (currentPosition > source.length) {
1987 currentPosition = source.length;
1988 return TokenName.EOF;
1990 startPosition = start;
1993 currentCharacter = source[currentPosition++];
1994 if (currentCharacter == '<') {
1995 if (getNextChar('?')) {
1996 currentCharacter = source[currentPosition++];
1997 if ((currentCharacter != 'P')
1998 && (currentCharacter != 'p')) {
1999 if (currentCharacter != '=') { // <?=
2001 phpShortTag = false;
2006 if (ignorePHPOneLiner) { // for CodeFormatter
2007 if (lookAheadLinePHPTag() == TokenName.INLINE_HTML) {
2010 fFillerToken = TokenName.ECHO_INVISIBLE;
2012 return TokenName.INLINE_HTML;
2015 boolean foundXML = false;
2016 if (getNextChar('X', 'x') >= 0) {
2017 if (getNextChar('M', 'm') >= 0) {
2018 if (getNextChar('L', 'l') >= 0) {
2027 fFillerToken = TokenName.ECHO_INVISIBLE;
2029 return TokenName.INLINE_HTML;
2032 if (getNextChar('H', 'h') >= 0) {
2033 if (getNextChar('P', 'p') >= 0) {
2035 if (ignorePHPOneLiner) {
2036 if (lookAheadLinePHPTag() == TokenName.INLINE_HTML) {
2038 return TokenName.INLINE_HTML;
2042 return TokenName.INLINE_HTML;
2050 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
2051 if (recordLineSeparator) {
2052 pushLineSeparator();
2057 } // -----------------while--------------------
2059 return TokenName.INLINE_HTML;
2060 } // -----------------try--------------------
2061 catch (IndexOutOfBoundsException e) {
2062 startPosition = start;
2066 return TokenName.INLINE_HTML;
2070 * check if the PHP is only in this line (for CodeFormatter)
2074 private TokenName lookAheadLinePHPTag() {
2075 int currentPositionInLine = currentPosition;
2076 char previousCharInLine = ' ';
2077 char currentCharInLine = ' ';
2078 boolean singleQuotedStringActive = false;
2079 boolean doubleQuotedStringActive = false;
2082 // look ahead in this line
2084 previousCharInLine = currentCharInLine;
2085 currentCharInLine = source[currentPositionInLine++];
2086 switch (currentCharInLine) {
2088 if (previousCharInLine == '?') {
2089 // update the scanner's current Position in the source
2090 currentPosition = currentPositionInLine;
2091 // use as "dummy" token
2092 return TokenName.EOF;
2096 if (doubleQuotedStringActive) {
2097 // ignore escaped characters in double quoted strings
2098 previousCharInLine = currentCharInLine;
2099 currentCharInLine = source[currentPositionInLine++];
2102 if (doubleQuotedStringActive) {
2103 doubleQuotedStringActive = false;
2105 if (!singleQuotedStringActive) {
2106 doubleQuotedStringActive = true;
2111 if (singleQuotedStringActive) {
2112 if (previousCharInLine != '\\') {
2113 singleQuotedStringActive = false;
2116 if (!doubleQuotedStringActive) {
2117 singleQuotedStringActive = true;
2123 return TokenName.INLINE_HTML;
2125 if (!singleQuotedStringActive && !doubleQuotedStringActive) {
2127 return TokenName.INLINE_HTML;
2131 if (previousCharInLine == '/' && !singleQuotedStringActive
2132 && !doubleQuotedStringActive) {
2134 return TokenName.INLINE_HTML;
2138 if (previousCharInLine == '/' && !singleQuotedStringActive
2139 && !doubleQuotedStringActive) {
2141 return TokenName.INLINE_HTML;
2146 } catch (IndexOutOfBoundsException e) {
2148 currentPosition = currentPositionInLine - 1;
2149 return TokenName.INLINE_HTML;
2153 // public final void getNextUnicodeChar()
2154 // throws IndexOutOfBoundsException, InvalidInputException {
2156 // //handle the case of unicode.
2157 // //when a unicode appears then we must use a buffer that holds char
2159 // //At the end of this method currentCharacter holds the new visited char
2160 // //and currentPosition points right next after it
2162 // //ALL getNextChar.... ARE OPTIMIZED COPIES
2164 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
2165 // currentPosition++;
2166 // while (source[currentPosition] == 'u') {
2167 // currentPosition++;
2171 // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2173 // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
2175 // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
2177 // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
2179 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2181 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2182 // //need the unicode buffer
2183 // if (withoutUnicodePtr == 0) {
2184 // //buffer all the entries that have been left aside....
2185 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
2186 // System.arraycopy(
2189 // withoutUnicodeBuffer,
2191 // withoutUnicodePtr);
2193 // //fill the buffer with the char
2194 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2196 // unicodeAsBackSlash = currentCharacter == '\\';
2199 * Tokenize a method body, assuming that curly brackets are properly
2202 public final void jumpOverMethodBody() {
2203 this.wasAcr = false;
2206 while (true) { // loop for jumping over comments
2207 // ---------Consume white space and handles
2208 // startPosition---------
2209 boolean isWhiteSpace;
2211 startPosition = currentPosition;
2212 currentCharacter = source[currentPosition++];
2213 // if (((currentCharacter = source[currentPosition++]) ==
2215 // && (source[currentPosition] == 'u')) {
2216 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
2218 if (recordLineSeparator
2219 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2220 pushLineSeparator();
2221 isWhiteSpace = Character.isWhitespace(currentCharacter);
2223 } while (isWhiteSpace);
2224 // -------consume token until } is found---------
2225 switch (currentCharacter) {
2236 test = getNextChar('\\');
2239 scanDoubleQuotedEscapeCharacter();
2240 } catch (InvalidInputException ex) {
2244 // try { // consume next character
2245 unicodeAsBackSlash = false;
2246 currentCharacter = source[currentPosition++];
2247 // if (((currentCharacter = source[currentPosition++])
2249 // && (source[currentPosition] == 'u')) {
2250 // getNextUnicodeChar();
2252 if (withoutUnicodePtr != 0) {
2253 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2256 // } catch (InvalidInputException ex) {
2264 // try { // consume next character
2265 unicodeAsBackSlash = false;
2266 currentCharacter = source[currentPosition++];
2267 // if (((currentCharacter = source[currentPosition++])
2269 // && (source[currentPosition] == 'u')) {
2270 // getNextUnicodeChar();
2272 if (withoutUnicodePtr != 0) {
2273 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2276 // } catch (InvalidInputException ex) {
2278 while (currentCharacter != '"') {
2279 if (currentCharacter == '\r') {
2280 if (source[currentPosition] == '\n')
2283 // the string cannot go further that the line
2285 if (currentCharacter == '\n') {
2287 // the string cannot go further that the line
2289 if (currentCharacter == '\\') {
2291 scanDoubleQuotedEscapeCharacter();
2292 } catch (InvalidInputException ex) {
2296 // try { // consume next character
2297 unicodeAsBackSlash = false;
2298 currentCharacter = source[currentPosition++];
2299 // if (((currentCharacter =
2300 // source[currentPosition++]) == '\\')
2301 // && (source[currentPosition] == 'u')) {
2302 // getNextUnicodeChar();
2304 if (withoutUnicodePtr != 0) {
2305 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2308 // } catch (InvalidInputException ex) {
2311 } catch (IndexOutOfBoundsException e) {
2317 if ((test = getNextChar('/', '*')) == 0) {
2320 // get the next char
2321 currentCharacter = source[currentPosition++];
2322 // if (((currentCharacter =
2323 // source[currentPosition++]) ==
2325 // && (source[currentPosition] == 'u')) {
2326 // //-------------unicode traitement ------------
2327 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2328 // currentPosition++;
2329 // while (source[currentPosition] == 'u') {
2330 // currentPosition++;
2333 // Character.getNumericValue(source[currentPosition++]))
2337 // Character.getNumericValue(source[currentPosition++]))
2341 // Character.getNumericValue(source[currentPosition++]))
2345 // Character.getNumericValue(source[currentPosition++]))
2348 // //error don't care of the value
2349 // currentCharacter = 'A';
2350 // } //something different from \n and \r
2352 // currentCharacter =
2353 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2356 while (currentCharacter != '\r'
2357 && currentCharacter != '\n') {
2358 // get the next char
2359 currentCharacter = source[currentPosition++];
2360 // if (((currentCharacter =
2361 // source[currentPosition++])
2363 // && (source[currentPosition] == 'u')) {
2364 // //-------------unicode traitement
2366 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2367 // currentPosition++;
2368 // while (source[currentPosition] == 'u') {
2369 // currentPosition++;
2372 // Character.getNumericValue(source[currentPosition++]))
2376 // Character.getNumericValue(source[currentPosition++]))
2380 // Character.getNumericValue(source[currentPosition++]))
2384 // Character.getNumericValue(source[currentPosition++]))
2387 // //error don't care of the value
2388 // currentCharacter = 'A';
2389 // } //something different from \n and \r
2391 // currentCharacter =
2392 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
2397 if (recordLineSeparator
2398 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2399 pushLineSeparator();
2400 } catch (IndexOutOfBoundsException e) {
2401 } // an eof will them be generated
2405 // traditional and annotation comment
2406 boolean star = false;
2407 // try { // consume next character
2408 unicodeAsBackSlash = false;
2409 currentCharacter = source[currentPosition++];
2410 // if (((currentCharacter = source[currentPosition++])
2412 // && (source[currentPosition] == 'u')) {
2413 // getNextUnicodeChar();
2415 if (withoutUnicodePtr != 0) {
2416 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2419 // } catch (InvalidInputException ex) {
2421 if (currentCharacter == '*') {
2424 if (recordLineSeparator
2425 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2426 pushLineSeparator();
2427 try { // get the next char
2428 currentCharacter = source[currentPosition++];
2429 // if (((currentCharacter =
2430 // source[currentPosition++]) ==
2432 // && (source[currentPosition] == 'u')) {
2433 // //-------------unicode traitement ------------
2434 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2435 // currentPosition++;
2436 // while (source[currentPosition] == 'u') {
2437 // currentPosition++;
2440 // Character.getNumericValue(source[currentPosition++]))
2444 // Character.getNumericValue(source[currentPosition++]))
2448 // Character.getNumericValue(source[currentPosition++]))
2452 // Character.getNumericValue(source[currentPosition++]))
2455 // //error don't care of the value
2456 // currentCharacter = 'A';
2457 // } //something different from * and /
2459 // currentCharacter =
2460 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2463 // loop until end of comment */
2464 while ((currentCharacter != '/') || (!star)) {
2465 if (recordLineSeparator
2466 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2467 pushLineSeparator();
2468 star = currentCharacter == '*';
2470 currentCharacter = source[currentPosition++];
2471 // if (((currentCharacter =
2472 // source[currentPosition++])
2474 // && (source[currentPosition] == 'u')) {
2475 // //-------------unicode traitement
2477 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2478 // currentPosition++;
2479 // while (source[currentPosition] == 'u') {
2480 // currentPosition++;
2483 // Character.getNumericValue(source[currentPosition++]))
2487 // Character.getNumericValue(source[currentPosition++]))
2491 // Character.getNumericValue(source[currentPosition++]))
2495 // Character.getNumericValue(source[currentPosition++]))
2498 // //error don't care of the value
2499 // currentCharacter = 'A';
2500 // } //something different from * and /
2502 // currentCharacter =
2503 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 +
2508 } catch (IndexOutOfBoundsException e) {
2516 if (isPHPIdentOrVarStart(currentCharacter)) {
2518 scanIdentifierOrKeyword((currentCharacter == '$'));
2519 } catch (InvalidInputException ex) {
2524 if (ObviousIdentCharNatures[currentCharacter] == C_DIGIT) {
2525 // if (Character.isDigit(currentCharacter)) {
2528 } catch (InvalidInputException ex) {
2535 // -----------------end switch while try--------------------
2536 } catch (IndexOutOfBoundsException e) {
2537 } catch (InvalidInputException e) {
2542 // public final boolean jumpOverUnicodeWhiteSpace()
2543 // throws InvalidInputException {
2545 // //handle the case of unicode. Jump over the next whiteSpace
2546 // //making startPosition pointing on the next available char
2547 // //On false, the currentCharacter is filled up with a potential
2551 // this.wasAcr = false;
2552 // int c1, c2, c3, c4;
2553 // int unicodeSize = 6;
2554 // currentPosition++;
2555 // while (source[currentPosition] == 'u') {
2556 // currentPosition++;
2560 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2562 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2564 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2566 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2568 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2571 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2572 // if (recordLineSeparator
2573 // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2574 // pushLineSeparator();
2575 // if (Character.isWhitespace(currentCharacter))
2578 // //buffer the new char which is not a white space
2579 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2580 // //withoutUnicodePtr == 1 is true here
2582 // } catch (IndexOutOfBoundsException e) {
2583 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2586 public final int[] getLineEnds() {
2587 // return a bounded copy of this.lineEnds
2589 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0,
2594 public char[] getSource() {
2598 public static boolean isIdentifierOrKeyword (TokenName token) {
2599 return (token == TokenName.IDENTIFIER) || (token.compareTo (TokenName.KEYWORD) > 0);
2602 final char[] optimizedCurrentTokenSource1() {
2603 // return always the same char[] build only once
2604 // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2605 char charOne = source[startPosition];
2660 return new char[] { charOne };
2664 final char[] optimizedCurrentTokenSource2() {
2666 c0 = source[startPosition];
2667 c1 = source[startPosition + 1];
2669 // return always the same char[] build only once
2670 // optimization at no speed cost of 99.5 % of the
2671 // singleCharIdentifier
2674 return charArray_va;
2676 return charArray_vb;
2678 return charArray_vc;
2680 return charArray_vd;
2682 return charArray_ve;
2684 return charArray_vf;
2686 return charArray_vg;
2688 return charArray_vh;
2690 return charArray_vi;
2692 return charArray_vj;
2694 return charArray_vk;
2696 return charArray_vl;
2698 return charArray_vm;
2700 return charArray_vn;
2702 return charArray_vo;
2704 return charArray_vp;
2706 return charArray_vq;
2708 return charArray_vr;
2710 return charArray_vs;
2712 return charArray_vt;
2714 return charArray_vu;
2716 return charArray_vv;
2718 return charArray_vw;
2720 return charArray_vx;
2722 return charArray_vy;
2724 return charArray_vz;
2727 // try to return the same char[] build only once
2728 int hash = ((c0 << 6) + c1) % TableSize;
2729 char[][] table = charArray_length[0][hash];
2731 while (++i < InternalTableSize) {
2732 char[] charArray = table[i];
2733 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2736 // ---------other side---------
2738 int max = newEntry2;
2739 while (++i <= max) {
2740 char[] charArray = table[i];
2741 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2744 // --------add the entry-------
2745 if (++max >= InternalTableSize)
2748 table[max] = (r = new char[] { c0, c1 });
2753 final char[] optimizedCurrentTokenSource3() {
2754 // try to return the same char[] build only once
2756 int hash = (((c0 = source[startPosition]) << 12)
2757 + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2759 char[][] table = charArray_length[1][hash];
2761 while (++i < InternalTableSize) {
2762 char[] charArray = table[i];
2763 if ((c0 == charArray[0]) && (c1 == charArray[1])
2764 && (c2 == charArray[2]))
2767 // ---------other side---------
2769 int max = newEntry3;
2770 while (++i <= max) {
2771 char[] charArray = table[i];
2772 if ((c0 == charArray[0]) && (c1 == charArray[1])
2773 && (c2 == charArray[2]))
2776 // --------add the entry-------
2777 if (++max >= InternalTableSize)
2780 table[max] = (r = new char[] { c0, c1, c2 });
2785 final char[] optimizedCurrentTokenSource4() {
2786 // try to return the same char[] build only once
2787 char c0, c1, c2, c3;
2788 long hash = ((((long) (c0 = source[startPosition])) << 18)
2789 + ((c1 = source[startPosition + 1]) << 12)
2790 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2792 char[][] table = charArray_length[2][(int) hash];
2794 while (++i < InternalTableSize) {
2795 char[] charArray = table[i];
2796 if ((c0 == charArray[0]) && (c1 == charArray[1])
2797 && (c2 == charArray[2]) && (c3 == charArray[3]))
2800 // ---------other side---------
2803 int max = newEntry4;
2804 while (++i <= max) {
2805 char[] charArray = table[i];
2806 if ((c0 == charArray[0]) && (c1 == charArray[1])
2807 && (c2 == charArray[2]) && (c3 == charArray[3]))
2810 // --------add the entry-------
2811 if (++max >= InternalTableSize)
2814 table[max] = (r = new char[] { c0, c1, c2, c3 });
2819 final char[] optimizedCurrentTokenSource5() {
2820 // try to return the same char[] build only once
2821 char c0, c1, c2, c3, c4;
2822 long hash = ((((long) (c0 = source[startPosition])) << 24)
2823 + (((long) (c1 = source[startPosition + 1])) << 18)
2824 + ((c2 = source[startPosition + 2]) << 12)
2825 + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2827 char[][] table = charArray_length[3][(int) hash];
2829 while (++i < InternalTableSize) {
2830 char[] charArray = table[i];
2831 if ((c0 == charArray[0]) && (c1 == charArray[1])
2832 && (c2 == charArray[2]) && (c3 == charArray[3])
2833 && (c4 == charArray[4]))
2836 // ---------other side---------
2838 int max = newEntry5;
2839 while (++i <= max) {
2840 char[] charArray = table[i];
2841 if ((c0 == charArray[0]) && (c1 == charArray[1])
2842 && (c2 == charArray[2]) && (c3 == charArray[3])
2843 && (c4 == charArray[4]))
2846 // --------add the entry-------
2847 if (++max >= InternalTableSize)
2850 table[max] = (r = new char[] { c0, c1, c2, c3, c4 });
2855 final char[] optimizedCurrentTokenSource6() {
2856 // try to return the same char[] build only once
2857 char c0, c1, c2, c3, c4, c5;
2858 long hash = ((((long) (c0 = source[startPosition])) << 32)
2859 + (((long) (c1 = source[startPosition + 1])) << 24)
2860 + (((long) (c2 = source[startPosition + 2])) << 18)
2861 + ((c3 = source[startPosition + 3]) << 12)
2862 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2864 char[][] table = charArray_length[4][(int) hash];
2866 while (++i < InternalTableSize) {
2867 char[] charArray = table[i];
2868 if ((c0 == charArray[0]) && (c1 == charArray[1])
2869 && (c2 == charArray[2]) && (c3 == charArray[3])
2870 && (c4 == charArray[4]) && (c5 == charArray[5]))
2873 // ---------other side---------
2875 int max = newEntry6;
2876 while (++i <= max) {
2877 char[] charArray = table[i];
2878 if ((c0 == charArray[0]) && (c1 == charArray[1])
2879 && (c2 == charArray[2]) && (c3 == charArray[3])
2880 && (c4 == charArray[4]) && (c5 == charArray[5]))
2883 // --------add the entry-------
2884 if (++max >= InternalTableSize)
2887 table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 });
2892 public final void pushLineSeparator() throws InvalidInputException {
2893 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2894 final int INCREMENT = 250;
2895 if (this.checkNonExternalizedStringLiterals) {
2896 // reinitialize the current line for non externalize strings purpose
2899 // currentCharacter is at position currentPosition-1
2901 if (currentCharacter == '\r') {
2902 int separatorPos = currentPosition - 1;
2903 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2905 // System.out.println("CR-" + separatorPos);
2907 lineEnds[++linePtr] = separatorPos;
2908 } catch (IndexOutOfBoundsException e) {
2909 // linePtr value is correct
2910 int oldLength = lineEnds.length;
2911 int[] old = lineEnds;
2912 lineEnds = new int[oldLength + INCREMENT];
2913 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2914 lineEnds[linePtr] = separatorPos;
2916 // look-ahead for merged cr+lf
2918 if (source[currentPosition] == '\n') {
2919 // System.out.println("look-ahead LF-" + currentPosition);
2920 lineEnds[linePtr] = currentPosition;
2926 } catch (IndexOutOfBoundsException e) {
2931 if (currentCharacter == '\n') {
2932 // must merge eventual cr followed by lf
2933 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2934 // System.out.println("merge LF-" + (currentPosition - 1));
2935 lineEnds[linePtr] = currentPosition - 1;
2937 int separatorPos = currentPosition - 1;
2938 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2940 // System.out.println("LF-" + separatorPos);
2942 lineEnds[++linePtr] = separatorPos;
2943 } catch (IndexOutOfBoundsException e) {
2944 // linePtr value is correct
2945 int oldLength = lineEnds.length;
2946 int[] old = lineEnds;
2947 lineEnds = new int[oldLength + INCREMENT];
2948 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2949 lineEnds[linePtr] = separatorPos;
2957 public final void pushUnicodeLineSeparator() {
2958 // isUnicode means that the \r or \n has been read as a unicode
2960 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2961 final int INCREMENT = 250;
2962 // currentCharacter is at position currentPosition-1
2963 if (this.checkNonExternalizedStringLiterals) {
2964 // reinitialize the current line for non externalize strings purpose
2968 if (currentCharacter == '\r') {
2969 int separatorPos = currentPosition - 6;
2970 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2972 // System.out.println("CR-" + separatorPos);
2974 lineEnds[++linePtr] = separatorPos;
2975 } catch (IndexOutOfBoundsException e) {
2976 // linePtr value is correct
2977 int oldLength = lineEnds.length;
2978 int[] old = lineEnds;
2979 lineEnds = new int[oldLength + INCREMENT];
2980 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2981 lineEnds[linePtr] = separatorPos;
2983 // look-ahead for merged cr+lf
2984 if (source[currentPosition] == '\n') {
2985 // System.out.println("look-ahead LF-" + currentPosition);
2986 lineEnds[linePtr] = currentPosition;
2994 if (currentCharacter == '\n') {
2995 // must merge eventual cr followed by lf
2996 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2997 // System.out.println("merge LF-" + (currentPosition - 1));
2998 lineEnds[linePtr] = currentPosition - 6;
3000 int separatorPos = currentPosition - 6;
3001 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
3003 // System.out.println("LF-" + separatorPos);
3005 lineEnds[++linePtr] = separatorPos;
3006 } catch (IndexOutOfBoundsException e) {
3007 // linePtr value is correct
3008 int oldLength = lineEnds.length;
3009 int[] old = lineEnds;
3010 lineEnds = new int[oldLength + INCREMENT];
3011 System.arraycopy(old, 0, lineEnds, 0, oldLength);
3012 lineEnds[linePtr] = separatorPos;
3020 public void recordComment(TokenName token) {
3022 int stopPosition = this.currentPosition;
3025 stopPosition = -this.lastCommentLinePosition;
3028 stopPosition = -this.currentPosition;
3032 // a new comment is recorded
3033 int length = this.commentStops.length;
3034 if (++this.commentPtr >= length) {
3035 System.arraycopy(this.commentStops, 0,
3036 this.commentStops = new int[length + 30], 0, length);
3037 // grows the positions buffers too
3038 System.arraycopy(this.commentStarts, 0,
3039 this.commentStarts = new int[length + 30], 0, length);
3041 this.commentStops[this.commentPtr] = stopPosition;
3042 this.commentStarts[this.commentPtr] = this.startPosition;
3045 // public final void recordComment(boolean isJavadoc) {
3046 // // a new annotation comment is recorded
3048 // commentStops[++commentPtr] = isJavadoc
3049 // ? currentPosition
3050 // : -currentPosition;
3051 // } catch (IndexOutOfBoundsException e) {
3052 // int oldStackLength = commentStops.length;
3053 // int[] oldStack = commentStops;
3054 // commentStops = new int[oldStackLength + 30];
3055 // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
3056 // commentStops[commentPtr] = isJavadoc ? currentPosition :
3057 // -currentPosition;
3058 // //grows the positions buffers too
3059 // int[] old = commentStarts;
3060 // commentStarts = new int[oldStackLength + 30];
3061 // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
3063 // //the buffer is of a correct size here
3064 // commentStarts[commentPtr] = startPosition;
3066 public void resetTo(int begin, int end) {
3067 // reset the scanner to a given position where it may rescan again
3069 initialPosition = startPosition = currentPosition = begin;
3070 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
3071 commentPtr = -1; // reset comment stack
3074 public final void scanSingleQuotedEscapeCharacter()
3075 throws InvalidInputException {
3076 // the string with "\\u" is a legal string of two chars \ and u
3077 // thus we use a direct access to the source (for regular cases).
3078 // if (unicodeAsBackSlash) {
3079 // // consume next character
3080 // unicodeAsBackSlash = false;
3081 // if (((currentCharacter = source[currentPosition++]) == '\\')
3082 // && (source[currentPosition] == 'u')) {
3083 // getNextUnicodeChar();
3085 // if (withoutUnicodePtr != 0) {
3086 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3090 currentCharacter = source[currentPosition++];
3091 switch (currentCharacter) {
3093 currentCharacter = '\'';
3096 currentCharacter = '\\';
3099 currentCharacter = '\\';
3104 public final void scanDoubleQuotedEscapeCharacter()
3105 throws InvalidInputException {
3106 currentCharacter = source[currentPosition++];
3107 switch (currentCharacter) {
3109 // currentCharacter = '\b';
3112 currentCharacter = '\t';
3115 currentCharacter = '\n';
3118 // currentCharacter = '\f';
3121 currentCharacter = '\r';
3124 currentCharacter = '\"';
3127 currentCharacter = '\'';
3130 currentCharacter = '\\';
3133 currentCharacter = '$';
3136 // -----------octal escape--------------
3138 // OctalDigit OctalDigit
3139 // ZeroToThree OctalDigit OctalDigit
3140 int number = Character.getNumericValue(currentCharacter);
3141 if (number >= 0 && number <= 7) {
3142 boolean zeroToThreeNot = number > 3;
3144 .isDigit(currentCharacter = source[currentPosition++])) {
3145 int digit = Character.getNumericValue(currentCharacter);
3146 if (digit >= 0 && digit <= 7) {
3147 number = (number * 8) + digit;
3149 .isDigit(currentCharacter = source[currentPosition++])) {
3150 if (zeroToThreeNot) { // has read \NotZeroToThree
3152 // Digit --> ignore last character
3156 .getNumericValue(currentCharacter);
3157 if (digit >= 0 && digit <= 7) {
3158 // has read \ZeroToThree OctalDigit
3160 number = (number * 8) + digit;
3161 } else { // has read \ZeroToThree OctalDigit
3163 // --> ignore last character
3167 } else { // has read \OctalDigit NonDigit--> ignore
3172 } else { // has read \OctalDigit NonOctalDigit--> ignore
3177 } else { // has read \OctalDigit --> ignore last character
3181 throw new InvalidInputException(INVALID_ESCAPE);
3182 currentCharacter = (char) number;
3185 // throw new InvalidInputException(INVALID_ESCAPE);
3189 // public int scanIdentifierOrKeyword() throws InvalidInputException {
3190 // return scanIdentifierOrKeyword( false );
3192 public TokenName scanIdentifierOrKeyword(boolean isVariable)
3193 throws InvalidInputException {
3195 // first dispatch on the first char.
3196 // then the length. If there are several
3197 // keywords with the same length AND the same first char, then do another
3198 // disptach on the second char :-)...cool....but fast !
3199 useAssertAsAnIndentifier = false;
3200 while (getNextCharAsJavaIdentifierPart()) {
3204 // if (new String(getCurrentTokenSource()).equals("$this")) {
3205 // return TokenName.this;
3207 return TokenName.VARIABLE;
3212 // if (withoutUnicodePtr == 0)
3213 // quick test on length == 1 but not on length > 12 while most
3215 // have a length which is <= 12...but there are lots of identifier with
3216 // only one char....
3218 if ((length = currentPosition - startPosition) == 1)
3219 return TokenName.IDENTIFIER;
3221 data = new char[length];
3222 index = startPosition;
3223 for (int i = 0; i < length; i++) {
3224 data[i] = Character.toLowerCase(source[index + i]);
3228 // if ((length = withoutUnicodePtr) == 1)
3229 // return TokenName.Identifier;
3230 // // data = withoutUnicodeBuffer;
3231 // data = new char[withoutUnicodeBuffer.length];
3232 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
3233 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
3237 firstLetter = data[index];
3238 switch (firstLetter) {
3243 if ((data[++index] == '_') && (data[++index] == 'f')
3244 && (data[++index] == 'i') && (data[++index] == 'l')
3245 && (data[++index] == 'e') && (data[++index] == '_')
3246 && (data[++index] == '_'))
3247 return TokenName.FILE;
3248 index = 0; // __LINE__
3249 if ((data[++index] == '_') && (data[++index] == 'l')
3250 && (data[++index] == 'i') && (data[++index] == 'n')
3251 && (data[++index] == 'e') && (data[++index] == '_')
3252 && (data[++index] == '_'))
3253 return TokenName.LINE;
3257 if ((data[++index] == '_') && (data[++index] == 'c')
3258 && (data[++index] == 'l') && (data[++index] == 'a')
3259 && (data[++index] == 's') && (data[++index] == 's')
3260 && (data[++index] == '_') && (data[++index] == '_'))
3261 return TokenName.CLASS_C;
3265 if ((data[++index] == '_') && (data[++index] == 'm')
3266 && (data[++index] == 'e') && (data[++index] == 't')
3267 && (data[++index] == 'h') && (data[++index] == 'o')
3268 && (data[++index] == 'd') && (data[++index] == '_')
3269 && (data[++index] == '_'))
3270 return TokenName.METHOD_C;
3274 if ((data[++index] == '_') && (data[++index] == 'f')
3275 && (data[++index] == 'u') && (data[++index] == 'n')
3276 && (data[++index] == 'c') && (data[++index] == 't')
3277 && (data[++index] == 'i') && (data[++index] == 'o')
3278 && (data[++index] == 'n') && (data[++index] == '_')
3279 && (data[++index] == '_'))
3280 return TokenName.FUNC_C;
3283 return TokenName.IDENTIFIER;
3285 // as and array abstract
3289 if ((data[++index] == 's')) {
3290 return TokenName.AS;
3292 return TokenName.IDENTIFIER;
3295 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3296 return TokenName.OP_AND_OLD;
3298 return TokenName.IDENTIFIER;
3301 if ((data[++index] == 'r') && (data[++index] == 'r')
3302 && (data[++index] == 'a') && (data[++index] == 'y'))
3303 return TokenName.ARRAY;
3304 return TokenName.IDENTIFIER;
3306 if ((data[++index] == 'b') && (data[++index] == 's')
3307 && (data[++index] == 't') && (data[++index] == 'r')
3308 && (data[++index] == 'a') && (data[++index] == 'c')
3309 && (data[++index] == 't'))
3310 return TokenName.ABSTRACT;
3311 return TokenName.IDENTIFIER;
3313 return TokenName.IDENTIFIER;
3318 if ((data[++index] == 'r') && (data[++index] == 'e')
3319 && (data[++index] == 'a') && (data[++index] == 'k'))
3320 return TokenName.BREAK;
3321 return TokenName.IDENTIFIER;
3323 return TokenName.IDENTIFIER;
3325 // case catch class clone const continue
3328 if ((data[++index] == 'a') && (data[++index] == 's')
3329 && (data[++index] == 'e'))
3330 return TokenName.CASE;
3331 return TokenName.IDENTIFIER;
3333 if ((data[++index] == 'a') && (data[++index] == 't')
3334 && (data[++index] == 'c') && (data[++index] == 'h'))
3335 return TokenName.CATCH;
3337 if ((data[++index] == 'l') && (data[++index] == 'a')
3338 && (data[++index] == 's') && (data[++index] == 's'))
3339 return TokenName.CLASS;
3341 if ((data[++index] == 'l') && (data[++index] == 'o')
3342 && (data[++index] == 'n') && (data[++index] == 'e'))
3343 return TokenName.CLONE;
3345 if ((data[++index] == 'o') && (data[++index] == 'n')
3346 && (data[++index] == 's') && (data[++index] == 't'))
3347 return TokenName.CONST;
3348 return TokenName.IDENTIFIER;
3350 if ((data[++index] == 'o') && (data[++index] == 'n')
3351 && (data[++index] == 't') && (data[++index] == 'i')
3352 && (data[++index] == 'n') && (data[++index] == 'u')
3353 && (data[++index] == 'e'))
3354 return TokenName.CONTINUE;
3355 return TokenName.IDENTIFIER;
3357 return TokenName.IDENTIFIER;
3359 // declare default do die
3360 // TODO delete define ==> no keyword !
3363 if ((data[++index] == 'o'))
3364 return TokenName.DO;
3365 return TokenName.IDENTIFIER;
3367 // if ((data[++index] == 'e')
3368 // && (data[++index] == 'f')
3369 // && (data[++index] == 'i')
3370 // && (data[++index] == 'n')
3371 // && (data[++index] == 'e'))
3372 // return TokenName.define;
3374 // return TokenName.Identifier;
3376 if ((data[++index] == 'e') && (data[++index] == 'c')
3377 && (data[++index] == 'l') && (data[++index] == 'a')
3378 && (data[++index] == 'r') && (data[++index] == 'e'))
3379 return TokenName.DECLARE;
3381 if ((data[++index] == 'e') && (data[++index] == 'f')
3382 && (data[++index] == 'a') && (data[++index] == 'u')
3383 && (data[++index] == 'l') && (data[++index] == 't'))
3384 return TokenName.DEFAULT;
3385 return TokenName.IDENTIFIER;
3387 return TokenName.IDENTIFIER;
3389 // echo else exit elseif extends eval
3392 if ((data[++index] == 'c') && (data[++index] == 'h')
3393 && (data[++index] == 'o'))
3394 return TokenName.ECHO;
3395 else if ((data[index] == 'l') && (data[++index] == 's')
3396 && (data[++index] == 'e'))
3397 return TokenName.ELSE;
3398 else if ((data[index] == 'x') && (data[++index] == 'i')
3399 && (data[++index] == 't'))
3400 return TokenName.EXIT;
3401 else if ((data[index] == 'v') && (data[++index] == 'a')
3402 && (data[++index] == 'l'))
3403 return TokenName.EVAL;
3404 return TokenName.IDENTIFIER;
3407 if ((data[++index] == 'n') && (data[++index] == 'd')
3408 && (data[++index] == 'i') && (data[++index] == 'f'))
3409 return TokenName.ENDIF;
3410 if ((data[index] == 'm') && (data[++index] == 'p')
3411 && (data[++index] == 't') && (data[++index] == 'y'))
3412 return TokenName.EMPTY;
3413 return TokenName.IDENTIFIER;
3416 if ((data[++index] == 'n') && (data[++index] == 'd')
3417 && (data[++index] == 'f') && (data[++index] == 'o')
3418 && (data[++index] == 'r'))
3419 return TokenName.ENDFOR;
3420 else if ((data[index] == 'l') && (data[++index] == 's')
3421 && (data[++index] == 'e') && (data[++index] == 'i')
3422 && (data[++index] == 'f'))
3423 return TokenName.ELSEIF;
3424 return TokenName.IDENTIFIER;
3426 if ((data[++index] == 'x') && (data[++index] == 't')
3427 && (data[++index] == 'e') && (data[++index] == 'n')
3428 && (data[++index] == 'd') && (data[++index] == 's'))
3429 return TokenName.EXTENDS;
3430 return TokenName.IDENTIFIER;
3433 if ((data[++index] == 'n') && (data[++index] == 'd')
3434 && (data[++index] == 'w') && (data[++index] == 'h')
3435 && (data[++index] == 'i') && (data[++index] == 'l')
3436 && (data[++index] == 'e'))
3437 return TokenName.ENDWHILE;
3438 return TokenName.IDENTIFIER;
3441 if ((data[++index] == 'n') && (data[++index] == 'd')
3442 && (data[++index] == 's') && (data[++index] == 'w')
3443 && (data[++index] == 'i') && (data[++index] == 't')
3444 && (data[++index] == 'c') && (data[++index] == 'h'))
3445 return TokenName.ENDSWITCH;
3446 return TokenName.IDENTIFIER;
3449 if ((data[++index] == 'n') && (data[++index] == 'd')
3450 && (data[++index] == 'd') && (data[++index] == 'e')
3451 && (data[++index] == 'c') && (data[++index] == 'l')
3452 && (data[++index] == 'a') && (data[++index] == 'r')
3453 && (data[++index] == 'e'))
3454 return TokenName.ENDDECLARE;
3456 if ((data[++index] == 'n') // endforeach
3457 && (data[++index] == 'd')
3458 && (data[++index] == 'f')
3459 && (data[++index] == 'o')
3460 && (data[++index] == 'r')
3461 && (data[++index] == 'e')
3462 && (data[++index] == 'a')
3463 && (data[++index] == 'c') && (data[++index] == 'h'))
3464 return TokenName.ENDFOREACH;
3465 return TokenName.IDENTIFIER;
3467 return TokenName.IDENTIFIER;
3469 // for false final function
3472 if ((data[++index] == 'o') && (data[++index] == 'r'))
3473 return TokenName.FOR;
3474 return TokenName.IDENTIFIER;
3476 // if ((data[++index] == 'a') && (data[++index] == 'l')
3477 // && (data[++index] == 's') && (data[++index] == 'e'))
3478 // return TokenName.false;
3479 if ((data[++index] == 'i') && (data[++index] == 'n')
3480 && (data[++index] == 'a') && (data[++index] == 'l'))
3481 return TokenName.FINAL;
3482 return TokenName.IDENTIFIER;
3485 if ((data[++index] == 'o') && (data[++index] == 'r')
3486 && (data[++index] == 'e') && (data[++index] == 'a')
3487 && (data[++index] == 'c') && (data[++index] == 'h'))
3488 return TokenName.FOREACH;
3489 return TokenName.IDENTIFIER;
3492 if ((data[++index] == 'u') && (data[++index] == 'n')
3493 && (data[++index] == 'c') && (data[++index] == 't')
3494 && (data[++index] == 'i') && (data[++index] == 'o')
3495 && (data[++index] == 'n'))
3496 return TokenName.FUNCTION;
3497 return TokenName.IDENTIFIER;
3499 return TokenName.IDENTIFIER;
3503 if ((data[++index] == 'l') && (data[++index] == 'o')
3504 && (data[++index] == 'b') && (data[++index] == 'a')
3505 && (data[++index] == 'l')) {
3506 return TokenName.GLOBAL;
3509 else if (length == 4) { // goto
3510 if ((data[++index] == 'o') &&
3511 (data[++index] == 't') &&
3512 (data[++index] == 'o')) {
3513 return TokenName.GOTO;
3516 return TokenName.IDENTIFIER;
3518 // if int isset include include_once instanceof interface implements
3521 if (data[++index] == 'f')
3522 return TokenName.IF;
3523 return TokenName.IDENTIFIER;
3525 // if ((data[++index] == 'n') && (data[++index] == 't'))
3526 // return TokenName.int;
3528 // return TokenName.IDENTIFIER;
3530 if ((data[++index] == 's') && (data[++index] == 's')
3531 && (data[++index] == 'e') && (data[++index] == 't'))
3532 return TokenName.ISSET;
3533 return TokenName.IDENTIFIER;
3535 if ((data[++index] == 'n') && (data[++index] == 'c')
3536 && (data[++index] == 'l') && (data[++index] == 'u')
3537 && (data[++index] == 'd') && (data[++index] == 'e'))
3538 return TokenName.INCLUDE;
3539 return TokenName.IDENTIFIER;
3542 if ((data[++index] == 'n') && (data[++index] == 't')
3543 && (data[++index] == 'e') && (data[++index] == 'r')
3544 && (data[++index] == 'f') && (data[++index] == 'a')
3545 && (data[++index] == 'c') && (data[++index] == 'e'))
3546 return TokenName.INTERFACE;
3547 return TokenName.IDENTIFIER;
3549 // instanceof implements
3550 if ((data[++index] == 'n') && (data[++index] == 's')
3551 && (data[++index] == 't') && (data[++index] == 'a')
3552 && (data[++index] == 'n') && (data[++index] == 'c')
3553 && (data[++index] == 'e') && (data[++index] == 'o')
3554 && (data[++index] == 'f'))
3555 return TokenName.INSTANCEOF;
3556 if ((data[index] == 'm') && (data[++index] == 'p')
3557 && (data[++index] == 'l') && (data[++index] == 'e')
3558 && (data[++index] == 'm') && (data[++index] == 'e')
3559 && (data[++index] == 'n') && (data[++index] == 't')
3560 && (data[++index] == 's'))
3561 return TokenName.IMPLEMENTS;
3562 return TokenName.IDENTIFIER;
3563 case 12: // include_once
3564 if ((data[++index] == 'n') && (data[++index] == 'c')
3565 && (data[++index] == 'l') && (data[++index] == 'u')
3566 && (data[++index] == 'd') && (data[++index] == 'e')
3567 && (data[++index] == '_') && (data[++index] == 'o')
3568 && (data[++index] == 'n') && (data[++index] == 'c')
3569 && (data[++index] == 'e'))
3570 return TokenName.INCLUDE_ONCE;
3571 return TokenName.IDENTIFIER;
3573 return TokenName.IDENTIFIER;
3577 if ((data[++index] == 'i') && (data[++index] == 's')
3578 && (data[++index] == 't')) {
3579 return TokenName.LIST;
3582 return TokenName.IDENTIFIER;
3584 // new null namespace
3587 if ((data[++index] == 'e') && (data[++index] == 'w'))
3588 return TokenName.NEW;
3589 return TokenName.IDENTIFIER;
3591 // if ((data[++index] == 'u') && (data[++index] == 'l')
3592 // && (data[++index] == 'l'))
3593 // return TokenName.null;
3595 // return TokenName.IDENTIFIER;
3597 if ((data[++index] == 'a') && (data[++index] == 'm')
3598 && (data[++index] == 'e') && (data[++index] == 's')
3599 && (data[++index] == 'p') && (data[++index] == 'a')
3600 && (data[++index] == 'c') && (data[++index] == 'e')) {
3601 return TokenName.NAMESPACE;
3603 return TokenName.IDENTIFIER;
3605 return TokenName.IDENTIFIER;
3609 if (data[++index] == 'r') {
3610 return TokenName.OP_OR_OLD;
3613 // if (length == 12) {
3614 // if ((data[++index] == 'l')
3615 // && (data[++index] == 'd')
3616 // && (data[++index] == '_')
3617 // && (data[++index] == 'f')
3618 // && (data[++index] == 'u')
3619 // && (data[++index] == 'n')
3620 // && (data[++index] == 'c')
3621 // && (data[++index] == 't')
3622 // && (data[++index] == 'i')
3623 // && (data[++index] == 'o')
3624 // && (data[++index] == 'n')) {
3625 // return TokenName.old_function;
3628 return TokenName.IDENTIFIER;
3630 // print public private protected
3633 if ((data[++index] == 'r') && (data[++index] == 'i')
3634 && (data[++index] == 'n') && (data[++index] == 't')) {
3635 return TokenName.PRINT;
3637 return TokenName.IDENTIFIER;
3639 if ((data[++index] == 'u') && (data[++index] == 'b')
3640 && (data[++index] == 'l') && (data[++index] == 'i')
3641 && (data[++index] == 'c')) {
3642 return TokenName.PUBLIC;
3644 return TokenName.IDENTIFIER;
3646 if ((data[++index] == 'r') && (data[++index] == 'i')
3647 && (data[++index] == 'v') && (data[++index] == 'a')
3648 && (data[++index] == 't') && (data[++index] == 'e')) {
3649 return TokenName.PRIVATE;
3651 return TokenName.IDENTIFIER;
3653 if ((data[++index] == 'r') && (data[++index] == 'o')
3654 && (data[++index] == 't') && (data[++index] == 'e')
3655 && (data[++index] == 'c') && (data[++index] == 't')
3656 && (data[++index] == 'e') && (data[++index] == 'd')) {
3657 return TokenName.PROTECTED;
3659 return TokenName.IDENTIFIER;
3661 return TokenName.IDENTIFIER;
3663 // return require require_once
3665 if ((data[++index] == 'e') && (data[++index] == 't')
3666 && (data[++index] == 'u') && (data[++index] == 'r')
3667 && (data[++index] == 'n')) {
3668 return TokenName.RETURN;
3670 } else if (length == 7) {
3671 if ((data[++index] == 'e') && (data[++index] == 'q')
3672 && (data[++index] == 'u') && (data[++index] == 'i')
3673 && (data[++index] == 'r') && (data[++index] == 'e')) {
3674 return TokenName.REQUIRE;
3676 } else if (length == 12) {
3677 if ((data[++index] == 'e') && (data[++index] == 'q')
3678 && (data[++index] == 'u') && (data[++index] == 'i')
3679 && (data[++index] == 'r') && (data[++index] == 'e')
3680 && (data[++index] == '_') && (data[++index] == 'o')
3681 && (data[++index] == 'n') && (data[++index] == 'c')
3682 && (data[++index] == 'e')) {
3683 return TokenName.REQUIRE_ONCE;
3686 return TokenName.IDENTIFIER;
3688 // self static switch
3691 // if ((data[++index] == 'e') && (data[++index] == 'l') &&
3694 // return TokenName.self;
3696 // return TokenName.IDENTIFIER;
3698 if (data[++index] == 't')
3699 if ((data[++index] == 'a') && (data[++index] == 't')
3700 && (data[++index] == 'i') && (data[++index] == 'c')) {
3701 return TokenName.STATIC;
3703 return TokenName.IDENTIFIER;
3704 else if ((data[index] == 'w') && (data[++index] == 'i')
3705 && (data[++index] == 't') && (data[++index] == 'c')
3706 && (data[++index] == 'h'))
3707 return TokenName.SWITCH;
3709 return TokenName.IDENTIFIER;
3714 if ((data[++index] == 'r') && (data[++index] == 'y'))
3715 return TokenName.TRY;
3717 // if ((data[++index] == 'r') && (data[++index] == 'u')
3718 // && (data[++index] == 'e'))
3719 // return TokenName.true;
3721 return TokenName.IDENTIFIER;
3723 if ((data[++index] == 'h') && (data[++index] == 'r')
3724 && (data[++index] == 'o') && (data[++index] == 'w'))
3725 return TokenName.THROW;
3727 return TokenName.IDENTIFIER;
3732 if ((data[++index] == 's') && (data[++index] == 'e'))
3733 return TokenName.USE;
3735 return TokenName.IDENTIFIER;
3737 if ((data[++index] == 'n') && (data[++index] == 's')
3738 && (data[++index] == 'e') && (data[++index] == 't'))
3739 return TokenName.UNSET;
3741 return TokenName.IDENTIFIER;
3746 if ((data[++index] == 'a') && (data[++index] == 'r'))
3747 return TokenName.VAR;
3749 return TokenName.IDENTIFIER;
3754 if ((data[++index] == 'h') && (data[++index] == 'i')
3755 && (data[++index] == 'l') && (data[++index] == 'e'))
3756 return TokenName.WHILE;
3757 // case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3758 // (data[++index]=='e') && (data[++index]=='f')&&
3759 // (data[++index]=='p'))
3760 // return TokenName.widefp ;
3762 // return TokenName.IDENTIFIER;
3764 return TokenName.IDENTIFIER;
3769 if ((data[++index] == 'o') && (data[++index] == 'r'))
3770 return TokenName.OP_XOR_OLD;
3772 return TokenName.IDENTIFIER;
3774 return TokenName.IDENTIFIER;
3776 return TokenName.IDENTIFIER;
3779 public TokenName scanNumber(boolean dotPrefix) throws InvalidInputException {
3780 // when entering this method the currentCharacter is the firt
3781 // digit of the number , i.e. it may be preceeded by a . when
3782 // dotPrefix is true
3783 boolean floating = dotPrefix;
3784 if ((!dotPrefix) && (currentCharacter == '0')) {
3785 if (getNextChar('x', 'X') >= 0) { // ----------hexa-----------------
3786 // force the first char of the hexa number do exist...
3787 // consume next character
3788 unicodeAsBackSlash = false;
3789 currentCharacter = source[currentPosition++];
3790 // if (((currentCharacter = source[currentPosition++]) == '\\')
3791 // && (source[currentPosition] == 'u')) {
3792 // getNextUnicodeChar();
3794 // if (withoutUnicodePtr != 0) {
3795 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3798 if (Character.digit(currentCharacter, 16) == -1)
3799 throw new InvalidInputException(INVALID_HEXA);
3801 while (getNextCharAsDigit(16)) {
3804 // if (getNextChar('l', 'L') >= 0)
3805 // return TokenName.LongLiteral;
3807 return TokenName.INTEGERLITERAL;
3809 // there is x or X in the number
3810 // potential octal ! ... some one may write 000099.0 ! thus 00100 <
3811 // 00078.0 is true !!!!! crazy language
3812 if (getNextCharAsDigit()) {
3813 // -------------potential octal-----------------
3814 while (getNextCharAsDigit()) {
3817 // if (getNextChar('l', 'L') >= 0) {
3818 // return TokenName.LongLiteral;
3821 // if (getNextChar('f', 'F') >= 0) {
3822 // return TokenName.FloatingPointLiteral;
3824 if (getNextChar('d', 'D') >= 0) {
3825 return TokenName.DOUBLELITERAL;
3826 } else { // make the distinction between octal and float ....
3827 if (getNextChar('.')) { // bingo ! ....
3828 while (getNextCharAsDigit()) {
3831 if (getNextChar('e', 'E') >= 0) {
3832 // consume next character
3833 unicodeAsBackSlash = false;
3834 currentCharacter = source[currentPosition++];
3835 // if (((currentCharacter =
3836 // source[currentPosition++]) == '\\')
3837 // && (source[currentPosition] == 'u')) {
3838 // getNextUnicodeChar();
3840 // if (withoutUnicodePtr != 0) {
3841 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3842 // currentCharacter;
3845 if ((currentCharacter == '-')
3846 || (currentCharacter == '+')) {
3847 // consume next character
3848 unicodeAsBackSlash = false;
3849 currentCharacter = source[currentPosition++];
3850 // if (((currentCharacter =
3851 // source[currentPosition++]) == '\\')
3852 // && (source[currentPosition] == 'u')) {
3853 // getNextUnicodeChar();
3855 // if (withoutUnicodePtr != 0) {
3856 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3857 // currentCharacter;
3861 if (!Character.isDigit(currentCharacter))
3862 throw new InvalidInputException(INVALID_FLOAT);
3863 while (getNextCharAsDigit()) {
3867 // if (getNextChar('f', 'F') >= 0)
3868 // return TokenName.FloatingPointLiteral;
3869 getNextChar('d', 'D'); // jump over potential d or D
3870 return TokenName.DOUBLELITERAL;
3872 return TokenName.INTEGERLITERAL;
3879 while (getNextCharAsDigit()) {
3882 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3883 // return TokenName.LongLiteral;
3884 if ((!dotPrefix) && (getNextChar('.'))) { // decimal part that can be
3886 while (getNextCharAsDigit()) {
3891 // if floating is true both exponant and suffix may be optional
3892 if (getNextChar('e', 'E') >= 0) {
3894 // consume next character
3895 unicodeAsBackSlash = false;
3896 currentCharacter = source[currentPosition++];
3897 // if (((currentCharacter = source[currentPosition++]) == '\\')
3898 // && (source[currentPosition] == 'u')) {
3899 // getNextUnicodeChar();
3901 // if (withoutUnicodePtr != 0) {
3902 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3905 if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
3908 unicodeAsBackSlash = false;
3909 currentCharacter = source[currentPosition++];
3910 // if (((currentCharacter = source[currentPosition++]) == '\\')
3911 // && (source[currentPosition] == 'u')) {
3912 // getNextUnicodeChar();
3914 // if (withoutUnicodePtr != 0) {
3915 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3919 if (!Character.isDigit(currentCharacter))
3920 throw new InvalidInputException(INVALID_FLOAT);
3921 while (getNextCharAsDigit()) {
3925 if (getNextChar('d', 'D') >= 0)
3926 return TokenName.DOUBLELITERAL;
3927 // if (getNextChar('f', 'F') >= 0)
3928 // return TokenName.FloatingPointLiteral;
3929 // the long flag has been tested before
3930 return floating ? TokenName.DOUBLELITERAL : TokenName.INTEGERLITERAL;
3934 * Search the line number corresponding to a specific position
3937 public final int getLineNumber(int position) {
3938 if (lineEnds == null)
3940 int length = linePtr + 1;
3943 int g = 0, d = length - 1;
3947 if (position < lineEnds[m]) {
3949 } else if (position > lineEnds[m]) {
3955 if (position < lineEnds[m]) {
3961 public void setPHPMode(boolean mode) {
3965 public final void setSource(char[] source) {
3966 setSource(null, source);
3969 public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3970 // the source-buffer is set to sourceString
3971 this.compilationUnit = compilationUnit;
3972 if (source == null) {
3973 this.source = new char[0];
3975 this.source = source;
3978 initialPosition = currentPosition = 0;
3979 containsAssertKeyword = false;
3980 withoutUnicodeBuffer = new char[this.source.length];
3981 fFillerToken = TokenName.EOF;
3982 // encapsedStringStack = new Stack();
3985 public String toString() {
3986 if (startPosition == source.length)
3987 return "EOF\n\n" + new String(source); //$NON-NLS-1$
3988 if (currentPosition > source.length)
3989 return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3990 char front[] = new char[startPosition];
3991 System.arraycopy(source, 0, front, 0, startPosition);
3992 int middleLength = (currentPosition - 1) - startPosition + 1;
3994 if (middleLength > -1) {
3995 middle = new char[middleLength];
3996 System.arraycopy(source, startPosition, middle, 0, middleLength);
3998 middle = new char[0];
4000 char end[] = new char[source.length - (currentPosition - 1)];
4001 System.arraycopy(source, (currentPosition - 1) + 1, end, 0,
4002 source.length - (currentPosition - 1) - 1);
4003 return new String(front)
4004 + "\n===============================\nStarts here -->" //$NON-NLS-1$
4005 + new String(middle)
4006 + "<-- Ends here\n===============================\n" //$NON-NLS-1$
4010 public final String toStringAction(TokenName act) {
4013 return "ScannerError"; // + new String(getCurrentTokenSource()) +
4017 return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4018 case ECHO_INVISIBLE:
4022 return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4024 return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4026 return "abstract"; //$NON-NLS-1$
4028 return "AND"; //$NON-NLS-1$
4030 return "array"; //$NON-NLS-1$
4032 return "as"; //$NON-NLS-1$
4034 return "break"; //$NON-NLS-1$
4036 return "case"; //$NON-NLS-1$
4038 return "class"; //$NON-NLS-1$
4040 return "catch"; //$NON-NLS-1$
4048 return "continue"; //$NON-NLS-1$
4050 return "default"; //$NON-NLS-1$
4052 // return "define"; //$NON-NLS-1$
4054 return "do"; //$NON-NLS-1$
4056 return "echo"; //$NON-NLS-1$
4058 return "else"; //$NON-NLS-1$
4060 return "elseif"; //$NON-NLS-1$
4062 return "endfor"; //$NON-NLS-1$
4064 return "endforeach"; //$NON-NLS-1$
4066 return "endif"; //$NON-NLS-1$
4068 return "endswitch"; //$NON-NLS-1$
4070 return "endwhile"; //$NON-NLS-1$
4074 return "extends"; //$NON-NLS-1$
4076 // return "false"; //$NON-NLS-1$
4078 return "final"; //$NON-NLS-1$
4080 return "for"; //$NON-NLS-1$
4082 return "foreach"; //$NON-NLS-1$
4084 return "function"; //$NON-NLS-1$
4086 return "global"; //$NON-NLS-1$
4088 return "if"; //$NON-NLS-1$
4090 return "implements"; //$NON-NLS-1$
4092 return "include"; //$NON-NLS-1$
4094 return "include_once"; //$NON-NLS-1$
4096 return "instanceof"; //$NON-NLS-1$
4098 return "interface"; //$NON-NLS-1$
4100 return "isset"; //$NON-NLS-1$
4102 return "list"; //$NON-NLS-1$
4104 return "new"; //$NON-NLS-1$
4106 // return "null"; //$NON-NLS-1$
4108 return "OR"; //$NON-NLS-1$
4110 return "print"; //$NON-NLS-1$
4112 return "private"; //$NON-NLS-1$
4114 return "protected"; //$NON-NLS-1$
4116 return "public"; //$NON-NLS-1$
4118 return "require"; //$NON-NLS-1$
4120 return "require_once"; //$NON-NLS-1$
4122 return "return"; //$NON-NLS-1$
4124 // return "self"; //$NON-NLS-1$
4126 return "static"; //$NON-NLS-1$
4128 return "switch"; //$NON-NLS-1$
4130 // return "true"; //$NON-NLS-1$
4132 return "unset"; //$NON-NLS-1$
4134 return "var"; //$NON-NLS-1$
4136 return "while"; //$NON-NLS-1$
4138 return "XOR"; //$NON-NLS-1$
4140 // return "$this"; //$NON-NLS-1$
4141 case INTEGERLITERAL:
4142 return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4144 return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4145 case STRINGDOUBLEQUOTE:
4146 return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4147 case STRINGSINGLEQUOTE:
4148 return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4149 case STRINGINTERPOLATED:
4150 return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4151 case ENCAPSEDSTRING0:
4152 return "`"; //$NON-NLS-1$
4153 // case EncapsedString1:
4154 // return "\'"; //$NON-NLS-1$
4155 // case EncapsedString2:
4156 // return "\""; //$NON-NLS-1$
4158 return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
4160 return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4162 return "++"; //$NON-NLS-1$
4164 return "--"; //$NON-NLS-1$
4166 return "=="; //$NON-NLS-1$
4167 case EQUAL_EQUAL_EQUAL:
4168 return "==="; //$NON-NLS-1$
4170 return "=>"; //$NON-NLS-1$
4172 return "<="; //$NON-NLS-1$
4174 return ">="; //$NON-NLS-1$
4176 return "!="; //$NON-NLS-1$
4177 case NOT_EQUAL_EQUAL:
4178 return "!=="; //$NON-NLS-1$
4180 return "<<"; //$NON-NLS-1$
4182 return ">>"; //$NON-NLS-1$
4184 return "+="; //$NON-NLS-1$
4186 return "-="; //$NON-NLS-1$
4187 case MULTIPLY_EQUAL:
4188 return "*="; //$NON-NLS-1$
4190 return "/="; //$NON-NLS-1$
4192 return "&="; //$NON-NLS-1$
4194 return "|="; //$NON-NLS-1$
4196 return "^="; //$NON-NLS-1$
4197 case REMAINDER_EQUAL:
4198 return "%="; //$NON-NLS-1$
4200 return ".="; //$NON-NLS-1$
4201 case LEFT_SHIFT_EQUAL:
4202 return "<<="; //$NON-NLS-1$
4203 case RIGHT_SHIFT_EQUAL:
4204 return ">>="; //$NON-NLS-1$
4206 return "||"; //$NON-NLS-1$
4208 return "&&"; //$NON-NLS-1$
4210 return "+"; //$NON-NLS-1$
4212 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$
4250 return ";"; //$NON-NLS-1$
4252 return "?"; //$NON-NLS-1$
4254 return ":"; //$NON-NLS-1$
4256 return ","; //$NON-NLS-1$
4258 return "."; //$NON-NLS-1$
4260 return "="; //$NON-NLS-1$
4270 return "EOF"; //$NON-NLS-1$
4272 return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4274 return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4276 return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4277 case COMMENT_PHPDOC:
4278 return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4280 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
4283 return "__FILE__"; //$NON-NLS-1$
4285 return "__LINE__"; //$NON-NLS-1$
4287 return "__CLASS__"; //$NON-NLS-1$
4289 return "__METHOD__"; //$NON-NLS-1$
4291 return "__FUNCTION__"; //$NON-NLS-1
4293 return "( bool )"; //$NON-NLS-1$
4295 return "( int )"; //$NON-NLS-1$
4297 return "( double )"; //$NON-NLS-1$
4299 return "( object )"; //$NON-NLS-1$
4301 return "( string )"; //$NON-NLS-1$
4303 return "( namespace )"; //$NON-NLS-1$
4305 return "token not handled (" + (act.toString ()) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
4313 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
4314 this(tokenizeComments, tokenizeWhiteSpace, false);
4317 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
4318 boolean checkNonExternalizedStringLiterals) {
4319 this(tokenizeComments, tokenizeWhiteSpace,
4320 checkNonExternalizedStringLiterals, false);
4323 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
4324 boolean checkNonExternalizedStringLiterals, boolean assertMode) {
4325 this(tokenizeComments, tokenizeWhiteSpace,
4326 checkNonExternalizedStringLiterals, assertMode, false, null,
4330 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
4331 boolean checkNonExternalizedStringLiterals, boolean assertMode,
4332 boolean tokenizeStrings, char[][] taskTags,
4333 char[][] taskPriorities, boolean isTaskCaseSensitive) {
4334 this.eofPosition = Integer.MAX_VALUE;
4335 this.tokenizeComments = tokenizeComments;
4336 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4337 this.tokenizeStrings = tokenizeStrings;
4338 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4339 // this.assertMode = assertMode;
4340 // this.encapsedStringStack = null;
4341 this.taskTags = taskTags;
4342 this.taskPriorities = taskPriorities;
4345 private void checkNonExternalizeString() throws InvalidInputException {
4346 if (currentLine == null)
4348 parseTags(currentLine);
4351 private void parseTags(NLSLine line) throws InvalidInputException {
4352 String s = new String(getCurrentTokenSource());
4353 int pos = s.indexOf(TAG_PREFIX);
4354 int lineLength = line.size();
4356 int start = pos + TAG_PREFIX_LENGTH;
4357 int end = s.indexOf(TAG_POSTFIX, start);
4358 String index = s.substring(start, end);
4361 i = Integer.parseInt(index) - 1;
4362 // Tags are one based not zero based.
4363 } catch (NumberFormatException e) {
4364 i = -1; // we don't want to consider this as a valid NLS tag
4366 if (line.exists(i)) {
4369 pos = s.indexOf(TAG_PREFIX, start);
4371 this.nonNLSStrings = new StringLiteral[lineLength];
4372 int nonNLSCounter = 0;
4373 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4374 StringLiteral literal = (StringLiteral) iterator.next();
4375 if (literal != null) {
4376 this.nonNLSStrings[nonNLSCounter++] = literal;
4379 if (nonNLSCounter == 0) {
4380 this.nonNLSStrings = null;
4384 this.wasNonExternalizedStringLiteral = true;
4385 if (nonNLSCounter != lineLength) {
4386 System.arraycopy(this.nonNLSStrings, 0,
4387 (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0,
4393 public final void scanEscapeCharacter() throws InvalidInputException {
4394 // the string with "\\u" is a legal string of two chars \ and u
4395 // thus we use a direct access to the source (for regular cases).
4396 if (unicodeAsBackSlash) {
4397 // consume next character
4398 unicodeAsBackSlash = false;
4399 // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4400 // (source[currentPosition] == 'u')) {
4401 // getNextUnicodeChar();
4403 if (withoutUnicodePtr != 0) {
4404 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4408 currentCharacter = source[currentPosition++];
4409 switch (currentCharacter) {
4411 currentCharacter = '\b';
4414 currentCharacter = '\t';
4417 currentCharacter = '\n';
4420 currentCharacter = '\f';
4423 currentCharacter = '\r';
4426 currentCharacter = '\"';
4429 currentCharacter = '\'';
4432 currentCharacter = '\\';
4435 // -----------octal escape--------------
4437 // OctalDigit OctalDigit
4438 // ZeroToThree OctalDigit OctalDigit
4439 int number = Character.getNumericValue(currentCharacter);
4440 if (number >= 0 && number <= 7) {
4441 boolean zeroToThreeNot = number > 3;
4443 .isDigit(currentCharacter = source[currentPosition++])) {
4444 int digit = Character.getNumericValue(currentCharacter);
4445 if (digit >= 0 && digit <= 7) {
4446 number = (number * 8) + digit;
4448 .isDigit(currentCharacter = source[currentPosition++])) {
4449 if (zeroToThreeNot) { // has read \NotZeroToThree
4451 // Digit --> ignore last character
4455 .getNumericValue(currentCharacter);
4456 if (digit >= 0 && digit <= 7) { // has read
4458 // OctalDigit OctalDigit
4459 number = (number * 8) + digit;
4460 } else { // has read \ZeroToThree OctalDigit
4462 // --> ignore last character
4466 } else { // has read \OctalDigit NonDigit--> ignore
4471 } else { // has read \OctalDigit NonOctalDigit--> ignore
4476 } else { // has read \OctalDigit --> ignore last character
4480 throw new InvalidInputException(INVALID_ESCAPE);
4481 currentCharacter = (char) number;
4483 throw new InvalidInputException(INVALID_ESCAPE);
4487 // chech presence of task: tags
4488 // TODO (frederic) see if we need to take unicode characters into account...
4489 public void checkTaskTag(int commentStart, int commentEnd) {
4490 char[] src = this.source;
4492 // only look for newer task: tags
4493 if (this.foundTaskCount > 0
4494 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4497 int foundTaskIndex = this.foundTaskCount;
4498 char previous = src[commentStart + 1]; // should be '*' or '/'
4499 nextChar: for (int i = commentStart + 2; i < commentEnd
4500 && i < this.eofPosition; i++) {
4502 char[] priority = null;
4503 // check for tag occurrence only if not ambiguous with javadoc tag
4504 if (previous != '@') {
4505 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4506 tag = this.taskTags[itag];
4507 int tagLength = tag.length;
4511 // ensure tag is not leaded with letter if tag starts with a
4513 if (Scanner.isPHPIdentifierStart(tag[0])) {
4514 if (Scanner.isPHPIdentifierPart(previous)) {
4519 for (int t = 0; t < tagLength; t++) {
4522 if (x >= this.eofPosition || x >= commentEnd)
4524 if ((sc = src[i + t]) != (tc = tag[t])) { // case
4527 if (this.isTaskCaseSensitive
4528 || (Character.toLowerCase(sc) != Character
4529 .toLowerCase(tc))) { // case
4536 // ensure tag is not followed with letter if tag finishes
4539 if (i + tagLength < commentEnd
4540 && Scanner.isPHPIdentifierPart(src[i + tagLength
4542 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4545 if (this.foundTaskTags == null) {
4546 this.foundTaskTags = new char[5][];
4547 this.foundTaskMessages = new char[5][];
4548 this.foundTaskPriorities = new char[5][];
4549 this.foundTaskPositions = new int[5][];
4550 } else if (this.foundTaskCount == this.foundTaskTags.length) {
4555 this.foundTaskTags = new char[this.foundTaskCount * 2][],
4556 0, this.foundTaskCount);
4559 this.foundTaskMessages,
4561 this.foundTaskMessages = new char[this.foundTaskCount * 2][],
4562 0, this.foundTaskCount);
4565 this.foundTaskPriorities,
4567 this.foundTaskPriorities = new char[this.foundTaskCount * 2][],
4568 0, this.foundTaskCount);
4571 this.foundTaskPositions,
4573 this.foundTaskPositions = new int[this.foundTaskCount * 2][],
4574 0, this.foundTaskCount);
4577 priority = this.taskPriorities != null
4578 && itag < this.taskPriorities.length ? this.taskPriorities[itag]
4581 this.foundTaskTags[this.foundTaskCount] = tag;
4582 this.foundTaskPriorities[this.foundTaskCount] = priority;
4583 this.foundTaskPositions[this.foundTaskCount] = new int[] {
4584 i, i + tagLength - 1 };
4585 this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4586 this.foundTaskCount++;
4587 i += tagLength - 1; // will be incremented when looping
4593 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4594 // retrieve message start and end positions
4595 int msgStart = this.foundTaskPositions[i][0]
4596 + this.foundTaskTags[i].length;
4597 int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1
4599 // at most beginning of next task
4600 if (max_value < msgStart) {
4601 max_value = msgStart; // would only occur if tag is before
4606 for (int j = msgStart; j < max_value; j++) {
4607 if ((c = src[j]) == '\n' || c == '\r') {
4613 for (int j = max_value; j > msgStart; j--) {
4614 if ((c = src[j]) == '*') {
4622 if (msgStart == end)
4625 while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4627 while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4629 // update the end position of the task
4630 this.foundTaskPositions[i][1] = end;
4631 // get the message source
4632 final int messageLength = end - msgStart + 1;
4633 char[] message = new char[messageLength];
4634 System.arraycopy(src, msgStart, message, 0, messageLength);
4635 this.foundTaskMessages[i] = message;
4639 // chech presence of task: tags
4640 // public void checkTaskTag(int commentStart, int commentEnd) {
4641 // // only look for newer task: tags
4642 // if (this.foundTaskCount > 0 &&
4643 // this.foundTaskPositions[this.foundTaskCount
4644 // - 1][0] >= commentStart) {
4647 // int foundTaskIndex = this.foundTaskCount;
4648 // nextChar: for (int i = commentStart; i < commentEnd && i <
4649 // this.eofPosition; i++) {
4650 // char[] tag = null;
4651 // char[] priority = null;
4652 // // check for tag occurrence
4653 // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4654 // tag = this.taskTags[itag];
4655 // priority = this.taskPriorities != null && itag <
4656 // this.taskPriorities.length
4657 // ? this.taskPriorities[itag] : null;
4658 // int tagLength = tag.length;
4659 // for (int t = 0; t < tagLength; t++) {
4660 // if (this.source[i + t] != tag[t])
4661 // continue nextTag;
4663 // if (this.foundTaskTags == null) {
4664 // this.foundTaskTags = new char[5][];
4665 // this.foundTaskMessages = new char[5][];
4666 // this.foundTaskPriorities = new char[5][];
4667 // this.foundTaskPositions = new int[5][];
4668 // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4669 // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new
4670 // char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4671 // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new
4672 // char[this.foundTaskCount * 2][], 0,
4673 // this.foundTaskCount);
4674 // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities =
4675 // new char[this.foundTaskCount * 2][], 0,
4676 // this.foundTaskCount);
4677 // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions =
4679 // int[this.foundTaskCount * 2][], 0,
4680 // this.foundTaskCount);
4682 // this.foundTaskTags[this.foundTaskCount] = tag;
4683 // this.foundTaskPriorities[this.foundTaskCount] = priority;
4684 // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i +
4687 // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4688 // this.foundTaskCount++;
4689 // i += tagLength - 1; // will be incremented when looping
4692 // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4693 // // retrieve message start and end positions
4694 // int msgStart = this.foundTaskPositions[i][0] +
4695 // this.foundTaskTags[i].length;
4696 // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i +
4697 // 1][0] - 1 : commentEnd - 1;
4698 // // at most beginning of next task
4699 // if (max_value < msgStart)
4700 // max_value = msgStart; // would only occur if tag is before EOF.
4703 // for (int j = msgStart; j < max_value; j++) {
4704 // if ((c = this.source[j]) == '\n' || c == '\r') {
4710 // for (int j = max_value; j > msgStart; j--) {
4711 // if ((c = this.source[j]) == '*') {
4719 // if (msgStart == end)
4720 // continue; // empty
4721 // // trim the message
4722 // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4724 // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4726 // // update the end position of the task
4727 // this.foundTaskPositions[i][1] = end;
4728 // // get the message source
4729 // final int messageLength = end - msgStart + 1;
4730 // char[] message = new char[messageLength];
4731 // System.arraycopy(source, msgStart, message, 0, messageLength);
4732 // this.foundTaskMessages[i] = message;