Prepared better HEREDOC support; see comment for bug #1319276
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / FastJavaPartitionScanner.java
index ec8321f..08d9af2 100644 (file)
@@ -1,10 +1,10 @@
 /*******************************************************************************
  * Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials 
+ * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
  * http://www.eclipse.org/legal/cpl-v10.html
- * 
+ *
  * Contributors:
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
@@ -37,12 +37,12 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
 
   private static final int STRING_SQ = 5;
 
-  //   private static final int CHARACTER= 4;
+  private static final int STRING_HEREDOC = 6;
 
   // beginning of prefixes and postfixes
   private static final int NONE = 0;
 
-  private static final int BACKSLASH = 1; // postfix for STRING and CHARACTER
+  private static final int BACKSLASH = 1; // postfix for STRING_DQ and CHARACTER
 
   private static final int SLASH = 2; // prefix for SINGLE_LINE or MULTI_LINE or JAVADOC
 
@@ -52,7 +52,9 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
 
   private static final int STAR = 5; // postfix for MULTI_LINE_COMMENT or JAVADOC
 
-  private static final int CARRIAGE_RETURN = 6; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
+  private static final int CARRIAGE_RETURN = 6; // postfix for STRING_DQ, CHARACTER and SINGLE_LINE_COMMENT
+
+//  private static final int HEREDOC = 7;
 
   /** The scanner. */
   private final BufferedDocumentScanner fScanner = new BufferedDocumentScanner(1000); // faster implementation
@@ -79,8 +81,14 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
 
   private int fJavaLength;
 
-  private final IToken[] fTokens = new IToken[] { new Token(null), new Token(PHP_SINGLELINE_COMMENT),
-      new Token(PHP_MULTILINE_COMMENT), new Token(PHP_PHPDOC_COMMENT), new Token(PHP_STRING_DQ), new Token(PHP_STRING_SQ) };
+  private final IToken[] fTokens = new IToken[] {
+      new Token(null),
+      new Token(PHP_SINGLELINE_COMMENT),
+      new Token(PHP_MULTILINE_COMMENT),
+      new Token(PHP_PHPDOC_COMMENT),
+      new Token(PHP_STRING_DQ),
+      new Token(PHP_STRING_SQ),
+      new Token(PHP_STRING_HEREDOC)};
 
   public FastJavaPartitionScanner(boolean emulate) {
     fEmulate = emulate;
@@ -180,6 +188,19 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
           continue;
         }
 
+      case '?':
+        if (fState == SINGLE_LINE_COMMENT) {
+          int nextch = fScanner.read();
+          if (nextch == '>') {
+            // <h1>This is an <?php # echo 'simple' ?> example.</h1>
+            fTokenLength--;
+            fScanner.unread();
+            fScanner.unread();
+            return postFix(fState);
+          }
+          fScanner.unread();
+        }
+
       default:
         if (!fEmulate && fLast == CARRIAGE_RETURN) {
           switch (fState) {
@@ -415,16 +436,16 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
       //                                       fLast= (fLast == BACKSLASH) ? NONE : BACKSLASH;
       //                                       fTokenLength++;
       //                                       break;
-      //       
+      //
       //                               case '\'':
       //                                       if (fLast != BACKSLASH) {
       //                                               return postFix(CHARACTER);
-      //       
+      //
       //                                       } else {
       //                                               consume();
       //                                               break;
       //                                       }
-      //       
+      //
       //                               default:
       //                                       consume();
       //                                       break;
@@ -507,8 +528,13 @@ public class FastJavaPartitionScanner implements IPartitionTokenScanner, IPHPPar
 
     else if (contentType.equals(PHP_STRING_DQ))
       return STRING_DQ;
+
     else if (contentType.equals(PHP_STRING_SQ))
       return STRING_SQ;
+
+    else if (contentType.equals(PHP_STRING_HEREDOC))
+      return STRING_HEREDOC;
+
     //         else if (contentType.equals(JAVA_CHARACTER))
     //                 return CHARACTER;