1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others. All rights reserved. This program and the
3 * accompanying materials are made available under the terms of the Common Public License v0.5 which accompanies this distribution,
4 * and is available at http://www.eclipse.org/legal/cpl-v05.html
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
11 import java.util.Iterator;
12 import java.util.List;
14 import net.sourceforge.phpdt.core.compiler.CharOperation;
15 import net.sourceforge.phpdt.core.compiler.IScanner;
16 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
17 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
18 import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral;
19 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
21 public class Scanner implements IScanner, ITerminalSymbols {
23 * APIs ares - getNextToken() which return the current type of the token (this
24 * value is not memorized by the scanner) - getCurrentTokenSource() which
25 * provides with the token "REAL" source (aka all unicode have been
26 * transformed into a correct char) - sourceStart gives the position into the
27 * stream - currentPosition-1 gives the sourceEnd position into the stream
30 // 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;
43 * This token is set to TokenNameecho if a short tag block begins (i.e. >?= ... )
44 * Directly after the "=" character the getNextToken() method returns TokenNameINLINE_HTML
45 * In the next call to the getNextToken() method the value of fFillerToken (==TokenNameecho) is returned
48 int fFillerToken = TokenNameEOF;
50 public char currentCharacter;
52 public int startPosition;
54 public int currentPosition;
56 public int initialPosition, eofPosition;
58 // after this position eof are generated instead of real token from the
60 public boolean tokenizeComments;
62 public boolean tokenizeWhiteSpace;
64 public boolean tokenizeStrings;
66 // source should be viewed as a window (aka a part)
67 // of a entire very large stream
71 public char[] withoutUnicodeBuffer;
73 public int withoutUnicodePtr;
75 // when == 0 ==> no unicode in the current token
76 public boolean unicodeAsBackSlash = false;
78 public boolean scanningFloatLiteral = false;
80 // support for /** comments
81 public int[] commentStops = new int[10];
83 public int[] commentStarts = new int[10];
85 public int commentPtr = -1; // no comment test with commentPtr value -1
87 protected int lastCommentLinePosition = -1;
89 // diet parsing support - jump over some method body when requested
90 public boolean diet = false;
92 // support for the poor-line-debuggers ....
93 // remember the position of the cr/lf
94 public int[] lineEnds = new int[250];
96 public int linePtr = -1;
98 public boolean wasAcr = false;
100 public static final String END_OF_SOURCE = "End_Of_Source"; //$NON-NLS-1$
102 public static final String INVALID_HEXA = "Invalid_Hexa_Literal"; //$NON-NLS-1$
104 public static final String INVALID_OCTAL = "Invalid_Octal_Literal"; //$NON-NLS-1$
106 public static final String INVALID_CHARACTER_CONSTANT = "Invalid_Character_Constant"; //$NON-NLS-1$
108 public static final String INVALID_ESCAPE = "Invalid_Escape"; //$NON-NLS-1$
110 public static final String INVALID_INPUT = "Invalid_Input"; //$NON-NLS-1$
112 public static final String INVALID_UNICODE_ESCAPE = "Invalid_Unicode_Escape"; //$NON-NLS-1$
114 public static final String INVALID_FLOAT = "Invalid_Float_Literal"; //$NON-NLS-1$
116 public static final String NULL_SOURCE_STRING = "Null_Source_String"; //$NON-NLS-1$
118 public static final String UNTERMINATED_STRING = "Unterminated_String"; //$NON-NLS-1$
120 public static final String UNTERMINATED_COMMENT = "Unterminated_Comment"; //$NON-NLS-1$
122 public static final String INVALID_CHAR_IN_STRING = "Invalid_Char_In_String"; //$NON-NLS-1$
124 // ----------------optimized identifier managment------------------
125 static final char[] charArray_a = new char[] { 'a' }, charArray_b = new char[] { 'b' }, charArray_c = new char[] { 'c' },
126 charArray_d = new char[] { 'd' }, charArray_e = new char[] { 'e' }, charArray_f = new char[] { 'f' },
127 charArray_g = new char[] { 'g' }, charArray_h = new char[] { 'h' }, charArray_i = new char[] { 'i' },
128 charArray_j = new char[] { 'j' }, charArray_k = new char[] { 'k' }, charArray_l = new char[] { 'l' },
129 charArray_m = new char[] { 'm' }, charArray_n = new char[] { 'n' }, charArray_o = new char[] { 'o' },
130 charArray_p = new char[] { 'p' }, charArray_q = new char[] { 'q' }, charArray_r = new char[] { 'r' },
131 charArray_s = new char[] { 's' }, charArray_t = new char[] { 't' }, charArray_u = new char[] { 'u' },
132 charArray_v = new char[] { 'v' }, charArray_w = new char[] { 'w' }, charArray_x = new char[] { 'x' },
133 charArray_y = new char[] { 'y' }, charArray_z = new char[] { 'z' };
135 static final char[] charArray_va = new char[] { '$', 'a' }, charArray_vb = new char[] { '$', 'b' }, charArray_vc = new char[] {
136 '$', 'c' }, charArray_vd = new char[] { '$', 'd' }, charArray_ve = new char[] { '$', 'e' }, charArray_vf = new char[] { '$',
137 'f' }, charArray_vg = new char[] { '$', 'g' }, charArray_vh = new char[] { '$', 'h' },
138 charArray_vi = new char[] { '$', 'i' }, charArray_vj = new char[] { '$', 'j' }, charArray_vk = new char[] { '$', 'k' },
139 charArray_vl = new char[] { '$', 'l' }, charArray_vm = new char[] { '$', 'm' }, charArray_vn = new char[] { '$', 'n' },
140 charArray_vo = new char[] { '$', 'o' }, charArray_vp = new char[] { '$', 'p' }, charArray_vq = new char[] { '$', 'q' },
141 charArray_vr = new char[] { '$', 'r' }, charArray_vs = new char[] { '$', 's' }, charArray_vt = new char[] { '$', 't' },
142 charArray_vu = new char[] { '$', 'u' }, charArray_vv = new char[] { '$', 'v' }, charArray_vw = new char[] { '$', 'w' },
143 charArray_vx = new char[] { '$', 'x' }, charArray_vy = new char[] { '$', 'y' }, charArray_vz = new char[] { '$', 'z' };
145 public final static int MAX_OBVIOUS = 256;
147 static final int[] ObviousIdentCharNatures = new int[MAX_OBVIOUS];
149 public final static int C_DOLLAR = 8;
151 public final static int C_LETTER = 4;
153 public final static int C_DIGIT = 3;
155 public final static int C_SEPARATOR = 2;
157 public final static int C_SPACE = 1;
159 for (int i = '0'; i <= '9'; i++)
160 ObviousIdentCharNatures[i] = C_DIGIT;
162 for (int i = 'a'; i <= 'z'; i++)
163 ObviousIdentCharNatures[i] = C_LETTER;
164 for (int i = 'A'; i <= 'Z'; i++)
165 ObviousIdentCharNatures[i] = C_LETTER;
166 ObviousIdentCharNatures['_'] = C_LETTER;
167 for (int i = 127; i <= 255; i++)
168 ObviousIdentCharNatures[i] = C_LETTER;
170 ObviousIdentCharNatures['$'] = C_DOLLAR;
172 ObviousIdentCharNatures[10] = C_SPACE; // \ u000a: LINE FEED
173 ObviousIdentCharNatures[12] = C_SPACE; // \ u000c: FORM FEED
174 ObviousIdentCharNatures[13] = C_SPACE; // \ u000d: CARRIAGE RETURN
175 ObviousIdentCharNatures[32] = C_SPACE; // \ u0020: SPACE
176 ObviousIdentCharNatures[9] = C_SPACE; // \ u0009: HORIZONTAL TABULATION
178 ObviousIdentCharNatures['.'] = C_SEPARATOR;
179 ObviousIdentCharNatures[':'] = C_SEPARATOR;
180 ObviousIdentCharNatures[';'] = C_SEPARATOR;
181 ObviousIdentCharNatures[','] = C_SEPARATOR;
182 ObviousIdentCharNatures['['] = C_SEPARATOR;
183 ObviousIdentCharNatures[']'] = C_SEPARATOR;
184 ObviousIdentCharNatures['('] = C_SEPARATOR;
185 ObviousIdentCharNatures[')'] = C_SEPARATOR;
186 ObviousIdentCharNatures['{'] = C_SEPARATOR;
187 ObviousIdentCharNatures['}'] = C_SEPARATOR;
188 ObviousIdentCharNatures['+'] = C_SEPARATOR;
189 ObviousIdentCharNatures['-'] = C_SEPARATOR;
190 ObviousIdentCharNatures['*'] = C_SEPARATOR;
191 ObviousIdentCharNatures['/'] = C_SEPARATOR;
192 ObviousIdentCharNatures['='] = C_SEPARATOR;
193 ObviousIdentCharNatures['&'] = C_SEPARATOR;
194 ObviousIdentCharNatures['|'] = C_SEPARATOR;
195 ObviousIdentCharNatures['?'] = C_SEPARATOR;
196 ObviousIdentCharNatures['<'] = C_SEPARATOR;
197 ObviousIdentCharNatures['>'] = C_SEPARATOR;
198 ObviousIdentCharNatures['!'] = C_SEPARATOR;
199 ObviousIdentCharNatures['%'] = C_SEPARATOR;
200 ObviousIdentCharNatures['^'] = C_SEPARATOR;
201 ObviousIdentCharNatures['~'] = C_SEPARATOR;
202 ObviousIdentCharNatures['"'] = C_SEPARATOR;
203 ObviousIdentCharNatures['\''] = C_SEPARATOR;
206 static final char[] initCharArray = new char[] { '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' };
208 static final int TableSize = 30, InternalTableSize = 6;
210 // 30*6 = 180 entries
211 public static final int OptimizedLength = 6;
214 final char[][][][] charArray_length = new char[OptimizedLength][TableSize][InternalTableSize][];
216 // support for detecting non-externalized string literals
217 int currentLineNr = -1;
219 int previousLineNr = -1;
221 NLSLine currentLine = null;
223 List lines = new ArrayList();
225 public static final String TAG_PREFIX = "//$NON-NLS-"; //$NON-NLS-1$
227 public static final int TAG_PREFIX_LENGTH = TAG_PREFIX.length();
229 public static final String TAG_POSTFIX = "$"; //$NON-NLS-1$
231 public static final int TAG_POSTFIX_LENGTH = TAG_POSTFIX.length();
233 public StringLiteral[] nonNLSStrings = null;
235 public boolean checkNonExternalizedStringLiterals = true;
237 public boolean wasNonExternalizedStringLiteral = false;
240 for (int i = 0; i < 6; i++) {
241 for (int j = 0; j < TableSize; j++) {
242 for (int k = 0; k < InternalTableSize; k++) {
243 charArray_length[i][j][k] = initCharArray;
249 static int newEntry2 = 0, newEntry3 = 0, newEntry4 = 0, newEntry5 = 0, newEntry6 = 0;
251 public static final int RoundBracket = 0;
253 public static final int SquareBracket = 1;
255 public static final int CurlyBracket = 2;
257 public static final int BracketKinds = 3;
260 public char[][] foundTaskTags = null;
262 public char[][] foundTaskMessages;
264 public char[][] foundTaskPriorities = null;
266 public int[][] foundTaskPositions;
268 public int foundTaskCount = 0;
270 public char[][] taskTags = null;
272 public char[][] taskPriorities = null;
274 public boolean isTaskCaseSensitive = true;
276 public static final boolean DEBUG = false;
278 public static final boolean TRACE = false;
280 public ICompilationUnit compilationUnit = null;
283 * Determines if the specified character is permissible as the first character
284 * in a PHP identifier or variable
286 * The '$' character for PHP variables is regarded as a correct first
290 public static boolean isPHPIdentOrVarStart(char ch) {
291 if (ch < MAX_OBVIOUS) {
292 return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DOLLAR;
295 // return Character.isLetter(ch) || (ch == '$') || (ch == '_') || (0x7F <=
296 // ch && ch <= 0xFF);
300 * Determines if the specified character is permissible as the first character
301 * in a PHP identifier.
303 * The '$' character for PHP variables isn't regarded as the first character !
305 public static boolean isPHPIdentifierStart(char ch) {
306 if (ch < MAX_OBVIOUS) {
307 return ObviousIdentCharNatures[ch] == C_LETTER;
310 // return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <=
315 * Determines if the specified character may be part of a PHP identifier as
316 * other than the first character
318 public static boolean isPHPIdentifierPart(char ch) {
319 if (ch < MAX_OBVIOUS) {
320 return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DIGIT;
323 // return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch
327 public static boolean isSQLIdentifierPart(char ch) {
328 if (ch < MAX_OBVIOUS) {
329 return ObviousIdentCharNatures[ch] == C_LETTER || ObviousIdentCharNatures[ch] == C_DIGIT;
334 public final boolean atEnd() {
335 // This code is not relevant if source is
336 // Only a part of the real stream input
337 return source.length == currentPosition;
340 public char[] getCurrentIdentifierSource() {
341 // return the token REAL source (aka unicodes are precomputed)
343 // if (withoutUnicodePtr != 0)
344 // //0 is used as a fast test flag so the real first char is in position 1
346 // withoutUnicodeBuffer,
348 // result = new char[withoutUnicodePtr],
350 // withoutUnicodePtr);
352 int length = currentPosition - startPosition;
353 switch (length) { // see OptimizedLength
355 return optimizedCurrentTokenSource1();
357 return optimizedCurrentTokenSource2();
359 return optimizedCurrentTokenSource3();
361 return optimizedCurrentTokenSource4();
363 return optimizedCurrentTokenSource5();
365 return optimizedCurrentTokenSource6();
368 System.arraycopy(source, startPosition, result = new char[length], 0, length);
373 public int getCurrentTokenEndPosition() {
374 return this.currentPosition - 1;
377 public final char[] getCurrentTokenSource() {
378 // Return the token REAL source (aka unicodes are precomputed)
380 // if (withoutUnicodePtr != 0)
381 // // 0 is used as a fast test flag so the real first char is in position 1
383 // withoutUnicodeBuffer,
385 // result = new char[withoutUnicodePtr],
387 // withoutUnicodePtr);
390 System.arraycopy(source, startPosition, result = new char[length = currentPosition - startPosition], 0, length);
395 public final char[] getCurrentTokenSource(int startPos) {
396 // Return the token REAL source (aka unicodes are precomputed)
398 // if (withoutUnicodePtr != 0)
399 // // 0 is used as a fast test flag so the real first char is in position 1
401 // withoutUnicodeBuffer,
403 // result = new char[withoutUnicodePtr],
405 // withoutUnicodePtr);
408 System.arraycopy(source, startPos, result = new char[length = currentPosition - startPos], 0, length);
413 public final char[] getCurrentTokenSourceString() {
414 // return the token REAL source (aka unicodes are precomputed).
415 // REMOVE the two " that are at the beginning and the end.
417 if (withoutUnicodePtr != 0)
418 // 0 is used as a fast test flag so the real first char is in position 1
419 System.arraycopy(withoutUnicodeBuffer, 2,
420 // 2 is 1 (real start) + 1 (to jump over the ")
421 result = new char[withoutUnicodePtr - 2], 0, withoutUnicodePtr - 2);
424 System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length);
429 public final boolean equalsCurrentTokenSource(char[] word) {
430 if (word.length != currentPosition - startPosition) {
433 for (int i = 0; i < word.length; i++) {
434 if (word[i] != source[startPosition + i]) {
441 public final char[] getRawTokenSourceEnd() {
442 int length = this.eofPosition - this.currentPosition - 1;
443 char[] sourceEnd = new char[length];
444 System.arraycopy(this.source, this.currentPosition, sourceEnd, 0, length);
448 public int getCurrentTokenStartPosition() {
449 return this.startPosition;
452 public final String getCurrentStringLiteral() {
453 char[] result = getCurrentStringLiteralSource();
454 return new String(result);
457 public final char[] getCurrentStringLiteralSource() {
458 // Return the token REAL source (aka unicodes are precomputed)
459 if (startPosition + 1 >= currentPosition) {
464 System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length);
469 public final char[] getCurrentStringLiteralSource(int startPos) {
470 // Return the token REAL source (aka unicodes are precomputed)
473 System.arraycopy(source, startPos + 1, result = new char[length = currentPosition - startPos - 2], 0, length);
479 * Search the source position corresponding to the end of a given line number
481 * Line numbers are 1-based, and relative to the scanner initialPosition.
482 * Character positions are 0-based.
484 * In case the given line number is inconsistent, answers -1.
486 public final int getLineEnd(int lineNumber) {
487 if (lineEnds == null)
489 if (lineNumber >= lineEnds.length)
493 if (lineNumber == lineEnds.length - 1)
495 return lineEnds[lineNumber - 1];
496 // next line start one character behind the lineEnd of the previous line
500 * Search the source position corresponding to the beginning of a given line
503 * Line numbers are 1-based, and relative to the scanner initialPosition.
504 * Character positions are 0-based.
506 * e.g. getLineStart(1) --> 0 i.e. first line starts at character 0.
508 * In case the given line number is inconsistent, answers -1.
510 public final int getLineStart(int lineNumber) {
511 if (lineEnds == null)
513 if (lineNumber >= lineEnds.length)
518 return initialPosition;
519 return lineEnds[lineNumber - 2] + 1;
520 // next line start one character behind the lineEnd of the previous line
523 public final boolean getNextChar(char testedChar) {
525 // handle the case of unicode.
526 // when a unicode appears then we must use a buffer that holds char
528 // At the end of this method currentCharacter holds the new visited char
529 // and currentPosition points right next after it
530 // Both previous lines are true if the currentCharacter is == to the
532 // On false, no side effect has occured.
533 // ALL getNextChar.... ARE OPTIMIZED COPIES
534 int temp = currentPosition;
536 currentCharacter = source[currentPosition++];
537 // if (((currentCharacter = source[currentPosition++]) == '\\')
538 // && (source[currentPosition] == 'u')) {
539 // //-------------unicode traitement ------------
540 // int c1, c2, c3, c4;
541 // int unicodeSize = 6;
542 // currentPosition++;
543 // while (source[currentPosition] == 'u') {
544 // currentPosition++;
548 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
550 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
552 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
554 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
556 // currentPosition = temp;
560 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
561 // if (currentCharacter != testedChar) {
562 // currentPosition = temp;
565 // unicodeAsBackSlash = currentCharacter == '\\';
567 // //need the unicode buffer
568 // if (withoutUnicodePtr == 0) {
569 // //buffer all the entries that have been left aside....
570 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
574 // withoutUnicodeBuffer,
576 // withoutUnicodePtr);
578 // //fill the buffer with the char
579 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
582 // } //-------------end unicode traitement--------------
584 if (currentCharacter != testedChar) {
585 currentPosition = temp;
588 unicodeAsBackSlash = false;
589 // if (withoutUnicodePtr != 0)
590 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
593 } catch (IndexOutOfBoundsException e) {
594 unicodeAsBackSlash = false;
595 currentPosition = temp;
600 public final int getNextChar(char testedChar1, char testedChar2) {
601 // INT 0 : testChar1 \\\\///\\\\ 1 : testedChar2 \\\\///\\\\ -1 : others
602 // test can be done with (x==0) for the first and (x>0) for the second
603 // handle the case of unicode.
604 // when a unicode appears then we must use a buffer that holds char
606 // At the end of this method currentCharacter holds the new visited char
607 // and currentPosition points right next after it
608 // Both previous lines are true if the currentCharacter is == to the
610 // On false, no side effect has occured.
611 // ALL getNextChar.... ARE OPTIMIZED COPIES
612 int temp = currentPosition;
615 currentCharacter = source[currentPosition++];
616 // if (((currentCharacter = source[currentPosition++]) == '\\')
617 // && (source[currentPosition] == 'u')) {
618 // //-------------unicode traitement ------------
619 // int c1, c2, c3, c4;
620 // int unicodeSize = 6;
621 // currentPosition++;
622 // while (source[currentPosition] == 'u') {
623 // currentPosition++;
627 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
629 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
631 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
633 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
635 // currentPosition = temp;
639 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
640 // if (currentCharacter == testedChar1)
642 // else if (currentCharacter == testedChar2)
645 // currentPosition = temp;
649 // //need the unicode buffer
650 // if (withoutUnicodePtr == 0) {
651 // //buffer all the entries that have been left aside....
652 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
656 // withoutUnicodeBuffer,
658 // withoutUnicodePtr);
660 // //fill the buffer with the char
661 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
663 // } //-------------end unicode traitement--------------
665 if (currentCharacter == testedChar1)
667 else if (currentCharacter == testedChar2)
670 currentPosition = temp;
673 // if (withoutUnicodePtr != 0)
674 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
677 } catch (IndexOutOfBoundsException e) {
678 currentPosition = temp;
683 public final boolean getNextCharAsDigit() {
685 // handle the case of unicode.
686 // when a unicode appears then we must use a buffer that holds char
688 // At the end of this method currentCharacter holds the new visited char
689 // and currentPosition points right next after it
690 // Both previous lines are true if the currentCharacter is a digit
691 // On false, no side effect has occured.
692 // ALL getNextChar.... ARE OPTIMIZED COPIES
693 int temp = currentPosition;
695 currentCharacter = source[currentPosition++];
696 // if (((currentCharacter = source[currentPosition++]) == '\\')
697 // && (source[currentPosition] == 'u')) {
698 // //-------------unicode traitement ------------
699 // int c1, c2, c3, c4;
700 // int unicodeSize = 6;
701 // currentPosition++;
702 // while (source[currentPosition] == 'u') {
703 // currentPosition++;
707 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
709 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
711 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
713 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
715 // currentPosition = temp;
719 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
720 // if (!Character.isDigit(currentCharacter)) {
721 // currentPosition = temp;
725 // //need the unicode buffer
726 // if (withoutUnicodePtr == 0) {
727 // //buffer all the entries that have been left aside....
728 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
732 // withoutUnicodeBuffer,
734 // withoutUnicodePtr);
736 // //fill the buffer with the char
737 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
739 // } //-------------end unicode traitement--------------
741 if (!Character.isDigit(currentCharacter)) {
742 currentPosition = temp;
745 // if (withoutUnicodePtr != 0)
746 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
749 } catch (IndexOutOfBoundsException e) {
750 currentPosition = temp;
755 public final boolean getNextCharAsDigit(int radix) {
757 // handle the case of unicode.
758 // when a unicode appears then we must use a buffer that holds char
760 // At the end of this method currentCharacter holds the new visited char
761 // and currentPosition points right next after it
762 // Both previous lines are true if the currentCharacter is a digit base on
764 // On false, no side effect has occured.
765 // ALL getNextChar.... ARE OPTIMIZED COPIES
766 int temp = currentPosition;
768 currentCharacter = source[currentPosition++];
769 // if (((currentCharacter = source[currentPosition++]) == '\\')
770 // && (source[currentPosition] == 'u')) {
771 // //-------------unicode traitement ------------
772 // int c1, c2, c3, c4;
773 // int unicodeSize = 6;
774 // currentPosition++;
775 // while (source[currentPosition] == 'u') {
776 // currentPosition++;
780 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
782 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
784 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
786 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
788 // currentPosition = temp;
792 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
793 // if (Character.digit(currentCharacter, radix) == -1) {
794 // currentPosition = temp;
798 // //need the unicode buffer
799 // if (withoutUnicodePtr == 0) {
800 // //buffer all the entries that have been left aside....
801 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
805 // withoutUnicodeBuffer,
807 // withoutUnicodePtr);
809 // //fill the buffer with the char
810 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
812 // } //-------------end unicode traitement--------------
814 if (Character.digit(currentCharacter, radix) == -1) {
815 currentPosition = temp;
818 // if (withoutUnicodePtr != 0)
819 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
822 } catch (IndexOutOfBoundsException e) {
823 currentPosition = temp;
828 public boolean getNextCharAsJavaIdentifierPart() {
830 // handle the case of unicode.
831 // when a unicode appears then we must use a buffer that holds char
833 // At the end of this method currentCharacter holds the new visited char
834 // and currentPosition points right next after it
835 // Both previous lines are true if the currentCharacter is a
836 // JavaIdentifierPart
837 // On false, no side effect has occured.
838 // ALL getNextChar.... ARE OPTIMIZED COPIES
839 int temp = currentPosition;
841 currentCharacter = source[currentPosition++];
842 // if (((currentCharacter = source[currentPosition++]) == '\\')
843 // && (source[currentPosition] == 'u')) {
844 // //-------------unicode traitement ------------
845 // int c1, c2, c3, c4;
846 // int unicodeSize = 6;
847 // currentPosition++;
848 // while (source[currentPosition] == 'u') {
849 // currentPosition++;
853 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
855 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
857 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
859 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
861 // currentPosition = temp;
865 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
866 // if (!isPHPIdentifierPart(currentCharacter)) {
867 // currentPosition = temp;
871 // //need the unicode buffer
872 // if (withoutUnicodePtr == 0) {
873 // //buffer all the entries that have been left aside....
874 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
878 // withoutUnicodeBuffer,
880 // withoutUnicodePtr);
882 // //fill the buffer with the char
883 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
885 // } //-------------end unicode traitement--------------
887 if (!isPHPIdentifierPart(currentCharacter)) {
888 currentPosition = temp;
891 // if (withoutUnicodePtr != 0)
892 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
895 } catch (IndexOutOfBoundsException e) {
896 currentPosition = temp;
901 public int getCastOrParen() {
902 int tempPosition = currentPosition;
903 char tempCharacter = currentCharacter;
904 int tempToken = TokenNameLPAREN;
905 boolean found = false;
906 StringBuffer buf = new StringBuffer();
909 currentCharacter = source[currentPosition++];
910 } while (currentCharacter == ' ' || currentCharacter == '\t');
911 while (ObviousIdentCharNatures[currentCharacter] == C_LETTER) {
912 // while((currentCharacter >= 'a' && currentCharacter <= 'z') ||
913 // (currentCharacter >= 'A' && currentCharacter <= 'Z')) {
914 buf.append(currentCharacter);
915 currentCharacter = source[currentPosition++];
917 if (buf.length() >= 3 && buf.length() <= 7) {
918 char[] data = buf.toString().toCharArray();
920 switch (data.length) {
923 if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
925 tempToken = TokenNameintCAST;
930 if ((data[index] == 'b') && (data[++index] == 'o') && (data[++index] == 'o') && (data[++index] == 'l')) {
932 tempToken = TokenNameboolCAST;
935 if ((data[index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'l')) {
937 tempToken = TokenNamedoubleCAST;
943 if ((data[index] == 'a') && (data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a')
944 && (data[++index] == 'y')) {
946 tempToken = TokenNamearrayCAST;
949 if ((data[index] == 'u') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e')
950 && (data[++index] == 't')) {
952 tempToken = TokenNameunsetCAST;
955 if ((data[index] == 'f') && (data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'a')
956 && (data[++index] == 't')) {
958 tempToken = TokenNamedoubleCAST;
964 // object string double
965 if ((data[index] == 'o') && (data[++index] == 'b') && (data[++index] == 'j') && (data[++index] == 'e')
966 && (data[++index] == 'c') && (data[++index] == 't')) {
968 tempToken = TokenNameobjectCAST;
971 if ((data[index] == 's') && (data[++index] == 't') && (data[++index] == 'r') && (data[++index] == 'i')
972 && (data[++index] == 'n') && (data[++index] == 'g')) {
974 tempToken = TokenNamestringCAST;
977 if ((data[index] == 'd') && (data[++index] == 'o') && (data[++index] == 'u') && (data[++index] == 'b')
978 && (data[++index] == 'l') && (data[++index] == 'e')) {
980 tempToken = TokenNamedoubleCAST;
987 if ((data[index] == 'b') && (data[++index] == 'o') && (data[++index] == 'o') && (data[++index] == 'l')
988 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'n')) {
990 tempToken = TokenNameboolCAST;
993 if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e')
994 && (data[++index] == 'g') && (data[++index] == 'e') && (data[++index] == 'r')) {
996 tempToken = TokenNameintCAST;
1002 while (currentCharacter == ' ' || currentCharacter == '\t') {
1003 currentCharacter = source[currentPosition++];
1005 if (currentCharacter == ')') {
1010 } catch (IndexOutOfBoundsException e) {
1012 currentCharacter = tempCharacter;
1013 currentPosition = tempPosition;
1014 return TokenNameLPAREN;
1017 public void consumeStringInterpolated() throws InvalidInputException {
1019 // consume next character
1020 unicodeAsBackSlash = false;
1021 currentCharacter = source[currentPosition++];
1022 // if (((currentCharacter = source[currentPosition++]) == '\\')
1023 // && (source[currentPosition] == 'u')) {
1024 // getNextUnicodeChar();
1026 // if (withoutUnicodePtr != 0) {
1027 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1028 // currentCharacter;
1031 while (currentCharacter != '`') {
1032 /** ** in PHP \r and \n are valid in string literals *** */
1033 // if ((currentCharacter == '\n')
1034 // || (currentCharacter == '\r')) {
1035 // // relocate if finding another quote fairly close: thus unicode
1036 // '/u000D' will be fully consumed
1037 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1038 // if (currentPosition + lookAhead == source.length)
1040 // if (source[currentPosition + lookAhead] == '\n')
1042 // if (source[currentPosition + lookAhead] == '\"') {
1043 // currentPosition += lookAhead + 1;
1047 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1049 if (currentCharacter == '\\') {
1050 int escapeSize = currentPosition;
1051 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1052 // scanEscapeCharacter make a side effect on this value and we need
1053 // the previous value few lines down this one
1054 scanDoubleQuotedEscapeCharacter();
1055 escapeSize = currentPosition - escapeSize;
1056 if (withoutUnicodePtr == 0) {
1057 // buffer all the entries that have been left aside....
1058 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1059 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1060 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1061 } else { // overwrite the / in the buffer
1062 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1063 if (backSlashAsUnicodeInString) { // there are TWO \ in the stream
1064 // where only one is correct
1065 withoutUnicodePtr--;
1068 } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1069 if (recordLineSeparator) {
1070 pushLineSeparator();
1073 // consume next character
1074 unicodeAsBackSlash = false;
1075 currentCharacter = source[currentPosition++];
1076 // if (((currentCharacter = source[currentPosition++]) == '\\')
1077 // && (source[currentPosition] == 'u')) {
1078 // getNextUnicodeChar();
1080 if (withoutUnicodePtr != 0) {
1081 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1085 } catch (IndexOutOfBoundsException e) {
1086 // reset end position for error reporting
1087 currentPosition -= 2;
1088 throw new InvalidInputException(UNTERMINATED_STRING);
1089 } catch (InvalidInputException e) {
1090 if (e.getMessage().equals(INVALID_ESCAPE)) {
1091 // relocate if finding another quote fairly close: thus unicode
1092 // '/u000D' will be fully consumed
1093 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1094 if (currentPosition + lookAhead == source.length)
1096 if (source[currentPosition + lookAhead] == '\n')
1098 if (source[currentPosition + lookAhead] == '`') {
1099 currentPosition += lookAhead + 1;
1106 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1107 // //$NON-NLS-?$ where ? is an
1109 if (currentLine == null) {
1110 currentLine = new NLSLine();
1111 lines.add(currentLine);
1113 currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1117 public void consumeStringConstant() throws InvalidInputException {
1119 // consume next character
1120 unicodeAsBackSlash = false;
1121 currentCharacter = source[currentPosition++];
1122 // if (((currentCharacter = source[currentPosition++]) == '\\')
1123 // && (source[currentPosition] == 'u')) {
1124 // getNextUnicodeChar();
1126 // if (withoutUnicodePtr != 0) {
1127 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1128 // currentCharacter;
1131 while (currentCharacter != '\'') {
1132 /** ** in PHP \r and \n are valid in string literals *** */
1133 // if ((currentCharacter == '\n')
1134 // || (currentCharacter == '\r')) {
1135 // // relocate if finding another quote fairly close: thus unicode
1136 // '/u000D' will be fully consumed
1137 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1138 // if (currentPosition + lookAhead == source.length)
1140 // if (source[currentPosition + lookAhead] == '\n')
1142 // if (source[currentPosition + lookAhead] == '\"') {
1143 // currentPosition += lookAhead + 1;
1147 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1149 if (currentCharacter == '\\') {
1150 int escapeSize = currentPosition;
1151 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1152 // scanEscapeCharacter make a side effect on this value and we need
1153 // the previous value few lines down this one
1154 scanSingleQuotedEscapeCharacter();
1155 escapeSize = currentPosition - escapeSize;
1156 if (withoutUnicodePtr == 0) {
1157 // buffer all the entries that have been left aside....
1158 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1159 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1160 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1161 } else { // overwrite the / in the buffer
1162 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1163 if (backSlashAsUnicodeInString) { // there are TWO \ in the stream
1164 // where only one is correct
1165 withoutUnicodePtr--;
1168 } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1169 if (recordLineSeparator) {
1170 pushLineSeparator();
1173 // consume next character
1174 unicodeAsBackSlash = false;
1175 currentCharacter = source[currentPosition++];
1176 // if (((currentCharacter = source[currentPosition++]) == '\\')
1177 // && (source[currentPosition] == 'u')) {
1178 // getNextUnicodeChar();
1180 if (withoutUnicodePtr != 0) {
1181 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1185 } catch (IndexOutOfBoundsException e) {
1186 // reset end position for error reporting
1187 currentPosition -= 2;
1188 throw new InvalidInputException(UNTERMINATED_STRING);
1189 } catch (InvalidInputException e) {
1190 if (e.getMessage().equals(INVALID_ESCAPE)) {
1191 // relocate if finding another quote fairly close: thus unicode
1192 // '/u000D' will be fully consumed
1193 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1194 if (currentPosition + lookAhead == source.length)
1196 if (source[currentPosition + lookAhead] == '\n')
1198 if (source[currentPosition + lookAhead] == '\'') {
1199 currentPosition += lookAhead + 1;
1206 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1207 // //$NON-NLS-?$ where ? is an
1209 if (currentLine == null) {
1210 currentLine = new NLSLine();
1211 lines.add(currentLine);
1213 currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1217 public void consumeStringLiteral() throws InvalidInputException {
1219 boolean openDollarBrace = false;
1220 // consume next character
1221 unicodeAsBackSlash = false;
1222 currentCharacter = source[currentPosition++];
1223 while (currentCharacter != '"' || openDollarBrace) {
1224 /** ** in PHP \r and \n are valid in string literals *** */
1225 if (currentCharacter == '\\') {
1226 int escapeSize = currentPosition;
1227 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1228 // scanEscapeCharacter make a side effect on this value and we need
1229 // the previous value few lines down this one
1230 scanDoubleQuotedEscapeCharacter();
1231 escapeSize = currentPosition - escapeSize;
1232 if (withoutUnicodePtr == 0) {
1233 // buffer all the entries that have been left aside....
1234 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1235 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1236 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1237 } else { // overwrite the / in the buffer
1238 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1239 if (backSlashAsUnicodeInString) { // there are TWO \ in the stream
1240 // where only one is correct
1241 withoutUnicodePtr--;
1244 } else if (currentCharacter == '$' && source[currentPosition] == '{') {
1245 openDollarBrace = true;
1246 } else if (currentCharacter == '{' && source[currentPosition] == '$') {
1247 openDollarBrace = true;
1248 } else if (currentCharacter == '}') {
1249 openDollarBrace = false;
1250 } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1251 if (recordLineSeparator) {
1252 pushLineSeparator();
1255 // consume next character
1256 unicodeAsBackSlash = false;
1257 currentCharacter = source[currentPosition++];
1258 if (withoutUnicodePtr != 0) {
1259 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1262 } catch (IndexOutOfBoundsException e) {
1263 // reset end position for error reporting
1264 currentPosition -= 2;
1265 throw new InvalidInputException(UNTERMINATED_STRING);
1266 } catch (InvalidInputException e) {
1267 if (e.getMessage().equals(INVALID_ESCAPE)) {
1268 // relocate if finding another quote fairly close: thus unicode
1269 // '/u000D' will be fully consumed
1270 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1271 if (currentPosition + lookAhead == source.length)
1273 if (source[currentPosition + lookAhead] == '\n')
1275 if (source[currentPosition + lookAhead] == '\"') {
1276 currentPosition += lookAhead + 1;
1283 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1284 // //$NON-NLS-?$ where ? is an
1286 if (currentLine == null) {
1287 currentLine = new NLSLine();
1288 lines.add(currentLine);
1290 currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1294 public int getNextToken() throws InvalidInputException {
1296 return getInlinedHTMLToken(currentPosition);
1298 if (fFillerToken != TokenNameEOF) {
1300 startPosition = currentPosition;
1301 tempToken = fFillerToken;
1302 fFillerToken = TokenNameEOF;
1305 this.wasAcr = false;
1307 jumpOverMethodBody();
1309 return currentPosition > source.length ? TokenNameEOF : TokenNameRBRACE;
1313 withoutUnicodePtr = 0;
1314 // ---------Consume white space and handles startPosition---------
1315 int whiteStart = currentPosition;
1316 startPosition = currentPosition;
1317 currentCharacter = source[currentPosition++];
1319 while ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) {
1320 startPosition = currentPosition;
1321 currentCharacter = source[currentPosition++];
1322 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1323 checkNonExternalizeString();
1324 if (recordLineSeparator) {
1325 pushLineSeparator();
1331 if (tokenizeWhiteSpace && (whiteStart != currentPosition - 1)) {
1332 // reposition scanner in case we are interested by spaces as tokens
1334 startPosition = whiteStart;
1335 return TokenNameWHITESPACE;
1337 // little trick to get out in the middle of a source compuation
1338 if (currentPosition > eofPosition)
1339 return TokenNameEOF;
1340 // ---------Identify the next token-------------
1341 switch (currentCharacter) {
1343 return getCastOrParen();
1345 return TokenNameRPAREN;
1347 return TokenNameLBRACE;
1349 return TokenNameRBRACE;
1351 return TokenNameLBRACKET;
1353 return TokenNameRBRACKET;
1355 return TokenNameSEMICOLON;
1357 return TokenNameCOMMA;
1359 if (getNextChar('='))
1360 return TokenNameDOT_EQUAL;
1361 if (getNextCharAsDigit())
1362 return scanNumber(true);
1363 return TokenNameDOT;
1366 if ((test = getNextChar('+', '=')) == 0)
1367 return TokenNamePLUS_PLUS;
1369 return TokenNamePLUS_EQUAL;
1370 return TokenNamePLUS;
1374 if ((test = getNextChar('-', '=')) == 0)
1375 return TokenNameMINUS_MINUS;
1377 return TokenNameMINUS_EQUAL;
1378 if (getNextChar('>'))
1379 return TokenNameMINUS_GREATER;
1380 return TokenNameMINUS;
1383 if (getNextChar('='))
1384 return TokenNameTWIDDLE_EQUAL;
1385 return TokenNameTWIDDLE;
1387 if (getNextChar('=')) {
1388 if (getNextChar('=')) {
1389 return TokenNameNOT_EQUAL_EQUAL;
1391 return TokenNameNOT_EQUAL;
1393 return TokenNameNOT;
1395 if (getNextChar('='))
1396 return TokenNameMULTIPLY_EQUAL;
1397 return TokenNameMULTIPLY;
1399 if (getNextChar('='))
1400 return TokenNameREMAINDER_EQUAL;
1401 return TokenNameREMAINDER;
1403 int oldPosition = currentPosition;
1405 currentCharacter = source[currentPosition++];
1406 } catch (IndexOutOfBoundsException e) {
1407 currentPosition = oldPosition;
1408 return TokenNameLESS;
1410 switch (currentCharacter) {
1412 return TokenNameLESS_EQUAL;
1414 return TokenNameNOT_EQUAL;
1416 if (getNextChar('='))
1417 return TokenNameLEFT_SHIFT_EQUAL;
1418 if (getNextChar('<')) {
1419 currentCharacter = source[currentPosition++];
1420 while (Character.isWhitespace(currentCharacter)) {
1421 currentCharacter = source[currentPosition++];
1423 int heredocStart = currentPosition - 1;
1424 int heredocLength = 0;
1425 if (isPHPIdentifierStart(currentCharacter)) {
1426 currentCharacter = source[currentPosition++];
1428 return TokenNameERROR;
1430 while (isPHPIdentifierPart(currentCharacter)) {
1431 currentCharacter = source[currentPosition++];
1433 heredocLength = currentPosition - heredocStart - 1;
1434 // heredoc end-tag determination
1435 boolean endTag = true;
1438 ch = source[currentPosition++];
1439 if (ch == '\r' || ch == '\n') {
1440 if (recordLineSeparator) {
1441 pushLineSeparator();
1445 for (int i = 0; i < heredocLength; i++) {
1446 if (source[currentPosition + i] != source[heredocStart + i]) {
1452 currentPosition += heredocLength - 1;
1453 currentCharacter = source[currentPosition++];
1454 break; // do...while loop
1460 return TokenNameHEREDOC;
1462 return TokenNameLEFT_SHIFT;
1464 currentPosition = oldPosition;
1465 return TokenNameLESS;
1469 if ((test = getNextChar('=', '>')) == 0)
1470 return TokenNameGREATER_EQUAL;
1472 if ((test = getNextChar('=', '>')) == 0)
1473 return TokenNameRIGHT_SHIFT_EQUAL;
1474 return TokenNameRIGHT_SHIFT;
1476 return TokenNameGREATER;
1479 if (getNextChar('=')) {
1480 if (getNextChar('=')) {
1481 return TokenNameEQUAL_EQUAL_EQUAL;
1483 return TokenNameEQUAL_EQUAL;
1485 if (getNextChar('>'))
1486 return TokenNameEQUAL_GREATER;
1487 return TokenNameEQUAL;
1490 if ((test = getNextChar('&', '=')) == 0)
1491 return TokenNameAND_AND;
1493 return TokenNameAND_EQUAL;
1494 return TokenNameAND;
1498 if ((test = getNextChar('|', '=')) == 0)
1499 return TokenNameOR_OR;
1501 return TokenNameOR_EQUAL;
1505 if (getNextChar('='))
1506 return TokenNameXOR_EQUAL;
1507 return TokenNameXOR;
1509 if (getNextChar('>')) {
1511 if (currentPosition == source.length) {
1513 return TokenNameINLINE_HTML;
1515 return getInlinedHTMLToken(currentPosition - 2);
1517 return TokenNameQUESTION;
1519 if (getNextChar(':'))
1520 return TokenNamePAAMAYIM_NEKUDOTAYIM;
1521 return TokenNameCOLON;
1525 consumeStringConstant();
1526 return TokenNameStringSingleQuote;
1528 // if (tokenizeStrings) {
1529 consumeStringLiteral();
1530 return TokenNameStringDoubleQuote;
1532 // return TokenNameEncapsedString2;
1534 // if (tokenizeStrings) {
1535 consumeStringInterpolated();
1536 return TokenNameStringInterpolated;
1538 // return TokenNameEncapsedString0;
1541 char startChar = currentCharacter;
1542 if (getNextChar('=') && startChar == '/') {
1543 return TokenNameDIVIDE_EQUAL;
1546 if ((startChar == '#') || (test = getNextChar('/', '*')) == 0) {
1548 this.lastCommentLinePosition = this.currentPosition;
1549 int endPositionForLineComment = 0;
1550 try { // get the next char
1551 currentCharacter = source[currentPosition++];
1552 // if (((currentCharacter = source[currentPosition++])
1554 // && (source[currentPosition] == 'u')) {
1555 // //-------------unicode traitement ------------
1556 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1557 // currentPosition++;
1558 // while (source[currentPosition] == 'u') {
1559 // currentPosition++;
1562 // Character.getNumericValue(source[currentPosition++]))
1566 // Character.getNumericValue(source[currentPosition++]))
1570 // Character.getNumericValue(source[currentPosition++]))
1574 // Character.getNumericValue(source[currentPosition++]))
1578 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1580 // currentCharacter =
1581 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1584 // handle the \\u case manually into comment
1585 // if (currentCharacter == '\\') {
1586 // if (source[currentPosition] == '\\')
1587 // currentPosition++;
1588 // } //jump over the \\
1589 boolean isUnicode = false;
1590 while (currentCharacter != '\r' && currentCharacter != '\n') {
1591 this.lastCommentLinePosition = this.currentPosition;
1592 if (currentCharacter == '?') {
1593 if (getNextChar('>')) {
1594 // ?> breaks line comments
1595 startPosition = currentPosition - 2;
1597 return TokenNameINLINE_HTML;
1600 // get the next char
1602 currentCharacter = source[currentPosition++];
1603 // if (((currentCharacter = source[currentPosition++])
1605 // && (source[currentPosition] == 'u')) {
1606 // isUnicode = true;
1607 // //-------------unicode traitement ------------
1608 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1609 // currentPosition++;
1610 // while (source[currentPosition] == 'u') {
1611 // currentPosition++;
1614 // Character.getNumericValue(source[currentPosition++]))
1618 // Character.getNumericValue(
1619 // source[currentPosition++]))
1623 // Character.getNumericValue(
1624 // source[currentPosition++]))
1628 // Character.getNumericValue(
1629 // source[currentPosition++]))
1633 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1635 // currentCharacter =
1636 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1639 // handle the \\u case manually into comment
1640 // if (currentCharacter == '\\') {
1641 // if (source[currentPosition] == '\\')
1642 // currentPosition++;
1643 // } //jump over the \\
1646 endPositionForLineComment = currentPosition - 6;
1648 endPositionForLineComment = currentPosition - 1;
1650 // recordComment(false);
1651 recordComment(TokenNameCOMMENT_LINE);
1652 if (this.taskTags != null)
1653 checkTaskTag(this.startPosition, this.currentPosition);
1654 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1655 checkNonExternalizeString();
1656 if (recordLineSeparator) {
1658 pushUnicodeLineSeparator();
1660 pushLineSeparator();
1666 if (tokenizeComments) {
1668 currentPosition = endPositionForLineComment;
1669 // reset one character behind
1671 return TokenNameCOMMENT_LINE;
1673 } catch (IndexOutOfBoundsException e) { // an eof will them
1675 if (tokenizeComments) {
1677 // reset one character behind
1678 return TokenNameCOMMENT_LINE;
1684 // traditional and annotation comment
1685 boolean isJavadoc = false, star = false;
1686 // consume next character
1687 unicodeAsBackSlash = false;
1688 currentCharacter = source[currentPosition++];
1689 // if (((currentCharacter = source[currentPosition++]) ==
1691 // && (source[currentPosition] == 'u')) {
1692 // getNextUnicodeChar();
1694 // if (withoutUnicodePtr != 0) {
1695 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1696 // currentCharacter;
1699 if (currentCharacter == '*') {
1703 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1704 checkNonExternalizeString();
1705 if (recordLineSeparator) {
1706 pushLineSeparator();
1711 try { // get the next char
1712 currentCharacter = source[currentPosition++];
1713 // if (((currentCharacter = source[currentPosition++])
1715 // && (source[currentPosition] == 'u')) {
1716 // //-------------unicode traitement ------------
1717 // getNextUnicodeChar();
1719 // handle the \\u case manually into comment
1720 // if (currentCharacter == '\\') {
1721 // if (source[currentPosition] == '\\')
1722 // currentPosition++;
1723 // //jump over the \\
1725 // empty comment is not a javadoc /**/
1726 if (currentCharacter == '/') {
1729 // loop until end of comment */
1730 while ((currentCharacter != '/') || (!star)) {
1731 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1732 checkNonExternalizeString();
1733 if (recordLineSeparator) {
1734 pushLineSeparator();
1739 star = currentCharacter == '*';
1741 currentCharacter = source[currentPosition++];
1742 // if (((currentCharacter = source[currentPosition++])
1744 // && (source[currentPosition] == 'u')) {
1745 // //-------------unicode traitement ------------
1746 // getNextUnicodeChar();
1748 // handle the \\u case manually into comment
1749 // if (currentCharacter == '\\') {
1750 // if (source[currentPosition] == '\\')
1751 // currentPosition++;
1752 // } //jump over the \\
1754 // recordComment(isJavadoc);
1756 recordComment(TokenNameCOMMENT_PHPDOC);
1758 recordComment(TokenNameCOMMENT_BLOCK);
1761 if (tokenizeComments) {
1763 return TokenNameCOMMENT_PHPDOC;
1764 return TokenNameCOMMENT_BLOCK;
1767 if (this.taskTags != null) {
1768 checkTaskTag(this.startPosition, this.currentPosition);
1770 } catch (IndexOutOfBoundsException e) {
1771 // reset end position for error reporting
1772 currentPosition -= 2;
1773 throw new InvalidInputException(UNTERMINATED_COMMENT);
1777 return TokenNameDIVIDE;
1781 return TokenNameEOF;
1782 // the atEnd may not be <currentPosition == source.length> if
1783 // source is only some part of a real (external) stream
1784 throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$
1786 if (currentCharacter == '$') {
1787 int oldPosition = currentPosition;
1789 currentCharacter = source[currentPosition++];
1790 if (isPHPIdentifierStart(currentCharacter)) {
1791 return scanIdentifierOrKeyword(true);
1793 currentPosition = oldPosition;
1794 return TokenNameDOLLAR;
1796 } catch (IndexOutOfBoundsException e) {
1797 currentPosition = oldPosition;
1798 return TokenNameDOLLAR;
1801 if (isPHPIdentifierStart(currentCharacter))
1802 return scanIdentifierOrKeyword(false);
1803 if (Character.isDigit(currentCharacter))
1804 return scanNumber(false);
1805 return TokenNameERROR;
1808 } // -----------------end switch while try--------------------
1809 catch (IndexOutOfBoundsException e) {
1812 return TokenNameEOF;
1817 * @throws InvalidInputException
1819 private int getInlinedHTMLToken(int start) throws InvalidInputException {
1820 boolean phpShortTag = false; // true, if <?= detected
1821 if (currentPosition > source.length) {
1822 currentPosition = source.length;
1823 return TokenNameEOF;
1825 startPosition = start;
1828 currentCharacter = source[currentPosition++];
1829 if (currentCharacter == '<') {
1830 if (getNextChar('?')) {
1831 currentCharacter = source[currentPosition++];
1832 if ((currentCharacter != 'P') && (currentCharacter != 'p')) {
1833 if (currentCharacter != '=') { // <?=
1835 phpShortTag = false;
1840 if (ignorePHPOneLiner) { // for CodeFormatter
1841 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1844 fFillerToken = TokenNameECHO_INVISIBLE;
1846 return TokenNameINLINE_HTML;
1851 fFillerToken = TokenNameECHO_INVISIBLE;
1853 return TokenNameINLINE_HTML;
1856 int test = getNextChar('H', 'h');
1858 test = getNextChar('P', 'p');
1861 if (ignorePHPOneLiner) {
1862 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1864 return TokenNameINLINE_HTML;
1868 return TokenNameINLINE_HTML;
1876 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1877 if (recordLineSeparator) {
1878 pushLineSeparator();
1883 } // -----------------while--------------------
1885 return TokenNameINLINE_HTML;
1886 } // -----------------try--------------------
1887 catch (IndexOutOfBoundsException e) {
1888 startPosition = start;
1892 return TokenNameINLINE_HTML;
1896 * check if the PHP is only in this line (for CodeFormatter)
1900 private int lookAheadLinePHPTag() {
1901 int currentPositionInLine = currentPosition;
1902 char previousCharInLine = ' ';
1903 char currentCharInLine = ' ';
1904 boolean singleQuotedStringActive = false;
1905 boolean doubleQuotedStringActive = false;
1908 // look ahead in this line
1910 previousCharInLine = currentCharInLine;
1911 currentCharInLine = source[currentPositionInLine++];
1912 switch (currentCharInLine) {
1914 if (previousCharInLine == '?') {
1915 // update the scanner's current Position in the source
1916 currentPosition = currentPositionInLine;
1917 // use as "dummy" token
1918 return TokenNameEOF;
1922 if (doubleQuotedStringActive) {
1923 // ignore escaped characters in double quoted strings
1924 previousCharInLine = currentCharInLine;
1925 currentCharInLine = source[currentPositionInLine++];
1928 if (doubleQuotedStringActive) {
1929 doubleQuotedStringActive = false;
1931 if (!singleQuotedStringActive) {
1932 doubleQuotedStringActive = true;
1937 if (singleQuotedStringActive) {
1938 if (previousCharInLine != '\\') {
1939 singleQuotedStringActive = false;
1942 if (!doubleQuotedStringActive) {
1943 singleQuotedStringActive = true;
1949 return TokenNameINLINE_HTML;
1951 if (!singleQuotedStringActive && !doubleQuotedStringActive) {
1953 return TokenNameINLINE_HTML;
1957 if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1959 return TokenNameINLINE_HTML;
1963 if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1965 return TokenNameINLINE_HTML;
1970 } catch (IndexOutOfBoundsException e) {
1972 currentPosition = currentPositionInLine;
1973 return TokenNameINLINE_HTML;
1977 // public final void getNextUnicodeChar()
1978 // throws IndexOutOfBoundsException, InvalidInputException {
1980 // //handle the case of unicode.
1981 // //when a unicode appears then we must use a buffer that holds char
1983 // //At the end of this method currentCharacter holds the new visited char
1984 // //and currentPosition points right next after it
1986 // //ALL getNextChar.... ARE OPTIMIZED COPIES
1988 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
1989 // currentPosition++;
1990 // while (source[currentPosition] == 'u') {
1991 // currentPosition++;
1995 // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
1997 // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
1999 // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
2001 // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
2003 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2005 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2006 // //need the unicode buffer
2007 // if (withoutUnicodePtr == 0) {
2008 // //buffer all the entries that have been left aside....
2009 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
2010 // System.arraycopy(
2013 // withoutUnicodeBuffer,
2015 // withoutUnicodePtr);
2017 // //fill the buffer with the char
2018 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2020 // unicodeAsBackSlash = currentCharacter == '\\';
2023 * Tokenize a method body, assuming that curly brackets are properly balanced.
2025 public final void jumpOverMethodBody() {
2026 this.wasAcr = false;
2029 while (true) { // loop for jumping over comments
2030 // ---------Consume white space and handles startPosition---------
2031 boolean isWhiteSpace;
2033 startPosition = currentPosition;
2034 currentCharacter = source[currentPosition++];
2035 // if (((currentCharacter = source[currentPosition++]) == '\\')
2036 // && (source[currentPosition] == 'u')) {
2037 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
2039 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2040 pushLineSeparator();
2041 isWhiteSpace = Character.isWhitespace(currentCharacter);
2043 } while (isWhiteSpace);
2044 // -------consume token until } is found---------
2045 switch (currentCharacter) {
2056 test = getNextChar('\\');
2059 scanDoubleQuotedEscapeCharacter();
2060 } catch (InvalidInputException ex) {
2064 // try { // consume next character
2065 unicodeAsBackSlash = false;
2066 currentCharacter = source[currentPosition++];
2067 // if (((currentCharacter = source[currentPosition++]) == '\\')
2068 // && (source[currentPosition] == 'u')) {
2069 // getNextUnicodeChar();
2071 if (withoutUnicodePtr != 0) {
2072 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2075 // } catch (InvalidInputException ex) {
2083 // try { // consume next character
2084 unicodeAsBackSlash = false;
2085 currentCharacter = source[currentPosition++];
2086 // if (((currentCharacter = source[currentPosition++]) == '\\')
2087 // && (source[currentPosition] == 'u')) {
2088 // getNextUnicodeChar();
2090 if (withoutUnicodePtr != 0) {
2091 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2094 // } catch (InvalidInputException ex) {
2096 while (currentCharacter != '"') {
2097 if (currentCharacter == '\r') {
2098 if (source[currentPosition] == '\n')
2101 // the string cannot go further that the line
2103 if (currentCharacter == '\n') {
2105 // the string cannot go further that the line
2107 if (currentCharacter == '\\') {
2109 scanDoubleQuotedEscapeCharacter();
2110 } catch (InvalidInputException ex) {
2114 // try { // consume next character
2115 unicodeAsBackSlash = false;
2116 currentCharacter = source[currentPosition++];
2117 // if (((currentCharacter = source[currentPosition++]) == '\\')
2118 // && (source[currentPosition] == 'u')) {
2119 // getNextUnicodeChar();
2121 if (withoutUnicodePtr != 0) {
2122 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2125 // } catch (InvalidInputException ex) {
2128 } catch (IndexOutOfBoundsException e) {
2134 if ((test = getNextChar('/', '*')) == 0) {
2137 // get the next char
2138 currentCharacter = source[currentPosition++];
2139 // if (((currentCharacter = source[currentPosition++]) ==
2141 // && (source[currentPosition] == 'u')) {
2142 // //-------------unicode traitement ------------
2143 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2144 // currentPosition++;
2145 // while (source[currentPosition] == 'u') {
2146 // currentPosition++;
2149 // Character.getNumericValue(source[currentPosition++]))
2153 // Character.getNumericValue(source[currentPosition++]))
2157 // Character.getNumericValue(source[currentPosition++]))
2161 // Character.getNumericValue(source[currentPosition++]))
2164 // //error don't care of the value
2165 // currentCharacter = 'A';
2166 // } //something different from \n and \r
2168 // currentCharacter =
2169 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2172 while (currentCharacter != '\r' && currentCharacter != '\n') {
2173 // get the next char
2174 currentCharacter = source[currentPosition++];
2175 // if (((currentCharacter = source[currentPosition++])
2177 // && (source[currentPosition] == 'u')) {
2178 // //-------------unicode traitement ------------
2179 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2180 // currentPosition++;
2181 // while (source[currentPosition] == 'u') {
2182 // currentPosition++;
2185 // Character.getNumericValue(source[currentPosition++]))
2189 // Character.getNumericValue(source[currentPosition++]))
2193 // Character.getNumericValue(source[currentPosition++]))
2197 // Character.getNumericValue(source[currentPosition++]))
2200 // //error don't care of the value
2201 // currentCharacter = 'A';
2202 // } //something different from \n and \r
2204 // currentCharacter =
2205 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2209 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2210 pushLineSeparator();
2211 } catch (IndexOutOfBoundsException e) {
2212 } // an eof will them be generated
2216 // traditional and annotation comment
2217 boolean star = false;
2218 // try { // consume next character
2219 unicodeAsBackSlash = false;
2220 currentCharacter = source[currentPosition++];
2221 // if (((currentCharacter = source[currentPosition++]) == '\\')
2222 // && (source[currentPosition] == 'u')) {
2223 // getNextUnicodeChar();
2225 if (withoutUnicodePtr != 0) {
2226 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2229 // } catch (InvalidInputException ex) {
2231 if (currentCharacter == '*') {
2234 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2235 pushLineSeparator();
2236 try { // get the next char
2237 currentCharacter = source[currentPosition++];
2238 // if (((currentCharacter = source[currentPosition++]) ==
2240 // && (source[currentPosition] == 'u')) {
2241 // //-------------unicode traitement ------------
2242 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2243 // currentPosition++;
2244 // while (source[currentPosition] == 'u') {
2245 // currentPosition++;
2248 // Character.getNumericValue(source[currentPosition++]))
2252 // Character.getNumericValue(source[currentPosition++]))
2256 // Character.getNumericValue(source[currentPosition++]))
2260 // Character.getNumericValue(source[currentPosition++]))
2263 // //error don't care of the value
2264 // currentCharacter = 'A';
2265 // } //something different from * and /
2267 // currentCharacter =
2268 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2271 // loop until end of comment */
2272 while ((currentCharacter != '/') || (!star)) {
2273 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2274 pushLineSeparator();
2275 star = currentCharacter == '*';
2277 currentCharacter = source[currentPosition++];
2278 // if (((currentCharacter = source[currentPosition++])
2280 // && (source[currentPosition] == 'u')) {
2281 // //-------------unicode traitement ------------
2282 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2283 // currentPosition++;
2284 // while (source[currentPosition] == 'u') {
2285 // currentPosition++;
2288 // Character.getNumericValue(source[currentPosition++]))
2292 // Character.getNumericValue(source[currentPosition++]))
2296 // Character.getNumericValue(source[currentPosition++]))
2300 // Character.getNumericValue(source[currentPosition++]))
2303 // //error don't care of the value
2304 // currentCharacter = 'A';
2305 // } //something different from * and /
2307 // currentCharacter =
2308 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2312 } catch (IndexOutOfBoundsException e) {
2320 if (isPHPIdentOrVarStart(currentCharacter)) {
2322 scanIdentifierOrKeyword((currentCharacter == '$'));
2323 } catch (InvalidInputException ex) {
2328 if (ObviousIdentCharNatures[currentCharacter] == C_DIGIT) {
2329 // if (Character.isDigit(currentCharacter)) {
2332 } catch (InvalidInputException ex) {
2339 // -----------------end switch while try--------------------
2340 } catch (IndexOutOfBoundsException e) {
2341 } catch (InvalidInputException e) {
2346 // public final boolean jumpOverUnicodeWhiteSpace()
2347 // throws InvalidInputException {
2349 // //handle the case of unicode. Jump over the next whiteSpace
2350 // //making startPosition pointing on the next available char
2351 // //On false, the currentCharacter is filled up with a potential
2355 // this.wasAcr = false;
2356 // int c1, c2, c3, c4;
2357 // int unicodeSize = 6;
2358 // currentPosition++;
2359 // while (source[currentPosition] == 'u') {
2360 // currentPosition++;
2364 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2366 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2368 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2370 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2372 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2375 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2376 // if (recordLineSeparator
2377 // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2378 // pushLineSeparator();
2379 // if (Character.isWhitespace(currentCharacter))
2382 // //buffer the new char which is not a white space
2383 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2384 // //withoutUnicodePtr == 1 is true here
2386 // } catch (IndexOutOfBoundsException e) {
2387 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2390 public final int[] getLineEnds() {
2391 // return a bounded copy of this.lineEnds
2393 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0, linePtr + 1);
2397 public char[] getSource() {
2401 public static boolean isIdentifierOrKeyword(int token) {
2402 return (token == TokenNameIdentifier) || (token > TokenNameKEYWORD);
2405 final char[] optimizedCurrentTokenSource1() {
2406 // return always the same char[] build only once
2407 // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2408 char charOne = source[startPosition];
2463 return new char[] { charOne };
2467 final char[] optimizedCurrentTokenSource2() {
2469 c0 = source[startPosition];
2470 c1 = source[startPosition + 1];
2472 // return always the same char[] build only once
2473 // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2476 return charArray_va;
2478 return charArray_vb;
2480 return charArray_vc;
2482 return charArray_vd;
2484 return charArray_ve;
2486 return charArray_vf;
2488 return charArray_vg;
2490 return charArray_vh;
2492 return charArray_vi;
2494 return charArray_vj;
2496 return charArray_vk;
2498 return charArray_vl;
2500 return charArray_vm;
2502 return charArray_vn;
2504 return charArray_vo;
2506 return charArray_vp;
2508 return charArray_vq;
2510 return charArray_vr;
2512 return charArray_vs;
2514 return charArray_vt;
2516 return charArray_vu;
2518 return charArray_vv;
2520 return charArray_vw;
2522 return charArray_vx;
2524 return charArray_vy;
2526 return charArray_vz;
2529 // try to return the same char[] build only once
2530 int hash = ((c0 << 6) + c1) % TableSize;
2531 char[][] table = charArray_length[0][hash];
2533 while (++i < InternalTableSize) {
2534 char[] charArray = table[i];
2535 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2538 // ---------other side---------
2540 int max = newEntry2;
2541 while (++i <= max) {
2542 char[] charArray = table[i];
2543 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2546 // --------add the entry-------
2547 if (++max >= InternalTableSize)
2550 table[max] = (r = new char[] { c0, c1 });
2555 final char[] optimizedCurrentTokenSource3() {
2556 // try to return the same char[] build only once
2558 int hash = (((c0 = source[startPosition]) << 12) + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2560 char[][] table = charArray_length[1][hash];
2562 while (++i < InternalTableSize) {
2563 char[] charArray = table[i];
2564 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2567 // ---------other side---------
2569 int max = newEntry3;
2570 while (++i <= max) {
2571 char[] charArray = table[i];
2572 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2575 // --------add the entry-------
2576 if (++max >= InternalTableSize)
2579 table[max] = (r = new char[] { c0, c1, c2 });
2584 final char[] optimizedCurrentTokenSource4() {
2585 // try to return the same char[] build only once
2586 char c0, c1, c2, c3;
2587 long hash = ((((long) (c0 = source[startPosition])) << 18) + ((c1 = source[startPosition + 1]) << 12)
2588 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2590 char[][] table = charArray_length[2][(int) hash];
2592 while (++i < InternalTableSize) {
2593 char[] charArray = table[i];
2594 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2597 // ---------other side---------
2599 int max = newEntry4;
2600 while (++i <= max) {
2601 char[] charArray = table[i];
2602 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2605 // --------add the entry-------
2606 if (++max >= InternalTableSize)
2609 table[max] = (r = new char[] { c0, c1, c2, c3 });
2614 final char[] optimizedCurrentTokenSource5() {
2615 // try to return the same char[] build only once
2616 char c0, c1, c2, c3, c4;
2617 long hash = ((((long) (c0 = source[startPosition])) << 24) + (((long) (c1 = source[startPosition + 1])) << 18)
2618 + ((c2 = source[startPosition + 2]) << 12) + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2620 char[][] table = charArray_length[3][(int) hash];
2622 while (++i < InternalTableSize) {
2623 char[] charArray = table[i];
2624 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2627 // ---------other side---------
2629 int max = newEntry5;
2630 while (++i <= max) {
2631 char[] charArray = table[i];
2632 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2635 // --------add the entry-------
2636 if (++max >= InternalTableSize)
2639 table[max] = (r = new char[] { c0, c1, c2, c3, c4 });
2644 final char[] optimizedCurrentTokenSource6() {
2645 // try to return the same char[] build only once
2646 char c0, c1, c2, c3, c4, c5;
2647 long hash = ((((long) (c0 = source[startPosition])) << 32) + (((long) (c1 = source[startPosition + 1])) << 24)
2648 + (((long) (c2 = source[startPosition + 2])) << 18) + ((c3 = source[startPosition + 3]) << 12)
2649 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2651 char[][] table = charArray_length[4][(int) hash];
2653 while (++i < InternalTableSize) {
2654 char[] charArray = table[i];
2655 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2656 && (c5 == charArray[5]))
2659 // ---------other side---------
2661 int max = newEntry6;
2662 while (++i <= max) {
2663 char[] charArray = table[i];
2664 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2665 && (c5 == charArray[5]))
2668 // --------add the entry-------
2669 if (++max >= InternalTableSize)
2672 table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 });
2677 public final void pushLineSeparator() throws InvalidInputException {
2678 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2679 final int INCREMENT = 250;
2680 if (this.checkNonExternalizedStringLiterals) {
2681 // reinitialize the current line for non externalize strings purpose
2684 // currentCharacter is at position currentPosition-1
2686 if (currentCharacter == '\r') {
2687 int separatorPos = currentPosition - 1;
2688 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2690 // System.out.println("CR-" + separatorPos);
2692 lineEnds[++linePtr] = separatorPos;
2693 } catch (IndexOutOfBoundsException e) {
2694 // linePtr value is correct
2695 int oldLength = lineEnds.length;
2696 int[] old = lineEnds;
2697 lineEnds = new int[oldLength + INCREMENT];
2698 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2699 lineEnds[linePtr] = separatorPos;
2701 // look-ahead for merged cr+lf
2703 if (source[currentPosition] == '\n') {
2704 // System.out.println("look-ahead LF-" + currentPosition);
2705 lineEnds[linePtr] = currentPosition;
2711 } catch (IndexOutOfBoundsException e) {
2716 if (currentCharacter == '\n') {
2717 // must merge eventual cr followed by lf
2718 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2719 // System.out.println("merge LF-" + (currentPosition - 1));
2720 lineEnds[linePtr] = currentPosition - 1;
2722 int separatorPos = currentPosition - 1;
2723 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2725 // System.out.println("LF-" + separatorPos);
2727 lineEnds[++linePtr] = separatorPos;
2728 } catch (IndexOutOfBoundsException e) {
2729 // linePtr value is correct
2730 int oldLength = lineEnds.length;
2731 int[] old = lineEnds;
2732 lineEnds = new int[oldLength + INCREMENT];
2733 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2734 lineEnds[linePtr] = separatorPos;
2742 public final void pushUnicodeLineSeparator() {
2743 // isUnicode means that the \r or \n has been read as a unicode character
2744 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2745 final int INCREMENT = 250;
2746 // currentCharacter is at position currentPosition-1
2747 if (this.checkNonExternalizedStringLiterals) {
2748 // reinitialize the current line for non externalize strings purpose
2752 if (currentCharacter == '\r') {
2753 int separatorPos = currentPosition - 6;
2754 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2756 // System.out.println("CR-" + separatorPos);
2758 lineEnds[++linePtr] = separatorPos;
2759 } catch (IndexOutOfBoundsException e) {
2760 // linePtr value is correct
2761 int oldLength = lineEnds.length;
2762 int[] old = lineEnds;
2763 lineEnds = new int[oldLength + INCREMENT];
2764 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2765 lineEnds[linePtr] = separatorPos;
2767 // look-ahead for merged cr+lf
2768 if (source[currentPosition] == '\n') {
2769 // System.out.println("look-ahead LF-" + currentPosition);
2770 lineEnds[linePtr] = currentPosition;
2778 if (currentCharacter == '\n') {
2779 // must merge eventual cr followed by lf
2780 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2781 // System.out.println("merge LF-" + (currentPosition - 1));
2782 lineEnds[linePtr] = currentPosition - 6;
2784 int separatorPos = currentPosition - 6;
2785 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2787 // System.out.println("LF-" + separatorPos);
2789 lineEnds[++linePtr] = separatorPos;
2790 } catch (IndexOutOfBoundsException e) {
2791 // linePtr value is correct
2792 int oldLength = lineEnds.length;
2793 int[] old = lineEnds;
2794 lineEnds = new int[oldLength + INCREMENT];
2795 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2796 lineEnds[linePtr] = separatorPos;
2804 public void recordComment(int token) {
2806 int stopPosition = this.currentPosition;
2808 case TokenNameCOMMENT_LINE:
2809 stopPosition = -this.lastCommentLinePosition;
2811 case TokenNameCOMMENT_BLOCK:
2812 stopPosition = -this.currentPosition;
2816 // a new comment is recorded
2817 int length = this.commentStops.length;
2818 if (++this.commentPtr >= length) {
2819 System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length);
2820 // grows the positions buffers too
2821 System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length);
2823 this.commentStops[this.commentPtr] = stopPosition;
2824 this.commentStarts[this.commentPtr] = this.startPosition;
2827 // public final void recordComment(boolean isJavadoc) {
2828 // // a new annotation comment is recorded
2830 // commentStops[++commentPtr] = isJavadoc
2831 // ? currentPosition
2832 // : -currentPosition;
2833 // } catch (IndexOutOfBoundsException e) {
2834 // int oldStackLength = commentStops.length;
2835 // int[] oldStack = commentStops;
2836 // commentStops = new int[oldStackLength + 30];
2837 // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
2838 // commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition;
2839 // //grows the positions buffers too
2840 // int[] old = commentStarts;
2841 // commentStarts = new int[oldStackLength + 30];
2842 // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
2844 // //the buffer is of a correct size here
2845 // commentStarts[commentPtr] = startPosition;
2847 public void resetTo(int begin, int end) {
2848 // reset the scanner to a given position where it may rescan again
2850 initialPosition = startPosition = currentPosition = begin;
2851 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
2852 commentPtr = -1; // reset comment stack
2855 public final void scanSingleQuotedEscapeCharacter() throws InvalidInputException {
2856 // the string with "\\u" is a legal string of two chars \ and u
2857 // thus we use a direct access to the source (for regular cases).
2858 // if (unicodeAsBackSlash) {
2859 // // consume next character
2860 // unicodeAsBackSlash = false;
2861 // if (((currentCharacter = source[currentPosition++]) == '\\')
2862 // && (source[currentPosition] == 'u')) {
2863 // getNextUnicodeChar();
2865 // if (withoutUnicodePtr != 0) {
2866 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2870 currentCharacter = source[currentPosition++];
2871 switch (currentCharacter) {
2873 currentCharacter = '\'';
2876 currentCharacter = '\\';
2879 currentCharacter = '\\';
2884 public final void scanDoubleQuotedEscapeCharacter() throws InvalidInputException {
2885 currentCharacter = source[currentPosition++];
2886 switch (currentCharacter) {
2888 // currentCharacter = '\b';
2891 currentCharacter = '\t';
2894 currentCharacter = '\n';
2897 // currentCharacter = '\f';
2900 currentCharacter = '\r';
2903 currentCharacter = '\"';
2906 currentCharacter = '\'';
2909 currentCharacter = '\\';
2912 currentCharacter = '$';
2915 // -----------octal escape--------------
2917 // OctalDigit OctalDigit
2918 // ZeroToThree OctalDigit OctalDigit
2919 int number = Character.getNumericValue(currentCharacter);
2920 if (number >= 0 && number <= 7) {
2921 boolean zeroToThreeNot = number > 3;
2922 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2923 int digit = Character.getNumericValue(currentCharacter);
2924 if (digit >= 0 && digit <= 7) {
2925 number = (number * 8) + digit;
2926 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2927 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
2928 // Digit --> ignore last character
2931 digit = Character.getNumericValue(currentCharacter);
2932 if (digit >= 0 && digit <= 7) {
2933 // has read \ZeroToThree OctalDigit OctalDigit
2934 number = (number * 8) + digit;
2935 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
2936 // --> ignore last character
2940 } else { // has read \OctalDigit NonDigit--> ignore last
2944 } else { // has read \OctalDigit NonOctalDigit--> ignore last
2948 } else { // has read \OctalDigit --> ignore last character
2952 throw new InvalidInputException(INVALID_ESCAPE);
2953 currentCharacter = (char) number;
2956 // throw new InvalidInputException(INVALID_ESCAPE);
2960 // public int scanIdentifierOrKeyword() throws InvalidInputException {
2961 // return scanIdentifierOrKeyword( false );
2963 public int scanIdentifierOrKeyword(boolean isVariable) throws InvalidInputException {
2965 // first dispatch on the first char.
2966 // then the length. If there are several
2967 // keywors with the same length AND the same first char, then do another
2968 // disptach on the second char :-)...cool....but fast !
2969 useAssertAsAnIndentifier = false;
2970 while (getNextCharAsJavaIdentifierPart()) {
2974 // if (new String(getCurrentTokenSource()).equals("$this")) {
2975 // return TokenNamethis;
2977 return TokenNameVariable;
2982 // if (withoutUnicodePtr == 0)
2983 // quick test on length == 1 but not on length > 12 while most identifier
2984 // have a length which is <= 12...but there are lots of identifier with
2985 // only one char....
2987 if ((length = currentPosition - startPosition) == 1)
2988 return TokenNameIdentifier;
2990 data = new char[length];
2991 index = startPosition;
2992 for (int i = 0; i < length; i++) {
2993 data[i] = Character.toLowerCase(source[index + i]);
2997 // if ((length = withoutUnicodePtr) == 1)
2998 // return TokenNameIdentifier;
2999 // // data = withoutUnicodeBuffer;
3000 // data = new char[withoutUnicodeBuffer.length];
3001 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
3002 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
3006 firstLetter = data[index];
3007 switch (firstLetter) {
3012 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'i') && (data[++index] == 'l')
3013 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3014 return TokenNameFILE;
3015 index = 0; // __LINE__
3016 if ((data[++index] == '_') && (data[++index] == 'l') && (data[++index] == 'i') && (data[++index] == 'n')
3017 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3018 return TokenNameLINE;
3022 if ((data[++index] == '_') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3023 && (data[++index] == 's') && (data[++index] == 's') && (data[++index] == '_') && (data[++index] == '_'))
3024 return TokenNameCLASS_C;
3028 if ((data[++index] == '_') && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 't')
3029 && (data[++index] == 'h') && (data[++index] == 'o') && (data[++index] == 'd') && (data[++index] == '_')
3030 && (data[++index] == '_'))
3031 return TokenNameMETHOD_C;
3035 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'u') && (data[++index] == 'n')
3036 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'o')
3037 && (data[++index] == 'n') && (data[++index] == '_') && (data[++index] == '_'))
3038 return TokenNameFUNC_C;
3041 return TokenNameIdentifier;
3043 // as and array abstract
3047 if ((data[++index] == 's')) {
3050 return TokenNameIdentifier;
3054 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3055 return TokenNameand;
3057 return TokenNameIdentifier;
3061 if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y'))
3062 return TokenNamearray;
3064 return TokenNameIdentifier;
3066 if ((data[++index] == 'b') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'r')
3067 && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 't'))
3068 return TokenNameabstract;
3070 return TokenNameIdentifier;
3072 return TokenNameIdentifier;
3078 if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k'))
3079 return TokenNamebreak;
3081 return TokenNameIdentifier;
3083 return TokenNameIdentifier;
3086 // case catch class clone const continue
3089 if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e'))
3090 return TokenNamecase;
3092 return TokenNameIdentifier;
3094 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3095 return TokenNamecatch;
3097 if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's'))
3098 return TokenNameclass;
3100 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 'e'))
3101 return TokenNameclone;
3103 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't'))
3104 return TokenNameconst;
3106 return TokenNameIdentifier;
3108 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'i')
3109 && (data[++index] == 'n') && (data[++index] == 'u') && (data[++index] == 'e'))
3110 return TokenNamecontinue;
3112 return TokenNameIdentifier;
3114 return TokenNameIdentifier;
3117 // declare default do die
3118 // TODO delete define ==> no keyword !
3121 if ((data[++index] == 'o'))
3124 return TokenNameIdentifier;
3126 // if ((data[++index] == 'e')
3127 // && (data[++index] == 'f')
3128 // && (data[++index] == 'i')
3129 // && (data[++index] == 'n')
3130 // && (data[++index] == 'e'))
3131 // return TokenNamedefine;
3133 // return TokenNameIdentifier;
3135 if ((data[++index] == 'e') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3136 && (data[++index] == 'r') && (data[++index] == 'e'))
3137 return TokenNamedeclare;
3139 if ((data[++index] == 'e') && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'u')
3140 && (data[++index] == 'l') && (data[++index] == 't'))
3141 return TokenNamedefault;
3143 return TokenNameIdentifier;
3145 return TokenNameIdentifier;
3148 // echo else exit elseif extends eval
3151 if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o'))
3152 return TokenNameecho;
3153 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e'))
3154 return TokenNameelse;
3155 else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't'))
3156 return TokenNameexit;
3157 else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l'))
3158 return TokenNameeval;
3160 return TokenNameIdentifier;
3163 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f'))
3164 return TokenNameendif;
3165 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 't') && (data[++index] == 'y'))
3166 return TokenNameempty;
3168 return TokenNameIdentifier;
3171 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o')
3172 && (data[++index] == 'r'))
3173 return TokenNameendfor;
3174 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 'i')
3175 && (data[++index] == 'f'))
3176 return TokenNameelseif;
3178 return TokenNameIdentifier;
3180 if ((data[++index] == 'x') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'n')
3181 && (data[++index] == 'd') && (data[++index] == 's'))
3182 return TokenNameextends;
3184 return TokenNameIdentifier;
3187 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'w') && (data[++index] == 'h')
3188 && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3189 return TokenNameendwhile;
3191 return TokenNameIdentifier;
3194 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 's') && (data[++index] == 'w')
3195 && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3196 return TokenNameendswitch;
3198 return TokenNameIdentifier;
3201 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'd') && (data[++index] == 'e')
3202 && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 'r')
3203 && (data[++index] == 'e'))
3204 return TokenNameenddeclare;
3206 if ((data[++index] == 'n') // endforeach
3207 && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r')
3208 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'h'))
3209 return TokenNameendforeach;
3211 return TokenNameIdentifier;
3213 return TokenNameIdentifier;
3216 // for false final function
3219 if ((data[++index] == 'o') && (data[++index] == 'r'))
3220 return TokenNamefor;
3222 return TokenNameIdentifier;
3224 // if ((data[++index] == 'a') && (data[++index] == 'l')
3225 // && (data[++index] == 's') && (data[++index] == 'e'))
3226 // return TokenNamefalse;
3227 if ((data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 'a') && (data[++index] == 'l'))
3228 return TokenNamefinal;
3230 return TokenNameIdentifier;
3233 if ((data[++index] == 'o') && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a')
3234 && (data[++index] == 'c') && (data[++index] == 'h'))
3235 return TokenNameforeach;
3237 return TokenNameIdentifier;
3240 if ((data[++index] == 'u') && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 't')
3241 && (data[++index] == 'i') && (data[++index] == 'o') && (data[++index] == 'n'))
3242 return TokenNamefunction;
3244 return TokenNameIdentifier;
3246 return TokenNameIdentifier;
3251 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'b') && (data[++index] == 'a')
3252 && (data[++index] == 'l')) {
3253 return TokenNameglobal;
3256 return TokenNameIdentifier;
3258 // if int isset include include_once instanceof interface implements
3261 if (data[++index] == 'f')
3264 return TokenNameIdentifier;
3266 // if ((data[++index] == 'n') && (data[++index] == 't'))
3267 // return TokenNameint;
3269 // return TokenNameIdentifier;
3271 if ((data[++index] == 's') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3272 return TokenNameisset;
3274 return TokenNameIdentifier;
3276 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3277 && (data[++index] == 'd') && (data[++index] == 'e'))
3278 return TokenNameinclude;
3280 return TokenNameIdentifier;
3283 if ((data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'r')
3284 && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'e'))
3285 return TokenNameinterface;
3287 return TokenNameIdentifier;
3290 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'a')
3291 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e') && (data[++index] == 'o')
3292 && (data[++index] == 'f'))
3293 return TokenNameinstanceof;
3294 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 'l') && (data[++index] == 'e')
3295 && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 'n') && (data[++index] == 't')
3296 && (data[++index] == 's'))
3297 return TokenNameimplements;
3299 return TokenNameIdentifier;
3301 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3302 && (data[++index] == 'd') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3303 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e'))
3304 return TokenNameinclude_once;
3306 return TokenNameIdentifier;
3308 return TokenNameIdentifier;
3313 if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) {
3314 return TokenNamelist;
3317 return TokenNameIdentifier;
3322 if ((data[++index] == 'e') && (data[++index] == 'w'))
3323 return TokenNamenew;
3325 return TokenNameIdentifier;
3327 // if ((data[++index] == 'u') && (data[++index] == 'l')
3328 // && (data[++index] == 'l'))
3329 // return TokenNamenull;
3331 // return TokenNameIdentifier;
3333 return TokenNameIdentifier;
3338 if (data[++index] == 'r') {
3342 // if (length == 12) {
3343 // if ((data[++index] == 'l')
3344 // && (data[++index] == 'd')
3345 // && (data[++index] == '_')
3346 // && (data[++index] == 'f')
3347 // && (data[++index] == 'u')
3348 // && (data[++index] == 'n')
3349 // && (data[++index] == 'c')
3350 // && (data[++index] == 't')
3351 // && (data[++index] == 'i')
3352 // && (data[++index] == 'o')
3353 // && (data[++index] == 'n')) {
3354 // return TokenNameold_function;
3357 return TokenNameIdentifier;
3359 // print public private protected
3362 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
3363 return TokenNameprint;
3365 return TokenNameIdentifier;
3367 if ((data[++index] == 'u') && (data[++index] == 'b') && (data[++index] == 'l') && (data[++index] == 'i')
3368 && (data[++index] == 'c')) {
3369 return TokenNamepublic;
3371 return TokenNameIdentifier;
3373 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'v') && (data[++index] == 'a')
3374 && (data[++index] == 't') && (data[++index] == 'e')) {
3375 return TokenNameprivate;
3377 return TokenNameIdentifier;
3379 if ((data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 't') && (data[++index] == 'e')
3380 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'd')) {
3381 return TokenNameprotected;
3383 return TokenNameIdentifier;
3385 return TokenNameIdentifier;
3387 // return require require_once
3389 if ((data[++index] == 'e') && (data[++index] == 't') && (data[++index] == 'u') && (data[++index] == 'r')
3390 && (data[++index] == 'n')) {
3391 return TokenNamereturn;
3393 } else if (length == 7) {
3394 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3395 && (data[++index] == 'r') && (data[++index] == 'e')) {
3396 return TokenNamerequire;
3398 } else if (length == 12) {
3399 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3400 && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3401 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e')) {
3402 return TokenNamerequire_once;
3405 return TokenNameIdentifier;
3407 // self static switch
3410 // if ((data[++index] == 'e') && (data[++index] == 'l') && (data[++index]
3412 // return TokenNameself;
3414 // return TokenNameIdentifier;
3416 if (data[++index] == 't')
3417 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) {
3418 return TokenNamestatic;
3420 return TokenNameIdentifier;
3421 else if ((data[index] == 'w') && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c')
3422 && (data[++index] == 'h'))
3423 return TokenNameswitch;
3425 return TokenNameIdentifier;
3427 return TokenNameIdentifier;
3433 if ((data[++index] == 'r') && (data[++index] == 'y'))
3434 return TokenNametry;
3436 return TokenNameIdentifier;
3438 // if ((data[++index] == 'r') && (data[++index] == 'u')
3439 // && (data[++index] == 'e'))
3440 // return TokenNametrue;
3442 // return TokenNameIdentifier;
3444 if ((data[++index] == 'h') && (data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 'w'))
3445 return TokenNamethrow;
3447 return TokenNameIdentifier;
3449 return TokenNameIdentifier;
3455 if ((data[++index] == 's') && (data[++index] == 'e'))
3456 return TokenNameuse;
3458 return TokenNameIdentifier;
3460 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3461 return TokenNameunset;
3463 return TokenNameIdentifier;
3465 return TokenNameIdentifier;
3471 if ((data[++index] == 'a') && (data[++index] == 'r'))
3472 return TokenNamevar;
3474 return TokenNameIdentifier;
3476 return TokenNameIdentifier;
3482 if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3483 return TokenNamewhile;
3485 return TokenNameIdentifier;
3486 // case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3487 // (data[++index]=='e') && (data[++index]=='f')&&
3488 // (data[++index]=='p'))
3489 // return TokenNamewidefp ;
3491 // return TokenNameIdentifier;
3493 return TokenNameIdentifier;
3499 if ((data[++index] == 'o') && (data[++index] == 'r'))
3500 return TokenNamexor;
3502 return TokenNameIdentifier;
3504 return TokenNameIdentifier;
3507 return TokenNameIdentifier;
3511 public int scanNumber(boolean dotPrefix) throws InvalidInputException {
3512 // when entering this method the currentCharacter is the firt
3513 // digit of the number , i.e. it may be preceeded by a . when
3514 // dotPrefix is true
3515 boolean floating = dotPrefix;
3516 if ((!dotPrefix) && (currentCharacter == '0')) {
3517 if (getNextChar('x', 'X') >= 0) { // ----------hexa-----------------
3518 // force the first char of the hexa number do exist...
3519 // consume next character
3520 unicodeAsBackSlash = false;
3521 currentCharacter = source[currentPosition++];
3522 // if (((currentCharacter = source[currentPosition++]) == '\\')
3523 // && (source[currentPosition] == 'u')) {
3524 // getNextUnicodeChar();
3526 // if (withoutUnicodePtr != 0) {
3527 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3530 if (Character.digit(currentCharacter, 16) == -1)
3531 throw new InvalidInputException(INVALID_HEXA);
3533 while (getNextCharAsDigit(16)) {
3536 // if (getNextChar('l', 'L') >= 0)
3537 // return TokenNameLongLiteral;
3539 return TokenNameIntegerLiteral;
3541 // there is x or X in the number
3542 // potential octal ! ... some one may write 000099.0 ! thus 00100 <
3543 // 00078.0 is true !!!!! crazy language
3544 if (getNextCharAsDigit()) {
3545 // -------------potential octal-----------------
3546 while (getNextCharAsDigit()) {
3549 // if (getNextChar('l', 'L') >= 0) {
3550 // return TokenNameLongLiteral;
3553 // if (getNextChar('f', 'F') >= 0) {
3554 // return TokenNameFloatingPointLiteral;
3556 if (getNextChar('d', 'D') >= 0) {
3557 return TokenNameDoubleLiteral;
3558 } else { // make the distinction between octal and float ....
3559 if (getNextChar('.')) { // bingo ! ....
3560 while (getNextCharAsDigit()) {
3563 if (getNextChar('e', 'E') >= 0) {
3564 // consume next character
3565 unicodeAsBackSlash = false;
3566 currentCharacter = source[currentPosition++];
3567 // if (((currentCharacter = source[currentPosition++]) == '\\')
3568 // && (source[currentPosition] == 'u')) {
3569 // getNextUnicodeChar();
3571 // if (withoutUnicodePtr != 0) {
3572 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3575 if ((currentCharacter == '-') || (currentCharacter == '+')) {
3576 // consume next character
3577 unicodeAsBackSlash = false;
3578 currentCharacter = source[currentPosition++];
3579 // if (((currentCharacter = source[currentPosition++]) == '\\')
3580 // && (source[currentPosition] == 'u')) {
3581 // getNextUnicodeChar();
3583 // if (withoutUnicodePtr != 0) {
3584 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3585 // currentCharacter;
3589 if (!Character.isDigit(currentCharacter))
3590 throw new InvalidInputException(INVALID_FLOAT);
3591 while (getNextCharAsDigit()) {
3595 // if (getNextChar('f', 'F') >= 0)
3596 // return TokenNameFloatingPointLiteral;
3597 getNextChar('d', 'D'); // jump over potential d or D
3598 return TokenNameDoubleLiteral;
3600 return TokenNameIntegerLiteral;
3607 while (getNextCharAsDigit()) {
3610 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3611 // return TokenNameLongLiteral;
3612 if ((!dotPrefix) && (getNextChar('.'))) { // decimal part that can be empty
3613 while (getNextCharAsDigit()) {
3618 // if floating is true both exponant and suffix may be optional
3619 if (getNextChar('e', 'E') >= 0) {
3621 // consume next character
3622 unicodeAsBackSlash = false;
3623 currentCharacter = source[currentPosition++];
3624 // if (((currentCharacter = source[currentPosition++]) == '\\')
3625 // && (source[currentPosition] == 'u')) {
3626 // getNextUnicodeChar();
3628 // if (withoutUnicodePtr != 0) {
3629 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3632 if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
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] = currentCharacter;
3646 if (!Character.isDigit(currentCharacter))
3647 throw new InvalidInputException(INVALID_FLOAT);
3648 while (getNextCharAsDigit()) {
3652 if (getNextChar('d', 'D') >= 0)
3653 return TokenNameDoubleLiteral;
3654 // if (getNextChar('f', 'F') >= 0)
3655 // return TokenNameFloatingPointLiteral;
3656 // the long flag has been tested before
3657 return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral;
3661 * Search the line number corresponding to a specific position
3664 public final int getLineNumber(int position) {
3665 if (lineEnds == null)
3667 int length = linePtr + 1;
3670 int g = 0, d = length - 1;
3674 if (position < lineEnds[m]) {
3676 } else if (position > lineEnds[m]) {
3682 if (position < lineEnds[m]) {
3688 public void setPHPMode(boolean mode) {
3692 public final void setSource(char[] source) {
3693 setSource(null, source);
3696 public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3697 // the source-buffer is set to sourceString
3698 this.compilationUnit = compilationUnit;
3699 if (source == null) {
3700 this.source = new char[0];
3702 this.source = source;
3705 initialPosition = currentPosition = 0;
3706 containsAssertKeyword = false;
3707 withoutUnicodeBuffer = new char[this.source.length];
3708 fFillerToken = TokenNameEOF;
3709 // encapsedStringStack = new Stack();
3712 public String toString() {
3713 if (startPosition == source.length)
3714 return "EOF\n\n" + new String(source); //$NON-NLS-1$
3715 if (currentPosition > source.length)
3716 return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3717 char front[] = new char[startPosition];
3718 System.arraycopy(source, 0, front, 0, startPosition);
3719 int middleLength = (currentPosition - 1) - startPosition + 1;
3721 if (middleLength > -1) {
3722 middle = new char[middleLength];
3723 System.arraycopy(source, startPosition, middle, 0, middleLength);
3725 middle = new char[0];
3727 char end[] = new char[source.length - (currentPosition - 1)];
3728 System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - (currentPosition - 1) - 1);
3729 return new String(front) + "\n===============================\nStarts here -->" //$NON-NLS-1$
3730 + new String(middle) + "<-- Ends here\n===============================\n" //$NON-NLS-1$
3734 public final String toStringAction(int act) {
3736 case TokenNameERROR:
3737 return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
3739 case TokenNameINLINE_HTML:
3740 return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3741 case TokenNameECHO_INVISIBLE:
3744 case TokenNameIdentifier:
3745 return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3746 case TokenNameVariable:
3747 return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3748 case TokenNameabstract:
3749 return "abstract"; //$NON-NLS-1$
3751 return "AND"; //$NON-NLS-1$
3752 case TokenNamearray:
3753 return "array"; //$NON-NLS-1$
3755 return "as"; //$NON-NLS-1$
3756 case TokenNamebreak:
3757 return "break"; //$NON-NLS-1$
3759 return "case"; //$NON-NLS-1$
3760 case TokenNameclass:
3761 return "class"; //$NON-NLS-1$
3762 case TokenNamecatch:
3763 return "catch"; //$NON-NLS-1$
3764 case TokenNameclone:
3767 case TokenNameconst:
3770 case TokenNamecontinue:
3771 return "continue"; //$NON-NLS-1$
3772 case TokenNamedefault:
3773 return "default"; //$NON-NLS-1$
3774 // case TokenNamedefine :
3775 // return "define"; //$NON-NLS-1$
3777 return "do"; //$NON-NLS-1$
3779 return "echo"; //$NON-NLS-1$
3781 return "else"; //$NON-NLS-1$
3782 case TokenNameelseif:
3783 return "elseif"; //$NON-NLS-1$
3784 case TokenNameendfor:
3785 return "endfor"; //$NON-NLS-1$
3786 case TokenNameendforeach:
3787 return "endforeach"; //$NON-NLS-1$
3788 case TokenNameendif:
3789 return "endif"; //$NON-NLS-1$
3790 case TokenNameendswitch:
3791 return "endswitch"; //$NON-NLS-1$
3792 case TokenNameendwhile:
3793 return "endwhile"; //$NON-NLS-1$
3796 case TokenNameextends:
3797 return "extends"; //$NON-NLS-1$
3798 // case TokenNamefalse :
3799 // return "false"; //$NON-NLS-1$
3800 case TokenNamefinal:
3801 return "final"; //$NON-NLS-1$
3803 return "for"; //$NON-NLS-1$
3804 case TokenNameforeach:
3805 return "foreach"; //$NON-NLS-1$
3806 case TokenNamefunction:
3807 return "function"; //$NON-NLS-1$
3808 case TokenNameglobal:
3809 return "global"; //$NON-NLS-1$
3811 return "if"; //$NON-NLS-1$
3812 case TokenNameimplements:
3813 return "implements"; //$NON-NLS-1$
3814 case TokenNameinclude:
3815 return "include"; //$NON-NLS-1$
3816 case TokenNameinclude_once:
3817 return "include_once"; //$NON-NLS-1$
3818 case TokenNameinstanceof:
3819 return "instanceof"; //$NON-NLS-1$
3820 case TokenNameinterface:
3821 return "interface"; //$NON-NLS-1$
3822 case TokenNameisset:
3823 return "isset"; //$NON-NLS-1$
3825 return "list"; //$NON-NLS-1$
3827 return "new"; //$NON-NLS-1$
3828 // case TokenNamenull :
3829 // return "null"; //$NON-NLS-1$
3831 return "OR"; //$NON-NLS-1$
3832 case TokenNameprint:
3833 return "print"; //$NON-NLS-1$
3834 case TokenNameprivate:
3835 return "private"; //$NON-NLS-1$
3836 case TokenNameprotected:
3837 return "protected"; //$NON-NLS-1$
3838 case TokenNamepublic:
3839 return "public"; //$NON-NLS-1$
3840 case TokenNamerequire:
3841 return "require"; //$NON-NLS-1$
3842 case TokenNamerequire_once:
3843 return "require_once"; //$NON-NLS-1$
3844 case TokenNamereturn:
3845 return "return"; //$NON-NLS-1$
3846 // case TokenNameself:
3847 // return "self"; //$NON-NLS-1$
3848 case TokenNamestatic:
3849 return "static"; //$NON-NLS-1$
3850 case TokenNameswitch:
3851 return "switch"; //$NON-NLS-1$
3852 // case TokenNametrue :
3853 // return "true"; //$NON-NLS-1$
3854 case TokenNameunset:
3855 return "unset"; //$NON-NLS-1$
3857 return "var"; //$NON-NLS-1$
3858 case TokenNamewhile:
3859 return "while"; //$NON-NLS-1$
3861 return "XOR"; //$NON-NLS-1$
3862 // case TokenNamethis :
3863 // return "$this"; //$NON-NLS-1$
3864 case TokenNameIntegerLiteral:
3865 return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3866 case TokenNameDoubleLiteral:
3867 return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3868 case TokenNameStringDoubleQuote:
3869 return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3870 case TokenNameStringSingleQuote:
3871 return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3872 case TokenNameStringInterpolated:
3873 return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3874 case TokenNameEncapsedString0:
3875 return "`"; //$NON-NLS-1$
3876 // case TokenNameEncapsedString1:
3877 // return "\'"; //$NON-NLS-1$
3878 // case TokenNameEncapsedString2:
3879 // return "\""; //$NON-NLS-1$
3880 case TokenNameSTRING:
3881 return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3882 case TokenNameHEREDOC:
3883 return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3884 case TokenNamePLUS_PLUS:
3885 return "++"; //$NON-NLS-1$
3886 case TokenNameMINUS_MINUS:
3887 return "--"; //$NON-NLS-1$
3888 case TokenNameEQUAL_EQUAL:
3889 return "=="; //$NON-NLS-1$
3890 case TokenNameEQUAL_EQUAL_EQUAL:
3891 return "==="; //$NON-NLS-1$
3892 case TokenNameEQUAL_GREATER:
3893 return "=>"; //$NON-NLS-1$
3894 case TokenNameLESS_EQUAL:
3895 return "<="; //$NON-NLS-1$
3896 case TokenNameGREATER_EQUAL:
3897 return ">="; //$NON-NLS-1$
3898 case TokenNameNOT_EQUAL:
3899 return "!="; //$NON-NLS-1$
3900 case TokenNameNOT_EQUAL_EQUAL:
3901 return "!=="; //$NON-NLS-1$
3902 case TokenNameLEFT_SHIFT:
3903 return "<<"; //$NON-NLS-1$
3904 case TokenNameRIGHT_SHIFT:
3905 return ">>"; //$NON-NLS-1$
3906 case TokenNamePLUS_EQUAL:
3907 return "+="; //$NON-NLS-1$
3908 case TokenNameMINUS_EQUAL:
3909 return "-="; //$NON-NLS-1$
3910 case TokenNameMULTIPLY_EQUAL:
3911 return "*="; //$NON-NLS-1$
3912 case TokenNameDIVIDE_EQUAL:
3913 return "/="; //$NON-NLS-1$
3914 case TokenNameAND_EQUAL:
3915 return "&="; //$NON-NLS-1$
3916 case TokenNameOR_EQUAL:
3917 return "|="; //$NON-NLS-1$
3918 case TokenNameXOR_EQUAL:
3919 return "^="; //$NON-NLS-1$
3920 case TokenNameREMAINDER_EQUAL:
3921 return "%="; //$NON-NLS-1$
3922 case TokenNameDOT_EQUAL:
3923 return ".="; //$NON-NLS-1$
3924 case TokenNameLEFT_SHIFT_EQUAL:
3925 return "<<="; //$NON-NLS-1$
3926 case TokenNameRIGHT_SHIFT_EQUAL:
3927 return ">>="; //$NON-NLS-1$
3928 case TokenNameOR_OR:
3929 return "||"; //$NON-NLS-1$
3930 case TokenNameAND_AND:
3931 return "&&"; //$NON-NLS-1$
3933 return "+"; //$NON-NLS-1$
3934 case TokenNameMINUS:
3935 return "-"; //$NON-NLS-1$
3936 case TokenNameMINUS_GREATER:
3939 return "!"; //$NON-NLS-1$
3940 case TokenNameREMAINDER:
3941 return "%"; //$NON-NLS-1$
3943 return "^"; //$NON-NLS-1$
3945 return "&"; //$NON-NLS-1$
3946 case TokenNameMULTIPLY:
3947 return "*"; //$NON-NLS-1$
3949 return "|"; //$NON-NLS-1$
3950 case TokenNameTWIDDLE:
3951 return "~"; //$NON-NLS-1$
3952 case TokenNameTWIDDLE_EQUAL:
3953 return "~="; //$NON-NLS-1$
3954 case TokenNameDIVIDE:
3955 return "/"; //$NON-NLS-1$
3956 case TokenNameGREATER:
3957 return ">"; //$NON-NLS-1$
3959 return "<"; //$NON-NLS-1$
3960 case TokenNameLPAREN:
3961 return "("; //$NON-NLS-1$
3962 case TokenNameRPAREN:
3963 return ")"; //$NON-NLS-1$
3964 case TokenNameLBRACE:
3965 return "{"; //$NON-NLS-1$
3966 case TokenNameRBRACE:
3967 return "}"; //$NON-NLS-1$
3968 case TokenNameLBRACKET:
3969 return "["; //$NON-NLS-1$
3970 case TokenNameRBRACKET:
3971 return "]"; //$NON-NLS-1$
3972 case TokenNameSEMICOLON:
3973 return ";"; //$NON-NLS-1$
3974 case TokenNameQUESTION:
3975 return "?"; //$NON-NLS-1$
3976 case TokenNameCOLON:
3977 return ":"; //$NON-NLS-1$
3978 case TokenNameCOMMA:
3979 return ","; //$NON-NLS-1$
3981 return "."; //$NON-NLS-1$
3982 case TokenNameEQUAL:
3983 return "="; //$NON-NLS-1$
3986 case TokenNameDOLLAR:
3988 case TokenNameDOLLAR_LBRACE:
3990 case TokenNameLBRACE_DOLLAR:
3993 return "EOF"; //$NON-NLS-1$
3994 case TokenNameWHITESPACE:
3995 return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3996 case TokenNameCOMMENT_LINE:
3997 return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3998 case TokenNameCOMMENT_BLOCK:
3999 return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4000 case TokenNameCOMMENT_PHPDOC:
4001 return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4002 // case TokenNameHTML :
4003 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
4006 return "__FILE__"; //$NON-NLS-1$
4008 return "__LINE__"; //$NON-NLS-1$
4009 case TokenNameCLASS_C:
4010 return "__CLASS__"; //$NON-NLS-1$
4011 case TokenNameMETHOD_C:
4012 return "__METHOD__"; //$NON-NLS-1$
4013 case TokenNameFUNC_C:
4014 return "__FUNCTION__"; //$NON-NLS-1
4015 case TokenNameboolCAST:
4016 return "( bool )"; //$NON-NLS-1$
4017 case TokenNameintCAST:
4018 return "( int )"; //$NON-NLS-1$
4019 case TokenNamedoubleCAST:
4020 return "( double )"; //$NON-NLS-1$
4021 case TokenNameobjectCAST:
4022 return "( object )"; //$NON-NLS-1$
4023 case TokenNamestringCAST:
4024 return "( string )"; //$NON-NLS-1$
4026 return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
4034 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
4035 this(tokenizeComments, tokenizeWhiteSpace, false);
4038 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals) {
4039 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, false);
4042 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4043 boolean assertMode) {
4044 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, assertMode, false, null, null, true);
4047 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4048 boolean assertMode, boolean tokenizeStrings, char[][] taskTags, char[][] taskPriorities, boolean isTaskCaseSensitive) {
4049 this.eofPosition = Integer.MAX_VALUE;
4050 this.tokenizeComments = tokenizeComments;
4051 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4052 this.tokenizeStrings = tokenizeStrings;
4053 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4054 // this.assertMode = assertMode;
4055 // this.encapsedStringStack = null;
4056 this.taskTags = taskTags;
4057 this.taskPriorities = taskPriorities;
4060 private void checkNonExternalizeString() throws InvalidInputException {
4061 if (currentLine == null)
4063 parseTags(currentLine);
4066 private void parseTags(NLSLine line) throws InvalidInputException {
4067 String s = new String(getCurrentTokenSource());
4068 int pos = s.indexOf(TAG_PREFIX);
4069 int lineLength = line.size();
4071 int start = pos + TAG_PREFIX_LENGTH;
4072 int end = s.indexOf(TAG_POSTFIX, start);
4073 String index = s.substring(start, end);
4076 i = Integer.parseInt(index) - 1;
4077 // Tags are one based not zero based.
4078 } catch (NumberFormatException e) {
4079 i = -1; // we don't want to consider this as a valid NLS tag
4081 if (line.exists(i)) {
4084 pos = s.indexOf(TAG_PREFIX, start);
4086 this.nonNLSStrings = new StringLiteral[lineLength];
4087 int nonNLSCounter = 0;
4088 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4089 StringLiteral literal = (StringLiteral) iterator.next();
4090 if (literal != null) {
4091 this.nonNLSStrings[nonNLSCounter++] = literal;
4094 if (nonNLSCounter == 0) {
4095 this.nonNLSStrings = null;
4099 this.wasNonExternalizedStringLiteral = true;
4100 if (nonNLSCounter != lineLength) {
4101 System.arraycopy(this.nonNLSStrings, 0, (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, nonNLSCounter);
4106 public final void scanEscapeCharacter() throws InvalidInputException {
4107 // the string with "\\u" is a legal string of two chars \ and u
4108 // thus we use a direct access to the source (for regular cases).
4109 if (unicodeAsBackSlash) {
4110 // consume next character
4111 unicodeAsBackSlash = false;
4112 // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4113 // (source[currentPosition] == 'u')) {
4114 // getNextUnicodeChar();
4116 if (withoutUnicodePtr != 0) {
4117 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4121 currentCharacter = source[currentPosition++];
4122 switch (currentCharacter) {
4124 currentCharacter = '\b';
4127 currentCharacter = '\t';
4130 currentCharacter = '\n';
4133 currentCharacter = '\f';
4136 currentCharacter = '\r';
4139 currentCharacter = '\"';
4142 currentCharacter = '\'';
4145 currentCharacter = '\\';
4148 // -----------octal escape--------------
4150 // OctalDigit OctalDigit
4151 // ZeroToThree OctalDigit OctalDigit
4152 int number = Character.getNumericValue(currentCharacter);
4153 if (number >= 0 && number <= 7) {
4154 boolean zeroToThreeNot = number > 3;
4155 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4156 int digit = Character.getNumericValue(currentCharacter);
4157 if (digit >= 0 && digit <= 7) {
4158 number = (number * 8) + digit;
4159 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4160 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
4161 // Digit --> ignore last character
4164 digit = Character.getNumericValue(currentCharacter);
4165 if (digit >= 0 && digit <= 7) { // has read \ZeroToThree
4166 // OctalDigit OctalDigit
4167 number = (number * 8) + digit;
4168 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
4169 // --> ignore last character
4173 } else { // has read \OctalDigit NonDigit--> ignore last
4177 } else { // has read \OctalDigit NonOctalDigit--> ignore last
4181 } else { // has read \OctalDigit --> ignore last character
4185 throw new InvalidInputException(INVALID_ESCAPE);
4186 currentCharacter = (char) number;
4188 throw new InvalidInputException(INVALID_ESCAPE);
4192 // chech presence of task: tags
4193 // TODO (frederic) see if we need to take unicode characters into account...
4194 public void checkTaskTag(int commentStart, int commentEnd) {
4195 char[] src = this.source;
4197 // only look for newer task: tags
4198 if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4201 int foundTaskIndex = this.foundTaskCount;
4202 char previous = src[commentStart + 1]; // should be '*' or '/'
4203 nextChar: for (int i = commentStart + 2; i < commentEnd && i < this.eofPosition; i++) {
4205 char[] priority = null;
4206 // check for tag occurrence only if not ambiguous with javadoc tag
4207 if (previous != '@') {
4208 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4209 tag = this.taskTags[itag];
4210 int tagLength = tag.length;
4214 // ensure tag is not leaded with letter if tag starts with a letter
4215 if (Scanner.isPHPIdentifierStart(tag[0])) {
4216 if (Scanner.isPHPIdentifierPart(previous)) {
4221 for (int t = 0; t < tagLength; t++) {
4224 if (x >= this.eofPosition || x >= commentEnd)
4226 if ((sc = src[i + t]) != (tc = tag[t])) { // case sensitive check
4227 if (this.isTaskCaseSensitive || (Character.toLowerCase(sc) != Character.toLowerCase(tc))) { // case
4234 // ensure tag is not followed with letter if tag finishes with a
4236 if (i + tagLength < commentEnd && Scanner.isPHPIdentifierPart(src[i + tagLength - 1])) {
4237 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4240 if (this.foundTaskTags == null) {
4241 this.foundTaskTags = new char[5][];
4242 this.foundTaskMessages = new char[5][];
4243 this.foundTaskPriorities = new char[5][];
4244 this.foundTaskPositions = new int[5][];
4245 } else if (this.foundTaskCount == this.foundTaskTags.length) {
4246 System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0,
4247 this.foundTaskCount);
4248 System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4249 this.foundTaskCount);
4250 System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4251 this.foundTaskCount);
4252 System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4253 this.foundTaskCount);
4256 priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4258 this.foundTaskTags[this.foundTaskCount] = tag;
4259 this.foundTaskPriorities[this.foundTaskCount] = priority;
4260 this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4261 this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4262 this.foundTaskCount++;
4263 i += tagLength - 1; // will be incremented when looping
4269 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4270 // retrieve message start and end positions
4271 int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4272 int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4273 // at most beginning of next task
4274 if (max_value < msgStart) {
4275 max_value = msgStart; // would only occur if tag is before EOF.
4279 for (int j = msgStart; j < max_value; j++) {
4280 if ((c = src[j]) == '\n' || c == '\r') {
4286 for (int j = max_value; j > msgStart; j--) {
4287 if ((c = src[j]) == '*') {
4295 if (msgStart == end)
4298 while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4300 while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4302 // update the end position of the task
4303 this.foundTaskPositions[i][1] = end;
4304 // get the message source
4305 final int messageLength = end - msgStart + 1;
4306 char[] message = new char[messageLength];
4307 System.arraycopy(src, msgStart, message, 0, messageLength);
4308 this.foundTaskMessages[i] = message;
4312 // chech presence of task: tags
4313 // public void checkTaskTag(int commentStart, int commentEnd) {
4314 // // only look for newer task: tags
4315 // if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount
4316 // - 1][0] >= commentStart) {
4319 // int foundTaskIndex = this.foundTaskCount;
4320 // nextChar: for (int i = commentStart; i < commentEnd && i <
4321 // this.eofPosition; i++) {
4322 // char[] tag = null;
4323 // char[] priority = null;
4324 // // check for tag occurrence
4325 // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4326 // tag = this.taskTags[itag];
4327 // priority = this.taskPriorities != null && itag < this.taskPriorities.length
4328 // ? this.taskPriorities[itag] : null;
4329 // int tagLength = tag.length;
4330 // for (int t = 0; t < tagLength; t++) {
4331 // if (this.source[i + t] != tag[t])
4332 // continue nextTag;
4334 // if (this.foundTaskTags == null) {
4335 // this.foundTaskTags = new char[5][];
4336 // this.foundTaskMessages = new char[5][];
4337 // this.foundTaskPriorities = new char[5][];
4338 // this.foundTaskPositions = new int[5][];
4339 // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4340 // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new
4341 // char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4342 // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new
4343 // char[this.foundTaskCount * 2][], 0,
4344 // this.foundTaskCount);
4345 // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities =
4346 // new char[this.foundTaskCount * 2][], 0,
4347 // this.foundTaskCount);
4348 // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new
4349 // int[this.foundTaskCount * 2][], 0,
4350 // this.foundTaskCount);
4352 // this.foundTaskTags[this.foundTaskCount] = tag;
4353 // this.foundTaskPriorities[this.foundTaskCount] = priority;
4354 // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength
4356 // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4357 // this.foundTaskCount++;
4358 // i += tagLength - 1; // will be incremented when looping
4361 // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4362 // // retrieve message start and end positions
4363 // int msgStart = this.foundTaskPositions[i][0] +
4364 // this.foundTaskTags[i].length;
4365 // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i +
4366 // 1][0] - 1 : commentEnd - 1;
4367 // // at most beginning of next task
4368 // if (max_value < msgStart)
4369 // max_value = msgStart; // would only occur if tag is before EOF.
4372 // for (int j = msgStart; j < max_value; j++) {
4373 // if ((c = this.source[j]) == '\n' || c == '\r') {
4379 // for (int j = max_value; j > msgStart; j--) {
4380 // if ((c = this.source[j]) == '*') {
4388 // if (msgStart == end)
4389 // continue; // empty
4390 // // trim the message
4391 // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4393 // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4395 // // update the end position of the task
4396 // this.foundTaskPositions[i][1] = end;
4397 // // get the message source
4398 // final int messageLength = end - msgStart + 1;
4399 // char[] message = new char[messageLength];
4400 // System.arraycopy(source, msgStart, message, 0, messageLength);
4401 // this.foundTaskMessages[i] = message;