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;
13 import java.util.Stack;
15 import net.sourceforge.phpdt.core.compiler.CharOperation;
16 import net.sourceforge.phpdt.core.compiler.IScanner;
17 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
18 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
19 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
20 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
22 public class Scanner implements IScanner, ITerminalSymbols {
24 * APIs ares - getNextToken() which return the current type of the token (this value is not memorized by the scanner) -
25 * getCurrentTokenSource() which provides with the token "REAL" source (aka all unicode have been transformed into a correct char) -
26 * sourceStart gives the position into the stream - currentPosition-1 gives the sourceEnd position into the stream
29 private boolean assertMode;
31 public boolean useAssertAsAnIndentifier = false;
33 //flag indicating if processed source contains occurrences of keyword assert
34 public boolean containsAssertKeyword = false;
36 public boolean recordLineSeparator;
38 public boolean ignorePHPOneLiner = false;
40 public boolean phpMode = false;
42 public Stack encapsedStringStack = null;
44 public char currentCharacter;
46 public int startPosition;
48 public int currentPosition;
50 public int initialPosition, eofPosition;
52 // after this position eof are generated instead of real token from the
54 public boolean tokenizeComments;
56 public boolean tokenizeWhiteSpace;
58 public boolean tokenizeStrings;
60 //source should be viewed as a window (aka a part)
61 //of a entire very large stream
65 public char[] withoutUnicodeBuffer;
67 public int withoutUnicodePtr;
69 //when == 0 ==> no unicode in the current token
70 public boolean unicodeAsBackSlash = false;
72 public boolean scanningFloatLiteral = false;
74 //support for /** comments
75 public int[] commentStops = new int[10];
77 public int[] commentStarts = new int[10];
79 public int commentPtr = -1; // no comment test with commentPtr value -1
81 protected int lastCommentLinePosition = -1;
83 //diet parsing support - jump over some method body when requested
84 public boolean diet = false;
86 //support for the poor-line-debuggers ....
87 //remember the position of the cr/lf
88 public int[] lineEnds = new int[250];
90 public int linePtr = -1;
92 public boolean wasAcr = false;
94 public static final String END_OF_SOURCE = "End_Of_Source"; //$NON-NLS-1$
96 public static final String INVALID_HEXA = "Invalid_Hexa_Literal"; //$NON-NLS-1$
98 public static final String INVALID_OCTAL = "Invalid_Octal_Literal"; //$NON-NLS-1$
100 public static final String INVALID_CHARACTER_CONSTANT = "Invalid_Character_Constant"; //$NON-NLS-1$
102 public static final String INVALID_ESCAPE = "Invalid_Escape"; //$NON-NLS-1$
104 public static final String INVALID_INPUT = "Invalid_Input"; //$NON-NLS-1$
106 public static final String INVALID_UNICODE_ESCAPE = "Invalid_Unicode_Escape"; //$NON-NLS-1$
108 public static final String INVALID_FLOAT = "Invalid_Float_Literal"; //$NON-NLS-1$
110 public static final String NULL_SOURCE_STRING = "Null_Source_String"; //$NON-NLS-1$
112 public static final String UNTERMINATED_STRING = "Unterminated_String"; //$NON-NLS-1$
114 public static final String UNTERMINATED_COMMENT = "Unterminated_Comment"; //$NON-NLS-1$
116 public static final String INVALID_CHAR_IN_STRING = "Invalid_Char_In_String"; //$NON-NLS-1$
118 //----------------optimized identifier managment------------------
119 static final char[] charArray_a = new char[] { 'a' }, charArray_b = new char[] { 'b' }, charArray_c = new char[] { 'c' },
120 charArray_d = new char[] { 'd' }, charArray_e = new char[] { 'e' }, charArray_f = new char[] { 'f' },
121 charArray_g = new char[] { 'g' }, charArray_h = new char[] { 'h' }, charArray_i = new char[] { 'i' },
122 charArray_j = new char[] { 'j' }, charArray_k = new char[] { 'k' }, charArray_l = new char[] { 'l' },
123 charArray_m = new char[] { 'm' }, charArray_n = new char[] { 'n' }, charArray_o = new char[] { 'o' },
124 charArray_p = new char[] { 'p' }, charArray_q = new char[] { 'q' }, charArray_r = new char[] { 'r' },
125 charArray_s = new char[] { 's' }, charArray_t = new char[] { 't' }, charArray_u = new char[] { 'u' },
126 charArray_v = new char[] { 'v' }, charArray_w = new char[] { 'w' }, charArray_x = new char[] { 'x' },
127 charArray_y = new char[] { 'y' }, charArray_z = new char[] { 'z' };
129 static final char[] charArray_va = new char[] { '$', 'a' }, charArray_vb = new char[] { '$', 'b' }, charArray_vc = new char[] {
131 'c' }, charArray_vd = new char[] { '$', 'd' }, charArray_ve = new char[] { '$', 'e' },
132 charArray_vf = new char[] { '$', 'f' }, charArray_vg = new char[] { '$', 'g' }, charArray_vh = new char[] { '$', 'h' },
133 charArray_vi = new char[] { '$', 'i' }, charArray_vj = new char[] { '$', 'j' }, charArray_vk = new char[] { '$', 'k' },
134 charArray_vl = new char[] { '$', 'l' }, charArray_vm = new char[] { '$', 'm' }, charArray_vn = new char[] { '$', 'n' },
135 charArray_vo = new char[] { '$', 'o' }, charArray_vp = new char[] { '$', 'p' }, charArray_vq = new char[] { '$', 'q' },
136 charArray_vr = new char[] { '$', 'r' }, charArray_vs = new char[] { '$', 's' }, charArray_vt = new char[] { '$', 't' },
137 charArray_vu = new char[] { '$', 'u' }, charArray_vv = new char[] { '$', 'v' }, charArray_vw = new char[] { '$', 'w' },
138 charArray_vx = new char[] { '$', 'x' }, charArray_vy = new char[] { '$', 'y' }, charArray_vz = new char[] { '$', 'z' };
140 static final char[] initCharArray = new char[] { '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' };
142 static final int TableSize = 30, InternalTableSize = 6;
145 public static final int OptimizedLength = 6;
148 final char[][][][] charArray_length = new char[OptimizedLength][TableSize][InternalTableSize][];
150 // support for detecting non-externalized string literals
151 int currentLineNr = -1;
153 int previousLineNr = -1;
155 NLSLine currentLine = null;
157 List lines = new ArrayList();
159 public static final String TAG_PREFIX = "//$NON-NLS-"; //$NON-NLS-1$
161 public static final int TAG_PREFIX_LENGTH = TAG_PREFIX.length();
163 public static final String TAG_POSTFIX = "$"; //$NON-NLS-1$
165 public static final int TAG_POSTFIX_LENGTH = TAG_POSTFIX.length();
167 public StringLiteral[] nonNLSStrings = null;
169 public boolean checkNonExternalizedStringLiterals = true;
171 public boolean wasNonExternalizedStringLiteral = false;
173 for (int i = 0; i < 6; i++) {
174 for (int j = 0; j < TableSize; j++) {
175 for (int k = 0; k < InternalTableSize; k++) {
176 charArray_length[i][j][k] = initCharArray;
182 static int newEntry2 = 0, newEntry3 = 0, newEntry4 = 0, newEntry5 = 0, newEntry6 = 0;
184 public static final int RoundBracket = 0;
186 public static final int SquareBracket = 1;
188 public static final int CurlyBracket = 2;
190 public static final int BracketKinds = 3;
193 public char[][] foundTaskTags = null;
195 public char[][] foundTaskMessages;
197 public char[][] foundTaskPriorities = null;
199 public int[][] foundTaskPositions;
201 public int foundTaskCount = 0;
203 public char[][] taskTags = null;
205 public char[][] taskPriorities = null;
207 public boolean isTaskCaseSensitive = true;
209 public static final boolean DEBUG = false;
211 public static final boolean TRACE = false;
213 public ICompilationUnit compilationUnit = null;
216 * Determines if the specified character is permissible as the first character in a PHP identifier or variable
218 * The '$' character for PHP variables is regarded as a correct first character !
221 public static boolean isPHPIdentOrVarStart(char ch) {
222 return Character.isLetter(ch) || (ch == '$') || (ch == '_') || (0x7F <= ch && ch <= 0xFF);
226 * Determines if the specified character is permissible as the first character in a PHP identifier.
228 * The '$' character for PHP variables isn't regarded as the first character !
230 public static boolean isPHPIdentifierStart(char ch) {
231 return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF);
235 * Determines if the specified character may be part of a PHP identifier as other than the first character
237 public static boolean isPHPIdentifierPart(char ch) {
238 return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF);
241 public final boolean atEnd() {
242 // This code is not relevant if source is
243 // Only a part of the real stream input
244 return source.length == currentPosition;
247 public char[] getCurrentIdentifierSource() {
248 //return the token REAL source (aka unicodes are precomputed)
250 // if (withoutUnicodePtr != 0)
251 // //0 is used as a fast test flag so the real first char is in position 1
253 // withoutUnicodeBuffer,
255 // result = new char[withoutUnicodePtr],
257 // withoutUnicodePtr);
259 int length = currentPosition - startPosition;
260 switch (length) { // see OptimizedLength
262 return optimizedCurrentTokenSource1();
264 return optimizedCurrentTokenSource2();
266 return optimizedCurrentTokenSource3();
268 return optimizedCurrentTokenSource4();
270 return optimizedCurrentTokenSource5();
272 return optimizedCurrentTokenSource6();
275 System.arraycopy(source, startPosition, result = new char[length], 0, length);
280 public int getCurrentTokenEndPosition() {
281 return this.currentPosition - 1;
284 public final char[] getCurrentTokenSource() {
285 // Return the token REAL source (aka unicodes are precomputed)
287 // if (withoutUnicodePtr != 0)
288 // // 0 is used as a fast test flag so the real first char is in position 1
290 // withoutUnicodeBuffer,
292 // result = new char[withoutUnicodePtr],
294 // withoutUnicodePtr);
297 System.arraycopy(source, startPosition, result = new char[length = currentPosition - startPosition], 0, length);
302 public final char[] getCurrentTokenSource(int startPos) {
303 // Return the token REAL source (aka unicodes are precomputed)
305 // if (withoutUnicodePtr != 0)
306 // // 0 is used as a fast test flag so the real first char is in position 1
308 // withoutUnicodeBuffer,
310 // result = new char[withoutUnicodePtr],
312 // withoutUnicodePtr);
315 System.arraycopy(source, startPos, result = new char[length = currentPosition - startPos], 0, length);
320 public final char[] getCurrentTokenSourceString() {
321 //return the token REAL source (aka unicodes are precomputed).
322 //REMOVE the two " that are at the beginning and the end.
324 if (withoutUnicodePtr != 0)
325 //0 is used as a fast test flag so the real first char is in position 1
326 System.arraycopy(withoutUnicodeBuffer, 2,
327 //2 is 1 (real start) + 1 (to jump over the ")
328 result = new char[withoutUnicodePtr - 2], 0, withoutUnicodePtr - 2);
331 System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length);
336 public final char[] getRawTokenSourceEnd() {
337 int length = this.eofPosition - this.currentPosition - 1;
338 char[] sourceEnd = new char[length];
339 System.arraycopy(this.source, this.currentPosition, sourceEnd, 0, length);
343 public int getCurrentTokenStartPosition() {
344 return this.startPosition;
347 public final char[] getCurrentStringLiteralSource() {
348 // Return the token REAL source (aka unicodes are precomputed)
349 if (startPosition + 1 >= currentPosition) {
354 System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length);
359 public final char[] getCurrentStringLiteralSource(int startPos) {
360 // Return the token REAL source (aka unicodes are precomputed)
363 System.arraycopy(source, startPos + 1, result = new char[length = currentPosition - startPos - 2], 0, length);
369 * Search the source position corresponding to the end of a given line number
371 * Line numbers are 1-based, and relative to the scanner initialPosition. Character positions are 0-based.
373 * In case the given line number is inconsistent, answers -1.
375 public final int getLineEnd(int lineNumber) {
376 if (lineEnds == null)
378 if (lineNumber >= lineEnds.length)
382 if (lineNumber == lineEnds.length - 1)
384 return lineEnds[lineNumber - 1];
385 // next line start one character behind the lineEnd of the previous line
389 * Search the source position corresponding to the beginning of a given line number
391 * Line numbers are 1-based, and relative to the scanner initialPosition. Character positions are 0-based.
393 * e.g. getLineStart(1) --> 0 i.e. first line starts at character 0.
395 * In case the given line number is inconsistent, answers -1.
397 public final int getLineStart(int lineNumber) {
398 if (lineEnds == null)
400 if (lineNumber >= lineEnds.length)
405 return initialPosition;
406 return lineEnds[lineNumber - 2] + 1;
407 // next line start one character behind the lineEnd of the previous line
410 public final boolean getNextChar(char testedChar) {
412 //handle the case of unicode.
413 //when a unicode appears then we must use a buffer that holds char
415 //At the end of this method currentCharacter holds the new visited char
416 //and currentPosition points right next after it
417 //Both previous lines are true if the currentCharacter is == to the
419 //On false, no side effect has occured.
420 //ALL getNextChar.... ARE OPTIMIZED COPIES
421 int temp = currentPosition;
423 currentCharacter = source[currentPosition++];
424 // if (((currentCharacter = source[currentPosition++]) == '\\')
425 // && (source[currentPosition] == 'u')) {
426 // //-------------unicode traitement ------------
427 // int c1, c2, c3, c4;
428 // int unicodeSize = 6;
429 // currentPosition++;
430 // while (source[currentPosition] == 'u') {
431 // currentPosition++;
435 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
437 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
439 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
441 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
443 // currentPosition = temp;
447 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
448 // if (currentCharacter != testedChar) {
449 // currentPosition = temp;
452 // unicodeAsBackSlash = currentCharacter == '\\';
454 // //need the unicode buffer
455 // if (withoutUnicodePtr == 0) {
456 // //buffer all the entries that have been left aside....
457 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
461 // withoutUnicodeBuffer,
463 // withoutUnicodePtr);
465 // //fill the buffer with the char
466 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
469 // } //-------------end unicode traitement--------------
471 if (currentCharacter != testedChar) {
472 currentPosition = temp;
475 unicodeAsBackSlash = false;
476 // if (withoutUnicodePtr != 0)
477 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
480 } catch (IndexOutOfBoundsException e) {
481 unicodeAsBackSlash = false;
482 currentPosition = temp;
487 public final int getNextChar(char testedChar1, char testedChar2) {
488 //INT 0 : testChar1 \\\\///\\\\ 1 : testedChar2 \\\\///\\\\ -1 : others
489 //test can be done with (x==0) for the first and (x>0) for the second
490 //handle the case of unicode.
491 //when a unicode appears then we must use a buffer that holds char
493 //At the end of this method currentCharacter holds the new visited char
494 //and currentPosition points right next after it
495 //Both previous lines are true if the currentCharacter is == to the
497 //On false, no side effect has occured.
498 //ALL getNextChar.... ARE OPTIMIZED COPIES
499 int temp = currentPosition;
502 currentCharacter = source[currentPosition++];
503 // if (((currentCharacter = source[currentPosition++]) == '\\')
504 // && (source[currentPosition] == 'u')) {
505 // //-------------unicode traitement ------------
506 // int c1, c2, c3, c4;
507 // int unicodeSize = 6;
508 // currentPosition++;
509 // while (source[currentPosition] == 'u') {
510 // currentPosition++;
514 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
516 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
518 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
520 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
522 // currentPosition = temp;
526 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
527 // if (currentCharacter == testedChar1)
529 // else if (currentCharacter == testedChar2)
532 // currentPosition = temp;
536 // //need the unicode buffer
537 // if (withoutUnicodePtr == 0) {
538 // //buffer all the entries that have been left aside....
539 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
543 // withoutUnicodeBuffer,
545 // withoutUnicodePtr);
547 // //fill the buffer with the char
548 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
550 // } //-------------end unicode traitement--------------
552 if (currentCharacter == testedChar1)
554 else if (currentCharacter == testedChar2)
557 currentPosition = temp;
560 // if (withoutUnicodePtr != 0)
561 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
564 } catch (IndexOutOfBoundsException e) {
565 currentPosition = temp;
570 public final boolean getNextCharAsDigit() {
572 //handle the case of unicode.
573 //when a unicode appears then we must use a buffer that holds char
575 //At the end of this method currentCharacter holds the new visited char
576 //and currentPosition points right next after it
577 //Both previous lines are true if the currentCharacter is a digit
578 //On false, no side effect has occured.
579 //ALL getNextChar.... ARE OPTIMIZED COPIES
580 int temp = currentPosition;
582 currentCharacter = source[currentPosition++];
583 // if (((currentCharacter = source[currentPosition++]) == '\\')
584 // && (source[currentPosition] == 'u')) {
585 // //-------------unicode traitement ------------
586 // int c1, c2, c3, c4;
587 // int unicodeSize = 6;
588 // currentPosition++;
589 // while (source[currentPosition] == 'u') {
590 // currentPosition++;
594 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
596 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
598 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
600 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
602 // currentPosition = temp;
606 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
607 // if (!Character.isDigit(currentCharacter)) {
608 // currentPosition = temp;
612 // //need the unicode buffer
613 // if (withoutUnicodePtr == 0) {
614 // //buffer all the entries that have been left aside....
615 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
619 // withoutUnicodeBuffer,
621 // withoutUnicodePtr);
623 // //fill the buffer with the char
624 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
626 // } //-------------end unicode traitement--------------
628 if (!Character.isDigit(currentCharacter)) {
629 currentPosition = temp;
632 // if (withoutUnicodePtr != 0)
633 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
636 } catch (IndexOutOfBoundsException e) {
637 currentPosition = temp;
642 public final boolean getNextCharAsDigit(int radix) {
644 //handle the case of unicode.
645 //when a unicode appears then we must use a buffer that holds char
647 //At the end of this method currentCharacter holds the new visited char
648 //and currentPosition points right next after it
649 //Both previous lines are true if the currentCharacter is a digit base on
651 //On false, no side effect has occured.
652 //ALL getNextChar.... ARE OPTIMIZED COPIES
653 int temp = currentPosition;
655 currentCharacter = source[currentPosition++];
656 // if (((currentCharacter = source[currentPosition++]) == '\\')
657 // && (source[currentPosition] == 'u')) {
658 // //-------------unicode traitement ------------
659 // int c1, c2, c3, c4;
660 // int unicodeSize = 6;
661 // currentPosition++;
662 // while (source[currentPosition] == 'u') {
663 // currentPosition++;
667 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
669 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
671 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
673 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
675 // currentPosition = temp;
679 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
680 // if (Character.digit(currentCharacter, radix) == -1) {
681 // currentPosition = temp;
685 // //need the unicode buffer
686 // if (withoutUnicodePtr == 0) {
687 // //buffer all the entries that have been left aside....
688 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
692 // withoutUnicodeBuffer,
694 // withoutUnicodePtr);
696 // //fill the buffer with the char
697 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
699 // } //-------------end unicode traitement--------------
701 if (Character.digit(currentCharacter, radix) == -1) {
702 currentPosition = temp;
705 // if (withoutUnicodePtr != 0)
706 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
709 } catch (IndexOutOfBoundsException e) {
710 currentPosition = temp;
715 public boolean getNextCharAsJavaIdentifierPart() {
717 //handle the case of unicode.
718 //when a unicode appears then we must use a buffer that holds char
720 //At the end of this method currentCharacter holds the new visited char
721 //and currentPosition points right next after it
722 //Both previous lines are true if the currentCharacter is a
723 // JavaIdentifierPart
724 //On false, no side effect has occured.
725 //ALL getNextChar.... ARE OPTIMIZED COPIES
726 int temp = currentPosition;
728 currentCharacter = source[currentPosition++];
729 // if (((currentCharacter = source[currentPosition++]) == '\\')
730 // && (source[currentPosition] == 'u')) {
731 // //-------------unicode traitement ------------
732 // int c1, c2, c3, c4;
733 // int unicodeSize = 6;
734 // currentPosition++;
735 // while (source[currentPosition] == 'u') {
736 // currentPosition++;
740 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
742 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
744 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
746 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
748 // currentPosition = temp;
752 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
753 // if (!isPHPIdentifierPart(currentCharacter)) {
754 // currentPosition = temp;
758 // //need the unicode buffer
759 // if (withoutUnicodePtr == 0) {
760 // //buffer all the entries that have been left aside....
761 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
765 // withoutUnicodeBuffer,
767 // withoutUnicodePtr);
769 // //fill the buffer with the char
770 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
772 // } //-------------end unicode traitement--------------
774 if (!isPHPIdentifierPart(currentCharacter)) {
775 currentPosition = temp;
778 // if (withoutUnicodePtr != 0)
779 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
782 } catch (IndexOutOfBoundsException e) {
783 currentPosition = temp;
788 public int getCastOrParen() {
789 int tempPosition = currentPosition;
790 char tempCharacter = currentCharacter;
791 int tempToken = TokenNameLPAREN;
792 boolean found = false;
793 StringBuffer buf = new StringBuffer();
796 currentCharacter = source[currentPosition++];
797 } while (currentCharacter == ' ' || currentCharacter == '\t');
798 while ((currentCharacter >= 'a' && currentCharacter <= 'z') || (currentCharacter >= 'A' && currentCharacter <= 'Z')) {
799 buf.append(currentCharacter);
800 currentCharacter = source[currentPosition++];
802 if (buf.length() >= 3 && buf.length() <= 7) {
803 char[] data = buf.toString().toCharArray();
805 switch (data.length) {
808 if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
810 tempToken = TokenNameintCAST;
815 if ((data[index] == 'b') && (data[++index] == 'o') && (data[++index] == 'o') && (data[++index] == 'l')) {
817 tempToken = TokenNameboolCAST;
820 if ((data[index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'l')) {
822 tempToken = TokenNamedoubleCAST;
828 if ((data[index] == 'a') && (data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a')
829 && (data[++index] == 'y')) {
831 tempToken = TokenNamearrayCAST;
834 if ((data[index] == 'u') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e')
835 && (data[++index] == 't')) {
837 tempToken = TokenNameunsetCAST;
840 if ((data[index] == 'f') && (data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'a')
841 && (data[++index] == 't')) {
843 tempToken = TokenNamedoubleCAST;
849 // object string double
850 if ((data[index] == 'o') && (data[++index] == 'b') && (data[++index] == 'j') && (data[++index] == 'e')
851 && (data[++index] == 'c') && (data[++index] == 't')) {
853 tempToken = TokenNameobjectCAST;
856 if ((data[index] == 's') && (data[++index] == 't') && (data[++index] == 'r') && (data[++index] == 'i')
857 && (data[++index] == 'n') && (data[++index] == 'g')) {
859 tempToken = TokenNamestringCAST;
862 if ((data[index] == 'd') && (data[++index] == 'o') && (data[++index] == 'u') && (data[++index] == 'b')
863 && (data[++index] == 'l') && (data[++index] == 'e')) {
865 tempToken = TokenNamedoubleCAST;
872 if ((data[index] == 'b') && (data[++index] == 'o') && (data[++index] == 'o') && (data[++index] == 'l')
873 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'n')) {
875 tempToken = TokenNameboolCAST;
878 if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e')
879 && (data[++index] == 'g') && (data[++index] == 'e') && (data[++index] == 'r')) {
881 tempToken = TokenNameintCAST;
887 while (currentCharacter == ' ' || currentCharacter == '\t') {
888 currentCharacter = source[currentPosition++];
890 if (currentCharacter == ')') {
895 } catch (IndexOutOfBoundsException e) {
897 currentCharacter = tempCharacter;
898 currentPosition = tempPosition;
899 return TokenNameLPAREN;
902 public void consumeStringInterpolated() throws InvalidInputException {
904 // consume next character
905 unicodeAsBackSlash = false;
906 currentCharacter = source[currentPosition++];
907 // if (((currentCharacter = source[currentPosition++]) == '\\')
908 // && (source[currentPosition] == 'u')) {
909 // getNextUnicodeChar();
911 // if (withoutUnicodePtr != 0) {
912 // withoutUnicodeBuffer[++withoutUnicodePtr] =
916 while (currentCharacter != '`') {
917 /** ** in PHP \r and \n are valid in string literals *** */
918 // if ((currentCharacter == '\n')
919 // || (currentCharacter == '\r')) {
920 // // relocate if finding another quote fairly close: thus unicode
921 // '/u000D' will be fully consumed
922 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
923 // if (currentPosition + lookAhead == source.length)
925 // if (source[currentPosition + lookAhead] == '\n')
927 // if (source[currentPosition + lookAhead] == '\"') {
928 // currentPosition += lookAhead + 1;
932 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
934 if (currentCharacter == '\\') {
935 int escapeSize = currentPosition;
936 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
937 //scanEscapeCharacter make a side effect on this value and we need
938 // the previous value few lines down this one
939 scanDoubleQuotedEscapeCharacter();
940 escapeSize = currentPosition - escapeSize;
941 if (withoutUnicodePtr == 0) {
942 //buffer all the entries that have been left aside....
943 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
944 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
945 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
946 } else { //overwrite the / in the buffer
947 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
948 if (backSlashAsUnicodeInString) { //there are TWO \ in the stream
949 // where only one is correct
954 // consume next character
955 unicodeAsBackSlash = false;
956 currentCharacter = source[currentPosition++];
957 // if (((currentCharacter = source[currentPosition++]) == '\\')
958 // && (source[currentPosition] == 'u')) {
959 // getNextUnicodeChar();
961 if (withoutUnicodePtr != 0) {
962 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
966 } catch (IndexOutOfBoundsException e) {
967 // reset end position for error reporting
968 currentPosition -= 2;
969 throw new InvalidInputException(UNTERMINATED_STRING);
970 } catch (InvalidInputException e) {
971 if (e.getMessage().equals(INVALID_ESCAPE)) {
972 // relocate if finding another quote fairly close: thus unicode
973 // '/u000D' will be fully consumed
974 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
975 if (currentPosition + lookAhead == source.length)
977 if (source[currentPosition + lookAhead] == '\n')
979 if (source[currentPosition + lookAhead] == '`') {
980 currentPosition += lookAhead + 1;
987 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
988 // //$NON-NLS-?$ where ? is an
990 if (currentLine == null) {
991 currentLine = new NLSLine();
992 lines.add(currentLine);
994 currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
998 public void consumeStringConstant() throws InvalidInputException {
1000 // consume next character
1001 unicodeAsBackSlash = false;
1002 currentCharacter = source[currentPosition++];
1003 // if (((currentCharacter = source[currentPosition++]) == '\\')
1004 // && (source[currentPosition] == 'u')) {
1005 // getNextUnicodeChar();
1007 // if (withoutUnicodePtr != 0) {
1008 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1009 // currentCharacter;
1012 while (currentCharacter != '\'') {
1013 /** ** in PHP \r and \n are valid in string literals *** */
1014 // if ((currentCharacter == '\n')
1015 // || (currentCharacter == '\r')) {
1016 // // relocate if finding another quote fairly close: thus unicode
1017 // '/u000D' will be fully consumed
1018 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1019 // if (currentPosition + lookAhead == source.length)
1021 // if (source[currentPosition + lookAhead] == '\n')
1023 // if (source[currentPosition + lookAhead] == '\"') {
1024 // currentPosition += lookAhead + 1;
1028 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1030 if (currentCharacter == '\\') {
1031 int escapeSize = currentPosition;
1032 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1033 //scanEscapeCharacter make a side effect on this value and we need
1034 // the previous value few lines down this one
1035 scanSingleQuotedEscapeCharacter();
1036 escapeSize = currentPosition - escapeSize;
1037 if (withoutUnicodePtr == 0) {
1038 //buffer all the entries that have been left aside....
1039 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1040 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1041 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1042 } else { //overwrite the / in the buffer
1043 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1044 if (backSlashAsUnicodeInString) { //there are TWO \ in the stream
1045 // where only one is correct
1046 withoutUnicodePtr--;
1050 // consume next character
1051 unicodeAsBackSlash = false;
1052 currentCharacter = source[currentPosition++];
1053 // if (((currentCharacter = source[currentPosition++]) == '\\')
1054 // && (source[currentPosition] == 'u')) {
1055 // getNextUnicodeChar();
1057 if (withoutUnicodePtr != 0) {
1058 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1062 } catch (IndexOutOfBoundsException e) {
1063 // reset end position for error reporting
1064 currentPosition -= 2;
1065 throw new InvalidInputException(UNTERMINATED_STRING);
1066 } catch (InvalidInputException e) {
1067 if (e.getMessage().equals(INVALID_ESCAPE)) {
1068 // relocate if finding another quote fairly close: thus unicode
1069 // '/u000D' will be fully consumed
1070 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1071 if (currentPosition + lookAhead == source.length)
1073 if (source[currentPosition + lookAhead] == '\n')
1075 if (source[currentPosition + lookAhead] == '\'') {
1076 currentPosition += lookAhead + 1;
1083 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1084 // //$NON-NLS-?$ where ? is an
1086 if (currentLine == null) {
1087 currentLine = new NLSLine();
1088 lines.add(currentLine);
1090 currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1094 public void consumeStringLiteral() throws InvalidInputException {
1096 // consume next character
1097 unicodeAsBackSlash = false;
1098 currentCharacter = source[currentPosition++];
1099 // if (((currentCharacter = source[currentPosition++]) == '\\')
1100 // && (source[currentPosition] == 'u')) {
1101 // getNextUnicodeChar();
1103 // if (withoutUnicodePtr != 0) {
1104 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1105 // currentCharacter;
1108 while (currentCharacter != '"') {
1109 /** ** in PHP \r and \n are valid in string literals *** */
1110 // if ((currentCharacter == '\n')
1111 // || (currentCharacter == '\r')) {
1112 // // relocate if finding another quote fairly close: thus unicode
1113 // '/u000D' will be fully consumed
1114 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1115 // if (currentPosition + lookAhead == source.length)
1117 // if (source[currentPosition + lookAhead] == '\n')
1119 // if (source[currentPosition + lookAhead] == '\"') {
1120 // currentPosition += lookAhead + 1;
1124 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1126 if (currentCharacter == '\\') {
1127 int escapeSize = currentPosition;
1128 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1129 //scanEscapeCharacter make a side effect on this value and we need
1130 // the previous value few lines down this one
1131 scanDoubleQuotedEscapeCharacter();
1132 escapeSize = currentPosition - escapeSize;
1133 if (withoutUnicodePtr == 0) {
1134 //buffer all the entries that have been left aside....
1135 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1136 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1137 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1138 } else { //overwrite the / in the buffer
1139 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1140 if (backSlashAsUnicodeInString) { //there are TWO \ in the stream
1141 // where only one is correct
1142 withoutUnicodePtr--;
1145 } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1146 if (recordLineSeparator) {
1147 pushLineSeparator();
1150 // consume next character
1151 unicodeAsBackSlash = false;
1152 currentCharacter = source[currentPosition++];
1153 // if (((currentCharacter = source[currentPosition++]) == '\\')
1154 // && (source[currentPosition] == 'u')) {
1155 // getNextUnicodeChar();
1157 if (withoutUnicodePtr != 0) {
1158 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1162 } catch (IndexOutOfBoundsException e) {
1163 // reset end position for error reporting
1164 currentPosition -= 2;
1165 throw new InvalidInputException(UNTERMINATED_STRING);
1166 } catch (InvalidInputException e) {
1167 if (e.getMessage().equals(INVALID_ESCAPE)) {
1168 // relocate if finding another quote fairly close: thus unicode
1169 // '/u000D' will be fully consumed
1170 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1171 if (currentPosition + lookAhead == source.length)
1173 if (source[currentPosition + lookAhead] == '\n')
1175 if (source[currentPosition + lookAhead] == '\"') {
1176 currentPosition += lookAhead + 1;
1183 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1184 // //$NON-NLS-?$ where ? is an
1186 if (currentLine == null) {
1187 currentLine = new NLSLine();
1188 lines.add(currentLine);
1190 currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1194 public int getNextToken() throws InvalidInputException {
1196 return getInlinedHTML(currentPosition);
1199 this.wasAcr = false;
1201 jumpOverMethodBody();
1203 return currentPosition > source.length ? TokenNameEOF : TokenNameRBRACE;
1207 withoutUnicodePtr = 0;
1208 //start with a new token
1209 char encapsedChar = ' ';
1210 if (!encapsedStringStack.isEmpty()) {
1211 encapsedChar = ((Character) encapsedStringStack.peek()).charValue();
1213 if (encapsedChar != '$' && encapsedChar != ' ') {
1214 currentCharacter = source[currentPosition++];
1215 if (currentCharacter == encapsedChar) {
1216 switch (currentCharacter) {
1218 return TokenNameEncapsedString0;
1220 return TokenNameEncapsedString1;
1222 return TokenNameEncapsedString2;
1225 while (currentCharacter != encapsedChar) {
1226 /** ** in PHP \r and \n are valid in string literals *** */
1227 switch (currentCharacter) {
1229 int escapeSize = currentPosition;
1230 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1231 //scanEscapeCharacter make a side effect on this value and
1232 // we need the previous value few lines down this one
1233 scanDoubleQuotedEscapeCharacter();
1234 escapeSize = currentPosition - escapeSize;
1235 if (withoutUnicodePtr == 0) {
1236 //buffer all the entries that have been left aside....
1237 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1238 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1239 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1240 } else { //overwrite the / in the buffer
1241 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1242 if (backSlashAsUnicodeInString) { //there are TWO \ in
1243 withoutUnicodePtr--;
1249 if (recordLineSeparator) {
1250 pushLineSeparator();
1254 if (isPHPIdentifierStart(source[currentPosition]) || source[currentPosition] == '{') {
1256 encapsedStringStack.push(new Character('$'));
1257 return TokenNameSTRING;
1261 if (source[currentPosition] == '$') { // CURLY_OPEN
1263 encapsedStringStack.push(new Character('$'));
1264 return TokenNameSTRING;
1267 // consume next character
1268 unicodeAsBackSlash = false;
1269 currentCharacter = source[currentPosition++];
1270 if (withoutUnicodePtr != 0) {
1271 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1276 return TokenNameSTRING;
1278 // ---------Consume white space and handles startPosition---------
1279 int whiteStart = currentPosition;
1280 startPosition = currentPosition;
1281 currentCharacter = source[currentPosition++];
1282 if (encapsedChar == '$') {
1283 switch (currentCharacter) {
1285 currentCharacter = source[currentPosition++];
1286 return TokenNameSTRING;
1288 if (encapsedChar == '$') {
1289 if (getNextChar('$'))
1290 return TokenNameLBRACE_DOLLAR;
1292 return TokenNameLBRACE;
1294 return TokenNameRBRACE;
1296 return TokenNameLBRACKET;
1298 return TokenNameRBRACKET;
1300 if (tokenizeStrings) {
1301 consumeStringConstant();
1302 return TokenNameStringSingleQuote;
1304 return TokenNameEncapsedString1;
1306 return TokenNameEncapsedString2;
1308 if (tokenizeStrings) {
1309 consumeStringInterpolated();
1310 return TokenNameStringInterpolated;
1312 return TokenNameEncapsedString0;
1314 if (getNextChar('>'))
1315 return TokenNameMINUS_GREATER;
1316 return TokenNameSTRING;
1318 if (currentCharacter == '$') {
1319 int oldPosition = currentPosition;
1321 currentCharacter = source[currentPosition++];
1322 if (currentCharacter == '{') {
1323 return TokenNameDOLLAR_LBRACE;
1325 if (isPHPIdentifierStart(currentCharacter)) {
1326 return scanIdentifierOrKeyword(true);
1328 currentPosition = oldPosition;
1329 return TokenNameSTRING;
1331 } catch (IndexOutOfBoundsException e) {
1332 currentPosition = oldPosition;
1333 return TokenNameSTRING;
1336 if (isPHPIdentifierStart(currentCharacter))
1337 return scanIdentifierOrKeyword(false);
1338 if (Character.isDigit(currentCharacter))
1339 return scanNumber(false);
1340 return TokenNameERROR;
1343 // boolean isWhiteSpace;
1345 while ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) {
1346 startPosition = currentPosition;
1347 currentCharacter = source[currentPosition++];
1348 // if (((currentCharacter = source[currentPosition++]) == '\\')
1349 // && (source[currentPosition] == 'u')) {
1350 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
1352 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1353 checkNonExternalizeString();
1354 if (recordLineSeparator) {
1355 pushLineSeparator();
1360 // isWhiteSpace = (currentCharacter == ' ')
1361 // || Character.isWhitespace(currentCharacter);
1364 if (tokenizeWhiteSpace && (whiteStart != currentPosition - 1)) {
1365 // reposition scanner in case we are interested by spaces as tokens
1367 startPosition = whiteStart;
1368 return TokenNameWHITESPACE;
1370 //little trick to get out in the middle of a source compuation
1371 if (currentPosition > eofPosition)
1372 return TokenNameEOF;
1373 // ---------Identify the next token-------------
1374 switch (currentCharacter) {
1376 return getCastOrParen();
1378 return TokenNameRPAREN;
1380 return TokenNameLBRACE;
1382 return TokenNameRBRACE;
1384 return TokenNameLBRACKET;
1386 return TokenNameRBRACKET;
1388 return TokenNameSEMICOLON;
1390 return TokenNameCOMMA;
1392 if (getNextChar('='))
1393 return TokenNameDOT_EQUAL;
1394 if (getNextCharAsDigit())
1395 return scanNumber(true);
1396 return TokenNameDOT;
1399 if ((test = getNextChar('+', '=')) == 0)
1400 return TokenNamePLUS_PLUS;
1402 return TokenNamePLUS_EQUAL;
1403 return TokenNamePLUS;
1407 if ((test = getNextChar('-', '=')) == 0)
1408 return TokenNameMINUS_MINUS;
1410 return TokenNameMINUS_EQUAL;
1411 if (getNextChar('>'))
1412 return TokenNameMINUS_GREATER;
1413 return TokenNameMINUS;
1416 if (getNextChar('='))
1417 return TokenNameTWIDDLE_EQUAL;
1418 return TokenNameTWIDDLE;
1420 if (getNextChar('=')) {
1421 if (getNextChar('=')) {
1422 return TokenNameNOT_EQUAL_EQUAL;
1424 return TokenNameNOT_EQUAL;
1426 return TokenNameNOT;
1428 if (getNextChar('='))
1429 return TokenNameMULTIPLY_EQUAL;
1430 return TokenNameMULTIPLY;
1432 if (getNextChar('='))
1433 return TokenNameREMAINDER_EQUAL;
1434 return TokenNameREMAINDER;
1436 int oldPosition = currentPosition;
1438 currentCharacter = source[currentPosition++];
1439 } catch (IndexOutOfBoundsException e) {
1440 currentPosition = oldPosition;
1441 return TokenNameLESS;
1443 switch (currentCharacter) {
1445 return TokenNameLESS_EQUAL;
1447 return TokenNameNOT_EQUAL;
1449 if (getNextChar('='))
1450 return TokenNameLEFT_SHIFT_EQUAL;
1451 if (getNextChar('<')) {
1452 currentCharacter = source[currentPosition++];
1453 while (Character.isWhitespace(currentCharacter)) {
1454 currentCharacter = source[currentPosition++];
1456 int heredocStart = currentPosition - 1;
1457 int heredocLength = 0;
1458 if (isPHPIdentifierStart(currentCharacter)) {
1459 currentCharacter = source[currentPosition++];
1461 return TokenNameERROR;
1463 while (isPHPIdentifierPart(currentCharacter)) {
1464 currentCharacter = source[currentPosition++];
1466 heredocLength = currentPosition - heredocStart - 1;
1467 // heredoc end-tag determination
1468 boolean endTag = true;
1471 ch = source[currentPosition++];
1472 if (ch == '\r' || ch == '\n') {
1473 if (recordLineSeparator) {
1474 pushLineSeparator();
1478 for (int i = 0; i < heredocLength; i++) {
1479 if (source[currentPosition + i] != source[heredocStart + i]) {
1485 currentPosition += heredocLength - 1;
1486 currentCharacter = source[currentPosition++];
1487 break; // do...while loop
1493 return TokenNameHEREDOC;
1495 return TokenNameLEFT_SHIFT;
1497 currentPosition = oldPosition;
1498 return TokenNameLESS;
1502 if ((test = getNextChar('=', '>')) == 0)
1503 return TokenNameGREATER_EQUAL;
1505 if ((test = getNextChar('=', '>')) == 0)
1506 return TokenNameRIGHT_SHIFT_EQUAL;
1507 return TokenNameRIGHT_SHIFT;
1509 return TokenNameGREATER;
1512 if (getNextChar('=')) {
1513 if (getNextChar('=')) {
1514 return TokenNameEQUAL_EQUAL_EQUAL;
1516 return TokenNameEQUAL_EQUAL;
1518 if (getNextChar('>'))
1519 return TokenNameEQUAL_GREATER;
1520 return TokenNameEQUAL;
1523 if ((test = getNextChar('&', '=')) == 0)
1524 return TokenNameAND_AND;
1526 return TokenNameAND_EQUAL;
1527 return TokenNameAND;
1531 if ((test = getNextChar('|', '=')) == 0)
1532 return TokenNameOR_OR;
1534 return TokenNameOR_EQUAL;
1538 if (getNextChar('='))
1539 return TokenNameXOR_EQUAL;
1540 return TokenNameXOR;
1542 if (getNextChar('>')) {
1544 if (currentPosition == source.length) {
1546 return TokenNameINLINE_HTML;
1548 return getInlinedHTML(currentPosition - 2);
1550 return TokenNameQUESTION;
1552 if (getNextChar(':'))
1553 return TokenNamePAAMAYIM_NEKUDOTAYIM;
1554 return TokenNameCOLON;
1558 consumeStringConstant();
1559 return TokenNameStringSingleQuote;
1561 if (tokenizeStrings) {
1562 consumeStringLiteral();
1563 return TokenNameStringDoubleQuote;
1565 return TokenNameEncapsedString2;
1567 if (tokenizeStrings) {
1568 consumeStringInterpolated();
1569 return TokenNameStringInterpolated;
1571 return TokenNameEncapsedString0;
1574 char startChar = currentCharacter;
1575 if (getNextChar('=') && startChar == '/') {
1576 return TokenNameDIVIDE_EQUAL;
1579 if ((startChar == '#') || (test = getNextChar('/', '*')) == 0) {
1581 this.lastCommentLinePosition = this.currentPosition;
1582 int endPositionForLineComment = 0;
1583 try { //get the next char
1584 currentCharacter = source[currentPosition++];
1585 // if (((currentCharacter = source[currentPosition++])
1587 // && (source[currentPosition] == 'u')) {
1588 // //-------------unicode traitement ------------
1589 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1590 // currentPosition++;
1591 // while (source[currentPosition] == 'u') {
1592 // currentPosition++;
1595 // Character.getNumericValue(source[currentPosition++]))
1599 // Character.getNumericValue(source[currentPosition++]))
1603 // Character.getNumericValue(source[currentPosition++]))
1607 // Character.getNumericValue(source[currentPosition++]))
1611 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1613 // currentCharacter =
1614 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1617 //handle the \\u case manually into comment
1618 // if (currentCharacter == '\\') {
1619 // if (source[currentPosition] == '\\')
1620 // currentPosition++;
1621 // } //jump over the \\
1622 boolean isUnicode = false;
1623 while (currentCharacter != '\r' && currentCharacter != '\n') {
1624 this.lastCommentLinePosition = this.currentPosition;
1625 if (currentCharacter == '?') {
1626 if (getNextChar('>')) {
1627 startPosition = currentPosition - 2;
1629 return TokenNameINLINE_HTML;
1634 currentCharacter = source[currentPosition++];
1635 // if (((currentCharacter = source[currentPosition++])
1637 // && (source[currentPosition] == 'u')) {
1638 // isUnicode = true;
1639 // //-------------unicode traitement ------------
1640 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1641 // currentPosition++;
1642 // while (source[currentPosition] == 'u') {
1643 // currentPosition++;
1646 // Character.getNumericValue(source[currentPosition++]))
1650 // Character.getNumericValue(
1651 // source[currentPosition++]))
1655 // Character.getNumericValue(
1656 // source[currentPosition++]))
1660 // Character.getNumericValue(
1661 // source[currentPosition++]))
1665 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1667 // currentCharacter =
1668 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1671 //handle the \\u case manually into comment
1672 // if (currentCharacter == '\\') {
1673 // if (source[currentPosition] == '\\')
1674 // currentPosition++;
1675 // } //jump over the \\
1678 endPositionForLineComment = currentPosition - 6;
1680 endPositionForLineComment = currentPosition - 1;
1682 // recordComment(false);
1683 recordComment(TokenNameCOMMENT_LINE);
1684 if (this.taskTags != null)
1685 checkTaskTag(this.startPosition, this.currentPosition);
1686 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1687 checkNonExternalizeString();
1688 if (recordLineSeparator) {
1690 pushUnicodeLineSeparator();
1692 pushLineSeparator();
1698 if (tokenizeComments) {
1700 currentPosition = endPositionForLineComment;
1701 // reset one character behind
1703 return TokenNameCOMMENT_LINE;
1705 } catch (IndexOutOfBoundsException e) { //an eof will them
1707 if (tokenizeComments) {
1709 // reset one character behind
1710 return TokenNameCOMMENT_LINE;
1716 //traditional and annotation comment
1717 boolean isJavadoc = false, star = false;
1718 // consume next character
1719 unicodeAsBackSlash = false;
1720 currentCharacter = source[currentPosition++];
1721 // if (((currentCharacter = source[currentPosition++]) ==
1723 // && (source[currentPosition] == 'u')) {
1724 // getNextUnicodeChar();
1726 // if (withoutUnicodePtr != 0) {
1727 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1728 // currentCharacter;
1731 if (currentCharacter == '*') {
1735 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1736 checkNonExternalizeString();
1737 if (recordLineSeparator) {
1738 pushLineSeparator();
1743 try { //get the next char
1744 currentCharacter = source[currentPosition++];
1745 // if (((currentCharacter = source[currentPosition++])
1747 // && (source[currentPosition] == 'u')) {
1748 // //-------------unicode traitement ------------
1749 // getNextUnicodeChar();
1751 //handle the \\u case manually into comment
1752 // if (currentCharacter == '\\') {
1753 // if (source[currentPosition] == '\\')
1754 // currentPosition++;
1755 // //jump over the \\
1757 // empty comment is not a javadoc /**/
1758 if (currentCharacter == '/') {
1761 //loop until end of comment */
1762 while ((currentCharacter != '/') || (!star)) {
1763 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1764 checkNonExternalizeString();
1765 if (recordLineSeparator) {
1766 pushLineSeparator();
1771 star = currentCharacter == '*';
1773 currentCharacter = source[currentPosition++];
1774 // if (((currentCharacter = source[currentPosition++])
1776 // && (source[currentPosition] == 'u')) {
1777 // //-------------unicode traitement ------------
1778 // getNextUnicodeChar();
1780 //handle the \\u case manually into comment
1781 // if (currentCharacter == '\\') {
1782 // if (source[currentPosition] == '\\')
1783 // currentPosition++;
1784 // } //jump over the \\
1786 //recordComment(isJavadoc);
1788 recordComment(TokenNameCOMMENT_PHPDOC);
1790 recordComment(TokenNameCOMMENT_BLOCK);
1793 if (tokenizeComments) {
1795 return TokenNameCOMMENT_PHPDOC;
1796 return TokenNameCOMMENT_BLOCK;
1799 if (this.taskTags != null) {
1800 checkTaskTag(this.startPosition, this.currentPosition);
1802 } catch (IndexOutOfBoundsException e) {
1803 // reset end position for error reporting
1804 currentPosition -= 2;
1805 throw new InvalidInputException(UNTERMINATED_COMMENT);
1809 return TokenNameDIVIDE;
1813 return TokenNameEOF;
1814 //the atEnd may not be <currentPosition == source.length> if
1815 // source is only some part of a real (external) stream
1816 throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$
1818 if (currentCharacter == '$') {
1819 int oldPosition = currentPosition;
1821 currentCharacter = source[currentPosition++];
1822 if (isPHPIdentifierStart(currentCharacter)) {
1823 return scanIdentifierOrKeyword(true);
1825 currentPosition = oldPosition;
1826 return TokenNameDOLLAR;
1828 } catch (IndexOutOfBoundsException e) {
1829 currentPosition = oldPosition;
1830 return TokenNameDOLLAR;
1833 if (isPHPIdentifierStart(currentCharacter))
1834 return scanIdentifierOrKeyword(false);
1835 if (Character.isDigit(currentCharacter))
1836 return scanNumber(false);
1837 return TokenNameERROR;
1840 } //-----------------end switch while try--------------------
1841 catch (IndexOutOfBoundsException e) {
1844 return TokenNameEOF;
1847 private int getInlinedHTML(int start) throws InvalidInputException {
1848 int token = getInlinedHTMLToken(start);
1849 if (token == TokenNameINLINE_HTML) {
1850 // Stack stack = new Stack();
1851 // // scan html for errors
1852 // Source inlinedHTMLSource = new Source(new String(source, startPosition, currentPosition - startPosition));
1853 // int lastPHPEndPos=0;
1854 // for (Iterator i=inlinedHTMLSource.getNextTagIterator(0); i.hasNext();) {
1855 // Tag tag=(Tag)i.next();
1857 // if (tag instanceof StartTag) {
1858 // StartTag startTag=(StartTag)tag;
1859 // // System.out.println("startTag: "+tag);
1860 // if (startTag.isServerTag()) {
1861 // // TODO : what to do with a server tag ?
1863 // // do whatever with HTML start tag
1864 // // use startTag.getElement() to find the element corresponding
1865 // // to this start tag which may be useful if you implement code
1867 // stack.push(startTag);
1870 // EndTag endTag=(EndTag)tag;
1871 // StartTag stag = (StartTag) stack.peek();
1872 //// System.out.println("endTag: "+tag);
1873 // // do whatever with HTML end tag.
1882 * @throws InvalidInputException
1884 private int getInlinedHTMLToken(int start) throws InvalidInputException {
1885 if (currentPosition > source.length) {
1886 currentPosition = source.length;
1887 return TokenNameEOF;
1889 startPosition = start;
1892 currentCharacter = source[currentPosition++];
1893 if (currentCharacter == '<') {
1894 if (getNextChar('?')) {
1895 currentCharacter = source[currentPosition++];
1896 if ((currentCharacter != 'P') && (currentCharacter != 'p')) {
1898 // (currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) {
1900 if (ignorePHPOneLiner) {
1901 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1903 return TokenNameINLINE_HTML;
1907 return TokenNameINLINE_HTML;
1910 // boolean phpStart = (currentCharacter == 'P') || (currentCharacter == 'p');
1912 int test = getNextChar('H', 'h');
1914 test = getNextChar('P', 'p');
1917 if (ignorePHPOneLiner) {
1918 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1920 return TokenNameINLINE_HTML;
1924 return TokenNameINLINE_HTML;
1932 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1933 if (recordLineSeparator) {
1934 pushLineSeparator();
1939 } //-----------------while--------------------
1941 return TokenNameINLINE_HTML;
1942 } //-----------------try--------------------
1943 catch (IndexOutOfBoundsException e) {
1944 startPosition = start;
1948 return TokenNameINLINE_HTML;
1954 private int lookAheadLinePHPTag() {
1955 // check if the PHP is only in this line (for CodeFormatter)
1956 int currentPositionInLine = currentPosition;
1957 char previousCharInLine = ' ';
1958 char currentCharInLine = ' ';
1959 boolean singleQuotedStringActive = false;
1960 boolean doubleQuotedStringActive = false;
1963 // look ahead in this line
1965 previousCharInLine = currentCharInLine;
1966 currentCharInLine = source[currentPositionInLine++];
1967 switch (currentCharInLine) {
1969 if (previousCharInLine == '?') {
1970 // update the scanner's current Position in the source
1971 currentPosition = currentPositionInLine;
1972 // use as "dummy" token
1973 return TokenNameEOF;
1977 if (doubleQuotedStringActive) {
1978 if (previousCharInLine != '\\') {
1979 doubleQuotedStringActive = false;
1982 if (!singleQuotedStringActive) {
1983 doubleQuotedStringActive = true;
1988 if (singleQuotedStringActive) {
1989 if (previousCharInLine != '\\') {
1990 singleQuotedStringActive = false;
1993 if (!doubleQuotedStringActive) {
1994 singleQuotedStringActive = true;
2000 return TokenNameINLINE_HTML;
2002 if (!singleQuotedStringActive && !doubleQuotedStringActive) {
2004 return TokenNameINLINE_HTML;
2008 if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
2010 return TokenNameINLINE_HTML;
2014 if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
2016 return TokenNameINLINE_HTML;
2021 } catch (IndexOutOfBoundsException e) {
2023 currentPosition = currentPositionInLine;
2024 return TokenNameINLINE_HTML;
2028 // public final void getNextUnicodeChar()
2029 // throws IndexOutOfBoundsException, InvalidInputException {
2031 // //handle the case of unicode.
2032 // //when a unicode appears then we must use a buffer that holds char
2034 // //At the end of this method currentCharacter holds the new visited char
2035 // //and currentPosition points right next after it
2037 // //ALL getNextChar.... ARE OPTIMIZED COPIES
2039 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
2040 // currentPosition++;
2041 // while (source[currentPosition] == 'u') {
2042 // currentPosition++;
2046 // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2048 // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
2050 // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
2052 // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
2054 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2056 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2057 // //need the unicode buffer
2058 // if (withoutUnicodePtr == 0) {
2059 // //buffer all the entries that have been left aside....
2060 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
2061 // System.arraycopy(
2064 // withoutUnicodeBuffer,
2066 // withoutUnicodePtr);
2068 // //fill the buffer with the char
2069 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2071 // unicodeAsBackSlash = currentCharacter == '\\';
2074 * Tokenize a method body, assuming that curly brackets are properly balanced.
2076 public final void jumpOverMethodBody() {
2077 this.wasAcr = false;
2080 while (true) { //loop for jumping over comments
2081 // ---------Consume white space and handles startPosition---------
2082 boolean isWhiteSpace;
2084 startPosition = currentPosition;
2085 currentCharacter = source[currentPosition++];
2086 // if (((currentCharacter = source[currentPosition++]) == '\\')
2087 // && (source[currentPosition] == 'u')) {
2088 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
2090 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2091 pushLineSeparator();
2092 isWhiteSpace = Character.isWhitespace(currentCharacter);
2094 } while (isWhiteSpace);
2095 // -------consume token until } is found---------
2096 switch (currentCharacter) {
2107 test = getNextChar('\\');
2110 scanDoubleQuotedEscapeCharacter();
2111 } catch (InvalidInputException ex) {
2115 // try { // consume next character
2116 unicodeAsBackSlash = false;
2117 currentCharacter = source[currentPosition++];
2118 // if (((currentCharacter = source[currentPosition++]) == '\\')
2119 // && (source[currentPosition] == 'u')) {
2120 // getNextUnicodeChar();
2122 if (withoutUnicodePtr != 0) {
2123 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2126 // } catch (InvalidInputException ex) {
2134 // try { // consume next character
2135 unicodeAsBackSlash = false;
2136 currentCharacter = source[currentPosition++];
2137 // if (((currentCharacter = source[currentPosition++]) == '\\')
2138 // && (source[currentPosition] == 'u')) {
2139 // getNextUnicodeChar();
2141 if (withoutUnicodePtr != 0) {
2142 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2145 // } catch (InvalidInputException ex) {
2147 while (currentCharacter != '"') {
2148 if (currentCharacter == '\r') {
2149 if (source[currentPosition] == '\n')
2152 // the string cannot go further that the line
2154 if (currentCharacter == '\n') {
2156 // the string cannot go further that the line
2158 if (currentCharacter == '\\') {
2160 scanDoubleQuotedEscapeCharacter();
2161 } catch (InvalidInputException ex) {
2165 // try { // consume next character
2166 unicodeAsBackSlash = false;
2167 currentCharacter = source[currentPosition++];
2168 // if (((currentCharacter = source[currentPosition++]) == '\\')
2169 // && (source[currentPosition] == 'u')) {
2170 // getNextUnicodeChar();
2172 if (withoutUnicodePtr != 0) {
2173 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2176 // } catch (InvalidInputException ex) {
2179 } catch (IndexOutOfBoundsException e) {
2185 if ((test = getNextChar('/', '*')) == 0) {
2189 currentCharacter = source[currentPosition++];
2190 // if (((currentCharacter = source[currentPosition++]) ==
2192 // && (source[currentPosition] == 'u')) {
2193 // //-------------unicode traitement ------------
2194 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2195 // currentPosition++;
2196 // while (source[currentPosition] == 'u') {
2197 // currentPosition++;
2200 // Character.getNumericValue(source[currentPosition++]))
2204 // Character.getNumericValue(source[currentPosition++]))
2208 // Character.getNumericValue(source[currentPosition++]))
2212 // Character.getNumericValue(source[currentPosition++]))
2215 // //error don't care of the value
2216 // currentCharacter = 'A';
2217 // } //something different from \n and \r
2219 // currentCharacter =
2220 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2223 while (currentCharacter != '\r' && currentCharacter != '\n') {
2225 currentCharacter = source[currentPosition++];
2226 // if (((currentCharacter = source[currentPosition++])
2228 // && (source[currentPosition] == 'u')) {
2229 // //-------------unicode traitement ------------
2230 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2231 // currentPosition++;
2232 // while (source[currentPosition] == 'u') {
2233 // currentPosition++;
2236 // Character.getNumericValue(source[currentPosition++]))
2240 // Character.getNumericValue(source[currentPosition++]))
2244 // Character.getNumericValue(source[currentPosition++]))
2248 // Character.getNumericValue(source[currentPosition++]))
2251 // //error don't care of the value
2252 // currentCharacter = 'A';
2253 // } //something different from \n and \r
2255 // currentCharacter =
2256 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2260 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2261 pushLineSeparator();
2262 } catch (IndexOutOfBoundsException e) {
2263 } //an eof will them be generated
2267 //traditional and annotation comment
2268 boolean star = false;
2269 // try { // consume next character
2270 unicodeAsBackSlash = false;
2271 currentCharacter = source[currentPosition++];
2272 // if (((currentCharacter = source[currentPosition++]) == '\\')
2273 // && (source[currentPosition] == 'u')) {
2274 // getNextUnicodeChar();
2276 if (withoutUnicodePtr != 0) {
2277 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2280 // } catch (InvalidInputException ex) {
2282 if (currentCharacter == '*') {
2285 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2286 pushLineSeparator();
2287 try { //get the next char
2288 currentCharacter = source[currentPosition++];
2289 // if (((currentCharacter = source[currentPosition++]) ==
2291 // && (source[currentPosition] == 'u')) {
2292 // //-------------unicode traitement ------------
2293 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2294 // currentPosition++;
2295 // while (source[currentPosition] == 'u') {
2296 // currentPosition++;
2299 // Character.getNumericValue(source[currentPosition++]))
2303 // Character.getNumericValue(source[currentPosition++]))
2307 // Character.getNumericValue(source[currentPosition++]))
2311 // Character.getNumericValue(source[currentPosition++]))
2314 // //error don't care of the value
2315 // currentCharacter = 'A';
2316 // } //something different from * and /
2318 // currentCharacter =
2319 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2322 //loop until end of comment */
2323 while ((currentCharacter != '/') || (!star)) {
2324 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2325 pushLineSeparator();
2326 star = currentCharacter == '*';
2328 currentCharacter = source[currentPosition++];
2329 // if (((currentCharacter = source[currentPosition++])
2331 // && (source[currentPosition] == 'u')) {
2332 // //-------------unicode traitement ------------
2333 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2334 // currentPosition++;
2335 // while (source[currentPosition] == 'u') {
2336 // currentPosition++;
2339 // Character.getNumericValue(source[currentPosition++]))
2343 // Character.getNumericValue(source[currentPosition++]))
2347 // Character.getNumericValue(source[currentPosition++]))
2351 // Character.getNumericValue(source[currentPosition++]))
2354 // //error don't care of the value
2355 // currentCharacter = 'A';
2356 // } //something different from * and /
2358 // currentCharacter =
2359 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2363 } catch (IndexOutOfBoundsException e) {
2371 if (isPHPIdentifierStart(currentCharacter) || currentCharacter == '$') {
2373 scanIdentifierOrKeyword((currentCharacter == '$'));
2374 } catch (InvalidInputException ex) {
2379 if (Character.isDigit(currentCharacter)) {
2382 } catch (InvalidInputException ex) {
2389 //-----------------end switch while try--------------------
2390 } catch (IndexOutOfBoundsException e) {
2391 } catch (InvalidInputException e) {
2396 // public final boolean jumpOverUnicodeWhiteSpace()
2397 // throws InvalidInputException {
2399 // //handle the case of unicode. Jump over the next whiteSpace
2400 // //making startPosition pointing on the next available char
2401 // //On false, the currentCharacter is filled up with a potential
2405 // this.wasAcr = false;
2406 // int c1, c2, c3, c4;
2407 // int unicodeSize = 6;
2408 // currentPosition++;
2409 // while (source[currentPosition] == 'u') {
2410 // currentPosition++;
2414 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2416 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2418 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2420 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2422 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2425 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2426 // if (recordLineSeparator
2427 // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2428 // pushLineSeparator();
2429 // if (Character.isWhitespace(currentCharacter))
2432 // //buffer the new char which is not a white space
2433 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2434 // //withoutUnicodePtr == 1 is true here
2436 // } catch (IndexOutOfBoundsException e) {
2437 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2440 public final int[] getLineEnds() {
2441 //return a bounded copy of this.lineEnds
2443 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0, linePtr + 1);
2447 public char[] getSource() {
2451 public static boolean isIdentifierOrKeyword(int token) {
2452 return (token == TokenNameIdentifier) || (token > TokenNameKEYWORD);
2455 final char[] optimizedCurrentTokenSource1() {
2456 //return always the same char[] build only once
2457 //optimization at no speed cost of 99.5 % of the singleCharIdentifier
2458 char charOne = source[startPosition];
2513 return new char[] { charOne };
2517 final char[] optimizedCurrentTokenSource2() {
2519 c0 = source[startPosition];
2520 c1 = source[startPosition + 1];
2522 //return always the same char[] build only once
2523 //optimization at no speed cost of 99.5 % of the singleCharIdentifier
2526 return charArray_va;
2528 return charArray_vb;
2530 return charArray_vc;
2532 return charArray_vd;
2534 return charArray_ve;
2536 return charArray_vf;
2538 return charArray_vg;
2540 return charArray_vh;
2542 return charArray_vi;
2544 return charArray_vj;
2546 return charArray_vk;
2548 return charArray_vl;
2550 return charArray_vm;
2552 return charArray_vn;
2554 return charArray_vo;
2556 return charArray_vp;
2558 return charArray_vq;
2560 return charArray_vr;
2562 return charArray_vs;
2564 return charArray_vt;
2566 return charArray_vu;
2568 return charArray_vv;
2570 return charArray_vw;
2572 return charArray_vx;
2574 return charArray_vy;
2576 return charArray_vz;
2579 //try to return the same char[] build only once
2580 int hash = ((c0 << 6) + c1) % TableSize;
2581 char[][] table = charArray_length[0][hash];
2583 while (++i < InternalTableSize) {
2584 char[] charArray = table[i];
2585 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2588 //---------other side---------
2590 int max = newEntry2;
2591 while (++i <= max) {
2592 char[] charArray = table[i];
2593 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2596 //--------add the entry-------
2597 if (++max >= InternalTableSize)
2600 table[max] = (r = new char[] { c0, c1 });
2605 final char[] optimizedCurrentTokenSource3() {
2606 //try to return the same char[] build only once
2608 int hash = (((c0 = source[startPosition]) << 12) + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2610 char[][] table = charArray_length[1][hash];
2612 while (++i < InternalTableSize) {
2613 char[] charArray = table[i];
2614 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2617 //---------other side---------
2619 int max = newEntry3;
2620 while (++i <= max) {
2621 char[] charArray = table[i];
2622 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2625 //--------add the entry-------
2626 if (++max >= InternalTableSize)
2629 table[max] = (r = new char[] { c0, c1, c2 });
2634 final char[] optimizedCurrentTokenSource4() {
2635 //try to return the same char[] build only once
2636 char c0, c1, c2, c3;
2637 long hash = ((((long) (c0 = source[startPosition])) << 18) + ((c1 = source[startPosition + 1]) << 12)
2638 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2640 char[][] table = charArray_length[2][(int) hash];
2642 while (++i < InternalTableSize) {
2643 char[] charArray = table[i];
2644 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2647 //---------other side---------
2649 int max = newEntry4;
2650 while (++i <= max) {
2651 char[] charArray = table[i];
2652 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2655 //--------add the entry-------
2656 if (++max >= InternalTableSize)
2659 table[max] = (r = new char[] { c0, c1, c2, c3 });
2664 final char[] optimizedCurrentTokenSource5() {
2665 //try to return the same char[] build only once
2666 char c0, c1, c2, c3, c4;
2667 long hash = ((((long) (c0 = source[startPosition])) << 24) + (((long) (c1 = source[startPosition + 1])) << 18)
2668 + ((c2 = source[startPosition + 2]) << 12) + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2670 char[][] table = charArray_length[3][(int) hash];
2672 while (++i < InternalTableSize) {
2673 char[] charArray = table[i];
2674 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2677 //---------other side---------
2679 int max = newEntry5;
2680 while (++i <= max) {
2681 char[] charArray = table[i];
2682 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2685 //--------add the entry-------
2686 if (++max >= InternalTableSize)
2689 table[max] = (r = new char[] { c0, c1, c2, c3, c4 });
2694 final char[] optimizedCurrentTokenSource6() {
2695 //try to return the same char[] build only once
2696 char c0, c1, c2, c3, c4, c5;
2697 long hash = ((((long) (c0 = source[startPosition])) << 32) + (((long) (c1 = source[startPosition + 1])) << 24)
2698 + (((long) (c2 = source[startPosition + 2])) << 18) + ((c3 = source[startPosition + 3]) << 12)
2699 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2701 char[][] table = charArray_length[4][(int) hash];
2703 while (++i < InternalTableSize) {
2704 char[] charArray = table[i];
2705 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2706 && (c5 == charArray[5]))
2709 //---------other side---------
2711 int max = newEntry6;
2712 while (++i <= max) {
2713 char[] charArray = table[i];
2714 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2715 && (c5 == charArray[5]))
2718 //--------add the entry-------
2719 if (++max >= InternalTableSize)
2722 table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 });
2727 public final void pushLineSeparator() throws InvalidInputException {
2728 //see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2729 final int INCREMENT = 250;
2730 if (this.checkNonExternalizedStringLiterals) {
2731 // reinitialize the current line for non externalize strings purpose
2734 //currentCharacter is at position currentPosition-1
2736 if (currentCharacter == '\r') {
2737 int separatorPos = currentPosition - 1;
2738 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2740 //System.out.println("CR-" + separatorPos);
2742 lineEnds[++linePtr] = separatorPos;
2743 } catch (IndexOutOfBoundsException e) {
2744 //linePtr value is correct
2745 int oldLength = lineEnds.length;
2746 int[] old = lineEnds;
2747 lineEnds = new int[oldLength + INCREMENT];
2748 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2749 lineEnds[linePtr] = separatorPos;
2751 // look-ahead for merged cr+lf
2753 if (source[currentPosition] == '\n') {
2754 //System.out.println("look-ahead LF-" + currentPosition);
2755 lineEnds[linePtr] = currentPosition;
2761 } catch (IndexOutOfBoundsException e) {
2766 if (currentCharacter == '\n') {
2767 //must merge eventual cr followed by lf
2768 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2769 //System.out.println("merge LF-" + (currentPosition - 1));
2770 lineEnds[linePtr] = currentPosition - 1;
2772 int separatorPos = currentPosition - 1;
2773 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2775 // System.out.println("LF-" + separatorPos);
2777 lineEnds[++linePtr] = separatorPos;
2778 } catch (IndexOutOfBoundsException e) {
2779 //linePtr value is correct
2780 int oldLength = lineEnds.length;
2781 int[] old = lineEnds;
2782 lineEnds = new int[oldLength + INCREMENT];
2783 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2784 lineEnds[linePtr] = separatorPos;
2792 public final void pushUnicodeLineSeparator() {
2793 // isUnicode means that the \r or \n has been read as a unicode character
2794 //see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2795 final int INCREMENT = 250;
2796 //currentCharacter is at position currentPosition-1
2797 if (this.checkNonExternalizedStringLiterals) {
2798 // reinitialize the current line for non externalize strings purpose
2802 if (currentCharacter == '\r') {
2803 int separatorPos = currentPosition - 6;
2804 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2806 //System.out.println("CR-" + separatorPos);
2808 lineEnds[++linePtr] = separatorPos;
2809 } catch (IndexOutOfBoundsException e) {
2810 //linePtr value is correct
2811 int oldLength = lineEnds.length;
2812 int[] old = lineEnds;
2813 lineEnds = new int[oldLength + INCREMENT];
2814 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2815 lineEnds[linePtr] = separatorPos;
2817 // look-ahead for merged cr+lf
2818 if (source[currentPosition] == '\n') {
2819 //System.out.println("look-ahead LF-" + currentPosition);
2820 lineEnds[linePtr] = currentPosition;
2828 if (currentCharacter == '\n') {
2829 //must merge eventual cr followed by lf
2830 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2831 //System.out.println("merge LF-" + (currentPosition - 1));
2832 lineEnds[linePtr] = currentPosition - 6;
2834 int separatorPos = currentPosition - 6;
2835 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2837 // System.out.println("LF-" + separatorPos);
2839 lineEnds[++linePtr] = separatorPos;
2840 } catch (IndexOutOfBoundsException e) {
2841 //linePtr value is correct
2842 int oldLength = lineEnds.length;
2843 int[] old = lineEnds;
2844 lineEnds = new int[oldLength + INCREMENT];
2845 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2846 lineEnds[linePtr] = separatorPos;
2854 public void recordComment(int token) {
2856 int stopPosition = this.currentPosition;
2858 case TokenNameCOMMENT_LINE:
2859 stopPosition = -this.lastCommentLinePosition;
2861 case TokenNameCOMMENT_BLOCK:
2862 stopPosition = -this.currentPosition;
2866 // a new comment is recorded
2867 int length = this.commentStops.length;
2868 if (++this.commentPtr >= length) {
2869 System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length);
2870 //grows the positions buffers too
2871 System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length);
2873 this.commentStops[this.commentPtr] = stopPosition;
2874 this.commentStarts[this.commentPtr] = this.startPosition;
2877 // public final void recordComment(boolean isJavadoc) {
2878 // // a new annotation comment is recorded
2880 // commentStops[++commentPtr] = isJavadoc
2881 // ? currentPosition
2882 // : -currentPosition;
2883 // } catch (IndexOutOfBoundsException e) {
2884 // int oldStackLength = commentStops.length;
2885 // int[] oldStack = commentStops;
2886 // commentStops = new int[oldStackLength + 30];
2887 // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
2888 // commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition;
2889 // //grows the positions buffers too
2890 // int[] old = commentStarts;
2891 // commentStarts = new int[oldStackLength + 30];
2892 // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
2894 // //the buffer is of a correct size here
2895 // commentStarts[commentPtr] = startPosition;
2897 public void resetTo(int begin, int end) {
2898 //reset the scanner to a given position where it may rescan again
2900 initialPosition = startPosition = currentPosition = begin;
2901 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
2902 commentPtr = -1; // reset comment stack
2905 public final void scanSingleQuotedEscapeCharacter() throws InvalidInputException {
2906 // the string with "\\u" is a legal string of two chars \ and u
2907 //thus we use a direct access to the source (for regular cases).
2908 // if (unicodeAsBackSlash) {
2909 // // consume next character
2910 // unicodeAsBackSlash = false;
2911 // if (((currentCharacter = source[currentPosition++]) == '\\')
2912 // && (source[currentPosition] == 'u')) {
2913 // getNextUnicodeChar();
2915 // if (withoutUnicodePtr != 0) {
2916 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2920 currentCharacter = source[currentPosition++];
2921 switch (currentCharacter) {
2923 currentCharacter = '\'';
2926 currentCharacter = '\\';
2929 currentCharacter = '\\';
2934 public final void scanDoubleQuotedEscapeCharacter() throws InvalidInputException {
2935 // the string with "\\u" is a legal string of two chars \ and u
2936 //thus we use a direct access to the source (for regular cases).
2937 // if (unicodeAsBackSlash) {
2938 // // consume next character
2939 // unicodeAsBackSlash = false;
2940 // if (((currentCharacter = source[currentPosition++]) == '\\')
2941 // && (source[currentPosition] == 'u')) {
2942 // getNextUnicodeChar();
2944 // if (withoutUnicodePtr != 0) {
2945 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2949 currentCharacter = source[currentPosition++];
2950 switch (currentCharacter) {
2952 // currentCharacter = '\b';
2955 currentCharacter = '\t';
2958 currentCharacter = '\n';
2961 // currentCharacter = '\f';
2964 currentCharacter = '\r';
2967 currentCharacter = '\"';
2970 currentCharacter = '\'';
2973 currentCharacter = '\\';
2976 currentCharacter = '$';
2979 // -----------octal escape--------------
2981 // OctalDigit OctalDigit
2982 // ZeroToThree OctalDigit OctalDigit
2983 int number = Character.getNumericValue(currentCharacter);
2984 if (number >= 0 && number <= 7) {
2985 boolean zeroToThreeNot = number > 3;
2986 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2987 int digit = Character.getNumericValue(currentCharacter);
2988 if (digit >= 0 && digit <= 7) {
2989 number = (number * 8) + digit;
2990 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2991 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
2992 // Digit --> ignore last character
2995 digit = Character.getNumericValue(currentCharacter);
2996 if (digit >= 0 && digit <= 7) {
2997 // has read \ZeroToThree OctalDigit OctalDigit
2998 number = (number * 8) + digit;
2999 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
3000 // --> ignore last character
3004 } else { // has read \OctalDigit NonDigit--> ignore last
3008 } else { // has read \OctalDigit NonOctalDigit--> ignore last
3012 } else { // has read \OctalDigit --> ignore last character
3016 throw new InvalidInputException(INVALID_ESCAPE);
3017 currentCharacter = (char) number;
3020 // throw new InvalidInputException(INVALID_ESCAPE);
3024 // public int scanIdentifierOrKeyword() throws InvalidInputException {
3025 // return scanIdentifierOrKeyword( false );
3027 public int scanIdentifierOrKeyword(boolean isVariable) throws InvalidInputException {
3029 //first dispatch on the first char.
3030 //then the length. If there are several
3031 //keywors with the same length AND the same first char, then do another
3032 //disptach on the second char :-)...cool....but fast !
3033 useAssertAsAnIndentifier = false;
3034 while (getNextCharAsJavaIdentifierPart()) {
3038 // if (new String(getCurrentTokenSource()).equals("$this")) {
3039 // return TokenNamethis;
3041 return TokenNameVariable;
3046 // if (withoutUnicodePtr == 0)
3047 //quick test on length == 1 but not on length > 12 while most identifier
3048 //have a length which is <= 12...but there are lots of identifier with
3051 if ((length = currentPosition - startPosition) == 1)
3052 return TokenNameIdentifier;
3054 data = new char[length];
3055 index = startPosition;
3056 for (int i = 0; i < length; i++) {
3057 data[i] = Character.toLowerCase(source[index + i]);
3061 // if ((length = withoutUnicodePtr) == 1)
3062 // return TokenNameIdentifier;
3063 // // data = withoutUnicodeBuffer;
3064 // data = new char[withoutUnicodeBuffer.length];
3065 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
3066 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
3070 firstLetter = data[index];
3071 switch (firstLetter) {
3076 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'i') && (data[++index] == 'l')
3077 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3078 return TokenNameFILE;
3079 index = 0; //__LINE__
3080 if ((data[++index] == '_') && (data[++index] == 'l') && (data[++index] == 'i') && (data[++index] == 'n')
3081 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3082 return TokenNameLINE;
3086 if ((data[++index] == '_') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3087 && (data[++index] == 's') && (data[++index] == 's') && (data[++index] == '_') && (data[++index] == '_'))
3088 return TokenNameCLASS_C;
3092 if ((data[++index] == '_') && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 't')
3093 && (data[++index] == 'h') && (data[++index] == 'o') && (data[++index] == 'd') && (data[++index] == '_')
3094 && (data[++index] == '_'))
3095 return TokenNameMETHOD_C;
3099 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'u') && (data[++index] == 'n')
3100 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'o')
3101 && (data[++index] == 'n') && (data[++index] == '_') && (data[++index] == '_'))
3102 return TokenNameFUNC_C;
3105 return TokenNameIdentifier;
3107 // as and array abstract
3111 if ((data[++index] == 's')) {
3114 return TokenNameIdentifier;
3118 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3119 return TokenNameand;
3121 return TokenNameIdentifier;
3125 if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y'))
3126 return TokenNamearray;
3128 return TokenNameIdentifier;
3130 if ((data[++index] == 'b') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'r')
3131 && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 't'))
3132 return TokenNameabstract;
3134 return TokenNameIdentifier;
3136 return TokenNameIdentifier;
3142 if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k'))
3143 return TokenNamebreak;
3145 return TokenNameIdentifier;
3147 return TokenNameIdentifier;
3150 //case catch class clone const continue
3153 if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e'))
3154 return TokenNamecase;
3156 return TokenNameIdentifier;
3158 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3159 return TokenNamecatch;
3161 if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's'))
3162 return TokenNameclass;
3164 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 'e'))
3165 return TokenNameclone;
3167 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't'))
3168 return TokenNameconst;
3170 return TokenNameIdentifier;
3172 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'i')
3173 && (data[++index] == 'n') && (data[++index] == 'u') && (data[++index] == 'e'))
3174 return TokenNamecontinue;
3176 return TokenNameIdentifier;
3178 return TokenNameIdentifier;
3181 // declare default do die
3182 // TODO delete define ==> no keyword !
3185 if ((data[++index] == 'o'))
3188 return TokenNameIdentifier;
3190 // if ((data[++index] == 'e')
3191 // && (data[++index] == 'f')
3192 // && (data[++index] == 'i')
3193 // && (data[++index] == 'n')
3194 // && (data[++index] == 'e'))
3195 // return TokenNamedefine;
3197 // return TokenNameIdentifier;
3199 if ((data[++index] == 'e') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3200 && (data[++index] == 'r') && (data[++index] == 'e'))
3201 return TokenNamedeclare;
3203 if ((data[++index] == 'e') && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'u')
3204 && (data[++index] == 'l') && (data[++index] == 't'))
3205 return TokenNamedefault;
3207 return TokenNameIdentifier;
3209 return TokenNameIdentifier;
3212 //echo else exit elseif extends eval
3215 if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o'))
3216 return TokenNameecho;
3217 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e'))
3218 return TokenNameelse;
3219 else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't'))
3220 return TokenNameexit;
3221 else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l'))
3222 return TokenNameeval;
3224 return TokenNameIdentifier;
3227 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f'))
3228 return TokenNameendif;
3229 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 't') && (data[++index] == 'y'))
3230 return TokenNameempty;
3232 return TokenNameIdentifier;
3235 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o')
3236 && (data[++index] == 'r'))
3237 return TokenNameendfor;
3238 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 'i')
3239 && (data[++index] == 'f'))
3240 return TokenNameelseif;
3242 return TokenNameIdentifier;
3244 if ((data[++index] == 'x') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'n')
3245 && (data[++index] == 'd') && (data[++index] == 's'))
3246 return TokenNameextends;
3248 return TokenNameIdentifier;
3251 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'w') && (data[++index] == 'h')
3252 && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3253 return TokenNameendwhile;
3255 return TokenNameIdentifier;
3258 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 's') && (data[++index] == 'w')
3259 && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3260 return TokenNameendswitch;
3262 return TokenNameIdentifier;
3265 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'd') && (data[++index] == 'e')
3266 && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 'r')
3267 && (data[++index] == 'e'))
3268 return TokenNameenddeclare;
3270 if ((data[++index] == 'n') // endforeach
3271 && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r')
3272 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'h'))
3273 return TokenNameendforeach;
3275 return TokenNameIdentifier;
3277 return TokenNameIdentifier;
3280 //for false final function
3283 if ((data[++index] == 'o') && (data[++index] == 'r'))
3284 return TokenNamefor;
3286 return TokenNameIdentifier;
3288 // if ((data[++index] == 'a') && (data[++index] == 'l')
3289 // && (data[++index] == 's') && (data[++index] == 'e'))
3290 // return TokenNamefalse;
3291 if ((data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 'a') && (data[++index] == 'l'))
3292 return TokenNamefinal;
3294 return TokenNameIdentifier;
3297 if ((data[++index] == 'o') && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a')
3298 && (data[++index] == 'c') && (data[++index] == 'h'))
3299 return TokenNameforeach;
3301 return TokenNameIdentifier;
3304 if ((data[++index] == 'u') && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 't')
3305 && (data[++index] == 'i') && (data[++index] == 'o') && (data[++index] == 'n'))
3306 return TokenNamefunction;
3308 return TokenNameIdentifier;
3310 return TokenNameIdentifier;
3315 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'b') && (data[++index] == 'a')
3316 && (data[++index] == 'l')) {
3317 return TokenNameglobal;
3320 return TokenNameIdentifier;
3322 //if int isset include include_once instanceof interface implements
3325 if (data[++index] == 'f')
3328 return TokenNameIdentifier;
3330 // if ((data[++index] == 'n') && (data[++index] == 't'))
3331 // return TokenNameint;
3333 // return TokenNameIdentifier;
3335 if ((data[++index] == 's') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3336 return TokenNameisset;
3338 return TokenNameIdentifier;
3340 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3341 && (data[++index] == 'd') && (data[++index] == 'e'))
3342 return TokenNameinclude;
3344 return TokenNameIdentifier;
3347 if ((data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'r')
3348 && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'e'))
3349 return TokenNameinterface;
3351 return TokenNameIdentifier;
3354 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'a')
3355 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e') && (data[++index] == 'o')
3356 && (data[++index] == 'f'))
3357 return TokenNameinstanceof;
3358 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 'l') && (data[++index] == 'e')
3359 && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 'n') && (data[++index] == 't')
3360 && (data[++index] == 's'))
3361 return TokenNameimplements;
3363 return TokenNameIdentifier;
3365 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3366 && (data[++index] == 'd') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3367 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e'))
3368 return TokenNameinclude_once;
3370 return TokenNameIdentifier;
3372 return TokenNameIdentifier;
3377 if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) {
3378 return TokenNamelist;
3381 return TokenNameIdentifier;
3386 if ((data[++index] == 'e') && (data[++index] == 'w'))
3387 return TokenNamenew;
3389 return TokenNameIdentifier;
3391 // if ((data[++index] == 'u') && (data[++index] == 'l')
3392 // && (data[++index] == 'l'))
3393 // return TokenNamenull;
3395 // return TokenNameIdentifier;
3397 return TokenNameIdentifier;
3402 if (data[++index] == 'r') {
3406 // if (length == 12) {
3407 // if ((data[++index] == 'l')
3408 // && (data[++index] == 'd')
3409 // && (data[++index] == '_')
3410 // && (data[++index] == 'f')
3411 // && (data[++index] == 'u')
3412 // && (data[++index] == 'n')
3413 // && (data[++index] == 'c')
3414 // && (data[++index] == 't')
3415 // && (data[++index] == 'i')
3416 // && (data[++index] == 'o')
3417 // && (data[++index] == 'n')) {
3418 // return TokenNameold_function;
3421 return TokenNameIdentifier;
3423 // print public private protected
3426 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
3427 return TokenNameprint;
3429 return TokenNameIdentifier;
3431 if ((data[++index] == 'u') && (data[++index] == 'b') && (data[++index] == 'l') && (data[++index] == 'i')
3432 && (data[++index] == 'c')) {
3433 return TokenNamepublic;
3435 return TokenNameIdentifier;
3437 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'v') && (data[++index] == 'a')
3438 && (data[++index] == 't') && (data[++index] == 'e')) {
3439 return TokenNameprivate;
3441 return TokenNameIdentifier;
3443 if ((data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 't') && (data[++index] == 'e')
3444 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'd')) {
3445 return TokenNameprotected;
3447 return TokenNameIdentifier;
3449 return TokenNameIdentifier;
3451 //return require require_once
3453 if ((data[++index] == 'e') && (data[++index] == 't') && (data[++index] == 'u') && (data[++index] == 'r')
3454 && (data[++index] == 'n')) {
3455 return TokenNamereturn;
3457 } else if (length == 7) {
3458 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3459 && (data[++index] == 'r') && (data[++index] == 'e')) {
3460 return TokenNamerequire;
3462 } else if (length == 12) {
3463 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3464 && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3465 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e')) {
3466 return TokenNamerequire_once;
3469 return TokenNameIdentifier;
3474 if (data[++index] == 't')
3475 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) {
3476 return TokenNamestatic;
3478 return TokenNameIdentifier;
3479 else if ((data[index] == 'w') && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c')
3480 && (data[++index] == 'h'))
3481 return TokenNameswitch;
3483 return TokenNameIdentifier;
3485 return TokenNameIdentifier;
3491 if ((data[++index] == 'r') && (data[++index] == 'y'))
3492 return TokenNametry;
3494 return TokenNameIdentifier;
3496 // if ((data[++index] == 'r') && (data[++index] == 'u')
3497 // && (data[++index] == 'e'))
3498 // return TokenNametrue;
3500 // return TokenNameIdentifier;
3502 if ((data[++index] == 'h') && (data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 'w'))
3503 return TokenNamethrow;
3505 return TokenNameIdentifier;
3507 return TokenNameIdentifier;
3513 if ((data[++index] == 's') && (data[++index] == 'e'))
3514 return TokenNameuse;
3516 return TokenNameIdentifier;
3518 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3519 return TokenNameunset;
3521 return TokenNameIdentifier;
3523 return TokenNameIdentifier;
3529 if ((data[++index] == 'a') && (data[++index] == 'r'))
3530 return TokenNamevar;
3532 return TokenNameIdentifier;
3534 return TokenNameIdentifier;
3540 if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3541 return TokenNamewhile;
3543 return TokenNameIdentifier;
3544 //case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3545 // (data[++index]=='e') && (data[++index]=='f')&&
3546 // (data[++index]=='p'))
3547 //return TokenNamewidefp ;
3549 //return TokenNameIdentifier;
3551 return TokenNameIdentifier;
3557 if ((data[++index] == 'o') && (data[++index] == 'r'))
3558 return TokenNamexor;
3560 return TokenNameIdentifier;
3562 return TokenNameIdentifier;
3565 return TokenNameIdentifier;
3569 public int scanNumber(boolean dotPrefix) throws InvalidInputException {
3570 //when entering this method the currentCharacter is the firt
3571 //digit of the number , i.e. it may be preceeded by a . when
3573 boolean floating = dotPrefix;
3574 if ((!dotPrefix) && (currentCharacter == '0')) {
3575 if (getNextChar('x', 'X') >= 0) { //----------hexa-----------------
3576 //force the first char of the hexa number do exist...
3577 // consume next character
3578 unicodeAsBackSlash = false;
3579 currentCharacter = source[currentPosition++];
3580 // if (((currentCharacter = source[currentPosition++]) == '\\')
3581 // && (source[currentPosition] == 'u')) {
3582 // getNextUnicodeChar();
3584 // if (withoutUnicodePtr != 0) {
3585 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3588 if (Character.digit(currentCharacter, 16) == -1)
3589 throw new InvalidInputException(INVALID_HEXA);
3591 while (getNextCharAsDigit(16)) {
3594 // if (getNextChar('l', 'L') >= 0)
3595 // return TokenNameLongLiteral;
3597 return TokenNameIntegerLiteral;
3599 //there is x or X in the number
3600 //potential octal ! ... some one may write 000099.0 ! thus 00100 <
3601 // 00078.0 is true !!!!! crazy language
3602 if (getNextCharAsDigit()) {
3603 //-------------potential octal-----------------
3604 while (getNextCharAsDigit()) {
3607 // if (getNextChar('l', 'L') >= 0) {
3608 // return TokenNameLongLiteral;
3611 // if (getNextChar('f', 'F') >= 0) {
3612 // return TokenNameFloatingPointLiteral;
3614 if (getNextChar('d', 'D') >= 0) {
3615 return TokenNameDoubleLiteral;
3616 } else { //make the distinction between octal and float ....
3617 if (getNextChar('.')) { //bingo ! ....
3618 while (getNextCharAsDigit()) {
3621 if (getNextChar('e', 'E') >= 0) {
3622 // consume next character
3623 unicodeAsBackSlash = false;
3624 currentCharacter = source[currentPosition++];
3625 // if (((currentCharacter = source[currentPosition++]) == '\\')
3626 // && (source[currentPosition] == 'u')) {
3627 // getNextUnicodeChar();
3629 // if (withoutUnicodePtr != 0) {
3630 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3633 if ((currentCharacter == '-') || (currentCharacter == '+')) {
3634 // consume next character
3635 unicodeAsBackSlash = false;
3636 currentCharacter = source[currentPosition++];
3637 // if (((currentCharacter = source[currentPosition++]) == '\\')
3638 // && (source[currentPosition] == 'u')) {
3639 // getNextUnicodeChar();
3641 // if (withoutUnicodePtr != 0) {
3642 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3643 // currentCharacter;
3647 if (!Character.isDigit(currentCharacter))
3648 throw new InvalidInputException(INVALID_FLOAT);
3649 while (getNextCharAsDigit()) {
3653 // if (getNextChar('f', 'F') >= 0)
3654 // return TokenNameFloatingPointLiteral;
3655 getNextChar('d', 'D'); //jump over potential d or D
3656 return TokenNameDoubleLiteral;
3658 return TokenNameIntegerLiteral;
3665 while (getNextCharAsDigit()) {
3668 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3669 // return TokenNameLongLiteral;
3670 if ((!dotPrefix) && (getNextChar('.'))) { //decimal part that can be empty
3671 while (getNextCharAsDigit()) {
3676 //if floating is true both exponant and suffix may be optional
3677 if (getNextChar('e', 'E') >= 0) {
3679 // consume next character
3680 unicodeAsBackSlash = false;
3681 currentCharacter = source[currentPosition++];
3682 // if (((currentCharacter = source[currentPosition++]) == '\\')
3683 // && (source[currentPosition] == 'u')) {
3684 // getNextUnicodeChar();
3686 // if (withoutUnicodePtr != 0) {
3687 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3690 if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
3693 unicodeAsBackSlash = false;
3694 currentCharacter = source[currentPosition++];
3695 // if (((currentCharacter = source[currentPosition++]) == '\\')
3696 // && (source[currentPosition] == 'u')) {
3697 // getNextUnicodeChar();
3699 // if (withoutUnicodePtr != 0) {
3700 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3704 if (!Character.isDigit(currentCharacter))
3705 throw new InvalidInputException(INVALID_FLOAT);
3706 while (getNextCharAsDigit()) {
3710 if (getNextChar('d', 'D') >= 0)
3711 return TokenNameDoubleLiteral;
3712 // if (getNextChar('f', 'F') >= 0)
3713 // return TokenNameFloatingPointLiteral;
3714 //the long flag has been tested before
3715 return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral;
3719 * Search the line number corresponding to a specific position
3722 public final int getLineNumber(int position) {
3723 if (lineEnds == null)
3725 int length = linePtr + 1;
3728 int g = 0, d = length - 1;
3732 if (position < lineEnds[m]) {
3734 } else if (position > lineEnds[m]) {
3740 if (position < lineEnds[m]) {
3746 public void setPHPMode(boolean mode) {
3750 public final void setSource(char[] source) {
3751 setSource(null, source);
3754 public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3755 //the source-buffer is set to sourceString
3756 this.compilationUnit = compilationUnit;
3757 if (source == null) {
3758 this.source = new char[0];
3760 this.source = source;
3763 initialPosition = currentPosition = 0;
3764 containsAssertKeyword = false;
3765 withoutUnicodeBuffer = new char[this.source.length];
3766 encapsedStringStack = new Stack();
3769 public String toString() {
3770 if (startPosition == source.length)
3771 return "EOF\n\n" + new String(source); //$NON-NLS-1$
3772 if (currentPosition > source.length)
3773 return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3774 char front[] = new char[startPosition];
3775 System.arraycopy(source, 0, front, 0, startPosition);
3776 int middleLength = (currentPosition - 1) - startPosition + 1;
3778 if (middleLength > -1) {
3779 middle = new char[middleLength];
3780 System.arraycopy(source, startPosition, middle, 0, middleLength);
3782 middle = new char[0];
3784 char end[] = new char[source.length - (currentPosition - 1)];
3785 System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - (currentPosition - 1) - 1);
3786 return new String(front) + "\n===============================\nStarts here -->" //$NON-NLS-1$
3787 + new String(middle) + "<-- Ends here\n===============================\n" //$NON-NLS-1$
3791 public final String toStringAction(int act) {
3793 case TokenNameERROR:
3794 return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
3796 case TokenNameINLINE_HTML:
3797 return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3798 case TokenNameIdentifier:
3799 return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3800 case TokenNameVariable:
3801 return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3802 case TokenNameabstract:
3803 return "abstract"; //$NON-NLS-1$
3805 return "AND"; //$NON-NLS-1$
3806 case TokenNamearray:
3807 return "array"; //$NON-NLS-1$
3809 return "as"; //$NON-NLS-1$
3810 case TokenNamebreak:
3811 return "break"; //$NON-NLS-1$
3813 return "case"; //$NON-NLS-1$
3814 case TokenNameclass:
3815 return "class"; //$NON-NLS-1$
3816 case TokenNamecatch:
3817 return "catch"; //$NON-NLS-1$
3818 case TokenNameclone:
3821 case TokenNameconst:
3824 case TokenNamecontinue:
3825 return "continue"; //$NON-NLS-1$
3826 case TokenNamedefault:
3827 return "default"; //$NON-NLS-1$
3828 // case TokenNamedefine :
3829 // return "define"; //$NON-NLS-1$
3831 return "do"; //$NON-NLS-1$
3833 return "echo"; //$NON-NLS-1$
3835 return "else"; //$NON-NLS-1$
3836 case TokenNameelseif:
3837 return "elseif"; //$NON-NLS-1$
3838 case TokenNameendfor:
3839 return "endfor"; //$NON-NLS-1$
3840 case TokenNameendforeach:
3841 return "endforeach"; //$NON-NLS-1$
3842 case TokenNameendif:
3843 return "endif"; //$NON-NLS-1$
3844 case TokenNameendswitch:
3845 return "endswitch"; //$NON-NLS-1$
3846 case TokenNameendwhile:
3847 return "endwhile"; //$NON-NLS-1$
3850 case TokenNameextends:
3851 return "extends"; //$NON-NLS-1$
3852 // case TokenNamefalse :
3853 // return "false"; //$NON-NLS-1$
3854 case TokenNamefinal:
3855 return "final"; //$NON-NLS-1$
3857 return "for"; //$NON-NLS-1$
3858 case TokenNameforeach:
3859 return "foreach"; //$NON-NLS-1$
3860 case TokenNamefunction:
3861 return "function"; //$NON-NLS-1$
3862 case TokenNameglobal:
3863 return "global"; //$NON-NLS-1$
3865 return "if"; //$NON-NLS-1$
3866 case TokenNameimplements:
3867 return "implements"; //$NON-NLS-1$
3868 case TokenNameinclude:
3869 return "include"; //$NON-NLS-1$
3870 case TokenNameinclude_once:
3871 return "include_once"; //$NON-NLS-1$
3872 case TokenNameinstanceof:
3873 return "instanceof"; //$NON-NLS-1$
3874 case TokenNameinterface:
3875 return "interface"; //$NON-NLS-1$
3876 case TokenNameisset:
3877 return "isset"; //$NON-NLS-1$
3879 return "list"; //$NON-NLS-1$
3881 return "new"; //$NON-NLS-1$
3882 // case TokenNamenull :
3883 // return "null"; //$NON-NLS-1$
3885 return "OR"; //$NON-NLS-1$
3886 case TokenNameprint:
3887 return "print"; //$NON-NLS-1$
3888 case TokenNameprivate:
3889 return "private"; //$NON-NLS-1$
3890 case TokenNameprotected:
3891 return "protected"; //$NON-NLS-1$
3892 case TokenNamepublic:
3893 return "public"; //$NON-NLS-1$
3894 case TokenNamerequire:
3895 return "require"; //$NON-NLS-1$
3896 case TokenNamerequire_once:
3897 return "require_once"; //$NON-NLS-1$
3898 case TokenNamereturn:
3899 return "return"; //$NON-NLS-1$
3900 case TokenNamestatic:
3901 return "static"; //$NON-NLS-1$
3902 case TokenNameswitch:
3903 return "switch"; //$NON-NLS-1$
3904 // case TokenNametrue :
3905 // return "true"; //$NON-NLS-1$
3906 case TokenNameunset:
3907 return "unset"; //$NON-NLS-1$
3909 return "var"; //$NON-NLS-1$
3910 case TokenNamewhile:
3911 return "while"; //$NON-NLS-1$
3913 return "XOR"; //$NON-NLS-1$
3914 // case TokenNamethis :
3915 // return "$this"; //$NON-NLS-1$
3916 case TokenNameIntegerLiteral:
3917 return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3918 case TokenNameDoubleLiteral:
3919 return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3920 case TokenNameStringDoubleQuote:
3921 return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3922 case TokenNameStringSingleQuote:
3923 return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3924 case TokenNameStringInterpolated:
3925 return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3926 case TokenNameEncapsedString0:
3927 return "`"; //$NON-NLS-1$
3928 case TokenNameEncapsedString1:
3929 return "\'"; //$NON-NLS-1$
3930 case TokenNameEncapsedString2:
3931 return "\""; //$NON-NLS-1$
3932 case TokenNameSTRING:
3933 return "STRING(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3934 case TokenNameHEREDOC:
3935 return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3936 case TokenNamePLUS_PLUS:
3937 return "++"; //$NON-NLS-1$
3938 case TokenNameMINUS_MINUS:
3939 return "--"; //$NON-NLS-1$
3940 case TokenNameEQUAL_EQUAL:
3941 return "=="; //$NON-NLS-1$
3942 case TokenNameEQUAL_EQUAL_EQUAL:
3943 return "==="; //$NON-NLS-1$
3944 case TokenNameEQUAL_GREATER:
3945 return "=>"; //$NON-NLS-1$
3946 case TokenNameLESS_EQUAL:
3947 return "<="; //$NON-NLS-1$
3948 case TokenNameGREATER_EQUAL:
3949 return ">="; //$NON-NLS-1$
3950 case TokenNameNOT_EQUAL:
3951 return "!="; //$NON-NLS-1$
3952 case TokenNameNOT_EQUAL_EQUAL:
3953 return "!=="; //$NON-NLS-1$
3954 case TokenNameLEFT_SHIFT:
3955 return "<<"; //$NON-NLS-1$
3956 case TokenNameRIGHT_SHIFT:
3957 return ">>"; //$NON-NLS-1$
3958 case TokenNamePLUS_EQUAL:
3959 return "+="; //$NON-NLS-1$
3960 case TokenNameMINUS_EQUAL:
3961 return "-="; //$NON-NLS-1$
3962 case TokenNameMULTIPLY_EQUAL:
3963 return "*="; //$NON-NLS-1$
3964 case TokenNameDIVIDE_EQUAL:
3965 return "/="; //$NON-NLS-1$
3966 case TokenNameAND_EQUAL:
3967 return "&="; //$NON-NLS-1$
3968 case TokenNameOR_EQUAL:
3969 return "|="; //$NON-NLS-1$
3970 case TokenNameXOR_EQUAL:
3971 return "^="; //$NON-NLS-1$
3972 case TokenNameREMAINDER_EQUAL:
3973 return "%="; //$NON-NLS-1$
3974 case TokenNameDOT_EQUAL:
3975 return ".="; //$NON-NLS-1$
3976 case TokenNameLEFT_SHIFT_EQUAL:
3977 return "<<="; //$NON-NLS-1$
3978 case TokenNameRIGHT_SHIFT_EQUAL:
3979 return ">>="; //$NON-NLS-1$
3980 case TokenNameOR_OR:
3981 return "||"; //$NON-NLS-1$
3982 case TokenNameAND_AND:
3983 return "&&"; //$NON-NLS-1$
3985 return "+"; //$NON-NLS-1$
3986 case TokenNameMINUS:
3987 return "-"; //$NON-NLS-1$
3988 case TokenNameMINUS_GREATER:
3991 return "!"; //$NON-NLS-1$
3992 case TokenNameREMAINDER:
3993 return "%"; //$NON-NLS-1$
3995 return "^"; //$NON-NLS-1$
3997 return "&"; //$NON-NLS-1$
3998 case TokenNameMULTIPLY:
3999 return "*"; //$NON-NLS-1$
4001 return "|"; //$NON-NLS-1$
4002 case TokenNameTWIDDLE:
4003 return "~"; //$NON-NLS-1$
4004 case TokenNameTWIDDLE_EQUAL:
4005 return "~="; //$NON-NLS-1$
4006 case TokenNameDIVIDE:
4007 return "/"; //$NON-NLS-1$
4008 case TokenNameGREATER:
4009 return ">"; //$NON-NLS-1$
4011 return "<"; //$NON-NLS-1$
4012 case TokenNameLPAREN:
4013 return "("; //$NON-NLS-1$
4014 case TokenNameRPAREN:
4015 return ")"; //$NON-NLS-1$
4016 case TokenNameLBRACE:
4017 return "{"; //$NON-NLS-1$
4018 case TokenNameRBRACE:
4019 return "}"; //$NON-NLS-1$
4020 case TokenNameLBRACKET:
4021 return "["; //$NON-NLS-1$
4022 case TokenNameRBRACKET:
4023 return "]"; //$NON-NLS-1$
4024 case TokenNameSEMICOLON:
4025 return ";"; //$NON-NLS-1$
4026 case TokenNameQUESTION:
4027 return "?"; //$NON-NLS-1$
4028 case TokenNameCOLON:
4029 return ":"; //$NON-NLS-1$
4030 case TokenNameCOMMA:
4031 return ","; //$NON-NLS-1$
4033 return "."; //$NON-NLS-1$
4034 case TokenNameEQUAL:
4035 return "="; //$NON-NLS-1$
4038 case TokenNameDOLLAR:
4040 case TokenNameDOLLAR_LBRACE:
4042 case TokenNameLBRACE_DOLLAR:
4045 return "EOF"; //$NON-NLS-1$
4046 case TokenNameWHITESPACE:
4047 return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4048 case TokenNameCOMMENT_LINE:
4049 return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4050 case TokenNameCOMMENT_BLOCK:
4051 return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4052 case TokenNameCOMMENT_PHPDOC:
4053 return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4054 // case TokenNameHTML :
4055 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
4058 return "__FILE__"; //$NON-NLS-1$
4060 return "__LINE__"; //$NON-NLS-1$
4061 case TokenNameCLASS_C:
4062 return "__CLASS__"; //$NON-NLS-1$
4063 case TokenNameMETHOD_C:
4064 return "__METHOD__"; //$NON-NLS-1$
4065 case TokenNameFUNC_C:
4066 return "__FUNCTION__"; //$NON-NLS-1
4067 case TokenNameboolCAST:
4068 return "( bool )"; //$NON-NLS-1$
4069 case TokenNameintCAST:
4070 return "( int )"; //$NON-NLS-1$
4071 case TokenNamedoubleCAST:
4072 return "( double )"; //$NON-NLS-1$
4073 case TokenNameobjectCAST:
4074 return "( object )"; //$NON-NLS-1$
4075 case TokenNamestringCAST:
4076 return "( string )"; //$NON-NLS-1$
4078 return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
4086 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
4087 this(tokenizeComments, tokenizeWhiteSpace, false);
4090 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals) {
4091 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, false);
4094 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4095 boolean assertMode) {
4096 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, assertMode, false, null, null, true);
4099 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4100 boolean assertMode, boolean tokenizeStrings, char[][] taskTags, char[][] taskPriorities, boolean isTaskCaseSensitive) {
4101 this.eofPosition = Integer.MAX_VALUE;
4102 this.tokenizeComments = tokenizeComments;
4103 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4104 this.tokenizeStrings = tokenizeStrings;
4105 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4106 this.assertMode = assertMode;
4107 this.encapsedStringStack = null;
4108 this.taskTags = taskTags;
4109 this.taskPriorities = taskPriorities;
4112 private void checkNonExternalizeString() throws InvalidInputException {
4113 if (currentLine == null)
4115 parseTags(currentLine);
4118 private void parseTags(NLSLine line) throws InvalidInputException {
4119 String s = new String(getCurrentTokenSource());
4120 int pos = s.indexOf(TAG_PREFIX);
4121 int lineLength = line.size();
4123 int start = pos + TAG_PREFIX_LENGTH;
4124 int end = s.indexOf(TAG_POSTFIX, start);
4125 String index = s.substring(start, end);
4128 i = Integer.parseInt(index) - 1;
4129 // Tags are one based not zero based.
4130 } catch (NumberFormatException e) {
4131 i = -1; // we don't want to consider this as a valid NLS tag
4133 if (line.exists(i)) {
4136 pos = s.indexOf(TAG_PREFIX, start);
4138 this.nonNLSStrings = new StringLiteral[lineLength];
4139 int nonNLSCounter = 0;
4140 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4141 StringLiteral literal = (StringLiteral) iterator.next();
4142 if (literal != null) {
4143 this.nonNLSStrings[nonNLSCounter++] = literal;
4146 if (nonNLSCounter == 0) {
4147 this.nonNLSStrings = null;
4151 this.wasNonExternalizedStringLiteral = true;
4152 if (nonNLSCounter != lineLength) {
4153 System.arraycopy(this.nonNLSStrings, 0, (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, nonNLSCounter);
4158 public final void scanEscapeCharacter() throws InvalidInputException {
4159 // the string with "\\u" is a legal string of two chars \ and u
4160 //thus we use a direct access to the source (for regular cases).
4161 if (unicodeAsBackSlash) {
4162 // consume next character
4163 unicodeAsBackSlash = false;
4164 // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4165 // (source[currentPosition] == 'u')) {
4166 // getNextUnicodeChar();
4168 if (withoutUnicodePtr != 0) {
4169 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4173 currentCharacter = source[currentPosition++];
4174 switch (currentCharacter) {
4176 currentCharacter = '\b';
4179 currentCharacter = '\t';
4182 currentCharacter = '\n';
4185 currentCharacter = '\f';
4188 currentCharacter = '\r';
4191 currentCharacter = '\"';
4194 currentCharacter = '\'';
4197 currentCharacter = '\\';
4200 // -----------octal escape--------------
4202 // OctalDigit OctalDigit
4203 // ZeroToThree OctalDigit OctalDigit
4204 int number = Character.getNumericValue(currentCharacter);
4205 if (number >= 0 && number <= 7) {
4206 boolean zeroToThreeNot = number > 3;
4207 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4208 int digit = Character.getNumericValue(currentCharacter);
4209 if (digit >= 0 && digit <= 7) {
4210 number = (number * 8) + digit;
4211 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4212 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
4213 // Digit --> ignore last character
4216 digit = Character.getNumericValue(currentCharacter);
4217 if (digit >= 0 && digit <= 7) { // has read \ZeroToThree
4218 // OctalDigit OctalDigit
4219 number = (number * 8) + digit;
4220 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
4221 // --> ignore last character
4225 } else { // has read \OctalDigit NonDigit--> ignore last
4229 } else { // has read \OctalDigit NonOctalDigit--> ignore last
4233 } else { // has read \OctalDigit --> ignore last character
4237 throw new InvalidInputException(INVALID_ESCAPE);
4238 currentCharacter = (char) number;
4240 throw new InvalidInputException(INVALID_ESCAPE);
4244 //chech presence of task: tags
4245 //TODO (frederic) see if we need to take unicode characters into account...
4246 public void checkTaskTag(int commentStart, int commentEnd) {
4247 char[] src = this.source;
4249 // only look for newer task: tags
4250 if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4253 int foundTaskIndex = this.foundTaskCount;
4254 char previous = src[commentStart + 1]; // should be '*' or '/'
4255 nextChar: for (int i = commentStart + 2; i < commentEnd && i < this.eofPosition; i++) {
4257 char[] priority = null;
4258 // check for tag occurrence only if not ambiguous with javadoc tag
4259 if (previous != '@') {
4260 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4261 tag = this.taskTags[itag];
4262 int tagLength = tag.length;
4266 // ensure tag is not leaded with letter if tag starts with a letter
4267 if (Scanner.isPHPIdentifierStart(tag[0])) {
4268 if (Scanner.isPHPIdentifierPart(previous)) {
4273 for (int t = 0; t < tagLength; t++) {
4276 if (x >= this.eofPosition || x >= commentEnd)
4278 if ((sc = src[i + t]) != (tc = tag[t])) { // case sensitive check
4279 if (this.isTaskCaseSensitive || (Character.toLowerCase(sc) != Character.toLowerCase(tc))) { // case insensitive check
4284 // ensure tag is not followed with letter if tag finishes with a letter
4285 if (i + tagLength < commentEnd && Scanner.isPHPIdentifierPart(src[i + tagLength - 1])) {
4286 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4289 if (this.foundTaskTags == null) {
4290 this.foundTaskTags = new char[5][];
4291 this.foundTaskMessages = new char[5][];
4292 this.foundTaskPriorities = new char[5][];
4293 this.foundTaskPositions = new int[5][];
4294 } else if (this.foundTaskCount == this.foundTaskTags.length) {
4295 System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0,
4296 this.foundTaskCount);
4297 System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4298 this.foundTaskCount);
4299 System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4300 this.foundTaskCount);
4301 System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4302 this.foundTaskCount);
4305 priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4307 this.foundTaskTags[this.foundTaskCount] = tag;
4308 this.foundTaskPriorities[this.foundTaskCount] = priority;
4309 this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4310 this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4311 this.foundTaskCount++;
4312 i += tagLength - 1; // will be incremented when looping
4318 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4319 // retrieve message start and end positions
4320 int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4321 int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4322 // at most beginning of next task
4323 if (max_value < msgStart) {
4324 max_value = msgStart; // would only occur if tag is before EOF.
4328 for (int j = msgStart; j < max_value; j++) {
4329 if ((c = src[j]) == '\n' || c == '\r') {
4335 for (int j = max_value; j > msgStart; j--) {
4336 if ((c = src[j]) == '*') {
4344 if (msgStart == end)
4347 while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4349 while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4351 // update the end position of the task
4352 this.foundTaskPositions[i][1] = end;
4353 // get the message source
4354 final int messageLength = end - msgStart + 1;
4355 char[] message = new char[messageLength];
4356 System.arraycopy(src, msgStart, message, 0, messageLength);
4357 this.foundTaskMessages[i] = message;
4361 // chech presence of task: tags
4362 // public void checkTaskTag(int commentStart, int commentEnd) {
4363 // // only look for newer task: tags
4364 // if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4367 // int foundTaskIndex = this.foundTaskCount;
4368 // nextChar: for (int i = commentStart; i < commentEnd && i < this.eofPosition; i++) {
4369 // char[] tag = null;
4370 // char[] priority = null;
4371 // // check for tag occurrence
4372 // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4373 // tag = this.taskTags[itag];
4374 // priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4375 // int tagLength = tag.length;
4376 // for (int t = 0; t < tagLength; t++) {
4377 // if (this.source[i + t] != tag[t])
4378 // continue nextTag;
4380 // if (this.foundTaskTags == null) {
4381 // this.foundTaskTags = new char[5][];
4382 // this.foundTaskMessages = new char[5][];
4383 // this.foundTaskPriorities = new char[5][];
4384 // this.foundTaskPositions = new int[5][];
4385 // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4386 // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4387 // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4388 // this.foundTaskCount);
4389 // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4390 // this.foundTaskCount);
4391 // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4392 // this.foundTaskCount);
4394 // this.foundTaskTags[this.foundTaskCount] = tag;
4395 // this.foundTaskPriorities[this.foundTaskCount] = priority;
4396 // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4397 // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4398 // this.foundTaskCount++;
4399 // i += tagLength - 1; // will be incremented when looping
4402 // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4403 // // retrieve message start and end positions
4404 // int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4405 // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4406 // // at most beginning of next task
4407 // if (max_value < msgStart)
4408 // max_value = msgStart; // would only occur if tag is before EOF.
4411 // for (int j = msgStart; j < max_value; j++) {
4412 // if ((c = this.source[j]) == '\n' || c == '\r') {
4418 // for (int j = max_value; j > msgStart; j--) {
4419 // if ((c = this.source[j]) == '*') {
4427 // if (msgStart == end)
4428 // continue; // empty
4429 // // trim the message
4430 // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4432 // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4434 // // update the end position of the task
4435 // this.foundTaskPositions[i][1] = end;
4436 // // get the message source
4437 // final int messageLength = end - msgStart + 1;
4438 // char[] message = new char[messageLength];
4439 // System.arraycopy(source, msgStart, message, 0, messageLength);
4440 // this.foundTaskMessages[i] = message;