X-Git-Url: http://secure.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.java b/net.sourceforge.phpeclipse/src/test/PHPParser.java
index 261d359..8b59f42 100644
--- a/net.sourceforge.phpeclipse/src/test/PHPParser.java
+++ b/net.sourceforge.phpeclipse/src/test/PHPParser.java
@@ -8,7 +8,6 @@ import org.eclipse.ui.texteditor.MarkerUtilities;
 import org.eclipse.jface.preference.IPreferenceStore;
 
 import java.util.Hashtable;
-import java.util.Enumeration;
 import java.util.ArrayList;
 import java.io.StringReader;
 import java.io.*;
@@ -39,8 +38,6 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
   private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
   static PHPOutlineInfo outlineInfo;
 
-  private static boolean assigning;
-
   /** 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 */
@@ -49,6 +46,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
   private static int errorStart = -1;
   private static int errorEnd = -1;
   private static PHPDocument phpDocument;
+
+  private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
   /**
    * The point where html starts.
    * It will be used by the token manager to create HTMLCode objects
@@ -101,7 +100,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
   }
 
   public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
-    currentSegment = new PHPDocument(parent);
+    phpDocument = new PHPDocument(parent,"_root".toCharArray());
+    currentSegment = phpDocument;
     outlineInfo = new PHPOutlineInfo(parent, currentSegment);
     final StringReader stream = new StringReader(s);
     if (jj_input_stream == null) {
@@ -111,9 +111,11 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
     init();
     try {
       parse();
-      phpDocument = new PHPDocument(null);
       phpDocument.nodes = new AstNode[nodes.length];
       System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
+      if (PHPeclipsePlugin.DEBUG) {
+        PHPeclipsePlugin.log(1,phpDocument.toString());
+      }
     } catch (ParseException e) {
       processParseException(e);
     }
@@ -145,8 +147,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
       if (errorStart == -1) {
         setMarker(fileToParse,
                   errorMessage,
-                  jj_input_stream.tokenBegin,
-                  jj_input_stream.tokenBegin + e.currentToken.image.length(),
+                  SimpleCharStream.tokenBegin,
+                  SimpleCharStream.tokenBegin + e.currentToken.image.length(),
                   errorLevel,
                   "Line " + e.currentToken.beginLine);
       } else {
@@ -164,31 +166,6 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
     }
   }
 
-  /**
-   * Create markers according to the external parser output
-   */
-  private static void createMarkers(final String output, final IFile file) throws CoreException {
-    // delete all markers
-    file.deleteMarkers(IMarker.PROBLEM, false, 0);
-
-    int indx = 0;
-    int brIndx;
-    boolean flag = true;
-    while ((brIndx = output.indexOf("
", indx)) != -1) {
-      // newer php error output (tested with 4.2.3)
-      scanLine(output, file, indx, brIndx);
-      indx = brIndx + 6;
-      flag = false;
-    }
-    if (flag) {
-      while ((brIndx = output.indexOf("
", indx)) != -1) {
-        // older php error output (tested with 4.2.3)
-        scanLine(output, file, indx, brIndx);
-        indx = brIndx + 4;
-      }
-    }
-  }
-
   private static void scanLine(final String output,
                                final IFile file,
                                final int indx,
@@ -278,6 +255,25 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
     pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
   }
 
+  /**
+   * Create a new task.
+   */
+  public static final void createNewTask() {
+    final int currentPosition = SimpleCharStream.getPosition();
+    final String  todo = SimpleCharStream.currentBuffer.substring(currentPosition+1,
+                                                                  SimpleCharStream.currentBuffer.indexOf("\n",
+                                                                                                         currentPosition)-1);
+    try {
+      setMarker(fileToParse,
+                "todo : " + todo,
+                SimpleCharStream.getBeginLine(),
+                TASK,
+                "Line "+SimpleCharStream.getBeginLine());
+    } catch (CoreException e) {
+      PHPeclipsePlugin.log(e);
+    }
+  }
+
   private static final void parse() throws ParseException {
           phpFile();
   }
@@ -340,7 +336,7 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
         }
         PhpBlock();
       }
-      jj_consume_token(0);
+     PHPParser.createNewHTMLCode();
     } catch (TokenMgrError e) {
     PHPeclipsePlugin.log(e);
     errorStart   = SimpleCharStream.getPosition();
@@ -358,9 +354,11 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
  */
   static final public void PhpBlock() throws ParseException {
   final int start = SimpleCharStream.getPosition();
+  final PHPEchoBlock phpEchoBlock;
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     case PHPECHOSTART:
-      phpEchoBlock();
+      phpEchoBlock = phpEchoBlock();
+   pushOnAstNodes(phpEchoBlock);
       break;
     case PHPSTARTSHORT:
     case PHPSTARTLONG:
@@ -444,7 +442,7 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
     errorLevel   = ERROR;
     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd   = SimpleCharStream.getPosition() + 1;
-    {if (true) throw e;}
+    processParseException(e);
       }
       break;
     default:
@@ -535,43 +533,48 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
   final Token className;
   Token superclassName = null;
   final int pos;
+  char[] classNameImage = SYNTAX_ERROR_CHAR;
+  char[] superclassNameImage = null;
     jj_consume_token(CLASS);
+   pos = SimpleCharStream.getPosition();
     try {
-     pos = SimpleCharStream.getPosition();
       className = jj_consume_token(IDENTIFIER);
+     classNameImage = className.image.toCharArray();
     } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
     errorLevel   = ERROR;
     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd     = SimpleCharStream.getPosition() + 1;
-    {if (true) throw e;}
+    processParseException(e);
     }
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     case EXTENDS:
       jj_consume_token(EXTENDS);
       try {
         superclassName = jj_consume_token(IDENTIFIER);
+       superclassNameImage = superclassName.image.toCharArray();
       } catch (ParseException e) {
       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
       errorLevel   = ERROR;
       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
       errorEnd   = SimpleCharStream.getPosition() + 1;
-      {if (true) throw e;}
+      processParseException(e);
+      superclassNameImage = SYNTAX_ERROR_CHAR;
       }
       break;
     default:
       jj_la1[6] = jj_gen;
       ;
     }
