1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.parser;
12 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
15 import java.util.Stack;
17 import net.sourceforge.phpdt.core.compiler.CharOperation;
18 import net.sourceforge.phpdt.core.compiler.IScanner;
19 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
20 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
21 import net.sourceforge.phpeclipse.internal.compiler.ast.StringLiteral;
24 public class Scanner implements IScanner, ITerminalSymbols {
26 * APIs ares - getNextToken() which return the current type of the token
27 * (this value is not memorized by the scanner) - getCurrentTokenSource()
28 * which provides with the token "REAL" source (aka all unicode have been
29 * transformed into a correct char) - sourceStart gives the position into the
30 * stream - currentPosition-1 gives the sourceEnd position into the stream
33 private boolean assertMode;
34 public boolean useAssertAsAnIndentifier = false;
35 //flag indicating if processed source contains occurrences of keyword assert
36 public boolean containsAssertKeyword = false;
37 public boolean recordLineSeparator;
38 public boolean phpMode = false;
39 public Stack encapsedStringStack = null;
40 public char currentCharacter;
41 public int startPosition;
42 public int currentPosition;
43 public int initialPosition, eofPosition;
44 // after this position eof are generated instead of real token from the
46 public boolean tokenizeComments;
47 public boolean tokenizeWhiteSpace;
48 public boolean tokenizeStrings;
49 //source should be viewed as a window (aka a part)
50 //of a entire very large stream
53 public char[] withoutUnicodeBuffer;
54 public int withoutUnicodePtr;
55 //when == 0 ==> no unicode in the current token
56 public boolean unicodeAsBackSlash = false;
57 public boolean scanningFloatLiteral = false;
58 //support for /** comments
59 public int[] commentStops = new int[10];
60 public int[] commentStarts = new int[10];
61 public int commentPtr = -1; // no comment test with commentPtr value -1
62 protected int lastCommentLinePosition = -1;
63 //diet parsing support - jump over some method body when requested
64 public boolean diet = false;
65 //support for the poor-line-debuggers ....
66 //remember the position of the cr/lf
67 public int[] lineEnds = new int[250];
68 public int linePtr = -1;
69 public boolean wasAcr = false;
70 public static final String END_OF_SOURCE = "End_Of_Source"; //$NON-NLS-1$
71 public static final String INVALID_HEXA = "Invalid_Hexa_Literal"; //$NON-NLS-1$
72 public static final String INVALID_OCTAL = "Invalid_Octal_Literal"; //$NON-NLS-1$
73 public static final String INVALID_CHARACTER_CONSTANT = "Invalid_Character_Constant"; //$NON-NLS-1$
74 public static final String INVALID_ESCAPE = "Invalid_Escape"; //$NON-NLS-1$
75 public static final String INVALID_INPUT = "Invalid_Input"; //$NON-NLS-1$
76 public static final String INVALID_UNICODE_ESCAPE = "Invalid_Unicode_Escape"; //$NON-NLS-1$
77 public static final String INVALID_FLOAT = "Invalid_Float_Literal"; //$NON-NLS-1$
78 public static final String NULL_SOURCE_STRING = "Null_Source_String"; //$NON-NLS-1$
79 public static final String UNTERMINATED_STRING = "Unterminated_String"; //$NON-NLS-1$
80 public static final String UNTERMINATED_COMMENT = "Unterminated_Comment"; //$NON-NLS-1$
81 public static final String INVALID_CHAR_IN_STRING = "Invalid_Char_In_String"; //$NON-NLS-1$
82 //----------------optimized identifier managment------------------
83 static final char[] charArray_a = new char[]{'a'},
84 charArray_b = new char[]{'b'}, charArray_c = new char[]{'c'},
85 charArray_d = new char[]{'d'}, charArray_e = new char[]{'e'},
86 charArray_f = new char[]{'f'}, charArray_g = new char[]{'g'},
87 charArray_h = new char[]{'h'}, charArray_i = new char[]{'i'},
88 charArray_j = new char[]{'j'}, charArray_k = new char[]{'k'},
89 charArray_l = new char[]{'l'}, charArray_m = new char[]{'m'},
90 charArray_n = new char[]{'n'}, charArray_o = new char[]{'o'},
91 charArray_p = new char[]{'p'}, charArray_q = new char[]{'q'},
92 charArray_r = new char[]{'r'}, charArray_s = new char[]{'s'},
93 charArray_t = new char[]{'t'}, charArray_u = new char[]{'u'},
94 charArray_v = new char[]{'v'}, charArray_w = new char[]{'w'},
95 charArray_x = new char[]{'x'}, charArray_y = new char[]{'y'},
96 charArray_z = new char[]{'z'};
97 static final char[] initCharArray = new char[]{'\u0000', '\u0000', '\u0000',
98 '\u0000', '\u0000', '\u0000'};
99 static final int TableSize = 30, InternalTableSize = 6;
101 public static final int OptimizedLength = 6;
103 final char[][][][] charArray_length = new char[OptimizedLength][TableSize][InternalTableSize][];
104 // support for detecting non-externalized string literals
105 int currentLineNr = -1;
106 int previousLineNr = -1;
107 NLSLine currentLine = null;
108 List lines = new ArrayList();
109 public static final String TAG_PREFIX = "//$NON-NLS-"; //$NON-NLS-1$
110 public static final int TAG_PREFIX_LENGTH = TAG_PREFIX.length();
111 public static final String TAG_POSTFIX = "$"; //$NON-NLS-1$
112 public static final int TAG_POSTFIX_LENGTH = TAG_POSTFIX.length();
113 public StringLiteral[] nonNLSStrings = null;
114 public boolean checkNonExternalizedStringLiterals = true;
115 public boolean wasNonExternalizedStringLiteral = false;
117 for (int i = 0; i < 6; i++) {
118 for (int j = 0; j < TableSize; j++) {
119 for (int k = 0; k < InternalTableSize; k++) {
120 charArray_length[i][j][k] = initCharArray;
125 static int newEntry2 = 0, newEntry3 = 0, newEntry4 = 0, newEntry5 = 0,
127 public static final int RoundBracket = 0;
128 public static final int SquareBracket = 1;
129 public static final int CurlyBracket = 2;
130 public static final int BracketKinds = 3;
132 public char[][] foundTaskTags = null;
133 public char[][] foundTaskMessages;
134 public char[][] foundTaskPriorities = null;
135 public int[][] foundTaskPositions;
136 public int foundTaskCount = 0;
137 public char[][] taskTags = null;
138 public char[][] taskPriorities = null;
139 public static final boolean DEBUG = false;
140 public static final boolean TRACE = false;
143 * Determines if the specified character is permissible as the first
144 * character in a PHP identifier
146 public static boolean isPHPIdentifierStart(char ch) {
147 return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF);
150 * Determines if the specified character may be part of a PHP identifier as
151 * other than the first character
153 public static boolean isPHPIdentifierPart(char ch) {
154 return Character.isLetterOrDigit(ch) || (ch == '_')
155 || (0x7F <= ch && ch <= 0xFF);
157 public final boolean atEnd() {
158 // This code is not relevant if source is
159 // Only a part of the real stream input
160 return source.length == currentPosition;
162 public char[] getCurrentIdentifierSource() {
163 //return the token REAL source (aka unicodes are precomputed)
165 // if (withoutUnicodePtr != 0)
166 // //0 is used as a fast test flag so the real first char is in position 1
168 // withoutUnicodeBuffer,
170 // result = new char[withoutUnicodePtr],
172 // withoutUnicodePtr);
174 int length = currentPosition - startPosition;
175 switch (length) { // see OptimizedLength
177 return optimizedCurrentTokenSource1();
179 return optimizedCurrentTokenSource2();
181 return optimizedCurrentTokenSource3();
183 return optimizedCurrentTokenSource4();
185 return optimizedCurrentTokenSource5();
187 return optimizedCurrentTokenSource6();
190 System.arraycopy(source, startPosition, result = new char[length], 0,
195 public int getCurrentTokenEndPosition() {
196 return this.currentPosition - 1;
198 public final char[] getCurrentTokenSource() {
199 // Return the token REAL source (aka unicodes are precomputed)
201 // if (withoutUnicodePtr != 0)
202 // // 0 is used as a fast test flag so the real first char is in position 1
204 // withoutUnicodeBuffer,
206 // result = new char[withoutUnicodePtr],
208 // withoutUnicodePtr);
211 System.arraycopy(source, startPosition,
212 result = new char[length = currentPosition - startPosition], 0, length);
216 public final char[] getCurrentTokenSource(int startPos) {
217 // Return the token REAL source (aka unicodes are precomputed)
219 // if (withoutUnicodePtr != 0)
220 // // 0 is used as a fast test flag so the real first char is in position 1
222 // withoutUnicodeBuffer,
224 // result = new char[withoutUnicodePtr],
226 // withoutUnicodePtr);
229 System.arraycopy(source, startPos,
230 result = new char[length = currentPosition - startPos], 0, length);
234 public final char[] getCurrentTokenSourceString() {
235 //return the token REAL source (aka unicodes are precomputed).
236 //REMOVE the two " that are at the beginning and the end.
238 if (withoutUnicodePtr != 0)
239 //0 is used as a fast test flag so the real first char is in position 1
240 System.arraycopy(withoutUnicodeBuffer, 2,
241 //2 is 1 (real start) + 1 (to jump over the ")
242 result = new char[withoutUnicodePtr - 2], 0, withoutUnicodePtr - 2);
245 System.arraycopy(source, startPosition + 1,
246 result = new char[length = currentPosition - startPosition - 2], 0,
251 public int getCurrentTokenStartPosition() {
252 return this.startPosition;
254 public final char[] getCurrentStringLiteralSource() {
255 // Return the token REAL source (aka unicodes are precomputed)
258 System.arraycopy(source, startPosition + 1,
259 result = new char[length = currentPosition - startPosition - 2], 0,
265 * Search the source position corresponding to the end of a given line number
267 * Line numbers are 1-based, and relative to the scanner initialPosition.
268 * Character positions are 0-based.
270 * In case the given line number is inconsistent, answers -1.
272 public final int getLineEnd(int lineNumber) {
273 if (lineEnds == null)
275 if (lineNumber >= lineEnds.length)
279 if (lineNumber == lineEnds.length - 1)
281 return lineEnds[lineNumber - 1];
282 // next line start one character behind the lineEnd of the previous line
285 * Search the source position corresponding to the beginning of a given line
288 * Line numbers are 1-based, and relative to the scanner initialPosition.
289 * Character positions are 0-based.
291 * e.g. getLineStart(1) --> 0 i.e. first line starts at character 0.
293 * In case the given line number is inconsistent, answers -1.
295 public final int getLineStart(int lineNumber) {
296 if (lineEnds == null)
298 if (lineNumber >= lineEnds.length)
303 return initialPosition;
304 return lineEnds[lineNumber - 2] + 1;
305 // next line start one character behind the lineEnd of the previous line
307 public final boolean getNextChar(char testedChar) {
309 //handle the case of unicode.
310 //when a unicode appears then we must use a buffer that holds char
312 //At the end of this method currentCharacter holds the new visited char
313 //and currentPosition points right next after it
314 //Both previous lines are true if the currentCharacter is == to the
316 //On false, no side effect has occured.
317 //ALL getNextChar.... ARE OPTIMIZED COPIES
318 int temp = currentPosition;
320 currentCharacter = source[currentPosition++];
321 // if (((currentCharacter = source[currentPosition++]) == '\\')
322 // && (source[currentPosition] == 'u')) {
323 // //-------------unicode traitement ------------
324 // int c1, c2, c3, c4;
325 // int unicodeSize = 6;
326 // currentPosition++;
327 // while (source[currentPosition] == 'u') {
328 // currentPosition++;
332 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
334 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
336 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
338 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
340 // currentPosition = temp;
344 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
345 // if (currentCharacter != testedChar) {
346 // currentPosition = temp;
349 // unicodeAsBackSlash = currentCharacter == '\\';
351 // //need the unicode buffer
352 // if (withoutUnicodePtr == 0) {
353 // //buffer all the entries that have been left aside....
354 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
358 // withoutUnicodeBuffer,
360 // withoutUnicodePtr);
362 // //fill the buffer with the char
363 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
366 // } //-------------end unicode traitement--------------
368 if (currentCharacter != testedChar) {
369 currentPosition = temp;
372 unicodeAsBackSlash = false;
373 // if (withoutUnicodePtr != 0)
374 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
377 } catch (IndexOutOfBoundsException e) {
378 unicodeAsBackSlash = false;
379 currentPosition = temp;
383 public final int getNextChar(char testedChar1, char testedChar2) {
384 //INT 0 : testChar1 \\\\///\\\\ 1 : testedChar2 \\\\///\\\\ -1 : others
385 //test can be done with (x==0) for the first and (x>0) for the second
386 //handle the case of unicode.
387 //when a unicode appears then we must use a buffer that holds char
389 //At the end of this method currentCharacter holds the new visited char
390 //and currentPosition points right next after it
391 //Both previous lines are true if the currentCharacter is == to the
393 //On false, no side effect has occured.
394 //ALL getNextChar.... ARE OPTIMIZED COPIES
395 int temp = currentPosition;
398 currentCharacter = source[currentPosition++];
399 // if (((currentCharacter = source[currentPosition++]) == '\\')
400 // && (source[currentPosition] == 'u')) {
401 // //-------------unicode traitement ------------
402 // int c1, c2, c3, c4;
403 // int unicodeSize = 6;
404 // currentPosition++;
405 // while (source[currentPosition] == 'u') {
406 // currentPosition++;
410 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
412 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
414 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
416 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
418 // currentPosition = temp;
422 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
423 // if (currentCharacter == testedChar1)
425 // else if (currentCharacter == testedChar2)
428 // currentPosition = temp;
432 // //need the unicode buffer
433 // if (withoutUnicodePtr == 0) {
434 // //buffer all the entries that have been left aside....
435 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
439 // withoutUnicodeBuffer,
441 // withoutUnicodePtr);
443 // //fill the buffer with the char
444 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
446 // } //-------------end unicode traitement--------------
448 if (currentCharacter == testedChar1)
450 else if (currentCharacter == testedChar2)
453 currentPosition = temp;
456 // if (withoutUnicodePtr != 0)
457 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
460 } catch (IndexOutOfBoundsException e) {
461 currentPosition = temp;
465 public final boolean getNextCharAsDigit() {
467 //handle the case of unicode.
468 //when a unicode appears then we must use a buffer that holds char
470 //At the end of this method currentCharacter holds the new visited char
471 //and currentPosition points right next after it
472 //Both previous lines are true if the currentCharacter is a digit
473 //On false, no side effect has occured.
474 //ALL getNextChar.... ARE OPTIMIZED COPIES
475 int temp = currentPosition;
477 currentCharacter = source[currentPosition++];
478 // if (((currentCharacter = source[currentPosition++]) == '\\')
479 // && (source[currentPosition] == 'u')) {
480 // //-------------unicode traitement ------------
481 // int c1, c2, c3, c4;
482 // int unicodeSize = 6;
483 // currentPosition++;
484 // while (source[currentPosition] == 'u') {
485 // currentPosition++;
489 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
491 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
493 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
495 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
497 // currentPosition = temp;
501 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
502 // if (!Character.isDigit(currentCharacter)) {
503 // currentPosition = temp;
507 // //need the unicode buffer
508 // if (withoutUnicodePtr == 0) {
509 // //buffer all the entries that have been left aside....
510 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
514 // withoutUnicodeBuffer,
516 // withoutUnicodePtr);
518 // //fill the buffer with the char
519 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
521 // } //-------------end unicode traitement--------------
523 if (!Character.isDigit(currentCharacter)) {
524 currentPosition = temp;
527 // if (withoutUnicodePtr != 0)
528 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
531 } catch (IndexOutOfBoundsException e) {
532 currentPosition = temp;
536 public final boolean getNextCharAsDigit(int radix) {
538 //handle the case of unicode.
539 //when a unicode appears then we must use a buffer that holds char
541 //At the end of this method currentCharacter holds the new visited char
542 //and currentPosition points right next after it
543 //Both previous lines are true if the currentCharacter is a digit base on
545 //On false, no side effect has occured.
546 //ALL getNextChar.... ARE OPTIMIZED COPIES
547 int temp = currentPosition;
549 currentCharacter = source[currentPosition++];
550 // if (((currentCharacter = source[currentPosition++]) == '\\')
551 // && (source[currentPosition] == 'u')) {
552 // //-------------unicode traitement ------------
553 // int c1, c2, c3, c4;
554 // int unicodeSize = 6;
555 // currentPosition++;
556 // while (source[currentPosition] == 'u') {
557 // currentPosition++;
561 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
563 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
565 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
567 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
569 // currentPosition = temp;
573 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
574 // if (Character.digit(currentCharacter, radix) == -1) {
575 // currentPosition = temp;
579 // //need the unicode buffer
580 // if (withoutUnicodePtr == 0) {
581 // //buffer all the entries that have been left aside....
582 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
586 // withoutUnicodeBuffer,
588 // withoutUnicodePtr);
590 // //fill the buffer with the char
591 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
593 // } //-------------end unicode traitement--------------
595 if (Character.digit(currentCharacter, radix) == -1) {
596 currentPosition = temp;
599 // if (withoutUnicodePtr != 0)
600 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
603 } catch (IndexOutOfBoundsException e) {
604 currentPosition = temp;
608 public boolean getNextCharAsJavaIdentifierPart() {
610 //handle the case of unicode.
611 //when a unicode appears then we must use a buffer that holds char
613 //At the end of this method currentCharacter holds the new visited char
614 //and currentPosition points right next after it
615 //Both previous lines are true if the currentCharacter is a
616 // JavaIdentifierPart
617 //On false, no side effect has occured.
618 //ALL getNextChar.... ARE OPTIMIZED COPIES
619 int temp = currentPosition;
621 currentCharacter = source[currentPosition++];
622 // if (((currentCharacter = source[currentPosition++]) == '\\')
623 // && (source[currentPosition] == 'u')) {
624 // //-------------unicode traitement ------------
625 // int c1, c2, c3, c4;
626 // int unicodeSize = 6;
627 // currentPosition++;
628 // while (source[currentPosition] == 'u') {
629 // currentPosition++;
633 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
635 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
637 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
639 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
641 // currentPosition = temp;
645 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
646 // if (!isPHPIdentifierPart(currentCharacter)) {
647 // currentPosition = temp;
651 // //need the unicode buffer
652 // if (withoutUnicodePtr == 0) {
653 // //buffer all the entries that have been left aside....
654 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
658 // withoutUnicodeBuffer,
660 // withoutUnicodePtr);
662 // //fill the buffer with the char
663 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
665 // } //-------------end unicode traitement--------------
667 if (!isPHPIdentifierPart(currentCharacter)) {
668 currentPosition = temp;
671 // if (withoutUnicodePtr != 0)
672 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
675 } catch (IndexOutOfBoundsException e) {
676 currentPosition = temp;
680 public int getCastOrParen() {
681 int tempPosition = currentPosition;
682 char tempCharacter = currentCharacter;
683 int tempToken = TokenNameLPAREN;
684 boolean found = false;
685 StringBuffer buf = new StringBuffer();
688 currentCharacter = source[currentPosition++];
689 } while (currentCharacter == ' ' || currentCharacter == '\t');
690 while ((currentCharacter >= 'a' && currentCharacter <= 'z')
691 || (currentCharacter >= 'A' && currentCharacter <= 'Z')) {
692 buf.append(currentCharacter);
693 currentCharacter = source[currentPosition++];
695 if (buf.length() >= 3 && buf.length() <= 7) {
696 char[] data = buf.toString().toCharArray();
698 switch (data.length) {
701 if ((data[index] == 'i') && (data[++index] == 'n')
702 && (data[++index] == 't')) {
704 tempToken = TokenNameintCAST;
709 if ((data[index] == 'b') && (data[++index] == 'o')
710 && (data[++index] == 'o') && (data[++index] == 'l')) {
712 tempToken = TokenNameboolCAST;
715 if ((data[index] == 'r') && (data[++index] == 'e')
716 && (data[++index] == 'a') && (data[++index] == 'l')) {
718 tempToken = TokenNamedoubleCAST;
724 if ((data[index] == 'a') && (data[++index] == 'r')
725 && (data[++index] == 'r') && (data[++index] == 'a')
726 && (data[++index] == 'y')) {
728 tempToken = TokenNamearrayCAST;
731 if ((data[index] == 'u') && (data[++index] == 'n')
732 && (data[++index] == 's') && (data[++index] == 'e')
733 && (data[++index] == 't')) {
735 tempToken = TokenNameunsetCAST;
738 if ((data[index] == 'f') && (data[++index] == 'l')
739 && (data[++index] == 'o') && (data[++index] == 'a')
740 && (data[++index] == 't')) {
742 tempToken = TokenNamedoubleCAST;
748 // object string double
749 if ((data[index] == 'o') && (data[++index] == 'b')
750 && (data[++index] == 'j') && (data[++index] == 'e')
751 && (data[++index] == 'c') && (data[++index] == 't')) {
753 tempToken = TokenNameobjectCAST;
756 if ((data[index] == 's') && (data[++index] == 't')
757 && (data[++index] == 'r') && (data[++index] == 'i')
758 && (data[++index] == 'n') && (data[++index] == 'g')) {
760 tempToken = TokenNamestringCAST;
763 if ((data[index] == 'd') && (data[++index] == 'o')
764 && (data[++index] == 'u') && (data[++index] == 'b')
765 && (data[++index] == 'l') && (data[++index] == 'e')) {
767 tempToken = TokenNamedoubleCAST;
774 if ((data[index] == 'b') && (data[++index] == 'o')
775 && (data[++index] == 'o') && (data[++index] == 'l')
776 && (data[++index] == 'e') && (data[++index] == 'a')
777 && (data[++index] == 'n')) {
779 tempToken = TokenNameboolCAST;
782 if ((data[index] == 'i') && (data[++index] == 'n')
783 && (data[++index] == 't') && (data[++index] == 'e')
784 && (data[++index] == 'g') && (data[++index] == 'e')
785 && (data[++index] == 'r')) {
787 tempToken = TokenNameintCAST;
793 while (currentCharacter == ' ' || currentCharacter == '\t') {
794 currentCharacter = source[currentPosition++];
796 if (currentCharacter == ')') {
801 } catch (IndexOutOfBoundsException e) {
803 currentCharacter = tempCharacter;
804 currentPosition = tempPosition;
805 return TokenNameLPAREN;
807 public void consumeStringInterpolated() throws InvalidInputException {
809 // consume next character
810 unicodeAsBackSlash = false;
811 currentCharacter = source[currentPosition++];
812 // if (((currentCharacter = source[currentPosition++]) == '\\')
813 // && (source[currentPosition] == 'u')) {
814 // getNextUnicodeChar();
816 // if (withoutUnicodePtr != 0) {
817 // withoutUnicodeBuffer[++withoutUnicodePtr] =
821 while (currentCharacter != '`') {
822 /** ** in PHP \r and \n are valid in string literals *** */
823 // if ((currentCharacter == '\n')
824 // || (currentCharacter == '\r')) {
825 // // relocate if finding another quote fairly close: thus unicode
826 // '/u000D' will be fully consumed
827 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
828 // if (currentPosition + lookAhead == source.length)
830 // if (source[currentPosition + lookAhead] == '\n')
832 // if (source[currentPosition + lookAhead] == '\"') {
833 // currentPosition += lookAhead + 1;
837 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
839 if (currentCharacter == '\\') {
840 int escapeSize = currentPosition;
841 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
842 //scanEscapeCharacter make a side effect on this value and we need
843 // the previous value few lines down this one
844 scanDoubleQuotedEscapeCharacter();
845 escapeSize = currentPosition - escapeSize;
846 if (withoutUnicodePtr == 0) {
847 //buffer all the entries that have been left aside....
848 withoutUnicodePtr = currentPosition - escapeSize - 1
850 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1,
852 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
853 } else { //overwrite the / in the buffer
854 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
855 if (backSlashAsUnicodeInString) { //there are TWO \ in the stream
856 // where only one is correct
861 // consume next character
862 unicodeAsBackSlash = false;
863 currentCharacter = source[currentPosition++];
864 // if (((currentCharacter = source[currentPosition++]) == '\\')
865 // && (source[currentPosition] == 'u')) {
866 // getNextUnicodeChar();
868 if (withoutUnicodePtr != 0) {
869 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
873 } catch (IndexOutOfBoundsException e) {
874 throw new InvalidInputException(UNTERMINATED_STRING);
875 } catch (InvalidInputException e) {
876 if (e.getMessage().equals(INVALID_ESCAPE)) {
877 // relocate if finding another quote fairly close: thus unicode
878 // '/u000D' will be fully consumed
879 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
880 if (currentPosition + lookAhead == source.length)
882 if (source[currentPosition + lookAhead] == '\n')
884 if (source[currentPosition + lookAhead] == '`') {
885 currentPosition += lookAhead + 1;
892 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
893 // //$NON-NLS-?$ where ? is an
895 if (currentLine == null) {
896 currentLine = new NLSLine();
897 lines.add(currentLine);
899 currentLine.add(new StringLiteral(getCurrentTokenSourceString(),
900 startPosition, currentPosition - 1));
903 public void consumeStringConstant() throws InvalidInputException {
905 // consume next character
906 unicodeAsBackSlash = false;
907 currentCharacter = source[currentPosition++];
908 // if (((currentCharacter = source[currentPosition++]) == '\\')
909 // && (source[currentPosition] == 'u')) {
910 // getNextUnicodeChar();
912 // if (withoutUnicodePtr != 0) {
913 // withoutUnicodeBuffer[++withoutUnicodePtr] =
917 while (currentCharacter != '\'') {
918 /** ** in PHP \r and \n are valid in string literals *** */
919 // if ((currentCharacter == '\n')
920 // || (currentCharacter == '\r')) {
921 // // relocate if finding another quote fairly close: thus unicode
922 // '/u000D' will be fully consumed
923 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
924 // if (currentPosition + lookAhead == source.length)
926 // if (source[currentPosition + lookAhead] == '\n')
928 // if (source[currentPosition + lookAhead] == '\"') {
929 // currentPosition += lookAhead + 1;
933 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
935 if (currentCharacter == '\\') {
936 int escapeSize = currentPosition;
937 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
938 //scanEscapeCharacter make a side effect on this value and we need
939 // the previous value few lines down this one
940 scanSingleQuotedEscapeCharacter();
941 escapeSize = currentPosition - escapeSize;
942 if (withoutUnicodePtr == 0) {
943 //buffer all the entries that have been left aside....
944 withoutUnicodePtr = currentPosition - escapeSize - 1
946 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1,
948 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
949 } else { //overwrite the / in the buffer
950 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
951 if (backSlashAsUnicodeInString) { //there are TWO \ in the stream
952 // where only one is correct
957 // consume next character
958 unicodeAsBackSlash = false;
959 currentCharacter = source[currentPosition++];
960 // if (((currentCharacter = source[currentPosition++]) == '\\')
961 // && (source[currentPosition] == 'u')) {
962 // getNextUnicodeChar();
964 if (withoutUnicodePtr != 0) {
965 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
969 } catch (IndexOutOfBoundsException e) {
970 throw new InvalidInputException(UNTERMINATED_STRING);
971 } catch (InvalidInputException e) {
972 if (e.getMessage().equals(INVALID_ESCAPE)) {
973 // relocate if finding another quote fairly close: thus unicode
974 // '/u000D' will be fully consumed
975 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
976 if (currentPosition + lookAhead == source.length)
978 if (source[currentPosition + lookAhead] == '\n')
980 if (source[currentPosition + lookAhead] == '\'') {
981 currentPosition += lookAhead + 1;
988 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
989 // //$NON-NLS-?$ where ? is an
991 if (currentLine == null) {
992 currentLine = new NLSLine();
993 lines.add(currentLine);
995 currentLine.add(new StringLiteral(getCurrentTokenSourceString(),
996 startPosition, currentPosition - 1));
999 public void consumeStringLiteral() throws InvalidInputException {
1001 // consume next character
1002 unicodeAsBackSlash = false;
1003 currentCharacter = source[currentPosition++];
1004 // if (((currentCharacter = source[currentPosition++]) == '\\')
1005 // && (source[currentPosition] == 'u')) {
1006 // getNextUnicodeChar();
1008 // if (withoutUnicodePtr != 0) {
1009 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1010 // currentCharacter;
1013 while (currentCharacter != '"') {
1014 /** ** in PHP \r and \n are valid in string literals *** */
1015 // if ((currentCharacter == '\n')
1016 // || (currentCharacter == '\r')) {
1017 // // relocate if finding another quote fairly close: thus unicode
1018 // '/u000D' will be fully consumed
1019 // for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1020 // if (currentPosition + lookAhead == source.length)
1022 // if (source[currentPosition + lookAhead] == '\n')
1024 // if (source[currentPosition + lookAhead] == '\"') {
1025 // currentPosition += lookAhead + 1;
1029 // throw new InvalidInputException(INVALID_CHAR_IN_STRING);
1031 if (currentCharacter == '\\') {
1032 int escapeSize = currentPosition;
1033 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1034 //scanEscapeCharacter make a side effect on this value and we need
1035 // the previous value few lines down this one
1036 scanDoubleQuotedEscapeCharacter();
1037 escapeSize = currentPosition - escapeSize;
1038 if (withoutUnicodePtr == 0) {
1039 //buffer all the entries that have been left aside....
1040 withoutUnicodePtr = currentPosition - escapeSize - 1
1042 System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1,
1044 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1045 } else { //overwrite the / in the buffer
1046 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1047 if (backSlashAsUnicodeInString) { //there are TWO \ in the stream
1048 // where only one is correct
1049 withoutUnicodePtr--;
1053 // consume next character
1054 unicodeAsBackSlash = false;
1055 currentCharacter = source[currentPosition++];
1056 // if (((currentCharacter = source[currentPosition++]) == '\\')
1057 // && (source[currentPosition] == 'u')) {
1058 // getNextUnicodeChar();
1060 if (withoutUnicodePtr != 0) {
1061 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1065 } catch (IndexOutOfBoundsException e) {
1066 throw new InvalidInputException(UNTERMINATED_STRING);
1067 } catch (InvalidInputException e) {
1068 if (e.getMessage().equals(INVALID_ESCAPE)) {
1069 // relocate if finding another quote fairly close: thus unicode
1070 // '/u000D' will be fully consumed
1071 for (int lookAhead = 0; lookAhead < 50; lookAhead++) {
1072 if (currentPosition + lookAhead == source.length)
1074 if (source[currentPosition + lookAhead] == '\n')
1076 if (source[currentPosition + lookAhead] == '\"') {
1077 currentPosition += lookAhead + 1;
1084 if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
1085 // //$NON-NLS-?$ where ? is an
1087 if (currentLine == null) {
1088 currentLine = new NLSLine();
1089 lines.add(currentLine);
1091 currentLine.add(new StringLiteral(getCurrentTokenSourceString(),
1092 startPosition, currentPosition - 1));
1095 public int getNextToken() throws InvalidInputException {
1097 return getInlinedHTML(currentPosition);
1100 this.wasAcr = false;
1102 jumpOverMethodBody();
1104 return currentPosition > source.length ? TokenNameEOF : TokenNameRBRACE;
1108 withoutUnicodePtr = 0;
1109 //start with a new token
1110 char encapsedChar = ' ';
1111 if (!encapsedStringStack.isEmpty()) {
1112 encapsedChar = ((Character) encapsedStringStack.peek()).charValue();
1114 if (encapsedChar != '$' && encapsedChar != ' ') {
1115 currentCharacter = source[currentPosition++];
1116 if (currentCharacter == encapsedChar) {
1117 switch (currentCharacter) {
1119 return TokenNameEncapsedString0;
1121 return TokenNameEncapsedString1;
1123 return TokenNameEncapsedString2;
1126 while (currentCharacter != encapsedChar) {
1127 /** ** in PHP \r and \n are valid in string literals *** */
1128 switch (currentCharacter) {
1130 int escapeSize = currentPosition;
1131 boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
1132 //scanEscapeCharacter make a side effect on this value and
1133 // we need the previous value few lines down this one
1134 scanDoubleQuotedEscapeCharacter();
1135 escapeSize = currentPosition - escapeSize;
1136 if (withoutUnicodePtr == 0) {
1137 //buffer all the entries that have been left aside....
1138 withoutUnicodePtr = currentPosition - escapeSize - 1
1140 System.arraycopy(source, startPosition,
1141 withoutUnicodeBuffer, 1, withoutUnicodePtr);
1142 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1143 } else { //overwrite the / in the buffer
1144 withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
1145 if (backSlashAsUnicodeInString) { //there are TWO \ in
1146 withoutUnicodePtr--;
1151 if (isPHPIdentifierStart(source[currentPosition])
1152 || source[currentPosition] == '{') {
1154 encapsedStringStack.push(new Character('$'));
1155 return TokenNameSTRING;
1159 if (source[currentPosition] == '$') { // CURLY_OPEN
1161 encapsedStringStack.push(new Character('$'));
1162 return TokenNameSTRING;
1165 // consume next character
1166 unicodeAsBackSlash = false;
1167 currentCharacter = source[currentPosition++];
1168 if (withoutUnicodePtr != 0) {
1169 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1174 return TokenNameSTRING;
1176 // ---------Consume white space and handles startPosition---------
1177 int whiteStart = currentPosition;
1178 startPosition = currentPosition;
1179 currentCharacter = source[currentPosition++];
1180 if (encapsedChar == '$') {
1181 switch (currentCharacter) {
1183 currentCharacter = source[currentPosition++];
1184 return TokenNameSTRING;
1186 if (encapsedChar == '$') {
1187 if (getNextChar('$'))
1188 return TokenNameCURLY_OPEN;
1190 return TokenNameLBRACE;
1192 return TokenNameRBRACE;
1194 return TokenNameLBRACKET;
1196 return TokenNameRBRACKET;
1198 if (tokenizeStrings) {
1199 consumeStringConstant();
1200 return TokenNameStringSingleQuote;
1202 return TokenNameEncapsedString1;
1204 return TokenNameEncapsedString2;
1206 if (tokenizeStrings) {
1207 consumeStringInterpolated();
1208 return TokenNameStringInterpolated;
1210 return TokenNameEncapsedString0;
1212 if (getNextChar('>'))
1213 return TokenNameMINUS_GREATER;
1214 return TokenNameSTRING;
1216 if (currentCharacter == '$') {
1217 int oldPosition = currentPosition;
1219 currentCharacter = source[currentPosition++];
1220 if (currentCharacter == '{') {
1221 return TokenNameDOLLAR_LBRACE;
1223 if (isPHPIdentifierStart(currentCharacter)) {
1224 return scanIdentifierOrKeyword(true);
1226 currentPosition = oldPosition;
1227 return TokenNameSTRING;
1229 } catch (IndexOutOfBoundsException e) {
1230 currentPosition = oldPosition;
1231 return TokenNameSTRING;
1234 if (isPHPIdentifierStart(currentCharacter))
1235 return scanIdentifierOrKeyword(false);
1236 if (Character.isDigit(currentCharacter))
1237 return scanNumber(false);
1238 return TokenNameERROR;
1241 // boolean isWhiteSpace;
1243 while ((currentCharacter == ' ')
1244 || Character.isWhitespace(currentCharacter)) {
1245 startPosition = currentPosition;
1246 currentCharacter = source[currentPosition++];
1247 // if (((currentCharacter = source[currentPosition++]) == '\\')
1248 // && (source[currentPosition] == 'u')) {
1249 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
1251 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1252 checkNonExternalizeString();
1253 if (recordLineSeparator) {
1254 pushLineSeparator();
1259 // isWhiteSpace = (currentCharacter == ' ')
1260 // || Character.isWhitespace(currentCharacter);
1263 if (tokenizeWhiteSpace && (whiteStart != currentPosition - 1)) {
1264 // reposition scanner in case we are interested by spaces as tokens
1266 startPosition = whiteStart;
1267 return TokenNameWHITESPACE;
1269 //little trick to get out in the middle of a source compuation
1270 if (currentPosition > eofPosition)
1271 return TokenNameEOF;
1272 // ---------Identify the next token-------------
1273 switch (currentCharacter) {
1275 return getCastOrParen();
1277 return TokenNameRPAREN;
1279 return TokenNameLBRACE;
1281 return TokenNameRBRACE;
1283 return TokenNameLBRACKET;
1285 return TokenNameRBRACKET;
1287 return TokenNameSEMICOLON;
1289 return TokenNameCOMMA;
1291 if (getNextChar('='))
1292 return TokenNameDOT_EQUAL;
1293 if (getNextCharAsDigit())
1294 return scanNumber(true);
1295 return TokenNameDOT;
1299 if ((test = getNextChar('+', '=')) == 0)
1300 return TokenNamePLUS_PLUS;
1302 return TokenNamePLUS_EQUAL;
1303 return TokenNamePLUS;
1308 if ((test = getNextChar('-', '=')) == 0)
1309 return TokenNameMINUS_MINUS;
1311 return TokenNameMINUS_EQUAL;
1312 if (getNextChar('>'))
1313 return TokenNameMINUS_GREATER;
1314 return TokenNameMINUS;
1317 if (getNextChar('='))
1318 return TokenNameTWIDDLE_EQUAL;
1319 return TokenNameTWIDDLE;
1321 if (getNextChar('=')) {
1322 if (getNextChar('=')) {
1323 return TokenNameNOT_EQUAL_EQUAL;
1325 return TokenNameNOT_EQUAL;
1327 return TokenNameNOT;
1329 if (getNextChar('='))
1330 return TokenNameMULTIPLY_EQUAL;
1331 return TokenNameMULTIPLY;
1333 if (getNextChar('='))
1334 return TokenNameREMAINDER_EQUAL;
1335 return TokenNameREMAINDER;
1338 int oldPosition = currentPosition;
1340 currentCharacter = source[currentPosition++];
1341 } catch (IndexOutOfBoundsException e) {
1342 currentPosition = oldPosition;
1343 return TokenNameLESS;
1345 switch (currentCharacter) {
1347 return TokenNameLESS_EQUAL;
1349 return TokenNameNOT_EQUAL;
1351 if (getNextChar('='))
1352 return TokenNameLEFT_SHIFT_EQUAL;
1353 if (getNextChar('<')) {
1354 currentCharacter = source[currentPosition++];
1355 while (Character.isWhitespace(currentCharacter)) {
1356 currentCharacter = source[currentPosition++];
1358 int heredocStart = currentPosition - 1;
1359 int heredocLength = 0;
1360 if (isPHPIdentifierStart(currentCharacter)) {
1361 currentCharacter = source[currentPosition++];
1363 return TokenNameERROR;
1365 while (isPHPIdentifierPart(currentCharacter)) {
1366 currentCharacter = source[currentPosition++];
1368 heredocLength = currentPosition - heredocStart - 1;
1369 // heredoc end-tag determination
1370 boolean endTag = true;
1373 ch = source[currentPosition++];
1374 if (ch == '\r' || ch == '\n') {
1375 if (recordLineSeparator) {
1376 pushLineSeparator();
1380 for (int i = 0; i < heredocLength; i++) {
1381 if (source[currentPosition + i] != source[heredocStart
1388 currentPosition += heredocLength - 1;
1389 currentCharacter = source[currentPosition++];
1390 break; // do...while loop
1396 return TokenNameHEREDOC;
1398 return TokenNameLEFT_SHIFT;
1400 currentPosition = oldPosition;
1401 return TokenNameLESS;
1406 if ((test = getNextChar('=', '>')) == 0)
1407 return TokenNameGREATER_EQUAL;
1409 if ((test = getNextChar('=', '>')) == 0)
1410 return TokenNameRIGHT_SHIFT_EQUAL;
1411 return TokenNameRIGHT_SHIFT;
1413 return TokenNameGREATER;
1416 if (getNextChar('=')) {
1417 if (getNextChar('=')) {
1418 return TokenNameEQUAL_EQUAL_EQUAL;
1420 return TokenNameEQUAL_EQUAL;
1422 if (getNextChar('>'))
1423 return TokenNameEQUAL_GREATER;
1424 return TokenNameEQUAL;
1428 if ((test = getNextChar('&', '=')) == 0)
1429 return TokenNameAND_AND;
1431 return TokenNameAND_EQUAL;
1432 return TokenNameAND;
1437 if ((test = getNextChar('|', '=')) == 0)
1438 return TokenNameOR_OR;
1440 return TokenNameOR_EQUAL;
1444 if (getNextChar('='))
1445 return TokenNameXOR_EQUAL;
1446 return TokenNameXOR;
1448 if (getNextChar('>')) {
1450 if (currentPosition == source.length) {
1452 return TokenNameINLINE_HTML;
1454 return getInlinedHTML(currentPosition - 2);
1456 return TokenNameQUESTION;
1458 if (getNextChar(':'))
1459 return TokenNamePAAMAYIM_NEKUDOTAYIM;
1460 return TokenNameCOLON;
1464 consumeStringConstant();
1465 return TokenNameStringSingleQuote;
1467 if (tokenizeStrings) {
1468 consumeStringLiteral();
1469 return TokenNameStringDoubleQuote;
1471 return TokenNameEncapsedString2;
1473 if (tokenizeStrings) {
1474 consumeStringInterpolated();
1475 return TokenNameStringInterpolated;
1477 return TokenNameEncapsedString0;
1481 char startChar = currentCharacter;
1482 if (getNextChar('=')) {
1483 return TokenNameDIVIDE_EQUAL;
1486 if ((startChar == '#') || (test = getNextChar('/', '*')) == 0) {
1488 this.lastCommentLinePosition = this.currentPosition;
1489 int endPositionForLineComment = 0;
1490 try { //get the next char
1491 currentCharacter = source[currentPosition++];
1492 // if (((currentCharacter = source[currentPosition++])
1494 // && (source[currentPosition] == 'u')) {
1495 // //-------------unicode traitement ------------
1496 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1497 // currentPosition++;
1498 // while (source[currentPosition] == 'u') {
1499 // currentPosition++;
1502 // Character.getNumericValue(source[currentPosition++]))
1506 // Character.getNumericValue(source[currentPosition++]))
1510 // Character.getNumericValue(source[currentPosition++]))
1514 // Character.getNumericValue(source[currentPosition++]))
1518 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1520 // currentCharacter =
1521 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1524 //handle the \\u case manually into comment
1525 // if (currentCharacter == '\\') {
1526 // if (source[currentPosition] == '\\')
1527 // currentPosition++;
1528 // } //jump over the \\
1529 boolean isUnicode = false;
1530 while (currentCharacter != '\r' && currentCharacter != '\n') {
1531 this.lastCommentLinePosition = this.currentPosition;
1532 if (currentCharacter == '?') {
1533 if (getNextChar('>')) {
1534 startPosition = currentPosition - 2;
1536 return TokenNameINLINE_HTML;
1541 currentCharacter = source[currentPosition++];
1542 // if (((currentCharacter = source[currentPosition++])
1544 // && (source[currentPosition] == 'u')) {
1545 // isUnicode = true;
1546 // //-------------unicode traitement ------------
1547 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
1548 // currentPosition++;
1549 // while (source[currentPosition] == 'u') {
1550 // currentPosition++;
1553 // Character.getNumericValue(source[currentPosition++]))
1557 // Character.getNumericValue(
1558 // source[currentPosition++]))
1562 // Character.getNumericValue(
1563 // source[currentPosition++]))
1567 // Character.getNumericValue(
1568 // source[currentPosition++]))
1572 // InvalidInputException(INVALID_UNICODE_ESCAPE);
1574 // currentCharacter =
1575 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1578 //handle the \\u case manually into comment
1579 // if (currentCharacter == '\\') {
1580 // if (source[currentPosition] == '\\')
1581 // currentPosition++;
1582 // } //jump over the \\
1585 endPositionForLineComment = currentPosition - 6;
1587 endPositionForLineComment = currentPosition - 1;
1589 // recordComment(false);
1590 recordComment(TokenNameCOMMENT_LINE);
1591 if (this.taskTags != null) checkTaskTag(this.startPosition, this.currentPosition);
1592 if ((currentCharacter == '\r')
1593 || (currentCharacter == '\n')) {
1594 checkNonExternalizeString();
1595 if (recordLineSeparator) {
1597 pushUnicodeLineSeparator();
1599 pushLineSeparator();
1605 if (tokenizeComments) {
1607 currentPosition = endPositionForLineComment;
1608 // reset one character behind
1610 return TokenNameCOMMENT_LINE;
1612 } catch (IndexOutOfBoundsException e) { //an eof will them
1614 if (tokenizeComments) {
1616 // reset one character behind
1617 return TokenNameCOMMENT_LINE;
1623 //traditional and annotation comment
1624 boolean isJavadoc = false, star = false;
1625 // consume next character
1626 unicodeAsBackSlash = false;
1627 currentCharacter = source[currentPosition++];
1628 // if (((currentCharacter = source[currentPosition++]) ==
1630 // && (source[currentPosition] == 'u')) {
1631 // getNextUnicodeChar();
1633 // if (withoutUnicodePtr != 0) {
1634 // withoutUnicodeBuffer[++withoutUnicodePtr] =
1635 // currentCharacter;
1638 if (currentCharacter == '*') {
1642 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1643 checkNonExternalizeString();
1644 if (recordLineSeparator) {
1645 pushLineSeparator();
1650 try { //get the next char
1651 currentCharacter = source[currentPosition++];
1652 // if (((currentCharacter = source[currentPosition++])
1654 // && (source[currentPosition] == 'u')) {
1655 // //-------------unicode traitement ------------
1656 // getNextUnicodeChar();
1658 //handle the \\u case manually into comment
1659 // if (currentCharacter == '\\') {
1660 // if (source[currentPosition] == '\\')
1661 // currentPosition++;
1662 // //jump over the \\
1664 // empty comment is not a javadoc /**/
1665 if (currentCharacter == '/') {
1668 //loop until end of comment */
1669 while ((currentCharacter != '/') || (!star)) {
1670 if ((currentCharacter == '\r')
1671 || (currentCharacter == '\n')) {
1672 checkNonExternalizeString();
1673 if (recordLineSeparator) {
1674 pushLineSeparator();
1679 star = currentCharacter == '*';
1681 currentCharacter = source[currentPosition++];
1682 // if (((currentCharacter = source[currentPosition++])
1684 // && (source[currentPosition] == 'u')) {
1685 // //-------------unicode traitement ------------
1686 // getNextUnicodeChar();
1688 //handle the \\u case manually into comment
1689 // if (currentCharacter == '\\') {
1690 // if (source[currentPosition] == '\\')
1691 // currentPosition++;
1692 // } //jump over the \\
1694 //recordComment(isJavadoc);
1696 recordComment(TokenNameCOMMENT_PHPDOC);
1698 recordComment(TokenNameCOMMENT_BLOCK);
1701 if (tokenizeComments) {
1703 return TokenNameCOMMENT_PHPDOC;
1704 return TokenNameCOMMENT_BLOCK;
1706 } catch (IndexOutOfBoundsException e) {
1707 throw new InvalidInputException(UNTERMINATED_COMMENT);
1711 return TokenNameDIVIDE;
1715 return TokenNameEOF;
1716 //the atEnd may not be <currentPosition == source.length> if
1717 // source is only some part of a real (external) stream
1718 throw new InvalidInputException("Ctrl-Z"); //$NON-NLS-1$
1720 if (currentCharacter == '$') {
1721 int oldPosition = currentPosition;
1723 currentCharacter = source[currentPosition++];
1724 if (isPHPIdentifierStart(currentCharacter)) {
1725 return scanIdentifierOrKeyword(true);
1727 currentPosition = oldPosition;
1728 return TokenNameDOLLAR;
1730 } catch (IndexOutOfBoundsException e) {
1731 currentPosition = oldPosition;
1732 return TokenNameDOLLAR;
1735 if (isPHPIdentifierStart(currentCharacter))
1736 return scanIdentifierOrKeyword(false);
1737 if (Character.isDigit(currentCharacter))
1738 return scanNumber(false);
1739 return TokenNameERROR;
1742 } //-----------------end switch while try--------------------
1743 catch (IndexOutOfBoundsException e) {
1746 return TokenNameEOF;
1749 private int getInlinedHTML(int start) throws InvalidInputException {
1750 int token = getInlinedHTMLToken(start);
1751 if (token == TokenNameINLINE_HTML) {
1752 // Stack stack = new Stack();
1753 // // scan html for errors
1754 // Source inlinedHTMLSource = new Source(new String(source, startPosition, currentPosition - startPosition));
1755 // int lastPHPEndPos=0;
1756 // for (Iterator i=inlinedHTMLSource.getNextTagIterator(0); i.hasNext();) {
1757 // Tag tag=(Tag)i.next();
1759 // if (tag instanceof StartTag) {
1760 // StartTag startTag=(StartTag)tag;
1761 // // System.out.println("startTag: "+tag);
1762 // if (startTag.isServerTag()) {
1763 // // TODO : what to do with a server tag ?
1765 // // do whatever with HTML start tag
1766 // // use startTag.getElement() to find the element corresponding
1767 // // to this start tag which may be useful if you implement code
1769 // stack.push(startTag);
1772 // EndTag endTag=(EndTag)tag;
1773 // StartTag stag = (StartTag) stack.peek();
1774 //// System.out.println("endTag: "+tag);
1775 // // do whatever with HTML end tag.
1783 * InvalidInputException
1785 private int getInlinedHTMLToken(int start) throws InvalidInputException {
1786 // int htmlPosition = start;
1787 if (currentPosition > source.length) {
1788 currentPosition = source.length;
1789 return TokenNameEOF;
1791 startPosition = start;
1794 currentCharacter = source[currentPosition++];
1795 if (currentCharacter == '<') {
1796 if (getNextChar('?')) {
1797 currentCharacter = source[currentPosition++];
1798 if ((currentCharacter == ' ')
1799 || Character.isWhitespace(currentCharacter)) {
1802 return TokenNameINLINE_HTML;
1804 boolean phpStart = (currentCharacter == 'P')
1805 || (currentCharacter == 'p');
1807 int test = getNextChar('H', 'h');
1809 test = getNextChar('P', 'p');
1813 return TokenNameINLINE_HTML;
1820 if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
1821 if (recordLineSeparator) {
1822 pushLineSeparator();
1827 } //-----------------while--------------------
1829 return TokenNameINLINE_HTML;
1830 } //-----------------try--------------------
1831 catch (IndexOutOfBoundsException e) {
1832 startPosition = start;
1836 return TokenNameINLINE_HTML;
1838 // public final void getNextUnicodeChar()
1839 // throws IndexOutOfBoundsException, InvalidInputException {
1841 // //handle the case of unicode.
1842 // //when a unicode appears then we must use a buffer that holds char
1844 // //At the end of this method currentCharacter holds the new visited char
1845 // //and currentPosition points right next after it
1847 // //ALL getNextChar.... ARE OPTIMIZED COPIES
1849 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6;
1850 // currentPosition++;
1851 // while (source[currentPosition] == 'u') {
1852 // currentPosition++;
1856 // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15
1858 // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15
1860 // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15
1862 // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15
1864 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
1866 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
1867 // //need the unicode buffer
1868 // if (withoutUnicodePtr == 0) {
1869 // //buffer all the entries that have been left aside....
1870 // withoutUnicodePtr = currentPosition - unicodeSize - startPosition;
1871 // System.arraycopy(
1874 // withoutUnicodeBuffer,
1876 // withoutUnicodePtr);
1878 // //fill the buffer with the char
1879 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1881 // unicodeAsBackSlash = currentCharacter == '\\';
1884 * Tokenize a method body, assuming that curly brackets are properly
1887 public final void jumpOverMethodBody() {
1888 this.wasAcr = false;
1891 while (true) { //loop for jumping over comments
1892 // ---------Consume white space and handles startPosition---------
1893 boolean isWhiteSpace;
1895 startPosition = currentPosition;
1896 currentCharacter = source[currentPosition++];
1897 // if (((currentCharacter = source[currentPosition++]) == '\\')
1898 // && (source[currentPosition] == 'u')) {
1899 // isWhiteSpace = jumpOverUnicodeWhiteSpace();
1901 if (recordLineSeparator
1902 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
1903 pushLineSeparator();
1904 isWhiteSpace = Character.isWhitespace(currentCharacter);
1906 } while (isWhiteSpace);
1907 // -------consume token until } is found---------
1908 switch (currentCharacter) {
1920 test = getNextChar('\\');
1923 scanDoubleQuotedEscapeCharacter();
1924 } catch (InvalidInputException ex) {
1927 // try { // consume next character
1928 unicodeAsBackSlash = false;
1929 currentCharacter = source[currentPosition++];
1930 // if (((currentCharacter = source[currentPosition++]) == '\\')
1931 // && (source[currentPosition] == 'u')) {
1932 // getNextUnicodeChar();
1934 if (withoutUnicodePtr != 0) {
1935 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1938 // } catch (InvalidInputException ex) {
1946 // try { // consume next character
1947 unicodeAsBackSlash = false;
1948 currentCharacter = source[currentPosition++];
1949 // if (((currentCharacter = source[currentPosition++]) == '\\')
1950 // && (source[currentPosition] == 'u')) {
1951 // getNextUnicodeChar();
1953 if (withoutUnicodePtr != 0) {
1954 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1957 // } catch (InvalidInputException ex) {
1959 while (currentCharacter != '"') {
1960 if (currentCharacter == '\r') {
1961 if (source[currentPosition] == '\n')
1964 // the string cannot go further that the line
1966 if (currentCharacter == '\n') {
1968 // the string cannot go further that the line
1970 if (currentCharacter == '\\') {
1972 scanDoubleQuotedEscapeCharacter();
1973 } catch (InvalidInputException ex) {
1976 // try { // consume next character
1977 unicodeAsBackSlash = false;
1978 currentCharacter = source[currentPosition++];
1979 // if (((currentCharacter = source[currentPosition++]) == '\\')
1980 // && (source[currentPosition] == 'u')) {
1981 // getNextUnicodeChar();
1983 if (withoutUnicodePtr != 0) {
1984 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
1987 // } catch (InvalidInputException ex) {
1990 } catch (IndexOutOfBoundsException e) {
1997 if ((test = getNextChar('/', '*')) == 0) {
2001 currentCharacter = source[currentPosition++];
2002 // if (((currentCharacter = source[currentPosition++]) ==
2004 // && (source[currentPosition] == 'u')) {
2005 // //-------------unicode traitement ------------
2006 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2007 // currentPosition++;
2008 // while (source[currentPosition] == 'u') {
2009 // currentPosition++;
2012 // Character.getNumericValue(source[currentPosition++]))
2016 // Character.getNumericValue(source[currentPosition++]))
2020 // Character.getNumericValue(source[currentPosition++]))
2024 // Character.getNumericValue(source[currentPosition++]))
2027 // //error don't care of the value
2028 // currentCharacter = 'A';
2029 // } //something different from \n and \r
2031 // currentCharacter =
2032 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2035 while (currentCharacter != '\r' && currentCharacter != '\n') {
2037 currentCharacter = source[currentPosition++];
2038 // if (((currentCharacter = source[currentPosition++])
2040 // && (source[currentPosition] == 'u')) {
2041 // //-------------unicode traitement ------------
2042 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2043 // currentPosition++;
2044 // while (source[currentPosition] == 'u') {
2045 // currentPosition++;
2048 // Character.getNumericValue(source[currentPosition++]))
2052 // Character.getNumericValue(source[currentPosition++]))
2056 // Character.getNumericValue(source[currentPosition++]))
2060 // Character.getNumericValue(source[currentPosition++]))
2063 // //error don't care of the value
2064 // currentCharacter = 'A';
2065 // } //something different from \n and \r
2067 // currentCharacter =
2068 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2072 if (recordLineSeparator
2073 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2074 pushLineSeparator();
2075 } catch (IndexOutOfBoundsException e) {
2076 } //an eof will them be generated
2080 //traditional and annotation comment
2081 boolean star = false;
2082 // try { // consume next character
2083 unicodeAsBackSlash = false;
2084 currentCharacter = source[currentPosition++];
2085 // if (((currentCharacter = source[currentPosition++]) == '\\')
2086 // && (source[currentPosition] == 'u')) {
2087 // getNextUnicodeChar();
2089 if (withoutUnicodePtr != 0) {
2090 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2093 // } catch (InvalidInputException ex) {
2095 if (currentCharacter == '*') {
2098 if (recordLineSeparator
2099 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2100 pushLineSeparator();
2101 try { //get the next char
2102 currentCharacter = source[currentPosition++];
2103 // if (((currentCharacter = source[currentPosition++]) ==
2105 // && (source[currentPosition] == 'u')) {
2106 // //-------------unicode traitement ------------
2107 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2108 // currentPosition++;
2109 // while (source[currentPosition] == 'u') {
2110 // currentPosition++;
2113 // Character.getNumericValue(source[currentPosition++]))
2117 // Character.getNumericValue(source[currentPosition++]))
2121 // Character.getNumericValue(source[currentPosition++]))
2125 // Character.getNumericValue(source[currentPosition++]))
2128 // //error don't care of the value
2129 // currentCharacter = 'A';
2130 // } //something different from * and /
2132 // currentCharacter =
2133 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2136 //loop until end of comment */
2137 while ((currentCharacter != '/') || (!star)) {
2138 if (recordLineSeparator
2139 && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2140 pushLineSeparator();
2141 star = currentCharacter == '*';
2143 currentCharacter = source[currentPosition++];
2144 // if (((currentCharacter = source[currentPosition++])
2146 // && (source[currentPosition] == 'u')) {
2147 // //-------------unicode traitement ------------
2148 // int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
2149 // currentPosition++;
2150 // while (source[currentPosition] == 'u') {
2151 // currentPosition++;
2154 // Character.getNumericValue(source[currentPosition++]))
2158 // Character.getNumericValue(source[currentPosition++]))
2162 // Character.getNumericValue(source[currentPosition++]))
2166 // Character.getNumericValue(source[currentPosition++]))
2169 // //error don't care of the value
2170 // currentCharacter = 'A';
2171 // } //something different from * and /
2173 // currentCharacter =
2174 // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2178 } catch (IndexOutOfBoundsException e) {
2186 if (isPHPIdentifierStart(currentCharacter)
2187 || currentCharacter == '$') {
2189 scanIdentifierOrKeyword((currentCharacter == '$'));
2190 } catch (InvalidInputException ex) {
2194 if (Character.isDigit(currentCharacter)) {
2197 } catch (InvalidInputException ex) {
2203 //-----------------end switch while try--------------------
2204 } catch (IndexOutOfBoundsException e) {
2205 } catch (InvalidInputException e) {
2209 // public final boolean jumpOverUnicodeWhiteSpace()
2210 // throws InvalidInputException {
2212 // //handle the case of unicode. Jump over the next whiteSpace
2213 // //making startPosition pointing on the next available char
2214 // //On false, the currentCharacter is filled up with a potential
2218 // this.wasAcr = false;
2219 // int c1, c2, c3, c4;
2220 // int unicodeSize = 6;
2221 // currentPosition++;
2222 // while (source[currentPosition] == 'u') {
2223 // currentPosition++;
2227 // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15
2229 // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15
2231 // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15
2233 // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15
2235 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2238 // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
2239 // if (recordLineSeparator
2240 // && ((currentCharacter == '\r') || (currentCharacter == '\n')))
2241 // pushLineSeparator();
2242 // if (Character.isWhitespace(currentCharacter))
2245 // //buffer the new char which is not a white space
2246 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2247 // //withoutUnicodePtr == 1 is true here
2249 // } catch (IndexOutOfBoundsException e) {
2250 // throw new InvalidInputException(INVALID_UNICODE_ESCAPE);
2253 public final int[] getLineEnds() {
2254 //return a bounded copy of this.lineEnds
2256 System.arraycopy(lineEnds, 0, copy = new int[linePtr + 1], 0, linePtr + 1);
2259 public char[] getSource() {
2262 final char[] optimizedCurrentTokenSource1() {
2263 //return always the same char[] build only once
2264 //optimization at no speed cost of 99.5 % of the singleCharIdentifier
2265 char charOne = source[startPosition];
2320 return new char[]{charOne};
2323 final char[] optimizedCurrentTokenSource2() {
2324 //try to return the same char[] build only once
2326 int hash = (((c0 = source[startPosition]) << 6) + (c1 = source[startPosition + 1]))
2328 char[][] table = charArray_length[0][hash];
2330 while (++i < InternalTableSize) {
2331 char[] charArray = table[i];
2332 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2335 //---------other side---------
2337 int max = newEntry2;
2338 while (++i <= max) {
2339 char[] charArray = table[i];
2340 if ((c0 == charArray[0]) && (c1 == charArray[1]))
2343 //--------add the entry-------
2344 if (++max >= InternalTableSize)
2347 table[max] = (r = new char[]{c0, c1});
2351 final char[] optimizedCurrentTokenSource3() {
2352 //try to return the same char[] build only once
2354 int hash = (((c0 = source[startPosition]) << 12)
2355 + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2]))
2357 char[][] table = charArray_length[1][hash];
2359 while (++i < InternalTableSize) {
2360 char[] charArray = table[i];
2361 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2364 //---------other side---------
2366 int max = newEntry3;
2367 while (++i <= max) {
2368 char[] charArray = table[i];
2369 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]))
2372 //--------add the entry-------
2373 if (++max >= InternalTableSize)
2376 table[max] = (r = new char[]{c0, c1, c2});
2380 final char[] optimizedCurrentTokenSource4() {
2381 //try to return the same char[] build only once
2382 char c0, c1, c2, c3;
2383 long hash = ((((long) (c0 = source[startPosition])) << 18)
2384 + ((c1 = source[startPosition + 1]) << 12)
2385 + ((c2 = source[startPosition + 2]) << 6) + (c3 = source[startPosition + 3]))
2387 char[][] table = charArray_length[2][(int) hash];
2389 while (++i < InternalTableSize) {
2390 char[] charArray = table[i];
2391 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2])
2392 && (c3 == charArray[3]))
2395 //---------other side---------
2397 int max = newEntry4;
2398 while (++i <= max) {
2399 char[] charArray = table[i];
2400 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2])
2401 && (c3 == charArray[3]))
2404 //--------add the entry-------
2405 if (++max >= InternalTableSize)
2408 table[max] = (r = new char[]{c0, c1, c2, c3});
2412 final char[] optimizedCurrentTokenSource5() {
2413 //try to return the same char[] build only once
2414 char c0, c1, c2, c3, c4;
2415 long hash = ((((long) (c0 = source[startPosition])) << 24)
2416 + (((long) (c1 = source[startPosition + 1])) << 18)
2417 + ((c2 = source[startPosition + 2]) << 12)
2418 + ((c3 = source[startPosition + 3]) << 6) + (c4 = source[startPosition + 4]))
2420 char[][] table = charArray_length[3][(int) hash];
2422 while (++i < InternalTableSize) {
2423 char[] charArray = table[i];
2424 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2])
2425 && (c3 == charArray[3]) && (c4 == charArray[4]))
2428 //---------other side---------
2430 int max = newEntry5;
2431 while (++i <= max) {
2432 char[] charArray = table[i];
2433 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2])
2434 && (c3 == charArray[3]) && (c4 == charArray[4]))
2437 //--------add the entry-------
2438 if (++max >= InternalTableSize)
2441 table[max] = (r = new char[]{c0, c1, c2, c3, c4});
2445 final char[] optimizedCurrentTokenSource6() {
2446 //try to return the same char[] build only once
2447 char c0, c1, c2, c3, c4, c5;
2448 long hash = ((((long) (c0 = source[startPosition])) << 32)
2449 + (((long) (c1 = source[startPosition + 1])) << 24)
2450 + (((long) (c2 = source[startPosition + 2])) << 18)
2451 + ((c3 = source[startPosition + 3]) << 12)
2452 + ((c4 = source[startPosition + 4]) << 6) + (c5 = source[startPosition + 5]))
2454 char[][] table = charArray_length[4][(int) hash];
2456 while (++i < InternalTableSize) {
2457 char[] charArray = table[i];
2458 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2])
2459 && (c3 == charArray[3]) && (c4 == charArray[4])
2460 && (c5 == charArray[5]))
2463 //---------other side---------
2465 int max = newEntry6;
2466 while (++i <= max) {
2467 char[] charArray = table[i];
2468 if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2])
2469 && (c3 == charArray[3]) && (c4 == charArray[4])
2470 && (c5 == charArray[5]))
2473 //--------add the entry-------
2474 if (++max >= InternalTableSize)
2477 table[max] = (r = new char[]{c0, c1, c2, c3, c4, c5});
2481 public final void pushLineSeparator() throws InvalidInputException {
2482 //see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2483 final int INCREMENT = 250;
2484 if (this.checkNonExternalizedStringLiterals) {
2485 // reinitialize the current line for non externalize strings purpose
2488 //currentCharacter is at position currentPosition-1
2490 if (currentCharacter == '\r') {
2491 int separatorPos = currentPosition - 1;
2492 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2494 //System.out.println("CR-" + separatorPos);
2496 lineEnds[++linePtr] = separatorPos;
2497 } catch (IndexOutOfBoundsException e) {
2498 //linePtr value is correct
2499 int oldLength = lineEnds.length;
2500 int[] old = lineEnds;
2501 lineEnds = new int[oldLength + INCREMENT];
2502 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2503 lineEnds[linePtr] = separatorPos;
2505 // look-ahead for merged cr+lf
2507 if (source[currentPosition] == '\n') {
2508 //System.out.println("look-ahead LF-" + currentPosition);
2509 lineEnds[linePtr] = currentPosition;
2515 } catch (IndexOutOfBoundsException e) {
2520 if (currentCharacter == '\n') {
2521 //must merge eventual cr followed by lf
2522 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 2))) {
2523 //System.out.println("merge LF-" + (currentPosition - 1));
2524 lineEnds[linePtr] = currentPosition - 1;
2526 int separatorPos = currentPosition - 1;
2527 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2529 // System.out.println("LF-" + separatorPos);
2531 lineEnds[++linePtr] = separatorPos;
2532 } catch (IndexOutOfBoundsException e) {
2533 //linePtr value is correct
2534 int oldLength = lineEnds.length;
2535 int[] old = lineEnds;
2536 lineEnds = new int[oldLength + INCREMENT];
2537 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2538 lineEnds[linePtr] = separatorPos;
2545 public final void pushUnicodeLineSeparator() {
2546 // isUnicode means that the \r or \n has been read as a unicode character
2547 //see comment on isLineDelimiter(char) for the use of '\n' and '\r'
2548 final int INCREMENT = 250;
2549 //currentCharacter is at position currentPosition-1
2550 if (this.checkNonExternalizedStringLiterals) {
2551 // reinitialize the current line for non externalize strings purpose
2555 if (currentCharacter == '\r') {
2556 int separatorPos = currentPosition - 6;
2557 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2559 //System.out.println("CR-" + separatorPos);
2561 lineEnds[++linePtr] = separatorPos;
2562 } catch (IndexOutOfBoundsException e) {
2563 //linePtr value is correct
2564 int oldLength = lineEnds.length;
2565 int[] old = lineEnds;
2566 lineEnds = new int[oldLength + INCREMENT];
2567 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2568 lineEnds[linePtr] = separatorPos;
2570 // look-ahead for merged cr+lf
2571 if (source[currentPosition] == '\n') {
2572 //System.out.println("look-ahead LF-" + currentPosition);
2573 lineEnds[linePtr] = currentPosition;
2581 if (currentCharacter == '\n') {
2582 //must merge eventual cr followed by lf
2583 if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) {
2584 //System.out.println("merge LF-" + (currentPosition - 1));
2585 lineEnds[linePtr] = currentPosition - 6;
2587 int separatorPos = currentPosition - 6;
2588 if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos))
2590 // System.out.println("LF-" + separatorPos);
2592 lineEnds[++linePtr] = separatorPos;
2593 } catch (IndexOutOfBoundsException e) {
2594 //linePtr value is correct
2595 int oldLength = lineEnds.length;
2596 int[] old = lineEnds;
2597 lineEnds = new int[oldLength + INCREMENT];
2598 System.arraycopy(old, 0, lineEnds, 0, oldLength);
2599 lineEnds[linePtr] = separatorPos;
2606 public void recordComment(int token) {
2608 int stopPosition = this.currentPosition;
2610 case TokenNameCOMMENT_LINE:
2611 stopPosition = -this.lastCommentLinePosition;
2613 case TokenNameCOMMENT_BLOCK:
2614 stopPosition = -this.currentPosition;
2618 // a new comment is recorded
2619 int length = this.commentStops.length;
2620 if (++this.commentPtr >= length) {
2621 System.arraycopy(this.commentStops, 0, this.commentStops = new int[length + 30], 0, length);
2622 //grows the positions buffers too
2623 System.arraycopy(this.commentStarts, 0, this.commentStarts = new int[length + 30], 0, length);
2625 this.commentStops[this.commentPtr] = stopPosition;
2626 this.commentStarts[this.commentPtr] = this.startPosition;
2628 // public final void recordComment(boolean isJavadoc) {
2629 // // a new annotation comment is recorded
2631 // commentStops[++commentPtr] = isJavadoc
2632 // ? currentPosition
2633 // : -currentPosition;
2634 // } catch (IndexOutOfBoundsException e) {
2635 // int oldStackLength = commentStops.length;
2636 // int[] oldStack = commentStops;
2637 // commentStops = new int[oldStackLength + 30];
2638 // System.arraycopy(oldStack, 0, commentStops, 0, oldStackLength);
2639 // commentStops[commentPtr] = isJavadoc ? currentPosition : -currentPosition;
2640 // //grows the positions buffers too
2641 // int[] old = commentStarts;
2642 // commentStarts = new int[oldStackLength + 30];
2643 // System.arraycopy(old, 0, commentStarts, 0, oldStackLength);
2645 // //the buffer is of a correct size here
2646 // commentStarts[commentPtr] = startPosition;
2648 public void resetTo(int begin, int end) {
2649 //reset the scanner to a given position where it may rescan again
2651 initialPosition = startPosition = currentPosition = begin;
2652 eofPosition = end < Integer.MAX_VALUE ? end + 1 : end;
2653 commentPtr = -1; // reset comment stack
2655 public final void scanSingleQuotedEscapeCharacter()
2656 throws InvalidInputException {
2657 // the string with "\\u" is a legal string of two chars \ and u
2658 //thus we use a direct access to the source (for regular cases).
2659 // if (unicodeAsBackSlash) {
2660 // // consume next character
2661 // unicodeAsBackSlash = false;
2662 // if (((currentCharacter = source[currentPosition++]) == '\\')
2663 // && (source[currentPosition] == 'u')) {
2664 // getNextUnicodeChar();
2666 // if (withoutUnicodePtr != 0) {
2667 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2671 currentCharacter = source[currentPosition++];
2672 switch (currentCharacter) {
2674 currentCharacter = '\'';
2677 currentCharacter = '\\';
2680 currentCharacter = '\\';
2684 public final void scanDoubleQuotedEscapeCharacter()
2685 throws InvalidInputException {
2686 // the string with "\\u" is a legal string of two chars \ and u
2687 //thus we use a direct access to the source (for regular cases).
2688 // if (unicodeAsBackSlash) {
2689 // // consume next character
2690 // unicodeAsBackSlash = false;
2691 // if (((currentCharacter = source[currentPosition++]) == '\\')
2692 // && (source[currentPosition] == 'u')) {
2693 // getNextUnicodeChar();
2695 // if (withoutUnicodePtr != 0) {
2696 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
2700 currentCharacter = source[currentPosition++];
2701 switch (currentCharacter) {
2703 // currentCharacter = '\b';
2706 currentCharacter = '\t';
2709 currentCharacter = '\n';
2712 // currentCharacter = '\f';
2715 currentCharacter = '\r';
2718 currentCharacter = '\"';
2721 currentCharacter = '\'';
2724 currentCharacter = '\\';
2727 currentCharacter = '$';
2730 // -----------octal escape--------------
2732 // OctalDigit OctalDigit
2733 // ZeroToThree OctalDigit OctalDigit
2734 int number = Character.getNumericValue(currentCharacter);
2735 if (number >= 0 && number <= 7) {
2736 boolean zeroToThreeNot = number > 3;
2737 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
2738 int digit = Character.getNumericValue(currentCharacter);
2739 if (digit >= 0 && digit <= 7) {
2740 number = (number * 8) + digit;
2742 .isDigit(currentCharacter = source[currentPosition++])) {
2743 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
2744 // Digit --> ignore last character
2747 digit = Character.getNumericValue(currentCharacter);
2748 if (digit >= 0 && digit <= 7) {
2749 // has read \ZeroToThree OctalDigit OctalDigit
2750 number = (number * 8) + digit;
2751 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
2752 // --> ignore last character
2756 } else { // has read \OctalDigit NonDigit--> ignore last
2760 } else { // has read \OctalDigit NonOctalDigit--> ignore last
2764 } else { // has read \OctalDigit --> ignore last character
2768 throw new InvalidInputException(INVALID_ESCAPE);
2769 currentCharacter = (char) number;
2772 // throw new InvalidInputException(INVALID_ESCAPE);
2775 // public int scanIdentifierOrKeyword() throws InvalidInputException {
2776 // return scanIdentifierOrKeyword( false );
2778 public int scanIdentifierOrKeyword(boolean isVariable)
2779 throws InvalidInputException {
2781 //first dispatch on the first char.
2782 //then the length. If there are several
2783 //keywors with the same length AND the same first char, then do another
2784 //disptach on the second char :-)...cool....but fast !
2785 useAssertAsAnIndentifier = false;
2786 while (getNextCharAsJavaIdentifierPart()) {
2789 // if (new String(getCurrentTokenSource()).equals("$this")) {
2790 // return TokenNamethis;
2792 return TokenNameVariable;
2797 // if (withoutUnicodePtr == 0)
2798 //quick test on length == 1 but not on length > 12 while most identifier
2799 //have a length which is <= 12...but there are lots of identifier with
2802 if ((length = currentPosition - startPosition) == 1)
2803 return TokenNameIdentifier;
2805 data = new char[length];
2806 index = startPosition;
2807 for (int i = 0; i < length; i++) {
2808 data[i] = Character.toLowerCase(source[index + i]);
2812 // if ((length = withoutUnicodePtr) == 1)
2813 // return TokenNameIdentifier;
2814 // // data = withoutUnicodeBuffer;
2815 // data = new char[withoutUnicodeBuffer.length];
2816 // for (int i = 0; i < withoutUnicodeBuffer.length; i++) {
2817 // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]);
2821 firstLetter = data[index];
2822 switch (firstLetter) {
2827 if ((data[++index] == '_') && (data[++index] == 'f')
2828 && (data[++index] == 'i') && (data[++index] == 'l')
2829 && (data[++index] == 'e') && (data[++index] == '_')
2830 && (data[++index] == '_'))
2831 return TokenNameFILE;
2832 index = 0; //__LINE__
2833 if ((data[++index] == '_') && (data[++index] == 'l')
2834 && (data[++index] == 'i') && (data[++index] == 'n')
2835 && (data[++index] == 'e') && (data[++index] == '_')
2836 && (data[++index] == '_'))
2837 return TokenNameLINE;
2841 if ((data[++index] == '_') && (data[++index] == 'c')
2842 && (data[++index] == 'l') && (data[++index] == 'a')
2843 && (data[++index] == 's') && (data[++index] == 's')
2844 && (data[++index] == '_') && (data[++index] == '_'))
2845 return TokenNameCLASS_C;
2849 if ((data[++index] == '_') && (data[++index] == 'm')
2850 && (data[++index] == 'e') && (data[++index] == 't')
2851 && (data[++index] == 'h') && (data[++index] == 'o')
2852 && (data[++index] == 'd') && (data[++index] == '_')
2853 && (data[++index] == '_'))
2854 return TokenNameMETHOD_C;
2858 if ((data[++index] == '_') && (data[++index] == 'f')
2859 && (data[++index] == 'u') && (data[++index] == 'n')
2860 && (data[++index] == 'c') && (data[++index] == 't')
2861 && (data[++index] == 'i') && (data[++index] == 'o')
2862 && (data[++index] == 'n') && (data[++index] == '_')
2863 && (data[++index] == '_'))
2864 return TokenNameFUNC_C;
2867 return TokenNameIdentifier;
2869 // as and array abstract
2873 if ((data[++index] == 's')) {
2876 return TokenNameIdentifier;
2880 if ((data[++index] == 'n') && (data[++index] == 'd')) {
2881 return TokenNameand;
2883 return TokenNameIdentifier;
2887 if ((data[++index] == 'r') && (data[++index] == 'r')
2888 && (data[++index] == 'a') && (data[++index] == 'y'))
2889 return TokenNamearray;
2891 return TokenNameIdentifier;
2893 if ((data[++index] == 'b') && (data[++index] == 's')
2894 && (data[++index] == 't') && (data[++index] == 'r')
2895 && (data[++index] == 'a') && (data[++index] == 'c')
2896 && (data[++index] == 't'))
2897 return TokenNameabstract;
2899 return TokenNameIdentifier;
2901 return TokenNameIdentifier;
2907 if ((data[++index] == 'r') && (data[++index] == 'e')
2908 && (data[++index] == 'a') && (data[++index] == 'k'))
2909 return TokenNamebreak;
2911 return TokenNameIdentifier;
2913 return TokenNameIdentifier;
2916 //case catch class clone const continue
2919 if ((data[++index] == 'a') && (data[++index] == 's')
2920 && (data[++index] == 'e'))
2921 return TokenNamecase;
2923 return TokenNameIdentifier;
2925 if ((data[++index] == 'a') && (data[++index] == 't')
2926 && (data[++index] == 'c') && (data[++index] == 'h'))
2927 return TokenNamecatch;
2929 if ((data[++index] == 'l') && (data[++index] == 'a')
2930 && (data[++index] == 's') && (data[++index] == 's'))
2931 return TokenNameclass;
2933 if ((data[++index] == 'l') && (data[++index] == 'o')
2934 && (data[++index] == 'n') && (data[++index] == 'e'))
2935 return TokenNameclone;
2937 if ((data[++index] == 'o') && (data[++index] == 'n')
2938 && (data[++index] == 's') && (data[++index] == 't'))
2939 return TokenNameconst;
2941 return TokenNameIdentifier;
2943 if ((data[++index] == 'o') && (data[++index] == 'n')
2944 && (data[++index] == 't') && (data[++index] == 'i')
2945 && (data[++index] == 'n') && (data[++index] == 'u')
2946 && (data[++index] == 'e'))
2947 return TokenNamecontinue;
2949 return TokenNameIdentifier;
2951 return TokenNameIdentifier;
2954 // declare default do die
2955 // TODO delete define ==> no keyword !
2958 if ((data[++index] == 'o'))
2961 return TokenNameIdentifier;
2963 // if ((data[++index] == 'e')
2964 // && (data[++index] == 'f')
2965 // && (data[++index] == 'i')
2966 // && (data[++index] == 'n')
2967 // && (data[++index] == 'e'))
2968 // return TokenNamedefine;
2970 // return TokenNameIdentifier;
2972 if ((data[++index] == 'e') && (data[++index] == 'c')
2973 && (data[++index] == 'l') && (data[++index] == 'a')
2974 && (data[++index] == 'r') && (data[++index] == 'e'))
2975 return TokenNamedeclare;
2977 if ((data[++index] == 'e') && (data[++index] == 'f')
2978 && (data[++index] == 'a') && (data[++index] == 'u')
2979 && (data[++index] == 'l') && (data[++index] == 't'))
2980 return TokenNamedefault;
2982 return TokenNameIdentifier;
2984 return TokenNameIdentifier;
2987 //echo else exit elseif extends eval
2990 if ((data[++index] == 'c') && (data[++index] == 'h')
2991 && (data[++index] == 'o'))
2992 return TokenNameecho;
2993 else if ((data[index] == 'l') && (data[++index] == 's')
2994 && (data[++index] == 'e'))
2995 return TokenNameelse;
2996 else if ((data[index] == 'x') && (data[++index] == 'i')
2997 && (data[++index] == 't'))
2998 return TokenNameexit;
2999 else if ((data[index] == 'v') && (data[++index] == 'a')
3000 && (data[++index] == 'l'))
3001 return TokenNameeval;
3003 return TokenNameIdentifier;
3006 if ((data[++index] == 'n') && (data[++index] == 'd')
3007 && (data[++index] == 'i') && (data[++index] == 'f'))
3008 return TokenNameendif;
3009 if ((data[index] == 'm') && (data[++index] == 'p')
3010 && (data[++index] == 't') && (data[++index] == 'y'))
3011 return TokenNameempty;
3013 return TokenNameIdentifier;
3016 if ((data[++index] == 'n') && (data[++index] == 'd')
3017 && (data[++index] == 'f') && (data[++index] == 'o')
3018 && (data[++index] == 'r'))
3019 return TokenNameendfor;
3020 else if ((data[index] == 'l') && (data[++index] == 's')
3021 && (data[++index] == 'e') && (data[++index] == 'i')
3022 && (data[++index] == 'f'))
3023 return TokenNameelseif;
3025 return TokenNameIdentifier;
3027 if ((data[++index] == 'x') && (data[++index] == 't')
3028 && (data[++index] == 'e') && (data[++index] == 'n')
3029 && (data[++index] == 'd') && (data[++index] == 's'))
3030 return TokenNameextends;
3032 return TokenNameIdentifier;
3035 if ((data[++index] == 'n') && (data[++index] == 'd')
3036 && (data[++index] == 'w') && (data[++index] == 'h')
3037 && (data[++index] == 'i') && (data[++index] == 'l')
3038 && (data[++index] == 'e'))
3039 return TokenNameendwhile;
3041 return TokenNameIdentifier;
3044 if ((data[++index] == 'n') && (data[++index] == 'd')
3045 && (data[++index] == 's') && (data[++index] == 'w')
3046 && (data[++index] == 'i') && (data[++index] == 't')
3047 && (data[++index] == 'c') && (data[++index] == 'h'))
3048 return TokenNameendswitch;
3050 return TokenNameIdentifier;
3053 if ((data[++index] == 'n') && (data[++index] == 'd')
3054 && (data[++index] == 'd') && (data[++index] == 'e')
3055 && (data[++index] == 'c') && (data[++index] == 'l')
3056 && (data[++index] == 'a') && (data[++index] == 'r')
3057 && (data[++index] == 'e'))
3058 return TokenNameendforeach;
3060 if ((data[++index] == 'n') // endforeach
3061 && (data[++index] == 'd') && (data[++index] == 'f')
3062 && (data[++index] == 'o') && (data[++index] == 'r')
3063 && (data[++index] == 'e') && (data[++index] == 'a')
3064 && (data[++index] == 'c') && (data[++index] == 'h'))
3065 return TokenNameendforeach;
3067 return TokenNameIdentifier;
3069 return TokenNameIdentifier;
3072 //for false final function
3075 if ((data[++index] == 'o') && (data[++index] == 'r'))
3076 return TokenNamefor;
3078 return TokenNameIdentifier;
3080 // if ((data[++index] == 'a') && (data[++index] == 'l')
3081 // && (data[++index] == 's') && (data[++index] == 'e'))
3082 // return TokenNamefalse;
3083 if ((data[++index] == 'i') && (data[++index] == 'n')
3084 && (data[++index] == 'a') && (data[++index] == 'l'))
3085 return TokenNamefinal;
3087 return TokenNameIdentifier;
3090 if ((data[++index] == 'o') && (data[++index] == 'r')
3091 && (data[++index] == 'e') && (data[++index] == 'a')
3092 && (data[++index] == 'c') && (data[++index] == 'h'))
3093 return TokenNameforeach;
3095 return TokenNameIdentifier;
3098 if ((data[++index] == 'u') && (data[++index] == 'n')
3099 && (data[++index] == 'c') && (data[++index] == 't')
3100 && (data[++index] == 'i') && (data[++index] == 'o')
3101 && (data[++index] == 'n'))
3102 return TokenNamefunction;
3104 return TokenNameIdentifier;
3106 return TokenNameIdentifier;
3111 if ((data[++index] == 'l') && (data[++index] == 'o')
3112 && (data[++index] == 'b') && (data[++index] == 'a')
3113 && (data[++index] == 'l')) {
3114 return TokenNameglobal;
3117 return TokenNameIdentifier;
3119 //if int isset include include_once instanceof interface implements
3122 if (data[++index] == 'f')
3125 return TokenNameIdentifier;
3127 // if ((data[++index] == 'n') && (data[++index] == 't'))
3128 // return TokenNameint;
3130 // return TokenNameIdentifier;
3132 if ((data[++index] == 's') && (data[++index] == 's')
3133 && (data[++index] == 'e') && (data[++index] == 't'))
3134 return TokenNameisset;
3136 return TokenNameIdentifier;
3138 if ((data[++index] == 'n') && (data[++index] == 'c')
3139 && (data[++index] == 'l') && (data[++index] == 'u')
3140 && (data[++index] == 'd') && (data[++index] == 'e'))
3141 return TokenNameinclude;
3143 return TokenNameIdentifier;
3146 if ((data[++index] == 'n') && (data[++index] == 't')
3147 && (data[++index] == 'e') && (data[++index] == 'r')
3148 && (data[++index] == 'f') && (data[++index] == 'a')
3149 && (data[++index] == 'c') && (data[++index] == 'e'))
3150 return TokenNameinterface;
3152 return TokenNameIdentifier;
3155 if ((data[++index] == 'n') && (data[++index] == 's')
3156 && (data[++index] == 't') && (data[++index] == 'a')
3157 && (data[++index] == 'n') && (data[++index] == 'c')
3158 && (data[++index] == 'e') && (data[++index] == 'o')
3159 && (data[++index] == 'f'))
3160 return TokenNameinstanceof;
3161 if ((data[index] == 'm') && (data[++index] == 'p')
3162 && (data[++index] == 'l') && (data[++index] == 'e')
3163 && (data[++index] == 'm') && (data[++index] == 'e')
3164 && (data[++index] == 'n') && (data[++index] == 't')
3165 && (data[++index] == 's'))
3166 return TokenNameimplements;
3168 return TokenNameIdentifier;
3170 if ((data[++index] == 'n') && (data[++index] == 'c')
3171 && (data[++index] == 'l') && (data[++index] == 'u')
3172 && (data[++index] == 'd') && (data[++index] == 'e')
3173 && (data[++index] == '_') && (data[++index] == 'o')
3174 && (data[++index] == 'n') && (data[++index] == 'c')
3175 && (data[++index] == 'e'))
3176 return TokenNameinclude_once;
3178 return TokenNameIdentifier;
3180 return TokenNameIdentifier;
3185 if ((data[++index] == 'i') && (data[++index] == 's')
3186 && (data[++index] == 't')) {
3187 return TokenNamelist;
3190 return TokenNameIdentifier;
3195 if ((data[++index] == 'e') && (data[++index] == 'w'))
3196 return TokenNamenew;
3198 return TokenNameIdentifier;
3200 // if ((data[++index] == 'u') && (data[++index] == 'l')
3201 // && (data[++index] == 'l'))
3202 // return TokenNamenull;
3204 // return TokenNameIdentifier;
3206 return TokenNameIdentifier;
3211 if (data[++index] == 'r') {
3215 // if (length == 12) {
3216 // if ((data[++index] == 'l')
3217 // && (data[++index] == 'd')
3218 // && (data[++index] == '_')
3219 // && (data[++index] == 'f')
3220 // && (data[++index] == 'u')
3221 // && (data[++index] == 'n')
3222 // && (data[++index] == 'c')
3223 // && (data[++index] == 't')
3224 // && (data[++index] == 'i')
3225 // && (data[++index] == 'o')
3226 // && (data[++index] == 'n')) {
3227 // return TokenNameold_function;
3230 return TokenNameIdentifier;
3232 // print public private protected
3235 if ((data[++index] == 'r') && (data[++index] == 'i')
3236 && (data[++index] == 'n') && (data[++index] == 't')) {
3237 return TokenNameprint;
3239 return TokenNameIdentifier;
3241 if ((data[++index] == 'u') && (data[++index] == 'b')
3242 && (data[++index] == 'l') && (data[++index] == 'i')
3243 && (data[++index] == 'c')) {
3244 return TokenNamepublic;
3246 return TokenNameIdentifier;
3248 if ((data[++index] == 'r') && (data[++index] == 'i')
3249 && (data[++index] == 'v') && (data[++index] == 'a')
3250 && (data[++index] == 't') && (data[++index] == 'e')) {
3251 return TokenNameprivate;
3253 return TokenNameIdentifier;
3255 if ((data[++index] == 'r') && (data[++index] == 'o')
3256 && (data[++index] == 't') && (data[++index] == 'e')
3257 && (data[++index] == 'c') && (data[++index] == 't')
3258 && (data[++index] == 'e') && (data[++index] == 'd')) {
3259 return TokenNameprotected;
3261 return TokenNameIdentifier;
3263 return TokenNameIdentifier;
3265 //return require require_once
3267 if ((data[++index] == 'e') && (data[++index] == 't')
3268 && (data[++index] == 'u') && (data[++index] == 'r')
3269 && (data[++index] == 'n')) {
3270 return TokenNamereturn;
3272 } else if (length == 7) {
3273 if ((data[++index] == 'e') && (data[++index] == 'q')
3274 && (data[++index] == 'u') && (data[++index] == 'i')
3275 && (data[++index] == 'r') && (data[++index] == 'e')) {
3276 return TokenNamerequire;
3278 } else if (length == 12) {
3279 if ((data[++index] == 'e') && (data[++index] == 'q')
3280 && (data[++index] == 'u') && (data[++index] == 'i')
3281 && (data[++index] == 'r') && (data[++index] == 'e')
3282 && (data[++index] == '_') && (data[++index] == 'o')
3283 && (data[++index] == 'n') && (data[++index] == 'c')
3284 && (data[++index] == 'e')) {
3285 return TokenNamerequire_once;
3288 return TokenNameIdentifier;
3293 if (data[++index] == 't')
3294 if ((data[++index] == 'a') && (data[++index] == 't')
3295 && (data[++index] == 'i') && (data[++index] == 'c')) {
3296 return TokenNamestatic;
3298 return TokenNameIdentifier;
3299 else if ((data[index] == 'w') && (data[++index] == 'i')
3300 && (data[++index] == 't') && (data[++index] == 'c')
3301 && (data[++index] == 'h'))
3302 return TokenNameswitch;
3304 return TokenNameIdentifier;
3306 return TokenNameIdentifier;
3312 if ((data[++index] == 'r') && (data[++index] == 'y'))
3313 return TokenNametry;
3315 return TokenNameIdentifier;
3317 // if ((data[++index] == 'r') && (data[++index] == 'u')
3318 // && (data[++index] == 'e'))
3319 // return TokenNametrue;
3321 // return TokenNameIdentifier;
3323 if ((data[++index] == 'h') && (data[++index] == 'r')
3324 && (data[++index] == 'o') && (data[++index] == 'w'))
3325 return TokenNamethrow;
3327 return TokenNameIdentifier;
3329 return TokenNameIdentifier;
3335 if ((data[++index] == 's') && (data[++index] == 'e'))
3336 return TokenNameuse;
3338 return TokenNameIdentifier;
3340 if ((data[++index] == 'n') && (data[++index] == 's')
3341 && (data[++index] == 'e') && (data[++index] == 't'))
3342 return TokenNameunset;
3344 return TokenNameIdentifier;
3346 return TokenNameIdentifier;
3352 if ((data[++index] == 'a') && (data[++index] == 'r'))
3353 return TokenNamevar;
3355 return TokenNameIdentifier;
3357 return TokenNameIdentifier;
3363 if ((data[++index] == 'h') && (data[++index] == 'i')
3364 && (data[++index] == 'l') && (data[++index] == 'e'))
3365 return TokenNamewhile;
3367 return TokenNameIdentifier;
3368 //case 6:if ( (data[++index] =='i') && (data[++index]=='d') &&
3369 // (data[++index]=='e') && (data[++index]=='f')&&
3370 // (data[++index]=='p'))
3371 //return TokenNamewidefp ;
3373 //return TokenNameIdentifier;
3375 return TokenNameIdentifier;
3381 if ((data[++index] == 'o') && (data[++index] == 'r'))
3382 return TokenNamexor;
3384 return TokenNameIdentifier;
3386 return TokenNameIdentifier;
3389 return TokenNameIdentifier;
3392 public int scanNumber(boolean dotPrefix) throws InvalidInputException {
3393 //when entering this method the currentCharacter is the firt
3394 //digit of the number , i.e. it may be preceeded by a . when
3396 boolean floating = dotPrefix;
3397 if ((!dotPrefix) && (currentCharacter == '0')) {
3398 if (getNextChar('x', 'X') >= 0) { //----------hexa-----------------
3399 //force the first char of the hexa number do exist...
3400 // consume next character
3401 unicodeAsBackSlash = false;
3402 currentCharacter = source[currentPosition++];
3403 // if (((currentCharacter = source[currentPosition++]) == '\\')
3404 // && (source[currentPosition] == 'u')) {
3405 // getNextUnicodeChar();
3407 // if (withoutUnicodePtr != 0) {
3408 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3411 if (Character.digit(currentCharacter, 16) == -1)
3412 throw new InvalidInputException(INVALID_HEXA);
3414 while (getNextCharAsDigit(16)) {
3416 // if (getNextChar('l', 'L') >= 0)
3417 // return TokenNameLongLiteral;
3419 return TokenNameIntegerLiteral;
3421 //there is x or X in the number
3422 //potential octal ! ... some one may write 000099.0 ! thus 00100 <
3423 // 00078.0 is true !!!!! crazy language
3424 if (getNextCharAsDigit()) {
3425 //-------------potential octal-----------------
3426 while (getNextCharAsDigit()) {
3428 // if (getNextChar('l', 'L') >= 0) {
3429 // return TokenNameLongLiteral;
3432 // if (getNextChar('f', 'F') >= 0) {
3433 // return TokenNameFloatingPointLiteral;
3435 if (getNextChar('d', 'D') >= 0) {
3436 return TokenNameDoubleLiteral;
3437 } else { //make the distinction between octal and float ....
3438 if (getNextChar('.')) { //bingo ! ....
3439 while (getNextCharAsDigit()) {
3441 if (getNextChar('e', 'E') >= 0) {
3442 // consume next character
3443 unicodeAsBackSlash = false;
3444 currentCharacter = source[currentPosition++];
3445 // if (((currentCharacter = source[currentPosition++]) == '\\')
3446 // && (source[currentPosition] == 'u')) {
3447 // getNextUnicodeChar();
3449 // if (withoutUnicodePtr != 0) {
3450 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3453 if ((currentCharacter == '-') || (currentCharacter == '+')) {
3454 // consume next character
3455 unicodeAsBackSlash = false;
3456 currentCharacter = source[currentPosition++];
3457 // if (((currentCharacter = source[currentPosition++]) == '\\')
3458 // && (source[currentPosition] == 'u')) {
3459 // getNextUnicodeChar();
3461 // if (withoutUnicodePtr != 0) {
3462 // withoutUnicodeBuffer[++withoutUnicodePtr] =
3463 // currentCharacter;
3467 if (!Character.isDigit(currentCharacter))
3468 throw new InvalidInputException(INVALID_FLOAT);
3469 while (getNextCharAsDigit()) {
3472 // if (getNextChar('f', 'F') >= 0)
3473 // return TokenNameFloatingPointLiteral;
3474 getNextChar('d', 'D'); //jump over potential d or D
3475 return TokenNameDoubleLiteral;
3477 return TokenNameIntegerLiteral;
3484 while (getNextCharAsDigit()) {
3486 // if ((!dotPrefix) && (getNextChar('l', 'L') >= 0))
3487 // return TokenNameLongLiteral;
3488 if ((!dotPrefix) && (getNextChar('.'))) { //decimal part that can be empty
3489 while (getNextCharAsDigit()) {
3493 //if floating is true both exponant and suffix may be optional
3494 if (getNextChar('e', 'E') >= 0) {
3496 // consume next character
3497 unicodeAsBackSlash = false;
3498 currentCharacter = source[currentPosition++];
3499 // if (((currentCharacter = source[currentPosition++]) == '\\')
3500 // && (source[currentPosition] == 'u')) {
3501 // getNextUnicodeChar();
3503 // if (withoutUnicodePtr != 0) {
3504 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3507 if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume
3510 unicodeAsBackSlash = false;
3511 currentCharacter = source[currentPosition++];
3512 // if (((currentCharacter = source[currentPosition++]) == '\\')
3513 // && (source[currentPosition] == 'u')) {
3514 // getNextUnicodeChar();
3516 // if (withoutUnicodePtr != 0) {
3517 // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3521 if (!Character.isDigit(currentCharacter))
3522 throw new InvalidInputException(INVALID_FLOAT);
3523 while (getNextCharAsDigit()) {
3526 if (getNextChar('d', 'D') >= 0)
3527 return TokenNameDoubleLiteral;
3528 // if (getNextChar('f', 'F') >= 0)
3529 // return TokenNameFloatingPointLiteral;
3530 //the long flag has been tested before
3531 return floating ? TokenNameDoubleLiteral : TokenNameIntegerLiteral;
3534 * Search the line number corresponding to a specific position
3537 public final int getLineNumber(int position) {
3538 if (lineEnds == null)
3540 int length = linePtr + 1;
3543 int g = 0, d = length - 1;
3547 if (position < lineEnds[m]) {
3549 } else if (position > lineEnds[m]) {
3555 if (position < lineEnds[m]) {
3560 public void setPHPMode(boolean mode) {
3563 public final void setSource(char[] source) {
3564 //the source-buffer is set to sourceString
3565 if (source == null) {
3566 this.source = new char[0];
3568 this.source = source;
3571 initialPosition = currentPosition = 0;
3572 containsAssertKeyword = false;
3573 withoutUnicodeBuffer = new char[this.source.length];
3574 encapsedStringStack = new Stack();
3576 public String toString() {
3577 if (startPosition == source.length)
3578 return "EOF\n\n" + new String(source); //$NON-NLS-1$
3579 if (currentPosition > source.length)
3580 return "behind the EOF :-( ....\n\n" + new String(source); //$NON-NLS-1$
3581 char front[] = new char[startPosition];
3582 System.arraycopy(source, 0, front, 0, startPosition);
3583 int middleLength = (currentPosition - 1) - startPosition + 1;
3585 if (middleLength > -1) {
3586 middle = new char[middleLength];
3587 System.arraycopy(source, startPosition, middle, 0, middleLength);
3589 middle = new char[0];
3591 char end[] = new char[source.length - (currentPosition - 1)];
3592 System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length
3593 - (currentPosition - 1) - 1);
3594 return new String(front)
3595 + "\n===============================\nStarts here -->" //$NON-NLS-1$
3596 + new String(middle)
3597 + "<-- Ends here\n===============================\n" //$NON-NLS-1$
3600 public final String toStringAction(int act) {
3602 case TokenNameERROR :
3603 return "ScannerError"; // + new String(getCurrentTokenSource()) + ")";
3605 case TokenNameINLINE_HTML :
3606 return "Inline-HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3607 case TokenNameIdentifier :
3608 return "Identifier(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3609 case TokenNameVariable :
3610 return "Variable(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3611 case TokenNameabstract :
3612 return "abstract"; //$NON-NLS-1$
3614 return "AND"; //$NON-NLS-1$
3615 case TokenNamearray :
3616 return "array"; //$NON-NLS-1$
3618 return "as"; //$NON-NLS-1$
3619 case TokenNamebreak :
3620 return "break"; //$NON-NLS-1$
3621 case TokenNamecase :
3622 return "case"; //$NON-NLS-1$
3623 case TokenNameclass :
3624 return "class"; //$NON-NLS-1$
3625 case TokenNamecatch :
3626 return "catch"; //$NON-NLS-1$
3627 case TokenNameclone :
3630 case TokenNameconst :
3633 case TokenNamecontinue :
3634 return "continue"; //$NON-NLS-1$
3635 case TokenNamedefault :
3636 return "default"; //$NON-NLS-1$
3637 // case TokenNamedefine :
3638 // return "define"; //$NON-NLS-1$
3640 return "do"; //$NON-NLS-1$
3641 case TokenNameecho :
3642 return "echo"; //$NON-NLS-1$
3643 case TokenNameelse :
3644 return "else"; //$NON-NLS-1$
3645 case TokenNameelseif :
3646 return "elseif"; //$NON-NLS-1$
3647 case TokenNameendfor :
3648 return "endfor"; //$NON-NLS-1$
3649 case TokenNameendforeach :
3650 return "endforeach"; //$NON-NLS-1$
3651 case TokenNameendif :
3652 return "endif"; //$NON-NLS-1$
3653 case TokenNameendswitch :
3654 return "endswitch"; //$NON-NLS-1$
3655 case TokenNameendwhile :
3656 return "endwhile"; //$NON-NLS-1$
3659 case TokenNameextends :
3660 return "extends"; //$NON-NLS-1$
3661 // case TokenNamefalse :
3662 // return "false"; //$NON-NLS-1$
3663 case TokenNamefinal :
3664 return "final"; //$NON-NLS-1$
3666 return "for"; //$NON-NLS-1$
3667 case TokenNameforeach :
3668 return "foreach"; //$NON-NLS-1$
3669 case TokenNamefunction :
3670 return "function"; //$NON-NLS-1$
3671 case TokenNameglobal :
3672 return "global"; //$NON-NLS-1$
3674 return "if"; //$NON-NLS-1$
3675 case TokenNameimplements :
3676 return "implements"; //$NON-NLS-1$
3677 case TokenNameinclude :
3678 return "include"; //$NON-NLS-1$
3679 case TokenNameinclude_once :
3680 return "include_once"; //$NON-NLS-1$
3681 case TokenNameinstanceof :
3682 return "instanceof"; //$NON-NLS-1$
3683 case TokenNameinterface :
3684 return "interface"; //$NON-NLS-1$
3685 case TokenNameisset :
3686 return "isset"; //$NON-NLS-1$
3687 case TokenNamelist :
3688 return "list"; //$NON-NLS-1$
3690 return "new"; //$NON-NLS-1$
3691 // case TokenNamenull :
3692 // return "null"; //$NON-NLS-1$
3694 return "OR"; //$NON-NLS-1$
3695 case TokenNameprint :
3696 return "print"; //$NON-NLS-1$
3697 case TokenNameprivate :
3698 return "private"; //$NON-NLS-1$
3699 case TokenNameprotected :
3700 return "protected"; //$NON-NLS-1$
3701 case TokenNamepublic :
3702 return "public"; //$NON-NLS-1$
3703 case TokenNamerequire :
3704 return "require"; //$NON-NLS-1$
3705 case TokenNamerequire_once :
3706 return "require_once"; //$NON-NLS-1$
3707 case TokenNamereturn :
3708 return "return"; //$NON-NLS-1$
3709 case TokenNamestatic :
3710 return "static"; //$NON-NLS-1$
3711 case TokenNameswitch :
3712 return "switch"; //$NON-NLS-1$
3713 // case TokenNametrue :
3714 // return "true"; //$NON-NLS-1$
3715 case TokenNameunset :
3716 return "unset"; //$NON-NLS-1$
3718 return "var"; //$NON-NLS-1$
3719 case TokenNamewhile :
3720 return "while"; //$NON-NLS-1$
3722 return "XOR"; //$NON-NLS-1$
3723 // case TokenNamethis :
3724 // return "$this"; //$NON-NLS-1$
3725 case TokenNameIntegerLiteral :
3726 return "Integer(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3727 case TokenNameDoubleLiteral :
3728 return "Double(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3729 case TokenNameStringDoubleQuote :
3730 return "StringLiteral(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3731 case TokenNameStringSingleQuote :
3732 return "StringConstant(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3733 case TokenNameStringInterpolated :
3734 return "StringInterpolated(" + new String(getCurrentTokenSource())
3735 + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3736 case TokenNameEncapsedString0 :
3737 return "`"; //$NON-NLS-1$
3738 case TokenNameEncapsedString1 :
3739 return "\'"; //$NON-NLS-1$
3740 case TokenNameEncapsedString2 :
3741 return "\""; //$NON-NLS-1$
3742 case TokenNameSTRING :
3743 return "STRING(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ //$NON-NLS-2$
3744 case TokenNameHEREDOC :
3745 return "HEREDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3746 case TokenNamePLUS_PLUS :
3747 return "++"; //$NON-NLS-1$
3748 case TokenNameMINUS_MINUS :
3749 return "--"; //$NON-NLS-1$
3750 case TokenNameEQUAL_EQUAL :
3751 return "=="; //$NON-NLS-1$
3752 case TokenNameEQUAL_EQUAL_EQUAL :
3753 return "==="; //$NON-NLS-1$
3754 case TokenNameEQUAL_GREATER :
3755 return "=>"; //$NON-NLS-1$
3756 case TokenNameLESS_EQUAL :
3757 return "<="; //$NON-NLS-1$
3758 case TokenNameGREATER_EQUAL :
3759 return ">="; //$NON-NLS-1$
3760 case TokenNameNOT_EQUAL :
3761 return "!="; //$NON-NLS-1$
3762 case TokenNameNOT_EQUAL_EQUAL :
3763 return "!=="; //$NON-NLS-1$
3764 case TokenNameLEFT_SHIFT :
3765 return "<<"; //$NON-NLS-1$
3766 case TokenNameRIGHT_SHIFT :
3767 return ">>"; //$NON-NLS-1$
3768 case TokenNamePLUS_EQUAL :
3769 return "+="; //$NON-NLS-1$
3770 case TokenNameMINUS_EQUAL :
3771 return "-="; //$NON-NLS-1$
3772 case TokenNameMULTIPLY_EQUAL :
3773 return "*="; //$NON-NLS-1$
3774 case TokenNameDIVIDE_EQUAL :
3775 return "/="; //$NON-NLS-1$
3776 case TokenNameAND_EQUAL :
3777 return "&="; //$NON-NLS-1$
3778 case TokenNameOR_EQUAL :
3779 return "|="; //$NON-NLS-1$
3780 case TokenNameXOR_EQUAL :
3781 return "^="; //$NON-NLS-1$
3782 case TokenNameREMAINDER_EQUAL :
3783 return "%="; //$NON-NLS-1$
3784 case TokenNameDOT_EQUAL :
3785 return ".="; //$NON-NLS-1$
3786 case TokenNameLEFT_SHIFT_EQUAL :
3787 return "<<="; //$NON-NLS-1$
3788 case TokenNameRIGHT_SHIFT_EQUAL :
3789 return ">>="; //$NON-NLS-1$
3790 case TokenNameOR_OR :
3791 return "||"; //$NON-NLS-1$
3792 case TokenNameAND_AND :
3793 return "&&"; //$NON-NLS-1$
3794 case TokenNamePLUS :
3795 return "+"; //$NON-NLS-1$
3796 case TokenNameMINUS :
3797 return "-"; //$NON-NLS-1$
3798 case TokenNameMINUS_GREATER :
3801 return "!"; //$NON-NLS-1$
3802 case TokenNameREMAINDER :
3803 return "%"; //$NON-NLS-1$
3805 return "^"; //$NON-NLS-1$
3807 return "&"; //$NON-NLS-1$
3808 case TokenNameMULTIPLY :
3809 return "*"; //$NON-NLS-1$
3811 return "|"; //$NON-NLS-1$
3812 case TokenNameTWIDDLE :
3813 return "~"; //$NON-NLS-1$
3814 case TokenNameTWIDDLE_EQUAL :
3815 return "~="; //$NON-NLS-1$
3816 case TokenNameDIVIDE :
3817 return "/"; //$NON-NLS-1$
3818 case TokenNameGREATER :
3819 return ">"; //$NON-NLS-1$
3820 case TokenNameLESS :
3821 return "<"; //$NON-NLS-1$
3822 case TokenNameLPAREN :
3823 return "("; //$NON-NLS-1$
3824 case TokenNameRPAREN :
3825 return ")"; //$NON-NLS-1$
3826 case TokenNameLBRACE :
3827 return "{"; //$NON-NLS-1$
3828 case TokenNameRBRACE :
3829 return "}"; //$NON-NLS-1$
3830 case TokenNameLBRACKET :
3831 return "["; //$NON-NLS-1$
3832 case TokenNameRBRACKET :
3833 return "]"; //$NON-NLS-1$
3834 case TokenNameSEMICOLON :
3835 return ";"; //$NON-NLS-1$
3836 case TokenNameQUESTION :
3837 return "?"; //$NON-NLS-1$
3838 case TokenNameCOLON :
3839 return ":"; //$NON-NLS-1$
3840 case TokenNameCOMMA :
3841 return ","; //$NON-NLS-1$
3843 return "."; //$NON-NLS-1$
3844 case TokenNameEQUAL :
3845 return "="; //$NON-NLS-1$
3848 case TokenNameDOLLAR :
3850 case TokenNameDOLLAR_LBRACE :
3853 return "EOF"; //$NON-NLS-1$
3854 case TokenNameWHITESPACE :
3855 return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3856 case TokenNameCOMMENT_LINE :
3857 return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3858 case TokenNameCOMMENT_BLOCK :
3859 return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3860 case TokenNameCOMMENT_PHPDOC :
3861 return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$
3862 // case TokenNameHTML :
3863 // return "HTML(" + new String(getCurrentTokenSource()) + ")";
3865 case TokenNameFILE :
3866 return "__FILE__"; //$NON-NLS-1$
3867 case TokenNameLINE :
3868 return "__LINE__"; //$NON-NLS-1$
3869 case TokenNameCLASS_C :
3870 return "__CLASS__"; //$NON-NLS-1$
3871 case TokenNameMETHOD_C :
3872 return "__METHOD__"; //$NON-NLS-1$
3873 case TokenNameFUNC_C :
3874 return "__FUNCTION__"; //$NON-NLS-1
3875 case TokenNameboolCAST :
3876 return "( bool )"; //$NON-NLS-1$
3877 case TokenNameintCAST :
3878 return "( int )"; //$NON-NLS-1$
3879 case TokenNamedoubleCAST :
3880 return "( double )"; //$NON-NLS-1$
3881 case TokenNameobjectCAST :
3882 return "( object )"; //$NON-NLS-1$
3883 case TokenNamestringCAST :
3884 return "( string )"; //$NON-NLS-1$
3886 return "not-a-token(" + (new Integer(act)) + ") "
3887 + new String(getCurrentTokenSource()); //$NON-NLS-1$
3894 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace) {
3895 this(tokenizeComments, tokenizeWhiteSpace, false);
3897 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
3898 boolean checkNonExternalizedStringLiterals) {
3899 this(tokenizeComments, tokenizeWhiteSpace,
3900 checkNonExternalizedStringLiterals, false);
3902 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
3903 boolean checkNonExternalizedStringLiterals, boolean assertMode) {
3904 this(tokenizeComments, tokenizeWhiteSpace,
3905 checkNonExternalizedStringLiterals, assertMode, false, null, null);
3907 public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace,
3908 boolean checkNonExternalizedStringLiterals, boolean assertMode,
3909 boolean tokenizeStrings,
3911 char[][] taskPriorities) {
3912 this.eofPosition = Integer.MAX_VALUE;
3913 this.tokenizeComments = tokenizeComments;
3914 this.tokenizeWhiteSpace = tokenizeWhiteSpace;
3915 this.tokenizeStrings = tokenizeStrings;
3916 this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals;
3917 this.assertMode = assertMode;
3918 this.encapsedStringStack = null;
3919 this.taskTags = taskTags;
3920 this.taskPriorities = taskPriorities;
3922 private void checkNonExternalizeString() throws InvalidInputException {
3923 if (currentLine == null)
3925 parseTags(currentLine);
3927 private void parseTags(NLSLine line) throws InvalidInputException {
3928 String s = new String(getCurrentTokenSource());
3929 int pos = s.indexOf(TAG_PREFIX);
3930 int lineLength = line.size();
3932 int start = pos + TAG_PREFIX_LENGTH;
3933 int end = s.indexOf(TAG_POSTFIX, start);
3934 String index = s.substring(start, end);
3937 i = Integer.parseInt(index) - 1;
3938 // Tags are one based not zero based.
3939 } catch (NumberFormatException e) {
3940 i = -1; // we don't want to consider this as a valid NLS tag
3942 if (line.exists(i)) {
3945 pos = s.indexOf(TAG_PREFIX, start);
3947 this.nonNLSStrings = new StringLiteral[lineLength];
3948 int nonNLSCounter = 0;
3949 for (Iterator iterator = line.iterator(); iterator.hasNext();) {
3950 StringLiteral literal = (StringLiteral) iterator.next();
3951 if (literal != null) {
3952 this.nonNLSStrings[nonNLSCounter++] = literal;
3955 if (nonNLSCounter == 0) {
3956 this.nonNLSStrings = null;
3960 this.wasNonExternalizedStringLiteral = true;
3961 if (nonNLSCounter != lineLength) {
3962 System.arraycopy(this.nonNLSStrings, 0,
3963 (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0,
3968 public final void scanEscapeCharacter() throws InvalidInputException {
3969 // the string with "\\u" is a legal string of two chars \ and u
3970 //thus we use a direct access to the source (for regular cases).
3971 if (unicodeAsBackSlash) {
3972 // consume next character
3973 unicodeAsBackSlash = false;
3974 // if (((currentCharacter = source[currentPosition++]) == '\\') &&
3975 // (source[currentPosition] == 'u')) {
3976 // getNextUnicodeChar();
3978 if (withoutUnicodePtr != 0) {
3979 withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
3983 currentCharacter = source[currentPosition++];
3984 switch (currentCharacter) {
3986 currentCharacter = '\b';
3989 currentCharacter = '\t';
3992 currentCharacter = '\n';
3995 currentCharacter = '\f';
3998 currentCharacter = '\r';
4001 currentCharacter = '\"';
4004 currentCharacter = '\'';
4007 currentCharacter = '\\';
4010 // -----------octal escape--------------
4012 // OctalDigit OctalDigit
4013 // ZeroToThree OctalDigit OctalDigit
4014 int number = Character.getNumericValue(currentCharacter);
4015 if (number >= 0 && number <= 7) {
4016 boolean zeroToThreeNot = number > 3;
4017 if (Character.isDigit(currentCharacter = source[currentPosition++])) {
4018 int digit = Character.getNumericValue(currentCharacter);
4019 if (digit >= 0 && digit <= 7) {
4020 number = (number * 8) + digit;
4022 .isDigit(currentCharacter = source[currentPosition++])) {
4023 if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit
4024 // Digit --> ignore last character
4027 digit = Character.getNumericValue(currentCharacter);
4028 if (digit >= 0 && digit <= 7) { // has read \ZeroToThree
4029 // OctalDigit OctalDigit
4030 number = (number * 8) + digit;
4031 } else { // has read \ZeroToThree OctalDigit NonOctalDigit
4032 // --> ignore last character
4036 } else { // has read \OctalDigit NonDigit--> ignore last
4040 } else { // has read \OctalDigit NonOctalDigit--> ignore last
4044 } else { // has read \OctalDigit --> ignore last character
4048 throw new InvalidInputException(INVALID_ESCAPE);
4049 currentCharacter = (char) number;
4051 throw new InvalidInputException(INVALID_ESCAPE);
4054 // chech presence of task: tags
4055 public void checkTaskTag(int commentStart, int commentEnd) {
4056 // only look for newer task: tags
4057 if (this.foundTaskCount > 0
4058 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) {
4061 int foundTaskIndex = this.foundTaskCount;
4062 nextChar : for (int i = commentStart; i < commentEnd
4063 && i < this.eofPosition; i++) {
4065 char[] priority = null;
4066 // check for tag occurrence
4067 nextTag : for (int itag = 0; itag < this.taskTags.length; itag++) {
4068 tag = this.taskTags[itag];
4069 priority = this.taskPriorities != null
4070 && itag < this.taskPriorities.length
4071 ? this.taskPriorities[itag]
4073 int tagLength = tag.length;
4074 for (int t = 0; t < tagLength; t++) {
4075 if (this.source[i + t] != tag[t])
4078 if (this.foundTaskTags == null) {
4079 this.foundTaskTags = new char[5][];
4080 this.foundTaskMessages = new char[5][];
4081 this.foundTaskPriorities = new char[5][];
4082 this.foundTaskPositions = new int[5][];
4083 } else if (this.foundTaskCount == this.foundTaskTags.length) {
4084 System.arraycopy(this.foundTaskTags, 0,
4085 this.foundTaskTags = new char[this.foundTaskCount * 2][], 0,
4086 this.foundTaskCount);
4087 System.arraycopy(this.foundTaskMessages, 0,
4088 this.foundTaskMessages = new char[this.foundTaskCount * 2][], 0,
4089 this.foundTaskCount);
4090 System.arraycopy(this.foundTaskPriorities, 0,
4091 this.foundTaskPriorities = new char[this.foundTaskCount * 2][],
4092 0, this.foundTaskCount);
4093 System.arraycopy(this.foundTaskPositions, 0,
4094 this.foundTaskPositions = new int[this.foundTaskCount * 2][], 0,
4095 this.foundTaskCount);
4097 this.foundTaskTags[this.foundTaskCount] = tag;
4098 this.foundTaskPriorities[this.foundTaskCount] = priority;
4099 this.foundTaskPositions[this.foundTaskCount] = new int[]{i,
4101 this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR;
4102 this.foundTaskCount++;
4103 i += tagLength - 1; // will be incremented when looping
4106 for (int i = foundTaskIndex; i < this.foundTaskCount; i++) {
4107 // retrieve message start and end positions
4108 int msgStart = this.foundTaskPositions[i][0]
4109 + this.foundTaskTags[i].length;
4110 int max_value = i + 1 < this.foundTaskCount
4111 ? this.foundTaskPositions[i + 1][0] - 1
4113 // at most beginning of next task
4114 if (max_value < msgStart)
4115 max_value = msgStart; // would only occur if tag is before EOF.
4118 for (int j = msgStart; j < max_value; j++) {
4119 if ((c = this.source[j]) == '\n' || c == '\r') {
4125 for (int j = max_value; j > msgStart; j--) {
4126 if ((c = this.source[j]) == '*') {
4134 if (msgStart == end)
4137 while (CharOperation.isWhitespace(source[end]) && msgStart <= end)
4139 while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end)
4141 // update the end position of the task
4142 this.foundTaskPositions[i][1] = end;
4143 // get the message source
4144 final int messageLength = end - msgStart + 1;
4145 char[] message = new char[messageLength];
4146 System.arraycopy(source, msgStart, message, 0, messageLength);
4147 this.foundTaskMessages[i] = message;