Some minor changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index 35e1229..9d2846a 100644 (file)
@@ -232,14 +232,14 @@ public final class PHPParser extends PHPParserSuperclass {
                   e.currentToken.sourceStart,
                   e.currentToken.sourceEnd,
                   errorLevel,
-                  "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+":"+e.currentToken.sourceEnd);
+                  "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+':'+e.currentToken.sourceEnd);
       } else {
         setMarker(fileToParse,
                   errorMessage,
                   errorStart,
                   errorEnd,
                   errorLevel,
-                  "Line " + e.currentToken.beginLine+", "+errorStart+":"+errorEnd);
+                  "Line " + e.currentToken.beginLine+", "+errorStart+':'+errorEnd);
         errorStart = -1;
         errorEnd = -1;
       }
@@ -335,9 +335,8 @@ public final class PHPParser extends PHPParserSuperclass {
           currentPosition > SimpleCharStream.currentBuffer.length()) {
       return;
     }
-    final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,
-                                                                  currentPosition).toCharArray();
-    pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
+    final String html = SimpleCharStream.currentBuffer.substring(htmlStart, currentPosition);
+    pushOnAstNodes(new HTMLCode(html, htmlStart,currentPosition));
   }
 
   /** Create a new task. */
@@ -788,8 +787,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 +893,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 +904,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 +942,6 @@ FieldDeclaration FieldDeclaration() :
   token = <VAR> variableDeclaration = VariableDeclaratorNoSuffix()
   {
     arrayList.add(variableDeclaration);
-    outlineInfo.addVariable(variableDeclaration.name());
     pos = variableDeclaration.sourceEnd;
   }
   (
@@ -1088,8 +1086,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 +1123,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 +1212,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 +1232,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 +1281,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 +1301,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 +1332,7 @@ VariableDeclaration FormalParameter() :
 {
   [token = <BIT_AND>] variableDeclaration = VariableDeclaratorNoSuffix()
   {
+    outlineInfo.addVariable('$'+variableDeclaration.name());
     if (token != null) {
       variableDeclaration.setReference(true);
     }
@@ -1640,7 +1642,7 @@ Expression MultiplicativeExpression() :
     expr = UnaryExpression()
   } catch (ParseException e) {
     if (errorMessage != null) throw e;
-    errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
+    errorMessage = "unexpected token '"+e.currentToken.next.image+'\'';
     errorLevel   = ERROR;
     errorStart = PHPParser.token.sourceStart;
     errorEnd   = PHPParser.token.sourceEnd;
@@ -2250,8 +2252,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;
   }
   {
@@ -2800,6 +2802,7 @@ AbstractCase switchLabel0() :
   Statement statement;
   final ArrayList stmts = new ArrayList();
   final Token token = PHPParser.token;
+  final int start = PHPParser.token.next.sourceStart;
 }
 {
   expr = SwitchLabel()
@@ -2812,7 +2815,8 @@ AbstractCase switchLabel0() :
     final Statement[] stmtsArray = new Statement[listSize];
     stmts.toArray(stmtsArray);
     if (expr == null) {//it's a default
-      return new DefaultCase(stmtsArray,token.sourceStart,stmtsArray[listSize-1].sourceEnd);
+      final int end = PHPParser.token.next.sourceStart;
+      return new DefaultCase(stmtsArray,start,end);
     }
     if (listSize != 0) {
       return new Case(expr,stmtsArray,expr.sourceStart,stmtsArray[listSize-1].sourceEnd);
@@ -2967,8 +2971,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 {
@@ -2976,8 +2980,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;
   }
     {
@@ -3017,8 +3021,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;
     }
   ]
@@ -3118,8 +3122,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 {
@@ -3131,8 +3135,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;
   }
 |
@@ -3185,8 +3189,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;}
   }
@@ -3196,8 +3200,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 {
@@ -3206,8 +3210,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 {
@@ -3217,8 +3221,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 {
@@ -3227,26 +3231,27 @@ 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 {
     statement = Statement()
-    {pos = rparenToken.sourceEnd+1;}
+    {pos = statement.sourceEnd+1;}
   } catch (ParseException e) {
     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,
+  {
+   return new ForeachStatement(expression,
                                variable,
                                statement,
                                foreachToken.sourceStart,
-                               statement.sourceEnd);}
+                               pos);}
 
 }