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 // ?> breaks line comments
1616 startPosition = currentPosition - 2;
1618 return TokenNameINLINE_HTML;
1623 currentCharacter = source[currentPosition++];
1624 // if (((currentCharacter = source[currentPosition++])
1626 // && (source[currentPosition] == 'u')) {
1627 // isUnicode = true;
1628 // //-------------unicode traitement ------------
1629 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1630 // currentPosition++;
1631 // while (source[currentPosition] == 'u') {
1632 // currentPosition++;
1635 // Character.getNumericValue(source[currentPosition++]))
1639 // Character.getNumericValue(
1640 // source[currentPosition++]))
1644 // Character.getNumericValue(
1645 // source[currentPosition++]))
1649 // Character.getNumericValue(
1650 // source[currentPosition++]))
1654 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1656 // currentCharacter =
1657 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1660 //handle the \\u case manually into comment
1661 // if (currentCharacter == '\\') {
1662 // if (source[currentPosition] == '\\')
1663 // currentPosition++;
1664 // } //jump over the \\
1667 endPositionForLineComment = currentPosition - 6;
1669 endPositionForLineComment = currentPosition - 1;
1671 // recordComment(false);
1672 recordComment(TokenNameCOMMENT_LINE);
1673 if (this.taskTags != null)
1674 checkTaskTag(this.startPosition, this.currentPosition);
1675 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1676 checkNonExternalizeString();
1677 if (recordLineSeparator) {
1679 pushUnicodeLineSeparator();
1681 pushLineSeparator();
1687 if (tokenizeComments) {
1689 currentPosition = endPositionForLineComment;
1690 // reset one character behind
1692 return TokenNameCOMMENT_LINE;
1694 } catch (IndexOutOfBoundsException e) { //an eof will them
1696 if (tokenizeComments) {
1698 // reset one character behind
1699 return TokenNameCOMMENT_LINE;
1705 //traditional and annotation comment
1706 boolean isJavadoc = false, star = false;
1707 // consume next character
1708 unicodeAsBackSlash = false;
1709 currentCharacter = source[currentPosition++];
1710 // if (((currentCharacter = source[currentPosition++]) ==
1712 // && (source[currentPosition] == 'u')) {
1713 // getNextUnicodeChar();
1715 // if (withoutUnicodePtr != 0) {
1716 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1717 // currentCharacter;
1720 if (currentCharacter == '*') {
1724 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1725 checkNonExternalizeString();
1726 if (recordLineSeparator) {
1727 pushLineSeparator();
1732 try { //get the next char
1733 currentCharacter = source[currentPosition++];
1734 // if (((currentCharacter = source[currentPosition++])
1736 // && (source[currentPosition] == 'u')) {
1737 // //-------------unicode traitement ------------
1738 // getNextUnicodeChar();
1740 //handle the \\u case manually into comment
1741 // if (currentCharacter == '\\') {
1742 // if (source[currentPosition] == '\\')
1743 // currentPosition++;
1744 // //jump over the \\
1746 // empty comment is not a javadoc /**/
1747 if (currentCharacter == '/') {
1750 //loop until end of comment */
1751 while ((currentCharacter != '/') || (!star)) {
1752 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1753 checkNonExternalizeString();
1754 if (recordLineSeparator) {
1755 pushLineSeparator();
1760 star = currentCharacter == '*';
1762 currentCharacter = source[currentPosition++];
1763 // if (((currentCharacter = source[currentPosition++])
1765 // && (source[currentPosition] == 'u')) {
1766 // //-------------unicode traitement ------------
1767 // getNextUnicodeChar();
1769 //handle the \\u case manually into comment
1770 // if (currentCharacter == '\\') {
1771 // if (source[currentPosition] == '\\')
1772 // currentPosition++;
1773 // } //jump over the \\
1775 //recordComment(isJavadoc);
1777 recordComment(TokenNameCOMMENT_PHPDOC);
1779 recordComment(TokenNameCOMMENT_BLOCK);
1782 if (tokenizeComments) {
1784 return TokenNameCOMMENT_PHPDOC;
1785 return TokenNameCOMMENT_BLOCK;
1788 if (this.taskTags != null) {
1789 checkTaskTag(this.startPosition, this.currentPosition);
1791 } catch (IndexOutOfBoundsException e) {
1792 // reset end position for error reporting
1793 currentPosition -= 2;
1794 throw new InvalidInputException(UNTERMINATED_COMMENT);
1798 return TokenNameDIVIDE;
1802 return TokenNameEOF;
1803 //the atEnd may not be <currentPosition == source.length> if
1804 // source is only some part of a real (external) stream
1805 throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$
1807 if (currentCharacter == '$') {
1808 int oldPosition = currentPosition;
1810 currentCharacter = source[currentPosition++];
1811 if (isPHPIdentifierStart(currentCharacter)) {
1812 return scanIdentifierOrKeyword(true);
1814 currentPosition = oldPosition;
1815 return TokenNameDOLLAR;
1817 } catch (IndexOutOfBoundsException e) {
1818 currentPosition = oldPosition;
1819 return TokenNameDOLLAR;
1822 if (isPHPIdentifierStart(currentCharacter))
1823 return scanIdentifierOrKeyword(false);
1824 if (Character.isDigit(currentCharacter))
1825 return scanNumber(false);
1826 return TokenNameERROR;
1829 } //-----------------end switch while try--------------------
1830 catch (IndexOutOfBoundsException e) {
1833 return TokenNameEOF;
1838 * @throws InvalidInputException
1840 private int getInlinedHTMLToken(int start) throws InvalidInputException {
1841 if (currentPosition > source.length) {
1842 currentPosition = source.length;
1843 return TokenNameEOF;
1845 startPosition = start;
1848 currentCharacter = source[currentPosition++];
1849 if (currentCharacter == '<') {
1850 if (getNextChar('?')) {
1851 currentCharacter = source[currentPosition++];
1852 if ((currentCharacter != 'P') && (currentCharacter != 'p')) {
1853 if (currentCharacter != '=') { // <?=
1856 phpExpressionTag = true;
1859 if (ignorePHPOneLiner) { // for CodeFormatter
1860 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1862 return TokenNameINLINE_HTML;
1866 return TokenNameINLINE_HTML;
1869 // boolean phpStart = (currentCharacter == 'P') || (currentCharacter == 'p');
1871 int test = getNextChar('H', 'h');
1873 test = getNextChar('P', 'p');
1876 if (ignorePHPOneLiner) {
1877 if (lookAheadLinePHPTag() == TokenNameINLINE_HTML) {
1879 return TokenNameINLINE_HTML;
1883 return TokenNameINLINE_HTML;
1891 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1892 if (recordLineSeparator) {
1893 pushLineSeparator();
1898 } //-----------------while--------------------
1900 return TokenNameINLINE_HTML;
1901 } //-----------------try--------------------
1902 catch (IndexOutOfBoundsException e) {
1903 startPosition = start;
1907 return TokenNameINLINE_HTML;
1913 private int lookAheadLinePHPTag() {
1914 // check if the PHP is only in this line (for CodeFormatter)
1915 int currentPositionInLine = currentPosition;
1916 char previousCharInLine = ' ';
1917 char currentCharInLine = ' ';
1918 boolean singleQuotedStringActive = false;
1919 boolean doubleQuotedStringActive = false;
1922 // look ahead in this line
1924 previousCharInLine = currentCharInLine;
1925 currentCharInLine = source[currentPositionInLine++];
1926 switch (currentCharInLine) {
1928 if (previousCharInLine == '?') {
1929 // update the scanner's current Position in the source
1930 currentPosition = currentPositionInLine;
1931 // use as "dummy" token
1932 return TokenNameEOF;
1936 if (doubleQuotedStringActive) {
1937 // ignore escaped characters in double quoted strings
1938 previousCharInLine = currentCharInLine;
1939 currentCharInLine = source[currentPositionInLine++];
1942 if (doubleQuotedStringActive) {
1943 doubleQuotedStringActive = false;
1945 if (!singleQuotedStringActive) {
1946 doubleQuotedStringActive = true;
1951 if (singleQuotedStringActive) {
1952 if (previousCharInLine != '\\') {
1953 singleQuotedStringActive = false;
1956 if (!doubleQuotedStringActive) {
1957 singleQuotedStringActive = true;
1963 return TokenNameINLINE_HTML;
1965 if (!singleQuotedStringActive && !doubleQuotedStringActive) {
1967 return TokenNameINLINE_HTML;
1971 if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1973 return TokenNameINLINE_HTML;
1977 if (previousCharInLine == '/' && !singleQuotedStringActive && !doubleQuotedStringActive) {
1979 return TokenNameINLINE_HTML;
1984 } catch (IndexOutOfBoundsException e) {
1986 currentPosition = currentPositionInLine;
1987 return TokenNameINLINE_HTML;
1991 // public final void getNextUnicodeChar()
1992 // throws IndexOutOfBoundsException, InvalidInputException {
1994 // //handle the case of unicode.
1995 // //when a unicode appears then we must use a buffer that holds char
1997 // //At the end of this method currentCharacter holds the new visited char
1998 // //and currentPosition points right next after it
2000 // //ALL getNextChar.... ARE OPTIMIZED COPIES
2002 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
2003 // currentPosition++;
2004 // while (source[currentPosition] == 'u') {
2005 // currentPosition++;
2009 // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2011 // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
2013 // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
2015 // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
2017 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2019 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2020 // //need the unicode buffer
2021 // if (withoutUnicodePtr == 0) {
2022 // //buffer all the entries that have been left aside....
2023 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
2024 // System.arraycopy(
2027 // withoutUnicodeBuffer,
2029 // withoutUnicodePtr);
2031 // //fill the buffer with the char
2032 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2034 // unicodeAsBackSlash = currentCharacter == '\\';
2037 * Tokenize a method body, assuming that curly brackets are properly balanced.
2039 public final void jumpOverMethodBody() {
2040 this.wasAcr = false;
2043 while (true) { //loop for jumping over comments
2044 // ---------Consume white space and handles startPosition---------
2045 boolean isWhiteSpace;
2047 startPosition = currentPosition;
2048 currentCharacter = source[currentPosition++];
2049 // if (((currentCharacter = source[currentPosition++]) == '\\')
2050 // && (source[currentPosition] == 'u')) {
2051 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
2053 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2054 pushLineSeparator();
2055 isWhiteSpace = Character.isWhitespace(currentCharacter);
2057 } while (isWhiteSpace);
2058 // -------consume token until } is found---------
2059 switch (currentCharacter) {
2070 test = getNextChar('\\');
2073 scanDoubleQuotedEscapeCharacter();
2074 } catch (InvalidInputException ex) {
2078 // try { // consume next character
2079 unicodeAsBackSlash = false;
2080 currentCharacter = source[currentPosition++];
2081 // if (((currentCharacter = source[currentPosition++]) == '\\')
2082 // && (source[currentPosition] == 'u')) {
2083 // getNextUnicodeChar();
2085 if (withoutUnicodePtr != 0) {
2086 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2089 // } catch (InvalidInputException ex) {
2097 // try { // consume next character
2098 unicodeAsBackSlash = false;
2099 currentCharacter = source[currentPosition++];
2100 // if (((currentCharacter = source[currentPosition++]) == '\\')
2101 // && (source[currentPosition] == 'u')) {
2102 // getNextUnicodeChar();
2104 if (withoutUnicodePtr != 0) {
2105 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2108 // } catch (InvalidInputException ex) {
2110 while (currentCharacter != '"') {
2111 if (currentCharacter == '\r') {
2112 if (source[currentPosition] == '\n')
2115 // the string cannot go further that the line
2117 if (currentCharacter == '\n') {
2119 // the string cannot go further that the line
2121 if (currentCharacter == '\\') {
2123 scanDoubleQuotedEscapeCharacter();
2124 } catch (InvalidInputException ex) {
2128 // try { // consume next character
2129 unicodeAsBackSlash = false;
2130 currentCharacter = source[currentPosition++];
2131 // if (((currentCharacter = source[currentPosition++]) == '\\')
2132 // && (source[currentPosition] == 'u')) {
2133 // getNextUnicodeChar();
2135 if (withoutUnicodePtr != 0) {
2136 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2139 // } catch (InvalidInputException ex) {
2142 } catch (IndexOutOfBoundsException e) {
2148 if ((test = getNextChar('/', '*')) == 0) {
2152 currentCharacter = source[currentPosition++];
2153 // if (((currentCharacter = source[currentPosition++]) ==
2155 // && (source[currentPosition] == 'u')) {
2156 // //-------------unicode traitement ------------
2157 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2158 // currentPosition++;
2159 // while (source[currentPosition] == 'u') {
2160 // currentPosition++;
2163 // Character.getNumericValue(source[currentPosition++]))
2167 // Character.getNumericValue(source[currentPosition++]))
2171 // Character.getNumericValue(source[currentPosition++]))
2175 // Character.getNumericValue(source[currentPosition++]))
2178 // //error don't care of the value
2179 // currentCharacter = 'A';
2180 // } //something different from \n and \r
2182 // currentCharacter =
2183 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2186 while (currentCharacter != '\r' && currentCharacter != '\n') {
2188 currentCharacter = source[currentPosition++];
2189 // if (((currentCharacter = source[currentPosition++])
2191 // && (source[currentPosition] == 'u')) {
2192 // //-------------unicode traitement ------------
2193 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2194 // currentPosition++;
2195 // while (source[currentPosition] == 'u') {
2196 // currentPosition++;
2199 // Character.getNumericValue(source[currentPosition++]))
2203 // Character.getNumericValue(source[currentPosition++]))
2207 // Character.getNumericValue(source[currentPosition++]))
2211 // Character.getNumericValue(source[currentPosition++]))
2214 // //error don't care of the value
2215 // currentCharacter = 'A';
2216 // } //something different from \n and \r
2218 // currentCharacter =
2219 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2223 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2224 pushLineSeparator();
2225 } catch (IndexOutOfBoundsException e) {
2226 } //an eof will them be generated
2230 //traditional and annotation comment
2231 boolean star = false;
2232 // try { // consume next character
2233 unicodeAsBackSlash = false;
2234 currentCharacter = source[currentPosition++];
2235 // if (((currentCharacter = source[currentPosition++]) == '\\')
2236 // && (source[currentPosition] == 'u')) {
2237 // getNextUnicodeChar();
2239 if (withoutUnicodePtr != 0) {
2240 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2243 // } catch (InvalidInputException ex) {
2245 if (currentCharacter == '*') {
2248 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2249 pushLineSeparator();
2250 try { //get the next char
2251 currentCharacter = source[currentPosition++];
2252 // if (((currentCharacter = source[currentPosition++]) ==
2254 // && (source[currentPosition] == 'u')) {
2255 // //-------------unicode traitement ------------
2256 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2257 // currentPosition++;
2258 // while (source[currentPosition] == 'u') {
2259 // currentPosition++;
2262 // Character.getNumericValue(source[currentPosition++]))
2266 // Character.getNumericValue(source[currentPosition++]))
2270 // Character.getNumericValue(source[currentPosition++]))
2274 // Character.getNumericValue(source[currentPosition++]))
2277 // //error don't care of the value
2278 // currentCharacter = 'A';
2279 // } //something different from * and /
2281 // currentCharacter =
2282 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2285 //loop until end of comment */
2286 while ((currentCharacter != '/') || (!star)) {
2287 if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2288 pushLineSeparator();
2289 star = currentCharacter == '*';
2291 currentCharacter = source[currentPosition++];
2292 // if (((currentCharacter = source[currentPosition++])
2294 // && (source[currentPosition] == 'u')) {
2295 // //-------------unicode traitement ------------
2296 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2297 // currentPosition++;
2298 // while (source[currentPosition] == 'u') {
2299 // currentPosition++;
2302 // Character.getNumericValue(source[currentPosition++]))
2306 // Character.getNumericValue(source[currentPosition++]))
2310 // Character.getNumericValue(source[currentPosition++]))
2314 // Character.getNumericValue(source[currentPosition++]))
2317 // //error don't care of the value
2318 // currentCharacter = 'A';
2319 // } //something different from * and /
2321 // currentCharacter =
2322 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2326 } catch (IndexOutOfBoundsException e) {
2334 if (isPHPIdentifierStart(currentCharacter) || currentCharacter == '$') {
2336 scanIdentifierOrKeyword((currentCharacter == '$'));
2337 } catch (InvalidInputException ex) {
2342 if (Character.isDigit(currentCharacter)) {
2345 } catch (InvalidInputException ex) {
2352 //-----------------end switch while try--------------------
2353 } catch (IndexOutOfBoundsException e) {
2354 } catch (InvalidInputException e) {
2359 // public final boolean jumpOverUnicodeWhiteSpace()
2360 // throws InvalidInputException {
2362 // //handle the case of unicode. Jump over the next whiteSpace
2363 // //making startPosition pointing on the next available char
2364 // //On false, the currentCharacter is filled up with a potential
2368 // this.wasAcr = false;
2369 // int c1, c2, c3, c4;
2370 // int unicodeSize = 6;
2371 // currentPosition++;
2372 // while (source[currentPosition] == 'u') {
2373 // currentPosition++;
2377 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2379 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2381 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2383 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2385 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2388 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2389 // if (recordLineSeparator
2390 // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2391 // pushLineSeparator();
2392 // if (Character.isWhitespace(currentCharacter))
2395 // //buffer the new char which is not a white space
2396 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2397 // //withoutUnicodePtr == 1 is true here
2399 // } catch (IndexOutOfBoundsException e) {
2400 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2403 public final int[] getLineEnds() {
2404 //return a bounded copy of this.lineEnds
2406 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0, linePtr + 1);
2410 public char[] getSource() {
2414 public static boolean isIdentifierOrKeyword(int token) {
2415 return (token == TokenNameIdentifier) || (token > TokenNameKEYWORD);
2418 final char[] optimizedCurrentTokenSource1() {
2419 //return always the same char[] build only once
2420 //optimization at no speed cost of 99.5 % of the singleCharIdentifier
2421 char charOne = source[startPosition];
2476 return new char[] { charOne };
2480 final char[] optimizedCurrentTokenSource2() {
2482 c0 = source[startPosition];
2483 c1 = source[startPosition + 1];
2485 //return always the same char[] build only once
2486 //optimization at no speed cost of 99.5 % of the singleCharIdentifier
2489 return charArray_va;
2491 return charArray_vb;
2493 return charArray_vc;
2495 return charArray_vd;
2497 return charArray_ve;
2499 return charArray_vf;
2501 return charArray_vg;
2503 return charArray_vh;
2505 return charArray_vi;
2507 return charArray_vj;
2509 return charArray_vk;
2511 return charArray_vl;
2513 return charArray_vm;
2515 return charArray_vn;
2517 return charArray_vo;
2519 return charArray_vp;
2521 return charArray_vq;
2523 return charArray_vr;
2525 return charArray_vs;
2527 return charArray_vt;
2529 return charArray_vu;
2531 return charArray_vv;
2533 return charArray_vw;
2535 return charArray_vx;
2537 return charArray_vy;
2539 return charArray_vz;
2542 //try to return the same char[] build only once
2543 int hash = ((c0 << 6) + c1) % TableSize;
2544 char[][] table = charArray_length[0][hash];
2546 while (++i < InternalTableSize) {
2547 char[] charArray = table[i];
2548 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2551 //---------other side---------
2553 int max = newEntry2;
2554 while (++i <= max) {
2555 char[] charArray = table[i];
2556 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2559 //--------add the entry-------
2560 if (++max >= InternalTableSize)
2563 table[max] = (r = new char[] { c0, c1 });
2568 final char[] optimizedCurrentTokenSource3() {
2569 //try to return the same char[] build only once
2571 int hash = (((c0 = source[startPosition]) << 12) + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2573 char[][] table = charArray_length[1][hash];
2575 while (++i < InternalTableSize) {
2576 char[] charArray = table[i];
2577 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2580 //---------other side---------
2582 int max = newEntry3;
2583 while (++i <= max) {
2584 char[] charArray = table[i];
2585 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2588 //--------add the entry-------
2589 if (++max >= InternalTableSize)
2592 table[max] = (r = new char[] { c0, c1, c2 });
2597 final char[] optimizedCurrentTokenSource4() {
2598 //try to return the same char[] build only once
2599 char c0, c1, c2, c3;
2600 long hash = ((((long) (c0 = source[startPosition])) << 18) + ((c1 = source[startPosition + 1]) << 12)
2601 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2603 char[][] table = charArray_length[2][(int) hash];
2605 while (++i < InternalTableSize) {
2606 char[] charArray = table[i];
2607 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2610 //---------other side---------
2612 int max = newEntry4;
2613 while (++i <= max) {
2614 char[] charArray = table[i];
2615 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]))
2618 //--------add the entry-------
2619 if (++max >= InternalTableSize)
2622 table[max] = (r = new char[] { c0, c1, c2, c3 });
2627 final char[] optimizedCurrentTokenSource5() {
2628 //try to return the same char[] build only once
2629 char c0, c1, c2, c3, c4;
2630 long hash = ((((long) (c0 = source[startPosition])) << 24) + (((long) (c1 = source[startPosition + 1])) << 18)
2631 + ((c2 = source[startPosition + 2]) << 12) + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2633 char[][] table = charArray_length[3][(int) hash];
2635 while (++i < InternalTableSize) {
2636 char[] charArray = table[i];
2637 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2640 //---------other side---------
2642 int max = newEntry5;
2643 while (++i <= max) {
2644 char[] charArray = table[i];
2645 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4]))
2648 //--------add the entry-------
2649 if (++max >= InternalTableSize)
2652 table[max] = (r = new char[] { c0, c1, c2, c3, c4 });
2657 final char[] optimizedCurrentTokenSource6() {
2658 //try to return the same char[] build only once
2659 char c0, c1, c2, c3, c4, c5;
2660 long hash = ((((long) (c0 = source[startPosition])) << 32) + (((long) (c1 = source[startPosition + 1])) << 24)
2661 + (((long) (c2 = source[startPosition + 2])) << 18) + ((c3 = source[startPosition + 3]) << 12)
2662 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2664 char[][] table = charArray_length[4][(int) hash];
2666 while (++i < InternalTableSize) {
2667 char[] charArray = table[i];
2668 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2669 && (c5 == charArray[5]))
2672 //---------other side---------
2674 int max = newEntry6;
2675 while (++i <= max) {
2676 char[] charArray = table[i];
2677 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])
2678 && (c5 == charArray[5]))
2681 //--------add the entry-------
2682 if (++max >= InternalTableSize)
2685 table[max] = (r = new char[] { c0, c1, c2, c3, c4, c5 });
2690 public final void pushLineSeparator() throws InvalidInputException {
2691 //see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2692 final int INCREMENT = 250;
2693 if (this.checkNonExternalizedStringLiterals) {
2694 // reinitialize the current line for non externalize strings purpose
2697 //currentCharacter is at position currentPosition-1
2699 if (currentCharacter == '\r') {
2700 int separatorPos = currentPosition - 1;
2701 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2703 //System.out.println("CR-" + separatorPos);
2705 lineEnds[++linePtr] = separatorPos;
2706 } catch (IndexOutOfBoundsException e) {
2707 //linePtr value is correct
2708 int oldLength = lineEnds.length;
2709 int[] old = lineEnds;
2710 lineEnds = new int[oldLength + INCREMENT];
2711 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2712 lineEnds[linePtr] = separatorPos;
2714 // look-ahead for merged cr+lf
2716 if (source[currentPosition] == '\n') {
2717 //System.out.println("look-ahead LF-" + currentPosition);
2718 lineEnds[linePtr] = currentPosition;
2724 } catch (IndexOutOfBoundsException e) {
2729 if (currentCharacter == '\n') {
2730 //must merge eventual cr followed by lf
2731 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2732 //System.out.println("merge LF-" + (currentPosition - 1));
2733 lineEnds[linePtr] = currentPosition - 1;
2735 int separatorPos = currentPosition - 1;
2736 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2738 // System.out.println("LF-" + separatorPos);
2740 lineEnds[++linePtr] = separatorPos;
2741 } catch (IndexOutOfBoundsException e) {
2742 //linePtr value is correct
2743 int oldLength = lineEnds.length;
2744 int[] old = lineEnds;
2745 lineEnds = new int[oldLength + INCREMENT];
2746 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2747 lineEnds[linePtr] = separatorPos;
2755 public final void pushUnicodeLineSeparator() {
2756 // isUnicode means that the \r or \n has been read as a unicode character
2757 //see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2758 final int INCREMENT = 250;
2759 //currentCharacter is at position currentPosition-1
2760 if (this.checkNonExternalizedStringLiterals) {
2761 // reinitialize the current line for non externalize strings purpose
2765 if (currentCharacter == '\r') {
2766 int separatorPos = currentPosition - 6;
2767 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2769 //System.out.println("CR-" + separatorPos);
2771 lineEnds[++linePtr] = separatorPos;
2772 } catch (IndexOutOfBoundsException e) {
2773 //linePtr value is correct
2774 int oldLength = lineEnds.length;
2775 int[] old = lineEnds;
2776 lineEnds = new int[oldLength + INCREMENT];
2777 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2778 lineEnds[linePtr] = separatorPos;
2780 // look-ahead for merged cr+lf
2781 if (source[currentPosition] == '\n') {
2782 //System.out.println("look-ahead LF-" + currentPosition);
2783 lineEnds[linePtr] = currentPosition;
2791 if (currentCharacter == '\n') {
2792 //must merge eventual cr followed by lf
2793 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2794 //System.out.println("merge LF-" + (currentPosition - 1));
2795 lineEnds[linePtr] = currentPosition - 6;
2797 int separatorPos = currentPosition - 6;
2798 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2800 // System.out.println("LF-" + separatorPos);
2802 lineEnds[++linePtr] = separatorPos;
2803 } catch (IndexOutOfBoundsException e) {
2804 //linePtr value is correct
2805 int oldLength = lineEnds.length;
2806 int[] old = lineEnds;
2807 lineEnds = new int[oldLength + INCREMENT];
2808 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2809 lineEnds[linePtr] = separatorPos;
2817 public void recordComment(int token) {
2819 int stopPosition = this.currentPosition;
2821 case TokenNameCOMMENT_LINE:
2822 stopPosition = -this.lastCommentLinePosition;
2824 case TokenNameCOMMENT_BLOCK:
2825 stopPosition = -this.currentPosition;
2829 // a new comment is recorded
2830 int length = this.commentStops.length;
2831 if (++this.commentPtr >= length) {
2832 System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length);
2833 //grows the positions buffers too
2834 System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length);
2836 this.commentStops[this.commentPtr] = stopPosition;
2837 this.commentStarts[this.commentPtr] = this.startPosition;
2840 // public final void recordComment(boolean isJavadoc) {
2841 // // a new annotation comment is recorded
2843 // commentStops[++commentPtr] = isJavadoc
2844 // ? currentPosition
2845 // : -currentPosition;
2846 // } catch (IndexOutOfBoundsException e) {
2847 // int oldStackLength = commentStops.length;
2848 // int[] oldStack = commentStops;
2849 // commentStops = new int[oldStackLength + 30];
2850 // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
2851 // commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition;
2852 // //grows the positions buffers too
2853 // int[] old = commentStarts;
2854 // commentStarts = new int[oldStackLength + 30];
2855 // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
2857 // //the buffer is of a correct size here
2858 // commentStarts[commentPtr] = startPosition;
2860 public void resetTo(int begin, int end) {
2861 //reset the scanner to a given position where it may rescan again
2863 initialPosition = startPosition = currentPosition = begin;
2864 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
2865 commentPtr = -1; // reset comment stack
2868 public final void scanSingleQuotedEscapeCharacter() throws InvalidInputException {
2869 // the string with "\\u" is a legal string of two chars \ and u
2870 //thus we use a direct access to the source (for regular cases).
2871 // if (unicodeAsBackSlash) {
2872 // // consume next character
2873 // unicodeAsBackSlash = false;
2874 // if (((currentCharacter = source[currentPosition++]) == '\\')
2875 // && (source[currentPosition] == 'u')) {
2876 // getNextUnicodeChar();
2878 // if (withoutUnicodePtr != 0) {
2879 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2883 currentCharacter = source[currentPosition++];
2884 switch (currentCharacter) {
2886 currentCharacter = '\'';
2889 currentCharacter = '\\';
2892 currentCharacter = '\\';
2897 public final void scanDoubleQuotedEscapeCharacter() throws InvalidInputException {
2898 currentCharacter = source[currentPosition++];
2899 switch (currentCharacter) {
2901 // currentCharacter = '\b';
2904 currentCharacter = '\t';
2907 currentCharacter = '\n';
2910 // currentCharacter = '\f';
2913 currentCharacter = '\r';
2916 currentCharacter = '\"';
2919 currentCharacter = '\'';
2922 currentCharacter = '\\';
2925 currentCharacter = '$';
2928 // -----------octal escape--------------
2930 // OctalDigit OctalDigit
2931 // ZeroToThree OctalDigit OctalDigit
2932 int number = Character.getNumericValue(currentCharacter);
2933 if (number >= 0 && number <= 7) {
2934 boolean zeroToThreeNot = number > 3;
2935 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2936 int digit = Character.getNumericValue(currentCharacter);
2937 if (digit >= 0 && digit <= 7) {
2938 number = (number * 8) + digit;
2939 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2940 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
2941 // Digit --> ignore last character
2944 digit = Character.getNumericValue(currentCharacter);
2945 if (digit >= 0 && digit <= 7) {
2946 // has read \ZeroToThree OctalDigit OctalDigit
2947 number = (number * 8) + digit;
2948 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
2949 // --> ignore last character
2953 } else { // has read \OctalDigit NonDigit--> ignore last
2957 } else { // has read \OctalDigit NonOctalDigit--> ignore last
2961 } else { // has read \OctalDigit --> ignore last character
2965 throw new InvalidInputException(INVALID_ESCAPE);
2966 currentCharacter = (char) number;
2969 // throw new InvalidInputException(INVALID_ESCAPE);
2973 // public int scanIdentifierOrKeyword() throws InvalidInputException {
2974 // return scanIdentifierOrKeyword( false );
2976 public int scanIdentifierOrKeyword(boolean isVariable) throws InvalidInputException {
2978 //first dispatch on the first char.
2979 //then the length. If there are several
2980 //keywors with the same length AND the same first char, then do another
2981 //disptach on the second char :-)...cool....but fast !
2982 useAssertAsAnIndentifier = false;
2983 while (getNextCharAsJavaIdentifierPart()) {
2987 // if (new String(getCurrentTokenSource()).equals("$this")) {
2988 // return TokenNamethis;
2990 return TokenNameVariable;
2995 // if (withoutUnicodePtr == 0)
2996 //quick test on length == 1 but not on length > 12 while most identifier
2997 //have a length which is <= 12...but there are lots of identifier with
3000 if ((length = currentPosition - startPosition) == 1)
3001 return TokenNameIdentifier;
3003 data = new char[length];
3004 index = startPosition;
3005 for (int i = 0; i < length; i++) {
3006 data[i] = Character.toLowerCase(source[index + i]);
3010 // if ((length = withoutUnicodePtr) == 1)
3011 // return TokenNameIdentifier;
3012 // // data = withoutUnicodeBuffer;
3013 // data = new char[withoutUnicodeBuffer.length];
3014 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
3015 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
3019 firstLetter = data[index];
3020 switch (firstLetter) {
3025 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'i') && (data[++index] == 'l')
3026 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3027 return TokenNameFILE;
3028 index = 0; //__LINE__
3029 if ((data[++index] == '_') && (data[++index] == 'l') && (data[++index] == 'i') && (data[++index] == 'n')
3030 && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == '_'))
3031 return TokenNameLINE;
3035 if ((data[++index] == '_') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3036 && (data[++index] == 's') && (data[++index] == 's') && (data[++index] == '_') && (data[++index] == '_'))
3037 return TokenNameCLASS_C;
3041 if ((data[++index] == '_') && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 't')
3042 && (data[++index] == 'h') && (data[++index] == 'o') && (data[++index] == 'd') && (data[++index] == '_')
3043 && (data[++index] == '_'))
3044 return TokenNameMETHOD_C;
3048 if ((data[++index] == '_') && (data[++index] == 'f') && (data[++index] == 'u') && (data[++index] == 'n')
3049 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'o')
3050 && (data[++index] == 'n') && (data[++index] == '_') && (data[++index] == '_'))
3051 return TokenNameFUNC_C;
3054 return TokenNameIdentifier;
3056 // as and array abstract
3060 if ((data[++index] == 's')) {
3063 return TokenNameIdentifier;
3067 if ((data[++index] == 'n') && (data[++index] == 'd')) {
3068 return TokenNameand;
3070 return TokenNameIdentifier;
3074 if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y'))
3075 return TokenNamearray;
3077 return TokenNameIdentifier;
3079 if ((data[++index] == 'b') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'r')
3080 && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 't'))
3081 return TokenNameabstract;
3083 return TokenNameIdentifier;
3085 return TokenNameIdentifier;
3091 if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k'))
3092 return TokenNamebreak;
3094 return TokenNameIdentifier;
3096 return TokenNameIdentifier;
3099 //case catch class clone const continue
3102 if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e'))
3103 return TokenNamecase;
3105 return TokenNameIdentifier;
3107 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3108 return TokenNamecatch;
3110 if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's'))
3111 return TokenNameclass;
3113 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 'e'))
3114 return TokenNameclone;
3116 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't'))
3117 return TokenNameconst;
3119 return TokenNameIdentifier;
3121 if ((data[++index] == 'o') && (data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'i')
3122 && (data[++index] == 'n') && (data[++index] == 'u') && (data[++index] == 'e'))
3123 return TokenNamecontinue;
3125 return TokenNameIdentifier;
3127 return TokenNameIdentifier;
3130 // declare default do die
3131 // TODO delete define ==> no keyword !
3134 if ((data[++index] == 'o'))
3137 return TokenNameIdentifier;
3139 // if ((data[++index] == 'e')
3140 // && (data[++index] == 'f')
3141 // && (data[++index] == 'i')
3142 // && (data[++index] == 'n')
3143 // && (data[++index] == 'e'))
3144 // return TokenNamedefine;
3146 // return TokenNameIdentifier;
3148 if ((data[++index] == 'e') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a')
3149 && (data[++index] == 'r') && (data[++index] == 'e'))
3150 return TokenNamedeclare;
3152 if ((data[++index] == 'e') && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'u')
3153 && (data[++index] == 'l') && (data[++index] == 't'))
3154 return TokenNamedefault;
3156 return TokenNameIdentifier;
3158 return TokenNameIdentifier;
3161 //echo else exit elseif extends eval
3164 if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o'))
3165 return TokenNameecho;
3166 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e'))
3167 return TokenNameelse;
3168 else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't'))
3169 return TokenNameexit;
3170 else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l'))
3171 return TokenNameeval;
3173 return TokenNameIdentifier;
3176 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f'))
3177 return TokenNameendif;
3178 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 't') && (data[++index] == 'y'))
3179 return TokenNameempty;
3181 return TokenNameIdentifier;
3184 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o')
3185 && (data[++index] == 'r'))
3186 return TokenNameendfor;
3187 else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 'i')
3188 && (data[++index] == 'f'))
3189 return TokenNameelseif;
3191 return TokenNameIdentifier;
3193 if ((data[++index] == 'x') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'n')
3194 && (data[++index] == 'd') && (data[++index] == 's'))
3195 return TokenNameextends;
3197 return TokenNameIdentifier;
3200 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'w') && (data[++index] == 'h')
3201 && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3202 return TokenNameendwhile;
3204 return TokenNameIdentifier;
3207 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 's') && (data[++index] == 'w')
3208 && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h'))
3209 return TokenNameendswitch;
3211 return TokenNameIdentifier;
3214 if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'd') && (data[++index] == 'e')
3215 && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 'r')
3216 && (data[++index] == 'e'))
3217 return TokenNameenddeclare;
3219 if ((data[++index] == 'n') // endforeach
3220 && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r')
3221 && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'h'))
3222 return TokenNameendforeach;
3224 return TokenNameIdentifier;
3226 return TokenNameIdentifier;
3229 //for false final function
3232 if ((data[++index] == 'o') && (data[++index] == 'r'))
3233 return TokenNamefor;
3235 return TokenNameIdentifier;
3237 // if ((data[++index] == 'a') && (data[++index] == 'l')
3238 // && (data[++index] == 's') && (data[++index] == 'e'))
3239 // return TokenNamefalse;
3240 if ((data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 'a') && (data[++index] == 'l'))
3241 return TokenNamefinal;
3243 return TokenNameIdentifier;
3246 if ((data[++index] == 'o') && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a')
3247 && (data[++index] == 'c') && (data[++index] == 'h'))
3248 return TokenNameforeach;
3250 return TokenNameIdentifier;
3253 if ((data[++index] == 'u') && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 't')
3254 && (data[++index] == 'i') && (data[++index] == 'o') && (data[++index] == 'n'))
3255 return TokenNamefunction;
3257 return TokenNameIdentifier;
3259 return TokenNameIdentifier;
3264 if ((data[++index] == 'l') && (data[++index] == 'o') && (data[++index] == 'b') && (data[++index] == 'a')
3265 && (data[++index] == 'l')) {
3266 return TokenNameglobal;
3269 return TokenNameIdentifier;
3271 //if int isset include include_once instanceof interface implements
3274 if (data[++index] == 'f')
3277 return TokenNameIdentifier;
3279 // if ((data[++index] == 'n') && (data[++index] == 't'))
3280 // return TokenNameint;
3282 // return TokenNameIdentifier;
3284 if ((data[++index] == 's') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3285 return TokenNameisset;
3287 return TokenNameIdentifier;
3289 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3290 && (data[++index] == 'd') && (data[++index] == 'e'))
3291 return TokenNameinclude;
3293 return TokenNameIdentifier;
3296 if ((data[++index] == 'n') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'r')
3297 && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'c') && (data[++index] == 'e'))
3298 return TokenNameinterface;
3300 return TokenNameIdentifier;
3303 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't') && (data[++index] == 'a')
3304 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e') && (data[++index] == 'o')
3305 && (data[++index] == 'f'))
3306 return TokenNameinstanceof;
3307 if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 'l') && (data[++index] == 'e')
3308 && (data[++index] == 'm') && (data[++index] == 'e') && (data[++index] == 'n') && (data[++index] == 't')
3309 && (data[++index] == 's'))
3310 return TokenNameimplements;
3312 return TokenNameIdentifier;
3314 if ((data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'l') && (data[++index] == 'u')
3315 && (data[++index] == 'd') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3316 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e'))
3317 return TokenNameinclude_once;
3319 return TokenNameIdentifier;
3321 return TokenNameIdentifier;
3326 if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) {
3327 return TokenNamelist;
3330 return TokenNameIdentifier;
3335 if ((data[++index] == 'e') && (data[++index] == 'w'))
3336 return TokenNamenew;
3338 return TokenNameIdentifier;
3340 // if ((data[++index] == 'u') && (data[++index] == 'l')
3341 // && (data[++index] == 'l'))
3342 // return TokenNamenull;
3344 // return TokenNameIdentifier;
3346 return TokenNameIdentifier;
3351 if (data[++index] == 'r') {
3355 // if (length == 12) {
3356 // if ((data[++index] == 'l')
3357 // && (data[++index] == 'd')
3358 // && (data[++index] == '_')
3359 // && (data[++index] == 'f')
3360 // && (data[++index] == 'u')
3361 // && (data[++index] == 'n')
3362 // && (data[++index] == 'c')
3363 // && (data[++index] == 't')
3364 // && (data[++index] == 'i')
3365 // && (data[++index] == 'o')
3366 // && (data[++index] == 'n')) {
3367 // return TokenNameold_function;
3370 return TokenNameIdentifier;
3372 // print public private protected
3375 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) {
3376 return TokenNameprint;
3378 return TokenNameIdentifier;
3380 if ((data[++index] == 'u') && (data[++index] == 'b') && (data[++index] == 'l') && (data[++index] == 'i')
3381 && (data[++index] == 'c')) {
3382 return TokenNamepublic;
3384 return TokenNameIdentifier;
3386 if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'v') && (data[++index] == 'a')
3387 && (data[++index] == 't') && (data[++index] == 'e')) {
3388 return TokenNameprivate;
3390 return TokenNameIdentifier;
3392 if ((data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 't') && (data[++index] == 'e')
3393 && (data[++index] == 'c') && (data[++index] == 't') && (data[++index] == 'e') && (data[++index] == 'd')) {
3394 return TokenNameprotected;
3396 return TokenNameIdentifier;
3398 return TokenNameIdentifier;
3400 //return require require_once
3402 if ((data[++index] == 'e') && (data[++index] == 't') && (data[++index] == 'u') && (data[++index] == 'r')
3403 && (data[++index] == 'n')) {
3404 return TokenNamereturn;
3406 } else if (length == 7) {
3407 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3408 && (data[++index] == 'r') && (data[++index] == 'e')) {
3409 return TokenNamerequire;
3411 } else if (length == 12) {
3412 if ((data[++index] == 'e') && (data[++index] == 'q') && (data[++index] == 'u') && (data[++index] == 'i')
3413 && (data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == '_') && (data[++index] == 'o')
3414 && (data[++index] == 'n') && (data[++index] == 'c') && (data[++index] == 'e')) {
3415 return TokenNamerequire_once;
3418 return TokenNameIdentifier;
3423 if (data[++index] == 't')
3424 if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) {
3425 return TokenNamestatic;
3427 return TokenNameIdentifier;
3428 else if ((data[index] == 'w') && (data[++index] == 'i') && (data[++index] == 't') && (data[++index] == 'c')
3429 && (data[++index] == 'h'))
3430 return TokenNameswitch;
3432 return TokenNameIdentifier;
3434 return TokenNameIdentifier;
3440 if ((data[++index] == 'r') && (data[++index] == 'y'))
3441 return TokenNametry;
3443 return TokenNameIdentifier;
3445 // if ((data[++index] == 'r') && (data[++index] == 'u')
3446 // && (data[++index] == 'e'))
3447 // return TokenNametrue;
3449 // return TokenNameIdentifier;
3451 if ((data[++index] == 'h') && (data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 'w'))
3452 return TokenNamethrow;
3454 return TokenNameIdentifier;
3456 return TokenNameIdentifier;
3462 if ((data[++index] == 's') && (data[++index] == 'e'))
3463 return TokenNameuse;
3465 return TokenNameIdentifier;
3467 if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't'))
3468 return TokenNameunset;
3470 return TokenNameIdentifier;
3472 return TokenNameIdentifier;
3478 if ((data[++index] == 'a') && (data[++index] == 'r'))
3479 return TokenNamevar;
3481 return TokenNameIdentifier;
3483 return TokenNameIdentifier;
3489 if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e'))
3490 return TokenNamewhile;
3492 return TokenNameIdentifier;
3493 //case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3494 // (data[++index]=='e') && (data[++index]=='f')&&
3495 // (data[++index]=='p'))
3496 //return TokenNamewidefp ;
3498 //return TokenNameIdentifier;
3500 return TokenNameIdentifier;
3506 if ((data[++index] == 'o') && (data[++index] == 'r'))
3507 return TokenNamexor;
3509 return TokenNameIdentifier;
3511 return TokenNameIdentifier;
3514 return TokenNameIdentifier;
3518 public int scanNumber(boolean dotPrefix) throws InvalidInputException {
3519 //when entering this method the currentCharacter is the firt
3520 //digit of the number , i.e. it may be preceeded by a . when
3522 boolean floating = dotPrefix;
3523 if ((!dotPrefix) && (currentCharacter == '0')) {
3524 if (getNextChar('x', 'X') >= 0) { //----------hexa-----------------
3525 //force the first char of the hexa number do exist...
3526 // consume next character
3527 unicodeAsBackSlash = false;
3528 currentCharacter = source[currentPosition++];
3529 // if (((currentCharacter = source[currentPosition++]) == '\\')
3530 // && (source[currentPosition] == 'u')) {
3531 // getNextUnicodeChar();
3533 // if (withoutUnicodePtr != 0) {
3534 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3537 if (Character.digit(currentCharacter, 16) == -1)
3538 throw new InvalidInputException(INVALID_HEXA);
3540 while (getNextCharAsDigit(16)) {
3543 // if (getNextChar('l', 'L') >= 0)
3544 // return TokenNameLongLiteral;
3546 return TokenNameIntegerLiteral;
3548 //there is x or X in the number
3549 //potential octal ! ... some one may write 000099.0 ! thus 00100 <
3550 // 00078.0 is true !!!!! crazy language
3551 if (getNextCharAsDigit()) {
3552 //-------------potential octal-----------------
3553 while (getNextCharAsDigit()) {
3556 // if (getNextChar('l', 'L') >= 0) {
3557 // return TokenNameLongLiteral;
3560 // if (getNextChar('f', 'F') >= 0) {
3561 // return TokenNameFloatingPointLiteral;
3563 if (getNextChar('d', 'D') >= 0) {
3564 return TokenNameDoubleLiteral;
3565 } else { //make the distinction between octal and float ....
3566 if (getNextChar('.')) { //bingo ! ....
3567 while (getNextCharAsDigit()) {
3570 if (getNextChar('e', 'E') >= 0) {
3571 // consume next character
3572 unicodeAsBackSlash = false;
3573 currentCharacter = source[currentPosition++];
3574 // if (((currentCharacter = source[currentPosition++]) == '\\')
3575 // && (source[currentPosition] == 'u')) {
3576 // getNextUnicodeChar();
3578 // if (withoutUnicodePtr != 0) {
3579 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3582 if ((currentCharacter == '-') || (currentCharacter == '+')) {
3583 // consume next character
3584 unicodeAsBackSlash = false;
3585 currentCharacter = source[currentPosition++];
3586 // if (((currentCharacter = source[currentPosition++]) == '\\')
3587 // && (source[currentPosition] == 'u')) {
3588 // getNextUnicodeChar();
3590 // if (withoutUnicodePtr != 0) {
3591 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3592 // currentCharacter;
3596 if (!Character.isDigit(currentCharacter))
3597 throw new InvalidInputException(INVALID_FLOAT);
3598 while (getNextCharAsDigit()) {
3602 // if (getNextChar('f', 'F') >= 0)
3603 // return TokenNameFloatingPointLiteral;
3604 getNextChar('d', 'D'); //jump over potential d or D
3605 return TokenNameDoubleLiteral;
3607 return TokenNameIntegerLiteral;
3614 while (getNextCharAsDigit()) {
3617 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3618 // return TokenNameLongLiteral;
3619 if ((!dotPrefix) && (getNextChar('.'))) { //decimal part that can be empty
3620 while (getNextCharAsDigit()) {
3625 //if floating is true both exponant and suffix may be optional
3626 if (getNextChar('e', 'E') >= 0) {
3628 // consume next character
3629 unicodeAsBackSlash = false;
3630 currentCharacter = source[currentPosition++];
3631 // if (((currentCharacter = source[currentPosition++]) == '\\')
3632 // && (source[currentPosition] == 'u')) {
3633 // getNextUnicodeChar();
3635 // if (withoutUnicodePtr != 0) {
3636 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3639 if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
3642 unicodeAsBackSlash = false;
3643 currentCharacter = source[currentPosition++];
3644 // if (((currentCharacter = source[currentPosition++]) == '\\')
3645 // && (source[currentPosition] == 'u')) {
3646 // getNextUnicodeChar();
3648 // if (withoutUnicodePtr != 0) {
3649 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3653 if (!Character.isDigit(currentCharacter))
3654 throw new InvalidInputException(INVALID_FLOAT);
3655 while (getNextCharAsDigit()) {
3659 if (getNextChar('d', 'D') >= 0)
3660 return TokenNameDoubleLiteral;
3661 // if (getNextChar('f', 'F') >= 0)
3662 // return TokenNameFloatingPointLiteral;
3663 //the long flag has been tested before
3664 return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral;
3668 * Search the line number corresponding to a specific position
3671 public final int getLineNumber(int position) {
3672 if (lineEnds == null)
3674 int length = linePtr + 1;
3677 int g = 0, d = length - 1;
3681 if (position < lineEnds[m]) {
3683 } else if (position > lineEnds[m]) {
3689 if (position < lineEnds[m]) {
3695 public void setPHPMode(boolean mode) {
3699 public final void setSource(char[] source) {
3700 setSource(null, source);
3703 public final void setSource(ICompilationUnit compilationUnit, char[] source) {
3704 //the source-buffer is set to sourceString
3705 this.compilationUnit = compilationUnit;
3706 if (source == null) {
3707 this.source = new char[0];
3709 this.source = source;
3712 initialPosition = currentPosition = 0;
3713 containsAssertKeyword = false;
3714 withoutUnicodeBuffer = new char[this.source.length];
3715 // encapsedStringStack = new Stack();
3718 public String toString() {
3719 if (startPosition == source.length)
3720 return "EOF\n\n" + new String(source); //$NON-NLS-1$
3721 if (currentPosition > source.length)
3722 return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3723 char front[] = new char[startPosition];
3724 System.arraycopy(source, 0, front, 0, startPosition);
3725 int middleLength = (currentPosition - 1) - startPosition + 1;
3727 if (middleLength > -1) {
3728 middle = new char[middleLength];
3729 System.arraycopy(source, startPosition, middle, 0, middleLength);
3731 middle = new char[0];
3733 char end[] = new char[source.length - (currentPosition - 1)];
3734 System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - (currentPosition - 1) - 1);
3735 return new String(front) + "\n===============================\nStarts here -->" //$NON-NLS-1$
3736 + new String(middle) + "<-- Ends here\n===============================\n" //$NON-NLS-1$
3740 public final String toStringAction(int act) {
3742 case TokenNameERROR:
3743 return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
3745 case TokenNameINLINE_HTML:
3746 return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3747 case TokenNameIdentifier:
3748 return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3749 case TokenNameVariable:
3750 return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3751 case TokenNameabstract:
3752 return "abstract"; //$NON-NLS-1$
3754 return "AND"; //$NON-NLS-1$
3755 case TokenNamearray:
3756 return "array"; //$NON-NLS-1$
3758 return "as"; //$NON-NLS-1$
3759 case TokenNamebreak:
3760 return "break"; //$NON-NLS-1$
3762 return "case"; //$NON-NLS-1$
3763 case TokenNameclass:
3764 return "class"; //$NON-NLS-1$
3765 case TokenNamecatch:
3766 return "catch"; //$NON-NLS-1$
3767 case TokenNameclone:
3770 case TokenNameconst:
3773 case TokenNamecontinue:
3774 return "continue"; //$NON-NLS-1$
3775 case TokenNamedefault:
3776 return "default"; //$NON-NLS-1$
3777 // case TokenNamedefine :
3778 // return "define"; //$NON-NLS-1$
3780 return "do"; //$NON-NLS-1$
3782 return "echo"; //$NON-NLS-1$
3784 return "else"; //$NON-NLS-1$
3785 case TokenNameelseif:
3786 return "elseif"; //$NON-NLS-1$
3787 case TokenNameendfor:
3788 return "endfor"; //$NON-NLS-1$
3789 case TokenNameendforeach:
3790 return "endforeach"; //$NON-NLS-1$
3791 case TokenNameendif:
3792 return "endif"; //$NON-NLS-1$
3793 case TokenNameendswitch:
3794 return "endswitch"; //$NON-NLS-1$
3795 case TokenNameendwhile:
3796 return "endwhile"; //$NON-NLS-1$
3799 case TokenNameextends:
3800 return "extends"; //$NON-NLS-1$
3801 // case TokenNamefalse :
3802 // return "false"; //$NON-NLS-1$
3803 case TokenNamefinal:
3804 return "final"; //$NON-NLS-1$
3806 return "for"; //$NON-NLS-1$
3807 case TokenNameforeach:
3808 return "foreach"; //$NON-NLS-1$
3809 case TokenNamefunction:
3810 return "function"; //$NON-NLS-1$
3811 case TokenNameglobal:
3812 return "global"; //$NON-NLS-1$
3814 return "if"; //$NON-NLS-1$
3815 case TokenNameimplements:
3816 return "implements"; //$NON-NLS-1$
3817 case TokenNameinclude:
3818 return "include"; //$NON-NLS-1$
3819 case TokenNameinclude_once:
3820 return "include_once"; //$NON-NLS-1$
3821 case TokenNameinstanceof:
3822 return "instanceof"; //$NON-NLS-1$
3823 case TokenNameinterface:
3824 return "interface"; //$NON-NLS-1$
3825 case TokenNameisset:
3826 return "isset"; //$NON-NLS-1$
3828 return "list"; //$NON-NLS-1$
3830 return "new"; //$NON-NLS-1$
3831 // case TokenNamenull :
3832 // return "null"; //$NON-NLS-1$
3834 return "OR"; //$NON-NLS-1$
3835 case TokenNameprint:
3836 return "print"; //$NON-NLS-1$
3837 case TokenNameprivate:
3838 return "private"; //$NON-NLS-1$
3839 case TokenNameprotected:
3840 return "protected"; //$NON-NLS-1$
3841 case TokenNamepublic:
3842 return "public"; //$NON-NLS-1$
3843 case TokenNamerequire:
3844 return "require"; //$NON-NLS-1$
3845 case TokenNamerequire_once:
3846 return "require_once"; //$NON-NLS-1$
3847 case TokenNamereturn:
3848 return "return"; //$NON-NLS-1$
3849 case TokenNamestatic:
3850 return "static"; //$NON-NLS-1$
3851 case TokenNameswitch:
3852 return "switch"; //$NON-NLS-1$
3853 // case TokenNametrue :
3854 // return "true"; //$NON-NLS-1$
3855 case TokenNameunset:
3856 return "unset"; //$NON-NLS-1$
3858 return "var"; //$NON-NLS-1$
3859 case TokenNamewhile:
3860 return "while"; //$NON-NLS-1$
3862 return "XOR"; //$NON-NLS-1$
3863 // case TokenNamethis :
3864 // return "$this"; //$NON-NLS-1$
3865 case TokenNameIntegerLiteral:
3866 return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3867 case TokenNameDoubleLiteral:
3868 return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3869 case TokenNameStringDoubleQuote:
3870 return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3871 case TokenNameStringSingleQuote:
3872 return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3873 case TokenNameStringInterpolated:
3874 return "StringInterpolated(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3875 case TokenNameEncapsedString0:
3876 return "`"; //$NON-NLS-1$
3877 // case TokenNameEncapsedString1:
3878 // return "\'"; //$NON-NLS-1$
3879 // case TokenNameEncapsedString2:
3880 // return "\""; //$NON-NLS-1$
3881 case TokenNameSTRING:
3882 return "STRING_DQ(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3883 case TokenNameHEREDOC:
3884 return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3885 case TokenNamePLUS_PLUS:
3886 return "++"; //$NON-NLS-1$
3887 case TokenNameMINUS_MINUS:
3888 return "--"; //$NON-NLS-1$
3889 case TokenNameEQUAL_EQUAL:
3890 return "=="; //$NON-NLS-1$
3891 case TokenNameEQUAL_EQUAL_EQUAL:
3892 return "==="; //$NON-NLS-1$
3893 case TokenNameEQUAL_GREATER:
3894 return "=>"; //$NON-NLS-1$
3895 case TokenNameLESS_EQUAL:
3896 return "<="; //$NON-NLS-1$
3897 case TokenNameGREATER_EQUAL:
3898 return ">="; //$NON-NLS-1$
3899 case TokenNameNOT_EQUAL:
3900 return "!="; //$NON-NLS-1$
3901 case TokenNameNOT_EQUAL_EQUAL:
3902 return "!=="; //$NON-NLS-1$
3903 case TokenNameLEFT_SHIFT:
3904 return "<<"; //$NON-NLS-1$
3905 case TokenNameRIGHT_SHIFT:
3906 return ">>"; //$NON-NLS-1$
3907 case TokenNamePLUS_EQUAL:
3908 return "+="; //$NON-NLS-1$
3909 case TokenNameMINUS_EQUAL:
3910 return "-="; //$NON-NLS-1$
3911 case TokenNameMULTIPLY_EQUAL:
3912 return "*="; //$NON-NLS-1$
3913 case TokenNameDIVIDE_EQUAL:
3914 return "/="; //$NON-NLS-1$
3915 case TokenNameAND_EQUAL:
3916 return "&="; //$NON-NLS-1$
3917 case TokenNameOR_EQUAL:
3918 return "|="; //$NON-NLS-1$
3919 case TokenNameXOR_EQUAL:
3920 return "^="; //$NON-NLS-1$
3921 case TokenNameREMAINDER_EQUAL:
3922 return "%="; //$NON-NLS-1$
3923 case TokenNameDOT_EQUAL:
3924 return ".="; //$NON-NLS-1$
3925 case TokenNameLEFT_SHIFT_EQUAL:
3926 return "<<="; //$NON-NLS-1$
3927 case TokenNameRIGHT_SHIFT_EQUAL:
3928 return ">>="; //$NON-NLS-1$
3929 case TokenNameOR_OR:
3930 return "||"; //$NON-NLS-1$
3931 case TokenNameAND_AND:
3932 return "&&"; //$NON-NLS-1$
3934 return "+"; //$NON-NLS-1$
3935 case TokenNameMINUS:
3936 return "-"; //$NON-NLS-1$
3937 case TokenNameMINUS_GREATER:
3940 return "!"; //$NON-NLS-1$
3941 case TokenNameREMAINDER:
3942 return "%"; //$NON-NLS-1$
3944 return "^"; //$NON-NLS-1$
3946 return "&"; //$NON-NLS-1$
3947 case TokenNameMULTIPLY:
3948 return "*"; //$NON-NLS-1$
3950 return "|"; //$NON-NLS-1$
3951 case TokenNameTWIDDLE:
3952 return "~"; //$NON-NLS-1$
3953 case TokenNameTWIDDLE_EQUAL:
3954 return "~="; //$NON-NLS-1$
3955 case TokenNameDIVIDE:
3956 return "/"; //$NON-NLS-1$
3957 case TokenNameGREATER:
3958 return ">"; //$NON-NLS-1$
3960 return "<"; //$NON-NLS-1$
3961 case TokenNameLPAREN:
3962 return "("; //$NON-NLS-1$
3963 case TokenNameRPAREN:
3964 return ")"; //$NON-NLS-1$
3965 case TokenNameLBRACE:
3966 return "{"; //$NON-NLS-1$
3967 case TokenNameRBRACE:
3968 return "}"; //$NON-NLS-1$
3969 case TokenNameLBRACKET:
3970 return "["; //$NON-NLS-1$
3971 case TokenNameRBRACKET:
3972 return "]"; //$NON-NLS-1$
3973 case TokenNameSEMICOLON:
3974 return ";"; //$NON-NLS-1$
3975 case TokenNameQUESTION:
3976 return "?"; //$NON-NLS-1$
3977 case TokenNameCOLON:
3978 return ":"; //$NON-NLS-1$
3979 case TokenNameCOMMA:
3980 return ","; //$NON-NLS-1$
3982 return "."; //$NON-NLS-1$
3983 case TokenNameEQUAL:
3984 return "="; //$NON-NLS-1$
3987 case TokenNameDOLLAR:
3989 case TokenNameDOLLAR_LBRACE:
3991 case TokenNameLBRACE_DOLLAR:
3994 return "EOF"; //$NON-NLS-1$
3995 case TokenNameWHITESPACE:
3996 return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3997 case TokenNameCOMMENT_LINE:
3998 return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3999 case TokenNameCOMMENT_BLOCK:
4000 return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4001 case TokenNameCOMMENT_PHPDOC:
4002 return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
4003 // case TokenNameHTML :
4004 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
4007 return "__FILE__"; //$NON-NLS-1$
4009 return "__LINE__"; //$NON-NLS-1$
4010 case TokenNameCLASS_C:
4011 return "__CLASS__"; //$NON-NLS-1$
4012 case TokenNameMETHOD_C:
4013 return "__METHOD__"; //$NON-NLS-1$
4014 case TokenNameFUNC_C:
4015 return "__FUNCTION__"; //$NON-NLS-1
4016 case TokenNameboolCAST:
4017 return "( bool )"; //$NON-NLS-1$
4018 case TokenNameintCAST:
4019 return "( int )"; //$NON-NLS-1$
4020 case TokenNamedoubleCAST:
4021 return "( double )"; //$NON-NLS-1$
4022 case TokenNameobjectCAST:
4023 return "( object )"; //$NON-NLS-1$
4024 case TokenNamestringCAST:
4025 return "( string )"; //$NON-NLS-1$
4027 return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$
4035 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
4036 this(tokenizeComments, tokenizeWhiteSpace, false);
4039 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals) {
4040 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, false);
4043 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4044 boolean assertMode) {
4045 this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, assertMode, false, null, null, true);
4048 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals,
4049 boolean assertMode, boolean tokenizeStrings, char[][] taskTags, char[][] taskPriorities, boolean isTaskCaseSensitive) {
4050 this.eofPosition = Integer.MAX_VALUE;
4051 this.tokenizeComments = tokenizeComments;
4052 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
4053 this.tokenizeStrings = tokenizeStrings;
4054 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
4055 this.assertMode = assertMode;
4056 // this.encapsedStringStack = null;
4057 this.taskTags = taskTags;
4058 this.taskPriorities = taskPriorities;
4061 private void checkNonExternalizeString() throws InvalidInputException {
4062 if (currentLine == null)
4064 parseTags(currentLine);
4067 private void parseTags(NLSLine line) throws InvalidInputException {
4068 String s = new String(getCurrentTokenSource());
4069 int pos = s.indexOf(TAG_PREFIX);
4070 int lineLength = line.size();
4072 int start = pos + TAG_PREFIX_LENGTH;
4073 int end = s.indexOf(TAG_POSTFIX, start);
4074 String index = s.substring(start, end);
4077 i = Integer.parseInt(index) - 1;
4078 // Tags are one based not zero based.
4079 } catch (NumberFormatException e) {
4080 i = -1; // we don't want to consider this as a valid NLS tag
4082 if (line.exists(i)) {
4085 pos = s.indexOf(TAG_PREFIX, start);
4087 this.nonNLSStrings = new StringLiteral[lineLength];
4088 int nonNLSCounter = 0;
4089 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
4090 StringLiteral literal = (StringLiteral) iterator.next();
4091 if (literal != null) {
4092 this.nonNLSStrings[nonNLSCounter++] = literal;
4095 if (nonNLSCounter == 0) {
4096 this.nonNLSStrings = null;
4100 this.wasNonExternalizedStringLiteral = true;
4101 if (nonNLSCounter != lineLength) {
4102 System.arraycopy(this.nonNLSStrings, 0, (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, nonNLSCounter);
4107 public final void scanEscapeCharacter() throws InvalidInputException {
4108 // the string with "\\u" is a legal string of two chars \ and u
4109 //thus we use a direct access to the source (for regular cases).
4110 if (unicodeAsBackSlash) {
4111 // consume next character
4112 unicodeAsBackSlash = false;
4113 // if (((currentCharacter = source[currentPosition++]) == '\\') &&
4114 // (source[currentPosition] == 'u')) {
4115 // getNextUnicodeChar();
4117 if (withoutUnicodePtr != 0) {
4118 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
4122 currentCharacter = source[currentPosition++];
4123 switch (currentCharacter) {
4125 currentCharacter = '\b';
4128 currentCharacter = '\t';
4131 currentCharacter = '\n';
4134 currentCharacter = '\f';
4137 currentCharacter = '\r';
4140 currentCharacter = '\"';
4143 currentCharacter = '\'';
4146 currentCharacter = '\\';
4149 // -----------octal escape--------------
4151 // OctalDigit OctalDigit
4152 // ZeroToThree OctalDigit OctalDigit
4153 int number = Character.getNumericValue(currentCharacter);
4154 if (number >= 0 && number <= 7) {
4155 boolean zeroToThreeNot = number > 3;
4156 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4157 int digit = Character.getNumericValue(currentCharacter);
4158 if (digit >= 0 && digit <= 7) {
4159 number = (number * 8) + digit;
4160 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4161 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
4162 // Digit --> ignore last character
4165 digit = Character.getNumericValue(currentCharacter);
4166 if (digit >= 0 && digit <= 7) { // has read \ZeroToThree
4167 // OctalDigit OctalDigit
4168 number = (number * 8) + digit;
4169 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
4170 // --> ignore last character
4174 } else { // has read \OctalDigit NonDigit--> ignore last
4178 } else { // has read \OctalDigit NonOctalDigit--> ignore last
4182 } else { // has read \OctalDigit --> ignore last character
4186 throw new InvalidInputException(INVALID_ESCAPE);
4187 currentCharacter = (char) number;
4189 throw new InvalidInputException(INVALID_ESCAPE);
4193 //chech presence of task: tags
4194 //TODO (frederic) see if we need to take unicode characters into account...
4195 public void checkTaskTag(int commentStart, int commentEnd) {
4196 char[] src = this.source;
4198 // only look for newer task: tags
4199 if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4202 int foundTaskIndex = this.foundTaskCount;
4203 char previous = src[commentStart + 1]; // should be '*' or '/'
4204 nextChar: for (int i = commentStart + 2; i < commentEnd && i < this.eofPosition; i++) {
4206 char[] priority = null;
4207 // check for tag occurrence only if not ambiguous with javadoc tag
4208 if (previous != '@') {
4209 nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4210 tag = this.taskTags[itag];
4211 int tagLength = tag.length;
4215 // ensure tag is not leaded with letter if tag starts with a letter
4216 if (Scanner.isPHPIdentifierStart(tag[0])) {
4217 if (Scanner.isPHPIdentifierPart(previous)) {
4222 for (int t = 0; t < tagLength; t++) {
4225 if (x >= this.eofPosition || x >= commentEnd)
4227 if ((sc = src[i + t]) != (tc = tag[t])) { // case sensitive check
4228 if (this.isTaskCaseSensitive || (Character.toLowerCase(sc) != Character.toLowerCase(tc))) { // case insensitive check
4233 // ensure tag is not followed with letter if tag finishes with a letter
4234 if (i + tagLength < commentEnd && Scanner.isPHPIdentifierPart(src[i + tagLength - 1])) {
4235 if (Scanner.isPHPIdentifierPart(src[i + tagLength]))
4238 if (this.foundTaskTags == null) {
4239 this.foundTaskTags = new char[5][];
4240 this.foundTaskMessages = new char[5][];
4241 this.foundTaskPriorities = new char[5][];
4242 this.foundTaskPositions = new int[5][];
4243 } else if (this.foundTaskCount == this.foundTaskTags.length) {
4244 System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0,
4245 this.foundTaskCount);
4246 System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4247 this.foundTaskCount);
4248 System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4249 this.foundTaskCount);
4250 System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4251 this.foundTaskCount);
4254 priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4256 this.foundTaskTags[this.foundTaskCount] = tag;
4257 this.foundTaskPriorities[this.foundTaskCount] = priority;
4258 this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4259 this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4260 this.foundTaskCount++;
4261 i += tagLength - 1; // will be incremented when looping
4267 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4268 // retrieve message start and end positions
4269 int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4270 int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4271 // at most beginning of next task
4272 if (max_value < msgStart) {
4273 max_value = msgStart; // would only occur if tag is before EOF.
4277 for (int j = msgStart; j < max_value; j++) {
4278 if ((c = src[j]) == '\n' || c == '\r') {
4284 for (int j = max_value; j > msgStart; j--) {
4285 if ((c = src[j]) == '*') {
4293 if (msgStart == end)
4296 while (CharOperation.isWhitespace(src[end]) && msgStart <= end)
4298 while (CharOperation.isWhitespace(src[msgStart]) && msgStart <= end)
4300 // update the end position of the task
4301 this.foundTaskPositions[i][1] = end;
4302 // get the message source
4303 final int messageLength = end - msgStart + 1;
4304 char[] message = new char[messageLength];
4305 System.arraycopy(src, msgStart, message, 0, messageLength);
4306 this.foundTaskMessages[i] = message;
4310 // chech presence of task: tags
4311 // public void checkTaskTag(int commentStart, int commentEnd) {
4312 // // only look for newer task: tags
4313 // if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4316 // int foundTaskIndex = this.foundTaskCount;
4317 // nextChar: for (int i = commentStart; i < commentEnd && i < this.eofPosition; i++) {
4318 // char[] tag = null;
4319 // char[] priority = null;
4320 // // check for tag occurrence
4321 // nextTag: for (int itag = 0; itag < this.taskTags.length; itag++) {
4322 // tag = this.taskTags[itag];
4323 // priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null;
4324 // int tagLength = tag.length;
4325 // for (int t = 0; t < tagLength; t++) {
4326 // if (this.source[i + t] != tag[t])
4327 // continue nextTag;
4329 // if (this.foundTaskTags == null) {
4330 // this.foundTaskTags = new char[5][];
4331 // this.foundTaskMessages = new char[5][];
4332 // this.foundTaskPriorities = new char[5][];
4333 // this.foundTaskPositions = new int[5][];
4334 // } else if (this.foundTaskCount == this.foundTaskTags.length) {
4335 // System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0, this.foundTaskCount);
4336 // System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4337 // this.foundTaskCount);
4338 // System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount * 2][], 0,
4339 // this.foundTaskCount);
4340 // System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4341 // this.foundTaskCount);
4343 // this.foundTaskTags[this.foundTaskCount] = tag;
4344 // this.foundTaskPriorities[this.foundTaskCount] = priority;
4345 // this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 };
4346 // this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4347 // this.foundTaskCount++;
4348 // i += tagLength - 1; // will be incremented when looping
4351 // for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4352 // // retrieve message start and end positions
4353 // int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length;
4354 // int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1;
4355 // // at most beginning of next task
4356 // if (max_value < msgStart)
4357 // max_value = msgStart; // would only occur if tag is before EOF.
4360 // for (int j = msgStart; j < max_value; j++) {
4361 // if ((c = this.source[j]) == '\n' || c == '\r') {
4367 // for (int j = max_value; j > msgStart; j--) {
4368 // if ((c = this.source[j]) == '*') {
4376 // if (msgStart == end)
4377 // continue; // empty
4378 // // trim the message
4379 // while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4381 // while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4383 // // update the end position of the task
4384 // this.foundTaskPositions[i][1] = end;
4385 // // get the message source
4386 // final int messageLength = end - msgStart + 1;
4387 // char[] message = new char[messageLength];
4388 // System.arraycopy(source, msgStart, message, 0, messageLength);
4389 // this.foundTaskMessages[i] = message;