some bugfixes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index 16847d8..14f1716 100644 (file)
@@ -788,8 +788,8 @@ void PhpBlock() :
   } catch (ParseException e) {
     errorMessage = "'?>' expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
 }
@@ -894,8 +894,8 @@ Token token;
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   ( ClassBodyDeclaration(classDeclaration) )*
@@ -905,8 +905,8 @@ Token token;
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
     return PHPParser.token.sourceEnd;
   }
@@ -943,7 +943,6 @@ FieldDeclaration FieldDeclaration() :
   token = <VAR> variableDeclaration = VariableDeclaratorNoSuffix()
   {
     arrayList.add(variableDeclaration);
-    outlineInfo.addVariable(variableDeclaration.name());
     pos = variableDeclaration.sourceEnd;
   }
   (
@@ -1088,8 +1087,8 @@ AbstractVariable VariableDeclaratorId() :
   } catch (ParseException e) {
     errorMessage = "'$' expected for variable identifier";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
 }
@@ -1125,7 +1124,10 @@ Variable Var() :
   }
 |
   token = <IDENTIFIER>
-  {return new Variable(token.image,token.sourceStart,token.sourceEnd);}
+  {
+   outlineInfo.addVariable("$" + token.image);
+   return new Variable(token.image,token.sourceStart,token.sourceEnd);
+  }
 }
 
 Expression VariableInitializer() :
@@ -1211,8 +1213,8 @@ MethodDeclaration MethodDeclaration() :
     if (errorMessage != null)  throw 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;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
   {currentSegment = functionDeclaration;}
@@ -1231,7 +1233,7 @@ MethodDeclaration MethodDeclarator(final int start) :
 {
   Token identifier = null;
   Token reference = null;
-  final Hashtable formalParameters = new Hashtable();
+  final ArrayList formalParameters = new ArrayList();
   String identifierChar = SYNTAX_ERROR_CHAR;
   int end = start;
 }
@@ -1280,7 +1282,7 @@ MethodDeclaration MethodDeclarator(final int start) :
  * FormalParameters follows method identifier.
  * (FormalParameter())
  */
-int FormalParameters(final Hashtable parameters) :
+int FormalParameters(final ArrayList parameters) :
 {
   VariableDeclaration var;
   final Token token;
@@ -1300,10 +1302,10 @@ int FormalParameters(final Hashtable parameters) :
   }
   [
     var = FormalParameter()
-    {parameters.put(var.name(),var);end = var.sourceEnd;}
+    {parameters.add(var);end = var.sourceEnd;}
     (
       <COMMA> var = FormalParameter()
-      {parameters.put(var.name(),var);end = var.sourceEnd;}
+      {parameters.add(var);end = var.sourceEnd;}
     )*
   ]
   try {
@@ -1331,6 +1333,7 @@ VariableDeclaration FormalParameter() :
 {
   [token = <BIT_AND>] variableDeclaration = VariableDeclaratorNoSuffix()
   {
+    outlineInfo.addVariable("$"+variableDeclaration.name());
     if (token != null) {
       variableDeclaration.setReference(true);
     }
@@ -2048,7 +2051,9 @@ final Token token,lparen;
     }
     processParseExceptionDebug(e);
   }
-  {return new FunctionCall(func,args,args[args.length-1].sourceEnd);}
+  {
+  int sourceEnd = (args == null && args.length != 0) ? lparen.sourceEnd+1 : args[args.length-1].sourceEnd;
+  return new FunctionCall(func,args,sourceEnd);}
 }
 
 /**
@@ -2248,8 +2253,8 @@ HTMLBlock htmlBlock() :
   } catch (ParseException e) {
     errorMessage = "unexpected end of file , '<?php' expected";
     errorLevel   = ERROR;
-    errorStart   = SimpleCharStream.getPosition();
-    errorEnd     = SimpleCharStream.getPosition();
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
   {
@@ -2844,7 +2849,6 @@ Expression SwitchLabel() :
   }
   try {
     token = <COLON>
-    {return expr;}
   } catch (ParseException e) {
     errorMessage = "':' expected after case expression";
     errorLevel   = ERROR;
@@ -2852,6 +2856,7 @@ Expression SwitchLabel() :
     errorEnd   = expr.sourceEnd+1;
     processParseExceptionDebug(e);
   }
+  {return expr;}
 |
   token = <_DEFAULT>
   try {
@@ -2965,8 +2970,8 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e
   } catch (ParseException e) {
     errorMessage = "'endif' expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
   try {
@@ -2974,8 +2979,8 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e
   } catch (ParseException e) {
     errorMessage = "';' expected after 'endif' keyword";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
     {
@@ -3015,8 +3020,8 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e
       }
       errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
       errorLevel   = ERROR;
-      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = SimpleCharStream.getPosition() + 1;
+      errorStart = e.currentToken.sourceStart;
+      errorEnd   = e.currentToken.sourceEnd;
       throw e;
     }
   ]
@@ -3116,8 +3121,8 @@ Statement WhileStatement0(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "'endwhile' expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
   try {
@@ -3129,8 +3134,8 @@ Statement WhileStatement0(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'endwhile' keyword";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
 |
@@ -3183,8 +3188,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "'(' expected after 'foreach' keyword";
     errorLevel   = ERROR;
-    errorStart = foreachToken.sourceEnd+1;
-    errorEnd   = foreachToken.sourceEnd+1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
     {pos = foreachToken.sourceEnd+1;}
   }
@@ -3194,8 +3199,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "variable expected";
     errorLevel   = ERROR;
-    errorStart = pos;
-    errorEnd   = pos;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   try {
@@ -3204,8 +3209,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "'as' expected";
     errorLevel   = ERROR;
-    errorStart = pos;
-    errorEnd   = pos;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   try {
@@ -3215,8 +3220,8 @@ ForeachStatement ForeachStatement() :
     if (errorMessage != null) throw e;
     errorMessage = "variable expected";
     errorLevel   = ERROR;
-    errorStart = pos;
-    errorEnd   = pos;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   try {
@@ -3225,8 +3230,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "')' expected after 'foreach' keyword";
     errorLevel   = ERROR;
-    errorStart = pos;
-    errorEnd   = pos;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   try {
@@ -3236,8 +3241,8 @@ ForeachStatement ForeachStatement() :
     if (errorMessage != null) throw e;
     errorMessage = "statement expected";
     errorLevel   = ERROR;
-    errorStart = pos;
-    errorEnd   = pos;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   {return new ForeachStatement(expression,