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 int openDollarBrace = 0;
1220 // consume next character
1221 unicodeAsBackSlash = false;
1222 currentCharacter = source[currentPosition++];
1223 while (currentCharacter != '"' || openDollarBrace>0) {
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] == '{') {
1246 } else if (currentCharacter == '{' && source[currentPosition] == '$') {
1248 } else if (currentCharacter == '}') {
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;
3061 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3062 return TokenNameand;
3064 return TokenNameIdentifier;
3067 if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y'))
3068 return TokenNamearray;
3069 return TokenNameIdentifier;
3071 if ((data[++index] == 'b') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'r')
3072 && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 't'))
3073 return TokenNameabstract;
3074 return TokenNameIdentifier;
3076 return TokenNameIdentifier;
3081 if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k'))
3082 return TokenNamebreak;
3083 return TokenNameIdentifier;
3085 return TokenNameIdentifier;
3087 // case catch class clone const continue
3090 if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e'))
3091 return TokenNamecase;
3092 return TokenNameIdentifier;
3094 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3095 return TokenNamecatch;
3097 if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's'))
3098 return TokenNameclass;
3100 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 'e'))
3101 return TokenNameclone;
3103 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't'))
3104 return TokenNameconst;
3105 return TokenNameIdentifier;
3107 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'i')
3108 && (data[++index] == 'n') && (data[++index] == 'u') && (data[++index] == 'e'))
3109 return TokenNamecontinue;
3110 return TokenNameIdentifier;
3112 return TokenNameIdentifier;
3114 // declare default do die
3115 // TODO delete define ==> no keyword !
3118 if ((data[++index] == 'o'))
3120 return TokenNameIdentifier;
3122 // if ((data[++index] == 'e')
3123 // && (data[++index] == 'f')
3124 // && (data[++index] == 'i')
3125 // && (data[++index] == 'n')
3126 // && (data[++index] == 'e'))
3127 // return TokenNamedefine;
3129 // return TokenNameIdentifier;
3131 if ((data[++index] == 'e') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3132 && (data[++index] == 'r') && (data[++index] == 'e'))
3133 return TokenNamedeclare;
3135 if ((data[++index] == 'e') && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'u')
3136 && (data[++index] == 'l') && (data[++index] == 't'))
3137 return TokenNamedefault;
3138 return TokenNameIdentifier;
3140 return TokenNameIdentifier;
3142 // echo else exit elseif extends eval
3145 if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o'))
3146 return TokenNameecho;
3147 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e'))
3148 return TokenNameelse;
3149 else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't'))
3150 return TokenNameexit;
3151 else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l'))
3152 return TokenNameeval;
3153 return TokenNameIdentifier;
3156 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f'))
3157 return TokenNameendif;
3158 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 't') && (data[++index] == 'y'))
3159 return TokenNameempty;
3160 return TokenNameIdentifier;
3163 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o')
3164 && (data[++index] == 'r'))
3165 return TokenNameendfor;
3166 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 'i')
3167 && (data[++index] == 'f'))
3168 return TokenNameelseif;
3169 return TokenNameIdentifier;
3171 if ((data[++index] == 'x') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'n')
3172 && (data[++index] == 'd') && (data[++index] == 's'))
3173 return TokenNameextends;
3174 return TokenNameIdentifier;
3177 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'w') && (data[++index] == 'h')
3178 && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3179 return TokenNameendwhile;
3180 return TokenNameIdentifier;
3183 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 's') && (data[++index] == 'w')
3184 && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3185 return TokenNameendswitch;
3186 return TokenNameIdentifier;
3189 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'd') && (data[++index] == 'e')
3190 && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 'r')
3191 && (data[++index] == 'e'))
3192 return TokenNameenddeclare;
3194 if ((data[++index] == 'n') // endforeach
3195 && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r')
3196 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'h'))
3197 return TokenNameendforeach;
3198 return TokenNameIdentifier;
3200 return TokenNameIdentifier;
3202 // for false final function
3205 if ((data[++index] == 'o') && (data[++index] == 'r'))
3206 return TokenNamefor;
3207 return TokenNameIdentifier;
3209 // if ((data[++index] == 'a') && (data[++index] == 'l')
3210 // && (data[++index] == 's') && (data[++index] == 'e'))
3211 // return TokenNamefalse;
3212 if ((data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 'a') && (data[++index] == 'l'))
3213 return TokenNamefinal;
3214 return TokenNameIdentifier;
3217 if ((data[++index] == 'o') && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a')
3218 && (data[++index] == 'c') && (data[++index] == 'h'))
3219 return TokenNameforeach;
3220 return TokenNameIdentifier;
3223 if ((data[++index] == 'u') && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 't')
3224 && (data[++index] == 'i') && (data[++index] == 'o') && (data[++index] == 'n'))
3225 return TokenNamefunction;
3226 return TokenNameIdentifier;
3228 return TokenNameIdentifier;
3232 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'b') && (data[++index] == 'a')
3233 && (data[++index] == 'l')) {
3234 return TokenNameglobal;
3237 return TokenNameIdentifier;
3239 // if int isset include include_once instanceof interface implements
3242 if (data[++index] == 'f')
3244 return TokenNameIdentifier;
3246 // if ((data[++index] == 'n') && (data[++index] == 't'))
3247 // return TokenNameint;
3249 // return TokenNameIdentifier;
3251 if ((data[++index] == 's') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3252 return TokenNameisset;
3253 return TokenNameIdentifier;
3255 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3256 && (data[++index] == 'd') && (data[++index] == 'e'))
3257 return TokenNameinclude;
3258 return TokenNameIdentifier;
3261 if ((data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'r')
3262 && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'e'))
3263 return TokenNameinterface;
3264 return TokenNameIdentifier;
3267 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'a')
3268 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e') && (data[++index] == 'o')
3269 && (data[++index] == 'f'))
3270 return TokenNameinstanceof;
3271 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 'l') && (data[++index] == 'e')
3272 && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 'n') && (data[++index] == 't')
3273 && (data[++index] == 's'))
3274 return TokenNameimplements;
3275 return TokenNameIdentifier;
3277 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3278 && (data[++index] == 'd') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3279 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e'))
3280 return TokenNameinclude_once;
3281 return TokenNameIdentifier;
3283 return TokenNameIdentifier;
3287 if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) {
3288 return TokenNamelist;
3291 return TokenNameIdentifier;
3296 if ((data[++index] == 'e') && (data[++index] == 'w'))
3297 return TokenNamenew;
3298 return TokenNameIdentifier;
3300 // if ((data[++index] == 'u') && (data[++index] == 'l')
3301 // && (data[++index] == 'l'))
3302 // return TokenNamenull;
3304 // return TokenNameIdentifier;
3306 return TokenNameIdentifier;
3310 if (data[++index] == 'r') {
3314 // if (length == 12) {
3315 // if ((data[++index] == 'l')
3316 // && (data[++index] == 'd')
3317 // && (data[++index] == '_')
3318 // && (data[++index] == 'f')
3319 // && (data[++index] == 'u')
3320 // && (data[++index] == 'n')
3321 // && (data[++index] == 'c')
3322 // && (data[++index] == 't')
3323 // && (data[++index] == 'i')
3324 // && (data[++index] == 'o')
3325 // && (data[++index] == 'n')) {
3326 // return TokenNameold_function;
3329 return TokenNameIdentifier;
3331 // print public private protected
3334 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
3335 return TokenNameprint;
3337 return TokenNameIdentifier;
3339 if ((data[++index] == 'u') && (data[++index] == 'b') && (data[++index] == 'l') && (data[++index] == 'i')
3340 && (data[++index] == 'c')) {
3341 return TokenNamepublic;
3343 return TokenNameIdentifier;
3345 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'v') && (data[++index] == 'a')
3346 && (data[++index] == 't') && (data[++index] == 'e')) {
3347 return TokenNameprivate;
3349 return TokenNameIdentifier;
3351 if ((data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 't') && (data[++index] == 'e')
3352 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'd')) {
3353 return TokenNameprotected;
3355 return TokenNameIdentifier;
3357 return TokenNameIdentifier;
3359 // return require require_once
3361 if ((data[++index] == 'e') && (data[++index] == 't') && (data[++index] == 'u') && (data[++index] == 'r')
3362 && (data[++index] == 'n')) {
3363 return TokenNamereturn;
3365 } else if (length == 7) {
3366 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3367 && (data[++index] == 'r') && (data[++index] == 'e')) {
3368 return TokenNamerequire;
3370 } else if (length == 12) {
3371 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3372 && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3373 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e')) {
3374 return TokenNamerequire_once;
3377 return TokenNameIdentifier;
3379 // self static switch
3382 // if ((data[++index] == 'e') && (data[++index] == 'l') && (data[++index]
3384 // return TokenNameself;
3386 // return TokenNameIdentifier;
3388 if (data[++index] == 't')
3389 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) {
3390 return TokenNamestatic;
3392 return TokenNameIdentifier;
3393 else if ((data[index] == 'w') && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c')
3394 && (data[++index] == 'h'))
3395 return TokenNameswitch;
3397 return TokenNameIdentifier;
3402 if ((data[++index] == 'r') && (data[++index] == 'y'))
3403 return TokenNametry;
3405 // if ((data[++index] == 'r') && (data[++index] == 'u')
3406 // && (data[++index] == 'e'))
3407 // return TokenNametrue;
3409 // return TokenNameIdentifier;
3411 if ((data[++index] == 'h') && (data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 'w'))
3412 return TokenNamethrow;
3414 return TokenNameIdentifier;
3419 if ((data[++index] == 's') && (data[++index] == 'e'))
3420 return TokenNameuse;
3422 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3423 return TokenNameunset;
3425 return TokenNameIdentifier;
3430 if ((data[++index] == 'a') && (data[++index] == 'r'))
3431 return TokenNamevar;
3433 return TokenNameIdentifier;
3438 if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3439 return TokenNamewhile;
3440 // case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3441 // (data[++index]=='e') && (data[++index]=='f')&&
3442 // (data[++index]=='p'))
3443 // return TokenNamewidefp ;
3445 // return TokenNameIdentifier;
3447 return TokenNameIdentifier;
3452 if ((data[++index] == 'o') && (data[++index] == 'r'))
3453 return TokenNamexor;
3455 return TokenNameIdentifier;
3457 return TokenNameIdentifier;
3459 return TokenNameIdentifier;
3462 public int scanNumber(boolean dotPrefix) throws InvalidInputException {
3463 // when entering this method the currentCharacter is the firt
3464 // digit of the number , i.e. it may be preceeded by a . when
3465 // dotPrefix is true
3466 boolean floating = dotPrefix;
3467 if ((!dotPrefix) && (currentCharacter == '0')) {
3468 if (getNextChar('x', 'X') >= 0) { // ----------hexa-----------------
3469 // force the first char of the hexa number do exist...
3470 // consume next character
3471 unicodeAsBackSlash = false;
3472 currentCharacter = source[currentPosition++];
3473 // if (((currentCharacter = source[currentPosition++]) == '\\')
3474 // && (source[currentPosition] == 'u')) {
3475 // getNextUnicodeChar();
3477 // if (withoutUnicodePtr != 0) {
3478 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3481 if (Character.digit(currentCharacter, 16) == -1)
3482 throw new InvalidInputException(INVALID_HEXA);
3484 while (getNextCharAsDigit(16)) {
3487 // if (getNextChar('l', 'L') >= 0)
3488 // return TokenNameLongLiteral;
3490 return TokenNameIntegerLiteral;
3492 // there is x or X in the number
3493 // potential octal ! ... some one may write 000099.0 ! thus 00100 <
3494 // 00078.0 is true !!!!! crazy language
3495 if (getNextCharAsDigit()) {
3496 // -------------potential octal-----------------
3497 while (getNextCharAsDigit()) {
3500 // if (getNextChar('l', 'L') >= 0) {
3501 // return TokenNameLongLiteral;
3504 // if (getNextChar('f', 'F') >= 0) {
3505 // return TokenNameFloatingPointLiteral;
3507 if (getNextChar('d', 'D') >= 0) {
3508 return TokenNameDoubleLiteral;
3509 } else { // make the distinction between octal and float ....
3510 if (getNextChar('.')) { // bingo ! ....
3511 while (getNextCharAsDigit()) {
3514 if (getNextChar('e', 'E') >= 0) {
3515 // consume next character
3516 unicodeAsBackSlash = false;
3517 currentCharacter = source[currentPosition++];
3518 // if (((currentCharacter = source[currentPosition++]) == '\\')
3519 // && (source[currentPosition] == 'u')) {
3520 // getNextUnicodeChar();
3522 // if (withoutUnicodePtr != 0) {
3523 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3526 if ((currentCharacter == '-') || (currentCharacter == '+')) {
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] =
3536 // currentCharacter;
3540 if (!Character.isDigit(currentCharacter))
3541 throw new InvalidInputException(INVALID_FLOAT);
3542 while (getNextCharAsDigit()) {
3546 // if (getNextChar('f', 'F') >= 0)
3547 // return TokenNameFloatingPointLiteral;
3548 getNextChar('d', 'D'); // jump over potential d or D
3549 return TokenNameDoubleLiteral;
3551 return TokenNameIntegerLiteral;
3558 while (getNextCharAsDigit()) {
3561 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3562 // return TokenNameLongLiteral;
3563 if ((!dotPrefix) && (getNextChar('.'))) { // decimal part that can be empty
3564 while (getNextCharAsDigit()) {
3569 // if floating is true both exponant and suffix may be optional
3570 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 == '+')) { // consume
3586 unicodeAsBackSlash = false;
3587 currentCharacter = source[currentPosition++];
3588 // if (((currentCharacter = source[currentPosition++]) == '\\')
3589 // && (source[currentPosition] == 'u')) {
3590 // getNextUnicodeChar();
3592 // if (withoutUnicodePtr != 0) {
3593 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3597 if (!Character.isDigit(currentCharacter))
3598 throw new InvalidInputException(INVALID_FLOAT);
3599 while (getNextCharAsDigit()) {
3603 if (getNextChar('d', 'D') >= 0)
3604 return TokenNameDoubleLiteral;
3605 // if (getNextChar('f', 'F') >= 0)
3606 // return TokenNameFloatingPointLiteral;
3607 // the long flag has been tested before
3608 return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral;
3612 * Search the line number corresponding to a specific position
3615 public final int getLineNumber(int position) {
3616 if (lineEnds == null)
3618 int length = linePtr + 1;
3621 int g = 0, d = length - 1;
3625 if (position < lineEnds[m]) {
3627 } else if (position > lineEnds[m]) {
3633 if (position < lineEnds[m]) {
3639 public void setPHPMode(boolean mode) {
3643 public final void setSource(char[] source) {
3644 setSource(null, source);
3647 public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3648 // the source-buffer is set to sourceString
3649 this.compilationUnit = compilationUnit;
3650 if (source == null) {
3651 this.source = new char[0];
3653 this.source = source;
3656 initialPosition = currentPosition = 0;
3657 containsAssertKeyword = false;
3658 withoutUnicodeBuffer = new char[this.source.length];
3659 fFillerToken = TokenNameEOF;
3660 // encapsedStringStack = new Stack();
3663 public String toString() {
3664 if (startPosition == source.length)
3665 return "EOF\n\n" + new String(source); //$NON-NLS-1$
3666 if (currentPosition > source.length)
3667 return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3668 char front[] = new char[startPosition];
3669 System.arraycopy(source, 0, front, 0, startPosition);
3670 int middleLength = (currentPosition - 1) - startPosition + 1;
3672 if (middleLength > -1) {
3673 middle = new char[middleLength];
3674 System.arraycopy(source, startPosition, middle, 0, middleLength);
3676 middle = new char[0];
3678 char end[] = new char[source.length - (currentPosition - 1)];
3679 System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - (currentPosition - 1) - 1);
3680 return new String(front) + "\n===============================\nStarts here -->" //$NON-NLS-1$
3681 + new String(middle) + "<-- Ends here\n===============================\n" //$NON-NLS-1$
3685 public final String toStringAction(int act) {
3687 case TokenNameERROR:
3688 return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
3690 case TokenNameINLINE_HTML:
3691 return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3692 case TokenNameECHO_INVISIBLE:
3695 case TokenNameIdentifier:
3696 return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3697 case TokenNameVariable:
3698 return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3699 case TokenNameabstract:
3700 return "abstract"; //$NON-NLS-1$
3702 return "AND"; //$NON-NLS-1$
3703 case TokenNamearray:
3704 return "array"; //$NON-NLS-1$
3706 return "as"; //$NON-NLS-1$
3707 case TokenNamebreak:
3708 return "break"; //$NON-NLS-1$
3710 return "case"; //$NON-NLS-1$
3711 case TokenNameclass:
3712 return "class"; //$NON-NLS-1$
3713 case TokenNamecatch:
3714 return "catch"; //$NON-NLS-1$
3715 case TokenNameclone:
3718 case TokenNameconst:
3721 case TokenNamecontinue:
3722 return "continue"; //$NON-NLS-1$
3723 case TokenNamedefault:
3724 return "default"; //$NON-NLS-1$
3725 // case TokenNamedefine :
3726 // return "define"; //$NON-NLS-1$
3728 return "do"; //$NON-NLS-1$
3730 return "echo"; //$NON-NLS-1$
3732 return "else"; //$NON-NLS-1$
3733 case TokenNameelseif:
3734 return "elseif"; //$NON-NLS-1$
3735 case TokenNameendfor:
3736 return "endfor"; //$NON-NLS-1$
3737 case TokenNameendforeach:
3738 return "endforeach"; //$NON-NLS-1$
3739 case TokenNameendif:
3740 return "endif"; //$NON-NLS-1$
3741 case TokenNameendswitch:
3742 return "endswitch"; //$NON-NLS-1$
3743 case TokenNameendwhile:
3744 return "endwhile"; //$NON-NLS-1$
3747 case TokenNameextends:
3748 return "extends"; //$NON-NLS-1$
3749 // case TokenNamefalse :
3750 // return "false"; //$NON-NLS-1$
3751 case TokenNamefinal:
3752 return "final"; //$NON-NLS-1$
3754 return "for"; //$NON-NLS-1$
3755 case TokenNameforeach:
3756 return "foreach"; //$NON-NLS-1$
3757 case TokenNamefunction:
3758 return "function"; //$NON-NLS-1$
3759 case TokenNameglobal:
3760 return "global"; //$NON-NLS-1$
3762 return "if"; //$NON-NLS-1$
3763 case TokenNameimplements:
3764 return "implements"; //$NON-NLS-1$
3765 case TokenNameinclude:
3766 return "include"; //$NON-NLS-1$
3767 case TokenNameinclude_once:
3768 return "include_once"; //$NON-NLS-1$
3769 case TokenNameinstanceof:
3770 return "instanceof"; //$NON-NLS-1$
3771 case TokenNameinterface:
3772 return "interface"; //$NON-NLS-1$
3773 case TokenNameisset:
3774 return "isset"; //$NON-NLS-1$
3776 return "list"; //$NON-NLS-1$
3778 return "new"; //$NON-NLS-1$
3779 // case TokenNamenull :
3780 // return "null"; //$NON-NLS-1$
3782 return "OR"; //$NON-NLS-1$
3783 case TokenNameprint:
3784 return "print"; //$NON-NLS-1$
3785 case TokenNameprivate:
3786 return "private"; //$NON-NLS-1$
3787 case TokenNameprotected:
3788 return "protected"; //$NON-NLS-1$
3789 case TokenNamepublic:
3790 return "public"; //$NON-NLS-1$
3791 case TokenNamerequire:
3792 return "require"; //$NON-NLS-1$
3793 case TokenNamerequire_once:
3794 return "require_once"; //$NON-NLS-1$
3795 case TokenNamereturn:
3796 return "return"; //$NON-NLS-1$
3797 // case TokenNameself:
3798 // return "self"; //$NON-NLS-1$
3799 case TokenNamestatic:
3800 return "static"; //$NON-NLS-1$
3801 case TokenNameswitch:
3802 return "switch"; //$NON-NLS-1$
3803 // case TokenNametrue :
3804 // return "true"; //$NON-NLS-1$
3805 case TokenNameunset:
3806 return "unset"; //$NON-NLS-1$
3808 return "var"; //$NON-NLS-1$
3809 case TokenNamewhile:
3810 return "while"; //$NON-NLS-1$
3812 return "XOR"; //$NON-NLS-1$
3813 // case TokenNamethis :
3814 // return "$this"; //$NON-NLS-1$
3815 case TokenNameIntegerLiteral:
3816 return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3817 case TokenNameDoubleLiteral:
3818 return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3819 case TokenNameStringDoubleQuote:
3820 return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3821 case TokenNameStringSingleQuote:
3822 return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3823 case TokenNameStringInterpolated:
3824 return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3825 case TokenNameEncapsedString0:
3826 return "`"; //$NON-NLS-1$
3827 // case TokenNameEncapsedString1:
3828 // return "\'"; //$NON-NLS-1$
3829 // case TokenNameEncapsedString2:
3830 // return "\""; //$NON-NLS-1$
3831 case TokenNameSTRING:
3832 return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3833 case TokenNameHEREDOC:
3834 return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3835 case TokenNamePLUS_PLUS:
3836 return "++"; //$NON-NLS-1$
3837 case TokenNameMINUS_MINUS:
3838 return "--"; //$NON-NLS-1$
3839 case TokenNameEQUAL_EQUAL:
3840 return "=="; //$NON-NLS-1$
3841 case TokenNameEQUAL_EQUAL_EQUAL:
3842 return "==="; //$NON-NLS-1$
3843 case TokenNameEQUAL_GREATER:
3844 return "=>"; //$NON-NLS-1$
3845 case TokenNameLESS_EQUAL:
3846 return "<="; //$NON-NLS-1$
3847 case TokenNameGREATER_EQUAL:
3848 return ">="; //$NON-NLS-1$
3849 case TokenNameNOT_EQUAL:
3850 return "!="; //$NON-NLS-1$
3851 case TokenNameNOT_EQUAL_EQUAL:
3852 return "!=="; //$NON-NLS-1$
3853 case TokenNameLEFT_SHIFT:
3854 return "<<"; //$NON-NLS-1$
3855 case TokenNameRIGHT_SHIFT:
3856 return ">>"; //$NON-NLS-1$
3857 case TokenNamePLUS_EQUAL:
3858 return "+="; //$NON-NLS-1$
3859 case TokenNameMINUS_EQUAL:
3860 return "-="; //$NON-NLS-1$
3861 case TokenNameMULTIPLY_EQUAL:
3862 return "*="; //$NON-NLS-1$
3863 case TokenNameDIVIDE_EQUAL:
3864 return "/="; //$NON-NLS-1$
3865 case TokenNameAND_EQUAL:
3866 return "&="; //$NON-NLS-1$
3867 case TokenNameOR_EQUAL:
3868 return "|="; //$NON-NLS-1$
3869 case TokenNameXOR_EQUAL:
3870 return "^="; //$NON-NLS-1$
3871 case TokenNameREMAINDER_EQUAL:
3872 return "%="; //$NON-NLS-1$
3873 case TokenNameDOT_EQUAL:
3874 return ".="; //$NON-NLS-1$
3875 case TokenNameLEFT_SHIFT_EQUAL:
3876 return "<<="; //$NON-NLS-1$
3877 case TokenNameRIGHT_SHIFT_EQUAL:
3878 return ">>="; //$NON-NLS-1$
3879 case TokenNameOR_OR:
3880 return "||"; //$NON-NLS-1$
3881 case TokenNameAND_AND:
3882 return "&&"; //$NON-NLS-1$
3884 return "+"; //$NON-NLS-1$
3885 case TokenNameMINUS:
3886 return "-"; //$NON-NLS-1$
3887 case TokenNameMINUS_GREATER:
3890 return "!"; //$NON-NLS-1$
3891 case TokenNameREMAINDER:
3892 return "%"; //$NON-NLS-1$
3894 return "^"; //$NON-NLS-1$
3896 return "&"; //$NON-NLS-1$
3897 case TokenNameMULTIPLY:
3898 return "*"; //$NON-NLS-1$
3900 return "|"; //$NON-NLS-1$
3901 case TokenNameTWIDDLE:
3902 return "~"; //$NON-NLS-1$
3903 case TokenNameTWIDDLE_EQUAL:
3904 return "~="; //$NON-NLS-1$
3905 case TokenNameDIVIDE:
3906 return "/"; //$NON-NLS-1$
3907 case TokenNameGREATER:
3908 return ">"; //$NON-NLS-1$
3910 return "<"; //$NON-NLS-1$
3911 case TokenNameLPAREN:
3912 return "("; //$NON-NLS-1$
3913 case TokenNameRPAREN:
3914 return ")"; //$NON-NLS-1$
3915 case TokenNameLBRACE:
3916 return "{"; //$NON-NLS-1$
3917 case TokenNameRBRACE:
3918 return "}"; //$NON-NLS-1$
3919 case TokenNameLBRACKET:
3920 return "["; //$NON-NLS-1$
3921 case TokenNameRBRACKET:
3922 return "]"; //$NON-NLS-1$
3923 case TokenNameSEMICOLON:
3924 return ";"; //$NON-NLS-1$
3925 case TokenNameQUESTION:
3926 return "?"; //$NON-NLS-1$
3927 case TokenNameCOLON:
3928 return ":"; //$NON-NLS-1$
3929 case TokenNameCOMMA:
3930 return ","; //$NON-NLS-1$
3932 return "."; //$NON-NLS-1$
3933 case TokenNameEQUAL:
3934 return "="; //$NON-NLS-1$
3937 case TokenNameDOLLAR:
3939 case TokenNameDOLLAR_LBRACE:
3941 case TokenNameLBRACE_DOLLAR:
3944 return "EOF"; //$NON-NLS-1$
3945 case TokenNameWHITESPACE:
3946 return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3947 case TokenNameCOMMENT_LINE:
3948 return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3949 case TokenNameCOMMENT_BLOCK:
3950 return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3951 case TokenNameCOMMENT_PHPDOC:
3952 return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3953 // case TokenNameHTML :
3954 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
3957 return "__FILE__"; //$NON-NLS-1$
3959 return "__LINE__"; //$NON-NLS-1$
3960 case TokenNameCLASS_C:
3961 return "__CLASS__"; //$NON-NLS-1$
3962 case TokenNameMETHOD_C:
3963 return "__METHOD__"; //$NON-NLS-1$
3964 case TokenNameFUNC_C:
3965 return "__FUNCTION__"; //$NON-NLS-1
3966 case TokenNameboolCAST:
3967 return "( bool )"; //$NON-NLS-1$
3968 case TokenNameintCAST:
3969 return "( int )"; //$NON-NLS-1$
3970 case TokenNamedoubleCAST:
3971 return "( double )"; //$NON-NLS-1$
3972 case TokenNameobjectCAST:
3973 return "( object )"; //$NON-NLS-1$
3974 case TokenNamestringCAST:
3975 return "( string )"; //$NON-NLS-1$
3977 return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
3985 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
3986 this(tokenizeComments, tokenizeWhiteSpace, false);
3989 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals) {
3990 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, false);
3993 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
3994 boolean assertMode) {
3995 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, assertMode, false, null, null, true);
3998 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
3999 boolean assertMode, boolean tokenizeStrings, char[][] taskTags, char[][] taskPriorities, boolean isTaskCaseSensitive) {
4000 this.eofPosition = Integer.MAX_VALUE;
4001 this.tokenizeComments = tokenizeComments;
4002 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4003 this.tokenizeStrings = tokenizeStrings;
4004 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4005 // this.assertMode = assertMode;
4006 // this.encapsedStringStack = null;
4007 this.taskTags = taskTags;
4008 this.taskPriorities = taskPriorities;
4011 private void checkNonExternalizeString() throws InvalidInputException {
4012 if (currentLine == null)
4014 parseTags(currentLine);
4017 private void parseTags(NLSLine line) throws InvalidInputException {
4018 String s = new String(getCurrentTokenSource());
4019 int pos = s.indexOf(TAG_PREFIX);
4020 int lineLength = line.size();
4022 int start = pos + TAG_PREFIX_LENGTH;
4023 int end = s.indexOf(TAG_POSTFIX, start);
4024 String index = s.substring(start, end);
4027 i = Integer.parseInt(index) - 1;
4028 // Tags are one based not zero based.
4029 } catch (NumberFormatException e) {
4030 i = -1; // we don't want to consider this as a valid NLS tag
4032 if (line.exists(i)) {
4035 pos = s.indexOf(TAG_PREFIX, start);
4037 this.nonNLSStrings = new StringLiteral[lineLength];
4038 int nonNLSCounter = 0;
4039 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4040 StringLiteral literal = (StringLiteral) iterator.next();
4041 if (literal != null) {
4042 this.nonNLSStrings[nonNLSCounter++] = literal;
4045 if (nonNLSCounter == 0) {
4046 this.nonNLSStrings = null;
4050 this.wasNonExternalizedStringLiteral = true;
4051 if (nonNLSCounter != lineLength) {
4052 System.arraycopy(this.nonNLSStrings, 0, (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, nonNLSCounter);
4057 public final void scanEscapeCharacter() throws InvalidInputException {
4058 // the string with "\\u" is a legal string of two chars \ and u
4059 // thus we use a direct access to the source (for regular cases).
4060 if (unicodeAsBackSlash) {
4061 // consume next character
4062 unicodeAsBackSlash = false;
4063 // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4064 // (source[currentPosition] == 'u')) {
4065 // getNextUnicodeChar();
4067 if (withoutUnicodePtr != 0) {
4068 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4072 currentCharacter = source[currentPosition++];
4073 switch (currentCharacter) {
4075 currentCharacter = '\b';
4078 currentCharacter = '\t';
4081 currentCharacter = '\n';
4084 currentCharacter = '\f';
4087 currentCharacter = '\r';
4090 currentCharacter = '\"';
4093 currentCharacter = '\'';
4096 currentCharacter = '\\';
4099 // -----------octal escape--------------
4101 // OctalDigit OctalDigit
4102 // ZeroToThree OctalDigit OctalDigit
4103 int number = Character.getNumericValue(currentCharacter);
4104 if (number >= 0 && number <= 7) {
4105 boolean zeroToThreeNot = number > 3;
4106 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4107 int digit = Character.getNumericValue(currentCharacter);
4108 if (digit >= 0 && digit <= 7) {
4109 number = (number * 8) + digit;
4110 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4111 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
4112 // Digit --> ignore last character
4115 digit = Character.getNumericValue(currentCharacter);
4116 if (digit >= 0 && digit <= 7) { // has read \ZeroToThree
4117 // OctalDigit OctalDigit
4118 number = (number * 8) + digit;
4119 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
4120 // --> ignore last character
4124 } else { // has read \OctalDigit NonDigit--> ignore last
4128 } else { // has read \OctalDigit NonOctalDigit--> ignore last
4132 } else { // has read \OctalDigit --> ignore last character
4136 throw new InvalidInputException(INVALID_ESCAPE);
4137 currentCharacter = (char) number;
4139 throw new InvalidInputException(INVALID_ESCAPE);
4143 // chech presence of task: tags
4144 // TODO (frederic) see if we need to take unicode characters into account...
4145 public void checkTaskTag(int commentStart, int commentEnd) {
4146 char[] src = this.source;
4148 // only look for newer task: tags
4149 if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4152 int foundTaskIndex = this.foundTaskCount;
4153 char previous = src[commentStart + 1]; // should be '*' or '/'
4154 nextChar: for (int i = commentStart + 2; i < commentEnd && i < this.eofPosition; i++) {
4156 char[] priority = null;
4157 // check for tag occurrence only if not ambiguous with javadoc tag
4158 if (previous != '@') {
4159 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4160 tag = this.taskTags[itag];
4161 int tagLength = tag.length;
4165 // ensure tag is not leaded with letter if tag starts with a letter
4166 if (Scanner.isPHPIdentifierStart(tag[0])) {
4167 if (Scanner.isPHPIdentifierPart(previous)) {
4172 for (int t = 0; t < tagLength; t++) {
4175 if (x >= this.eofPosition || x >= commentEnd)
4177 if ((sc = src[i + t]) != (tc = tag[t])) { // case sensitive check
4178 if (this.isTaskCaseSensitive || (Character.toLowerCase(sc) != Character.toLowerCase(tc))) { // case
4185 // ensure tag is not followed with letter if tag finishes with a
4187 if (i + tagLength < commentEnd && Scanner.isPHPIdentifierPart(src[i + tagLength - 1])) {
4188 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4191 if (this.foundTaskTags == null) {
4192 this.foundTaskTags = new char[5][];
4193 this.foundTaskMessages = new char[5][];
4194 this.foundTaskPriorities = new char[5][];
4195 this.foundTaskPositions = new int[5][];
4196 } else if (this.foundTaskCount == this.foundTaskTags.length) {
4197 System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0,
4198 this.foundTaskCount);
4199 System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4200 this.foundTaskCount);
4201 System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4202 this.foundTaskCount);
4203 System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4204 this.foundTaskCount);
4207 priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4209 this.foundTaskTags[this.foundTaskCount] = tag;
4210 this.foundTaskPriorities[this.foundTaskCount] = priority;
4211 this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4212 this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4213 this.foundTaskCount++;
4214 i += tagLength - 1; // will be incremented when looping
4220 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4221 // retrieve message start and end positions
4222 int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4223 int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4224 // at most beginning of next task
4225 if (max_value < msgStart) {
4226 max_value = msgStart; // would only occur if tag is before EOF.
4230 for (int j = msgStart; j < max_value; j++) {
4231 if ((c = src[j]) == '\n' || c == '\r') {
4237 for (int j = max_value; j > msgStart; j--) {
4238 if ((c = src[j]) == '*') {
4246 if (msgStart == end)
4249 while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4251 while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4253 // update the end position of the task
4254 this.foundTaskPositions[i][1] = end;
4255 // get the message source
4256 final int messageLength = end - msgStart + 1;
4257 char[] message = new char[messageLength];
4258 System.arraycopy(src, msgStart, message, 0, messageLength);
4259 this.foundTaskMessages[i] = message;
4263 // chech presence of task: tags
4264 // public void checkTaskTag(int commentStart, int commentEnd) {
4265 // // only look for newer task: tags
4266 // if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount
4267 // - 1][0] >= commentStart) {
4270 // int foundTaskIndex = this.foundTaskCount;
4271 // nextChar: for (int i = commentStart; i < commentEnd && i <
4272 // this.eofPosition; i++) {
4273 // char[] tag = null;
4274 // char[] priority = null;
4275 // // check for tag occurrence
4276 // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4277 // tag = this.taskTags[itag];
4278 // priority = this.taskPriorities != null && itag < this.taskPriorities.length
4279 // ? this.taskPriorities[itag] : null;
4280 // int tagLength = tag.length;
4281 // for (int t = 0; t < tagLength; t++) {
4282 // if (this.source[i + t] != tag[t])
4283 // continue nextTag;
4285 // if (this.foundTaskTags == null) {
4286 // this.foundTaskTags = new char[5][];
4287 // this.foundTaskMessages = new char[5][];
4288 // this.foundTaskPriorities = new char[5][];
4289 // this.foundTaskPositions = new int[5][];
4290 // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4291 // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new
4292 // char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4293 // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new
4294 // char[this.foundTaskCount * 2][], 0,
4295 // this.foundTaskCount);
4296 // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities =
4297 // new char[this.foundTaskCount * 2][], 0,
4298 // this.foundTaskCount);
4299 // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new
4300 // int[this.foundTaskCount * 2][], 0,
4301 // this.foundTaskCount);
4303 // this.foundTaskTags[this.foundTaskCount] = tag;
4304 // this.foundTaskPriorities[this.foundTaskCount] = priority;
4305 // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength
4307 // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4308 // this.foundTaskCount++;
4309 // i += tagLength - 1; // will be incremented when looping
4312 // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4313 // // retrieve message start and end positions
4314 // int msgStart = this.foundTaskPositions[i][0] +
4315 // this.foundTaskTags[i].length;
4316 // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i +
4317 // 1][0] - 1 : commentEnd - 1;
4318 // // at most beginning of next task
4319 // if (max_value < msgStart)
4320 // max_value = msgStart; // would only occur if tag is before EOF.
4323 // for (int j = msgStart; j < max_value; j++) {
4324 // if ((c = this.source[j]) == '\n' || c == '\r') {
4330 // for (int j = max_value; j > msgStart; j--) {
4331 // if ((c = this.source[j]) == '*') {
4339 // if (msgStart == end)
4340 // continue; // empty
4341 // // trim the message
4342 // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4344 // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4346 // // update the end position of the task
4347 // this.foundTaskPositions[i][1] = end;
4348 // // get the message source
4349 // final int messageLength = end - msgStart + 1;
4350 // char[] message = new char[messageLength];
4351 // System.arraycopy(source, msgStart, message, 0, messageLength);
4352 // this.foundTaskMessages[i] = message;