1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others. All rights reserved. This program and the
3 * accompanying materials are made available under the terms of the Common Public License v0.5 which accompanies this distribution,
4 * and is available at http://www.eclipse.org/legal/cpl-v05.html
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpdt.internal.compiler.parser;
10 import java.util.ArrayList;
11 import java.util.Iterator;
12 import java.util.List;
13 import java.util.Stack;
15 import net.sourceforge.phpdt.core.compiler.CharOperation;
16 import net.sourceforge.phpdt.core.compiler.IScanner;
17 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
18 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
19 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
20 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
22 public class Scanner implements IScanner, ITerminalSymbols {
24 * APIs ares - getNextToken() which return the current type of the token (this value is not memorized by the scanner) -
25 * getCurrentTokenSource() which provides with the token "REAL" source (aka all unicode have been transformed into a correct char) -
26 * sourceStart gives the position into the stream - currentPosition-1 gives the sourceEnd position into the stream
29 private boolean assertMode;
31 public boolean useAssertAsAnIndentifier = false;
33 //flag indicating if processed source contains occurrences of keyword assert
34 public boolean containsAssertKeyword = false;
36 public boolean recordLineSeparator;
38 public boolean ignorePHPOneLiner = false;
40 public boolean phpMode = false;
42 public boolean phpExpressionTag = false;
44 // public Stack encapsedStringStack = null;
46 public char currentCharacter;
48 public int startPosition;
50 public int currentPosition;
52 public int initialPosition, eofPosition;
54 // after this position eof are generated instead of real token from the
56 public boolean tokenizeComments;
58 public boolean tokenizeWhiteSpace;
60 public boolean tokenizeStrings;
62 //source should be viewed as a window (aka a part)
63 //of a entire very large stream
67 public char[] withoutUnicodeBuffer;
69 public int withoutUnicodePtr;
71 //when == 0 ==> no unicode in the current token
72 public boolean unicodeAsBackSlash = false;
74 public boolean scanningFloatLiteral = false;
76 //support for /** comments
77 public int[] commentStops = new int[10];
79 public int[] commentStarts = new int[10];
81 public int commentPtr = -1; // no comment test with commentPtr value -1
83 protected int lastCommentLinePosition = -1;
85 //diet parsing support - jump over some method body when requested
86 public boolean diet = false;
88 //support for the poor-line-debuggers ....
89 //remember the position of the cr/lf
90 public int[] lineEnds = new int[250];
92 public int linePtr = -1;
94 public boolean wasAcr = false;
96 public static final String END_OF_SOURCE = "End_Of_Source"; //$NON-NLS-1$
98 public static final String INVALID_HEXA = "Invalid_Hexa_Literal"; //$NON-NLS-1$
100 public static final String INVALID_OCTAL = "Invalid_Octal_Literal"; //$NON-NLS-1$
102 public static final String INVALID_CHARACTER_CONSTANT = "Invalid_Character_Constant"; //$NON-NLS-1$
104 public static final String INVALID_ESCAPE = "Invalid_Escape"; //$NON-NLS-1$
106 public static final String INVALID_INPUT = "Invalid_Input"; //$NON-NLS-1$
108 public static final String INVALID_UNICODE_ESCAPE = "Invalid_Unicode_Escape"; //$NON-NLS-1$
110 public static final String INVALID_FLOAT = "Invalid_Float_Literal"; //$NON-NLS-1$
112 public static final String NULL_SOURCE_STRING = "Null_Source_String"; //$NON-NLS-1$
114 public static final String UNTERMINATED_STRING = "Unterminated_String"; //$NON-NLS-1$
116 public static final String UNTERMINATED_COMMENT = "Unterminated_Comment"; //$NON-NLS-1$
118 public static final String INVALID_CHAR_IN_STRING = "Invalid_Char_In_String"; //$NON-NLS-1$
120 //----------------optimized identifier managment------------------
121 static final char[] charArray_a = new char[] { 'a' }, charArray_b = new char[] { 'b' }, charArray_c = new char[] { 'c' },
122 charArray_d = new char[] { 'd' }, charArray_e = new char[] { 'e' }, charArray_f = new char[] { 'f' },
123 charArray_g = new char[] { 'g' }, charArray_h = new char[] { 'h' }, charArray_i = new char[] { 'i' },
124 charArray_j = new char[] { 'j' }, charArray_k = new char[] { 'k' }, charArray_l = new char[] { 'l' },
125 charArray_m = new char[] { 'm' }, charArray_n = new char[] { 'n' }, charArray_o = new char[] { 'o' },
126 charArray_p = new char[] { 'p' }, charArray_q = new char[] { 'q' }, charArray_r = new char[] { 'r' },
127 charArray_s = new char[] { 's' }, charArray_t = new char[] { 't' }, charArray_u = new char[] { 'u' },
128 charArray_v = new char[] { 'v' }, charArray_w = new char[] { 'w' }, charArray_x = new char[] { 'x' },
129 charArray_y = new char[] { 'y' }, charArray_z = new char[] { 'z' };
131 static final char[] charArray_va = new char[] { '$', 'a' }, charArray_vb = new char[] { '$', 'b' }, charArray_vc = new char[] {
133 'c' }, charArray_vd = new char[] { '$', 'd' }, charArray_ve = new char[] { '$', 'e' },
134 charArray_vf = new char[] { '$', 'f' }, charArray_vg = new char[] { '$', 'g' }, charArray_vh = new char[] { '$', 'h' },
135 charArray_vi = new char[] { '$', 'i' }, charArray_vj = new char[] { '$', 'j' }, charArray_vk = new char[] { '$', 'k' },
136 charArray_vl = new char[] { '$', 'l' }, charArray_vm = new char[] { '$', 'm' }, charArray_vn = new char[] { '$', 'n' },
137 charArray_vo = new char[] { '$', 'o' }, charArray_vp = new char[] { '$', 'p' }, charArray_vq = new char[] { '$', 'q' },
138 charArray_vr = new char[] { '$', 'r' }, charArray_vs = new char[] { '$', 's' }, charArray_vt = new char[] { '$', 't' },
139 charArray_vu = new char[] { '$', 'u' }, charArray_vv = new char[] { '$', 'v' }, charArray_vw = new char[] { '$', 'w' },
140 charArray_vx = new char[] { '$', 'x' }, charArray_vy = new char[] { '$', 'y' }, charArray_vz = new char[] { '$', 'z' };
142 static final char[] initCharArray = new char[] { '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' };
144 static final int TableSize = 30, InternalTableSize = 6;
147 public static final int OptimizedLength = 6;
150 final char[][][][] charArray_length = new char[OptimizedLength][TableSize][InternalTableSize][];
152 // support for detecting non-externalized string literals
153 int currentLineNr = -1;
155 int previousLineNr = -1;
157 NLSLine currentLine = null;
159 List lines = new ArrayList();
161 public static final String TAG_PREFIX = "//$NON-NLS-"; //$NON-NLS-1$
163 public static final int TAG_PREFIX_LENGTH = TAG_PREFIX.length();
165 public static final String TAG_POSTFIX = "$"; //$NON-NLS-1$
167 public static final int TAG_POSTFIX_LENGTH = TAG_POSTFIX.length();
169 public StringLiteral[] nonNLSStrings = null;
171 public boolean checkNonExternalizedStringLiterals = true;
173 public boolean wasNonExternalizedStringLiteral = false;
175 for (int i = 0; i < 6; i++) {
176 for (int j = 0; j < TableSize; j++) {
177 for (int k = 0; k < InternalTableSize; k++) {
178 charArray_length[i][j][k] = initCharArray;
184 static int newEntry2 = 0, newEntry3 = 0, newEntry4 = 0, newEntry5 = 0, newEntry6 = 0;
186 public static final int RoundBracket = 0;
188 public static final int SquareBracket = 1;
190 public static final int CurlyBracket = 2;
192 public static final int BracketKinds = 3;
195 public char[][] foundTaskTags = null;
197 public char[][] foundTaskMessages;
199 public char[][] foundTaskPriorities = null;
201 public int[][] foundTaskPositions;
203 public int foundTaskCount = 0;
205 public char[][] taskTags = null;
207 public char[][] taskPriorities = null;
209 public boolean isTaskCaseSensitive = true;
211 public static final boolean DEBUG = false;
213 public static final boolean TRACE = false;
215 public ICompilationUnit compilationUnit = null;
218 * Determines if the specified character is permissible as the first character in a PHP identifier or variable
220 * The '$' character for PHP variables is regarded as a correct first character !
223 public static boolean isPHPIdentOrVarStart(char ch) {
224 return Character.isLetter(ch) || (ch == '$') || (ch == '_') || (0x7F <= ch && ch <= 0xFF);
228 * Determines if the specified character is permissible as the first character in a PHP identifier.
230 * The '$' character for PHP variables isn't regarded as the first character !
232 public static boolean isPHPIdentifierStart(char ch) {
233 return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF);
237 * Determines if the specified character may be part of a PHP identifier as other than the first character
239 public static boolean isPHPIdentifierPart(char ch) {
240 return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF);
243 public final boolean atEnd() {
244 // This code is not relevant if source is
245 // Only a part of the real stream input
246 return source.length == currentPosition;
249 public char[] getCurrentIdentifierSource() {
250 //return the token REAL source (aka unicodes are precomputed)
252 // if (withoutUnicodePtr != 0)
253 // //0 is used as a fast test flag so the real first char is in position 1
255 // withoutUnicodeBuffer,
257 // result = new char[withoutUnicodePtr],
259 // withoutUnicodePtr);
261 int length = currentPosition - startPosition;
262 switch (length) { // see OptimizedLength
264 return optimizedCurrentTokenSource1();
266 return optimizedCurrentTokenSource2();
268 return optimizedCurrentTokenSource3();
270 return optimizedCurrentTokenSource4();
272 return optimizedCurrentTokenSource5();
274 return optimizedCurrentTokenSource6();
277 System.arraycopy(source, startPosition, result = new char[length], 0, length);
282 public int getCurrentTokenEndPosition() {
283 return this.currentPosition - 1;
286 public final char[] getCurrentTokenSource() {
287 // Return the token REAL source (aka unicodes are precomputed)
289 // if (withoutUnicodePtr != 0)
290 // // 0 is used as a fast test flag so the real first char is in position 1
292 // withoutUnicodeBuffer,
294 // result = new char[withoutUnicodePtr],
296 // withoutUnicodePtr);
299 System.arraycopy(source, startPosition, result = new char[length = currentPosition - startPosition], 0, length);
304 public final char[] getCurrentTokenSource(int startPos) {
305 // Return the token REAL source (aka unicodes are precomputed)
307 // if (withoutUnicodePtr != 0)
308 // // 0 is used as a fast test flag so the real first char is in position 1
310 // withoutUnicodeBuffer,
312 // result = new char[withoutUnicodePtr],
314 // withoutUnicodePtr);
317 System.arraycopy(source, startPos, result = new char[length = currentPosition - startPos], 0, length);
322 public final char[] getCurrentTokenSourceString() {
323 //return the token REAL source (aka unicodes are precomputed).
324 //REMOVE the two " that are at the beginning and the end.
326 if (withoutUnicodePtr != 0)
327 //0 is used as a fast test flag so the real first char is in position 1
328 System.arraycopy(withoutUnicodeBuffer, 2,
329 //2 is 1 (real start) + 1 (to jump over the ")
330 result = new char[withoutUnicodePtr - 2], 0, withoutUnicodePtr - 2);
333 System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length);
338 public final char[] getRawTokenSourceEnd() {
339 int length = this.eofPosition - this.currentPosition - 1;
340 char[] sourceEnd = new char[length];
341 System.arraycopy(this.source, this.currentPosition, sourceEnd, 0, length);
345 public int getCurrentTokenStartPosition() {
346 return this.startPosition;
349 public final char[] getCurrentStringLiteralSource() {
350 // Return the token REAL source (aka unicodes are precomputed)
351 if (startPosition + 1 >= currentPosition) {
356 System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length);
361 public final char[] getCurrentStringLiteralSource(int startPos) {
362 // Return the token REAL source (aka unicodes are precomputed)
365 System.arraycopy(source, startPos + 1, result = new char[length = currentPosition - startPos - 2], 0, length);
371 * Search the source position corresponding to the end of a given line number
373 * Line numbers are 1-based, and relative to the scanner initialPosition. Character positions are 0-based.
375 * In case the given line number is inconsistent, answers -1.
377 public final int getLineEnd(int lineNumber) {
378 if (lineEnds == null)
380 if (lineNumber >= lineEnds.length)
384 if (lineNumber == lineEnds.length - 1)
386 return lineEnds[lineNumber - 1];
387 // next line start one character behind the lineEnd of the previous line
391 * Search the source position corresponding to the beginning of a given line number
393 * Line numbers are 1-based, and relative to the scanner initialPosition. Character positions are 0-based.
395 * e.g. getLineStart(1) --> 0 i.e. first line starts at character 0.
397 * In case the given line number is inconsistent, answers -1.
399 public final int getLineStart(int lineNumber) {
400 if (lineEnds == null)
402 if (lineNumber >= lineEnds.length)
407 return initialPosition;
408 return lineEnds[lineNumber - 2] + 1;
409 // next line start one character behind the lineEnd of the previous line
412 public final boolean getNextChar(char testedChar) {
414 //handle the case of unicode.
415 //when a unicode appears then we must use a buffer that holds char
417 //At the end of this method currentCharacter holds the new visited char
418 //and currentPosition points right next after it
419 //Both previous lines are true if the currentCharacter is == to the
421 //On false, no side effect has occured.
422 //ALL getNextChar.... ARE OPTIMIZED COPIES
423 int temp = currentPosition;
425 currentCharacter = source[currentPosition++];
426 // if (((currentCharacter = source[currentPosition++]) == '\\')
427 // && (source[currentPosition] == 'u')) {
428 // //-------------unicode traitement ------------
429 // int c1, c2, c3, c4;
430 // int unicodeSize = 6;
431 // currentPosition++;
432 // while (source[currentPosition] == 'u') {
433 // currentPosition++;
437 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
439 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
441 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
443 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
445 // currentPosition = temp;
449 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
450 // if (currentCharacter != testedChar) {
451 // currentPosition = temp;
454 // unicodeAsBackSlash = currentCharacter == '\\';
456 // //need the unicode buffer
457 // if (withoutUnicodePtr == 0) {
458 // //buffer all the entries that have been left aside....
459 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
463 // withoutUnicodeBuffer,
465 // withoutUnicodePtr);
467 // //fill the buffer with the char
468 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
471 // } //-------------end unicode traitement--------------
473 if (currentCharacter != testedChar) {
474 currentPosition = temp;
477 unicodeAsBackSlash = false;
478 // if (withoutUnicodePtr != 0)
479 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
482 } catch (IndexOutOfBoundsException e) {
483 unicodeAsBackSlash = false;
484 currentPosition = temp;
489 public final int getNextChar(char testedChar1, char testedChar2) {
490 //INT 0 : testChar1 \\\\///\\\\ 1 : testedChar2 \\\\///\\\\ -1 : others
491 //test can be done with (x==0) for the first and (x>0) for the second
492 //handle the case of unicode.
493 //when a unicode appears then we must use a buffer that holds char
495 //At the end of this method currentCharacter holds the new visited char
496 //and currentPosition points right next after it
497 //Both previous lines are true if the currentCharacter is == to the
499 //On false, no side effect has occured.
500 //ALL getNextChar.... ARE OPTIMIZED COPIES
501 int temp = currentPosition;
504 currentCharacter = source[currentPosition++];
505 // if (((currentCharacter = source[currentPosition++]) == '\\')
506 // && (source[currentPosition] == 'u')) {
507 // //-------------unicode traitement ------------
508 // int c1, c2, c3, c4;
509 // int unicodeSize = 6;
510 // currentPosition++;
511 // while (source[currentPosition] == 'u') {
512 // currentPosition++;
516 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
518 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
520 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
522 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
524 // currentPosition = temp;
528 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
529 // if (currentCharacter == testedChar1)
531 // else if (currentCharacter == testedChar2)
534 // currentPosition = temp;
538 // //need the unicode buffer
539 // if (withoutUnicodePtr == 0) {
540 // //buffer all the entries that have been left aside....
541 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
545 // withoutUnicodeBuffer,
547 // withoutUnicodePtr);
549 // //fill the buffer with the char
550 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
552 // } //-------------end unicode traitement--------------
554 if (currentCharacter == testedChar1)
556 else if (currentCharacter == testedChar2)
559 currentPosition = temp;
562 // if (withoutUnicodePtr != 0)
563 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
566 } catch (IndexOutOfBoundsException e) {
567 currentPosition = temp;
572 public final boolean getNextCharAsDigit() {
574 //handle the case of unicode.
575 //when a unicode appears then we must use a buffer that holds char
577 //At the end of this method currentCharacter holds the new visited char
578 //and currentPosition points right next after it
579 //Both previous lines are true if the currentCharacter is a digit
580 //On false, no side effect has occured.
581 //ALL getNextChar.... ARE OPTIMIZED COPIES
582 int temp = currentPosition;
584 currentCharacter = source[currentPosition++];
585 // if (((currentCharacter = source[currentPosition++]) == '\\')
586 // && (source[currentPosition] == 'u')) {
587 // //-------------unicode traitement ------------
588 // int c1, c2, c3, c4;
589 // int unicodeSize = 6;
590 // currentPosition++;
591 // while (source[currentPosition] == 'u') {
592 // currentPosition++;
596 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
598 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
600 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
602 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
604 // currentPosition = temp;
608 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
609 // if (!Character.isDigit(currentCharacter)) {
610 // currentPosition = temp;
614 // //need the unicode buffer
615 // if (withoutUnicodePtr == 0) {
616 // //buffer all the entries that have been left aside....
617 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
621 // withoutUnicodeBuffer,
623 // withoutUnicodePtr);
625 // //fill the buffer with the char
626 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
628 // } //-------------end unicode traitement--------------
630 if (!Character.isDigit(currentCharacter)) {
631 currentPosition = temp;
634 // if (withoutUnicodePtr != 0)
635 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
638 } catch (IndexOutOfBoundsException e) {
639 currentPosition = temp;
644 public final boolean getNextCharAsDigit(int radix) {
646 //handle the case of unicode.
647 //when a unicode appears then we must use a buffer that holds char
649 //At the end of this method currentCharacter holds the new visited char
650 //and currentPosition points right next after it
651 //Both previous lines are true if the currentCharacter is a digit base on
653 //On false, no side effect has occured.
654 //ALL getNextChar.... ARE OPTIMIZED COPIES
655 int temp = currentPosition;
657 currentCharacter = source[currentPosition++];
658 // if (((currentCharacter = source[currentPosition++]) == '\\')
659 // && (source[currentPosition] == 'u')) {
660 // //-------------unicode traitement ------------
661 // int c1, c2, c3, c4;
662 // int unicodeSize = 6;
663 // currentPosition++;
664 // while (source[currentPosition] == 'u') {
665 // currentPosition++;
669 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
671 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
673 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
675 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
677 // currentPosition = temp;
681 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
682 // if (Character.digit(currentCharacter, radix) == -1) {
683 // currentPosition = temp;
687 // //need the unicode buffer
688 // if (withoutUnicodePtr == 0) {
689 // //buffer all the entries that have been left aside....
690 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
694 // withoutUnicodeBuffer,
696 // withoutUnicodePtr);
698 // //fill the buffer with the char
699 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
701 // } //-------------end unicode traitement--------------
703 if (Character.digit(currentCharacter, radix) == -1) {
704 currentPosition = temp;
707 // if (withoutUnicodePtr != 0)
708 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
711 } catch (IndexOutOfBoundsException e) {
712 currentPosition = temp;
717 public boolean getNextCharAsJavaIdentifierPart() {
719 //handle the case of unicode.
720 //when a unicode appears then we must use a buffer that holds char
722 //At the end of this method currentCharacter holds the new visited char
723 //and currentPosition points right next after it
724 //Both previous lines are true if the currentCharacter is a
725 // JavaIdentifierPart
726 //On false, no side effect has occured.
727 //ALL getNextChar.... ARE OPTIMIZED COPIES
728 int temp = currentPosition;
730 currentCharacter = source[currentPosition++];
731 // if (((currentCharacter = source[currentPosition++]) == '\\')
732 // && (source[currentPosition] == 'u')) {
733 // //-------------unicode traitement ------------
734 // int c1, c2, c3, c4;
735 // int unicodeSize = 6;
736 // currentPosition++;
737 // while (source[currentPosition] == 'u') {
738 // currentPosition++;
742 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
744 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
746 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
748 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
750 // currentPosition = temp;
754 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
755 // if (!isPHPIdentifierPart(currentCharacter)) {
756 // currentPosition = temp;
760 // //need the unicode buffer
761 // if (withoutUnicodePtr == 0) {
762 // //buffer all the entries that have been left aside....
763 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
767 // withoutUnicodeBuffer,
769 // withoutUnicodePtr);
771 // //fill the buffer with the char
772 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
774 // } //-------------end unicode traitement--------------
776 if (!isPHPIdentifierPart(currentCharacter)) {
777 currentPosition = temp;
780 // if (withoutUnicodePtr != 0)
781 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
784 } catch (IndexOutOfBoundsException e) {
785 currentPosition = temp;
790 public int getCastOrParen() {
791 int tempPosition = currentPosition;
792 char tempCharacter = currentCharacter;
793 int tempToken = TokenNameLPAREN;
794 boolean found = false;
795 StringBuffer buf = new StringBuffer();
798 currentCharacter = source[currentPosition++];
799 } while (currentCharacter == ' ' || currentCharacter == '\t');
800 while ((currentCharacter >= 'a' && currentCharacter <= 'z') || (currentCharacter >= 'A' && currentCharacter <= 'Z')) {
801 buf.append(currentCharacter);
802 currentCharacter = source[currentPosition++];
804 if (buf.length() >= 3 && buf.length() <= 7) {
805 char[] data = buf.toString().toCharArray();
807 switch (data.length) {
810 if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
812 tempToken = TokenNameintCAST;
817 if ((data[index] == 'b') && (data[++index] == 'o') && (data[++index] == 'o') && (data[++index] == 'l')) {
819 tempToken = TokenNameboolCAST;
822 if ((data[index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'l')) {
824 tempToken = TokenNamedoubleCAST;
830 if ((data[index] == 'a') && (data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a')
831 && (data[++index] == 'y')) {
833 tempToken = TokenNamearrayCAST;
836 if ((data[index] == 'u') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e')
837 && (data[++index] == 't')) {
839 tempToken = TokenNameunsetCAST;
842 if ((data[index] == 'f') && (data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'a')
843 && (data[++index] == 't')) {
845 tempToken = TokenNamedoubleCAST;
851 // object string double
852 if ((data[index] == 'o') && (data[++index] == 'b') && (data[++index] == 'j') && (data[++index] == 'e')
853 && (data[++index] == 'c') && (data[++index] == 't')) {
855 tempToken = TokenNameobjectCAST;
858 if ((data[index] == 's') && (data[++index] == 't') && (data[++index] == 'r') && (data[++index] == 'i')
859 && (data[++index] == 'n') && (data[++index] == 'g')) {
861 tempToken = TokenNamestringCAST;
864 if ((data[index] == 'd') && (data[++index] == 'o') && (data[++index] == 'u') && (data[++index] == 'b')
865 && (data[++index] == 'l') && (data[++index] == 'e')) {
867 tempToken = TokenNamedoubleCAST;
874 if ((data[index] == 'b') && (data[++index] == 'o') && (data[++index] == 'o') && (data[++index] == 'l')
875 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'n')) {
877 tempToken = TokenNameboolCAST;
880 if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e')
881 && (data[++index] == 'g') && (data[++index] == 'e') && (data[++index] == 'r')) {
883 tempToken = TokenNameintCAST;
889 while (currentCharacter == ' ' || currentCharacter == '\t') {
890 currentCharacter = source[currentPosition++];
892 if (currentCharacter == ')') {
897 } catch (IndexOutOfBoundsException e) {
899 currentCharacter = tempCharacter;
900 currentPosition = tempPosition;
901 return TokenNameLPAREN;
904 public void consumeStringInterpolated() throws InvalidInputException {
906 // consume next character
907 unicodeAsBackSlash = false;
908 currentCharacter = source[currentPosition++];
909 // if (((currentCharacter = source[currentPosition++]) == '\\')
910 // && (source[currentPosition] == 'u')) {
911 // getNextUnicodeChar();
913 // if (withoutUnicodePtr != 0) {
914 // withoutUnicodeBuffer[++withoutUnicodePtr] =
918 while (currentCharacter != '`') {
919 /** ** in PHP \r and \n are valid in string literals *** */
920 // if ((currentCharacter == '\n')
921 // || (currentCharacter == '\r')) {
922 // // relocate if finding another quote fairly close: thus unicode
923 // '/u000D' will be fully consumed
924 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
925 // if (currentPosition + lookAhead == source.length)
927 // if (source[currentPosition + lookAhead] == '\n')
929 // if (source[currentPosition + lookAhead] == '\"') {
930 // currentPosition += lookAhead + 1;
934 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
936 if (currentCharacter == '\\') {
937 int escapeSize = currentPosition;
938 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
939 //scanEscapeCharacter make a side effect on this value and we need
940 // the previous value few lines down this one
941 scanDoubleQuotedEscapeCharacter();
942 escapeSize = currentPosition - escapeSize;
943 if (withoutUnicodePtr == 0) {
944 //buffer all the entries that have been left aside....
945 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
946 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
947 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
948 } else { //overwrite the / in the buffer
949 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
950 if (backSlashAsUnicodeInString) { //there are TWO \ in the stream
951 // where only one is correct
955 } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
956 if (recordLineSeparator) {
960 // consume next character
961 unicodeAsBackSlash = false;
962 currentCharacter = source[currentPosition++];
963 // if (((currentCharacter = source[currentPosition++]) == '\\')
964 // && (source[currentPosition] == 'u')) {
965 // getNextUnicodeChar();
967 if (withoutUnicodePtr != 0) {
968 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
972 } catch (IndexOutOfBoundsException e) {
973 // reset end position for error reporting
974 currentPosition -= 2;
975 throw new InvalidInputException(UNTERMINATED_STRING);
976 } catch (InvalidInputException e) {
977 if (e.getMessage().equals(INVALID_ESCAPE)) {
978 // relocate if finding another quote fairly close: thus unicode
979 // '/u000D' will be fully consumed
980 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
981 if (currentPosition + lookAhead == source.length)
983 if (source[currentPosition + lookAhead] == '\n')
985 if (source[currentPosition + lookAhead] == '`') {
986 currentPosition += lookAhead + 1;
993 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
994 // //$NON-NLS-?$ where ? is an
996 if (currentLine == null) {
997 currentLine = new NLSLine();
998 lines.add(currentLine);
1000 currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1004 public void consumeStringConstant() throws InvalidInputException {
1006 // consume next character
1007 unicodeAsBackSlash = false;
1008 currentCharacter = source[currentPosition++];
1009 // if (((currentCharacter = source[currentPosition++]) == '\\')
1010 // && (source[currentPosition] == 'u')) {
1011 // getNextUnicodeChar();
1013 // if (withoutUnicodePtr != 0) {
1014 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1015 // currentCharacter;
1018 while (currentCharacter != '\'') {
1019 /** ** in PHP \r and \n are valid in string literals *** */
1020 // if ((currentCharacter == '\n')
1021 // || (currentCharacter == '\r')) {
1022 // // relocate if finding another quote fairly close: thus unicode
1023 // '/u000D' will be fully consumed
1024 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1025 // if (currentPosition + lookAhead == source.length)
1027 // if (source[currentPosition + lookAhead] == '\n')
1029 // if (source[currentPosition + lookAhead] == '\"') {
1030 // currentPosition += lookAhead + 1;
1034 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1036 if (currentCharacter == '\\') {
1037 int escapeSize = currentPosition;
1038 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1039 //scanEscapeCharacter make a side effect on this value and we need
1040 // the previous value few lines down this one
1041 scanSingleQuotedEscapeCharacter();
1042 escapeSize = currentPosition - escapeSize;
1043 if (withoutUnicodePtr == 0) {
1044 //buffer all the entries that have been left aside....
1045 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1046 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1047 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1048 } else { //overwrite the / in the buffer
1049 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1050 if (backSlashAsUnicodeInString) { //there are TWO \ in the stream
1051 // where only one is correct
1052 withoutUnicodePtr--;
1055 } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1056 if (recordLineSeparator) {
1057 pushLineSeparator();
1060 // consume next character
1061 unicodeAsBackSlash = false;
1062 currentCharacter = source[currentPosition++];
1063 // if (((currentCharacter = source[currentPosition++]) == '\\')
1064 // && (source[currentPosition] == 'u')) {
1065 // getNextUnicodeChar();
1067 if (withoutUnicodePtr != 0) {
1068 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1072 } catch (IndexOutOfBoundsException e) {
1073 // reset end position for error reporting
1074 currentPosition -= 2;
1075 throw new InvalidInputException(UNTERMINATED_STRING);
1076 } catch (InvalidInputException e) {
1077 if (e.getMessage().equals(INVALID_ESCAPE)) {
1078 // relocate if finding another quote fairly close: thus unicode
1079 // '/u000D' will be fully consumed
1080 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1081 if (currentPosition + lookAhead == source.length)
1083 if (source[currentPosition + lookAhead] == '\n')
1085 if (source[currentPosition + lookAhead] == '\'') {
1086 currentPosition += lookAhead + 1;
1093 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1094 // //$NON-NLS-?$ where ? is an
1096 if (currentLine == null) {
1097 currentLine = new NLSLine();
1098 lines.add(currentLine);
1100 currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1104 public void consumeStringLiteral() throws InvalidInputException {
1106 boolean openDollarBrace = false;
1107 // consume next character
1108 unicodeAsBackSlash = false;
1109 currentCharacter = source[currentPosition++];
1110 while (currentCharacter != '"' || openDollarBrace) {
1111 /** ** in PHP \r and \n are valid in string literals *** */
1112 if (currentCharacter == '\\') {
1113 int escapeSize = currentPosition;
1114 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1115 //scanEscapeCharacter make a side effect on this value and we need
1116 // the previous value few lines down this one
1117 scanDoubleQuotedEscapeCharacter();
1118 escapeSize = currentPosition - escapeSize;
1119 if (withoutUnicodePtr == 0) {
1120 //buffer all the entries that have been left aside....
1121 withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1122 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1123 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1124 } else { //overwrite the / in the buffer
1125 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1126 if (backSlashAsUnicodeInString) { //there are TWO \ in the stream
1127 // where only one is correct
1128 withoutUnicodePtr--;
1131 } else if (currentCharacter == '$' && source[currentPosition] == '{') {
1132 openDollarBrace = true;
1133 } else if (currentCharacter == '{' && source[currentPosition] == '$') {
1134 openDollarBrace = true;
1135 } else if (currentCharacter == '}') {
1136 openDollarBrace = false;
1137 } else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1138 if (recordLineSeparator) {
1139 pushLineSeparator();
1142 // consume next character
1143 unicodeAsBackSlash = false;
1144 currentCharacter = source[currentPosition++];
1145 if (withoutUnicodePtr != 0) {
1146 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1149 } catch (IndexOutOfBoundsException e) {
1150 // reset end position for error reporting
1151 currentPosition -= 2;
1152 throw new InvalidInputException(UNTERMINATED_STRING);
1153 } catch (InvalidInputException e) {
1154 if (e.getMessage().equals(INVALID_ESCAPE)) {
1155 // relocate if finding another quote fairly close: thus unicode
1156 // '/u000D' will be fully consumed
1157 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1158 if (currentPosition + lookAhead == source.length)
1160 if (source[currentPosition + lookAhead] == '\n')
1162 if (source[currentPosition + lookAhead] == '\"') {
1163 currentPosition += lookAhead + 1;
1170 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1171 // //$NON-NLS-?$ where ? is an
1173 if (currentLine == null) {
1174 currentLine = new NLSLine();
1175 lines.add(currentLine);
1177 currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1));
1181 public int getNextToken() throws InvalidInputException {
1182 phpExpressionTag = false;
1184 return getInlinedHTMLToken(currentPosition);
1187 this.wasAcr = false;
1189 jumpOverMethodBody();
1191 return currentPosition > source.length ? TokenNameEOF : TokenNameRBRACE;
1195 withoutUnicodePtr = 0;
1196 //start with a new token
1197 char encapsedChar = ' ';
1198 // if (!encapsedStringStack.isEmpty()) {
1199 // encapsedChar = ((Character) encapsedStringStack.peek()).charValue();
1201 // if (encapsedChar != '$' && encapsedChar != ' ') {
1202 // currentCharacter = source[currentPosition++];
1203 // if (currentCharacter == encapsedChar) {
1204 // switch (currentCharacter) {
1206 // return TokenNameEncapsedString0;
1208 // return TokenNameEncapsedString1;
1210 // return TokenNameEncapsedString2;
1213 // while (currentCharacter != encapsedChar) {
1214 // /** ** in PHP \r and \n are valid in string literals *** */
1215 // switch (currentCharacter) {
1217 // int escapeSize = currentPosition;
1218 // boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1219 // //scanEscapeCharacter make a side effect on this value and
1220 // // we need the previous value few lines down this one
1221 // scanDoubleQuotedEscapeCharacter();
1222 // escapeSize = currentPosition - escapeSize;
1223 // if (withoutUnicodePtr == 0) {
1224 // //buffer all the entries that have been left aside....
1225 // withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition;
1226 // System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr);
1227 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1228 // } else { //overwrite the / in the buffer
1229 // withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1230 // if (backSlashAsUnicodeInString) { //there are TWO \ in
1231 // withoutUnicodePtr--;
1237 // if (recordLineSeparator) {
1238 // pushLineSeparator();
1242 // if (isPHPIdentifierStart(source[currentPosition]) || source[currentPosition] == '{') {
1243 // currentPosition--;
1244 // encapsedStringStack.push(new Character('$'));
1245 // return TokenNameSTRING;
1249 // if (source[currentPosition] == '$') { // CURLY_OPEN
1250 // currentPosition--;
1251 // encapsedStringStack.push(new Character('$'));
1252 // return TokenNameSTRING;
1255 // // consume next character
1256 // unicodeAsBackSlash = false;
1257 // currentCharacter = source[currentPosition++];
1258 // if (withoutUnicodePtr != 0) {
1259 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1263 // currentPosition--;
1264 // return TokenNameSTRING;
1266 // ---------Consume white space and handles startPosition---------
1267 int whiteStart = currentPosition;
1268 startPosition = currentPosition;
1269 currentCharacter = source[currentPosition++];
1270 // if (encapsedChar == '$') {
1271 // switch (currentCharacter) {
1273 // currentCharacter = source[currentPosition++];
1274 // return TokenNameSTRING;
1276 // if (encapsedChar == '$') {
1277 // if (getNextChar('$'))
1278 // return TokenNameLBRACE_DOLLAR;
1280 // return TokenNameLBRACE;
1282 // return TokenNameRBRACE;
1284 // return TokenNameLBRACKET;
1286 // return TokenNameRBRACKET;
1288 // if (tokenizeStrings) {
1289 // consumeStringConstant();
1290 // return TokenNameStringSingleQuote;
1292 // return TokenNameEncapsedString1;
1294 // return TokenNameEncapsedString2;
1296 // if (tokenizeStrings) {
1297 // consumeStringInterpolated();
1298 // return TokenNameStringInterpolated;
1300 // return TokenNameEncapsedString0;
1302 // if (getNextChar('>'))
1303 // return TokenNameMINUS_GREATER;
1304 // return TokenNameSTRING;
1306 // if (currentCharacter == '$') {
1307 // int oldPosition = currentPosition;
1309 // currentCharacter = source[currentPosition++];
1310 // if (currentCharacter == '{') {
1311 // return TokenNameDOLLAR_LBRACE;
1313 // if (isPHPIdentifierStart(currentCharacter)) {
1314 // return scanIdentifierOrKeyword(true);
1316 // currentPosition = oldPosition;
1317 // return TokenNameSTRING;
1319 // } catch (IndexOutOfBoundsException e) {
1320 // currentPosition = oldPosition;
1321 // return TokenNameSTRING;
1324 // if (isPHPIdentifierStart(currentCharacter))
1325 // return scanIdentifierOrKeyword(false);
1326 // if (Character.isDigit(currentCharacter))
1327 // return scanNumber(false);
1328 // return TokenNameERROR;
1331 // boolean isWhiteSpace;
1333 while ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) {
1334 startPosition = currentPosition;
1335 currentCharacter = source[currentPosition++];
1336 // if (((currentCharacter = source[currentPosition++]) == '\\')
1337 // && (source[currentPosition] == 'u')) {
1338 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
1340 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1341 checkNonExternalizeString();
1342 if (recordLineSeparator) {
1343 pushLineSeparator();
1348 // isWhiteSpace = (currentCharacter == ' ')
1349 // || Character.isWhitespace(currentCharacter);
1352 if (tokenizeWhiteSpace && (whiteStart != currentPosition - 1)) {
1353 // reposition scanner in case we are interested by spaces as tokens
1355 startPosition = whiteStart;
1356 return TokenNameWHITESPACE;
1358 //little trick to get out in the middle of a source compuation
1359 if (currentPosition > eofPosition)
1360 return TokenNameEOF;
1361 // ---------Identify the next token-------------
1362 switch (currentCharacter) {
1364 return getCastOrParen();
1366 return TokenNameRPAREN;
1368 return TokenNameLBRACE;
1370 return TokenNameRBRACE;
1372 return TokenNameLBRACKET;
1374 return TokenNameRBRACKET;
1376 return TokenNameSEMICOLON;
1378 return TokenNameCOMMA;
1380 if (getNextChar('='))
1381 return TokenNameDOT_EQUAL;
1382 if (getNextCharAsDigit())
1383 return scanNumber(true);
1384 return TokenNameDOT;
1387 if ((test = getNextChar('+', '=')) == 0)
1388 return TokenNamePLUS_PLUS;
1390 return TokenNamePLUS_EQUAL;
1391 return TokenNamePLUS;
1395 if ((test = getNextChar('-', '=')) == 0)
1396 return TokenNameMINUS_MINUS;
1398 return TokenNameMINUS_EQUAL;
1399 if (getNextChar('>'))
1400 return TokenNameMINUS_GREATER;
1401 return TokenNameMINUS;
1404 if (getNextChar('='))
1405 return TokenNameTWIDDLE_EQUAL;
1406 return TokenNameTWIDDLE;
1408 if (getNextChar('=')) {
1409 if (getNextChar('=')) {
1410 return TokenNameNOT_EQUAL_EQUAL;
1412 return TokenNameNOT_EQUAL;
1414 return TokenNameNOT;
1416 if (getNextChar('='))
1417 return TokenNameMULTIPLY_EQUAL;
1418 return TokenNameMULTIPLY;
1420 if (getNextChar('='))
1421 return TokenNameREMAINDER_EQUAL;
1422 return TokenNameREMAINDER;
1424 int oldPosition = currentPosition;
1426 currentCharacter = source[currentPosition++];
1427 } catch (IndexOutOfBoundsException e) {
1428 currentPosition = oldPosition;
1429 return TokenNameLESS;
1431 switch (currentCharacter) {
1433 return TokenNameLESS_EQUAL;
1435 return TokenNameNOT_EQUAL;
1437 if (getNextChar('='))
1438 return TokenNameLEFT_SHIFT_EQUAL;
1439 if (getNextChar('<')) {
1440 currentCharacter = source[currentPosition++];
1441 while (Character.isWhitespace(currentCharacter)) {
1442 currentCharacter = source[currentPosition++];
1444 int heredocStart = currentPosition - 1;
1445 int heredocLength = 0;
1446 if (isPHPIdentifierStart(currentCharacter)) {
1447 currentCharacter = source[currentPosition++];
1449 return TokenNameERROR;
1451 while (isPHPIdentifierPart(currentCharacter)) {
1452 currentCharacter = source[currentPosition++];
1454 heredocLength = currentPosition - heredocStart - 1;
1455 // heredoc end-tag determination
1456 boolean endTag = true;
1459 ch = source[currentPosition++];
1460 if (ch == '\r' || ch == '\n') {
1461 if (recordLineSeparator) {
1462 pushLineSeparator();
1466 for (int i = 0; i < heredocLength; i++) {
1467 if (source[currentPosition + i] != source[heredocStart + i]) {
1473 currentPosition += heredocLength - 1;
1474 currentCharacter = source[currentPosition++];
1475 break; // do...while loop
1481 return TokenNameHEREDOC;
1483 return TokenNameLEFT_SHIFT;
1485 currentPosition = oldPosition;
1486 return TokenNameLESS;
1490 if ((test = getNextChar('=', '>')) == 0)
1491 return TokenNameGREATER_EQUAL;
1493 if ((test = getNextChar('=', '>')) == 0)
1494 return TokenNameRIGHT_SHIFT_EQUAL;
1495 return TokenNameRIGHT_SHIFT;
1497 return TokenNameGREATER;
1500 if (getNextChar('=')) {
1501 if (getNextChar('=')) {
1502 return TokenNameEQUAL_EQUAL_EQUAL;
1504 return TokenNameEQUAL_EQUAL;
1506 if (getNextChar('>'))
1507 return TokenNameEQUAL_GREATER;
1508 return TokenNameEQUAL;
1511 if ((test = getNextChar('&', '=')) == 0)
1512 return TokenNameAND_AND;
1514 return TokenNameAND_EQUAL;
1515 return TokenNameAND;
1519 if ((test = getNextChar('|', '=')) == 0)
1520 return TokenNameOR_OR;
1522 return TokenNameOR_EQUAL;
1526 if (getNextChar('='))
1527 return TokenNameXOR_EQUAL;
1528 return TokenNameXOR;
1530 if (getNextChar('>')) {
1532 if (currentPosition == source.length) {
1534 return TokenNameINLINE_HTML;
1536 return getInlinedHTMLToken(currentPosition - 2);
1538 return TokenNameQUESTION;
1540 if (getNextChar(':'))
1541 return TokenNamePAAMAYIM_NEKUDOTAYIM;
1542 return TokenNameCOLON;
1546 consumeStringConstant();
1547 return TokenNameStringSingleQuote;
1549 // if (tokenizeStrings) {
1550 consumeStringLiteral();
1551 return TokenNameStringDoubleQuote;
1553 // return TokenNameEncapsedString2;
1555 // if (tokenizeStrings) {
1556 consumeStringInterpolated();
1557 return TokenNameStringInterpolated;
1559 // return TokenNameEncapsedString0;
1562 char startChar = currentCharacter;
1563 if (getNextChar('=') && startChar == '/') {
1564 return TokenNameDIVIDE_EQUAL;
1567 if ((startChar == '#') || (test = getNextChar('/', '*')) == 0) {
1569 this.lastCommentLinePosition = this.currentPosition;
1570 int endPositionForLineComment = 0;
1571 try { //get the next char
1572 currentCharacter = source[currentPosition++];
1573 // if (((currentCharacter = source[currentPosition++])
1575 // && (source[currentPosition] == 'u')) {
1576 // //-------------unicode traitement ------------
1577 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1578 // currentPosition++;
1579 // while (source[currentPosition] == 'u') {
1580 // currentPosition++;
1583 // Character.getNumericValue(source[currentPosition++]))
1587 // Character.getNumericValue(source[currentPosition++]))
1591 // Character.getNumericValue(source[currentPosition++]))
1595 // Character.getNumericValue(source[currentPosition++]))
1599 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1601 // currentCharacter =
1602 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1605 //handle the \\u case manually into comment
1606 // if (currentCharacter == '\\') {
1607 // if (source[currentPosition] == '\\')
1608 // currentPosition++;
1609 // } //jump over the \\
1610 boolean isUnicode = false;
1611 while (currentCharacter != '\r' && currentCharacter != '\n') {
1612 this.lastCommentLinePosition = this.currentPosition;
1613 if (currentCharacter == '?') {
1614 if (getNextChar('>')) {
1615 startPosition = currentPosition - 2;
1617 return TokenNameINLINE_HTML;
1622 currentCharacter = source[currentPosition++];
1623 // if (((currentCharacter = source[currentPosition++])
1625 // && (source[currentPosition] == 'u')) {
1626 // isUnicode = true;
1627 // //-------------unicode traitement ------------
1628 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1629 // currentPosition++;
1630 // while (source[currentPosition] == 'u') {
1631 // currentPosition++;
1634 // Character.getNumericValue(source[currentPosition++]))
1638 // Character.getNumericValue(
1639 // source[currentPosition++]))
1643 // Character.getNumericValue(
1644 // source[currentPosition++]))
1648 // Character.getNumericValue(
1649 // source[currentPosition++]))
1653 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1655 // currentCharacter =
1656 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1659 //handle the \\u case manually into comment
1660 // if (currentCharacter == '\\') {
1661 // if (source[currentPosition] == '\\')
1662 // currentPosition++;
1663 // } //jump over the \\
1666 endPositionForLineComment = currentPosition - 6;
1668 endPositionForLineComment = currentPosition - 1;
1670 // recordComment(false);
1671 recordComment(TokenNameCOMMENT_LINE);
1672 if (this.taskTags != null)
1673 checkTaskTag(this.startPosition, this.currentPosition);
1674 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1675 checkNonExternalizeString();
1676 if (recordLineSeparator) {
1678 pushUnicodeLineSeparator();
1680 pushLineSeparator();
1686 if (tokenizeComments) {
1688 currentPosition = endPositionForLineComment;
1689 // reset one character behind
1691 return TokenNameCOMMENT_LINE;
1693 } catch (IndexOutOfBoundsException e) { //an eof will them
1695 if (tokenizeComments) {
1697 // reset one character behind
1698 return TokenNameCOMMENT_LINE;
1704 //traditional and annotation comment
1705 boolean isJavadoc = false, star = false;
1706 // consume next character
1707 unicodeAsBackSlash = false;
1708 currentCharacter = source[currentPosition++];
1709 // if (((currentCharacter = source[currentPosition++]) ==
1711 // && (source[currentPosition] == 'u')) {
1712 // getNextUnicodeChar();
1714 // if (withoutUnicodePtr != 0) {
1715 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1716 // currentCharacter;
1719 if (currentCharacter == '*') {
1723 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1724 checkNonExternalizeString();
1725 if (recordLineSeparator) {
1726 pushLineSeparator();
1731 try { //get the next char
1732 currentCharacter = source[currentPosition++];
1733 // if (((currentCharacter = source[currentPosition++])
1735 // && (source[currentPosition] == 'u')) {
1736 // //-------------unicode traitement ------------
1737 // getNextUnicodeChar();
1739 //handle the \\u case manually into comment
1740 // if (currentCharacter == '\\') {
1741 // if (source[currentPosition] == '\\')
1742 // currentPosition++;
1743 // //jump over the \\
1745 // empty comment is not a javadoc /**/
1746 if (currentCharacter == '/') {
1749 //loop until end of comment */
1750 while ((currentCharacter != '/') || (!star)) {
1751 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1752 checkNonExternalizeString();
1753 if (recordLineSeparator) {
1754 pushLineSeparator();
1759 star = currentCharacter == '*';
1761 currentCharacter = source[currentPosition++];
1762 // if (((currentCharacter = source[currentPosition++])
1764 // && (source[currentPosition] == 'u')) {
1765 // //-------------unicode traitement ------------
1766 // getNextUnicodeChar();
1768 //handle the \\u case manually into comment
1769 // if (currentCharacter == '\\') {
1770 // if (source[currentPosition] == '\\')
1771 // currentPosition++;
1772 // } //jump over the \\
1774 //recordComment(isJavadoc);
1776 recordComment(TokenNameCOMMENT_PHPDOC);
1778 recordComment(TokenNameCOMMENT_BLOCK);
1781 if (tokenizeComments) {
1783 return TokenNameCOMMENT_PHPDOC;
1784 return TokenNameCOMMENT_BLOCK;
1787 if (this.taskTags != null) {
1788 checkTaskTag(this.startPosition, this.currentPosition);
1790 } catch (IndexOutOfBoundsException e) {
1791 // reset end position for error reporting
1792 currentPosition -= 2;
1793 throw new InvalidInputException(UNTERMINATED_COMMENT);
1797 return TokenNameDIVIDE;
1801 return TokenNameEOF;
1802 //the atEnd may not be <currentPosition == source.length> if
1803 // source is only some part of a real (external) stream
1804 throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$
1806 if (currentCharacter == '$') {
1807 int oldPosition = currentPosition;
1809 currentCharacter = source[currentPosition++];
1810 if (isPHPIdentifierStart(currentCharacter)) {
1811 return scanIdentifierOrKeyword(true);
1813 currentPosition = oldPosition;
1814 return TokenNameDOLLAR;
1816 } catch (IndexOutOfBoundsException e) {
1817 currentPosition = oldPosition;
1818 return TokenNameDOLLAR;
1821 if (isPHPIdentifierStart(currentCharacter))
1822 return scanIdentifierOrKeyword(false);
1823 if (Character.isDigit(currentCharacter))
1824 return scanNumber(false);
1825 return TokenNameERROR;
1828 } //-----------------end switch while try--------------------
1829 catch (IndexOutOfBoundsException e) {
1832 return TokenNameEOF;
1837 * @throws InvalidInputException
1839 private int getInlinedHTMLToken(int start) throws InvalidInputException {
1840 if (currentPosition > source.length) {
1841 currentPosition = source.length;
1842 return TokenNameEOF;
1844 startPosition = start;
1847 currentCharacter = source[currentPosition++];
1848 if (currentCharacter == '<') {
1849 if (getNextChar('?')) {
1850 currentCharacter = source[currentPosition++];
1851 if ((currentCharacter != 'P') && (currentCharacter != 'p')) {
1852 if (currentCharacter != '=') { // <?=
1855 phpExpressionTag = true;
1858 if (ignorePHPOneLiner) { // for CodeFormatter
1859 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1861 return TokenNameINLINE_HTML;
1865 return TokenNameINLINE_HTML;
1868 // boolean phpStart = (currentCharacter == 'P') || (currentCharacter == 'p');
1870 int test = getNextChar('H', 'h');
1872 test = getNextChar('P', 'p');
1875 if (ignorePHPOneLiner) {
1876 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1878 return TokenNameINLINE_HTML;
1882 return TokenNameINLINE_HTML;
1890 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1891 if (recordLineSeparator) {
1892 pushLineSeparator();
1897 } //-----------------while--------------------
1899 return TokenNameINLINE_HTML;
1900 } //-----------------try--------------------
1901 catch (IndexOutOfBoundsException e) {
1902 startPosition = start;
1906 return TokenNameINLINE_HTML;
1912 private int lookAheadLinePHPTag() {
1913 // check if the PHP is only in this line (for CodeFormatter)
1914 int currentPositionInLine = currentPosition;
1915 char previousCharInLine = ' ';
1916 char currentCharInLine = ' ';
1917 boolean singleQuotedStringActive = false;
1918 boolean doubleQuotedStringActive = false;
1921 // look ahead in this line
1923 previousCharInLine = currentCharInLine;
1924 currentCharInLine = source[currentPositionInLine++];
1925 switch (currentCharInLine) {
1927 if (previousCharInLine == '?') {
1928 // update the scanner's current Position in the source
1929 currentPosition = currentPositionInLine;
1930 // use as "dummy" token
1931 return TokenNameEOF;
1935 if (doubleQuotedStringActive) {
1936 // ignore escaped characters in double quoted strings
1937 previousCharInLine = currentCharInLine;
1938 currentCharInLine = source[currentPositionInLine++];
1941 if (doubleQuotedStringActive) {
1942 doubleQuotedStringActive = false;
1944 if (!singleQuotedStringActive) {
1945 doubleQuotedStringActive = true;
1950 if (singleQuotedStringActive) {
1951 if (previousCharInLine != '\\') {
1952 singleQuotedStringActive = false;
1955 if (!doubleQuotedStringActive) {
1956 singleQuotedStringActive = true;
1962 return TokenNameINLINE_HTML;
1964 if (!singleQuotedStringActive && !doubleQuotedStringActive) {
1966 return TokenNameINLINE_HTML;
1970 if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1972 return TokenNameINLINE_HTML;
1976 if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1978 return TokenNameINLINE_HTML;
1983 } catch (IndexOutOfBoundsException e) {
1985 currentPosition = currentPositionInLine;
1986 return TokenNameINLINE_HTML;
1990 // public final void getNextUnicodeChar()
1991 // throws IndexOutOfBoundsException, InvalidInputException {
1993 // //handle the case of unicode.
1994 // //when a unicode appears then we must use a buffer that holds char
1996 // //At the end of this method currentCharacter holds the new visited char
1997 // //and currentPosition points right next after it
1999 // //ALL getNextChar.... ARE OPTIMIZED COPIES
2001 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
2002 // currentPosition++;
2003 // while (source[currentPosition] == 'u') {
2004 // currentPosition++;
2008 // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2010 // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
2012 // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
2014 // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
2016 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2018 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2019 // //need the unicode buffer
2020 // if (withoutUnicodePtr == 0) {
2021 // //buffer all the entries that have been left aside....
2022 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
2023 // System.arraycopy(
2026 // withoutUnicodeBuffer,
2028 // withoutUnicodePtr);
2030 // //fill the buffer with the char
2031 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2033 // unicodeAsBackSlash = currentCharacter == '\\';
2036 * Tokenize a method body, assuming that curly brackets are properly balanced.
2038 public final void jumpOverMethodBody() {
2039 this.wasAcr = false;
2042 while (true) { //loop for jumping over comments
2043 // ---------Consume white space and handles startPosition---------
2044 boolean isWhiteSpace;
2046 startPosition = currentPosition;
2047 currentCharacter = source[currentPosition++];
2048 // if (((currentCharacter = source[currentPosition++]) == '\\')
2049 // && (source[currentPosition] == 'u')) {
2050 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
2052 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2053 pushLineSeparator();
2054 isWhiteSpace = Character.isWhitespace(currentCharacter);
2056 } while (isWhiteSpace);
2057 // -------consume token until } is found---------
2058 switch (currentCharacter) {
2069 test = getNextChar('\\');
2072 scanDoubleQuotedEscapeCharacter();
2073 } catch (InvalidInputException ex) {
2077 // try { // consume next character
2078 unicodeAsBackSlash = false;
2079 currentCharacter = source[currentPosition++];
2080 // if (((currentCharacter = source[currentPosition++]) == '\\')
2081 // && (source[currentPosition] == 'u')) {
2082 // getNextUnicodeChar();
2084 if (withoutUnicodePtr != 0) {
2085 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2088 // } catch (InvalidInputException ex) {
2096 // try { // consume next character
2097 unicodeAsBackSlash = false;
2098 currentCharacter = source[currentPosition++];
2099 // if (((currentCharacter = source[currentPosition++]) == '\\')
2100 // && (source[currentPosition] == 'u')) {
2101 // getNextUnicodeChar();
2103 if (withoutUnicodePtr != 0) {
2104 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2107 // } catch (InvalidInputException ex) {
2109 while (currentCharacter != '"') {
2110 if (currentCharacter == '\r') {
2111 if (source[currentPosition] == '\n')
2114 // the string cannot go further that the line
2116 if (currentCharacter == '\n') {
2118 // the string cannot go further that the line
2120 if (currentCharacter == '\\') {
2122 scanDoubleQuotedEscapeCharacter();
2123 } catch (InvalidInputException ex) {
2127 // try { // consume next character
2128 unicodeAsBackSlash = false;
2129 currentCharacter = source[currentPosition++];
2130 // if (((currentCharacter = source[currentPosition++]) == '\\')
2131 // && (source[currentPosition] == 'u')) {
2132 // getNextUnicodeChar();
2134 if (withoutUnicodePtr != 0) {
2135 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2138 // } catch (InvalidInputException ex) {
2141 } catch (IndexOutOfBoundsException e) {
2147 if ((test = getNextChar('/', '*')) == 0) {
2151 currentCharacter = source[currentPosition++];
2152 // if (((currentCharacter = source[currentPosition++]) ==
2154 // && (source[currentPosition] == 'u')) {
2155 // //-------------unicode traitement ------------
2156 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2157 // currentPosition++;
2158 // while (source[currentPosition] == 'u') {
2159 // currentPosition++;
2162 // Character.getNumericValue(source[currentPosition++]))
2166 // Character.getNumericValue(source[currentPosition++]))
2170 // Character.getNumericValue(source[currentPosition++]))
2174 // Character.getNumericValue(source[currentPosition++]))
2177 // //error don't care of the value
2178 // currentCharacter = 'A';
2179 // } //something different from \n and \r
2181 // currentCharacter =
2182 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2185 while (currentCharacter != '\r' && currentCharacter != '\n') {
2187 currentCharacter = source[currentPosition++];
2188 // if (((currentCharacter = source[currentPosition++])
2190 // && (source[currentPosition] == 'u')) {
2191 // //-------------unicode traitement ------------
2192 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2193 // currentPosition++;
2194 // while (source[currentPosition] == 'u') {
2195 // currentPosition++;
2198 // Character.getNumericValue(source[currentPosition++]))
2202 // Character.getNumericValue(source[currentPosition++]))
2206 // Character.getNumericValue(source[currentPosition++]))
2210 // Character.getNumericValue(source[currentPosition++]))
2213 // //error don't care of the value
2214 // currentCharacter = 'A';
2215 // } //something different from \n and \r
2217 // currentCharacter =
2218 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2222 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2223 pushLineSeparator();
2224 } catch (IndexOutOfBoundsException e) {
2225 } //an eof will them be generated
2229 //traditional and annotation comment
2230 boolean star = false;
2231 // try { // consume next character
2232 unicodeAsBackSlash = false;
2233 currentCharacter = source[currentPosition++];
2234 // if (((currentCharacter = source[currentPosition++]) == '\\')
2235 // && (source[currentPosition] == 'u')) {
2236 // getNextUnicodeChar();
2238 if (withoutUnicodePtr != 0) {
2239 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2242 // } catch (InvalidInputException ex) {
2244 if (currentCharacter == '*') {
2247 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2248 pushLineSeparator();
2249 try { //get the next char
2250 currentCharacter = source[currentPosition++];
2251 // if (((currentCharacter = source[currentPosition++]) ==
2253 // && (source[currentPosition] == 'u')) {
2254 // //-------------unicode traitement ------------
2255 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2256 // currentPosition++;
2257 // while (source[currentPosition] == 'u') {
2258 // currentPosition++;
2261 // Character.getNumericValue(source[currentPosition++]))
2265 // Character.getNumericValue(source[currentPosition++]))
2269 // Character.getNumericValue(source[currentPosition++]))
2273 // Character.getNumericValue(source[currentPosition++]))
2276 // //error don't care of the value
2277 // currentCharacter = 'A';
2278 // } //something different from * and /
2280 // currentCharacter =
2281 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2284 //loop until end of comment */
2285 while ((currentCharacter != '/') || (!star)) {
2286 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2287 pushLineSeparator();
2288 star = currentCharacter == '*';
2290 currentCharacter = source[currentPosition++];
2291 // if (((currentCharacter = source[currentPosition++])
2293 // && (source[currentPosition] == 'u')) {
2294 // //-------------unicode traitement ------------
2295 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2296 // currentPosition++;
2297 // while (source[currentPosition] == 'u') {
2298 // currentPosition++;
2301 // Character.getNumericValue(source[currentPosition++]))
2305 // Character.getNumericValue(source[currentPosition++]))
2309 // Character.getNumericValue(source[currentPosition++]))
2313 // Character.getNumericValue(source[currentPosition++]))
2316 // //error don't care of the value
2317 // currentCharacter = 'A';
2318 // } //something different from * and /
2320 // currentCharacter =
2321 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2325 } catch (IndexOutOfBoundsException e) {
2333 if (isPHPIdentifierStart(currentCharacter) || currentCharacter == '$') {
2335 scanIdentifierOrKeyword((currentCharacter == '$'));
2336 } catch (InvalidInputException ex) {
2341 if (Character.isDigit(currentCharacter)) {
2344 } catch (InvalidInputException ex) {
2351 //-----------------end switch while try--------------------
2352 } catch (IndexOutOfBoundsException e) {
2353 } catch (InvalidInputException e) {
2358 // public final boolean jumpOverUnicodeWhiteSpace()
2359 // throws InvalidInputException {
2361 // //handle the case of unicode. Jump over the next whiteSpace
2362 // //making startPosition pointing on the next available char
2363 // //On false, the currentCharacter is filled up with a potential
2367 // this.wasAcr = false;
2368 // int c1, c2, c3, c4;
2369 // int unicodeSize = 6;
2370 // currentPosition++;
2371 // while (source[currentPosition] == 'u') {
2372 // currentPosition++;
2376 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2378 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2380 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2382 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2384 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2387 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2388 // if (recordLineSeparator
2389 // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2390 // pushLineSeparator();
2391 // if (Character.isWhitespace(currentCharacter))
2394 // //buffer the new char which is not a white space
2395 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2396 // //withoutUnicodePtr == 1 is true here
2398 // } catch (IndexOutOfBoundsException e) {
2399 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2402 public final int[] getLineEnds() {
2403 //return a bounded copy of this.lineEnds
2405 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0, linePtr + 1);
2409 public char[] getSource() {
2413 public static boolean isIdentifierOrKeyword(int token) {
2414 return (token == TokenNameIdentifier) || (token > TokenNameKEYWORD);
2417 final char[] optimizedCurrentTokenSource1() {
2418 //return always the same char[] build only once
2419 //optimization at no speed cost of 99.5 % of the singleCharIdentifier
2420 char charOne = source[startPosition];
2475 return new char[] { charOne };
2479 final char[] optimizedCurrentTokenSource2() {
2481 c0 = source[startPosition];
2482 c1 = source[startPosition + 1];
2484 //return always the same char[] build only once
2485 //optimization at no speed cost of 99.5 % of the singleCharIdentifier
2488 return charArray_va;
2490 return charArray_vb;
2492 return charArray_vc;
2494 return charArray_vd;
2496 return charArray_ve;
2498 return charArray_vf;
2500 return charArray_vg;
2502 return charArray_vh;
2504 return charArray_vi;
2506 return charArray_vj;
2508 return charArray_vk;
2510 return charArray_vl;
2512 return charArray_vm;
2514 return charArray_vn;
2516 return charArray_vo;
2518 return charArray_vp;
2520 return charArray_vq;
2522 return charArray_vr;
2524 return charArray_vs;
2526 return charArray_vt;
2528 return charArray_vu;
2530 return charArray_vv;
2532 return charArray_vw;
2534 return charArray_vx;
2536 return charArray_vy;
2538 return charArray_vz;
2541 //try to return the same char[] build only once
2542 int hash = ((c0 << 6) + c1) % TableSize;
2543 char[][] table = charArray_length[0][hash];
2545 while (++i < InternalTableSize) {
2546 char[] charArray = table[i];
2547 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2550 //---------other side---------
2552 int max = newEntry2;
2553 while (++i <= max) {
2554 char[] charArray = table[i];
2555 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2558 //--------add the entry-------
2559 if (++max >= InternalTableSize)
2562 table[max] = (r = new char[] { c0, c1 });
2567 final char[] optimizedCurrentTokenSource3() {
2568 //try to return the same char[] build only once
2570 int hash = (((c0 = source[startPosition]) << 12) + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2572 char[][] table = charArray_length[1][hash];
2574 while (++i < InternalTableSize) {
2575 char[] charArray = table[i];
2576 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2579 //---------other side---------
2581 int max = newEntry3;
2582 while (++i <= max) {
2583 char[] charArray = table[i];
2584 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2587 //--------add the entry-------
2588 if (++max >= InternalTableSize)
2591 table[max] = (r = new char[] { c0, c1, c2 });
2596 final char[] optimizedCurrentTokenSource4() {
2597 //try to return the same char[] build only once
2598 char c0, c1, c2, c3;
2599 long hash = ((((long) (c0 = source[startPosition])) << 18) + ((c1 = source[startPosition + 1]) << 12)
2600 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2602 char[][] table = charArray_length[2][(int) hash];
2604 while (++i < InternalTableSize) {
2605 char[] charArray = table[i];
2606 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2609 //---------other side---------
2611 int max = newEntry4;
2612 while (++i <= max) {
2613 char[] charArray = table[i];
2614 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2617 //--------add the entry-------
2618 if (++max >= InternalTableSize)
2621 table[max] = (r = new char[] { c0, c1, c2, c3 });
2626 final char[] optimizedCurrentTokenSource5() {
2627 //try to return the same char[] build only once
2628 char c0, c1, c2, c3, c4;
2629 long hash = ((((long) (c0 = source[startPosition])) << 24) + (((long) (c1 = source[startPosition + 1])) << 18)
2630 + ((c2 = source[startPosition + 2]) << 12) + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2632 char[][] table = charArray_length[3][(int) hash];
2634 while (++i < InternalTableSize) {
2635 char[] charArray = table[i];
2636 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2639 //---------other side---------
2641 int max = newEntry5;
2642 while (++i <= max) {
2643 char[] charArray = table[i];
2644 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2647 //--------add the entry-------
2648 if (++max >= InternalTableSize)
2651 table[max] = (r = new char[] { c0, c1, c2, c3, c4 });
2656 final char[] optimizedCurrentTokenSource6() {
2657 //try to return the same char[] build only once
2658 char c0, c1, c2, c3, c4, c5;
2659 long hash = ((((long) (c0 = source[startPosition])) << 32) + (((long) (c1 = source[startPosition + 1])) << 24)
2660 + (((long) (c2 = source[startPosition + 2])) << 18) + ((c3 = source[startPosition + 3]) << 12)
2661 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2663 char[][] table = charArray_length[4][(int) hash];
2665 while (++i < InternalTableSize) {
2666 char[] charArray = table[i];
2667 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2668 && (c5 == charArray[5]))
2671 //---------other side---------
2673 int max = newEntry6;
2674 while (++i <= max) {
2675 char[] charArray = table[i];
2676 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2677 && (c5 == charArray[5]))
2680 //--------add the entry-------
2681 if (++max >= InternalTableSize)
2684 table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 });
2689 public final void pushLineSeparator() throws InvalidInputException {
2690 //see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2691 final int INCREMENT = 250;
2692 if (this.checkNonExternalizedStringLiterals) {
2693 // reinitialize the current line for non externalize strings purpose
2696 //currentCharacter is at position currentPosition-1
2698 if (currentCharacter == '\r') {
2699 int separatorPos = currentPosition - 1;
2700 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2702 //System.out.println("CR-" + separatorPos);
2704 lineEnds[++linePtr] = separatorPos;
2705 } catch (IndexOutOfBoundsException e) {
2706 //linePtr value is correct
2707 int oldLength = lineEnds.length;
2708 int[] old = lineEnds;
2709 lineEnds = new int[oldLength + INCREMENT];
2710 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2711 lineEnds[linePtr] = separatorPos;
2713 // look-ahead for merged cr+lf
2715 if (source[currentPosition] == '\n') {
2716 //System.out.println("look-ahead LF-" + currentPosition);
2717 lineEnds[linePtr] = currentPosition;
2723 } catch (IndexOutOfBoundsException e) {
2728 if (currentCharacter == '\n') {
2729 //must merge eventual cr followed by lf
2730 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2731 //System.out.println("merge LF-" + (currentPosition - 1));
2732 lineEnds[linePtr] = currentPosition - 1;
2734 int separatorPos = currentPosition - 1;
2735 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2737 // System.out.println("LF-" + separatorPos);
2739 lineEnds[++linePtr] = separatorPos;
2740 } catch (IndexOutOfBoundsException e) {
2741 //linePtr value is correct
2742 int oldLength = lineEnds.length;
2743 int[] old = lineEnds;
2744 lineEnds = new int[oldLength + INCREMENT];
2745 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2746 lineEnds[linePtr] = separatorPos;
2754 public final void pushUnicodeLineSeparator() {
2755 // isUnicode means that the \r or \n has been read as a unicode character
2756 //see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2757 final int INCREMENT = 250;
2758 //currentCharacter is at position currentPosition-1
2759 if (this.checkNonExternalizedStringLiterals) {
2760 // reinitialize the current line for non externalize strings purpose
2764 if (currentCharacter == '\r') {
2765 int separatorPos = currentPosition - 6;
2766 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2768 //System.out.println("CR-" + separatorPos);
2770 lineEnds[++linePtr] = separatorPos;
2771 } catch (IndexOutOfBoundsException e) {
2772 //linePtr value is correct
2773 int oldLength = lineEnds.length;
2774 int[] old = lineEnds;
2775 lineEnds = new int[oldLength + INCREMENT];
2776 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2777 lineEnds[linePtr] = separatorPos;
2779 // look-ahead for merged cr+lf
2780 if (source[currentPosition] == '\n') {
2781 //System.out.println("look-ahead LF-" + currentPosition);
2782 lineEnds[linePtr] = currentPosition;
2790 if (currentCharacter == '\n') {
2791 //must merge eventual cr followed by lf
2792 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2793 //System.out.println("merge LF-" + (currentPosition - 1));
2794 lineEnds[linePtr] = currentPosition - 6;
2796 int separatorPos = currentPosition - 6;
2797 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2799 // System.out.println("LF-" + separatorPos);
2801 lineEnds[++linePtr] = separatorPos;
2802 } catch (IndexOutOfBoundsException e) {
2803 //linePtr value is correct
2804 int oldLength = lineEnds.length;
2805 int[] old = lineEnds;
2806 lineEnds = new int[oldLength + INCREMENT];
2807 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2808 lineEnds[linePtr] = separatorPos;
2816 public void recordComment(int token) {
2818 int stopPosition = this.currentPosition;
2820 case TokenNameCOMMENT_LINE:
2821 stopPosition = -this.lastCommentLinePosition;
2823 case TokenNameCOMMENT_BLOCK:
2824 stopPosition = -this.currentPosition;
2828 // a new comment is recorded
2829 int length = this.commentStops.length;
2830 if (++this.commentPtr >= length) {
2831 System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length);
2832 //grows the positions buffers too
2833 System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length);
2835 this.commentStops[this.commentPtr] = stopPosition;
2836 this.commentStarts[this.commentPtr] = this.startPosition;
2839 // public final void recordComment(boolean isJavadoc) {
2840 // // a new annotation comment is recorded
2842 // commentStops[++commentPtr] = isJavadoc
2843 // ? currentPosition
2844 // : -currentPosition;
2845 // } catch (IndexOutOfBoundsException e) {
2846 // int oldStackLength = commentStops.length;
2847 // int[] oldStack = commentStops;
2848 // commentStops = new int[oldStackLength + 30];
2849 // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
2850 // commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition;
2851 // //grows the positions buffers too
2852 // int[] old = commentStarts;
2853 // commentStarts = new int[oldStackLength + 30];
2854 // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
2856 // //the buffer is of a correct size here
2857 // commentStarts[commentPtr] = startPosition;
2859 public void resetTo(int begin, int end) {
2860 //reset the scanner to a given position where it may rescan again
2862 initialPosition = startPosition = currentPosition = begin;
2863 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
2864 commentPtr = -1; // reset comment stack
2867 public final void scanSingleQuotedEscapeCharacter() throws InvalidInputException {
2868 // the string with "\\u" is a legal string of two chars \ and u
2869 //thus we use a direct access to the source (for regular cases).
2870 // if (unicodeAsBackSlash) {
2871 // // consume next character
2872 // unicodeAsBackSlash = false;
2873 // if (((currentCharacter = source[currentPosition++]) == '\\')
2874 // && (source[currentPosition] == 'u')) {
2875 // getNextUnicodeChar();
2877 // if (withoutUnicodePtr != 0) {
2878 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2882 currentCharacter = source[currentPosition++];
2883 switch (currentCharacter) {
2885 currentCharacter = '\'';
2888 currentCharacter = '\\';
2891 currentCharacter = '\\';
2896 public final void scanDoubleQuotedEscapeCharacter() throws InvalidInputException {
2897 currentCharacter = source[currentPosition++];
2898 switch (currentCharacter) {
2900 // currentCharacter = '\b';
2903 currentCharacter = '\t';
2906 currentCharacter = '\n';
2909 // currentCharacter = '\f';
2912 currentCharacter = '\r';
2915 currentCharacter = '\"';
2918 currentCharacter = '\'';
2921 currentCharacter = '\\';
2924 currentCharacter = '$';
2927 // -----------octal escape--------------
2929 // OctalDigit OctalDigit
2930 // ZeroToThree OctalDigit OctalDigit
2931 int number = Character.getNumericValue(currentCharacter);
2932 if (number >= 0 && number <= 7) {
2933 boolean zeroToThreeNot = number > 3;
2934 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2935 int digit = Character.getNumericValue(currentCharacter);
2936 if (digit >= 0 && digit <= 7) {
2937 number = (number * 8) + digit;
2938 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2939 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
2940 // Digit --> ignore last character
2943 digit = Character.getNumericValue(currentCharacter);
2944 if (digit >= 0 && digit <= 7) {
2945 // has read \ZeroToThree OctalDigit OctalDigit
2946 number = (number * 8) + digit;
2947 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
2948 // --> ignore last character
2952 } else { // has read \OctalDigit NonDigit--> ignore last
2956 } else { // has read \OctalDigit NonOctalDigit--> ignore last
2960 } else { // has read \OctalDigit --> ignore last character
2964 throw new InvalidInputException(INVALID_ESCAPE);
2965 currentCharacter = (char) number;
2968 // throw new InvalidInputException(INVALID_ESCAPE);
2972 // public int scanIdentifierOrKeyword() throws InvalidInputException {
2973 // return scanIdentifierOrKeyword( false );
2975 public int scanIdentifierOrKeyword(boolean isVariable) throws InvalidInputException {
2977 //first dispatch on the first char.
2978 //then the length. If there are several
2979 //keywors with the same length AND the same first char, then do another
2980 //disptach on the second char :-)...cool....but fast !
2981 useAssertAsAnIndentifier = false;
2982 while (getNextCharAsJavaIdentifierPart()) {
2986 // if (new String(getCurrentTokenSource()).equals("$this")) {
2987 // return TokenNamethis;
2989 return TokenNameVariable;
2994 // if (withoutUnicodePtr == 0)
2995 //quick test on length == 1 but not on length > 12 while most identifier
2996 //have a length which is <= 12...but there are lots of identifier with
2999 if ((length = currentPosition - startPosition) == 1)
3000 return TokenNameIdentifier;
3002 data = new char[length];
3003 index = startPosition;
3004 for (int i = 0; i < length; i++) {
3005 data[i] = Character.toLowerCase(source[index + i]);
3009 // if ((length = withoutUnicodePtr) == 1)
3010 // return TokenNameIdentifier;
3011 // // data = withoutUnicodeBuffer;
3012 // data = new char[withoutUnicodeBuffer.length];
3013 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
3014 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
3018 firstLetter = data[index];
3019 switch (firstLetter) {
3024 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'i') && (data[++index] == 'l')
3025 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3026 return TokenNameFILE;
3027 index = 0; //__LINE__
3028 if ((data[++index] == '_') && (data[++index] == 'l') && (data[++index] == 'i') && (data[++index] == 'n')
3029 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3030 return TokenNameLINE;
3034 if ((data[++index] == '_') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3035 && (data[++index] == 's') && (data[++index] == 's') && (data[++index] == '_') && (data[++index] == '_'))
3036 return TokenNameCLASS_C;
3040 if ((data[++index] == '_') && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 't')
3041 && (data[++index] == 'h') && (data[++index] == 'o') && (data[++index] == 'd') && (data[++index] == '_')
3042 && (data[++index] == '_'))
3043 return TokenNameMETHOD_C;
3047 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'u') && (data[++index] == 'n')
3048 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'o')
3049 && (data[++index] == 'n') && (data[++index] == '_') && (data[++index] == '_'))
3050 return TokenNameFUNC_C;
3053 return TokenNameIdentifier;
3055 // as and array abstract
3059 if ((data[++index] == 's')) {
3062 return TokenNameIdentifier;
3066 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3067 return TokenNameand;
3069 return TokenNameIdentifier;
3073 if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y'))
3074 return TokenNamearray;
3076 return TokenNameIdentifier;
3078 if ((data[++index] == 'b') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'r')
3079 && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 't'))
3080 return TokenNameabstract;
3082 return TokenNameIdentifier;
3084 return TokenNameIdentifier;
3090 if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k'))
3091 return TokenNamebreak;
3093 return TokenNameIdentifier;
3095 return TokenNameIdentifier;
3098 //case catch class clone const continue
3101 if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e'))
3102 return TokenNamecase;
3104 return TokenNameIdentifier;
3106 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3107 return TokenNamecatch;
3109 if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's'))
3110 return TokenNameclass;
3112 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 'e'))
3113 return TokenNameclone;
3115 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't'))
3116 return TokenNameconst;
3118 return TokenNameIdentifier;
3120 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'i')
3121 && (data[++index] == 'n') && (data[++index] == 'u') && (data[++index] == 'e'))
3122 return TokenNamecontinue;
3124 return TokenNameIdentifier;
3126 return TokenNameIdentifier;
3129 // declare default do die
3130 // TODO delete define ==> no keyword !
3133 if ((data[++index] == 'o'))
3136 return TokenNameIdentifier;
3138 // if ((data[++index] == 'e')
3139 // && (data[++index] == 'f')
3140 // && (data[++index] == 'i')
3141 // && (data[++index] == 'n')
3142 // && (data[++index] == 'e'))
3143 // return TokenNamedefine;
3145 // return TokenNameIdentifier;
3147 if ((data[++index] == 'e') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3148 && (data[++index] == 'r') && (data[++index] == 'e'))
3149 return TokenNamedeclare;
3151 if ((data[++index] == 'e') && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'u')
3152 && (data[++index] == 'l') && (data[++index] == 't'))
3153 return TokenNamedefault;
3155 return TokenNameIdentifier;
3157 return TokenNameIdentifier;
3160 //echo else exit elseif extends eval
3163 if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o'))
3164 return TokenNameecho;
3165 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e'))
3166 return TokenNameelse;
3167 else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't'))
3168 return TokenNameexit;
3169 else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l'))
3170 return TokenNameeval;
3172 return TokenNameIdentifier;
3175 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f'))
3176 return TokenNameendif;
3177 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 't') && (data[++index] == 'y'))
3178 return TokenNameempty;
3180 return TokenNameIdentifier;
3183 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o')
3184 && (data[++index] == 'r'))
3185 return TokenNameendfor;
3186 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 'i')
3187 && (data[++index] == 'f'))
3188 return TokenNameelseif;
3190 return TokenNameIdentifier;
3192 if ((data[++index] == 'x') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'n')
3193 && (data[++index] == 'd') && (data[++index] == 's'))
3194 return TokenNameextends;
3196 return TokenNameIdentifier;
3199 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'w') && (data[++index] == 'h')
3200 && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3201 return TokenNameendwhile;
3203 return TokenNameIdentifier;
3206 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 's') && (data[++index] == 'w')
3207 && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3208 return TokenNameendswitch;
3210 return TokenNameIdentifier;
3213 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'd') && (data[++index] == 'e')
3214 && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 'r')
3215 && (data[++index] == 'e'))
3216 return TokenNameenddeclare;
3218 if ((data[++index] == 'n') // endforeach
3219 && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r')
3220 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'h'))
3221 return TokenNameendforeach;
3223 return TokenNameIdentifier;
3225 return TokenNameIdentifier;
3228 //for false final function
3231 if ((data[++index] == 'o') && (data[++index] == 'r'))
3232 return TokenNamefor;
3234 return TokenNameIdentifier;
3236 // if ((data[++index] == 'a') && (data[++index] == 'l')
3237 // && (data[++index] == 's') && (data[++index] == 'e'))
3238 // return TokenNamefalse;
3239 if ((data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 'a') && (data[++index] == 'l'))
3240 return TokenNamefinal;
3242 return TokenNameIdentifier;
3245 if ((data[++index] == 'o') && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a')
3246 && (data[++index] == 'c') && (data[++index] == 'h'))
3247 return TokenNameforeach;
3249 return TokenNameIdentifier;
3252 if ((data[++index] == 'u') && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 't')
3253 && (data[++index] == 'i') && (data[++index] == 'o') && (data[++index] == 'n'))
3254 return TokenNamefunction;
3256 return TokenNameIdentifier;
3258 return TokenNameIdentifier;
3263 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'b') && (data[++index] == 'a')
3264 && (data[++index] == 'l')) {
3265 return TokenNameglobal;
3268 return TokenNameIdentifier;
3270 //if int isset include include_once instanceof interface implements
3273 if (data[++index] == 'f')
3276 return TokenNameIdentifier;
3278 // if ((data[++index] == 'n') && (data[++index] == 't'))
3279 // return TokenNameint;
3281 // return TokenNameIdentifier;
3283 if ((data[++index] == 's') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3284 return TokenNameisset;
3286 return TokenNameIdentifier;
3288 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3289 && (data[++index] == 'd') && (data[++index] == 'e'))
3290 return TokenNameinclude;
3292 return TokenNameIdentifier;
3295 if ((data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'r')
3296 && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'e'))
3297 return TokenNameinterface;
3299 return TokenNameIdentifier;
3302 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'a')
3303 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e') && (data[++index] == 'o')
3304 && (data[++index] == 'f'))
3305 return TokenNameinstanceof;
3306 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 'l') && (data[++index] == 'e')
3307 && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 'n') && (data[++index] == 't')
3308 && (data[++index] == 's'))
3309 return TokenNameimplements;
3311 return TokenNameIdentifier;
3313 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3314 && (data[++index] == 'd') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3315 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e'))
3316 return TokenNameinclude_once;
3318 return TokenNameIdentifier;
3320 return TokenNameIdentifier;
3325 if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) {
3326 return TokenNamelist;
3329 return TokenNameIdentifier;
3334 if ((data[++index] == 'e') && (data[++index] == 'w'))
3335 return TokenNamenew;
3337 return TokenNameIdentifier;
3339 // if ((data[++index] == 'u') && (data[++index] == 'l')
3340 // && (data[++index] == 'l'))
3341 // return TokenNamenull;
3343 // return TokenNameIdentifier;
3345 return TokenNameIdentifier;
3350 if (data[++index] == 'r') {
3354 // if (length == 12) {
3355 // if ((data[++index] == 'l')
3356 // && (data[++index] == 'd')
3357 // && (data[++index] == '_')
3358 // && (data[++index] == 'f')
3359 // && (data[++index] == 'u')
3360 // && (data[++index] == 'n')
3361 // && (data[++index] == 'c')
3362 // && (data[++index] == 't')
3363 // && (data[++index] == 'i')
3364 // && (data[++index] == 'o')
3365 // && (data[++index] == 'n')) {
3366 // return TokenNameold_function;
3369 return TokenNameIdentifier;
3371 // print public private protected
3374 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
3375 return TokenNameprint;
3377 return TokenNameIdentifier;
3379 if ((data[++index] == 'u') && (data[++index] == 'b') && (data[++index] == 'l') && (data[++index] == 'i')
3380 && (data[++index] == 'c')) {
3381 return TokenNamepublic;
3383 return TokenNameIdentifier;
3385 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'v') && (data[++index] == 'a')
3386 && (data[++index] == 't') && (data[++index] == 'e')) {
3387 return TokenNameprivate;
3389 return TokenNameIdentifier;
3391 if ((data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 't') && (data[++index] == 'e')
3392 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'd')) {
3393 return TokenNameprotected;
3395 return TokenNameIdentifier;
3397 return TokenNameIdentifier;
3399 //return require require_once
3401 if ((data[++index] == 'e') && (data[++index] == 't') && (data[++index] == 'u') && (data[++index] == 'r')
3402 && (data[++index] == 'n')) {
3403 return TokenNamereturn;
3405 } else if (length == 7) {
3406 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3407 && (data[++index] == 'r') && (data[++index] == 'e')) {
3408 return TokenNamerequire;
3410 } else if (length == 12) {
3411 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3412 && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3413 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e')) {
3414 return TokenNamerequire_once;
3417 return TokenNameIdentifier;
3422 if (data[++index] == 't')
3423 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) {
3424 return TokenNamestatic;
3426 return TokenNameIdentifier;
3427 else if ((data[index] == 'w') && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c')
3428 && (data[++index] == 'h'))
3429 return TokenNameswitch;
3431 return TokenNameIdentifier;
3433 return TokenNameIdentifier;
3439 if ((data[++index] == 'r') && (data[++index] == 'y'))
3440 return TokenNametry;
3442 return TokenNameIdentifier;
3444 // if ((data[++index] == 'r') && (data[++index] == 'u')
3445 // && (data[++index] == 'e'))
3446 // return TokenNametrue;
3448 // return TokenNameIdentifier;
3450 if ((data[++index] == 'h') && (data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 'w'))
3451 return TokenNamethrow;
3453 return TokenNameIdentifier;
3455 return TokenNameIdentifier;
3461 if ((data[++index] == 's') && (data[++index] == 'e'))
3462 return TokenNameuse;
3464 return TokenNameIdentifier;
3466 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3467 return TokenNameunset;
3469 return TokenNameIdentifier;
3471 return TokenNameIdentifier;
3477 if ((data[++index] == 'a') && (data[++index] == 'r'))
3478 return TokenNamevar;
3480 return TokenNameIdentifier;
3482 return TokenNameIdentifier;
3488 if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3489 return TokenNamewhile;
3491 return TokenNameIdentifier;
3492 //case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3493 // (data[++index]=='e') && (data[++index]=='f')&&
3494 // (data[++index]=='p'))
3495 //return TokenNamewidefp ;
3497 //return TokenNameIdentifier;
3499 return TokenNameIdentifier;
3505 if ((data[++index] == 'o') && (data[++index] == 'r'))
3506 return TokenNamexor;
3508 return TokenNameIdentifier;
3510 return TokenNameIdentifier;
3513 return TokenNameIdentifier;
3517 public int scanNumber(boolean dotPrefix) throws InvalidInputException {
3518 //when entering this method the currentCharacter is the firt
3519 //digit of the number , i.e. it may be preceeded by a . when
3521 boolean floating = dotPrefix;
3522 if ((!dotPrefix) && (currentCharacter == '0')) {
3523 if (getNextChar('x', 'X') >= 0) { //----------hexa-----------------
3524 //force the first char of the hexa number do exist...
3525 // consume next character
3526 unicodeAsBackSlash = false;
3527 currentCharacter = source[currentPosition++];
3528 // if (((currentCharacter = source[currentPosition++]) == '\\')
3529 // && (source[currentPosition] == 'u')) {
3530 // getNextUnicodeChar();
3532 // if (withoutUnicodePtr != 0) {
3533 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3536 if (Character.digit(currentCharacter, 16) == -1)
3537 throw new InvalidInputException(INVALID_HEXA);
3539 while (getNextCharAsDigit(16)) {
3542 // if (getNextChar('l', 'L') >= 0)
3543 // return TokenNameLongLiteral;
3545 return TokenNameIntegerLiteral;
3547 //there is x or X in the number
3548 //potential octal ! ... some one may write 000099.0 ! thus 00100 <
3549 // 00078.0 is true !!!!! crazy language
3550 if (getNextCharAsDigit()) {
3551 //-------------potential octal-----------------
3552 while (getNextCharAsDigit()) {
3555 // if (getNextChar('l', 'L') >= 0) {
3556 // return TokenNameLongLiteral;
3559 // if (getNextChar('f', 'F') >= 0) {
3560 // return TokenNameFloatingPointLiteral;
3562 if (getNextChar('d', 'D') >= 0) {
3563 return TokenNameDoubleLiteral;
3564 } else { //make the distinction between octal and float ....
3565 if (getNextChar('.')) { //bingo ! ....
3566 while (getNextCharAsDigit()) {
3569 if (getNextChar('e', 'E') >= 0) {
3570 // consume next character
3571 unicodeAsBackSlash = false;
3572 currentCharacter = source[currentPosition++];
3573 // if (((currentCharacter = source[currentPosition++]) == '\\')
3574 // && (source[currentPosition] == 'u')) {
3575 // getNextUnicodeChar();
3577 // if (withoutUnicodePtr != 0) {
3578 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3581 if ((currentCharacter == '-') || (currentCharacter == '+')) {
3582 // consume next character
3583 unicodeAsBackSlash = false;
3584 currentCharacter = source[currentPosition++];
3585 // if (((currentCharacter = source[currentPosition++]) == '\\')
3586 // && (source[currentPosition] == 'u')) {
3587 // getNextUnicodeChar();
3589 // if (withoutUnicodePtr != 0) {
3590 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3591 // currentCharacter;
3595 if (!Character.isDigit(currentCharacter))
3596 throw new InvalidInputException(INVALID_FLOAT);
3597 while (getNextCharAsDigit()) {
3601 // if (getNextChar('f', 'F') >= 0)
3602 // return TokenNameFloatingPointLiteral;
3603 getNextChar('d', 'D'); //jump over potential d or D
3604 return TokenNameDoubleLiteral;
3606 return TokenNameIntegerLiteral;
3613 while (getNextCharAsDigit()) {
3616 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3617 // return TokenNameLongLiteral;
3618 if ((!dotPrefix) && (getNextChar('.'))) { //decimal part that can be empty
3619 while (getNextCharAsDigit()) {
3624 //if floating is true both exponant and suffix may be optional
3625 if (getNextChar('e', 'E') >= 0) {
3627 // consume next character
3628 unicodeAsBackSlash = false;
3629 currentCharacter = source[currentPosition++];
3630 // if (((currentCharacter = source[currentPosition++]) == '\\')
3631 // && (source[currentPosition] == 'u')) {
3632 // getNextUnicodeChar();
3634 // if (withoutUnicodePtr != 0) {
3635 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3638 if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
3641 unicodeAsBackSlash = false;
3642 currentCharacter = source[currentPosition++];
3643 // if (((currentCharacter = source[currentPosition++]) == '\\')
3644 // && (source[currentPosition] == 'u')) {
3645 // getNextUnicodeChar();
3647 // if (withoutUnicodePtr != 0) {
3648 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3652 if (!Character.isDigit(currentCharacter))
3653 throw new InvalidInputException(INVALID_FLOAT);
3654 while (getNextCharAsDigit()) {
3658 if (getNextChar('d', 'D') >= 0)
3659 return TokenNameDoubleLiteral;
3660 // if (getNextChar('f', 'F') >= 0)
3661 // return TokenNameFloatingPointLiteral;
3662 //the long flag has been tested before
3663 return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral;
3667 * Search the line number corresponding to a specific position
3670 public final int getLineNumber(int position) {
3671 if (lineEnds == null)
3673 int length = linePtr + 1;
3676 int g = 0, d = length - 1;
3680 if (position < lineEnds[m]) {
3682 } else if (position > lineEnds[m]) {
3688 if (position < lineEnds[m]) {
3694 public void setPHPMode(boolean mode) {
3698 public final void setSource(char[] source) {
3699 setSource(null, source);
3702 public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3703 //the source-buffer is set to sourceString
3704 this.compilationUnit = compilationUnit;
3705 if (source == null) {
3706 this.source = new char[0];
3708 this.source = source;
3711 initialPosition = currentPosition = 0;
3712 containsAssertKeyword = false;
3713 withoutUnicodeBuffer = new char[this.source.length];
3714 // encapsedStringStack = new Stack();
3717 public String toString() {
3718 if (startPosition == source.length)
3719 return "EOF\n\n" + new String(source); //$NON-NLS-1$
3720 if (currentPosition > source.length)
3721 return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3722 char front[] = new char[startPosition];
3723 System.arraycopy(source, 0, front, 0, startPosition);
3724 int middleLength = (currentPosition - 1) - startPosition + 1;
3726 if (middleLength > -1) {
3727 middle = new char[middleLength];
3728 System.arraycopy(source, startPosition, middle, 0, middleLength);
3730 middle = new char[0];
3732 char end[] = new char[source.length - (currentPosition - 1)];
3733 System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - (currentPosition - 1) - 1);
3734 return new String(front) + "\n===============================\nStarts here -->" //$NON-NLS-1$
3735 + new String(middle) + "<-- Ends here\n===============================\n" //$NON-NLS-1$
3739 public final String toStringAction(int act) {
3741 case TokenNameERROR:
3742 return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
3744 case TokenNameINLINE_HTML:
3745 return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3746 case TokenNameIdentifier:
3747 return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3748 case TokenNameVariable:
3749 return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3750 case TokenNameabstract:
3751 return "abstract"; //$NON-NLS-1$
3753 return "AND"; //$NON-NLS-1$
3754 case TokenNamearray:
3755 return "array"; //$NON-NLS-1$
3757 return "as"; //$NON-NLS-1$
3758 case TokenNamebreak:
3759 return "break"; //$NON-NLS-1$
3761 return "case"; //$NON-NLS-1$
3762 case TokenNameclass:
3763 return "class"; //$NON-NLS-1$
3764 case TokenNamecatch:
3765 return "catch"; //$NON-NLS-1$
3766 case TokenNameclone:
3769 case TokenNameconst:
3772 case TokenNamecontinue:
3773 return "continue"; //$NON-NLS-1$
3774 case TokenNamedefault:
3775 return "default"; //$NON-NLS-1$
3776 // case TokenNamedefine :
3777 // return "define"; //$NON-NLS-1$
3779 return "do"; //$NON-NLS-1$
3781 return "echo"; //$NON-NLS-1$
3783 return "else"; //$NON-NLS-1$
3784 case TokenNameelseif:
3785 return "elseif"; //$NON-NLS-1$
3786 case TokenNameendfor:
3787 return "endfor"; //$NON-NLS-1$
3788 case TokenNameendforeach:
3789 return "endforeach"; //$NON-NLS-1$
3790 case TokenNameendif:
3791 return "endif"; //$NON-NLS-1$
3792 case TokenNameendswitch:
3793 return "endswitch"; //$NON-NLS-1$
3794 case TokenNameendwhile:
3795 return "endwhile"; //$NON-NLS-1$
3798 case TokenNameextends:
3799 return "extends"; //$NON-NLS-1$
3800 // case TokenNamefalse :
3801 // return "false"; //$NON-NLS-1$
3802 case TokenNamefinal:
3803 return "final"; //$NON-NLS-1$
3805 return "for"; //$NON-NLS-1$
3806 case TokenNameforeach:
3807 return "foreach"; //$NON-NLS-1$
3808 case TokenNamefunction:
3809 return "function"; //$NON-NLS-1$
3810 case TokenNameglobal:
3811 return "global"; //$NON-NLS-1$
3813 return "if"; //$NON-NLS-1$
3814 case TokenNameimplements:
3815 return "implements"; //$NON-NLS-1$
3816 case TokenNameinclude:
3817 return "include"; //$NON-NLS-1$
3818 case TokenNameinclude_once:
3819 return "include_once"; //$NON-NLS-1$
3820 case TokenNameinstanceof:
3821 return "instanceof"; //$NON-NLS-1$
3822 case TokenNameinterface:
3823 return "interface"; //$NON-NLS-1$
3824 case TokenNameisset:
3825 return "isset"; //$NON-NLS-1$
3827 return "list"; //$NON-NLS-1$
3829 return "new"; //$NON-NLS-1$
3830 // case TokenNamenull :
3831 // return "null"; //$NON-NLS-1$
3833 return "OR"; //$NON-NLS-1$
3834 case TokenNameprint:
3835 return "print"; //$NON-NLS-1$
3836 case TokenNameprivate:
3837 return "private"; //$NON-NLS-1$
3838 case TokenNameprotected:
3839 return "protected"; //$NON-NLS-1$
3840 case TokenNamepublic:
3841 return "public"; //$NON-NLS-1$
3842 case TokenNamerequire:
3843 return "require"; //$NON-NLS-1$
3844 case TokenNamerequire_once:
3845 return "require_once"; //$NON-NLS-1$
3846 case TokenNamereturn:
3847 return "return"; //$NON-NLS-1$
3848 case TokenNamestatic:
3849 return "static"; //$NON-NLS-1$
3850 case TokenNameswitch:
3851 return "switch"; //$NON-NLS-1$
3852 // case TokenNametrue :
3853 // return "true"; //$NON-NLS-1$
3854 case TokenNameunset:
3855 return "unset"; //$NON-NLS-1$
3857 return "var"; //$NON-NLS-1$
3858 case TokenNamewhile:
3859 return "while"; //$NON-NLS-1$
3861 return "XOR"; //$NON-NLS-1$
3862 // case TokenNamethis :
3863 // return "$this"; //$NON-NLS-1$
3864 case TokenNameIntegerLiteral:
3865 return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3866 case TokenNameDoubleLiteral:
3867 return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3868 case TokenNameStringDoubleQuote:
3869 return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3870 case TokenNameStringSingleQuote:
3871 return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3872 case TokenNameStringInterpolated:
3873 return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3874 case TokenNameEncapsedString0:
3875 return "`"; //$NON-NLS-1$
3876 // case TokenNameEncapsedString1:
3877 // return "\'"; //$NON-NLS-1$
3878 // case TokenNameEncapsedString2:
3879 // return "\""; //$NON-NLS-1$
3880 case TokenNameSTRING:
3881 return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3882 case TokenNameHEREDOC:
3883 return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3884 case TokenNamePLUS_PLUS:
3885 return "++"; //$NON-NLS-1$
3886 case TokenNameMINUS_MINUS:
3887 return "--"; //$NON-NLS-1$
3888 case TokenNameEQUAL_EQUAL:
3889 return "=="; //$NON-NLS-1$
3890 case TokenNameEQUAL_EQUAL_EQUAL:
3891 return "==="; //$NON-NLS-1$
3892 case TokenNameEQUAL_GREATER:
3893 return "=>"; //$NON-NLS-1$
3894 case TokenNameLESS_EQUAL:
3895 return "<="; //$NON-NLS-1$
3896 case TokenNameGREATER_EQUAL:
3897 return ">="; //$NON-NLS-1$
3898 case TokenNameNOT_EQUAL:
3899 return "!="; //$NON-NLS-1$
3900 case TokenNameNOT_EQUAL_EQUAL:
3901 return "!=="; //$NON-NLS-1$
3902 case TokenNameLEFT_SHIFT:
3903 return "<<"; //$NON-NLS-1$
3904 case TokenNameRIGHT_SHIFT:
3905 return ">>"; //$NON-NLS-1$
3906 case TokenNamePLUS_EQUAL:
3907 return "+="; //$NON-NLS-1$
3908 case TokenNameMINUS_EQUAL:
3909 return "-="; //$NON-NLS-1$
3910 case TokenNameMULTIPLY_EQUAL:
3911 return "*="; //$NON-NLS-1$
3912 case TokenNameDIVIDE_EQUAL:
3913 return "/="; //$NON-NLS-1$
3914 case TokenNameAND_EQUAL:
3915 return "&="; //$NON-NLS-1$
3916 case TokenNameOR_EQUAL:
3917 return "|="; //$NON-NLS-1$
3918 case TokenNameXOR_EQUAL:
3919 return "^="; //$NON-NLS-1$
3920 case TokenNameREMAINDER_EQUAL:
3921 return "%="; //$NON-NLS-1$
3922 case TokenNameDOT_EQUAL:
3923 return ".="; //$NON-NLS-1$
3924 case TokenNameLEFT_SHIFT_EQUAL:
3925 return "<<="; //$NON-NLS-1$
3926 case TokenNameRIGHT_SHIFT_EQUAL:
3927 return ">>="; //$NON-NLS-1$
3928 case TokenNameOR_OR:
3929 return "||"; //$NON-NLS-1$
3930 case TokenNameAND_AND:
3931 return "&&"; //$NON-NLS-1$
3933 return "+"; //$NON-NLS-1$
3934 case TokenNameMINUS:
3935 return "-"; //$NON-NLS-1$
3936 case TokenNameMINUS_GREATER:
3939 return "!"; //$NON-NLS-1$
3940 case TokenNameREMAINDER:
3941 return "%"; //$NON-NLS-1$
3943 return "^"; //$NON-NLS-1$
3945 return "&"; //$NON-NLS-1$
3946 case TokenNameMULTIPLY:
3947 return "*"; //$NON-NLS-1$
3949 return "|"; //$NON-NLS-1$
3950 case TokenNameTWIDDLE:
3951 return "~"; //$NON-NLS-1$
3952 case TokenNameTWIDDLE_EQUAL:
3953 return "~="; //$NON-NLS-1$
3954 case TokenNameDIVIDE:
3955 return "/"; //$NON-NLS-1$
3956 case TokenNameGREATER:
3957 return ">"; //$NON-NLS-1$
3959 return "<"; //$NON-NLS-1$
3960 case TokenNameLPAREN:
3961 return "("; //$NON-NLS-1$
3962 case TokenNameRPAREN:
3963 return ")"; //$NON-NLS-1$
3964 case TokenNameLBRACE:
3965 return "{"; //$NON-NLS-1$
3966 case TokenNameRBRACE:
3967 return "}"; //$NON-NLS-1$
3968 case TokenNameLBRACKET:
3969 return "["; //$NON-NLS-1$
3970 case TokenNameRBRACKET:
3971 return "]"; //$NON-NLS-1$
3972 case TokenNameSEMICOLON:
3973 return ";"; //$NON-NLS-1$
3974 case TokenNameQUESTION:
3975 return "?"; //$NON-NLS-1$
3976 case TokenNameCOLON:
3977 return ":"; //$NON-NLS-1$
3978 case TokenNameCOMMA:
3979 return ","; //$NON-NLS-1$
3981 return "."; //$NON-NLS-1$
3982 case TokenNameEQUAL:
3983 return "="; //$NON-NLS-1$
3986 case TokenNameDOLLAR:
3988 case TokenNameDOLLAR_LBRACE:
3990 case TokenNameLBRACE_DOLLAR:
3993 return "EOF"; //$NON-NLS-1$
3994 case TokenNameWHITESPACE:
3995 return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3996 case TokenNameCOMMENT_LINE:
3997 return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3998 case TokenNameCOMMENT_BLOCK:
3999 return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4000 case TokenNameCOMMENT_PHPDOC:
4001 return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4002 // case TokenNameHTML :
4003 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
4006 return "__FILE__"; //$NON-NLS-1$
4008 return "__LINE__"; //$NON-NLS-1$
4009 case TokenNameCLASS_C:
4010 return "__CLASS__"; //$NON-NLS-1$
4011 case TokenNameMETHOD_C:
4012 return "__METHOD__"; //$NON-NLS-1$
4013 case TokenNameFUNC_C:
4014 return "__FUNCTION__"; //$NON-NLS-1
4015 case TokenNameboolCAST:
4016 return "( bool )"; //$NON-NLS-1$
4017 case TokenNameintCAST:
4018 return "( int )"; //$NON-NLS-1$
4019 case TokenNamedoubleCAST:
4020 return "( double )"; //$NON-NLS-1$
4021 case TokenNameobjectCAST:
4022 return "( object )"; //$NON-NLS-1$
4023 case TokenNamestringCAST:
4024 return "( string )"; //$NON-NLS-1$
4026 return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
4034 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
4035 this(tokenizeComments, tokenizeWhiteSpace, false);
4038 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals) {
4039 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, false);
4042 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4043 boolean assertMode) {
4044 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, assertMode, false, null, null, true);
4047 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4048 boolean assertMode, boolean tokenizeStrings, char[][] taskTags, char[][] taskPriorities, boolean isTaskCaseSensitive) {
4049 this.eofPosition = Integer.MAX_VALUE;
4050 this.tokenizeComments = tokenizeComments;
4051 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4052 this.tokenizeStrings = tokenizeStrings;
4053 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4054 this.assertMode = assertMode;
4055 // this.encapsedStringStack = null;
4056 this.taskTags = taskTags;
4057 this.taskPriorities = taskPriorities;
4060 private void checkNonExternalizeString() throws InvalidInputException {
4061 if (currentLine == null)
4063 parseTags(currentLine);
4066 private void parseTags(NLSLine line) throws InvalidInputException {
4067 String s = new String(getCurrentTokenSource());
4068 int pos = s.indexOf(TAG_PREFIX);
4069 int lineLength = line.size();
4071 int start = pos + TAG_PREFIX_LENGTH;
4072 int end = s.indexOf(TAG_POSTFIX, start);
4073 String index = s.substring(start, end);
4076 i = Integer.parseInt(index) - 1;
4077 // Tags are one based not zero based.
4078 } catch (NumberFormatException e) {
4079 i = -1; // we don't want to consider this as a valid NLS tag
4081 if (line.exists(i)) {
4084 pos = s.indexOf(TAG_PREFIX, start);
4086 this.nonNLSStrings = new StringLiteral[lineLength];
4087 int nonNLSCounter = 0;
4088 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4089 StringLiteral literal = (StringLiteral) iterator.next();
4090 if (literal != null) {
4091 this.nonNLSStrings[nonNLSCounter++] = literal;
4094 if (nonNLSCounter == 0) {
4095 this.nonNLSStrings = null;
4099 this.wasNonExternalizedStringLiteral = true;
4100 if (nonNLSCounter != lineLength) {
4101 System.arraycopy(this.nonNLSStrings, 0, (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, nonNLSCounter);
4106 public final void scanEscapeCharacter() throws InvalidInputException {
4107 // the string with "\\u" is a legal string of two chars \ and u
4108 //thus we use a direct access to the source (for regular cases).
4109 if (unicodeAsBackSlash) {
4110 // consume next character
4111 unicodeAsBackSlash = false;
4112 // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4113 // (source[currentPosition] == 'u')) {
4114 // getNextUnicodeChar();
4116 if (withoutUnicodePtr != 0) {
4117 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4121 currentCharacter = source[currentPosition++];
4122 switch (currentCharacter) {
4124 currentCharacter = '\b';
4127 currentCharacter = '\t';
4130 currentCharacter = '\n';
4133 currentCharacter = '\f';
4136 currentCharacter = '\r';
4139 currentCharacter = '\"';
4142 currentCharacter = '\'';
4145 currentCharacter = '\\';
4148 // -----------octal escape--------------
4150 // OctalDigit OctalDigit
4151 // ZeroToThree OctalDigit OctalDigit
4152 int number = Character.getNumericValue(currentCharacter);
4153 if (number >= 0 && number <= 7) {
4154 boolean zeroToThreeNot = number > 3;
4155 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4156 int digit = Character.getNumericValue(currentCharacter);
4157 if (digit >= 0 && digit <= 7) {
4158 number = (number * 8) + digit;
4159 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4160 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
4161 // Digit --> ignore last character
4164 digit = Character.getNumericValue(currentCharacter);
4165 if (digit >= 0 && digit <= 7) { // has read \ZeroToThree
4166 // OctalDigit OctalDigit
4167 number = (number * 8) + digit;
4168 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
4169 // --> ignore last character
4173 } else { // has read \OctalDigit NonDigit--> ignore last
4177 } else { // has read \OctalDigit NonOctalDigit--> ignore last
4181 } else { // has read \OctalDigit --> ignore last character
4185 throw new InvalidInputException(INVALID_ESCAPE);
4186 currentCharacter = (char) number;
4188 throw new InvalidInputException(INVALID_ESCAPE);
4192 //chech presence of task: tags
4193 //TODO (frederic) see if we need to take unicode characters into account...
4194 public void checkTaskTag(int commentStart, int commentEnd) {
4195 char[] src = this.source;
4197 // only look for newer task: tags
4198 if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4201 int foundTaskIndex = this.foundTaskCount;
4202 char previous = src[commentStart + 1]; // should be '*' or '/'
4203 nextChar: for (int i = commentStart + 2; i < commentEnd && i < this.eofPosition; i++) {
4205 char[] priority = null;
4206 // check for tag occurrence only if not ambiguous with javadoc tag
4207 if (previous != '@') {
4208 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4209 tag = this.taskTags[itag];
4210 int tagLength = tag.length;
4214 // ensure tag is not leaded with letter if tag starts with a letter
4215 if (Scanner.isPHPIdentifierStart(tag[0])) {
4216 if (Scanner.isPHPIdentifierPart(previous)) {
4221 for (int t = 0; t < tagLength; t++) {
4224 if (x >= this.eofPosition || x >= commentEnd)
4226 if ((sc = src[i + t]) != (tc = tag[t])) { // case sensitive check
4227 if (this.isTaskCaseSensitive || (Character.toLowerCase(sc) != Character.toLowerCase(tc))) { // case insensitive check
4232 // ensure tag is not followed with letter if tag finishes with a letter
4233 if (i + tagLength < commentEnd && Scanner.isPHPIdentifierPart(src[i + tagLength - 1])) {
4234 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4237 if (this.foundTaskTags == null) {
4238 this.foundTaskTags = new char[5][];
4239 this.foundTaskMessages = new char[5][];
4240 this.foundTaskPriorities = new char[5][];
4241 this.foundTaskPositions = new int[5][];
4242 } else if (this.foundTaskCount == this.foundTaskTags.length) {
4243 System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0,
4244 this.foundTaskCount);
4245 System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4246 this.foundTaskCount);
4247 System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4248 this.foundTaskCount);
4249 System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4250 this.foundTaskCount);
4253 priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4255 this.foundTaskTags[this.foundTaskCount] = tag;
4256 this.foundTaskPriorities[this.foundTaskCount] = priority;
4257 this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4258 this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4259 this.foundTaskCount++;
4260 i += tagLength - 1; // will be incremented when looping
4266 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4267 // retrieve message start and end positions
4268 int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4269 int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4270 // at most beginning of next task
4271 if (max_value < msgStart) {
4272 max_value = msgStart; // would only occur if tag is before EOF.
4276 for (int j = msgStart; j < max_value; j++) {
4277 if ((c = src[j]) == '\n' || c == '\r') {
4283 for (int j = max_value; j > msgStart; j--) {
4284 if ((c = src[j]) == '*') {
4292 if (msgStart == end)
4295 while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4297 while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4299 // update the end position of the task
4300 this.foundTaskPositions[i][1] = end;
4301 // get the message source
4302 final int messageLength = end - msgStart + 1;
4303 char[] message = new char[messageLength];
4304 System.arraycopy(src, msgStart, message, 0, messageLength);
4305 this.foundTaskMessages[i] = message;
4309 // chech presence of task: tags
4310 // public void checkTaskTag(int commentStart, int commentEnd) {
4311 // // only look for newer task: tags
4312 // if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4315 // int foundTaskIndex = this.foundTaskCount;
4316 // nextChar: for (int i = commentStart; i < commentEnd && i < this.eofPosition; i++) {
4317 // char[] tag = null;
4318 // char[] priority = null;
4319 // // check for tag occurrence
4320 // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4321 // tag = this.taskTags[itag];
4322 // priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4323 // int tagLength = tag.length;
4324 // for (int t = 0; t < tagLength; t++) {
4325 // if (this.source[i + t] != tag[t])
4326 // continue nextTag;
4328 // if (this.foundTaskTags == null) {
4329 // this.foundTaskTags = new char[5][];
4330 // this.foundTaskMessages = new char[5][];
4331 // this.foundTaskPriorities = new char[5][];
4332 // this.foundTaskPositions = new int[5][];
4333 // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4334 // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4335 // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4336 // this.foundTaskCount);
4337 // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4338 // this.foundTaskCount);
4339 // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4340 // this.foundTaskCount);
4342 // this.foundTaskTags[this.foundTaskCount] = tag;
4343 // this.foundTaskPriorities[this.foundTaskCount] = priority;
4344 // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4345 // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4346 // this.foundTaskCount++;
4347 // i += tagLength - 1; // will be incremented when looping
4350 // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4351 // // retrieve message start and end positions
4352 // int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4353 // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4354 // // at most beginning of next task
4355 // if (max_value < msgStart)
4356 // max_value = msgStart; // would only occur if tag is before EOF.
4359 // for (int j = msgStart; j < max_value; j++) {
4360 // if ((c = this.source[j]) == '\n' || c == '\r') {
4366 // for (int j = max_value; j > msgStart; j--) {
4367 // if ((c = this.source[j]) == '*') {
4375 // if (msgStart == end)
4376 // continue; // empty
4377 // // trim the message
4378 // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4380 // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4382 // // update the end position of the task
4383 // this.foundTaskPositions[i][1] = end;
4384 // // get the message source
4385 // final int messageLength = end - msgStart + 1;
4386 // char[] message = new char[messageLength];
4387 // System.arraycopy(source, msgStart, message, 0, messageLength);
4388 // this.foundTaskMessages[i] = message;