*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index 23b070d..0d76a4c 100644 (file)
@@ -83,12 +83,6 @@ public final class PHPParser extends PHPParserSuperclass {
   private static AstNode[] nodes;
   /** The cursor in expression stack. */
   private static int nodePtr;
-  private static VariableDeclaration[] variableDeclarationStack;
-  private static int variableDeclarationPtr;
-  private static Statement[] statementStack;
-  private static int statementPtr;
-  private static ElseIf[] elseIfStack;
-  private static int elseIfPtr;
 
   public final void setFileToParse(final IFile fileToParse) {
     this.fileToParse = fileToParse;
@@ -107,11 +101,7 @@ public final class PHPParser extends PHPParserSuperclass {
    */
   private static final void init() {
     nodes = new AstNode[AstStackIncrement];
-    statementStack = new Statement[AstStackIncrement];
-    elseIfStack = new ElseIf[AstStackIncrement];
     nodePtr = -1;
-    statementPtr = -1;
-    elseIfPtr = -1;
     htmlStart = 0;
   }
 
@@ -132,45 +122,6 @@ public final class PHPParser extends PHPParserSuperclass {
     }
   }
 
-  private static final void pushOnVariableDeclarationStack(VariableDeclaration var) {
-    try {
-      variableDeclarationStack[++variableDeclarationPtr] = var;
-    } catch (IndexOutOfBoundsException e) {
-      int oldStackLength = variableDeclarationStack.length;
-      VariableDeclaration[] oldStack = variableDeclarationStack;
-      variableDeclarationStack = new VariableDeclaration[oldStackLength + AstStackIncrement];
-      System.arraycopy(oldStack, 0, variableDeclarationStack, 0, oldStackLength);
-      variableDeclarationPtr = oldStackLength;
-      variableDeclarationStack[variableDeclarationPtr] = var;
-    }
-  }
-
-  private static final void pushOnStatementStack(Statement statement) {
-    try {
-      statementStack[++statementPtr] = statement;
-    } catch (IndexOutOfBoundsException e) {
-      int oldStackLength = statementStack.length;
-      Statement[] oldStack = statementStack;
-      statementStack = new Statement[oldStackLength + AstStackIncrement];
-      System.arraycopy(oldStack, 0, statementStack, 0, oldStackLength);
-      statementPtr = oldStackLength;
-      statementStack[statementPtr] = statement;
-    }
-  }
-
-  private static final void pushOnElseIfStack(ElseIf elseIf) {
-    try {
-      elseIfStack[++elseIfPtr] = elseIf;
-    } catch (IndexOutOfBoundsException e) {
-      int oldStackLength = elseIfStack.length;
-      ElseIf[] oldStack = elseIfStack;
-      elseIfStack = new ElseIf[oldStackLength + AstStackIncrement];
-      System.arraycopy(oldStack, 0, elseIfStack, 0, oldStackLength);
-      elseIfPtr = oldStackLength;
-      elseIfStack[elseIfPtr] = elseIf;
-    }
-  }
-
   public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
     PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
     final StringReader stream = new StringReader(strEval);
@@ -569,39 +520,38 @@ MORE :
 /* LITERALS */
 <PHPPARSING> TOKEN :
 {
-  < INTEGER_LITERAL:
+  <INTEGER_LITERAL:
         <DECIMAL_LITERAL> (["l","L"])?
       | <HEX_LITERAL> (["l","L"])?
       | <OCTAL_LITERAL> (["l","L"])?
   >
 |
-  < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
+  <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
 |
-  < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
+  <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
 |
-  < #OCTAL_LITERAL: "0" (["0"-"7"])* >
+  <#OCTAL_LITERAL: "0" (["0"-"7"])* >
 |
-  < FLOATING_POINT_LITERAL:
+  <FLOATING_POINT_LITERAL:
         (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
       | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
       | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
       | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
   >
 |
-  < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+  <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
 |
-  < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
-|    < STRING_1:
+  <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
+|    <STRING_1:
       "\""
       (
-          ~["\"","{","}"]
+          ~["\""]
         | "\\\""
         | "\\"
-        | "{" ~["\""] "}"
       )*
       "\""
     >
-|    < STRING_2:
+|    <STRING_2:
       "'"
       (
          ~["'"]
@@ -610,7 +560,7 @@ MORE :
 
       "'"
     >
-|   < STRING_3:
+|   <STRING_3:
       "`"
       (
         ~["`"]
@@ -903,7 +853,7 @@ FieldDeclaration FieldDeclaration() :
 
 VariableDeclaration VariableDeclarator() :
 {
-  final String varName, varValue;
+  final String varName;
   Expression initializer = null;
   final int pos = jj_input_stream.getPosition();
 }
@@ -1097,18 +1047,15 @@ ArrayVariableDeclaration[] ArrayInitializer() :
 MethodDeclaration MethodDeclaration() :
 {
   final MethodDeclaration functionDeclaration;
-  Token functionToken;
   final Block block;
 }
 {
-  functionToken = <FUNCTION>
+  <FUNCTION>
   try {
     functionDeclaration = MethodDeclarator()
     {outlineInfo.addVariable(new String(functionDeclaration.name));}
   } catch (ParseException e) {
-    if (errorMessage != null) {
-      throw e;
-    }
+    if (errorMessage != null)  throw e;
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
     errorLevel   = ERROR;
     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
@@ -1146,8 +1093,7 @@ MethodDeclaration MethodDeclarator() :
   final int pos = SimpleCharStream.getPosition();
 }
 {
-  [ reference = <BIT_AND> ]
-  identifier = <IDENTIFIER>
+  [reference = <BIT_AND>] identifier = <IDENTIFIER>
   formalParameters = FormalParameters()
   {return new MethodDeclaration(currentSegment,
                                  identifier.image.toCharArray(),
@@ -1163,8 +1109,6 @@ MethodDeclaration MethodDeclarator() :
  */
 Hashtable FormalParameters() :
 {
-  String expr;
-  final StringBuffer buff = new StringBuffer("(");
   VariableDeclaration var;
   final Hashtable parameters = new Hashtable();
 }
@@ -1504,9 +1448,7 @@ Expression MultiplicativeExpression() :
   try {
     expr = UnaryExpression()
   } catch (ParseException e) {
-    if (errorMessage != null) {
-      throw e;
-    }
+    if (errorMessage != null) throw e;
     errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
     errorLevel   = ERROR;
     errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
@@ -1535,8 +1477,7 @@ Expression UnaryExpression() :
   <BIT_AND> expr = UnaryExpressionNoPrefix()
   {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
 |
-  expr = AtUnaryExpression()
-  {return expr;}
+  expr = AtUnaryExpression() {return expr;}
 }
 
 Expression AtUnaryExpression() :
@@ -1647,7 +1588,6 @@ Expression PrimaryExpression() :
 {
   final Token identifier;
   Expression expr;
-  final StringBuffer buff = new StringBuffer();
   final int pos = SimpleCharStream.getPosition();
 }
 {
@@ -1788,7 +1728,7 @@ Literal Literal() :
 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
                                     return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
 | token = <STRING_LITERAL>         {pos = SimpleCharStream.getPosition();
-                                    return new StringLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
+                                    return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
 | <TRUE>                           {pos = SimpleCharStream.getPosition();
                                     return new TrueLiteral(pos-4,pos);}
 | <FALSE>                          {pos = SimpleCharStream.getPosition();
@@ -1799,7 +1739,7 @@ Literal Literal() :
 
 FunctionCall Arguments(Expression func) :
 {
-ArgumentDeclaration[] args = null;
+Expression[] args = null;
 }
 {
   <LPAREN> [ args = ArgumentList() ]
@@ -1815,18 +1755,22 @@ ArgumentDeclaration[] args = null;
   {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
 }
 
-ArgumentDeclaration[] ArgumentList() :
+/**
+ * An argument list is a list of arguments separated by comma :
+ * argumentDeclaration() (, argumentDeclaration)*
+ * @return an array of arguments
+ */
+Expression[] ArgumentList() :
 {
-ArgumentDeclaration arg;
+Expression arg;
 final ArrayList list = new ArrayList();
-ArgumentDeclaration argument;
 }
 {
-  arg = argumentDeclaration()
+  arg = Expression()
   {list.add(arg);}
   ( <COMMA>
       try {
-        arg = argumentDeclaration()
+        arg = Expression()
         {list.add(arg);}
       } catch (ParseException e) {
         errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
@@ -1837,45 +1781,11 @@ ArgumentDeclaration argument;
       }
    )*
    {
-   ArgumentDeclaration[] args = new ArgumentDeclaration[list.size()];
-   list.toArray(args);
-   return args;}
+   Expression[] arguments = new Expression[list.size()];
+   list.toArray(arguments);
+   return arguments;}
 }
 
-ArgumentDeclaration argumentDeclaration() :
-{
-  boolean reference = false;
-  String varName;
-  Expression initializer = null;
-  final int pos = SimpleCharStream.getPosition();
-}
-{
-  [<BIT_AND> {reference = true;}]
-  varName = VariableDeclaratorId()
- [
-    <ASSIGN>
-    try {
-      initializer = VariableInitializer()
-    } catch (ParseException e) {
-      errorMessage = "Literal expression expected in variable initializer";
-      errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
-      throw e;
-    }
-  ]
-  {
-  if (initializer == null) {
-    return new ArgumentDeclaration(varName.toCharArray(),
-                                   reference,
-                                   pos);
-  }
-  return new ArgumentDeclaration(varName.toCharArray(),
-                                 reference,
-                                 initializer,
-                                 pos);
-  }
-}
 /**
  * A Statement without break.
  */
@@ -1965,7 +1875,7 @@ HTMLBlock htmlBlock() :
     throw e;
   }
   {
-  nbNodes = nodePtr-startIndex;
+  nbNodes = nodePtr-startIndex - 1;
   blockNodes = new AstNode[nbNodes];
   System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
   return new HTMLBlock(nodes);}
@@ -1977,7 +1887,6 @@ HTMLBlock htmlBlock() :
 InclusionStatement IncludeStatement() :
 {
   final Expression expr;
-  final Token token;
   final int keyword;
   final int pos = jj_input_stream.getPosition();
   final InclusionStatement inclusionStatement;
@@ -2463,7 +2372,6 @@ AbstractCase switchLabel0() :
  */
 Expression SwitchLabel() :
 {
-  final Token token;
   final Expression expr;
 }
 {
@@ -2792,7 +2700,6 @@ ForeachStatement ForeachStatement() :
 {
   Statement statement;
   Expression expression;
-  final StringBuffer buff = new StringBuffer();
   final int pos = SimpleCharStream.getPosition();
   ArrayVariableDeclaration variable;
 }