Added "Task Tags" functionality (TODO,...)
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / parser / Parser.java
index 8cf9f7e..238bdbe 100644 (file)
  **********************************************************************/
 package net.sourceforge.phpdt.internal.compiler.parser;
 import java.util.ArrayList;
+
 import net.sourceforge.phpdt.core.compiler.CharOperation;
 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
+import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
 import net.sourceforge.phpdt.internal.compiler.lookup.CompilerModifiers;
 import net.sourceforge.phpdt.internal.compiler.lookup.TypeConstants;
 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
+import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
 import net.sourceforge.phpeclipse.internal.compiler.ast.AbstractMethodDeclaration;
 import net.sourceforge.phpeclipse.internal.compiler.ast.AstNode;
 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
@@ -24,6 +27,8 @@ import net.sourceforge.phpeclipse.internal.compiler.ast.FieldDeclaration;
 import net.sourceforge.phpeclipse.internal.compiler.ast.MethodDeclaration;
 import net.sourceforge.phpeclipse.internal.compiler.ast.SingleTypeReference;
 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
+import net.sourceforge.phpdt.internal.compiler.util.Util;
+
 import org.eclipse.core.resources.IFile;
 public class Parser //extends PHPParserSuperclass
     implements ITerminalSymbols, CompilerModifiers, ParserBasicInformation {
@@ -65,7 +70,9 @@ public class Parser //extends PHPParserSuperclass
   //private boolean phpMode;
   protected int modifiers;
   protected int modifiersSourceStart;
-  protected Parser() {
+  protected Parser(ProblemReporter problemReporter) {
+    this.problemReporter = problemReporter;
+    this.options = problemReporter.options;
     this.currentPHPString = 0;
     //         PHPParserSuperclass.fileToParse = fileToParse;
     this.phpList = null;
@@ -115,7 +122,14 @@ public class Parser //extends PHPParserSuperclass
     this.initializeScanner();
   }
   public void initializeScanner() {
-    this.scanner = new Scanner(false, false, false, false);
+       this.scanner = new Scanner(
+               false /*comment*/, 
+               false /*whitespace*/, 
+               this.options.getSeverity(CompilerOptions.NonExternalizedString) != ProblemSeverities.Ignore /*nls*/, 
+               false, 
+               false, 
+               this.options.taskTags/*taskTags*/,
+               this.options.taskPriorites/*taskPriorities*/);
   }
   /**
    * Create marker for the parse error
@@ -274,7 +288,7 @@ public class Parser //extends PHPParserSuperclass
           }
           throwSyntaxError("End-of-file not reached.");
         }
-        return;
+        break;
       } catch (SyntaxError sytaxErr1) {
         // setMarker(sytaxErr1.getMessage(), sytaxErr1.getLine(),
         // ERROR);
@@ -293,7 +307,7 @@ public class Parser //extends PHPParserSuperclass
             getNextToken();
           }
           if (token == TokenNameEOF || token == TokenNameERROR) {
-            return;
+            break;
           }
         } catch (SyntaxError sytaxErr2) {
           //    setMarker(sytaxErr2.getMessage(), sytaxErr2.getLine(),
@@ -301,10 +315,48 @@ public class Parser //extends PHPParserSuperclass
           //          setMarker(sytaxErr2.getMessage(),
           // scanner.getCurrentTokenStartPosition(),
           // scanner.getCurrentTokenEndPosition(), ERROR);
-          return;
+          break;
         }
       }
     } while (true);
+    
+    endParse(0);
+  }
+    
+  protected CompilationUnitDeclaration endParse(int act) {
+
+    this.lastAct = act;
+
+    if (currentElement != null) {
+      currentElement.topElement().updateParseTree();
+      if (VERBOSE_RECOVERY) {
+        System.out.print(Util.bind("parser.syntaxRecovery")); //$NON-NLS-1$
+        System.out.println("--------------------------"); //$NON-NLS-1$
+        System.out.println(compilationUnit);
+        System.out.println("----------------------------------"); //$NON-NLS-1$
+      }
+    } else {
+      if (diet & VERBOSE_RECOVERY) {
+        System.out.print(Util.bind("parser.regularParse")); //$NON-NLS-1$
+        System.out.println("--------------------------"); //$NON-NLS-1$
+        System.out.println(compilationUnit);
+        System.out.println("----------------------------------"); //$NON-NLS-1$
+      }
+    }
+    if (scanner.recordLineSeparator) {
+      compilationUnit.compilationResult.lineSeparatorPositions = scanner.getLineEnds();
+    }
+    if (scanner.taskTags != null) {
+      for (int i = 0; i < scanner.foundTaskCount; i++) {
+        problemReporter().task(
+          new String(scanner.foundTaskTags[i]),
+          new String(scanner.foundTaskMessages[i]),
+          scanner.foundTaskPriorities[i] == null ? null : new String(scanner.foundTaskPriorities[i]),
+          scanner.foundTaskPositions[i][0],
+          scanner.foundTaskPositions[i][1]);
+      }
+    }
+    return compilationUnit;
   }
   //  public PHPOutlineInfo parseInfo(Object parent, String s) {
   //    PHPOutlineInfo outlineInfo = new PHPOutlineInfo(parent);
@@ -3418,6 +3470,7 @@ public class Parser //extends PHPParserSuperclass
                                                       */
   protected ReferenceContext referenceContext;
   protected ProblemReporter problemReporter;
+  protected CompilerOptions options;
   //  protected CompilationResult compilationResult;
   /**
    * Returns this parser's problem reporter initialized with its reference