*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index 9327af8..e4026ea 100644 (file)
@@ -50,6 +50,7 @@ import net.sourceforge.phpdt.internal.compiler.parser.PHPReqIncDeclaration;
  */
 public final class PHPParser extends PHPParserSuperclass {
 
+  /** The file that is parsed. */
   private static IFile fileToParse;
 
   /** The current segment */
@@ -58,9 +59,15 @@ public final class PHPParser extends PHPParserSuperclass {
   private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
   private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
   PHPOutlineInfo outlineInfo;
+
+  /** The error level of the current ParseException. */
   private static int errorLevel = ERROR;
+  /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
   private static String errorMessage;
 
+  private static int errorStart = -1;
+  private static int errorEnd = -1;
+
   public PHPParser() {
   }
 
@@ -128,12 +135,23 @@ public final class PHPParser extends PHPParserSuperclass {
    */
   private static void setMarker(final ParseException e) {
     try {
-      setMarker(fileToParse,
-                errorMessage,
-                jj_input_stream.tokenBegin,
-                jj_input_stream.tokenBegin + e.currentToken.image.length(),
-                errorLevel,
-                "Line " + e.currentToken.beginLine);
+      if (errorStart == -1) {
+        setMarker(fileToParse,
+                  errorMessage,
+                  jj_input_stream.tokenBegin,
+                  jj_input_stream.tokenBegin + e.currentToken.image.length(),
+                  errorLevel,
+                  "Line " + e.currentToken.beginLine);
+      } else {
+        setMarker(fileToParse,
+                  errorMessage,
+                  errorStart,
+                  errorEnd,
+                  errorLevel,
+                  "Line " + e.currentToken.beginLine);
+        errorStart = -1;
+        errorEnd = -1;
+      }
     } catch (CoreException e2) {
       PHPeclipsePlugin.log(e2);
     }
@@ -282,6 +300,8 @@ PARSER_END(PHPParser)
 {
   "//" : IN_SINGLE_LINE_COMMENT
 |
+  "#"  : IN_SINGLE_LINE_COMMENT
+|
   <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
 |
   "/*" : IN_MULTI_LINE_COMMENT
@@ -610,10 +630,28 @@ void ClassDeclaration() :
 {
   final PHPClassDeclaration classDeclaration;
   final Token className;
-  final int pos = jj_input_stream.bufpos;
+  final int pos;
 }
 {
-  <CLASS> className = <IDENTIFIER> [ <EXTENDS> <IDENTIFIER> ]
+  <CLASS>
+  try {
+    {pos = jj_input_stream.bufpos;}
+    className = <IDENTIFIER>
+  } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
+    errorLevel   = ERROR;
+    throw e;
+  }
+  [
+    <EXTENDS>
+    try {
+      <IDENTIFIER>
+    } catch (ParseException e) {
+      errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
+      errorLevel   = ERROR;
+      throw e;
+    }
+  ]
   {
     if (currentSegment != null) {
       classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
@@ -832,7 +870,17 @@ void MethodDeclaration() :
   final PHPFunctionDeclaration functionDeclaration;
 }
 {
-  <FUNCTION> functionDeclaration = MethodDeclarator()
+  <FUNCTION>
+  try {
+    functionDeclaration = MethodDeclarator()
+  } catch (ParseException e) {
+    if (errorMessage != null) {
+      throw e;
+    }
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
+    errorLevel   = ERROR;
+    throw e;
+  }
   {
     if (currentSegment != null) {
       currentSegment.add(functionDeclaration);