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;
1849 boolean foundXML=false;
1850 if (getNextChar('X','x')>=0) {
1851 if (getNextChar('M','m')>=0) {
1852 if (getNextChar('L','l')>=0) {
1861 fFillerToken = TokenNameECHO_INVISIBLE;
1863 return TokenNameINLINE_HTML;
1866 if (getNextChar('H', 'h') >= 0) {
1867 if (getNextChar('P', 'p') >= 0) {
1869 if (ignorePHPOneLiner) {
1870 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1872 return TokenNameINLINE_HTML;
1876 return TokenNameINLINE_HTML;
1884 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1885 if (recordLineSeparator) {
1886 pushLineSeparator();
1891 } // -----------------while--------------------
1893 return TokenNameINLINE_HTML;
1894 } // -----------------try--------------------
1895 catch (IndexOutOfBoundsException e) {
1896 startPosition = start;
1900 return TokenNameINLINE_HTML;
1904 * check if the PHP is only in this line (for CodeFormatter)
1908 private int lookAheadLinePHPTag() {
1909 int currentPositionInLine = currentPosition;
1910 char previousCharInLine = ' ';
1911 char currentCharInLine = ' ';
1912 boolean singleQuotedStringActive = false;
1913 boolean doubleQuotedStringActive = false;
1916 // look ahead in this line
1918 previousCharInLine = currentCharInLine;
1919 currentCharInLine = source[currentPositionInLine++];
1920 switch (currentCharInLine) {
1922 if (previousCharInLine == '?') {
1923 // update the scanner's current Position in the source
1924 currentPosition = currentPositionInLine;
1925 // use as "dummy" token
1926 return TokenNameEOF;
1930 if (doubleQuotedStringActive) {
1931 // ignore escaped characters in double quoted strings
1932 previousCharInLine = currentCharInLine;
1933 currentCharInLine = source[currentPositionInLine++];
1936 if (doubleQuotedStringActive) {
1937 doubleQuotedStringActive = false;
1939 if (!singleQuotedStringActive) {
1940 doubleQuotedStringActive = true;
1945 if (singleQuotedStringActive) {
1946 if (previousCharInLine != '\\') {
1947 singleQuotedStringActive = false;
1950 if (!doubleQuotedStringActive) {
1951 singleQuotedStringActive = true;
1957 return TokenNameINLINE_HTML;
1959 if (!singleQuotedStringActive && !doubleQuotedStringActive) {
1961 return TokenNameINLINE_HTML;
1965 if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1967 return TokenNameINLINE_HTML;
1971 if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1973 return TokenNameINLINE_HTML;
1978 } catch (IndexOutOfBoundsException e) {
1980 currentPosition = currentPositionInLine;
1981 return TokenNameINLINE_HTML;
1985 // public final void getNextUnicodeChar()
1986 // throws IndexOutOfBoundsException, InvalidInputException {
1988 // //handle the case of unicode.
1989 // //when a unicode appears then we must use a buffer that holds char
1991 // //At the end of this method currentCharacter holds the new visited char
1992 // //and currentPosition points right next after it
1994 // //ALL getNextChar.... ARE OPTIMIZED COPIES
1996 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
1997 // currentPosition++;
1998 // while (source[currentPosition] == 'u') {
1999 // currentPosition++;
2003 // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2005 // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
2007 // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
2009 // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
2011 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2013 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2014 // //need the unicode buffer
2015 // if (withoutUnicodePtr == 0) {
2016 // //buffer all the entries that have been left aside....
2017 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
2018 // System.arraycopy(
2021 // withoutUnicodeBuffer,
2023 // withoutUnicodePtr);
2025 // //fill the buffer with the char
2026 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2028 // unicodeAsBackSlash = currentCharacter == '\\';
2031 * Tokenize a method body, assuming that curly brackets are properly balanced.
2033 public final void jumpOverMethodBody() {
2034 this.wasAcr = false;
2037 while (true) { // loop for jumping over comments
2038 // ---------Consume white space and handles startPosition---------
2039 boolean isWhiteSpace;
2041 startPosition = currentPosition;
2042 currentCharacter = source[currentPosition++];
2043 // if (((currentCharacter = source[currentPosition++]) == '\\')
2044 // && (source[currentPosition] == 'u')) {
2045 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
2047 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2048 pushLineSeparator();
2049 isWhiteSpace = Character.isWhitespace(currentCharacter);
2051 } while (isWhiteSpace);
2052 // -------consume token until } is found---------
2053 switch (currentCharacter) {
2064 test = getNextChar('\\');
2067 scanDoubleQuotedEscapeCharacter();
2068 } catch (InvalidInputException ex) {
2072 // try { // consume next character
2073 unicodeAsBackSlash = false;
2074 currentCharacter = source[currentPosition++];
2075 // if (((currentCharacter = source[currentPosition++]) == '\\')
2076 // && (source[currentPosition] == 'u')) {
2077 // getNextUnicodeChar();
2079 if (withoutUnicodePtr != 0) {
2080 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2083 // } catch (InvalidInputException ex) {
2091 // try { // consume next character
2092 unicodeAsBackSlash = false;
2093 currentCharacter = source[currentPosition++];
2094 // if (((currentCharacter = source[currentPosition++]) == '\\')
2095 // && (source[currentPosition] == 'u')) {
2096 // getNextUnicodeChar();
2098 if (withoutUnicodePtr != 0) {
2099 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2102 // } catch (InvalidInputException ex) {
2104 while (currentCharacter != '"') {
2105 if (currentCharacter == '\r') {
2106 if (source[currentPosition] == '\n')
2109 // the string cannot go further that the line
2111 if (currentCharacter == '\n') {
2113 // the string cannot go further that the line
2115 if (currentCharacter == '\\') {
2117 scanDoubleQuotedEscapeCharacter();
2118 } catch (InvalidInputException ex) {
2122 // try { // consume next character
2123 unicodeAsBackSlash = false;
2124 currentCharacter = source[currentPosition++];
2125 // if (((currentCharacter = source[currentPosition++]) == '\\')
2126 // && (source[currentPosition] == 'u')) {
2127 // getNextUnicodeChar();
2129 if (withoutUnicodePtr != 0) {
2130 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2133 // } catch (InvalidInputException ex) {
2136 } catch (IndexOutOfBoundsException e) {
2142 if ((test = getNextChar('/', '*')) == 0) {
2145 // get the next char
2146 currentCharacter = source[currentPosition++];
2147 // if (((currentCharacter = source[currentPosition++]) ==
2149 // && (source[currentPosition] == 'u')) {
2150 // //-------------unicode traitement ------------
2151 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2152 // currentPosition++;
2153 // while (source[currentPosition] == 'u') {
2154 // currentPosition++;
2157 // Character.getNumericValue(source[currentPosition++]))
2161 // Character.getNumericValue(source[currentPosition++]))
2165 // Character.getNumericValue(source[currentPosition++]))
2169 // Character.getNumericValue(source[currentPosition++]))
2172 // //error don't care of the value
2173 // currentCharacter = 'A';
2174 // } //something different from \n and \r
2176 // currentCharacter =
2177 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2180 while (currentCharacter != '\r' && currentCharacter != '\n') {
2181 // get the next char
2182 currentCharacter = source[currentPosition++];
2183 // if (((currentCharacter = source[currentPosition++])
2185 // && (source[currentPosition] == 'u')) {
2186 // //-------------unicode traitement ------------
2187 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2188 // currentPosition++;
2189 // while (source[currentPosition] == 'u') {
2190 // currentPosition++;
2193 // Character.getNumericValue(source[currentPosition++]))
2197 // Character.getNumericValue(source[currentPosition++]))
2201 // Character.getNumericValue(source[currentPosition++]))
2205 // Character.getNumericValue(source[currentPosition++]))
2208 // //error don't care of the value
2209 // currentCharacter = 'A';
2210 // } //something different from \n and \r
2212 // currentCharacter =
2213 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2217 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2218 pushLineSeparator();
2219 } catch (IndexOutOfBoundsException e) {
2220 } // an eof will them be generated
2224 // traditional and annotation comment
2225 boolean star = false;
2226 // try { // consume next character
2227 unicodeAsBackSlash = false;
2228 currentCharacter = source[currentPosition++];
2229 // if (((currentCharacter = source[currentPosition++]) == '\\')
2230 // && (source[currentPosition] == 'u')) {
2231 // getNextUnicodeChar();
2233 if (withoutUnicodePtr != 0) {
2234 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2237 // } catch (InvalidInputException ex) {
2239 if (currentCharacter == '*') {
2242 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2243 pushLineSeparator();
2244 try { // get the next char
2245 currentCharacter = source[currentPosition++];
2246 // if (((currentCharacter = source[currentPosition++]) ==
2248 // && (source[currentPosition] == 'u')) {
2249 // //-------------unicode traitement ------------
2250 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2251 // currentPosition++;
2252 // while (source[currentPosition] == 'u') {
2253 // currentPosition++;
2256 // Character.getNumericValue(source[currentPosition++]))
2260 // Character.getNumericValue(source[currentPosition++]))
2264 // Character.getNumericValue(source[currentPosition++]))
2268 // Character.getNumericValue(source[currentPosition++]))
2271 // //error don't care of the value
2272 // currentCharacter = 'A';
2273 // } //something different from * and /
2275 // currentCharacter =
2276 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2279 // loop until end of comment */
2280 while ((currentCharacter != '/') || (!star)) {
2281 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2282 pushLineSeparator();
2283 star = currentCharacter == '*';
2285 currentCharacter = source[currentPosition++];
2286 // if (((currentCharacter = source[currentPosition++])
2288 // && (source[currentPosition] == 'u')) {
2289 // //-------------unicode traitement ------------
2290 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2291 // currentPosition++;
2292 // while (source[currentPosition] == 'u') {
2293 // currentPosition++;
2296 // Character.getNumericValue(source[currentPosition++]))
2300 // Character.getNumericValue(source[currentPosition++]))
2304 // Character.getNumericValue(source[currentPosition++]))
2308 // Character.getNumericValue(source[currentPosition++]))
2311 // //error don't care of the value
2312 // currentCharacter = 'A';
2313 // } //something different from * and /
2315 // currentCharacter =
2316 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2320 } catch (IndexOutOfBoundsException e) {
2328 if (isPHPIdentOrVarStart(currentCharacter)) {
2330 scanIdentifierOrKeyword((currentCharacter == '$'));
2331 } catch (InvalidInputException ex) {
2336 if (ObviousIdentCharNatures[currentCharacter] == C_DIGIT) {
2337 // if (Character.isDigit(currentCharacter)) {
2340 } catch (InvalidInputException ex) {
2347 // -----------------end switch while try--------------------
2348 } catch (IndexOutOfBoundsException e) {
2349 } catch (InvalidInputException e) {
2354 // public final boolean jumpOverUnicodeWhiteSpace()
2355 // throws InvalidInputException {
2357 // //handle the case of unicode. Jump over the next whiteSpace
2358 // //making startPosition pointing on the next available char
2359 // //On false, the currentCharacter is filled up with a potential
2363 // this.wasAcr = false;
2364 // int c1, c2, c3, c4;
2365 // int unicodeSize = 6;
2366 // currentPosition++;
2367 // while (source[currentPosition] == 'u') {
2368 // currentPosition++;
2372 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2374 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2376 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2378 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2380 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2383 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2384 // if (recordLineSeparator
2385 // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2386 // pushLineSeparator();
2387 // if (Character.isWhitespace(currentCharacter))
2390 // //buffer the new char which is not a white space
2391 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2392 // //withoutUnicodePtr == 1 is true here
2394 // } catch (IndexOutOfBoundsException e) {
2395 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2398 public final int[] getLineEnds() {
2399 // return a bounded copy of this.lineEnds
2401 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0, linePtr + 1);
2405 public char[] getSource() {
2409 public static boolean isIdentifierOrKeyword(int token) {
2410 return (token == TokenNameIdentifier) || (token > TokenNameKEYWORD);
2413 final char[] optimizedCurrentTokenSource1() {
2414 // return always the same char[] build only once
2415 // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2416 char charOne = source[startPosition];
2471 return new char[] { charOne };
2475 final char[] optimizedCurrentTokenSource2() {
2477 c0 = source[startPosition];
2478 c1 = source[startPosition + 1];
2480 // return always the same char[] build only once
2481 // optimization at no speed cost of 99.5 % of the singleCharIdentifier
2484 return charArray_va;
2486 return charArray_vb;
2488 return charArray_vc;
2490 return charArray_vd;
2492 return charArray_ve;
2494 return charArray_vf;
2496 return charArray_vg;
2498 return charArray_vh;
2500 return charArray_vi;
2502 return charArray_vj;
2504 return charArray_vk;
2506 return charArray_vl;
2508 return charArray_vm;
2510 return charArray_vn;
2512 return charArray_vo;
2514 return charArray_vp;
2516 return charArray_vq;
2518 return charArray_vr;
2520 return charArray_vs;
2522 return charArray_vt;
2524 return charArray_vu;
2526 return charArray_vv;
2528 return charArray_vw;
2530 return charArray_vx;
2532 return charArray_vy;
2534 return charArray_vz;
2537 // try to return the same char[] build only once
2538 int hash = ((c0 << 6) + c1) % TableSize;
2539 char[][] table = charArray_length[0][hash];
2541 while (++i < InternalTableSize) {
2542 char[] charArray = table[i];
2543 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2546 // ---------other side---------
2548 int max = newEntry2;
2549 while (++i <= max) {
2550 char[] charArray = table[i];
2551 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2554 // --------add the entry-------
2555 if (++max >= InternalTableSize)
2558 table[max] = (r = new char[] { c0, c1 });
2563 final char[] optimizedCurrentTokenSource3() {
2564 // try to return the same char[] build only once
2566 int hash = (((c0 = source[startPosition]) << 12) + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2568 char[][] table = charArray_length[1][hash];
2570 while (++i < InternalTableSize) {
2571 char[] charArray = table[i];
2572 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2575 // ---------other side---------
2577 int max = newEntry3;
2578 while (++i <= max) {
2579 char[] charArray = table[i];
2580 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2583 // --------add the entry-------
2584 if (++max >= InternalTableSize)
2587 table[max] = (r = new char[] { c0, c1, c2 });
2592 final char[] optimizedCurrentTokenSource4() {
2593 // try to return the same char[] build only once
2594 char c0, c1, c2, c3;
2595 long hash = ((((long) (c0 = source[startPosition])) << 18) + ((c1 = source[startPosition + 1]) << 12)
2596 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2598 char[][] table = charArray_length[2][(int) hash];
2600 while (++i < InternalTableSize) {
2601 char[] charArray = table[i];
2602 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2605 // ---------other side---------
2607 int max = newEntry4;
2608 while (++i <= max) {
2609 char[] charArray = table[i];
2610 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2613 // --------add the entry-------
2614 if (++max >= InternalTableSize)
2617 table[max] = (r = new char[] { c0, c1, c2, c3 });
2622 final char[] optimizedCurrentTokenSource5() {
2623 // try to return the same char[] build only once
2624 char c0, c1, c2, c3, c4;
2625 long hash = ((((long) (c0 = source[startPosition])) << 24) + (((long) (c1 = source[startPosition + 1])) << 18)
2626 + ((c2 = source[startPosition + 2]) << 12) + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2628 char[][] table = charArray_length[3][(int) hash];
2630 while (++i < InternalTableSize) {
2631 char[] charArray = table[i];
2632 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2635 // ---------other side---------
2637 int max = newEntry5;
2638 while (++i <= max) {
2639 char[] charArray = table[i];
2640 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2643 // --------add the entry-------
2644 if (++max >= InternalTableSize)
2647 table[max] = (r = new char[] { c0, c1, c2, c3, c4 });
2652 final char[] optimizedCurrentTokenSource6() {
2653 // try to return the same char[] build only once
2654 char c0, c1, c2, c3, c4, c5;
2655 long hash = ((((long) (c0 = source[startPosition])) << 32) + (((long) (c1 = source[startPosition + 1])) << 24)
2656 + (((long) (c2 = source[startPosition + 2])) << 18) + ((c3 = source[startPosition + 3]) << 12)
2657 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2659 char[][] table = charArray_length[4][(int) hash];
2661 while (++i < InternalTableSize) {
2662 char[] charArray = table[i];
2663 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2664 && (c5 == charArray[5]))
2667 // ---------other side---------
2669 int max = newEntry6;
2670 while (++i <= max) {
2671 char[] charArray = table[i];
2672 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2673 && (c5 == charArray[5]))
2676 // --------add the entry-------
2677 if (++max >= InternalTableSize)
2680 table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 });
2685 public final void pushLineSeparator() throws InvalidInputException {
2686 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2687 final int INCREMENT = 250;
2688 if (this.checkNonExternalizedStringLiterals) {
2689 // reinitialize the current line for non externalize strings purpose
2692 // currentCharacter is at position currentPosition-1
2694 if (currentCharacter == '\r') {
2695 int separatorPos = currentPosition - 1;
2696 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2698 // System.out.println("CR-" + separatorPos);
2700 lineEnds[++linePtr] = separatorPos;
2701 } catch (IndexOutOfBoundsException e) {
2702 // linePtr value is correct
2703 int oldLength = lineEnds.length;
2704 int[] old = lineEnds;
2705 lineEnds = new int[oldLength + INCREMENT];
2706 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2707 lineEnds[linePtr] = separatorPos;
2709 // look-ahead for merged cr+lf
2711 if (source[currentPosition] == '\n') {
2712 // System.out.println("look-ahead LF-" + currentPosition);
2713 lineEnds[linePtr] = currentPosition;
2719 } catch (IndexOutOfBoundsException e) {
2724 if (currentCharacter == '\n') {
2725 // must merge eventual cr followed by lf
2726 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2727 // System.out.println("merge LF-" + (currentPosition - 1));
2728 lineEnds[linePtr] = currentPosition - 1;
2730 int separatorPos = currentPosition - 1;
2731 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2733 // System.out.println("LF-" + separatorPos);
2735 lineEnds[++linePtr] = separatorPos;
2736 } catch (IndexOutOfBoundsException e) {
2737 // linePtr value is correct
2738 int oldLength = lineEnds.length;
2739 int[] old = lineEnds;
2740 lineEnds = new int[oldLength + INCREMENT];
2741 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2742 lineEnds[linePtr] = separatorPos;
2750 public final void pushUnicodeLineSeparator() {
2751 // isUnicode means that the \r or \n has been read as a unicode character
2752 // see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2753 final int INCREMENT = 250;
2754 // currentCharacter is at position currentPosition-1
2755 if (this.checkNonExternalizedStringLiterals) {
2756 // reinitialize the current line for non externalize strings purpose
2760 if (currentCharacter == '\r') {
2761 int separatorPos = currentPosition - 6;
2762 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2764 // System.out.println("CR-" + separatorPos);
2766 lineEnds[++linePtr] = separatorPos;
2767 } catch (IndexOutOfBoundsException e) {
2768 // linePtr value is correct
2769 int oldLength = lineEnds.length;
2770 int[] old = lineEnds;
2771 lineEnds = new int[oldLength + INCREMENT];
2772 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2773 lineEnds[linePtr] = separatorPos;
2775 // look-ahead for merged cr+lf
2776 if (source[currentPosition] == '\n') {
2777 // System.out.println("look-ahead LF-" + currentPosition);
2778 lineEnds[linePtr] = currentPosition;
2786 if (currentCharacter == '\n') {
2787 // must merge eventual cr followed by lf
2788 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2789 // System.out.println("merge LF-" + (currentPosition - 1));
2790 lineEnds[linePtr] = currentPosition - 6;
2792 int separatorPos = currentPosition - 6;
2793 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2795 // System.out.println("LF-" + separatorPos);
2797 lineEnds[++linePtr] = separatorPos;
2798 } catch (IndexOutOfBoundsException e) {
2799 // linePtr value is correct
2800 int oldLength = lineEnds.length;
2801 int[] old = lineEnds;
2802 lineEnds = new int[oldLength + INCREMENT];
2803 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2804 lineEnds[linePtr] = separatorPos;
2812 public void recordComment(int token) {
2814 int stopPosition = this.currentPosition;
2816 case TokenNameCOMMENT_LINE:
2817 stopPosition = -this.lastCommentLinePosition;
2819 case TokenNameCOMMENT_BLOCK:
2820 stopPosition = -this.currentPosition;
2824 // a new comment is recorded
2825 int length = this.commentStops.length;
2826 if (++this.commentPtr >= length) {
2827 System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length);
2828 // grows the positions buffers too
2829 System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length);
2831 this.commentStops[this.commentPtr] = stopPosition;
2832 this.commentStarts[this.commentPtr] = this.startPosition;
2835 // public final void recordComment(boolean isJavadoc) {
2836 // // a new annotation comment is recorded
2838 // commentStops[++commentPtr] = isJavadoc
2839 // ? currentPosition
2840 // : -currentPosition;
2841 // } catch (IndexOutOfBoundsException e) {
2842 // int oldStackLength = commentStops.length;
2843 // int[] oldStack = commentStops;
2844 // commentStops = new int[oldStackLength + 30];
2845 // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
2846 // commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition;
2847 // //grows the positions buffers too
2848 // int[] old = commentStarts;
2849 // commentStarts = new int[oldStackLength + 30];
2850 // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
2852 // //the buffer is of a correct size here
2853 // commentStarts[commentPtr] = startPosition;
2855 public void resetTo(int begin, int end) {
2856 // reset the scanner to a given position where it may rescan again
2858 initialPosition = startPosition = currentPosition = begin;
2859 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
2860 commentPtr = -1; // reset comment stack
2863 public final void scanSingleQuotedEscapeCharacter() throws InvalidInputException {
2864 // the string with "\\u" is a legal string of two chars \ and u
2865 // thus we use a direct access to the source (for regular cases).
2866 // if (unicodeAsBackSlash) {
2867 // // consume next character
2868 // unicodeAsBackSlash = false;
2869 // if (((currentCharacter = source[currentPosition++]) == '\\')
2870 // && (source[currentPosition] == 'u')) {
2871 // getNextUnicodeChar();
2873 // if (withoutUnicodePtr != 0) {
2874 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2878 currentCharacter = source[currentPosition++];
2879 switch (currentCharacter) {
2881 currentCharacter = '\'';
2884 currentCharacter = '\\';
2887 currentCharacter = '\\';
2892 public final void scanDoubleQuotedEscapeCharacter() throws InvalidInputException {
2893 currentCharacter = source[currentPosition++];
2894 switch (currentCharacter) {
2896 // currentCharacter = '\b';
2899 currentCharacter = '\t';
2902 currentCharacter = '\n';
2905 // currentCharacter = '\f';
2908 currentCharacter = '\r';
2911 currentCharacter = '\"';
2914 currentCharacter = '\'';
2917 currentCharacter = '\\';
2920 currentCharacter = '$';
2923 // -----------octal escape--------------
2925 // OctalDigit OctalDigit
2926 // ZeroToThree OctalDigit OctalDigit
2927 int number = Character.getNumericValue(currentCharacter);
2928 if (number >= 0 && number <= 7) {
2929 boolean zeroToThreeNot = number > 3;
2930 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2931 int digit = Character.getNumericValue(currentCharacter);
2932 if (digit >= 0 && digit <= 7) {
2933 number = (number * 8) + digit;
2934 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2935 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
2936 // Digit --> ignore last character
2939 digit = Character.getNumericValue(currentCharacter);
2940 if (digit >= 0 && digit <= 7) {
2941 // has read \ZeroToThree OctalDigit OctalDigit
2942 number = (number * 8) + digit;
2943 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
2944 // --> ignore last character
2948 } else { // has read \OctalDigit NonDigit--> ignore last
2952 } else { // has read \OctalDigit NonOctalDigit--> ignore last
2956 } else { // has read \OctalDigit --> ignore last character
2960 throw new InvalidInputException(INVALID_ESCAPE);
2961 currentCharacter = (char) number;
2964 // throw new InvalidInputException(INVALID_ESCAPE);
2968 // public int scanIdentifierOrKeyword() throws InvalidInputException {
2969 // return scanIdentifierOrKeyword( false );
2971 public int scanIdentifierOrKeyword(boolean isVariable) throws InvalidInputException {
2973 // first dispatch on the first char.
2974 // then the length. If there are several
2975 // keywors with the same length AND the same first char, then do another
2976 // disptach on the second char :-)...cool....but fast !
2977 useAssertAsAnIndentifier = false;
2978 while (getNextCharAsJavaIdentifierPart()) {
2982 // if (new String(getCurrentTokenSource()).equals("$this")) {
2983 // return TokenNamethis;
2985 return TokenNameVariable;
2990 // if (withoutUnicodePtr == 0)
2991 // quick test on length == 1 but not on length > 12 while most identifier
2992 // have a length which is <= 12...but there are lots of identifier with
2993 // only one char....
2995 if ((length = currentPosition - startPosition) == 1)
2996 return TokenNameIdentifier;
2998 data = new char[length];
2999 index = startPosition;
3000 for (int i = 0; i < length; i++) {
3001 data[i] = Character.toLowerCase(source[index + i]);
3005 // if ((length = withoutUnicodePtr) == 1)
3006 // return TokenNameIdentifier;
3007 // // data = withoutUnicodeBuffer;
3008 // data = new char[withoutUnicodeBuffer.length];
3009 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
3010 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
3014 firstLetter = data[index];
3015 switch (firstLetter) {
3020 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'i') && (data[++index] == 'l')
3021 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3022 return TokenNameFILE;
3023 index = 0; // __LINE__
3024 if ((data[++index] == '_') && (data[++index] == 'l') && (data[++index] == 'i') && (data[++index] == 'n')
3025 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3026 return TokenNameLINE;
3030 if ((data[++index] == '_') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3031 && (data[++index] == 's') && (data[++index] == 's') && (data[++index] == '_') && (data[++index] == '_'))
3032 return TokenNameCLASS_C;
3036 if ((data[++index] == '_') && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 't')
3037 && (data[++index] == 'h') && (data[++index] == 'o') && (data[++index] == 'd') && (data[++index] == '_')
3038 && (data[++index] == '_'))
3039 return TokenNameMETHOD_C;
3043 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'u') && (data[++index] == 'n')
3044 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'o')
3045 && (data[++index] == 'n') && (data[++index] == '_') && (data[++index] == '_'))
3046 return TokenNameFUNC_C;
3049 return TokenNameIdentifier;
3051 // as and array abstract
3055 if ((data[++index] == 's')) {
3058 return TokenNameIdentifier;
3062 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3063 return TokenNameand;
3065 return TokenNameIdentifier;
3069 if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y'))
3070 return TokenNamearray;
3072 return TokenNameIdentifier;
3074 if ((data[++index] == 'b') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'r')
3075 && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 't'))
3076 return TokenNameabstract;
3078 return TokenNameIdentifier;
3080 return TokenNameIdentifier;
3086 if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k'))
3087 return TokenNamebreak;
3089 return TokenNameIdentifier;
3091 return TokenNameIdentifier;
3094 // case catch class clone const continue
3097 if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e'))
3098 return TokenNamecase;
3100 return TokenNameIdentifier;
3102 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3103 return TokenNamecatch;
3105 if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's'))
3106 return TokenNameclass;
3108 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 'e'))
3109 return TokenNameclone;
3111 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't'))
3112 return TokenNameconst;
3114 return TokenNameIdentifier;
3116 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'i')
3117 && (data[++index] == 'n') && (data[++index] == 'u') && (data[++index] == 'e'))
3118 return TokenNamecontinue;
3120 return TokenNameIdentifier;
3122 return TokenNameIdentifier;
3125 // declare default do die
3126 // TODO delete define ==> no keyword !
3129 if ((data[++index] == 'o'))
3132 return TokenNameIdentifier;
3134 // if ((data[++index] == 'e')
3135 // && (data[++index] == 'f')
3136 // && (data[++index] == 'i')
3137 // && (data[++index] == 'n')
3138 // && (data[++index] == 'e'))
3139 // return TokenNamedefine;
3141 // return TokenNameIdentifier;
3143 if ((data[++index] == 'e') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3144 && (data[++index] == 'r') && (data[++index] == 'e'))
3145 return TokenNamedeclare;
3147 if ((data[++index] == 'e') && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'u')
3148 && (data[++index] == 'l') && (data[++index] == 't'))
3149 return TokenNamedefault;
3151 return TokenNameIdentifier;
3153 return TokenNameIdentifier;
3156 // echo else exit elseif extends eval
3159 if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o'))
3160 return TokenNameecho;
3161 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e'))
3162 return TokenNameelse;
3163 else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't'))
3164 return TokenNameexit;
3165 else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l'))
3166 return TokenNameeval;
3168 return TokenNameIdentifier;
3171 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f'))
3172 return TokenNameendif;
3173 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 't') && (data[++index] == 'y'))
3174 return TokenNameempty;
3176 return TokenNameIdentifier;
3179 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o')
3180 && (data[++index] == 'r'))
3181 return TokenNameendfor;
3182 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 'i')
3183 && (data[++index] == 'f'))
3184 return TokenNameelseif;
3186 return TokenNameIdentifier;
3188 if ((data[++index] == 'x') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'n')
3189 && (data[++index] == 'd') && (data[++index] == 's'))
3190 return TokenNameextends;
3192 return TokenNameIdentifier;
3195 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'w') && (data[++index] == 'h')
3196 && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3197 return TokenNameendwhile;
3199 return TokenNameIdentifier;
3202 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 's') && (data[++index] == 'w')
3203 && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3204 return TokenNameendswitch;
3206 return TokenNameIdentifier;
3209 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'd') && (data[++index] == 'e')
3210 && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 'r')
3211 && (data[++index] == 'e'))
3212 return TokenNameenddeclare;
3214 if ((data[++index] == 'n') // endforeach
3215 && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r')
3216 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'h'))
3217 return TokenNameendforeach;
3219 return TokenNameIdentifier;
3221 return TokenNameIdentifier;
3224 // for false final function
3227 if ((data[++index] == 'o') && (data[++index] == 'r'))
3228 return TokenNamefor;
3230 return TokenNameIdentifier;
3232 // if ((data[++index] == 'a') && (data[++index] == 'l')
3233 // && (data[++index] == 's') && (data[++index] == 'e'))
3234 // return TokenNamefalse;
3235 if ((data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 'a') && (data[++index] == 'l'))
3236 return TokenNamefinal;
3238 return TokenNameIdentifier;
3241 if ((data[++index] == 'o') && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a')
3242 && (data[++index] == 'c') && (data[++index] == 'h'))
3243 return TokenNameforeach;
3245 return TokenNameIdentifier;
3248 if ((data[++index] == 'u') && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 't')
3249 && (data[++index] == 'i') && (data[++index] == 'o') && (data[++index] == 'n'))
3250 return TokenNamefunction;
3252 return TokenNameIdentifier;
3254 return TokenNameIdentifier;
3259 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'b') && (data[++index] == 'a')
3260 && (data[++index] == 'l')) {
3261 return TokenNameglobal;
3264 return TokenNameIdentifier;
3266 // if int isset include include_once instanceof interface implements
3269 if (data[++index] == 'f')
3272 return TokenNameIdentifier;
3274 // if ((data[++index] == 'n') && (data[++index] == 't'))
3275 // return TokenNameint;
3277 // return TokenNameIdentifier;
3279 if ((data[++index] == 's') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3280 return TokenNameisset;
3282 return TokenNameIdentifier;
3284 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3285 && (data[++index] == 'd') && (data[++index] == 'e'))
3286 return TokenNameinclude;
3288 return TokenNameIdentifier;
3291 if ((data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'r')
3292 && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'e'))
3293 return TokenNameinterface;
3295 return TokenNameIdentifier;
3298 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'a')
3299 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e') && (data[++index] == 'o')
3300 && (data[++index] == 'f'))
3301 return TokenNameinstanceof;
3302 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 'l') && (data[++index] == 'e')
3303 && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 'n') && (data[++index] == 't')
3304 && (data[++index] == 's'))
3305 return TokenNameimplements;
3307 return TokenNameIdentifier;
3309 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3310 && (data[++index] == 'd') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3311 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e'))
3312 return TokenNameinclude_once;
3314 return TokenNameIdentifier;
3316 return TokenNameIdentifier;
3321 if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) {
3322 return TokenNamelist;
3325 return TokenNameIdentifier;
3330 if ((data[++index] == 'e') && (data[++index] == 'w'))
3331 return TokenNamenew;
3333 return TokenNameIdentifier;
3335 // if ((data[++index] == 'u') && (data[++index] == 'l')
3336 // && (data[++index] == 'l'))
3337 // return TokenNamenull;
3339 // return TokenNameIdentifier;
3341 return TokenNameIdentifier;
3346 if (data[++index] == 'r') {
3350 // if (length == 12) {
3351 // if ((data[++index] == 'l')
3352 // && (data[++index] == 'd')
3353 // && (data[++index] == '_')
3354 // && (data[++index] == 'f')
3355 // && (data[++index] == 'u')
3356 // && (data[++index] == 'n')
3357 // && (data[++index] == 'c')
3358 // && (data[++index] == 't')
3359 // && (data[++index] == 'i')
3360 // && (data[++index] == 'o')
3361 // && (data[++index] == 'n')) {
3362 // return TokenNameold_function;
3365 return TokenNameIdentifier;
3367 // print public private protected
3370 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
3371 return TokenNameprint;
3373 return TokenNameIdentifier;
3375 if ((data[++index] == 'u') && (data[++index] == 'b') && (data[++index] == 'l') && (data[++index] == 'i')
3376 && (data[++index] == 'c')) {
3377 return TokenNamepublic;
3379 return TokenNameIdentifier;
3381 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'v') && (data[++index] == 'a')
3382 && (data[++index] == 't') && (data[++index] == 'e')) {
3383 return TokenNameprivate;
3385 return TokenNameIdentifier;
3387 if ((data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 't') && (data[++index] == 'e')
3388 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'd')) {
3389 return TokenNameprotected;
3391 return TokenNameIdentifier;
3393 return TokenNameIdentifier;
3395 // return require require_once
3397 if ((data[++index] == 'e') && (data[++index] == 't') && (data[++index] == 'u') && (data[++index] == 'r')
3398 && (data[++index] == 'n')) {
3399 return TokenNamereturn;
3401 } else if (length == 7) {
3402 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3403 && (data[++index] == 'r') && (data[++index] == 'e')) {
3404 return TokenNamerequire;
3406 } else if (length == 12) {
3407 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3408 && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3409 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e')) {
3410 return TokenNamerequire_once;
3413 return TokenNameIdentifier;
3415 // self static switch
3418 // if ((data[++index] == 'e') && (data[++index] == 'l') && (data[++index]
3420 // return TokenNameself;
3422 // return TokenNameIdentifier;
3424 if (data[++index] == 't')
3425 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) {
3426 return TokenNamestatic;
3428 return TokenNameIdentifier;
3429 else if ((data[index] == 'w') && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c')
3430 && (data[++index] == 'h'))
3431 return TokenNameswitch;
3433 return TokenNameIdentifier;
3435 return TokenNameIdentifier;
3441 if ((data[++index] == 'r') && (data[++index] == 'y'))
3442 return TokenNametry;
3444 return TokenNameIdentifier;
3446 // if ((data[++index] == 'r') && (data[++index] == 'u')
3447 // && (data[++index] == 'e'))
3448 // return TokenNametrue;
3450 // return TokenNameIdentifier;
3452 if ((data[++index] == 'h') && (data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 'w'))
3453 return TokenNamethrow;
3455 return TokenNameIdentifier;
3457 return TokenNameIdentifier;
3463 if ((data[++index] == 's') && (data[++index] == 'e'))
3464 return TokenNameuse;
3466 return TokenNameIdentifier;
3468 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3469 return TokenNameunset;
3471 return TokenNameIdentifier;
3473 return TokenNameIdentifier;
3479 if ((data[++index] == 'a') && (data[++index] == 'r'))
3480 return TokenNamevar;
3482 return TokenNameIdentifier;
3484 return TokenNameIdentifier;
3490 if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3491 return TokenNamewhile;
3493 return TokenNameIdentifier;
3494 // case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3495 // (data[++index]=='e') && (data[++index]=='f')&&
3496 // (data[++index]=='p'))
3497 // return TokenNamewidefp ;
3499 // return TokenNameIdentifier;
3501 return TokenNameIdentifier;
3507 if ((data[++index] == 'o') && (data[++index] == 'r'))
3508 return TokenNamexor;
3510 return TokenNameIdentifier;
3512 return TokenNameIdentifier;
3515 return TokenNameIdentifier;
3519 public int scanNumber(boolean dotPrefix) throws InvalidInputException {
3520 // when entering this method the currentCharacter is the firt
3521 // digit of the number , i.e. it may be preceeded by a . when
3522 // dotPrefix is true
3523 boolean floating = dotPrefix;
3524 if ((!dotPrefix) && (currentCharacter == '0')) {
3525 if (getNextChar('x', 'X') >= 0) { // ----------hexa-----------------
3526 // force the first char of the hexa number do exist...
3527 // consume next character
3528 unicodeAsBackSlash = false;
3529 currentCharacter = source[currentPosition++];
3530 // if (((currentCharacter = source[currentPosition++]) == '\\')
3531 // && (source[currentPosition] == 'u')) {
3532 // getNextUnicodeChar();
3534 // if (withoutUnicodePtr != 0) {
3535 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3538 if (Character.digit(currentCharacter, 16) == -1)
3539 throw new InvalidInputException(INVALID_HEXA);
3541 while (getNextCharAsDigit(16)) {
3544 // if (getNextChar('l', 'L') >= 0)
3545 // return TokenNameLongLiteral;
3547 return TokenNameIntegerLiteral;
3549 // there is x or X in the number
3550 // potential octal ! ... some one may write 000099.0 ! thus 00100 <
3551 // 00078.0 is true !!!!! crazy language
3552 if (getNextCharAsDigit()) {
3553 // -------------potential octal-----------------
3554 while (getNextCharAsDigit()) {
3557 // if (getNextChar('l', 'L') >= 0) {
3558 // return TokenNameLongLiteral;
3561 // if (getNextChar('f', 'F') >= 0) {
3562 // return TokenNameFloatingPointLiteral;
3564 if (getNextChar('d', 'D') >= 0) {
3565 return TokenNameDoubleLiteral;
3566 } else { // make the distinction between octal and float ....
3567 if (getNextChar('.')) { // bingo ! ....
3568 while (getNextCharAsDigit()) {
3571 if (getNextChar('e', 'E') >= 0) {
3572 // consume next character
3573 unicodeAsBackSlash = false;
3574 currentCharacter = source[currentPosition++];
3575 // if (((currentCharacter = source[currentPosition++]) == '\\')
3576 // && (source[currentPosition] == 'u')) {
3577 // getNextUnicodeChar();
3579 // if (withoutUnicodePtr != 0) {
3580 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3583 if ((currentCharacter == '-') || (currentCharacter == '+')) {
3584 // consume next character
3585 unicodeAsBackSlash = false;
3586 currentCharacter = source[currentPosition++];
3587 // if (((currentCharacter = source[currentPosition++]) == '\\')
3588 // && (source[currentPosition] == 'u')) {
3589 // getNextUnicodeChar();
3591 // if (withoutUnicodePtr != 0) {
3592 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3593 // currentCharacter;
3597 if (!Character.isDigit(currentCharacter))
3598 throw new InvalidInputException(INVALID_FLOAT);
3599 while (getNextCharAsDigit()) {
3603 // if (getNextChar('f', 'F') >= 0)
3604 // return TokenNameFloatingPointLiteral;
3605 getNextChar('d', 'D'); // jump over potential d or D
3606 return TokenNameDoubleLiteral;
3608 return TokenNameIntegerLiteral;
3615 while (getNextCharAsDigit()) {
3618 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3619 // return TokenNameLongLiteral;
3620 if ((!dotPrefix) && (getNextChar('.'))) { // decimal part that can be empty
3621 while (getNextCharAsDigit()) {
3626 // if floating is true both exponant and suffix may be optional
3627 if (getNextChar('e', 'E') >= 0) {
3629 // consume next character
3630 unicodeAsBackSlash = false;
3631 currentCharacter = source[currentPosition++];
3632 // if (((currentCharacter = source[currentPosition++]) == '\\')
3633 // && (source[currentPosition] == 'u')) {
3634 // getNextUnicodeChar();
3636 // if (withoutUnicodePtr != 0) {
3637 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3640 if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
3643 unicodeAsBackSlash = false;
3644 currentCharacter = source[currentPosition++];
3645 // if (((currentCharacter = source[currentPosition++]) == '\\')
3646 // && (source[currentPosition] == 'u')) {
3647 // getNextUnicodeChar();
3649 // if (withoutUnicodePtr != 0) {
3650 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3654 if (!Character.isDigit(currentCharacter))
3655 throw new InvalidInputException(INVALID_FLOAT);
3656 while (getNextCharAsDigit()) {
3660 if (getNextChar('d', 'D') >= 0)
3661 return TokenNameDoubleLiteral;
3662 // if (getNextChar('f', 'F') >= 0)
3663 // return TokenNameFloatingPointLiteral;
3664 // the long flag has been tested before
3665 return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral;
3669 * Search the line number corresponding to a specific position
3672 public final int getLineNumber(int position) {
3673 if (lineEnds == null)
3675 int length = linePtr + 1;
3678 int g = 0, d = length - 1;
3682 if (position < lineEnds[m]) {
3684 } else if (position > lineEnds[m]) {
3690 if (position < lineEnds[m]) {
3696 public void setPHPMode(boolean mode) {
3700 public final void setSource(char[] source) {
3701 setSource(null, source);
3704 public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3705 // the source-buffer is set to sourceString
3706 this.compilationUnit = compilationUnit;
3707 if (source == null) {
3708 this.source = new char[0];
3710 this.source = source;
3713 initialPosition = currentPosition = 0;
3714 containsAssertKeyword = false;
3715 withoutUnicodeBuffer = new char[this.source.length];
3716 fFillerToken = TokenNameEOF;
3717 // encapsedStringStack = new Stack();
3720 public String toString() {
3721 if (startPosition == source.length)
3722 return "EOF\n\n" + new String(source); //$NON-NLS-1$
3723 if (currentPosition > source.length)
3724 return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3725 char front[] = new char[startPosition];
3726 System.arraycopy(source, 0, front, 0, startPosition);
3727 int middleLength = (currentPosition - 1) - startPosition + 1;
3729 if (middleLength > -1) {
3730 middle = new char[middleLength];
3731 System.arraycopy(source, startPosition, middle, 0, middleLength);
3733 middle = new char[0];
3735 char end[] = new char[source.length - (currentPosition - 1)];
3736 System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - (currentPosition - 1) - 1);
3737 return new String(front) + "\n===============================\nStarts here -->" //$NON-NLS-1$
3738 + new String(middle) + "<-- Ends here\n===============================\n" //$NON-NLS-1$
3742 public final String toStringAction(int act) {
3744 case TokenNameERROR:
3745 return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
3747 case TokenNameINLINE_HTML:
3748 return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3749 case TokenNameECHO_INVISIBLE:
3752 case TokenNameIdentifier:
3753 return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3754 case TokenNameVariable:
3755 return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3756 case TokenNameabstract:
3757 return "abstract"; //$NON-NLS-1$
3759 return "AND"; //$NON-NLS-1$
3760 case TokenNamearray:
3761 return "array"; //$NON-NLS-1$
3763 return "as"; //$NON-NLS-1$
3764 case TokenNamebreak:
3765 return "break"; //$NON-NLS-1$
3767 return "case"; //$NON-NLS-1$
3768 case TokenNameclass:
3769 return "class"; //$NON-NLS-1$
3770 case TokenNamecatch:
3771 return "catch"; //$NON-NLS-1$
3772 case TokenNameclone:
3775 case TokenNameconst:
3778 case TokenNamecontinue:
3779 return "continue"; //$NON-NLS-1$
3780 case TokenNamedefault:
3781 return "default"; //$NON-NLS-1$
3782 // case TokenNamedefine :
3783 // return "define"; //$NON-NLS-1$
3785 return "do"; //$NON-NLS-1$
3787 return "echo"; //$NON-NLS-1$
3789 return "else"; //$NON-NLS-1$
3790 case TokenNameelseif:
3791 return "elseif"; //$NON-NLS-1$
3792 case TokenNameendfor:
3793 return "endfor"; //$NON-NLS-1$
3794 case TokenNameendforeach:
3795 return "endforeach"; //$NON-NLS-1$
3796 case TokenNameendif:
3797 return "endif"; //$NON-NLS-1$
3798 case TokenNameendswitch:
3799 return "endswitch"; //$NON-NLS-1$
3800 case TokenNameendwhile:
3801 return "endwhile"; //$NON-NLS-1$
3804 case TokenNameextends:
3805 return "extends"; //$NON-NLS-1$
3806 // case TokenNamefalse :
3807 // return "false"; //$NON-NLS-1$
3808 case TokenNamefinal:
3809 return "final"; //$NON-NLS-1$
3811 return "for"; //$NON-NLS-1$
3812 case TokenNameforeach:
3813 return "foreach"; //$NON-NLS-1$
3814 case TokenNamefunction:
3815 return "function"; //$NON-NLS-1$
3816 case TokenNameglobal:
3817 return "global"; //$NON-NLS-1$
3819 return "if"; //$NON-NLS-1$
3820 case TokenNameimplements:
3821 return "implements"; //$NON-NLS-1$
3822 case TokenNameinclude:
3823 return "include"; //$NON-NLS-1$
3824 case TokenNameinclude_once:
3825 return "include_once"; //$NON-NLS-1$
3826 case TokenNameinstanceof:
3827 return "instanceof"; //$NON-NLS-1$
3828 case TokenNameinterface:
3829 return "interface"; //$NON-NLS-1$
3830 case TokenNameisset:
3831 return "isset"; //$NON-NLS-1$
3833 return "list"; //$NON-NLS-1$
3835 return "new"; //$NON-NLS-1$
3836 // case TokenNamenull :
3837 // return "null"; //$NON-NLS-1$
3839 return "OR"; //$NON-NLS-1$
3840 case TokenNameprint:
3841 return "print"; //$NON-NLS-1$
3842 case TokenNameprivate:
3843 return "private"; //$NON-NLS-1$
3844 case TokenNameprotected:
3845 return "protected"; //$NON-NLS-1$
3846 case TokenNamepublic:
3847 return "public"; //$NON-NLS-1$
3848 case TokenNamerequire:
3849 return "require"; //$NON-NLS-1$
3850 case TokenNamerequire_once:
3851 return "require_once"; //$NON-NLS-1$
3852 case TokenNamereturn:
3853 return "return"; //$NON-NLS-1$
3854 // case TokenNameself:
3855 // return "self"; //$NON-NLS-1$
3856 case TokenNamestatic:
3857 return "static"; //$NON-NLS-1$
3858 case TokenNameswitch:
3859 return "switch"; //$NON-NLS-1$
3860 // case TokenNametrue :
3861 // return "true"; //$NON-NLS-1$
3862 case TokenNameunset:
3863 return "unset"; //$NON-NLS-1$
3865 return "var"; //$NON-NLS-1$
3866 case TokenNamewhile:
3867 return "while"; //$NON-NLS-1$
3869 return "XOR"; //$NON-NLS-1$
3870 // case TokenNamethis :
3871 // return "$this"; //$NON-NLS-1$
3872 case TokenNameIntegerLiteral:
3873 return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3874 case TokenNameDoubleLiteral:
3875 return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3876 case TokenNameStringDoubleQuote:
3877 return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3878 case TokenNameStringSingleQuote:
3879 return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3880 case TokenNameStringInterpolated:
3881 return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3882 case TokenNameEncapsedString0:
3883 return "`"; //$NON-NLS-1$
3884 // case TokenNameEncapsedString1:
3885 // return "\'"; //$NON-NLS-1$
3886 // case TokenNameEncapsedString2:
3887 // return "\""; //$NON-NLS-1$
3888 case TokenNameSTRING:
3889 return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3890 case TokenNameHEREDOC:
3891 return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3892 case TokenNamePLUS_PLUS:
3893 return "++"; //$NON-NLS-1$
3894 case TokenNameMINUS_MINUS:
3895 return "--"; //$NON-NLS-1$
3896 case TokenNameEQUAL_EQUAL:
3897 return "=="; //$NON-NLS-1$
3898 case TokenNameEQUAL_EQUAL_EQUAL:
3899 return "==="; //$NON-NLS-1$
3900 case TokenNameEQUAL_GREATER:
3901 return "=>"; //$NON-NLS-1$
3902 case TokenNameLESS_EQUAL:
3903 return "<="; //$NON-NLS-1$
3904 case TokenNameGREATER_EQUAL:
3905 return ">="; //$NON-NLS-1$
3906 case TokenNameNOT_EQUAL:
3907 return "!="; //$NON-NLS-1$
3908 case TokenNameNOT_EQUAL_EQUAL:
3909 return "!=="; //$NON-NLS-1$
3910 case TokenNameLEFT_SHIFT:
3911 return "<<"; //$NON-NLS-1$
3912 case TokenNameRIGHT_SHIFT:
3913 return ">>"; //$NON-NLS-1$
3914 case TokenNamePLUS_EQUAL:
3915 return "+="; //$NON-NLS-1$
3916 case TokenNameMINUS_EQUAL:
3917 return "-="; //$NON-NLS-1$
3918 case TokenNameMULTIPLY_EQUAL:
3919 return "*="; //$NON-NLS-1$
3920 case TokenNameDIVIDE_EQUAL:
3921 return "/="; //$NON-NLS-1$
3922 case TokenNameAND_EQUAL:
3923 return "&="; //$NON-NLS-1$
3924 case TokenNameOR_EQUAL:
3925 return "|="; //$NON-NLS-1$
3926 case TokenNameXOR_EQUAL:
3927 return "^="; //$NON-NLS-1$
3928 case TokenNameREMAINDER_EQUAL:
3929 return "%="; //$NON-NLS-1$
3930 case TokenNameDOT_EQUAL:
3931 return ".="; //$NON-NLS-1$
3932 case TokenNameLEFT_SHIFT_EQUAL:
3933 return "<<="; //$NON-NLS-1$
3934 case TokenNameRIGHT_SHIFT_EQUAL:
3935 return ">>="; //$NON-NLS-1$
3936 case TokenNameOR_OR:
3937 return "||"; //$NON-NLS-1$
3938 case TokenNameAND_AND:
3939 return "&&"; //$NON-NLS-1$
3941 return "+"; //$NON-NLS-1$
3942 case TokenNameMINUS:
3943 return "-"; //$NON-NLS-1$
3944 case TokenNameMINUS_GREATER:
3947 return "!"; //$NON-NLS-1$
3948 case TokenNameREMAINDER:
3949 return "%"; //$NON-NLS-1$
3951 return "^"; //$NON-NLS-1$
3953 return "&"; //$NON-NLS-1$
3954 case TokenNameMULTIPLY:
3955 return "*"; //$NON-NLS-1$
3957 return "|"; //$NON-NLS-1$
3958 case TokenNameTWIDDLE:
3959 return "~"; //$NON-NLS-1$
3960 case TokenNameTWIDDLE_EQUAL:
3961 return "~="; //$NON-NLS-1$
3962 case TokenNameDIVIDE:
3963 return "/"; //$NON-NLS-1$
3964 case TokenNameGREATER:
3965 return ">"; //$NON-NLS-1$
3967 return "<"; //$NON-NLS-1$
3968 case TokenNameLPAREN:
3969 return "("; //$NON-NLS-1$
3970 case TokenNameRPAREN:
3971 return ")"; //$NON-NLS-1$
3972 case TokenNameLBRACE:
3973 return "{"; //$NON-NLS-1$
3974 case TokenNameRBRACE:
3975 return "}"; //$NON-NLS-1$
3976 case TokenNameLBRACKET:
3977 return "["; //$NON-NLS-1$
3978 case TokenNameRBRACKET:
3979 return "]"; //$NON-NLS-1$
3980 case TokenNameSEMICOLON:
3981 return ";"; //$NON-NLS-1$
3982 case TokenNameQUESTION:
3983 return "?"; //$NON-NLS-1$
3984 case TokenNameCOLON:
3985 return ":"; //$NON-NLS-1$
3986 case TokenNameCOMMA:
3987 return ","; //$NON-NLS-1$
3989 return "."; //$NON-NLS-1$
3990 case TokenNameEQUAL:
3991 return "="; //$NON-NLS-1$
3994 case TokenNameDOLLAR:
3996 case TokenNameDOLLAR_LBRACE:
3998 case TokenNameLBRACE_DOLLAR:
4001 return "EOF"; //$NON-NLS-1$
4002 case TokenNameWHITESPACE:
4003 return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4004 case TokenNameCOMMENT_LINE:
4005 return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4006 case TokenNameCOMMENT_BLOCK:
4007 return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4008 case TokenNameCOMMENT_PHPDOC:
4009 return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4010 // case TokenNameHTML :
4011 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
4014 return "__FILE__"; //$NON-NLS-1$
4016 return "__LINE__"; //$NON-NLS-1$
4017 case TokenNameCLASS_C:
4018 return "__CLASS__"; //$NON-NLS-1$
4019 case TokenNameMETHOD_C:
4020 return "__METHOD__"; //$NON-NLS-1$
4021 case TokenNameFUNC_C:
4022 return "__FUNCTION__"; //$NON-NLS-1
4023 case TokenNameboolCAST:
4024 return "( bool )"; //$NON-NLS-1$
4025 case TokenNameintCAST:
4026 return "( int )"; //$NON-NLS-1$
4027 case TokenNamedoubleCAST:
4028 return "( double )"; //$NON-NLS-1$
4029 case TokenNameobjectCAST:
4030 return "( object )"; //$NON-NLS-1$
4031 case TokenNamestringCAST:
4032 return "( string )"; //$NON-NLS-1$
4034 return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
4042 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
4043 this(tokenizeComments, tokenizeWhiteSpace, false);
4046 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals) {
4047 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, false);
4050 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4051 boolean assertMode) {
4052 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, assertMode, false, null, null, true);
4055 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4056 boolean assertMode, boolean tokenizeStrings, char[][] taskTags, char[][] taskPriorities, boolean isTaskCaseSensitive) {
4057 this.eofPosition = Integer.MAX_VALUE;
4058 this.tokenizeComments = tokenizeComments;
4059 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4060 this.tokenizeStrings = tokenizeStrings;
4061 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4062 // this.assertMode = assertMode;
4063 // this.encapsedStringStack = null;
4064 this.taskTags = taskTags;
4065 this.taskPriorities = taskPriorities;
4068 private void checkNonExternalizeString() throws InvalidInputException {
4069 if (currentLine == null)
4071 parseTags(currentLine);
4074 private void parseTags(NLSLine line) throws InvalidInputException {
4075 String s = new String(getCurrentTokenSource());
4076 int pos = s.indexOf(TAG_PREFIX);
4077 int lineLength = line.size();
4079 int start = pos + TAG_PREFIX_LENGTH;
4080 int end = s.indexOf(TAG_POSTFIX, start);
4081 String index = s.substring(start, end);
4084 i = Integer.parseInt(index) - 1;
4085 // Tags are one based not zero based.
4086 } catch (NumberFormatException e) {
4087 i = -1; // we don't want to consider this as a valid NLS tag
4089 if (line.exists(i)) {
4092 pos = s.indexOf(TAG_PREFIX, start);
4094 this.nonNLSStrings = new StringLiteral[lineLength];
4095 int nonNLSCounter = 0;
4096 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4097 StringLiteral literal = (StringLiteral) iterator.next();
4098 if (literal != null) {
4099 this.nonNLSStrings[nonNLSCounter++] = literal;
4102 if (nonNLSCounter == 0) {
4103 this.nonNLSStrings = null;
4107 this.wasNonExternalizedStringLiteral = true;
4108 if (nonNLSCounter != lineLength) {
4109 System.arraycopy(this.nonNLSStrings, 0, (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, nonNLSCounter);
4114 public final void scanEscapeCharacter() throws InvalidInputException {
4115 // the string with "\\u" is a legal string of two chars \ and u
4116 // thus we use a direct access to the source (for regular cases).
4117 if (unicodeAsBackSlash) {
4118 // consume next character
4119 unicodeAsBackSlash = false;
4120 // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4121 // (source[currentPosition] == 'u')) {
4122 // getNextUnicodeChar();
4124 if (withoutUnicodePtr != 0) {
4125 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4129 currentCharacter = source[currentPosition++];
4130 switch (currentCharacter) {
4132 currentCharacter = '\b';
4135 currentCharacter = '\t';
4138 currentCharacter = '\n';
4141 currentCharacter = '\f';
4144 currentCharacter = '\r';
4147 currentCharacter = '\"';
4150 currentCharacter = '\'';
4153 currentCharacter = '\\';
4156 // -----------octal escape--------------
4158 // OctalDigit OctalDigit
4159 // ZeroToThree OctalDigit OctalDigit
4160 int number = Character.getNumericValue(currentCharacter);
4161 if (number >= 0 && number <= 7) {
4162 boolean zeroToThreeNot = number > 3;
4163 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4164 int digit = Character.getNumericValue(currentCharacter);
4165 if (digit >= 0 && digit <= 7) {
4166 number = (number * 8) + digit;
4167 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4168 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
4169 // Digit --> ignore last character
4172 digit = Character.getNumericValue(currentCharacter);
4173 if (digit >= 0 && digit <= 7) { // has read \ZeroToThree
4174 // OctalDigit OctalDigit
4175 number = (number * 8) + digit;
4176 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
4177 // --> ignore last character
4181 } else { // has read \OctalDigit NonDigit--> ignore last
4185 } else { // has read \OctalDigit NonOctalDigit--> ignore last
4189 } else { // has read \OctalDigit --> ignore last character
4193 throw new InvalidInputException(INVALID_ESCAPE);
4194 currentCharacter = (char) number;
4196 throw new InvalidInputException(INVALID_ESCAPE);
4200 // chech presence of task: tags
4201 // TODO (frederic) see if we need to take unicode characters into account...
4202 public void checkTaskTag(int commentStart, int commentEnd) {
4203 char[] src = this.source;
4205 // only look for newer task: tags
4206 if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4209 int foundTaskIndex = this.foundTaskCount;
4210 char previous = src[commentStart + 1]; // should be '*' or '/'
4211 nextChar: for (int i = commentStart + 2; i < commentEnd && i < this.eofPosition; i++) {
4213 char[] priority = null;
4214 // check for tag occurrence only if not ambiguous with javadoc tag
4215 if (previous != '@') {
4216 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4217 tag = this.taskTags[itag];
4218 int tagLength = tag.length;
4222 // ensure tag is not leaded with letter if tag starts with a letter
4223 if (Scanner.isPHPIdentifierStart(tag[0])) {
4224 if (Scanner.isPHPIdentifierPart(previous)) {
4229 for (int t = 0; t < tagLength; t++) {
4232 if (x >= this.eofPosition || x >= commentEnd)
4234 if ((sc = src[i + t]) != (tc = tag[t])) { // case sensitive check
4235 if (this.isTaskCaseSensitive || (Character.toLowerCase(sc) != Character.toLowerCase(tc))) { // case
4242 // ensure tag is not followed with letter if tag finishes with a
4244 if (i + tagLength < commentEnd && Scanner.isPHPIdentifierPart(src[i + tagLength - 1])) {
4245 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4248 if (this.foundTaskTags == null) {
4249 this.foundTaskTags = new char[5][];
4250 this.foundTaskMessages = new char[5][];
4251 this.foundTaskPriorities = new char[5][];
4252 this.foundTaskPositions = new int[5][];
4253 } else if (this.foundTaskCount == this.foundTaskTags.length) {
4254 System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0,
4255 this.foundTaskCount);
4256 System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4257 this.foundTaskCount);
4258 System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4259 this.foundTaskCount);
4260 System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4261 this.foundTaskCount);
4264 priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4266 this.foundTaskTags[this.foundTaskCount] = tag;
4267 this.foundTaskPriorities[this.foundTaskCount] = priority;
4268 this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4269 this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4270 this.foundTaskCount++;
4271 i += tagLength - 1; // will be incremented when looping
4277 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4278 // retrieve message start and end positions
4279 int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4280 int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4281 // at most beginning of next task
4282 if (max_value < msgStart) {
4283 max_value = msgStart; // would only occur if tag is before EOF.
4287 for (int j = msgStart; j < max_value; j++) {
4288 if ((c = src[j]) == '\n' || c == '\r') {
4294 for (int j = max_value; j > msgStart; j--) {
4295 if ((c = src[j]) == '*') {
4303 if (msgStart == end)
4306 while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4308 while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4310 // update the end position of the task
4311 this.foundTaskPositions[i][1] = end;
4312 // get the message source
4313 final int messageLength = end - msgStart + 1;
4314 char[] message = new char[messageLength];
4315 System.arraycopy(src, msgStart, message, 0, messageLength);
4316 this.foundTaskMessages[i] = message;
4320 // chech presence of task: tags
4321 // public void checkTaskTag(int commentStart, int commentEnd) {
4322 // // only look for newer task: tags
4323 // if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount
4324 // - 1][0] >= commentStart) {
4327 // int foundTaskIndex = this.foundTaskCount;
4328 // nextChar: for (int i = commentStart; i < commentEnd && i <
4329 // this.eofPosition; i++) {
4330 // char[] tag = null;
4331 // char[] priority = null;
4332 // // check for tag occurrence
4333 // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4334 // tag = this.taskTags[itag];
4335 // priority = this.taskPriorities != null && itag < this.taskPriorities.length
4336 // ? this.taskPriorities[itag] : null;
4337 // int tagLength = tag.length;
4338 // for (int t = 0; t < tagLength; t++) {
4339 // if (this.source[i + t] != tag[t])
4340 // continue nextTag;
4342 // if (this.foundTaskTags == null) {
4343 // this.foundTaskTags = new char[5][];
4344 // this.foundTaskMessages = new char[5][];
4345 // this.foundTaskPriorities = new char[5][];
4346 // this.foundTaskPositions = new int[5][];
4347 // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4348 // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new
4349 // char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4350 // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new
4351 // char[this.foundTaskCount * 2][], 0,
4352 // this.foundTaskCount);
4353 // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities =
4354 // new char[this.foundTaskCount * 2][], 0,
4355 // this.foundTaskCount);
4356 // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new
4357 // int[this.foundTaskCount * 2][], 0,
4358 // this.foundTaskCount);
4360 // this.foundTaskTags[this.foundTaskCount] = tag;
4361 // this.foundTaskPriorities[this.foundTaskCount] = priority;
4362 // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength
4364 // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4365 // this.foundTaskCount++;
4366 // i += tagLength - 1; // will be incremented when looping
4369 // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4370 // // retrieve message start and end positions
4371 // int msgStart = this.foundTaskPositions[i][0] +
4372 // this.foundTaskTags[i].length;
4373 // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i +
4374 // 1][0] - 1 : commentEnd - 1;
4375 // // at most beginning of next task
4376 // if (max_value < msgStart)
4377 // max_value = msgStart; // would only occur if tag is before EOF.
4380 // for (int j = msgStart; j < max_value; j++) {
4381 // if ((c = this.source[j]) == '\n' || c == '\r') {
4387 // for (int j = max_value; j > msgStart; j--) {
4388 // if ((c = this.source[j]) == '*') {
4396 // if (msgStart == end)
4397 // continue; // empty
4398 // // trim the message
4399 // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4401 // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4403 // // update the end position of the task
4404 // this.foundTaskPositions[i][1] = end;
4405 // // get the message source
4406 // final int messageLength = end - msgStart + 1;
4407 // char[] message = new char[messageLength];
4408 // System.arraycopy(source, msgStart, message, 0, messageLength);
4409 // this.foundTaskMessages[i] = message;