-    if (superclassName == null) {
+    if (superclassNameImage == null) {
       classDeclaration = new ClassDeclaration(currentSegment,
-                                              className.image.toCharArray(),
+                                              classNameImage,
                                               pos,
                                               0);
     } else {
       classDeclaration = new ClassDeclaration(currentSegment,
-                                              className.image.toCharArray(),
-                                              superclassName.image.toCharArray(),
+                                              classNameImage,
+                                              superclassNameImage,
                                               pos,
                                               0);
     }
@@ -628,12 +631,11 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     case FUNCTION:
       method = MethodDeclaration();
-                                method.setParent(classDeclaration);
                                 classDeclaration.addMethod(method);
       break;
     case VAR:
       field = FieldDeclaration();
-                                classDeclaration.addVariable(field);
+                                classDeclaration.addField(field);
       break;
     default:
       jj_la1[8] = jj_gen;
@@ -654,7 +656,6 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
     variableDeclaration = VariableDeclarator();
    arrayList.add(variableDeclaration);
    outlineInfo.addVariable(new String(variableDeclaration.name));
-   currentSegment.add(variableDeclaration);
     label_4:
     while (true) {
       switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
@@ -669,7 +670,6 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
       variableDeclaration = VariableDeclarator();
        arrayList.add(variableDeclaration);
        outlineInfo.addVariable(new String(variableDeclaration.name));
-       currentSegment.add(variableDeclaration);
     }
     try {
       jj_consume_token(SEMICOLON);
@@ -678,7 +678,7 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
     errorLevel   = ERROR;
     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd     = SimpleCharStream.getPosition() + 1;
-    {if (true) throw e;}
+    processParseException(e);
     }
    list = new VariableDeclaration[arrayList.size()];
    arrayList.toArray(list);
@@ -730,13 +730,12 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
  */
   static final public String VariableDeclaratorId() throws ParseException {
   String expr;
-  Expression expression;
+  Expression expression = null;
   final StringBuffer buff = new StringBuffer();
   final int pos = SimpleCharStream.getPosition();
   ConstantIdentifier ex;
     try {
       expr = Variable();
-                         buff.append(expr);
       label_5:
       while (true) {
         if (jj_2_1(2)) {
@@ -748,9 +747,11 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
                                    pos,
                                    SimpleCharStream.getPosition());
         expression = VariableSuffix(ex);
-       buff.append(expression.toStringExpression());
       }
-     {if (true) return buff.toString();}
+     if (expression == null) {
+       {if (true) return expr;}
+     }
+     {if (true) return expression.toStringExpression();}
     } catch (ParseException e) {
     errorMessage = "'$' expected for variable identifier";
     errorLevel   = ERROR;
@@ -761,6 +762,10 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
     throw new Error("Missing return statement in function");
   }
 
+/**
+ * Return a variablename without the $.
+ * @return a variable name
+ */
   static final public String Variable() throws ParseException {
   final StringBuffer buff;
   Expression expression = null;
@@ -779,13 +784,13 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
         jj_la1[11] = jj_gen;
         ;
       }
-    if (expression == null && !assigning) {
+    if (expression == null) {
       {if (true) return token.image.substring(1);}
     }
     buff = new StringBuffer(token.image);
-    buff.append('{');
+    buff.append("{");
     buff.append(expression.toStringExpression());
-    buff.append('}');
+    buff.append("}");
     {if (true) return buff.toString();}
       break;
     case DOLLAR:
@@ -801,6 +806,10 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
     throw new Error("Missing return statement in function");
   }
 
+/**
+ * A Variable name (without the $)
+ * @return a variable name String
+ */
   static final public String VariableName() throws ParseException {
   final StringBuffer buff;
   String expr = null;
@@ -832,15 +841,15 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon
       {if (true) return token.image;}
     }
     buff = new StringBuffer(token.image);
-    buff.append('{');
+    buff.append("{");
     buff.append(expression.toStringExpression());
-    buff.append('}');
+    buff.append("}");
     {if (true) return buff.toString();}
       break;
     case DOLLAR:
       jj_consume_token(DOLLAR);
       expr = VariableName();
-    buff = new StringBuffer('$');
+    buff = new StringBuffer("$");
     buff.append(expr);
     {if (true) return buff.toString();}
       break;
@@ -1010,6 +1019,7 @@ Expression expr,expr2;
   static final public MethodDeclaration MethodDeclaration() throws ParseException {
   final MethodDeclaration functionDeclaration;
   final Block block;
+  final OutlineableWithChildren seg = currentSegment;
     jj_consume_token(FUNCTION);
     try {
       functionDeclaration = MethodDeclarator();
@@ -1022,16 +1032,11 @@ Expression expr,expr2;
     errorEnd   = SimpleCharStream.getPosition() + 1;
     {if (true) throw e;}
     }
-    if (currentSegment != null) {
-      currentSegment.add(functionDeclaration);
-      currentSegment = functionDeclaration;
-    }
+   currentSegment = functionDeclaration;
     block = Block();
-    functionDeclaration.statements = block.statements;
-    if (currentSegment != null) {
-      currentSegment = (OutlineableWithChildren) currentSegment.getParent();
-    }
-    {if (true) return functionDeclaration;}
+   functionDeclaration.statements = block.statements;
+   currentSegment = seg;
+   {if (true) return functionDeclaration;}
     throw new Error("Missing return statement in function");
   }
 
@@ -1045,6 +1050,7 @@ Expression expr,expr2;
   Token reference = null;
   final Hashtable formalParameters;
   final int pos = SimpleCharStream.getPosition();
+  char[] identifierChar = SYNTAX_ERROR_CHAR;
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     case BIT_AND:
       reference = jj_consume_token(BIT_AND);
@@ -1053,14 +1059,23 @@ Expression expr,expr2;
       jj_la1[21] = jj_gen;
       ;
     }
-    identifier = jj_consume_token(IDENTIFIER);
+    try {
+      identifier = jj_consume_token(IDENTIFIER);
+     identifierChar = identifier.image.toCharArray();
+    } catch (ParseException e) {
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
+    errorLevel   = ERROR;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
+    }
     formalParameters = FormalParameters();
    {if (true) return new MethodDeclaration(currentSegment,
-                                 identifier.image.toCharArray(),
-                                 formalParameters,
-                                 reference != null,
-                                 pos,
-                                 SimpleCharStream.getPosition());}
+                                identifierChar,
+                                formalParameters,
+                                reference != null,
+                                pos,
+                                SimpleCharStream.getPosition());}
     throw new Error("Missing return statement in function");
   }
 
