*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index d3b3e59..95618cb 100644 (file)
@@ -569,29 +569,29 @@ 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:
       "\""
       (
           ~["\"","{","}"]
@@ -601,7 +601,7 @@ MORE :
       )*
       "\""
     >
-|    < STRING_2:
+|    <STRING_2:
       "'"
       (
          ~["'"]
@@ -610,7 +610,7 @@ MORE :
 
       "'"
     >
-|   < STRING_3:
+|   <STRING_3:
       "`"
       (
         ~["`"]
@@ -870,21 +870,17 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
 FieldDeclaration FieldDeclaration() :
 {
   VariableDeclaration variableDeclaration;
-  variableDeclarationPtr = 0;
-  variableDeclarationStack = new VariableDeclaration[AstStackIncrement];
   VariableDeclaration[] list;
+  final ArrayList arrayList = new ArrayList();
   final int pos = SimpleCharStream.getPosition();
 }
 {
   <VAR> variableDeclaration = VariableDeclarator()
-  {
-    pushOnVariableDeclarationStack(variableDeclaration);
-    outlineInfo.addVariable(new String(variableDeclaration.name));
-    currentSegment.add(variableDeclaration);
-  }
-  ( <COMMA>
-      variableDeclaration = VariableDeclarator()
-      {pushOnVariableDeclarationStack(variableDeclaration);
+  {arrayList.add(variableDeclaration);
+   outlineInfo.addVariable(new String(variableDeclaration.name));
+   currentSegment.add(variableDeclaration);}
+  ( <COMMA> variableDeclaration = VariableDeclarator()
+      {arrayList.add(variableDeclaration);
        outlineInfo.addVariable(new String(variableDeclaration.name));
        currentSegment.add(variableDeclaration);}
   )*
@@ -898,8 +894,8 @@ FieldDeclaration FieldDeclaration() :
     throw e;
   }
 
-  {list = new VariableDeclaration[variableDeclarationPtr];
-   System.arraycopy(variableDeclarationStack,0,list,0,variableDeclarationPtr);
+  {list = new VariableDeclaration[arrayList.size()];
+   arrayList.toArray(list);
    return new FieldDeclaration(list,
                                pos,
                                SimpleCharStream.getPosition());}
@@ -1064,12 +1060,14 @@ Expression VariableInitializer() :
 
 ArrayVariableDeclaration ArrayVariable() :
 {
-Expression expr;
-Expression expr2 = null;
+Expression expr,expr2;
 }
 {
-  expr = Expression() [<ARRAYASSIGN> expr2 = Expression()]
+  expr = Expression()
+  [<ARRAYASSIGN> expr2 = Expression()
   {return new ArrayVariableDeclaration(expr,expr2);}
+  ]
+  {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
 }
 
 ArrayVariableDeclaration[] ArrayInitializer() :
@@ -1108,9 +1106,7 @@ MethodDeclaration MethodDeclaration() :
     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;
@@ -1148,8 +1144,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(),
@@ -1506,9 +1501,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;
@@ -1537,8 +1530,7 @@ Expression UnaryExpression() :
   <BIT_AND> expr = UnaryExpressionNoPrefix()
   {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
 |
-  expr = AtUnaryExpression()
-  {return expr;}
+  expr = AtUnaryExpression() {return expr;}
 }
 
 Expression AtUnaryExpression() :
@@ -1790,7 +1782,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();
@@ -1801,7 +1793,7 @@ Literal Literal() :
 
 FunctionCall Arguments(Expression func) :
 {
-ArgumentDeclaration[] args = null;
+Expression[] args = null;
 }
 {
   <LPAREN> [ args = ArgumentList() ]
@@ -1817,18 +1809,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";
@@ -1839,45 +1835,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.
  */
@@ -1967,7 +1929,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);}
@@ -2204,10 +2166,8 @@ LabeledStatement LabeledStatement() :
 Block Block() :
 {
   final int pos = SimpleCharStream.getPosition();
-  Statement[] statements;
+  final ArrayList list = new ArrayList();
   Statement statement;
-  final int startingPtr = statementPtr;
-  final int length;
 }
 {
   try {
@@ -2219,8 +2179,8 @@ Block Block() :
     errorEnd   = jj_input_stream.getPosition() + 1;
     throw e;
   }
-  ( statement = BlockStatement() {pushOnStatementStack(statement);}
-  | statement = htmlBlock()      {pushOnStatementStack(statement);})*
+  ( statement = BlockStatement() {list.add(statement);}
+  | statement = htmlBlock()      {list.add(statement);})*
   try {
     <RBRACE>
   } catch (ParseException e) {
@@ -2231,10 +2191,8 @@ Block Block() :
     throw e;
   }
   {
-  length = statementPtr-startingPtr+1;
-  statements = new Statement[length];
-  System.arraycopy(variableDeclarationStack,startingPtr+1,statements,0,length);
-  statementPtr = startingPtr;
+  Statement[] statements = new Statement[list.size()];
+  list.toArray(statements);
   return new Block(statements,pos,SimpleCharStream.getPosition());}
 }
 
@@ -2310,19 +2268,23 @@ EmptyStatement EmptyStatement() :
 
 Statement StatementExpression() :
 {
-  Expression expr;
+  Expression expr,expr2;
+  int operator;
 }
 {
   expr = PreIncDecExpression() {return expr;}
 |
   expr = PrimaryExpression()
-  [ <INCR> {expr = new PostfixedUnaryExpression(expr,
+  [ <INCR> {return new PostfixedUnaryExpression(expr,
                                                 OperatorIds.PLUS_PLUS,
                                                 SimpleCharStream.getPosition());}
-  | <DECR> {expr = new PostfixedUnaryExpression(expr,
+  | <DECR> {return new PostfixedUnaryExpression(expr,
                                                 OperatorIds.MINUS_MINUS,
                                                 SimpleCharStream.getPosition());}
-  | AssignmentOperator() Expression() ]
+  | operator = AssignmentOperator() expr2 = Expression()
+    {return new BinaryExpression(expr,expr2,operator);}
+  ]
+  {return expr;}
 }
 
 SwitchStatement SwitchStatement() :