Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / php / PHPCodeScanner.java
index 1fd27c1..09d6734 100644 (file)
@@ -34,18 +34,7 @@ import org.eclipse.jface.text.rules.WordRule;
 /**
  * PHP Code Scanner
  */
-public class PHPCodeScanner
-  extends AbstractJavaScanner {
-
-//  private static Token variable;
-//  private static Token keyword;
-//  private static Token type;
-//  private static Token constant;
-//  private static Token functionName;
-//  private static Token string;
-//  private static Token comment;
-//  private static Token multi_comment;
-//  private static Token other;
+public class PHPCodeScanner extends AbstractJavaScanner {
 
   private class PHPWordRule extends WordRule {
     private StringBuffer fBuffer = new StringBuffer();
@@ -61,6 +50,37 @@ public class PHPCodeScanner
     public IToken evaluate(ICharacterScanner scanner) {
       int c = scanner.read();
       boolean isVariable = false;
+      if (c == '<') {
+        c = scanner.read();
+        if (c != '?') {
+          scanner.unread();
+        } else {
+          c = scanner.read();
+          if (c != 'p') {
+            scanner.unread();
+          } else {
+            c = scanner.read();
+            if (c != 'h') {
+              scanner.unread();
+            } else {
+              c = scanner.read();
+              if (c != 'p') {
+                scanner.unread();
+              } else {
+                return getToken(IPreferenceConstants.PHP_TAG);
+              }
+            }
+          }
+        }
+
+      }
+      if (c == '?') {
+                               c = scanner.read();
+        if (c == '>') {
+          return getToken(IPreferenceConstants.PHP_TAG);
+        }
+        scanner.unread();
+      }
       if (fDetector.isWordStart((char) c)) {
         if (c == '$') {
           isVariable = true;
@@ -71,8 +91,7 @@ public class PHPCodeScanner
           do {
             fBuffer.append((char) c);
             c = scanner.read();
-          } while (
-            c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
+          } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
           scanner.unread();
 
           if (isVariable) {
@@ -96,16 +115,18 @@ public class PHPCodeScanner
 
   //private PHPColorProvider fColorProvider;
 
-  private static String[] fgTokenProperties = {
-               IPreferenceConstants.PHP_MULTILINE_COMMENT,
-               IPreferenceConstants.PHP_SINGLELINE_COMMENT,
-               IPreferenceConstants.PHP_KEYWORD,
-               IPreferenceConstants.PHP_FUNCTIONNAME,
-               IPreferenceConstants.PHP_VARIABLE,
-               IPreferenceConstants.PHP_STRING,
-               IPreferenceConstants.PHP_TYPE,
-               IPreferenceConstants.PHP_CONSTANT,
-               IPreferenceConstants.PHP_DEFAULT };
+  private static String[] fgTokenProperties =
+    {
+      IPreferenceConstants.PHP_MULTILINE_COMMENT,
+      IPreferenceConstants.PHP_SINGLELINE_COMMENT,
+                       IPreferenceConstants.PHP_TAG,
+      IPreferenceConstants.PHP_KEYWORD,
+      IPreferenceConstants.PHP_FUNCTIONNAME,
+      IPreferenceConstants.PHP_VARIABLE,
+      IPreferenceConstants.PHP_STRING,
+      IPreferenceConstants.PHP_TYPE,
+      IPreferenceConstants.PHP_CONSTANT,
+      IPreferenceConstants.PHP_DEFAULT };
   /**
        * Creates a PHP code scanner
        */
@@ -248,12 +269,12 @@ public class PHPCodeScanner
    */
   protected List createRules() {
     List rules = new ArrayList();
-    Token token= getToken(IPreferenceConstants.PHP_SINGLELINE_COMMENT);
+    Token token = getToken(IPreferenceConstants.PHP_SINGLELINE_COMMENT);
     // Add rule for single line comments.
     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);
+    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$
@@ -261,28 +282,27 @@ public class PHPCodeScanner
     //previous version
     //rules.add(new SingleLineRule("'", "'", token, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
 
-       
-    token= getToken(IPreferenceConstants.PHP_MULTILINE_COMMENT);
+    token = getToken(IPreferenceConstants.PHP_MULTILINE_COMMENT);
     rules.add(new MultiLineRule("/*", "*/", token)); //$NON-NLS-2$ //$NON-NLS-1$
     // Add generic whitespace rule.
     rules.add(new WhitespaceRule(new PHPWhitespaceDetector()));
     // Add word rule for keywords, types, and constants.
-    token= getToken(IPreferenceConstants.PHP_DEFAULT);
+    token = getToken(IPreferenceConstants.PHP_DEFAULT);
     PHPWordRule wordRule = new PHPWordRule(new PHPWordDetector(), token);
 
-    Token keyword= getToken(IPreferenceConstants.PHP_KEYWORD);
-    Token functionName= getToken(IPreferenceConstants.PHP_FUNCTIONNAME);
-    Token type= getToken(IPreferenceConstants.PHP_TYPE);
-    Token constant= getToken(IPreferenceConstants.PHP_CONSTANT);
-    
+    Token keyword = getToken(IPreferenceConstants.PHP_KEYWORD);
+    Token functionName = getToken(IPreferenceConstants.PHP_FUNCTIONNAME);
+    Token type = getToken(IPreferenceConstants.PHP_TYPE);
+    Token constant = getToken(IPreferenceConstants.PHP_CONSTANT);
+
     ArrayList buffer = PHPSyntaxRdr.getSyntaxData();
-  //  String strbuffer = null;  unused
+    //  String strbuffer = null;  unused
     PHPElement elbuffer = null;
-    for (int i=0;i<buffer.size();i++) {
-//    while ((buffer != null)
-//      && (!buffer.isEmpty()
-//        && ((elbuffer = (PHPElement) buffer.remove(0)) != null))) {
-                       elbuffer = (PHPElement) buffer.get(i);
+    for (int i = 0; i < buffer.size(); i++) {
+      //    while ((buffer != null)
+      //      && (!buffer.isEmpty()
+      //        && ((elbuffer = (PHPElement) buffer.remove(0)) != null))) {
+      elbuffer = (PHPElement) buffer.get(i);
       if (elbuffer instanceof PHPKeyword)
         wordRule.addWord(((PHPKeyword) elbuffer).getName(), keyword);
       if (elbuffer instanceof PHPFunction)
@@ -293,7 +313,7 @@ public class PHPCodeScanner
         wordRule.addWord(elbuffer.getName(), constant);
     }
     rules.add(wordRule);
-   // IRule[] result = new IRule[rules.size()];unused
+    // IRule[] result = new IRule[rules.size()];unused
     //    rules.toArray(result);
     //    setRules(result);
     return rules;