1) Fixed issue #776.
authorrobekras <robert.kraske@weihenstephan.org>
Sun, 2 Dec 2012 14:36:49 +0000 (15:36 +0100)
committerrobekras <robert.kraske@weihenstephan.org>
Sun, 2 Dec 2012 14:39:14 +0000 (15:39 +0100)
Signed-off-by: robekras <robert.kraske@weihenstephan.org>

net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java

index ae73d5f..c390b61 100644 (file)
@@ -1107,6 +1107,10 @@ public class Scanner implements IScanner, ITerminalSymbols {
                return TokenName.LPAREN;
        }
 
+       /**
+        *
+        *
+        */
        public void consumeStringInterpolated() throws InvalidInputException {
                try {
                        // consume next character
@@ -1323,54 +1327,60 @@ public class Scanner implements IScanner, ITerminalSymbols {
                }
        }
 
+       /**
+        *
+        *
+        */
        public void consumeStringLiteral() throws InvalidInputException {
                try {
                        int openDollarBrace = 0;
-                       // consume next character
-                       unicodeAsBackSlash = false;
-                       currentCharacter = source[currentPosition++];
-                       while (currentCharacter != '"' || openDollarBrace > 0) {
-                               /** ** in PHP \r and \n are valid in string literals *** */
+
+                       unicodeAsBackSlash  = false;
+                       currentCharacter    = source[currentPosition++];                                   // consume next character
+
+                       while (currentCharacter != '"' ||                                          // As long as the ending '"' isn't found, or
+                              openDollarBrace > 0) {                                              // the last '}' isn't found
                                if (currentCharacter == '\\') {
-                                       int escapeSize = currentPosition;
+                                       int     escapeSize                 = currentPosition;
                                        boolean backSlashAsUnicodeInString = unicodeAsBackSlash;
-                                       // scanEscapeCharacter make a side effect on this value and
-                                       // we need
+
+                                       // scanEscapeCharacter make a side effect on this value and we need
                                        // the previous value few lines down this one
-                                       scanDoubleQuotedEscapeCharacter();
+                                       scanDoubleQuotedEscapeCharacter ();
                                        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);
+
+                                       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;
-                                       } else { // overwrite the / in the buffer
+                                       }
+                                       else {                                                             // overwrite the / in the buffer
                                                withoutUnicodeBuffer[withoutUnicodePtr] = currentCharacter;
-                                               if (backSlashAsUnicodeInString) { // there are TWO \
-                                                                                                                       // in the stream
-                                                       // where only one is correct
+
+                                               if (backSlashAsUnicodeInString) {                              // there are TWO \ in the stream where only one is correct
                                                        withoutUnicodePtr--;
                                                }
                                        }
-                               } else if (currentCharacter == '$'
-                                               && source[currentPosition] == '{') {
+                               }
+                               else if (currentCharacter == '$' && source[currentPosition] == '{') {  // If found '${'
                                        openDollarBrace++;
-                               } else if (currentCharacter == '{'
-                                               && source[currentPosition] == '$') {
+                                       currentCharacter = source[currentPosition++];                      // consume next character, or we count one open brace to much!
+                               }
+                               else if (currentCharacter == '{' && source[currentPosition] == '$') {  // If found '{$'
                                        openDollarBrace++;
-                               } else if (currentCharacter == '}') {
+                               }
+                               else if (currentCharacter == '}') {                                    // If found '}'
                                        openDollarBrace--;
-                               } else if ((currentCharacter == '\r')
-                                               || (currentCharacter == '\n')) {
+                               }
+                               else if ((currentCharacter == '\r') || (currentCharacter == '\n')) {   // In PHP \r and \n are valid in string literals
                                        if (recordLineSeparator) {
-                                               pushLineSeparator();
+                                               pushLineSeparator ();
                                        }
                                }
-                               // consume next character
+
                                unicodeAsBackSlash = false;
-                               currentCharacter = source[currentPosition++];
+                               currentCharacter = source[currentPosition++];                          // consume next character
+
                                if (withoutUnicodePtr != 0) {
                                        withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter;
                                }
@@ -1396,19 +1406,20 @@ public class Scanner implements IScanner, ITerminalSymbols {
                        }
                        throw e; // rethrow
                }
-               if (checkNonExternalizedStringLiterals) { // check for presence of NLS
-                                                                                                       // tags
-                       // //$NON-NLS-?$ where ? is an
-                       // int.
+
+               if (checkNonExternalizedStringLiterals) { // check for presence of NLS tags
+                       // $NON-NLS-?$ where ? is an int.
                        if (currentLine == null) {
-                               currentLine = new NLSLine();
-                               lines.add(currentLine);
+                               currentLine = new NLSLine ();
+                               lines.add (currentLine);
                        }
-                       currentLine.add(new StringLiteral(getCurrentTokenSourceString(),
-                                       startPosition, currentPosition - 1));
+                       currentLine.add (new StringLiteral (getCurrentTokenSourceString (), startPosition, currentPosition - 1));
                }
        }
 
+       /**
+        *
+        */
        public TokenName getNextToken() throws InvalidInputException {
                if (!phpMode) {
                        return getInlinedHTMLToken(currentPosition);
@@ -1439,7 +1450,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
                                        while ((currentCharacter == ' ') || Character.isWhitespace(currentCharacter)) {
                                                if ((currentCharacter == '\r') || (currentCharacter == '\n')) {
                                                        checkNonExternalizeString();
-                                                       
+
                                                        if (recordLineSeparator) {
                                                                pushLineSeparator();
                                                        } else {
@@ -1449,7 +1460,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
                                                startPosition = currentPosition;
                                                currentCharacter = source[currentPosition++];
                                        }
-                                       
+
                                        if (tokenizeWhiteSpace && (whiteStart != currentPosition - 1)) {
                                                // reposition scanner in case we are interested by
                                                // spaces as tokens
@@ -2788,6 +2799,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
                }
                // ---------other side---------
                i = -1;
+
                int max = newEntry4;
                while (++i <= max) {
                        char[] charArray = table[i];
@@ -4721,3 +4733,4 @@ public class Scanner implements IScanner, ITerminalSymbols {
        // }
        // }
 }
+