1) Fixed issue #347: Syntax highlight doesn't like apostrophe in heredoc.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Scanner.java
index ae73d5f..56a9b14 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
@@ -1525,73 +1536,92 @@ public class Scanner implements IScanner, ITerminalSymbols {
                                                if (getNextChar('='))
                                                        return TokenName.REMAINDER_EQUAL;
                                                return TokenName.REMAINDER;
+                                               
                                        case '<': {
                                                int oldPosition = currentPosition;
+                                               
                                                try {
                                                        currentCharacter = source[currentPosition++];
                                                } catch (IndexOutOfBoundsException e) {
                                                        currentPosition = oldPosition;
                                                        return TokenName.LESS;
                                                }
+                                               
                                                switch (currentCharacter) {
-                                               case '=':
-                                                       return TokenName.LESS_EQUAL;
-                                               case '>':
-                                                       return TokenName.NOT_EQUAL;
-                                               case '<':
-                                                       if (getNextChar('='))
-                                                               return TokenName.LEFT_SHIFT_EQUAL;
-                                                       if (getNextChar('<')) {
-                                                               currentCharacter = source[currentPosition++];
-                                                               while (Character.isWhitespace(currentCharacter)) {
-                                                                       currentCharacter = source[currentPosition++];
+                                                       case '=':
+                                                               return TokenName.LESS_EQUAL;
+                                                               
+                                                       case '>':
+                                                               return TokenName.NOT_EQUAL;
+                                                               
+                                                       case '<':
+                                                               if (getNextChar ('=')) {
+                                                                       return TokenName.LEFT_SHIFT_EQUAL;
                                                                }
-                                                               int heredocStart = currentPosition - 1;
-                                                               int heredocLength = 0;
-                                                               if (isPHPIdentifierStart(currentCharacter)) {
+                                                               
+                                                               if (getNextChar('<')) {
                                                                        currentCharacter = source[currentPosition++];
-                                                               } else {
-                                                                       return TokenName.ERROR;
-                                                               }
-                                                               while (isPHPIdentifierPart(currentCharacter)) {
-                                                                       currentCharacter = source[currentPosition++];
-                                                               }
-                                                               heredocLength = currentPosition - heredocStart
-                                                                               - 1;
-                                                               // heredoc end-tag determination
-                                                               boolean endTag = true;
-                                                               char ch;
-                                                               do {
-                                                                       ch = source[currentPosition++];
-                                                                       if (ch == '\r' || ch == '\n') {
-                                                                               if (recordLineSeparator) {
-                                                                                       pushLineSeparator();
-                                                                               } else {
-                                                                                       currentLine = null;
-                                                                               }
-                                                                               for (int i = 0; i < heredocLength; i++) {
-                                                                                       if (source[currentPosition + i] != source[heredocStart
-                                                                                                       + i]) {
-                                                                                               endTag = false;
-                                                                                               break;
+                                                                       
+                                                                       while (Character.isWhitespace(currentCharacter)) {
+                                                                               currentCharacter = source[currentPosition++];
+                                                                       }
+                                                                       
+                                                                       int heredocStart = currentPosition - 1;
+                                                                       int heredocLength = 0;
+                                                                       
+                                                                       if (isPHPIdentifierStart (currentCharacter)) {
+                                                                               currentCharacter = source[currentPosition++];
+                                                                       } 
+                                                                       else {
+                                                                               return TokenName.ERROR;
+                                                                       }
+                                                                       
+                                                                       while (isPHPIdentifierPart(currentCharacter)) {
+                                                                               currentCharacter = source[currentPosition++];
+                                                                       }
+                                                                       
+                                                                       heredocLength = currentPosition - heredocStart - 1;
+                                                                       
+                                                                       // heredoc end-tag determination
+                                                                       boolean endTag = true;
+                                                                       char ch;
+                                                                       do {
+                                                                               ch = source[currentPosition++];
+                                                                               
+                                                                               if (ch == '\r' || ch == '\n') {
+                                                                                       if (recordLineSeparator) {
+                                                                                               pushLineSeparator();
+                                                                                       } 
+                                                                                       else {
+                                                                                               currentLine = null;
+                                                                                       }
+                                                                                       
+                                                                                       for (int i = 0; i < heredocLength; i++) {
+                                                                                               if (source[currentPosition + i] != source[heredocStart + i]) {
+                                                                                                       endTag = false;
+                                                                                                       break;
+                                                                                               }
+                                                                                       }
+                                                                                       
+                                                                                       if (endTag) {
+                                                                                               currentPosition += heredocLength - 1;
+                                                                                               currentCharacter = source[currentPosition++];
+                                                                                               break; // do...while loop
+                                                                                       } 
+                                                                                       else {
+                                                                                               endTag = true;
                                                                                        }
                                                                                }
-                                                                               if (endTag) {
-                                                                                       currentPosition += heredocLength - 1;
-                                                                                       currentCharacter = source[currentPosition++];
-                                                                                       break; // do...while loop
-                                                                               } else {
-                                                                                       endTag = true;
-                                                                               }
-                                                                       }
-                                                               } while (true);
-                                                               return TokenName.HEREDOC;
+                                                                       } while (true);
+                                                                       
+                                                                       return TokenName.HEREDOC;
+                                                               }
+                                                               return TokenName.LEFT_SHIFT;
                                                        }
-                                                       return TokenName.LEFT_SHIFT;
+                                                       currentPosition = oldPosition;
+                                                       return TokenName.LESS;
                                                }
-                                               currentPosition = oldPosition;
-                                               return TokenName.LESS;
-                                       }
+                                       
                                        case '>': {
                                                int test;
                                                if ((test = getNextChar('=', '>')) == 0)
@@ -1642,7 +1672,12 @@ public class Scanner implements IScanner, ITerminalSymbols {
                                                        }
                                                        return getInlinedHTMLToken(currentPosition - 2);
                                                }
+                                               else if (getNextChar(':')) {
+                                                       return TokenName.TERNARY_SHORT;
+                                               }
+                                               
                                                return TokenName.QUESTION;
+                                               
                                        case ':':
                                                if (getNextChar(':'))
                                                        return TokenName.PAAMAYIM_NEKUDOTAYIM;
@@ -2788,6 +2823,7 @@ public class Scanner implements IScanner, ITerminalSymbols {
                }
                // ---------other side---------
                i = -1;
+
                int max = newEntry4;
                while (++i <= max) {
                        char[] charArray = table[i];
@@ -4721,3 +4757,4 @@ public class Scanner implements IScanner, ITerminalSymbols {
        // }
        // }
 }
+