*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index e69a928..abf9f51 100644 (file)
@@ -29,7 +29,6 @@ import org.eclipse.ui.texteditor.MarkerUtilities;
 import org.eclipse.jface.preference.IPreferenceStore;
 
 import java.util.Hashtable;
-import java.util.ArrayList;
 import java.util.Enumeration;
 import java.io.StringReader;
 import java.io.*;
@@ -51,7 +50,7 @@ public final class PHPParser extends PHPParserSuperclass {
   /** The file that is parsed. */
   private static IFile fileToParse;
 
-  /** The current segment */
+  /** The current segment. */
   private static PHPSegmentWithChildren currentSegment;
 
   private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
@@ -59,6 +58,7 @@ public final class PHPParser extends PHPParserSuperclass {
   PHPOutlineInfo outlineInfo;
 
   private static PHPFunctionDeclaration currentFunction;
+  private static boolean assigning;
 
   /** The error level of the current ParseException. */
   private static int errorLevel = ERROR;
@@ -68,13 +68,13 @@ public final class PHPParser extends PHPParserSuperclass {
   private static int errorStart = -1;
   private static int errorEnd = -1;
 
-  public PHPParser() {
-  }
-
   public final void setFileToParse(final IFile fileToParse) {
     this.fileToParse = fileToParse;
   }
 
+  public PHPParser() {
+  }
+
   public PHPParser(final IFile fileToParse) {
     this(new StringReader(""));
     this.fileToParse = fileToParse;
@@ -778,7 +778,7 @@ PHPVarDeclaration VariableDeclarator() :
     <ASSIGN>
     try {
       varValue = VariableInitializer()
-      {return new PHPVarDeclaration(currentSegment,varName.substring(1),pos,varValue);}
+      {return new PHPVarDeclaration(currentSegment,varName,pos,varValue);}
     } catch (ParseException e) {
       errorMessage = "Literal expression expected in variable initializer";
       errorLevel   = ERROR;
@@ -820,20 +820,20 @@ String Variable():
 {
   token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
   {
-    if (expr == null) {
+    if (expr == null && !assigning) {
       if (currentFunction != null) {
         PHPVarDeclaration var = currentFunction.getParameter(token.image.substring(1));
         if (var != null) {
           var.getVariable().setUsed(true);
         }
       }
-      return token.image;
+      return token.image.substring(1);
     }
     return token + "{" + expr + "}";
   }
 |
   <DOLLAR> expr = VariableName()
-  {return "$" + expr;}
+  {return expr;}
 }
 
 String VariableName():
@@ -1075,7 +1075,7 @@ PHPVarDeclaration FormalParameter() :
   [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
   {
     if (token != null) {
-      variableDeclaration.getVariable().setPrefix("@");
+      variableDeclaration.getVariable().setReference(true);
     }
     return variableDeclaration;
   }
@@ -1125,12 +1125,29 @@ String Expression() :
   expr = ListExpression()
   {return expr;}
 |
+  LOOKAHEAD(varAssignation())
+  expr = varAssignation()
+  {return expr;}
+|
   expr = ConditionalExpression()
-  [
-    assignOperator = AssignmentOperator()
+  {return expr;}
+}
+
+/**
+ * A Variable assignation.
+ * varName (an assign operator) any expression
+ */
+String varAssignation() :
+{
+  String varName,assignOperator,expr2;
+  PHPVarDeclaration variable;
+  final int pos = SimpleCharStream.getPosition();
+}
+{
+  varName = VariableDeclaratorId()
+  assignOperator = AssignmentOperator()
     try {
       expr2 = Expression()
-      {return expr + assignOperator + expr2;}
     } catch (ParseException e) {
       if (errorMessage != null) {
         throw e;
@@ -1141,8 +1158,7 @@ String Expression() :
       errorEnd   = jj_input_stream.getPosition() + 1;
       throw e;
     }
-  ]
-  {return expr;}
+    {return varName + assignOperator + expr2;}
 }
 
 String AssignmentOperator() :