Two interfaces added for outlineable objects
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Parser.java
index ea3cd80..e3d3672 100644 (file)
@@ -16,7 +16,6 @@ import java.util.Hashtable;
 import net.sourceforge.phpdt.core.compiler.*;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.phpeditor.PHPString;
-import net.sourceforge.phpeclipse.phpeditor.php.PHPKeywords;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IMarker;
@@ -25,15 +24,9 @@ import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.ui.texteditor.MarkerUtilities;
 import test.PHPParserSuperclass;
 
-public class Parser
-  extends PHPParserSuperclass
-  implements PHPKeywords, ITerminalSymbols {
+public class Parser extends PHPParserSuperclass implements ITerminalSymbols {
 
-  public static final int ERROR = 2;
-  public static final int WARNING = 1;
-  public static final int INFO = 0;
-
-  //scanner token 
+  //scanner token
   public Scanner scanner;
 
   private IFile fileToParse;
@@ -159,7 +152,7 @@ public class Parser
     this.initializeScanner();
   }
   /**
-   *  Class Constructor.
+   *  ClassDeclaration Constructor.
    *
    *@param  s
    *@param  sess  Description of Parameter
@@ -201,36 +194,6 @@ public class Parser
     setMarker(fileToParse, message, charStart, charEnd, errorLevel);
   }
 
-  public static void setMarker(
-    IFile file,
-    String message,
-    int charStart,
-    int charEnd,
-    int errorLevel)
-    throws CoreException {
-    if (file != null) {
-      Hashtable attributes = new Hashtable();
-      MarkerUtilities.setMessage(attributes, message);
-      switch (errorLevel) {
-        case ERROR :
-          attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
-          break;
-        case WARNING :
-          attributes.put(
-            IMarker.SEVERITY,
-            new Integer(IMarker.SEVERITY_WARNING));
-          break;
-        case INFO :
-          attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
-          break;
-      }
-      MarkerUtilities.setCharStart(attributes, charStart);
-      MarkerUtilities.setCharEnd(attributes, charEnd);
-      // setLineNumber(attributes, lineNumber);
-      MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
-    }
-  }
-
   /**
    * This method will throw the SyntaxError.
    * It will add the good lines and columns to the Error
@@ -1455,7 +1418,7 @@ public class Parser
 
   private void parseDeclarations(
     PHPOutlineInfo outlineInfo,
-    PHPSegmentWithChildren current,
+    OutlineableWithChildren current,
     boolean goBack) {
     char[] ident;
     //   PHPClassDeclaration current = (PHPClassDeclaration) stack.peek();
@@ -1474,7 +1437,8 @@ public class Parser
           if (token == TokenNameVariable
             && store.getBoolean(PHPeclipsePlugin.PHP_OUTLINE_VAR)) {
             ident = scanner.getCurrentIdentifierSource();
-            String variableName = new String(ident);
+            //substring(1) added because PHPVarDeclaration doesn't need the $ anymore
+            String variableName = new String(ident).substring(1);
             outlineInfo.addVariable(variableName);
             getNextToken();
             if (token != TokenNameSEMICOLON) {
@@ -2012,11 +1976,15 @@ public class Parser
         if (token == TokenNameIdentifier) {
           getNextToken();
         } else {
-          throwSyntaxError("Class name expected after keyword 'extends'.");
+          throwSyntaxError("ClassDeclaration name expected after keyword 'extends'.");
         }
       }
     } else {
-      throwSyntaxError("Class name expected after keyword 'class'.");
+      if (token > TokenNameKEYWORD) {
+        throwSyntaxError(
+          "Don't use keyword for class declaration [" + token + "].");
+      }
+      throwSyntaxError("ClassDeclaration name expected after keyword 'class'.");
     }
   }
 
@@ -2107,6 +2075,12 @@ public class Parser
       } else {
         getNextToken();
       }
+    } else {
+      if (token > TokenNameKEYWORD) {
+        throwSyntaxError(
+          "Don't use keyword for function declaration [" + token + "].");
+      }
+      throwSyntaxError("Function name expected after keyword 'function'.");
     }
   }
   //
@@ -2835,26 +2809,26 @@ public class Parser
     unaryExpression();
   }
 
-  private void typeName() throws CoreException {
-    //'string' 'unset' 'array' 'object'
-    //'bool' 'boolean'
-    //'real' 'double' 'float'
-    //'int' 'integer'
-    String identifier = "";
-    if (token == TokenNameIdentifier) {
-      char[] ident = scanner.getCurrentIdentifierSource();
-      identifier = new String(ident);
-      String str = identifier.toLowerCase();
-      getNextToken();
-      for (int i = 0; i < PHP_TYPES.length; i++) {
-        if (PHP_TYPES[i].equals(str)) {
-          return;
-        }
-      }
-    }
-    throwSyntaxError(
-      "Expected type cast '( <type-name> )'; Got '" + identifier + "'.");
-  }
+  //  private void typeName() throws CoreException {
+  //    //'string' 'unset' 'array' 'object'
+  //    //'bool' 'boolean'
+  //    //'real' 'double' 'float'
+  //    //'int' 'integer'
+  //    String identifier = "";
+  //    if (token == TokenNameIdentifier) {
+  //      char[] ident = scanner.getCurrentIdentifierSource();
+  //      identifier = new String(ident);
+  //      String str = identifier.toLowerCase();
+  //      getNextToken();
+  //      for (int i = 0; i < PHP_TYPES.length; i++) {
+  //        if (PHP_TYPES[i].equals(str)) {
+  //          return;
+  //        }
+  //      }
+  //    }
+  //    throwSyntaxError(
+  //      "Expected type cast '( <type-name> )'; Got '" + identifier + "'.");
+  //  }
 
   private void assignExpression() throws CoreException {
     castExpression();