fix for http://sourceforge.net/tracker/index.php?func=detail&aid=1431317&group_id...
authorbananeweizen <bananeweizen>
Tue, 14 Feb 2006 20:46:58 +0000 (20:46 +0000)
committerbananeweizen <bananeweizen>
Tue, 14 Feb 2006 20:46:58 +0000 (20:46 +0000)
recognize object structures in double quoted strings for syntax coloring

net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/ui/text/PHPStringDQCodeScanner.java

index df0bf72..85dbb75 100644 (file)
@@ -33,59 +33,72 @@ public final class PHPStringDQCodeScanner extends AbstractJavaScanner {
   private static String[] fgTokenProperties = { IPreferenceConstants.PHP_STRING_DQ, IPreferenceConstants.PHP_VARIABLE, IPreferenceConstants.PHP_VARIABLE_DOLLAR};
 
   private class PHPWordRule extends WordRule {
-    private StringBuffer fBuffer = new StringBuffer();
-
-    public PHPWordRule(IWordDetector detector) {
-      super(detector, Token.UNDEFINED);
-    }
-
-    public PHPWordRule(IWordDetector detector, IToken defaultToken) {
-      super(detector, defaultToken);
-    }
-
-    public IToken evaluate(ICharacterScanner scanner) {
-      int c = scanner.read();
-      boolean isUnderscore = false;
-      if (fDetector.isWordStart((char) c)) {
-        if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
-
-          fBuffer.setLength(0);
-          fBuffer.append((char) c);
-          c = scanner.read();
-          if (c=='_') {
-               isUnderscore = true;
-          }
-          while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c)) {
-            fBuffer.append((char) c);
-            c = scanner.read();
-          } 
-          scanner.unread();
-          if (isUnderscore) {
-               return getToken(IPreferenceConstants.PHP_VARIABLE_DOLLAR);
-          }
-          return getToken(IPreferenceConstants.PHP_VARIABLE);
-        }
-      }
-
-      scanner.unread();
-      return Token.UNDEFINED;
-    }
+       private StringBuffer fBuffer = new StringBuffer();
+
+       public PHPWordRule(IWordDetector detector) {
+         super(detector, Token.UNDEFINED);
+       }
+
+       public PHPWordRule(IWordDetector detector, IToken defaultToken) {
+         super(detector, defaultToken);
+       }
+
+       public IToken evaluate(ICharacterScanner scanner) {
+         int c = scanner.read();
+         boolean isUnderscore = false;
+         if (fDetector.isWordStart((char) c)) {
+               if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
+
+                 fBuffer.setLength(0);
+                 fBuffer.append((char) c);
+                 c = scanner.read();
+                 if (c=='_') {
+                         isUnderscore = true;
+                 }
+                 while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c)) {
+                       fBuffer.append((char) c);
+                       c = scanner.read();
+                       // hack for coloring object elements with variable color instead of string color
+                       if (c=='-') {
+                               int c2=scanner.read();
+                               if (c2=='>') {
+                                       fBuffer.append(c);
+                                       fBuffer.append(c2);
+                                       c=scanner.read();
+                               }
+                               else {
+                                       scanner.unread();
+                               }
+                       }
+                       // hack end
+                 }
+                 scanner.unread();
+                 if (isUnderscore) {
+                         return getToken(IPreferenceConstants.PHP_VARIABLE_DOLLAR);
+                 }
+                 return getToken(IPreferenceConstants.PHP_VARIABLE);
+               }
+         }
+
+         scanner.unread();
+         return Token.UNDEFINED;
+       }
   }
 
   public PHPStringDQCodeScanner(IColorManager manager, IPreferenceStore store) {
-    super(manager, store);
-    initialize();
+       super(manager, store);
+       initialize();
   }
 
   public IDocument getDocument() {
-    return fDocument;
+       return fDocument;
   }
 
   /*
    * @see AbstractJavaScanner#getTokenProperties()
    */
   protected String[] getTokenProperties() {
-    return fgTokenProperties;
+       return fgTokenProperties;
   }
 
   /*
@@ -93,16 +106,16 @@ public final class PHPStringDQCodeScanner extends AbstractJavaScanner {
    */
   protected List createRules() {
 
-    List list = new ArrayList();
+       List list = new ArrayList();
 
-    // Add rule for tags.
-    Token token = getToken(IPreferenceConstants.PHP_STRING_DQ);
-    PHPWordRule wordRule = new PHPWordRule(new PHPVariableDetector(), token);
+       // Add rule for tags.
+       Token token = getToken(IPreferenceConstants.PHP_STRING_DQ);
+       PHPWordRule wordRule = new PHPWordRule(new PHPVariableDetector(), token);
 
-    list.add(wordRule);
+       list.add(wordRule);
 
-    setDefaultReturnToken(getToken(IPreferenceConstants.PHP_STRING_DQ));
-    return list;
+       setDefaultReturnToken(getToken(IPreferenceConstants.PHP_STRING_DQ));
+       return list;
   }
 }