From: khartlage Date: Fri, 23 May 2003 18:45:32 +0000 (+0000) Subject: Added debug infos to CodeFormatter X-Git-Url: http://secure.phpeclipse.com Added debug infos to CodeFormatter --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java index ac3546e..2fa5f0b 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java @@ -116,14 +116,12 @@ public class Scanner implements IScanner, ITerminalSymbols { charArray_y = new char[] { 'y' }, charArray_z = new char[] { 'z' }; - static final char[] initCharArray = - new char[] { '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' }; + static final char[] initCharArray = new char[] { '\u0000', '\u0000', '\u0000', '\u0000', '\u0000', '\u0000' }; static final int TableSize = 30, InternalTableSize = 6; //30*6 = 180 entries public static final int OptimizedLength = 6; public /*static*/ - final char[][][][] charArray_length = - new char[OptimizedLength][TableSize][InternalTableSize][]; + final char[][][][] charArray_length = new char[OptimizedLength][TableSize][InternalTableSize][]; // support for detecting non-externalized string literals int currentLineNr = -1; int previousLineNr = -1; @@ -146,11 +144,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } } } - static int newEntry2 = 0, - newEntry3 = 0, - newEntry4 = 0, - newEntry5 = 0, - newEntry6 = 0; + static int newEntry2 = 0, newEntry3 = 0, newEntry4 = 0, newEntry5 = 0, newEntry6 = 0; public static final int RoundBracket = 0; public static final int SquareBracket = 1; @@ -158,7 +152,7 @@ public class Scanner implements IScanner, ITerminalSymbols { public static final int BracketKinds = 3; public static final boolean DEBUG = false; - + public Scanner() { this(false, false); } @@ -171,9 +165,7 @@ public class Scanner implements IScanner, ITerminalSymbols { * permissible as the first character in a PHP identifier */ public static boolean isPHPIdentifierStart(char ch) { - return Character.isLetter(ch) - || (ch == '_') - || (0x7F <= ch && ch <= 0xFF); + return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF); } /** @@ -181,9 +173,7 @@ public class Scanner implements IScanner, ITerminalSymbols { * other than the first character */ public static boolean isPHPIdentifierPart(char ch) { - return Character.isLetterOrDigit(ch) - || (ch == '_') - || (0x7F <= ch && ch <= 0xFF); + return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF); } public final boolean atEnd() { @@ -196,38 +186,33 @@ public class Scanner implements IScanner, ITerminalSymbols { //return the token REAL source (aka unicodes are precomputed) char[] result; -// if (withoutUnicodePtr != 0) -// //0 is used as a fast test flag so the real first char is in position 1 -// System.arraycopy( -// withoutUnicodeBuffer, -// 1, -// result = new char[withoutUnicodePtr], -// 0, -// withoutUnicodePtr); -// else { - int length = currentPosition - startPosition; - switch (length) { // see OptimizedLength - case 1 : - return optimizedCurrentTokenSource1(); - case 2 : - return optimizedCurrentTokenSource2(); - case 3 : - return optimizedCurrentTokenSource3(); - case 4 : - return optimizedCurrentTokenSource4(); - case 5 : - return optimizedCurrentTokenSource5(); - case 6 : - return optimizedCurrentTokenSource6(); - } - //no optimization - System.arraycopy( - source, - startPosition, - result = new char[length], - 0, - length); - // } + // if (withoutUnicodePtr != 0) + // //0 is used as a fast test flag so the real first char is in position 1 + // System.arraycopy( + // withoutUnicodeBuffer, + // 1, + // result = new char[withoutUnicodePtr], + // 0, + // withoutUnicodePtr); + // else { + int length = currentPosition - startPosition; + switch (length) { // see OptimizedLength + case 1 : + return optimizedCurrentTokenSource1(); + case 2 : + return optimizedCurrentTokenSource2(); + case 3 : + return optimizedCurrentTokenSource3(); + case 4 : + return optimizedCurrentTokenSource4(); + case 5 : + return optimizedCurrentTokenSource5(); + case 6 : + return optimizedCurrentTokenSource6(); + } + //no optimization + System.arraycopy(source, startPosition, result = new char[length], 0, length); + // } return result; } public int getCurrentTokenEndPosition() { @@ -237,23 +222,18 @@ public class Scanner implements IScanner, ITerminalSymbols { // Return the token REAL source (aka unicodes are precomputed) char[] result; -// if (withoutUnicodePtr != 0) -// // 0 is used as a fast test flag so the real first char is in position 1 -// System.arraycopy( -// withoutUnicodeBuffer, -// 1, -// result = new char[withoutUnicodePtr], -// 0, -// withoutUnicodePtr); -// else { - int length; - System.arraycopy( - source, - startPosition, - result = new char[length = currentPosition - startPosition], - 0, - length); -// } + // if (withoutUnicodePtr != 0) + // // 0 is used as a fast test flag so the real first char is in position 1 + // System.arraycopy( + // withoutUnicodeBuffer, + // 1, + // result = new char[withoutUnicodePtr], + // 0, + // withoutUnicodePtr); + // else { + int length; + System.arraycopy(source, startPosition, result = new char[length = currentPosition - startPosition], 0, length); + // } return result; } @@ -261,23 +241,18 @@ public class Scanner implements IScanner, ITerminalSymbols { // Return the token REAL source (aka unicodes are precomputed) char[] result; -// if (withoutUnicodePtr != 0) -// // 0 is used as a fast test flag so the real first char is in position 1 -// System.arraycopy( -// withoutUnicodeBuffer, -// 1, -// result = new char[withoutUnicodePtr], -// 0, -// withoutUnicodePtr); -// else { - int length; - System.arraycopy( - source, - startPos, - result = new char[length = currentPosition - startPos], - 0, - length); - // } + // if (withoutUnicodePtr != 0) + // // 0 is used as a fast test flag so the real first char is in position 1 + // System.arraycopy( + // withoutUnicodeBuffer, + // 1, + // result = new char[withoutUnicodePtr], + // 0, + // withoutUnicodePtr); + // else { + int length; + System.arraycopy(source, startPos, result = new char[length = currentPosition - startPos], 0, length); + // } return result; } @@ -293,12 +268,7 @@ public class Scanner implements IScanner, ITerminalSymbols { result = new char[withoutUnicodePtr - 2], 0, withoutUnicodePtr - 2); else { int length; - System.arraycopy( - source, - startPosition + 1, - result = new char[length = currentPosition - startPosition - 2], - 0, - length); + System.arraycopy(source, startPosition + 1, result = new char[length = currentPosition - startPosition - 2], 0, length); } return result; } @@ -365,62 +335,62 @@ public class Scanner implements IScanner, ITerminalSymbols { int temp = currentPosition; try { currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// int c1, c2, c3, c4; -// int unicodeSize = 6; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// unicodeSize++; -// } -// -// if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c1 < 0) -// || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c2 < 0) -// || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c3 < 0) -// || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c4 < 0)) { -// currentPosition = temp; -// return false; -// } -// -// currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// if (currentCharacter != testedChar) { -// currentPosition = temp; -// return false; -// } -// unicodeAsBackSlash = currentCharacter == '\\'; -// -// //need the unicode buffer -// if (withoutUnicodePtr == 0) { -// //buffer all the entries that have been left aside.... -// withoutUnicodePtr = currentPosition - unicodeSize - startPosition; -// System.arraycopy( -// source, -// startPosition, -// withoutUnicodeBuffer, -// 1, -// withoutUnicodePtr); -// } -// //fill the buffer with the char -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// return true; -// -// } //-------------end unicode traitement-------------- -// else { - if (currentCharacter != testedChar) { - currentPosition = temp; - return false; - } - unicodeAsBackSlash = false; -// if (withoutUnicodePtr != 0) -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; - return true; -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1, c2, c3, c4; + // int unicodeSize = 6; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // unicodeSize++; + // } + // + // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c1 < 0) + // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c2 < 0) + // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c3 < 0) + // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c4 < 0)) { + // currentPosition = temp; + // return false; + // } + // + // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // if (currentCharacter != testedChar) { + // currentPosition = temp; + // return false; + // } + // unicodeAsBackSlash = currentCharacter == '\\'; + // + // //need the unicode buffer + // if (withoutUnicodePtr == 0) { + // //buffer all the entries that have been left aside.... + // withoutUnicodePtr = currentPosition - unicodeSize - startPosition; + // System.arraycopy( + // source, + // startPosition, + // withoutUnicodeBuffer, + // 1, + // withoutUnicodePtr); + // } + // //fill the buffer with the char + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // return true; + // + // } //-------------end unicode traitement-------------- + // else { + if (currentCharacter != testedChar) { + currentPosition = temp; + return false; + } + unicodeAsBackSlash = false; + // if (withoutUnicodePtr != 0) + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + return true; + // } } catch (IndexOutOfBoundsException e) { unicodeAsBackSlash = false; currentPosition = temp; @@ -443,68 +413,68 @@ public class Scanner implements IScanner, ITerminalSymbols { try { int result; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// int c1, c2, c3, c4; -// int unicodeSize = 6; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// unicodeSize++; -// } -// -// if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c1 < 0) -// || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c2 < 0) -// || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c3 < 0) -// || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c4 < 0)) { -// currentPosition = temp; -// return 2; -// } -// -// currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// if (currentCharacter == testedChar1) -// result = 0; -// else if (currentCharacter == testedChar2) -// result = 1; -// else { -// currentPosition = temp; -// return -1; -// } -// -// //need the unicode buffer -// if (withoutUnicodePtr == 0) { -// //buffer all the entries that have been left aside.... -// withoutUnicodePtr = currentPosition - unicodeSize - startPosition; -// System.arraycopy( -// source, -// startPosition, -// withoutUnicodeBuffer, -// 1, -// withoutUnicodePtr); -// } -// //fill the buffer with the char -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// return result; -// } //-------------end unicode traitement-------------- -// else { - if (currentCharacter == testedChar1) - result = 0; - else if (currentCharacter == testedChar2) - result = 1; - else { - currentPosition = temp; - return -1; - } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1, c2, c3, c4; + // int unicodeSize = 6; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // unicodeSize++; + // } + // + // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c1 < 0) + // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c2 < 0) + // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c3 < 0) + // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c4 < 0)) { + // currentPosition = temp; + // return 2; + // } + // + // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // if (currentCharacter == testedChar1) + // result = 0; + // else if (currentCharacter == testedChar2) + // result = 1; + // else { + // currentPosition = temp; + // return -1; + // } + // + // //need the unicode buffer + // if (withoutUnicodePtr == 0) { + // //buffer all the entries that have been left aside.... + // withoutUnicodePtr = currentPosition - unicodeSize - startPosition; + // System.arraycopy( + // source, + // startPosition, + // withoutUnicodeBuffer, + // 1, + // withoutUnicodePtr); + // } + // //fill the buffer with the char + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // return result; + // } //-------------end unicode traitement-------------- + // else { + if (currentCharacter == testedChar1) + result = 0; + else if (currentCharacter == testedChar2) + result = 1; + else { + currentPosition = temp; + return -1; + } -// if (withoutUnicodePtr != 0) -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; - return result; - // } + // if (withoutUnicodePtr != 0) + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + return result; + // } } catch (IndexOutOfBoundsException e) { currentPosition = temp; return -1; @@ -524,59 +494,59 @@ public class Scanner implements IScanner, ITerminalSymbols { int temp = currentPosition; try { currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// int c1, c2, c3, c4; -// int unicodeSize = 6; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// unicodeSize++; -// } -// -// if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c1 < 0) -// || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c2 < 0) -// || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c3 < 0) -// || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c4 < 0)) { -// currentPosition = temp; -// return false; -// } -// -// currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// if (!Character.isDigit(currentCharacter)) { -// currentPosition = temp; -// return false; -// } -// -// //need the unicode buffer -// if (withoutUnicodePtr == 0) { -// //buffer all the entries that have been left aside.... -// withoutUnicodePtr = currentPosition - unicodeSize - startPosition; -// System.arraycopy( -// source, -// startPosition, -// withoutUnicodeBuffer, -// 1, -// withoutUnicodePtr); -// } -// //fill the buffer with the char -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// return true; -// } //-------------end unicode traitement-------------- -// else { - if (!Character.isDigit(currentCharacter)) { - currentPosition = temp; - return false; - } -// if (withoutUnicodePtr != 0) -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; - return true; -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1, c2, c3, c4; + // int unicodeSize = 6; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // unicodeSize++; + // } + // + // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c1 < 0) + // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c2 < 0) + // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c3 < 0) + // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c4 < 0)) { + // currentPosition = temp; + // return false; + // } + // + // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // if (!Character.isDigit(currentCharacter)) { + // currentPosition = temp; + // return false; + // } + // + // //need the unicode buffer + // if (withoutUnicodePtr == 0) { + // //buffer all the entries that have been left aside.... + // withoutUnicodePtr = currentPosition - unicodeSize - startPosition; + // System.arraycopy( + // source, + // startPosition, + // withoutUnicodeBuffer, + // 1, + // withoutUnicodePtr); + // } + // //fill the buffer with the char + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // return true; + // } //-------------end unicode traitement-------------- + // else { + if (!Character.isDigit(currentCharacter)) { + currentPosition = temp; + return false; + } + // if (withoutUnicodePtr != 0) + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + return true; + // } } catch (IndexOutOfBoundsException e) { currentPosition = temp; return false; @@ -596,59 +566,59 @@ public class Scanner implements IScanner, ITerminalSymbols { int temp = currentPosition; try { currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// int c1, c2, c3, c4; -// int unicodeSize = 6; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// unicodeSize++; -// } -// -// if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c1 < 0) -// || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c2 < 0) -// || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c3 < 0) -// || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c4 < 0)) { -// currentPosition = temp; -// return false; -// } -// -// currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// if (Character.digit(currentCharacter, radix) == -1) { -// currentPosition = temp; -// return false; -// } -// -// //need the unicode buffer -// if (withoutUnicodePtr == 0) { -// //buffer all the entries that have been left aside.... -// withoutUnicodePtr = currentPosition - unicodeSize - startPosition; -// System.arraycopy( -// source, -// startPosition, -// withoutUnicodeBuffer, -// 1, -// withoutUnicodePtr); -// } -// //fill the buffer with the char -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// return true; -// } //-------------end unicode traitement-------------- -// else { - if (Character.digit(currentCharacter, radix) == -1) { - currentPosition = temp; - return false; - } -// if (withoutUnicodePtr != 0) -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; - return true; -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1, c2, c3, c4; + // int unicodeSize = 6; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // unicodeSize++; + // } + // + // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c1 < 0) + // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c2 < 0) + // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c3 < 0) + // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c4 < 0)) { + // currentPosition = temp; + // return false; + // } + // + // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // if (Character.digit(currentCharacter, radix) == -1) { + // currentPosition = temp; + // return false; + // } + // + // //need the unicode buffer + // if (withoutUnicodePtr == 0) { + // //buffer all the entries that have been left aside.... + // withoutUnicodePtr = currentPosition - unicodeSize - startPosition; + // System.arraycopy( + // source, + // startPosition, + // withoutUnicodeBuffer, + // 1, + // withoutUnicodePtr); + // } + // //fill the buffer with the char + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // return true; + // } //-------------end unicode traitement-------------- + // else { + if (Character.digit(currentCharacter, radix) == -1) { + currentPosition = temp; + return false; + } + // if (withoutUnicodePtr != 0) + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + return true; + // } } catch (IndexOutOfBoundsException e) { currentPosition = temp; return false; @@ -668,60 +638,60 @@ public class Scanner implements IScanner, ITerminalSymbols { int temp = currentPosition; try { currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// int c1, c2, c3, c4; -// int unicodeSize = 6; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// unicodeSize++; -// } -// -// if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c1 < 0) -// || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c2 < 0) -// || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c3 < 0) -// || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c4 < 0)) { -// currentPosition = temp; -// return false; -// } -// -// currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// if (!isPHPIdentifierPart(currentCharacter)) { -// currentPosition = temp; -// return false; -// } -// -// //need the unicode buffer -// if (withoutUnicodePtr == 0) { -// //buffer all the entries that have been left aside.... -// withoutUnicodePtr = currentPosition - unicodeSize - startPosition; -// System.arraycopy( -// source, -// startPosition, -// withoutUnicodeBuffer, -// 1, -// withoutUnicodePtr); -// } -// //fill the buffer with the char -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// return true; -// } //-------------end unicode traitement-------------- -// else { - if (!isPHPIdentifierPart(currentCharacter)) { - currentPosition = temp; - return false; - } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1, c2, c3, c4; + // int unicodeSize = 6; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // unicodeSize++; + // } + // + // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c1 < 0) + // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c2 < 0) + // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c3 < 0) + // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c4 < 0)) { + // currentPosition = temp; + // return false; + // } + // + // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // if (!isPHPIdentifierPart(currentCharacter)) { + // currentPosition = temp; + // return false; + // } + // + // //need the unicode buffer + // if (withoutUnicodePtr == 0) { + // //buffer all the entries that have been left aside.... + // withoutUnicodePtr = currentPosition - unicodeSize - startPosition; + // System.arraycopy( + // source, + // startPosition, + // withoutUnicodeBuffer, + // 1, + // withoutUnicodePtr); + // } + // //fill the buffer with the char + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // return true; + // } //-------------end unicode traitement-------------- + // else { + if (!isPHPIdentifierPart(currentCharacter)) { + currentPosition = temp; + return false; + } -// if (withoutUnicodePtr != 0) -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; - return true; -// } + // if (withoutUnicodePtr != 0) + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + return true; + // } } catch (IndexOutOfBoundsException e) { currentPosition = temp; return false; @@ -736,8 +706,7 @@ public class Scanner implements IScanner, ITerminalSymbols { if (currentCharacter == '<') { if (getNextChar('?')) { currentCharacter = source[currentPosition++]; - if ((currentCharacter == ' ') - || Character.isWhitespace(currentCharacter)) { + if ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) { // = 0) { @@ -808,22 +776,20 @@ public class Scanner implements IScanner, ITerminalSymbols { do { startPosition = currentPosition; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// isWhiteSpace = jumpOverUnicodeWhiteSpace(); -// } else { - if ((currentCharacter == '\r') || (currentCharacter == '\n')) { - checkNonExternalizeString(); - if (recordLineSeparator) { - pushLineSeparator(); - } else { - currentLine = null; - } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // isWhiteSpace = jumpOverUnicodeWhiteSpace(); + // } else { + if ((currentCharacter == '\r') || (currentCharacter == '\n')) { + checkNonExternalizeString(); + if (recordLineSeparator) { + pushLineSeparator(); + } else { + currentLine = null; } - isWhiteSpace = - (currentCharacter == ' ') - || Character.isWhitespace(currentCharacter); -// } + } + isWhiteSpace = (currentCharacter == ' ') || Character.isWhitespace(currentCharacter); + // } } while (isWhiteSpace); if (tokenizeWhiteSpace && (whiteStart != currentPosition - 1)) { // reposition scanner in case we are interested by spaces as tokens @@ -931,8 +897,7 @@ public class Scanner implements IScanner, ITerminalSymbols { currentLine = null; } for (int i = 0; i < heredocLength; i++) { - if (source[currentPosition + i] - != source[heredocStart + i]) { + if (source[currentPosition + i] != source[heredocStart + i]) { endTag = false; break; } @@ -1085,15 +1050,15 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = -// currentCharacter; -// } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = + // currentCharacter; + // } + // } while (currentCharacter != '\'') { @@ -1121,19 +1086,11 @@ public class Scanner implements IScanner, ITerminalSymbols { escapeSize = currentPosition - escapeSize; if (withoutUnicodePtr == 0) { //buffer all the entries that have been left aside.... - withoutUnicodePtr = - currentPosition - escapeSize - 1 - startPosition; - System.arraycopy( - source, - startPosition, - withoutUnicodeBuffer, - 1, - withoutUnicodePtr); - withoutUnicodeBuffer[++withoutUnicodePtr] = - currentCharacter; + withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition; + System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr); + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } else { //overwrite the / in the buffer - withoutUnicodeBuffer[withoutUnicodePtr] = - currentCharacter; + withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter; if (backSlashAsUnicodeInString) { //there are TWO \ in the stream where only one is correct withoutUnicodePtr--; } @@ -1142,15 +1099,14 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = - currentCharacter; - } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } + // } } } catch (IndexOutOfBoundsException e) { @@ -1177,11 +1133,7 @@ public class Scanner implements IScanner, ITerminalSymbols { currentLine = new NLSLine(); lines.add(currentLine); } - currentLine.add( - new StringLiteral( - getCurrentTokenSourceString(), - startPosition, - currentPosition - 1)); + currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1)); } return TokenNameStringConstant; case '"' : @@ -1189,15 +1141,15 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = -// currentCharacter; -// } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = + // currentCharacter; + // } + // } while (currentCharacter != '"') { @@ -1225,19 +1177,11 @@ public class Scanner implements IScanner, ITerminalSymbols { escapeSize = currentPosition - escapeSize; if (withoutUnicodePtr == 0) { //buffer all the entries that have been left aside.... - withoutUnicodePtr = - currentPosition - escapeSize - 1 - startPosition; - System.arraycopy( - source, - startPosition, - withoutUnicodeBuffer, - 1, - withoutUnicodePtr); - withoutUnicodeBuffer[++withoutUnicodePtr] = - currentCharacter; + withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition; + System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr); + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } else { //overwrite the / in the buffer - withoutUnicodeBuffer[withoutUnicodePtr] = - currentCharacter; + withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter; if (backSlashAsUnicodeInString) { //there are TWO \ in the stream where only one is correct withoutUnicodePtr--; } @@ -1246,15 +1190,14 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = - currentCharacter; - } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } + // } } } catch (IndexOutOfBoundsException e) { @@ -1281,11 +1224,7 @@ public class Scanner implements IScanner, ITerminalSymbols { currentLine = new NLSLine(); lines.add(currentLine); } - currentLine.add( - new StringLiteral( - getCurrentTokenSourceString(), - startPosition, - currentPosition - 1)); + currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1)); } return TokenNameStringLiteral; case '`' : @@ -1293,15 +1232,15 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = -// currentCharacter; -// } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = + // currentCharacter; + // } + // } while (currentCharacter != '`') { @@ -1329,19 +1268,11 @@ public class Scanner implements IScanner, ITerminalSymbols { escapeSize = currentPosition - escapeSize; if (withoutUnicodePtr == 0) { //buffer all the entries that have been left aside.... - withoutUnicodePtr = - currentPosition - escapeSize - 1 - startPosition; - System.arraycopy( - source, - startPosition, - withoutUnicodeBuffer, - 1, - withoutUnicodePtr); - withoutUnicodeBuffer[++withoutUnicodePtr] = - currentCharacter; + withoutUnicodePtr = currentPosition - escapeSize - 1 - startPosition; + System.arraycopy(source, startPosition, withoutUnicodeBuffer, 1, withoutUnicodePtr); + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; } else { //overwrite the / in the buffer - withoutUnicodeBuffer[withoutUnicodePtr] = - currentCharacter; + withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter; if (backSlashAsUnicodeInString) { //there are TWO \ in the stream where only one is correct withoutUnicodePtr--; } @@ -1350,15 +1281,14 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = - currentCharacter; - } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } + // } } } catch (IndexOutOfBoundsException e) { @@ -1385,63 +1315,57 @@ public class Scanner implements IScanner, ITerminalSymbols { currentLine = new NLSLine(); lines.add(currentLine); } - currentLine.add( - new StringLiteral( - getCurrentTokenSourceString(), - startPosition, - currentPosition - 1)); + currentLine.add(new StringLiteral(getCurrentTokenSourceString(), startPosition, currentPosition - 1)); } return TokenNameStringInterpolated; case '#' : case '/' : { int test; - if ((currentCharacter == '#') - || (test = getNextChar('/', '*')) == 0) { + if ((currentCharacter == '#') || (test = getNextChar('/', '*')) == 0) { //line comment int endPositionForLineComment = 0; try { //get the next char currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) -// == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// int c1 = 0, c2 = 0, c3 = 0, c4 = 0; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// } -// if ((c1 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c1 < 0 -// || (c2 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c2 < 0 -// || (c3 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c3 < 0 -// || (c4 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c4 < 0) { -// throw new InvalidInputException(INVALID_UNICODE_ESCAPE); -// } else { -// currentCharacter = -// (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// } -// } + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c4 < 0) { + // throw new InvalidInputException(INVALID_UNICODE_ESCAPE); + // } else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } //handle the \\u case manually into comment -// if (currentCharacter == '\\') { -// if (source[currentPosition] == '\\') -// currentPosition++; -// } //jump over the \\ + // if (currentCharacter == '\\') { + // if (source[currentPosition] == '\\') + // currentPosition++; + // } //jump over the \\ boolean isUnicode = false; - while (currentCharacter != '\r' - && currentCharacter != '\n') { + while (currentCharacter != '\r' && currentCharacter != '\n') { if (currentCharacter == '?') { if (getNextChar('>')) { startPosition = currentPosition - 2; @@ -1453,46 +1377,46 @@ public class Scanner implements IScanner, ITerminalSymbols { //get the next char isUnicode = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) -// == '\\') -// && (source[currentPosition] == 'u')) { -// isUnicode = true; -// //-------------unicode traitement ------------ -// int c1 = 0, c2 = 0, c3 = 0, c4 = 0; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// } -// if ((c1 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c1 < 0 -// || (c2 = -// Character.getNumericValue( -// source[currentPosition++])) -// > 15 -// || c2 < 0 -// || (c3 = -// Character.getNumericValue( -// source[currentPosition++])) -// > 15 -// || c3 < 0 -// || (c4 = -// Character.getNumericValue( -// source[currentPosition++])) -// > 15 -// || c4 < 0) { -// throw new InvalidInputException(INVALID_UNICODE_ESCAPE); -// } else { -// currentCharacter = -// (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// } -// } + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // isUnicode = true; + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue( + // source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue( + // source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue( + // source[currentPosition++])) + // > 15 + // || c4 < 0) { + // throw new InvalidInputException(INVALID_UNICODE_ESCAPE); + // } else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } //handle the \\u case manually into comment -// if (currentCharacter == '\\') { -// if (source[currentPosition] == '\\') -// currentPosition++; -// } //jump over the \\ + // if (currentCharacter == '\\') { + // if (source[currentPosition] == '\\') + // currentPosition++; + // } //jump over the \\ } if (isUnicode) { endPositionForLineComment = currentPosition - 6; @@ -1500,8 +1424,7 @@ public class Scanner implements IScanner, ITerminalSymbols { endPositionForLineComment = currentPosition - 1; } recordComment(false); - if ((currentCharacter == '\r') - || (currentCharacter == '\n')) { + if ((currentCharacter == '\r') || (currentCharacter == '\n')) { checkNonExternalizeString(); if (recordLineSeparator) { if (isUnicode) { @@ -1535,22 +1458,21 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = -// currentCharacter; -// } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = + // currentCharacter; + // } + // } if (currentCharacter == '*') { isJavadoc = true; star = true; } - if ((currentCharacter == '\r') - || (currentCharacter == '\n')) { + if ((currentCharacter == '\r') || (currentCharacter == '\n')) { checkNonExternalizeString(); if (recordLineSeparator) { pushLineSeparator(); @@ -1560,26 +1482,25 @@ public class Scanner implements IScanner, ITerminalSymbols { } try { //get the next char currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) -// == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// getNextUnicodeChar(); -// } + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // getNextUnicodeChar(); + // } //handle the \\u case manually into comment -// if (currentCharacter == '\\') { -// if (source[currentPosition] == '\\') -// currentPosition++; -// //jump over the \\ -// } + // if (currentCharacter == '\\') { + // if (source[currentPosition] == '\\') + // currentPosition++; + // //jump over the \\ + // } // empty comment is not a javadoc /**/ if (currentCharacter == '/') { isJavadoc = false; } //loop until end of comment */ while ((currentCharacter != '/') || (!star)) { - if ((currentCharacter == '\r') - || (currentCharacter == '\n')) { + if ((currentCharacter == '\r') || (currentCharacter == '\n')) { checkNonExternalizeString(); if (recordLineSeparator) { pushLineSeparator(); @@ -1590,17 +1511,17 @@ public class Scanner implements IScanner, ITerminalSymbols { star = currentCharacter == '*'; //get next char currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) -// == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// getNextUnicodeChar(); -// } + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // getNextUnicodeChar(); + // } //handle the \\u case manually into comment -// if (currentCharacter == '\\') { -// if (source[currentPosition] == '\\') -// currentPosition++; -// } //jump over the \\ + // if (currentCharacter == '\\') { + // if (source[currentPosition] == '\\') + // currentPosition++; + // } //jump over the \\ } recordComment(isJavadoc); if (tokenizeComments) { @@ -1647,50 +1568,50 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameEOF; } -// public final void getNextUnicodeChar() -// throws IndexOutOfBoundsException, InvalidInputException { -// //VOID -// //handle the case of unicode. -// //when a unicode appears then we must use a buffer that holds char internal values -// //At the end of this method currentCharacter holds the new visited char -// //and currentPosition points right next after it -// -// //ALL getNextChar.... ARE OPTIMIZED COPIES -// -// int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// unicodeSize++; -// } -// -// if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c1 < 0 -// || (c2 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c2 < 0 -// || (c3 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c3 < 0 -// || (c4 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c4 < 0) { -// throw new InvalidInputException(INVALID_UNICODE_ESCAPE); -// } else { -// currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// //need the unicode buffer -// if (withoutUnicodePtr == 0) { -// //buffer all the entries that have been left aside.... -// withoutUnicodePtr = currentPosition - unicodeSize - startPosition; -// System.arraycopy( -// source, -// startPosition, -// withoutUnicodeBuffer, -// 1, -// withoutUnicodePtr); -// } -// //fill the buffer with the char -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// } -// unicodeAsBackSlash = currentCharacter == '\\'; -// } + // public final void getNextUnicodeChar() + // throws IndexOutOfBoundsException, InvalidInputException { + // //VOID + // //handle the case of unicode. + // //when a unicode appears then we must use a buffer that holds char internal values + // //At the end of this method currentCharacter holds the new visited char + // //and currentPosition points right next after it + // + // //ALL getNextChar.... ARE OPTIMIZED COPIES + // + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0, unicodeSize = 6; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // unicodeSize++; + // } + // + // if ((c1 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c1 < 0 + // || (c2 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c2 < 0 + // || (c3 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c3 < 0 + // || (c4 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c4 < 0) { + // throw new InvalidInputException(INVALID_UNICODE_ESCAPE); + // } else { + // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // //need the unicode buffer + // if (withoutUnicodePtr == 0) { + // //buffer all the entries that have been left aside.... + // withoutUnicodePtr = currentPosition - unicodeSize - startPosition; + // System.arraycopy( + // source, + // startPosition, + // withoutUnicodeBuffer, + // 1, + // withoutUnicodePtr); + // } + // //fill the buffer with the char + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // } + // unicodeAsBackSlash = currentCharacter == '\\'; + // } /* Tokenize a method body, assuming that curly brackets are properly balanced. */ public final void jumpOverMethodBody() { @@ -1704,15 +1625,14 @@ public class Scanner implements IScanner, ITerminalSymbols { do { startPosition = currentPosition; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// isWhiteSpace = jumpOverUnicodeWhiteSpace(); -// } else { - if (recordLineSeparator - && ((currentCharacter == '\r') || (currentCharacter == '\n'))) - pushLineSeparator(); - isWhiteSpace = Character.isWhitespace(currentCharacter); -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // isWhiteSpace = jumpOverUnicodeWhiteSpace(); + // } else { + if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + pushLineSeparator(); + isWhiteSpace = Character.isWhitespace(currentCharacter); + // } } while (isWhiteSpace); // -------consume token until } is found--------- @@ -1735,40 +1655,38 @@ public class Scanner implements IScanner, ITerminalSymbols { } catch (InvalidInputException ex) { }; } else { -// try { // consume next character - unicodeAsBackSlash = false; - currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = - currentCharacter; - } -// } -// } catch (InvalidInputException ex) { -// }; + // try { // consume next character + unicodeAsBackSlash = false; + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } + // } + // } catch (InvalidInputException ex) { + // }; } getNextChar('\''); break; } case '"' : try { -// try { // consume next character - unicodeAsBackSlash = false; - currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = - currentCharacter; - } -// } -// } catch (InvalidInputException ex) { -// }; + // try { // consume next character + unicodeAsBackSlash = false; + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } + // } + // } catch (InvalidInputException ex) { + // }; while (currentCharacter != '"') { if (currentCharacter == '\r') { if (source[currentPosition] == '\n') @@ -1786,20 +1704,19 @@ public class Scanner implements IScanner, ITerminalSymbols { } catch (InvalidInputException ex) { }; } -// try { // consume next character - unicodeAsBackSlash = false; - currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = - currentCharacter; - } -// } -// } catch (InvalidInputException ex) { -// }; + // try { // consume next character + unicodeAsBackSlash = false; + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } + // } + // } catch (InvalidInputException ex) { + // }; } } catch (IndexOutOfBoundsException e) { return; @@ -1813,79 +1730,77 @@ public class Scanner implements IScanner, ITerminalSymbols { try { //get the next char currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// int c1 = 0, c2 = 0, c3 = 0, c4 = 0; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// } -// if ((c1 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c1 < 0 -// || (c2 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c2 < 0 -// || (c3 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c3 < 0 -// || (c4 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c4 < 0) { -// //error don't care of the value -// currentCharacter = 'A'; -// } //something different from \n and \r -// else { -// currentCharacter = -// (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// } -// } - - while (currentCharacter != '\r' - && currentCharacter != '\n') { + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c4 < 0) { + // //error don't care of the value + // currentCharacter = 'A'; + // } //something different from \n and \r + // else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } + + while (currentCharacter != '\r' && currentCharacter != '\n') { //get the next char currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) -// == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// int c1 = 0, c2 = 0, c3 = 0, c4 = 0; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// } -// if ((c1 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c1 < 0 -// || (c2 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c2 < 0 -// || (c3 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c3 < 0 -// || (c4 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c4 < 0) { -// //error don't care of the value -// currentCharacter = 'A'; -// } //something different from \n and \r -// else { -// currentCharacter = -// (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// } -// } + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c4 < 0) { + // //error don't care of the value + // currentCharacter = 'A'; + // } //something different from \n and \r + // else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } } - if (recordLineSeparator - && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) pushLineSeparator(); } catch (IndexOutOfBoundsException e) { } //an eof will them be generated @@ -1894,102 +1809,98 @@ public class Scanner implements IScanner, ITerminalSymbols { if (test > 0) { //traditional and annotation comment boolean star = false; -// try { // consume next character - unicodeAsBackSlash = false; - currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = - currentCharacter; - } -// }; -// } catch (InvalidInputException ex) { -// }; + // try { // consume next character + unicodeAsBackSlash = false; + currentCharacter = source[currentPosition++]; + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + } + // }; + // } catch (InvalidInputException ex) { + // }; if (currentCharacter == '*') { star = true; } - if (recordLineSeparator - && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) pushLineSeparator(); try { //get the next char currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// int c1 = 0, c2 = 0, c3 = 0, c4 = 0; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// } -// if ((c1 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c1 < 0 -// || (c2 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c2 < 0 -// || (c3 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c3 < 0 -// || (c4 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c4 < 0) { -// //error don't care of the value -// currentCharacter = 'A'; -// } //something different from * and / -// else { -// currentCharacter = -// (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c4 < 0) { + // //error don't care of the value + // currentCharacter = 'A'; + // } //something different from * and / + // else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } //loop until end of comment */ while ((currentCharacter != '/') || (!star)) { - if (recordLineSeparator - && ((currentCharacter == '\r') - || (currentCharacter == '\n'))) + if (recordLineSeparator && ((currentCharacter == '\r') || (currentCharacter == '\n'))) pushLineSeparator(); star = currentCharacter == '*'; //get next char currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) -// == '\\') -// && (source[currentPosition] == 'u')) { -// //-------------unicode traitement ------------ -// int c1 = 0, c2 = 0, c3 = 0, c4 = 0; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// } -// if ((c1 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c1 < 0 -// || (c2 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c2 < 0 -// || (c3 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c3 < 0 -// || (c4 = -// Character.getNumericValue(source[currentPosition++])) -// > 15 -// || c4 < 0) { -// //error don't care of the value -// currentCharacter = 'A'; -// } //something different from * and / -// else { -// currentCharacter = -// (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// } -// } + // if (((currentCharacter = source[currentPosition++]) + // == '\\') + // && (source[currentPosition] == 'u')) { + // //-------------unicode traitement ------------ + // int c1 = 0, c2 = 0, c3 = 0, c4 = 0; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // } + // if ((c1 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c1 < 0 + // || (c2 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c2 < 0 + // || (c3 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c3 < 0 + // || (c4 = + // Character.getNumericValue(source[currentPosition++])) + // > 15 + // || c4 < 0) { + // //error don't care of the value + // currentCharacter = 'A'; + // } //something different from * and / + // else { + // currentCharacter = + // (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // } + // } } } catch (IndexOutOfBoundsException e) { return; @@ -2000,8 +1911,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } default : - if (isPHPIdentifierStart(currentCharacter) - || currentCharacter == '$') { + if (isPHPIdentifierStart(currentCharacter) || currentCharacter == '$') { try { scanIdentifierOrKeyword((currentCharacter == '$')); } catch (InvalidInputException ex) { @@ -2023,50 +1933,50 @@ public class Scanner implements IScanner, ITerminalSymbols { } return; } -// public final boolean jumpOverUnicodeWhiteSpace() -// throws InvalidInputException { -// //BOOLEAN -// //handle the case of unicode. Jump over the next whiteSpace -// //making startPosition pointing on the next available char -// //On false, the currentCharacter is filled up with a potential -// //correct char -// -// try { -// this.wasAcr = false; -// int c1, c2, c3, c4; -// int unicodeSize = 6; -// currentPosition++; -// while (source[currentPosition] == 'u') { -// currentPosition++; -// unicodeSize++; -// } -// -// if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c1 < 0) -// || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c2 < 0) -// || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c3 < 0) -// || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 -// || c4 < 0)) { -// throw new InvalidInputException(INVALID_UNICODE_ESCAPE); -// } -// -// currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); -// if (recordLineSeparator -// && ((currentCharacter == '\r') || (currentCharacter == '\n'))) -// pushLineSeparator(); -// if (Character.isWhitespace(currentCharacter)) -// return true; -// -// //buffer the new char which is not a white space -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// //withoutUnicodePtr == 1 is true here -// return false; -// } catch (IndexOutOfBoundsException e) { -// throw new InvalidInputException(INVALID_UNICODE_ESCAPE); -// } -// } + // public final boolean jumpOverUnicodeWhiteSpace() + // throws InvalidInputException { + // //BOOLEAN + // //handle the case of unicode. Jump over the next whiteSpace + // //making startPosition pointing on the next available char + // //On false, the currentCharacter is filled up with a potential + // //correct char + // + // try { + // this.wasAcr = false; + // int c1, c2, c3, c4; + // int unicodeSize = 6; + // currentPosition++; + // while (source[currentPosition] == 'u') { + // currentPosition++; + // unicodeSize++; + // } + // + // if (((c1 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c1 < 0) + // || ((c2 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c2 < 0) + // || ((c3 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c3 < 0) + // || ((c4 = Character.getNumericValue(source[currentPosition++])) > 15 + // || c4 < 0)) { + // throw new InvalidInputException(INVALID_UNICODE_ESCAPE); + // } + // + // currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); + // if (recordLineSeparator + // && ((currentCharacter == '\r') || (currentCharacter == '\n'))) + // pushLineSeparator(); + // if (Character.isWhitespace(currentCharacter)) + // return true; + // + // //buffer the new char which is not a white space + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // //withoutUnicodePtr == 1 is true here + // return false; + // } catch (IndexOutOfBoundsException e) { + // throw new InvalidInputException(INVALID_UNICODE_ESCAPE); + // } + // } public final int[] getLineEnds() { //return a bounded copy of this.lineEnds @@ -2145,9 +2055,7 @@ public class Scanner implements IScanner, ITerminalSymbols { //try to return the same char[] build only once char c0, c1; - int hash = - (((c0 = source[startPosition]) << 6) + (c1 = source[startPosition + 1])) - % TableSize; + int hash = (((c0 = source[startPosition]) << 6) + (c1 = source[startPosition + 1])) % TableSize; char[][] table = charArray_length[0][hash]; int i = newEntry2; while (++i < InternalTableSize) { @@ -2177,9 +2085,7 @@ public class Scanner implements IScanner, ITerminalSymbols { char c0, c1, c2; int hash = - (((c0 = source[startPosition]) << 12) - + ((c1 = source[startPosition + 1]) << 6) - + (c2 = source[startPosition + 2])) + (((c0 = source[startPosition]) << 12) + ((c1 = source[startPosition + 1]) << 6) + (c2 = source[startPosition + 2])) % TableSize; char[][] table = charArray_length[1][hash]; int i = newEntry3; @@ -2219,10 +2125,7 @@ public class Scanner implements IScanner, ITerminalSymbols { int i = newEntry4; while (++i < InternalTableSize) { char[] charArray = table[i]; - if ((c0 == charArray[0]) - && (c1 == charArray[1]) - && (c2 == charArray[2]) - && (c3 == charArray[3])) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3])) return charArray; } //---------other side--------- @@ -2230,10 +2133,7 @@ public class Scanner implements IScanner, ITerminalSymbols { int max = newEntry4; while (++i <= max) { char[] charArray = table[i]; - if ((c0 == charArray[0]) - && (c1 == charArray[1]) - && (c2 == charArray[2]) - && (c3 == charArray[3])) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3])) return charArray; } //--------add the entry------- @@ -2261,11 +2161,7 @@ public class Scanner implements IScanner, ITerminalSymbols { int i = newEntry5; while (++i < InternalTableSize) { char[] charArray = table[i]; - if ((c0 == charArray[0]) - && (c1 == charArray[1]) - && (c2 == charArray[2]) - && (c3 == charArray[3]) - && (c4 == charArray[4])) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])) return charArray; } //---------other side--------- @@ -2273,11 +2169,7 @@ public class Scanner implements IScanner, ITerminalSymbols { int max = newEntry5; while (++i <= max) { char[] charArray = table[i]; - if ((c0 == charArray[0]) - && (c1 == charArray[1]) - && (c2 == charArray[2]) - && (c3 == charArray[3]) - && (c4 == charArray[4])) + if ((c0 == charArray[0]) && (c1 == charArray[1]) && (c2 == charArray[2]) && (c3 == charArray[3]) && (c4 == charArray[4])) return charArray; } //--------add the entry------- @@ -2471,8 +2363,7 @@ public class Scanner implements IScanner, ITerminalSymbols { // a new annotation comment is recorded try { - commentStops[++commentPtr] = - isJavadoc ? currentPosition : -currentPosition; + commentStops[++commentPtr] = isJavadoc ? currentPosition : -currentPosition; } catch (IndexOutOfBoundsException e) { int oldStackLength = commentStops.length; int[] oldStack = commentStops; @@ -2497,24 +2388,23 @@ public class Scanner implements IScanner, ITerminalSymbols { commentPtr = -1; // reset comment stack } - public final void scanSingleQuotedEscapeCharacter() - throws InvalidInputException { + public final void scanSingleQuotedEscapeCharacter() throws InvalidInputException { // the string with "\\u" is a legal string of two chars \ and u //thus we use a direct access to the source (for regular cases). -// if (unicodeAsBackSlash) { -// // consume next character -// unicodeAsBackSlash = false; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// } -// } -// } else - currentCharacter = source[currentPosition++]; + // if (unicodeAsBackSlash) { + // // consume next character + // unicodeAsBackSlash = false; + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // } + // } + // } else + currentCharacter = source[currentPosition++]; switch (currentCharacter) { case '\'' : currentCharacter = '\''; @@ -2528,24 +2418,23 @@ public class Scanner implements IScanner, ITerminalSymbols { } } - public final void scanDoubleQuotedEscapeCharacter() - throws InvalidInputException { + public final void scanDoubleQuotedEscapeCharacter() throws InvalidInputException { // the string with "\\u" is a legal string of two chars \ and u //thus we use a direct access to the source (for regular cases). -// if (unicodeAsBackSlash) { -// // consume next character -// unicodeAsBackSlash = false; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// } -// } -// } else - currentCharacter = source[currentPosition++]; + // if (unicodeAsBackSlash) { + // // consume next character + // unicodeAsBackSlash = false; + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // } + // } + // } else + currentCharacter = source[currentPosition++]; switch (currentCharacter) { // case 'b' : // currentCharacter = '\b'; @@ -2583,13 +2472,11 @@ public class Scanner implements IScanner, ITerminalSymbols { int number = Character.getNumericValue(currentCharacter); if (number >= 0 && number <= 7) { boolean zeroToThreeNot = number > 3; - if (Character - .isDigit(currentCharacter = source[currentPosition++])) { + if (Character.isDigit(currentCharacter = source[currentPosition++])) { int digit = Character.getNumericValue(currentCharacter); if (digit >= 0 && digit <= 7) { number = (number * 8) + digit; - if (Character - .isDigit(currentCharacter = source[currentPosition++])) { + if (Character.isDigit(currentCharacter = source[currentPosition++])) { if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit Digit --> ignore last character currentPosition--; } else { @@ -2623,8 +2510,7 @@ public class Scanner implements IScanner, ITerminalSymbols { // return scanIdentifierOrKeyword( false ); // } - public int scanIdentifierOrKeyword(boolean isVariable) - throws InvalidInputException { + public int scanIdentifierOrKeyword(boolean isVariable) throws InvalidInputException { //test keywords //first dispatch on the first char. @@ -2643,32 +2529,32 @@ public class Scanner implements IScanner, ITerminalSymbols { int index, length; char[] data; char firstLetter; -// if (withoutUnicodePtr == 0) - - //quick test on length == 1 but not on length > 12 while most identifier - //have a length which is <= 12...but there are lots of identifier with - //only one char.... - -// { - if ((length = currentPosition - startPosition) == 1) - return TokenNameIdentifier; - // data = source; - data = new char[length]; - index = startPosition; - for (int i = 0; i < length; i++) { - data[i] = Character.toLowerCase(source[index + i]); - } - index = 0; -// } else { -// if ((length = withoutUnicodePtr) == 1) -// return TokenNameIdentifier; -// // data = withoutUnicodeBuffer; -// data = new char[withoutUnicodeBuffer.length]; -// for (int i = 0; i < withoutUnicodeBuffer.length; i++) { -// data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]); -// } -// index = 1; -// } + // if (withoutUnicodePtr == 0) + + //quick test on length == 1 but not on length > 12 while most identifier + //have a length which is <= 12...but there are lots of identifier with + //only one char.... + + // { + if ((length = currentPosition - startPosition) == 1) + return TokenNameIdentifier; + // data = source; + data = new char[length]; + index = startPosition; + for (int i = 0; i < length; i++) { + data[i] = Character.toLowerCase(source[index + i]); + } + index = 0; + // } else { + // if ((length = withoutUnicodePtr) == 1) + // return TokenNameIdentifier; + // // data = withoutUnicodeBuffer; + // data = new char[withoutUnicodeBuffer.length]; + // for (int i = 0; i < withoutUnicodeBuffer.length; i++) { + // data[i] = Character.toLowerCase(withoutUnicodeBuffer[i]); + // } + // index = 1; + // } firstLetter = data[index]; switch (firstLetter) { @@ -2698,10 +2584,7 @@ public class Scanner implements IScanner, ITerminalSymbols { case 'b' : //break switch (length) { case 5 : - if ((data[++index] == 'r') - && (data[++index] == 'e') - && (data[++index] == 'a') - && (data[++index] == 'k')) + if ((data[++index] == 'r') && (data[++index] == 'e') && (data[++index] == 'a') && (data[++index] == 'k')) return TokenNamebreak; else return TokenNameIdentifier; @@ -2712,17 +2595,12 @@ public class Scanner implements IScanner, ITerminalSymbols { case 'c' : //case class continue switch (length) { case 4 : - if ((data[++index] == 'a') - && (data[++index] == 's') - && (data[++index] == 'e')) + if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e')) return TokenNamecase; else return TokenNameIdentifier; case 5 : - if ((data[++index] == 'l') - && (data[++index] == 'a') - && (data[++index] == 's') - && (data[++index] == 's')) + if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's')) return TokenNameclass; else return TokenNameIdentifier; @@ -2773,22 +2651,14 @@ public class Scanner implements IScanner, ITerminalSymbols { case 'e' : //echo else elseif extends switch (length) { case 4 : - if ((data[++index] == 'c') - && (data[++index] == 'h') - && (data[++index] == 'o')) + if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o')) return TokenNameecho; - else if ( - (data[index] == 'l') - && (data[++index] == 's') - && (data[++index] == 'e')) + else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e')) return TokenNameelse; else return TokenNameIdentifier; case 5 : // endif - if ((data[++index] == 'n') - && (data[++index] == 'd') - && (data[++index] == 'i') - && (data[++index] == 'f')) + if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f')) return TokenNameendif; else return TokenNameIdentifier; @@ -2867,10 +2737,7 @@ public class Scanner implements IScanner, ITerminalSymbols { else return TokenNameIdentifier; case 5 : - if ((data[++index] == 'a') - && (data[++index] == 'l') - && (data[++index] == 's') - && (data[++index] == 'e')) + if ((data[++index] == 'a') && (data[++index] == 'l') && (data[++index] == 's') && (data[++index] == 'e')) return TokenNamefalse; else return TokenNameIdentifier; @@ -2953,9 +2820,7 @@ public class Scanner implements IScanner, ITerminalSymbols { case 'l' : //list if (length == 4) { - if ((data[++index] == 'i') - && (data[++index] == 's') - && (data[++index] == 't')) { + if ((data[++index] == 'i') && (data[++index] == 's') && (data[++index] == 't')) { return TokenNamelist; } } @@ -2969,9 +2834,7 @@ public class Scanner implements IScanner, ITerminalSymbols { else return TokenNameIdentifier; case 4 : - if ((data[++index] == 'u') - && (data[++index] == 'l') - && (data[++index] == 'l')) + if ((data[++index] == 'u') && (data[++index] == 'l') && (data[++index] == 'l')) return TokenNamenull; else return TokenNameIdentifier; @@ -3004,10 +2867,7 @@ public class Scanner implements IScanner, ITerminalSymbols { case 'p' : // print if (length == 5) { - if ((data[++index] == 'r') - && (data[++index] == 'i') - && (data[++index] == 'n') - && (data[++index] == 't')) { + if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) { return TokenNameprint; } } @@ -3051,10 +2911,7 @@ public class Scanner implements IScanner, ITerminalSymbols { switch (length) { case 6 : if (data[++index] == 't') - if ((data[++index] == 'a') - && (data[++index] == 't') - && (data[++index] == 'i') - && (data[++index] == 'c')) { + if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'i') && (data[++index] == 'c')) { return TokenNamestatic; } else return TokenNameIdentifier; @@ -3075,9 +2932,7 @@ public class Scanner implements IScanner, ITerminalSymbols { switch (length) { case 4 : - if ((data[++index] == 'r') - && (data[++index] == 'u') - && (data[++index] == 'e')) + if ((data[++index] == 'r') && (data[++index] == 'u') && (data[++index] == 'e')) return TokenNametrue; else return TokenNameIdentifier; @@ -3103,10 +2958,7 @@ public class Scanner implements IScanner, ITerminalSymbols { case 'w' : //while switch (length) { case 5 : - if ((data[++index] == 'h') - && (data[++index] == 'i') - && (data[++index] == 'l') - && (data[++index] == 'e')) + if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e')) return TokenNamewhile; else return TokenNameIdentifier; @@ -3146,14 +2998,14 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // } + // } if (Character.digit(currentCharacter, 16) == -1) throw new InvalidInputException(INVALID_HEXA); //---end forcing-- @@ -3190,28 +3042,28 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // } + // } if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = -// currentCharacter; -// } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = + // currentCharacter; + // } + // } } if (!Character.isDigit(currentCharacter)) throw new InvalidInputException(INVALID_FLOAT); @@ -3250,27 +3102,26 @@ public class Scanner implements IScanner, ITerminalSymbols { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// } -// } - - if ((currentCharacter == '-') - || (currentCharacter == '+')) { // consume next character + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // } + // } + + if ((currentCharacter == '-') || (currentCharacter == '+')) { // consume next character unicodeAsBackSlash = false; currentCharacter = source[currentPosition++]; -// if (((currentCharacter = source[currentPosition++]) == '\\') -// && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { -// if (withoutUnicodePtr != 0) { -// withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// } -// } + // if (((currentCharacter = source[currentPosition++]) == '\\') + // && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + // if (withoutUnicodePtr != 0) { + // withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // } + // } } if (!Character.isDigit(currentCharacter)) throw new InvalidInputException(INVALID_FLOAT); @@ -3354,18 +3205,14 @@ public class Scanner implements IScanner, ITerminalSymbols { } char end[] = new char[source.length - (currentPosition - 1)]; - System.arraycopy( - source, - (currentPosition - 1) + 1, - end, - 0, - source.length - (currentPosition - 1) - 1); + System.arraycopy(source, (currentPosition - 1) + 1, end, 0, source.length - (currentPosition - 1) - 1); return new String(front) + "\n===============================\nStarts here -->" //$NON-NLS-1$ + new String(middle) + "<-- Ends here\n===============================\n" //$NON-NLS-1$ + new String(end); } public final String toStringAction(int act) { + switch (act) { case TokenNameERROR : return "ScannerError(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ @@ -3562,20 +3409,23 @@ public class Scanner implements IScanner, ITerminalSymbols { return "${"; case TokenNameEOF : return "EOF"; //$NON-NLS-1$ + case TokenNameWHITESPACE : + return "WHITESPACE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ + case TokenNameCOMMENT_LINE : + return "COMMENT_LINE(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ + case TokenNameCOMMENT_BLOCK : + return "COMMENT_BLOCK(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ + case TokenNameCOMMENT_PHPDOC : + return "COMMENT_PHPDOC(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ + case TokenNameHTML : + return "HTML(" + new String(getCurrentTokenSource()) + ")"; //$NON-NLS-1$ default : return "not-a-token(" + (new Integer(act)) + ") " + new String(getCurrentTokenSource()); //$NON-NLS-1$ } } - public Scanner( - boolean tokenizeComments, - boolean tokenizeWhiteSpace, - boolean checkNonExternalizedStringLiterals) { - this( - tokenizeComments, - tokenizeWhiteSpace, - checkNonExternalizedStringLiterals, - false); + public Scanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean checkNonExternalizedStringLiterals) { + this(tokenizeComments, tokenizeWhiteSpace, checkNonExternalizedStringLiterals, false); } public Scanner( @@ -3586,8 +3436,7 @@ public class Scanner implements IScanner, ITerminalSymbols { this.eofPosition = Integer.MAX_VALUE; this.tokenizeComments = tokenizeComments; this.tokenizeWhiteSpace = tokenizeWhiteSpace; - this.checkNonExternalizedStringLiterals = - checkNonExternalizedStringLiterals; + this.checkNonExternalizedStringLiterals = checkNonExternalizedStringLiterals; this.assertMode = assertMode; } @@ -3633,12 +3482,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } this.wasNonExternalizedStringLiteral = true; if (nonNLSCounter != lineLength) { - System.arraycopy( - this.nonNLSStrings, - 0, - (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), - 0, - nonNLSCounter); + System.arraycopy(this.nonNLSStrings, 0, (this.nonNLSStrings = new StringLiteral[nonNLSCounter]), 0, nonNLSCounter); } currentLine = null; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java index 516c7de..51bda8a 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/formatter/CodeFormatter.java @@ -315,6 +315,7 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { boolean inArrayAssignment = false; boolean inThrowsClause = false; boolean inClassOrInterfaceHeader = false; + int dollarBraceCount = 0; // openBracketCount is used to count the number of open brackets not closed yet. int openBracketCount = 0; @@ -349,6 +350,13 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { // exit the loop. try { token = scanner.getNextToken(); + if (Scanner.DEBUG) { + int currentEndPosition = scanner.getCurrentTokenEndPosition(); + int currentStartPosition = scanner.getCurrentTokenStartPosition(); + + System.out.print(currentStartPosition + "," + currentEndPosition + ": "); + System.out.println(scanner.toStringAction(token)); + } // Patch for line comment // See PR http://dev.eclipse.org/bugs/show_bug.cgi?id=23096 @@ -600,6 +608,9 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { } } switch (token) { + case TokenNameDOLLAR_LBRACE : + dollarBraceCount++; + break; case TokenNameelse : // case TokenNamefinally : expectingOpenBrace = true; @@ -723,6 +734,10 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { } break; case TokenNameRBRACE : + if (dollarBraceCount > 0) { + dollarBraceCount--; + break; + } if (previousCompilableToken == TokenNameRPAREN) { pendingSpace = false; } @@ -856,17 +871,17 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { } increaseLineDelta(scanner.startPosition - scanner.currentPosition); break; -// case TokenNameHTML : -// // Add the next token to the formatted source string. -// // outputCurrentToken(token); -// int startPosition = scanner.startPosition; -// flushBuffer(); -// for (int i = startPosition, max = scanner.currentPosition; i < max; i++) { -// char currentCharacter = scanner.source[i]; -// updateMappedPositions(i); -// currentLineBuffer.append(currentCharacter); -// } -// break; + // case TokenNameHTML : + // // Add the next token to the formatted source string. + // // outputCurrentToken(token); + // int startPosition = scanner.startPosition; + // flushBuffer(); + // for (int i = startPosition, max = scanner.currentPosition; i < max; i++) { + // char currentCharacter = scanner.source[i]; + // updateMappedPositions(i); + // currentLineBuffer.append(currentCharacter); + // } + // break; default : if ((token == TokenNameIdentifier) || isLiteralToken(token)) { // || token == TokenNamesuper @@ -1973,6 +1988,13 @@ public class CodeFormatter implements ITerminalSymbols, ICodeFormatter { if (currentToken != Scanner.TokenNameWHITESPACE) previousToken = currentToken; currentToken = splitScanner.getNextToken(); + if (Scanner.DEBUG) { + int currentEndPosition = splitScanner.getCurrentTokenEndPosition(); + int currentStartPosition = splitScanner.getCurrentTokenStartPosition(); + + System.out.print(currentStartPosition + "," + currentEndPosition + ": "); + System.out.println(scanner.toStringAction(currentToken)); + } } catch (InvalidInputException e) { if (!handleInvalidToken(e)) throw e;