@@ -1078,7 +1093,7 @@ Expression expr,expr2;
     errorLevel   = ERROR;
     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd   = SimpleCharStream.getPosition() + 1;
-    {if (true) throw e;}
+    processParseException(e);
     }
     switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
     case DOLLAR:
@@ -1112,7 +1127,7 @@ Expression expr,expr2;
     errorLevel   = ERROR;
     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd   = SimpleCharStream.getPosition() + 1;
-    {if (true) throw e;}
+    processParseException(e);
     }
   {if (true) return parameters;}
     throw new Error("Missing return statement in function");
@@ -1147,56 +1162,47 @@ Expression expr,expr2;
     case STRING:
       jj_consume_token(STRING);
                         pos = SimpleCharStream.getPosition();
-                        {if (true) return new ConstantIdentifier(Types.STRING,
-                                                      pos,pos-6);}
+                        {if (true) return new ConstantIdentifier(Types.STRING,pos,pos-6);}
       break;
     case BOOL:
       jj_consume_token(BOOL);
                         pos = SimpleCharStream.getPosition();
-                        {if (true) return new ConstantIdentifier(Types.BOOL,
-                                                      pos,pos-4);}
+                        {if (true) return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
       break;
     case BOOLEAN:
       jj_consume_token(BOOLEAN);
                         pos = SimpleCharStream.getPosition();
-                        {if (true) return new ConstantIdentifier(Types.BOOLEAN,
-                                                      pos,pos-7);}
+                        {if (true) return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
       break;
     case REAL:
       jj_consume_token(REAL);
                         pos = SimpleCharStream.getPosition();
-                        {if (true) return new ConstantIdentifier(Types.REAL,
-                                                      pos,pos-4);}
+                        {if (true) return new ConstantIdentifier(Types.REAL,pos,pos-4);}
       break;
     case DOUBLE:
       jj_consume_token(DOUBLE);
                         pos = SimpleCharStream.getPosition();
-                        {if (true) return new ConstantIdentifier(Types.DOUBLE,
-                                                      pos,pos-5);}
+                        {if (true) return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
       break;
     case FLOAT:
       jj_consume_token(FLOAT);
                         pos = SimpleCharStream.getPosition();
-                        {if (true) return new ConstantIdentifier(Types.FLOAT,
-                                                      pos,pos-5);}
+                        {if (true) return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
       break;
     case INT:
       jj_consume_token(INT);
                         pos = SimpleCharStream.getPosition();
-                        {if (true) return new ConstantIdentifier(Types.INT,
-                                                      pos,pos-3);}
+                        {if (true) return new ConstantIdentifier(Types.INT,pos,pos-3);}
       break;
     case INTEGER:
       jj_consume_token(INTEGER);
                         pos = SimpleCharStream.getPosition();
-                        {if (true) return new ConstantIdentifier(Types.INTEGER,
-                                                      pos,pos-7);}
+                        {if (true) return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
       break;
     case OBJECT:
       jj_consume_token(OBJECT);
                         pos = SimpleCharStream.getPosition();
-                        {if (true) return new ConstantIdentifier(Types.OBJECT,
-                                                      pos,pos-6);}
+                        {if (true) return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
       break;
     default:
       jj_la1[25] = jj_gen;
@@ -1262,13 +1268,13 @@ Expression expr,expr2;
  */
   static final public VarAssignation varAssignation() throws ParseException {
   String varName;
-  final Expression expression;
+  final Expression initializer;
   final int assignOperator;
   final int pos = SimpleCharStream.getPosition();
     varName = VariableDeclaratorId();
     assignOperator = AssignmentOperator();
     try {
-      expression = Expression();
+      initializer = Expression();
     } catch (ParseException e) {
       if (errorMessage != null) {
         {if (true) throw e;}
@@ -1280,7 +1286,7 @@ Expression expr,expr2;
       {if (true) throw e;}
     }
      {if (true) return new VarAssignation(varName.toCharArray(),
-                               expression,
+                               initializer,
                                assignOperator,
                                pos,
                                SimpleCharStream.getPosition());}
@@ -2474,7 +2480,7 @@ final ArrayList list = new ArrayList();
       try {
         jj_consume_token(SEMICOLON);
       } catch (ParseException e) {
-    if (e.currentToken.next.kind != 4) {
+    if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
       errorLevel   = ERROR;
       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
@@ -2680,16 +2686,17 @@ final ArrayList list = new ArrayList();
         throw new ParseException();
       }
     } catch (ParseException e) {
-    errorMessage = "End of file unexpected, '= 0) {
@@ -6817,7 +6837,7 @@ final int startBlock, endBlock;
         }
       }
     }
-    for (int i = 0; i < 141; i++) {
+    for (int i = 0; i < 142; i++) {
       if (la1tokens[i]) {
         jj_expentry = new int[1];
         jj_expentry[0] = i;