Improved xml scanner for this bug
authoraxelcl <axelcl>
Sun, 15 May 2005 23:24:48 +0000 (23:24 +0000)
committeraxelcl <axelcl>
Sun, 15 May 2005 23:24:48 +0000 (23:24 +0000)
See: http://garv.in/serendipity/archives/653-PHP-Eclipse-Bug.html

12 files changed:
net.sourceforge.phpeclipse.xml.ui/src/net/sourceforge/phpeclipse/xml/ui/internal/text/PHPXMLPartitionScanner.java [new file with mode: 0644]
net.sourceforge.phpeclipse.xml.ui/src/net/sourceforge/phpeclipse/xml/ui/internal/text/XMLPartitionScanner.java
net.sourceforge.phpeclipse.xml.ui/src/net/sourceforge/phpeclipse/xml/ui/text/XMLTextTools.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/JavaTextTools.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/PHPSourceViewerConfiguration.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/HTMLCodeScanner.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPCodeScanner.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPDocumentPartitioner.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartitionScanner.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition_delete_it.java [deleted file]
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/SmartyCodeScanner.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/util/PHPColorProvider.java

diff --git a/net.sourceforge.phpeclipse.xml.ui/src/net/sourceforge/phpeclipse/xml/ui/internal/text/PHPXMLPartitionScanner.java b/net.sourceforge.phpeclipse.xml.ui/src/net/sourceforge/phpeclipse/xml/ui/internal/text/PHPXMLPartitionScanner.java
new file mode 100644 (file)
index 0000000..37946aa
--- /dev/null
@@ -0,0 +1,557 @@
+/*
+ * Copyright (c) 2002-2004 Widespace, OU and others.
+ * 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:
+ *     Igor Malinin - initial contribution
+ *
+ * $Id: PHPXMLPartitionScanner.java,v 1.1 2005-05-15 23:23:02 axelcl Exp $
+ */
+
+package net.sourceforge.phpeclipse.xml.ui.internal.text;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.jface.text.Assert;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.rules.ICharacterScanner;
+import org.eclipse.jface.text.rules.IPartitionTokenScanner;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+
+
+/**
+ * 
+ * 
+ * @author Igor Malinin
+ */
+public class PHPXMLPartitionScanner implements IPartitionTokenScanner {
+//     public static final String XML_PI         = "__xml_processing_instruction";
+       public static final String XML_COMMENT    = "__xml_comment";
+       public static final String XML_DECL       = "__xml_declaration";
+       public static final String XML_TAG        = "__xml_tag";
+       public static final String XML_ATTRIBUTE  = "__xml_attribute";
+       public static final String XML_CDATA      = "__xml_cdata";
+
+       public static final String DTD_INTERNAL         = "__dtd_internal";
+//     public static final String DTD_INTERNAL_PI      = "__dtd_internal_pi";
+       public static final String DTD_INTERNAL_COMMENT = "__dtd_internal_comment";
+       public static final String DTD_INTERNAL_DECL    = "__dtd_internal_declaration";
+       public static final String DTD_CONDITIONAL      = "__dtd_conditional";
+
+       public static final int STATE_DEFAULT     = 0;
+       public static final int STATE_TAG         = 1;
+       public static final int STATE_DECL        = 2;
+       public static final int STATE_CDATA       = 4;
+
+       public static final int STATE_INTERNAL    = 8;
+
+       protected IDocument document;
+       protected int end;
+
+       protected int offset;
+       protected int length;
+
+       protected int position;
+       protected int state;
+
+       protected boolean parsedtd;
+
+       protected Map tokens = new HashMap();
+
+       public PHPXMLPartitionScanner(boolean parsedtd) {
+               this.parsedtd = parsedtd;
+       }
+
+       /*
+        * @see org.eclipse.jface.text.rules.ITokenScanner#nextToken()
+        */
+       public IToken nextToken() {
+               offset += length;
+
+               switch (state) {
+                       case STATE_TAG:
+                               return nextTagToken();
+
+                       case STATE_DECL:
+                               return nextDeclToken();
+
+                       case STATE_CDATA:
+                               return nextCDATAToken();
+               }
+
+               switch (read()) {
+                       case ICharacterScanner.EOF:
+                               state = STATE_DEFAULT;
+                               return getToken(null);
+
+                       case '<':
+                               switch (read()) {
+                                       case ICharacterScanner.EOF:
+                                               if (parsedtd || isInternal()) {
+                                                       break;
+                                               }
+
+                                               state = STATE_DEFAULT;
+                                               return getToken(XML_TAG);
+
+                                       case '?': // <?  <?PI 
+                                           unread();
+                                           break;
+//                                             return nextPIToken(); 
+
+                                       case '!': // <!  <!DEFINITION or <![CDATA[ or <!--COMMENT
+                                               switch (read()) {
+                                                       case ICharacterScanner.EOF:
+                                                               state = STATE_DEFAULT;
+                                                               return getToken(XML_TAG);
+
+                                                       case '-': // <!-  <!--COMMENT
+                                                               switch (read()) {
+                                                                       case ICharacterScanner.EOF:
+                                                                               return nextDeclToken();
+
+                                                                       case '-': // <!--
+                                                                               return nextCommentToken();
+                                                               }
+
+                                                       case '[': // <![  <![CDATA[ or <![%cond;[
+                                                               if (parsedtd) {
+                                                                       return nextConditionalToken();
+                                                               }
+
+                                                               if (!isInternal()) {
+                                                                       return nextCDATAToken();
+                                                               }
+                                               }
+
+                                               return nextDeclToken();
+                               }
+
+                               if (parsedtd || isInternal()) {
+                                       break;
+                               }
+
+                               unread();
+
+                               return nextTagToken();
+
+                       case ']':
+                               if (isInternal()) {
+                                       unread();
+
+                                       state = STATE_DECL;
+                                       length = 0;
+                                       return nextToken();
+                               }
+                               break;
+                   default:
+                       unread();
+               }
+
+loop:
+               while (true) {
+                       switch (read()) {
+                               case ICharacterScanner.EOF:
+                                       state = STATE_DEFAULT;
+                                       return getToken(null);
+
+                               case '<':
+                                       if (parsedtd || isInternal()) {
+                                               switch (read()) {
+                                                       case ICharacterScanner.EOF:
+                                                               state = STATE_DEFAULT;
+                                                               return getToken(null);
+
+                                                       case '!':
+                                                       case '?':
+                                                               unread();
+                                                               break;
+
+                                                       default:
+                                                               continue loop;
+                                               }
+                                       }
+
+                                       unread();
+
+                                       state &= STATE_INTERNAL;
+                                       return getToken(isInternal() ? DTD_INTERNAL : null);
+
+                               case ']':
+                                       if (isInternal()) {
+                                               unread();
+
+                                               state = STATE_DECL;
+                                               if (position == offset) {
+                                                       // nothing between
+                                                       length = 0;
+                                                       return nextToken();
+                                               }
+
+                                               return getToken(DTD_INTERNAL);
+                                       }
+                       }
+               }
+       }
+
+       private IToken nextTagToken() {
+               int quot = read();
+
+               switch (quot) {
+                       case ICharacterScanner.EOF:
+                       case '>':
+                               state = STATE_DEFAULT;
+                               return getToken(XML_TAG);
+
+                       case '"': case '\'':
+                               while (true) {
+                                       int ch = read();
+
+                                       if (ch == quot) {
+                                               state = STATE_TAG;
+                                               return getToken(XML_ATTRIBUTE);
+                                       }
+
+                                       switch (ch) {
+                                               case '<':
+                                                       unread();
+
+                                               case ICharacterScanner.EOF:
+                                                       state = STATE_DEFAULT;
+                                                       return getToken(XML_ATTRIBUTE);
+                                       }
+                               }
+                       default:
+                         unread();
+               }
+
+               while (true) {
+                       switch (read()) {
+                               case '<':
+                                       unread();
+
+                               case ICharacterScanner.EOF:
+                               case '>':
+                                       state = STATE_DEFAULT;
+                                       return getToken(XML_TAG);
+
+                               case '"': case '\'':
+                                       unread();
+
+                                       state = STATE_TAG;
+                                       return getToken(XML_TAG);
+                       }
+               }
+       }
+
+       private IToken nextDeclToken() {
+               loop: while (true) {
+                       switch (read()) {
+                               case ICharacterScanner.EOF:
+                                       state = STATE_DEFAULT;
+                                       return getToken(isInternal() ? DTD_INTERNAL_DECL : XML_DECL);
+
+                               case '<':
+                                       if (parsedtd || isInternal()) {
+                                               switch (read()) {
+                                                       case ICharacterScanner.EOF:
+                                                               state = STATE_DEFAULT;
+                                                               return getToken(isInternal() ? DTD_INTERNAL : null);
+
+                                                       case '!':
+                                                       case '?':
+                                                               unread();
+                                                               break;
+
+                                                       default:
+                                                               continue loop;
+                                               }
+                                       }
+
+                                       unread();
+
+                               case '>':
+                                       state &= STATE_INTERNAL;
+                                       return getToken(isInternal() ? DTD_INTERNAL_DECL : XML_DECL);
+
+                               case '[': // <!DOCTYPE xxx [dtd]>
+                                       if (!isInternal()) {
+                                               state = STATE_INTERNAL;
+                                               return getToken(XML_DECL);
+                                       }
+                       }
+               }
+       }
+
+       private IToken nextCommentToken() {
+               state &= STATE_INTERNAL;
+
+               loop: while (true) {
+                       switch (read()) {
+                               case ICharacterScanner.EOF:
+                                       break loop;
+
+                               case '-': // -  -->
+                                       switch (read()) {
+                                               case ICharacterScanner.EOF:
+                                                       break loop;
+
+                                               case '-': // --  -->
+                                                       switch (read()) {
+                                                               case ICharacterScanner.EOF:
+                                                               case '>':
+                                                                       break loop;
+                                                       }
+
+                                                       unread();
+                                                       break loop;
+                                       }
+                       }
+               }
+
+               return getToken(isInternal() ? DTD_INTERNAL_COMMENT : XML_COMMENT);
+       }
+
+       private IToken nextCDATAToken() {
+               state = STATE_DEFAULT;
+
+loop:
+       while (true) {
+                       switch (read()) {
+                               case ICharacterScanner.EOF:
+                                       break loop;
+
+                               case ']': // ]  ]]>
+                                       switch (read()) {
+                                               case ICharacterScanner.EOF:
+                                                       break loop;
+
+                                               case ']': // ]]  ]]>
+                                                       switch (read()) {
+                                                               case ICharacterScanner.EOF:
+                                                               case '>': // ]]>
+                                                                       break loop;
+                                                       }
+
+                                                       unread();
+                                                       unread();
+                                                       continue loop;
+                                       }
+                       }
+               }
+
+               return getToken(XML_CDATA);
+       }
+
+       private IToken nextConditionalToken() {
+               state = STATE_DEFAULT;
+
+               int level = 1;
+
+loop:
+       while (true) {
+                       switch (read()) {
+                               case ICharacterScanner.EOF:
+                                       break loop;
+
+                               case '<': // -  -->
+                                       switch (read()) {
+                                               case ICharacterScanner.EOF:
+                                                       break loop;
+
+                                               case '!': // --  -->
+                                                       switch (read()) {
+                                                               case ICharacterScanner.EOF:
+                                                                       break loop;
+
+                                                               case '[':
+                                                                       ++level;
+                                                                       continue loop;
+                                                       }
+
+                                                       unread();
+                                                       continue loop;
+                                       }
+
+                                       unread();
+                                       continue loop;
+
+                               case ']': // -  -->
+                                       switch (read()) {
+                                               case ICharacterScanner.EOF:
+                                                       break loop;
+
+                                               case ']': // --  -->
+                                                       switch (read()) {
+                                                               case ICharacterScanner.EOF:
+                                                               case '>':
+                                                                       if (--level == 0) {
+                                                                               break loop;
+                                                                       }
+
+                                                                       continue loop;
+                                                       }
+
+                                                       unread();
+                                                       unread();
+                                                       continue loop;
+                                       }
+                       }
+               }
+
+               return getToken(DTD_CONDITIONAL);
+       }
+
+       private IToken getToken(String type) {
+               length = position - offset;
+
+               if (length == 0) {
+                       return Token.EOF;
+               }
+
+               if (type == null) {
+                       return Token.UNDEFINED;
+               }
+
+               IToken token = (IToken) tokens.get(type);
+               if (token == null) {
+                       token = new Token(type);
+                       tokens.put(type, token);
+               }
+
+               return token;
+       }
+
+       private boolean isInternal() {
+               return (state & STATE_INTERNAL) != 0;
+       }
+
+       private int read() {
+               if (position >= end) {
+                       return ICharacterScanner.EOF;
+               }
+
+               try {
+                       return document.getChar(position++);
+               } catch (BadLocationException e) {
+                       --position;
+                       return ICharacterScanner.EOF;
+               }
+       }
+
+       private void unread() {
+               --position;
+       }
+
+       /*
+        * @see org.eclipse.jface.text.rules.ITokenScanner#getTokenOffset()
+        */
+       public int getTokenOffset() {
+         Assert.isTrue(offset>=0, Integer.toString(offset));
+               return offset;
+       }
+
+       /*
+        * @see org.eclipse.jface.text.rules.ITokenScanner#getTokenLength()
+        */
+       public int getTokenLength() {
+               return length;
+       }
+
+       /*
+        * @see org.eclipse.jface.text.rules.ITokenScanner#setRange(IDocument, int, int)
+        */
+       public void setRange(IDocument document, int offset, int length) {
+               this.document = document;
+               this.end = offset + length;
+
+               this.offset = offset;
+               this.position = offset;
+               this.length = 0;
+
+               this.state = STATE_DEFAULT;
+       }
+
+       /*
+          * @see org.eclipse.jface.text.rules.IPartitionTokenScanner
+          */
+//       public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) {
+//         state = STATE_DEFAULT;
+//         if (partitionOffset > -1) {
+//           int delta = offset - partitionOffset;
+//           if (delta > 0) {
+//             setRange(document, partitionOffset, length + delta);
+//             return;
+//           }
+//         }
+//         setRange(document, partitionOffset, length);
+//       }
+       /*
+        * @see org.eclipse.jface.text.rules.IPartitionTokenScanner
+        */
+       public void setPartialRange(
+               IDocument document, int offset, int length,
+               String contentType, int partitionOffset
+       ) {
+//       boolean flag = false;
+               this.document = document;
+               this.end = offset + length;
+
+               // NB! Undocumented value: -1
+               if (partitionOffset >= 0) {
+                       offset = partitionOffset;
+//                     flag = true;
+               }
+
+               this.offset = offset;
+               this.position = offset;
+               this.length = 0;
+
+//             if (flag) {
+//               state = STATE_DEFAULT;
+//               return;
+//             }
+               if (contentType == XML_ATTRIBUTE) {
+                       state = STATE_TAG;
+                       return;
+               }
+
+               if (contentType == XML_TAG) {
+                       state = isContinuationPartition() ? STATE_TAG : STATE_DEFAULT;
+                       return;
+               }
+
+               if (contentType == XML_DECL) {
+                       state = isContinuationPartition() ? STATE_DECL : STATE_DEFAULT;
+                       return;
+               }
+
+               if (contentType == DTD_INTERNAL ||
+                       contentType == DTD_INTERNAL_DECL ||
+                       contentType == DTD_INTERNAL_COMMENT
+               ) {
+                       state = STATE_INTERNAL;
+                       return;
+               }
+
+               state = STATE_DEFAULT;
+       }
+
+       private boolean isContinuationPartition() {
+               try {
+                       String type = document.getContentType(offset - 1);
+
+                       if (type != IDocument.DEFAULT_CONTENT_TYPE) {
+                               return true;
+                       }
+               } catch (BadLocationException e) {}
+
+               return false;
+       }
+}
index 1064ca3..c74cc32 100644 (file)
@@ -8,7 +8,7 @@
  * Contributors:
  *     Igor Malinin - initial contribution
  *
