1) Fixed issue #347: Syntax highlight doesn't like apostrophe in heredoc.
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / php / PHPPartitionScanner.java
index 514e802..a3a6e0f 100644 (file)
@@ -8,7 +8,7 @@
  Contributors:
  Igor Malinin - initial contribution
 
- $Id: PHPPartitionScanner.java,v 1.34 2006-10-21 23:18:32 pombredanne Exp $
+ $Id: PHPPartitionScanner.java,v 1.35 2007-03-17 14:07:31 axelcl Exp $
  **********************************************************************/
 package net.sourceforge.phpeclipse.phpeditor.php;
 
@@ -18,7 +18,9 @@ import java.util.Map;
 import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
 import net.sourceforge.phpeclipse.ui.text.rules.AbstractPartitioner;
 
-import org.eclipse.jface.text.Assert;
+//incastrix
+//import org.eclipse.jface.text.Assert;
+import org.eclipse.core.runtime.Assert;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.rules.ICharacterScanner;
@@ -268,7 +270,7 @@ public class PHPPartitionScanner implements IPartitionTokenScanner {
                                                return false;
                                        }
                                        ch = document.getChar(position++); // ignore escaped
-                                                                                                               // character
+                                       // character
                                } else if (ch == '"') {
                                        return true;
                                }
@@ -293,7 +295,7 @@ public class PHPPartitionScanner implements IPartitionTokenScanner {
                                                return false;
                                        }
                                        ch = document.getChar(position++); // ignore escaped
-                                                                                                               // character
+                                       // character
                                } else if (ch == '\'') {
                                        return true;
                                }
@@ -304,19 +306,35 @@ public class PHPPartitionScanner implements IPartitionTokenScanner {
                return false;
        }
 
+       /**
+        * Read until HEREDOC ends
+        * 
+        * @return
+        */
        private boolean readUntilEscapedHEREDOC() {
-               // search until heredoc ends
                try {
                        char ch;
                        StringBuffer buf = new StringBuffer();
                        char[] heredocIdent;
+                       
                        if (position >= end) {
                                return false;
                        }
+                       
                        ch = document.getChar(position++);
+                       
+                       
+                       while (ch == ' ') {
+                               if (position >= end) {
+                                       return false;
+                               }
+                               ch = document.getChar(position++);
+                       }
+                       
                        if (!Scanner.isPHPIdentifierStart(ch)) {
                                return false;
                        }
+                       
                        while (Scanner.isPHPIdentifierPart(ch)) {
                                buf.append(ch);
                                if (position >= end) {
@@ -324,27 +342,35 @@ public class PHPPartitionScanner implements IPartitionTokenScanner {
                                }
                                ch = document.getChar(position++);
                        }
+                       
                        heredocIdent = buf.toString().toCharArray();
+                       
                        while (true) {
                                if (position >= end) {
                                        return false;
                                }
-                               ch = document.getChar(position++);
-                               if (ch == '\n') { // heredoc could end after a newline
+                               
+                               ch = document.getChar (position++);                                     // Get the next character from file
+                               
+                               if (ch == '\n') {                                   // heredoc could end after a newline
                                        int pos = 0;
+                                       
                                        while (true) {
-                                               if (position >= end) {
-                                                       return false;
+                                               if (position >= end) {                                          // If we are at the end of file
+                                                       return false;                                                   // Return                                                                       
                                                }
-                                               if (pos == heredocIdent.length) {
-                                                       return true;
+                                               
+                                               if (pos == heredocIdent.length) {                       // If the found length equals the length of heredoc id
+                                                       return true;                                                    // we found the end of heredoc
                                                }
-                                               ch = document.getChar(position++); // ignore escaped
-                                                                                                                       // character
-                                               if (ch != heredocIdent[pos]) {
-                                                       break;
+                                               
+                                               ch = document.getChar (position++);                     // Ignore escaped character
+                                               
+                                               if (ch != heredocIdent[pos]) {                          // If current character doesn't match the heredoc id
+                                                       break;                                                                  // break the heredoc end search
                                                }
-                                               pos++;
+                                               
+                                               pos++;                                                                          // Character matched the heredoc id so far
                                        }
                                }
                        }