- * $Id: XMLPartitionScanner.java,v 1.2 2005-05-15 23:09:09 axelcl Exp $
+ * $Id: XMLPartitionScanner.java,v 1.3 2005-05-15 23:23:02 axelcl Exp $
  */
 
 package net.sourceforge.phpeclipse.xml.ui.internal.text;
@@ -101,9 +101,7 @@ public class XMLPartitionScanner implements IPartitionTokenScanner {
                                                return getToken(XML_TAG);
 
                                        case '?': // <?  <?PI 
-                                           unread();
-                                           break;
-//                                             return nextPIToken(); 
+                                               return nextPIToken(); 
 
                                        case '!': // <!  <!DEFINITION or <![CDATA[ or <!--COMMENT
                                                switch (read()) {
index 81ce13f..8d05650 100644 (file)
@@ -8,7 +8,7 @@
  * Contributors:
  *     Igor Malinin - initial contribution
  *
- * $Id: XMLTextTools.java,v 1.2 2005-05-06 00:55:41 stefanbjarni Exp $
+ * $Id: XMLTextTools.java,v 1.3 2005-05-15 23:23:02 axelcl Exp $
  */
 
 package net.sourceforge.phpeclipse.xml.ui.text;
@@ -17,6 +17,7 @@ import java.util.Map;
 
 import net.sourceforge.phpeclipse.ui.text.AbstractTextTools;
 import net.sourceforge.phpeclipse.xml.ui.internal.text.DeclScanner;
+import net.sourceforge.phpeclipse.xml.ui.internal.text.PHPXMLPartitionScanner;
 import net.sourceforge.phpeclipse.xml.ui.internal.text.SingleTokenScanner;
 import net.sourceforge.phpeclipse.xml.ui.internal.text.TextScanner;
 import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLCDATAScanner;
@@ -26,7 +27,6 @@ import net.sourceforge.phpeclipse.xml.ui.internal.text.XMLTagScanner;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.text.IDocumentPartitioner;
 import org.eclipse.jface.text.rules.DefaultPartitioner;
-import org.eclipse.jface.text.rules.IPartitionTokenScanner;
 import org.eclipse.jface.text.rules.ITokenScanner;
 import org.eclipse.jface.text.rules.RuleBasedScanner;
 
@@ -67,7 +67,8 @@ public class XMLTextTools extends AbstractTextTools {
 
        /** The XML partitions scanner */
        private XMLPartitionScanner xmlPartitionScanner;
-
+       
+       private PHPXMLPartitionScanner phpXMLPartitionScanner;
        /** The XML text scanner */
        private TextScanner xmlTextScanner;
 
@@ -101,7 +102,7 @@ public class XMLTextTools extends AbstractTextTools {
                super( store, strTokens );
 
                xmlPartitionScanner = new XMLPartitionScanner( false );
-
+               phpXMLPartitionScanner = new PHPXMLPartitionScanner( false );
                Map tokens = getTokens();
 
                xmlTextScanner = new TextScanner(
@@ -133,12 +134,16 @@ public class XMLTextTools extends AbstractTextTools {
                return new DefaultPartitioner( xmlPartitionScanner, TYPES );
        }
 
+       public IDocumentPartitioner createPHPXMLPartitioner() {
+               return new DefaultPartitioner( phpXMLPartitionScanner, TYPES );
+       }
+       
        /**
         * 
         */
-       public IPartitionTokenScanner getXMLPartitionScanner() {
-               return xmlPartitionScanner;
-       }
+//     public IPartitionTokenScanner getXMLPartitionScanner() {
+//             return xmlPartitionScanner;
+//     }
 
        /**
         * Returns a scanner which is configured to scan XML text.
index 91283c2..eaf1d71 100644 (file)
@@ -102,9 +102,12 @@ public class JavaTextTools implements IPHPPartitions {
   /** The Java singleline comment scanner */
   private SingleTokenPHPScanner fSinglelineCommentScanner;
 
-  /** The Java string scanner */
-  private SingleTokenPHPScanner fStringScanner;
+  /** The PHP double quoted string scanner */
+//  private SingleTokenPHPScanner fStringDQScanner;
 
+  /** The PHP single quoted string scanner */
+//  private SingleTokenPHPScanner fStringSQScanner;
+  
   /** The PHPDoc scanner */
   private PHPDocCodeScanner fPHPDocScanner;
 
@@ -197,7 +200,9 @@ public class JavaTextTools implements IPHPPartitions {
         IPreferenceConstants.PHP_MULTILINE_COMMENT);
     fSinglelineCommentScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store,
         IPreferenceConstants.PHP_SINGLELINE_COMMENT);
-    fStringScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store, IPreferenceConstants.PHP_STRING);
+//    fStringDQScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store, IPreferenceConstants.PHP_STRING);
+//    fStringSQScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store, IPreferenceConstants.PHP_STRING);
+    
     fPHPDocScanner = new PHPDocCodeScanner((JavaColorManager) colorManager, store);
     //    fHTMLScanner = new HTMLCodeScanner((JavaColorManager)fColorManager, store);
     fSmartyScanner = new SmartyCodeScanner((JavaColorManager) colorManager, store);
@@ -230,7 +235,8 @@ public class JavaTextTools implements IPHPPartitions {
     fCodeScanner = null;
     fMultilineCommentScanner = null;
     fSinglelineCommentScanner = null;
-    fStringScanner = null;
+//    fStringDQScanner = null;
+//    fStringSQScanner = null;
     fPHPDocScanner = null;
     //    fPartitionScanner = null;
 
@@ -331,9 +337,9 @@ public class JavaTextTools implements IPHPPartitions {
    * 
    * @since 2.0
    */
-  public RuleBasedScanner getStringScanner() {
-    return fStringScanner;
-  }
+//  public RuleBasedScanner getStringScanner() {
+//    return fStringDQScanner;
+//  }
 
   /**
    * Returns a scanner which is configured to scan JavaDoc compliant comments. Notes that the start sequence "/**" and the
@@ -481,7 +487,7 @@ public class JavaTextTools implements IPHPPartitions {
   //    return fCodeScanner.affectsBehavior(event)
   //        || fMultilineCommentScanner.affectsBehavior(event)
   //        || fSinglelineCommentScanner.affectsBehavior(event)
-  //        || fStringScanner.affectsBehavior(event)
+  //        || fStringDQScanner.affectsBehavior(event)
   //        || fPHPDocScanner.affectsBehavior(event);
   //  }
   /**
@@ -498,8 +504,8 @@ public class JavaTextTools implements IPHPPartitions {
       fMultilineCommentScanner.adaptToPreferenceChange(event);
     if (fSinglelineCommentScanner.affectsBehavior(event))
       fSinglelineCommentScanner.adaptToPreferenceChange(event);
-    //    if (fStringScanner.affectsBehavior(event))
-    //      fStringScanner.adaptToPreferenceChange(event);
+    //    if (fStringDQScanner.affectsBehavior(event))
+    //      fStringDQScanner.adaptToPreferenceChange(event);
     if (fPHPDocScanner.affectsBehavior(event))
       fPHPDocScanner.adaptToPreferenceChange(event);
     //    if (fHTMLScanner.affectsBehavior(event))
@@ -612,14 +618,14 @@ public class JavaTextTools implements IPHPPartitions {
   /**
    * Return a scanner for creating xml partitions.
    */
-  private static XMLPartitionScanner getXMLPartitionScanner() {
-    //    if (XML_PARTITION_SCANNER == null)
-    //      XML_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.XML_FILE);
-    //    return XML_PARTITION_SCANNER;
-    if (XML_PARTITION_SCANNER == null)
-      XML_PARTITION_SCANNER = new XMLPartitionScanner(false);
-    return XML_PARTITION_SCANNER;
-  }
+//  private static XMLPartitionScanner getXMLPartitionScanner() {
+//    //    if (XML_PARTITION_SCANNER == null)
+//    //      XML_PARTITION_SCANNER = new HTMLPartitionScanner(IPHPPartitions.XML_FILE);
+//    //    return XML_PARTITION_SCANNER;
+//    if (XML_PARTITION_SCANNER == null)
+//      XML_PARTITION_SCANNER = new XMLPartitionScanner(false);
+//    return XML_PARTITION_SCANNER;
+//  }
 
   private PHPPartitionScanner getJSPPartitionScanner() {
     if (jspPartitionScanner == null)
index cfd2d31..2f9211a 100644 (file)
@@ -165,12 +165,14 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
   private AbstractJavaScanner fSinglelineCommentScanner;
 
   /**
-   * The Java string scanner
-   * 
-   * @since 3.0
+   * The PHP double quoted string scanner
    */
-  private AbstractJavaScanner fStringScanner;
-
+  private AbstractJavaScanner fStringDQScanner;
+  /**
+   * The PHP single quoted string scanner
+   */
+  private AbstractJavaScanner fStringSQScanner;
+  
   /**
    * The Javadoc scanner
    * 
@@ -251,7 +253,7 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
   //    fCodeScanner = (AbstractJavaScanner) fJavaTextTools.getCodeScanner();
   //    fMultilineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getMultilineCommentScanner();
   //    fSinglelineCommentScanner = (AbstractJavaScanner) fJavaTextTools.getSinglelineCommentScanner();
-  //    fStringScanner = (AbstractJavaScanner) fJavaTextTools.getStringScanner();
+  //    fStringDQScanner = (AbstractJavaScanner) fJavaTextTools.getStringScanner();
   //    fJavaDocScanner = (AbstractJavaScanner) fJavaTextTools.getJavaDocScanner();
   //    fTextEditor = editor;
   //    fXMLTextTools = XMLPlugin.getDefault().getXMLTextTools();
@@ -278,7 +280,8 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
         IPreferenceConstants.PHP_MULTILINE_COMMENT);
     fSinglelineCommentScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore,
         IPreferenceConstants.PHP_SINGLELINE_COMMENT);
-    fStringScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING);
+    fStringDQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_DQ);
+    fStringSQScanner = new SingleTokenPHPScanner(getColorManager(), fPreferenceStore, IPreferenceConstants.PHP_STRING_SQ);
     fJavaDocScanner = new PHPDocCodeScanner(getColorManager(), fPreferenceStore);
   }
 
@@ -292,7 +295,7 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
    */
   public boolean affectsTextPresentation(PropertyChangeEvent event) {
     return fCodeScanner.affectsBehavior(event) || fMultilineCommentScanner.affectsBehavior(event)
-        || fSinglelineCommentScanner.affectsBehavior(event) || fStringScanner.affectsBehavior(event)
+        || fSinglelineCommentScanner.affectsBehavior(event) || fStringDQScanner.affectsBehavior(event)|| fStringSQScanner.affectsBehavior(event)
         || fJavaDocScanner.affectsBehavior(event);
   }
 
@@ -315,8 +318,10 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
       fMultilineCommentScanner.adaptToPreferenceChange(event);
     if (fSinglelineCommentScanner.affectsBehavior(event))
       fSinglelineCommentScanner.adaptToPreferenceChange(event);
-    if (fStringScanner.affectsBehavior(event))
-      fStringScanner.adaptToPreferenceChange(event);
+    if (fStringDQScanner.affectsBehavior(event))
+      fStringDQScanner.adaptToPreferenceChange(event);
+    if (fStringSQScanner.affectsBehavior(event))
+      fStringSQScanner.adaptToPreferenceChange(event);
     if (fJavaDocScanner.affectsBehavior(event))
       fJavaDocScanner.adaptToPreferenceChange(event);
   }
@@ -455,16 +460,23 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
   }
 
   /**
-   * Returns the Java string scanner for this configuration.
+   * Returns the PHP double quoted string scanner for this configuration.
    * 
-   * @return the Java string scanner
-   * @since 2.0
+   * @return the PHP double quoted string scanner
    */
-  protected RuleBasedScanner getStringScanner() {
-    return fStringScanner;
+  protected RuleBasedScanner getStringDQScanner() {
+    return fStringDQScanner;
   }
 
   /**
+   * Returns the PHP single quoted string scanner for this configuration.
+   * 
+   * @return the PHP single quoted string scanner
+   */
+  protected RuleBasedScanner getStringSQScanner() {
+    return fStringSQScanner;
+  }
+  /**
    * Returns the HTML source code scanner for this configuration.
    * 
    * @return the HTML source code scanner
@@ -805,12 +817,12 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
     phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
     phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_PHPDOC_COMMENT);
 
-    phpDR = new DefaultDamagerRepairer(getStringScanner());
+    phpDR = new DefaultDamagerRepairer(getStringDQScanner());
     phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_DQ);
     phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_DQ);
-    phpDR = new DefaultDamagerRepairer(getStringScanner());
+    phpDR = new DefaultDamagerRepairer(getStringSQScanner());
     phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
-    phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
+    phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ); 
     phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
     phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
     phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
index 242f759..28f0e13 100644 (file)
@@ -51,7 +51,8 @@ public class HTMLCodeScanner extends AbstractJavaScanner {
     IPreferenceConstants.PHP_KEYWORD,
     IPreferenceConstants.PHP_FUNCTIONNAME,
     IPreferenceConstants.PHP_VARIABLE,
-    IPreferenceConstants.PHP_STRING,
+    IPreferenceConstants.PHP_STRING_DQ,
+    IPreferenceConstants.PHP_STRING_SQ,
     IPreferenceConstants.PHP_TYPE,
     IPreferenceConstants.PHP_CONSTANT,
     IPreferenceConstants.PHP_DEFAULT,
@@ -142,7 +143,7 @@ public class HTMLCodeScanner extends AbstractJavaScanner {
 
 //  keyword = new Token(new TextAttribute(provider.getColor(PHPColorProvider.KEYWORD)));
 //  IToken type = new Token(new TextAttribute(provider.getColor(PHPColorProvider.FUNCTION_NAME)));
-//    IToken string = new Token(new TextAttribute(provider.getColor(PHPColorProvider.STRING)));
+//    IToken string = new Token(new TextAttribute(provider.getColor(PHPColorProvider.STRING_DQ)));
 //  IToken comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.SINGLE_LINE_COMMENT)));
 //  IToken multi_comment = new Token(new TextAttribute(provider.getColor(PHPColorProvider.MULTI_LINE_COMMENT)));
 //    IToken other = new Token(new TextAttribute(provider.getColor(PHPColorProvider.DEFAULT)));
@@ -155,7 +156,7 @@ public class HTMLCodeScanner extends AbstractJavaScanner {
   //rules.add(new EndOfLineRule("#", comment));
 
   // Add rule for strings and character constants.
-  rules.add(new SingleLineRule("\"", "\"", getToken(IPreferenceConstants.PHP_STRING))); //$NON-NLS-2$ //$NON-NLS-1$
+  rules.add(new SingleLineRule("\"", "\"", getToken(IPreferenceConstants.PHP_STRING_DQ))); //$NON-NLS-2$ //$NON-NLS-1$
   // rules.add(new SingleLineRule("'", "'", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
 
   // rules.add(new SingleLineRule("//", "//", php_comment));
index 250fdc1..8a50ffd 100644 (file)
@@ -367,7 +367,8 @@ public class PHPCodeScanner extends AbstractJavaScanner {
       IPreferenceConstants.PHP_KEYWORD,
       IPreferenceConstants.PHP_FUNCTIONNAME,
       IPreferenceConstants.PHP_VARIABLE,
-      IPreferenceConstants.PHP_STRING,
+      IPreferenceConstants.PHP_STRING_DQ,
+      IPreferenceConstants.PHP_STRING_SQ,
       IPreferenceConstants.PHP_TYPE,
       IPreferenceConstants.PHP_CONSTANT,
       IPreferenceConstants.PHP_DEFAULT,
@@ -401,12 +402,10 @@ public class PHPCodeScanner extends AbstractJavaScanner {
     rules.add(new EndOfLineRule("//", token)); //$NON-NLS-1$
     rules.add(new EndOfLineRule("#", token)); //$NON-NLS-1$
     // Add rule for strings and character constants.
-    token = getToken(IPreferenceConstants.PHP_STRING);
-//    rules.add(new MultiLineRule("\"", "\"", token, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
-//    rules.add(new MultiLineRule("`", "`", token, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
-//    rules.add(new MultiLineRule("'", "'", token, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
-    rules.add(new SingleQuoteStringRule(token));
-    rules.add(new DoubleQuoteStringRule(token));
+//    token = getToken(IPreferenceConstants.PHP_STRING_SQ);
+//    rules.add(new SingleQuoteStringRule(token));
+//    token = getToken(IPreferenceConstants.PHP_STRING_DQ);
+//    rules.add(new DoubleQuoteStringRule(token));
     rules.add(new AccentStringRule(token));
 
     token = getToken(IPreferenceConstants.PHP_MULTILINE_COMMENT);
index 107fa08..7dc609a 100644 (file)
@@ -8,7 +8,7 @@
  Contributors:
  Igor Malinin - initial contribution
 
- $Id: PHPDocumentPartitioner.java,v 1.2 2004-11-12 20:17:10 axelcl Exp $
+ $Id: PHPDocumentPartitioner.java,v 1.3 2005-05-15 23:24:41 axelcl Exp $
  **********************************************************************/
 package net.sourceforge.phpeclipse.phpeditor.php;
 
@@ -60,7 +60,7 @@ public class PHPDocumentPartitioner extends MultiViewPartitioner {
   protected IDocumentPartitioner createPartitioner(String contentType) {
     if (contentType == null) {
       //                       return JavaTextTools.createHTMLPartitioner();
-      return PHPeclipsePlugin.getDefault().getJavaTextTools().getXMLTextTools().createXMLPartitioner();
+      return PHPeclipsePlugin.getDefault().getJavaTextTools().getXMLTextTools().createPHPXMLPartitioner();
     }
 
     if (contentType.equals(PHPPartitionScanner.PHP_SCRIPTING_AREA)) {
index 5f1c3a7..a4581f8 100644 (file)
@@ -8,7 +8,7 @@
  Contributors:
  Igor Malinin - initial contribution
 
- $Id: PHPPartitionScanner.java,v 1.28 2005-05-13 20:19:42 axelcl Exp $
+ $Id: PHPPartitionScanner.java,v 1.29 2005-05-15 23:24:41 axelcl Exp $
  **********************************************************************/
 package net.sourceforge.phpeclipse.phpeditor.php;
 
@@ -31,14 +31,8 @@ import org.eclipse.jface.text.rules.Token;
  * @author Igor Malinin
  */
 public class PHPPartitionScanner implements IPartitionTokenScanner {
-  //   public static final String JSP_DIRECTIVE = "__jsp_directive";
-  //   public static final String JSP_COMMENT = "__jsp_comment";
-  //// public static final String JSP_TAG = "__jsp_tag";
-  //   public static final String JSP_DECLARATION = "__jsp_declaration";
   public static final String PHP_SCRIPTING_AREA = "__php_scripting_area ";
 
-  //   public static final String JSP_EXPRESSION = "__jsp_expression";
-
   public static final int STATE_DEFAULT = 0;
 
   //   public static final int STATE_TAG = 1;
@@ -84,26 +78,14 @@ public class PHPPartitionScanner implements IPartitionTokenScanner {
         state = STATE_DEFAULT;
         return getToken(null);
 
-      case '?': // <%SCRIPLET <%@DIRECTIVE <%!DECLARATION <%=EXPRESSION <%--COMMENT
-        int ch = read();
-        //                                              if (Character.isWhitespace((char)ch)) {
-        //                                                return nextJSPToken(PHP_SCRIPTING_AREA);
-        //                                              }
-        switch (ch) {
-        case ICharacterScanner.EOF:
-          state = STATE_DEFAULT;
-          return getToken(PHP_SCRIPTING_AREA);
-
-        //                                                     case '-': // <%- <%--COMMENT
-        //                                                             switch (read()) {
-        //                                                                     case ICharacterScanner.EOF:
-        //                                                                     case '-': // <%--
-        //                                                                             return nextCommentToken();
-        //                                                             }
-        //
-        //                                                             break;
-        }
-
+      case '?': // <?
+//        int ch = read();
+//
+//        switch (ch) {
+//        case ICharacterScanner.EOF:
+//          state = STATE_DEFAULT;
+//          return getToken(PHP_SCRIPTING_AREA);
+//        }
         return scanUntilPHPEndToken(PHP_SCRIPTING_AREA);
       }
 
@@ -211,51 +193,6 @@ public class PHPPartitionScanner implements IPartitionTokenScanner {
     }
   }
 
-  //   private IToken nextCommentToken() {
-  //           int ch = read();
-  //           loop: while (true) {
-  //                   switch (ch) {
-  //                           case ICharacterScanner.EOF:
-  //                                   break loop;
-  //
-  //                           case '-': // - --%>
-  //                                   ch = read();
-  //                                   switch (ch) {
-  //                                           case ICharacterScanner.EOF:
-  //                                                   break loop;
-  //
-  //                                           case '-': // -- --%>
-  //                                                   ch = read();
-  //                                                   switch (ch) {
-  //                                                           case ICharacterScanner.EOF:
-  //                                                                   break loop;
-  //
-  //                                                           case '%': // --% --%>
-  //                                                                   ch = read();
-  //                                                                   switch (ch) {
-  //                                                                           case ICharacterScanner.EOF:
-  //                                                                           case '>':
-  //                                                                                   break loop;
-  //                                                                   }
-  //
-  //                                                                   continue loop;
-  //
-  //                                                           case '-': // --- ---%>
-  //                                                                   unread();
-  //                                                                   continue loop;
-  //                                                   }
-  //
-  //                                                   ch = read();
-  //                                                   continue loop;
-  //                                   }
-  //                   }
-  //
-  //                   ch = read();
-  //           }
-  //
-  //           return getToken(JSP_COMMENT);
-  //   }
-
   private IToken getToken(String type) {
     length = position - offset;
 
@@ -422,13 +359,13 @@ public class PHPPartitionScanner implements IPartitionTokenScanner {
    */
   public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) {
     state = STATE_DEFAULT;
-    //    if (partitionOffset > -1) {
-    //         int delta= offset - partitionOffset;
-    //         if (delta > 0) {
-    //                 this.setRange(document, partitionOffset, length + delta);
-    //                 return;
-    //         }
-    // }
+    if (partitionOffset > -1) {
+      int delta = offset - partitionOffset;
+      if (delta > 0) {
+        setRange(document, partitionOffset, length + delta);
+        return;
+      }
+    }
     setRange(document, partitionOffset, length);
   }
 
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition_delete_it.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/php/PHPPartition_delete_it.java
deleted file mode 100644 (file)
index 541079a..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Created on 28.04.2003
- *
- */
-package net.sourceforge.phpeclipse.phpeditor.php;
-
-import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
-
-import org.eclipse.jface.text.IDocument;
-
-/**
- * @author slanger
- * @version $Revision: 1.2 $
- */
-public class PHPPartition_delete_it extends Partition
-{
-       private boolean fShortTagsEnabled = true;
-       
-    /**
-     * @param document
-     * @param delim
-     * @param contentType
-     * @param parentPartition
-     */
-    public PHPPartition_delete_it(IDocument document, String parentPartition)
-    {
-        super(
-            document,
-            new char[] { '<', '>' },
-            IPHPPartitions.PHP_PARTITIONING,
-            parentPartition);
-    }
-
-    
-
-    /* (non-Javadoc)
-     * @see net.sourceforge.phpeclipse.phpeditor.php.Partition#allowedPartition(java.lang.String)
-     */
-    protected boolean allowedPartition(String type)
-    {
-        if(type.equals(IPHPPartitions.PHP_PHPDOC_COMMENT))
-               return true;
-               
-        return false;
-    }
-
-    /* (non-Javadoc)
-     * @see net.sourceforge.phpeclipse.phpeditor.php.Partition#scan()
-     */
-    protected boolean scan()
-    {
-       int ch;
-       if(fShortTagsEnabled && checkPattern("<?", true))
-       {
-               scanToEnd();
-       }
-       else if(checkPattern("<?php", false))
-       {
-               scanToEnd();
-       }    
-       else
-               return false;
-       
-       return true;    
-    }
-       
-       private void scanToEnd()
-       {
-               if(isEnd())
-                       return;
-                               
-               while(!checkPattern("?>", true))
-               {
-                       int offset = getOffset();
-                       if(checkPattern("/*", true))
-                       {       
-                               unread(2);
-                               return;
-                       }
-               }               
-       }
-}
index 99b3235..9240bbd 100644 (file)
@@ -134,7 +134,8 @@ public class SmartyCodeScanner extends AbstractJavaScanner {
       IPreferenceConstants.PHP_KEYWORD,
       IPreferenceConstants.PHP_FUNCTIONNAME,
       IPreferenceConstants.PHP_VARIABLE,
-      IPreferenceConstants.PHP_STRING,
+      IPreferenceConstants.PHP_STRING_DQ,
+      IPreferenceConstants.PHP_STRING_SQ,
       IPreferenceConstants.PHP_TYPE,
       IPreferenceConstants.PHP_CONSTANT,
       IPreferenceConstants.PHP_DEFAULT };
@@ -159,7 +160,7 @@ public class SmartyCodeScanner extends AbstractJavaScanner {
   protected List createRules() {
     List rules = new ArrayList();
     // Add rule for strings and character constants.
-    Token token = getToken(IPreferenceConstants.PHP_STRING);
+    Token token = getToken(IPreferenceConstants.PHP_STRING_DQ);
     rules.add(new MultiLineRule("\"", "\"", token, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
 
     // Add generic whitespace rule.
index 24c25ee..6f05c78 100644 (file)
@@ -29,7 +29,8 @@ public class PHPColorProvider {
   public static final RGB KEYWORD = new RGB(127, 0, 85);
   public static final RGB VARIABLE = new RGB(127, 159, 191);
   public static final RGB FUNCTION_NAME = new RGB(127, 127, 159);
-  public static final RGB STRING = new RGB(42, 0, 255);
+  public static final RGB STRING_DQ = new RGB(42, 0, 255);
+  public static final RGB STRING_SQ = new RGB(42, 0, 255);
   public static final RGB DEFAULT = new RGB(0, 0, 0);
   public static final RGB TYPE = new RGB(127, 0, 85);
   public static final RGB CONSTANT = new RGB(127, 0, 85);