*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index 23b070d..cb90b27 100644 (file)
@@ -60,7 +60,6 @@ public final class PHPParser extends PHPParserSuperclass {
   private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
   static PHPOutlineInfo outlineInfo;
 
-  public static MethodDeclaration currentFunction;
   private static boolean assigning;
 
   /** The error level of the current ParseException. */
@@ -71,6 +70,8 @@ public final class PHPParser extends PHPParserSuperclass {
   private static int errorStart = -1;
   private static int errorEnd = -1;
   private static PHPDocument phpDocument;
+
+  private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
   /**
    * The point where html starts.
    * It will be used by the token manager to create HTMLCode objects
@@ -83,12 +84,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 +102,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,83 +123,10 @@ 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);
-    if (jj_input_stream == null) {
-      jj_input_stream = new SimpleCharStream(stream, 1, 1);
-    }
-    ReInit(new StringReader(strEval));
-    init();
-    phpTest();
-  }
-
-  public static final void htmlParserTester(final File fileName) throws CoreException, ParseException {
-    try {
-      final Reader stream = new FileReader(fileName);
-      if (jj_input_stream == null) {
-        jj_input_stream = new SimpleCharStream(stream, 1, 1);
-      }
-      ReInit(stream);
-      init();
-      phpFile();
-    } catch (FileNotFoundException e) {
-      e.printStackTrace();  //To change body of catch statement use Options | File Templates.
-    }
-  }
-
-  public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
-    final StringReader stream = new StringReader(strEval);
-    if (jj_input_stream == null) {
-      jj_input_stream = new SimpleCharStream(stream, 1, 1);
-    }
-    ReInit(stream);
-    init();
-    phpFile();
-  }
-
   public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
-    currentSegment = new PHPDocument(parent);
-    outlineInfo = new PHPOutlineInfo(parent);
+    phpDocument = new PHPDocument(parent,"_root".toCharArray());
+    currentSegment = phpDocument;
+    outlineInfo = new PHPOutlineInfo(parent, currentSegment);
     final StringReader stream = new StringReader(s);
     if (jj_input_stream == null) {
       jj_input_stream = new SimpleCharStream(stream, 1, 1);
@@ -217,9 +135,11 @@ public final class PHPParser extends PHPParserSuperclass {
     init();
     try {
       parse();
-      phpDocument = new PHPDocument(null);
-      phpDocument.nodes = nodes;
-      PHPeclipsePlugin.log(1,phpDocument.toString());
+      phpDocument.nodes = new AstNode[nodes.length];
+      System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
+      if (PHPeclipsePlugin.DEBUG) {
+        PHPeclipsePlugin.log(1,phpDocument.toString());
+      }
     } catch (ParseException e) {
       processParseException(e);
     }
@@ -235,7 +155,7 @@ public final class PHPParser extends PHPParserSuperclass {
     if (errorMessage == null) {
       PHPeclipsePlugin.log(e);
       errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
-      errorStart = jj_input_stream.getPosition();
+      errorStart = SimpleCharStream.getPosition();
       errorEnd   = errorStart + 1;
     }
     setMarker(e);
@@ -251,8 +171,8 @@ public final class PHPParser extends PHPParserSuperclass {
       if (errorStart == -1) {
         setMarker(fileToParse,
                   errorMessage,
-                  jj_input_stream.tokenBegin,
-                  jj_input_stream.tokenBegin + e.currentToken.image.length(),
+                  SimpleCharStream.tokenBegin,
+                  SimpleCharStream.tokenBegin + e.currentToken.image.length(),
                   errorLevel,
                   "Line " + e.currentToken.beginLine);
       } else {
@@ -380,7 +300,7 @@ public final class PHPParser extends PHPParserSuperclass {
     if (currentPosition == htmlStart) {
       return;
     }
-    final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition).toCharArray();
+    final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
     pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
   }
 
@@ -569,39 +489,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 +529,7 @@ MORE :
 
       "'"
     >
-|   < STRING_3:
+|   <STRING_3:
       "`"
       (
         ~["`"]
@@ -692,14 +611,6 @@ MORE :
   < DOLLAR_ID: <DOLLAR> <IDENTIFIER>  >
 }
 
-void phpTest() :
-{}
-{
-  Php()
-  <EOF>
-  {PHPParser.createNewHTMLCode();}
-}
-
 void phpFile() :
 {}
 {
@@ -723,18 +634,18 @@ void phpFile() :
  */
 void PhpBlock() :
 {
-  final int start = jj_input_stream.getPosition();
+  final int start = SimpleCharStream.getPosition();
 }
 {
   phpEchoBlock()
 |
-  [ <PHPSTARTLONG>
+  [   <PHPSTARTLONG>
     | <PHPSTARTSHORT>
     {try {
       setMarker(fileToParse,
                 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
                 start,
-                jj_input_stream.getPosition(),
+                SimpleCharStream.getPosition(),
                 INFO,
                 "Line " + token.beginLine);
     } catch (CoreException e) {
@@ -747,9 +658,9 @@ void PhpBlock() :
   } catch (ParseException e) {
     errorMessage = "'?>' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
   }
 }
 
@@ -779,41 +690,46 @@ ClassDeclaration ClassDeclaration() :
   final Token className;
   Token superclassName = null;
   final int pos;
+  char[] classNameImage = SYNTAX_ERROR_CHAR;
+  char[] superclassNameImage = null;
 }
 {
   <CLASS>
+  {pos = SimpleCharStream.getPosition();}
   try {
-    {pos = jj_input_stream.getPosition();}
     className = <IDENTIFIER>
+    {classNameImage = className.image.toCharArray();}
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
   }
   [
     <EXTENDS>
     try {
       superclassName = <IDENTIFIER>
+      {superclassNameImage = superclassName .image.toCharArray();}
     } catch (ParseException e) {
       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
       errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
-      throw e;
+      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd   = SimpleCharStream.getPosition() + 1;
+      processParseException(e);
+      superclassNameImage = SYNTAX_ERROR_CHAR;
     }
   ]
   {
-    if (superclassName == null) {
+    if (superclassNameImage == null) {
       classDeclaration = new ClassDeclaration(currentSegment,
-                                              className.image.toCharArray(),
+                                              classNameImage,
                                               pos,
                                               0);
     } else {
       classDeclaration = new ClassDeclaration(currentSegment,
-                                              className.image.toCharArray(),
-                                              superclassName.image.toCharArray(),
+                                              classNameImage,
+                                              superclassNameImage,
                                               pos,
                                               0);
     }
@@ -835,8 +751,8 @@ void ClassBody(ClassDeclaration classDeclaration) :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   ( ClassBodyDeclaration(classDeclaration) )*
@@ -845,8 +761,8 @@ void ClassBody(ClassDeclaration classDeclaration) :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -860,8 +776,8 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
   FieldDeclaration field;
 }
 {
-  method = MethodDeclaration() {classDeclaration.addMethod(method);}
-| field = FieldDeclaration()   {classDeclaration.addVariable(field);}
+  method = MethodDeclaration() {method.setParent(classDeclaration);}
+| field = FieldDeclaration()
 }
 
 /**
@@ -889,23 +805,24 @@ FieldDeclaration FieldDeclaration() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
   }
 
   {list = new VariableDeclaration[arrayList.size()];
    arrayList.toArray(list);
    return new FieldDeclaration(list,
                                pos,
-                               SimpleCharStream.getPosition());}
+                               SimpleCharStream.getPosition(),
+                               currentSegment);}
 }
 
 VariableDeclaration VariableDeclarator() :
 {
-  final String varName, varValue;
+  final String varName;
   Expression initializer = null;
-  final int pos = jj_input_stream.getPosition();
+  final int pos = SimpleCharStream.getPosition();
 }
 {
   varName = VariableDeclaratorId()
@@ -916,8 +833,8 @@ VariableDeclaration VariableDeclarator() :
     } 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;
+      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd   = SimpleCharStream.getPosition() + 1;
       throw e;
     }
   ]
@@ -926,7 +843,7 @@ VariableDeclaration VariableDeclarator() :
     return new VariableDeclaration(currentSegment,
                                   varName.toCharArray(),
                                   pos,
-                                  jj_input_stream.getPosition());
+                                  SimpleCharStream.getPosition());
   }
     return new VariableDeclaration(currentSegment,
                                     varName.toCharArray(),
@@ -961,8 +878,8 @@ String VariableDeclaratorId() :
   } catch (ParseException e) {
     errorMessage = "'$' expected for variable identifier";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -981,14 +898,14 @@ String Variable():
       return token.image.substring(1);
     }
     buff = new StringBuffer(token.image);
-    buff.append('{');
+    buff.append("{");
     buff.append(expression.toStringExpression());
-    buff.append('}');
+    buff.append("}");
     return buff.toString();
   }
 |
   <DOLLAR> expr = VariableName()
-  {return expr;}
+  {return "$" + expr;}
 }
 
 String VariableName():
@@ -1000,9 +917,9 @@ String VariableName():
 }
 {
   <LBRACE> expression = Expression() <RBRACE>
-  {buff = new StringBuffer('{');
+  {buff = new StringBuffer("{");
    buff.append(expression.toStringExpression());
-   buff.append('}');
+   buff.append("}");
    return buff.toString();}
 |
   token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
@@ -1011,15 +928,15 @@ String VariableName():
       return token.image;
     }
     buff = new StringBuffer(token.image);
-    buff.append('{');
+    buff.append("{");
     buff.append(expression.toStringExpression());
-    buff.append('}');
+    buff.append("}");
     return buff.toString();
   }
 |
   <DOLLAR> expr = VariableName()
   {
-    buff = new StringBuffer('$');
+    buff = new StringBuffer("$");
     buff.append(expr);
     return buff.toString();
   }
@@ -1097,22 +1014,19 @@ 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;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {
@@ -1120,12 +1034,10 @@ MethodDeclaration MethodDeclaration() :
       currentSegment.add(functionDeclaration);
       currentSegment = functionDeclaration;
     }
-    currentFunction = functionDeclaration;
   }
   block = Block()
   {
     functionDeclaration.statements = block.statements;
-    currentFunction = null;
     if (currentSegment != null) {
       currentSegment = (OutlineableWithChildren) currentSegment.getParent();
     }
@@ -1144,13 +1056,23 @@ MethodDeclaration MethodDeclarator() :
   Token reference = null;
   final Hashtable formalParameters;
   final int pos = SimpleCharStream.getPosition();
+  char[] identifierChar = SYNTAX_ERROR_CHAR;
 }
 {
-  [ reference = <BIT_AND> ]
-  identifier = <IDENTIFIER>
+  [reference = <BIT_AND>]
+  try {
+    identifier = <IDENTIFIER>
+    {identifierChar = identifier.image.toCharArray();}
+  } catch (ParseException 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;
+    processParseException(e);
+  }
   formalParameters = FormalParameters()
   {return new MethodDeclaration(currentSegment,
-                                 identifier.image.toCharArray(),
+                                 identifierChar,
                                  formalParameters,
                                  reference != null,
                                  pos,
@@ -1163,8 +1085,6 @@ MethodDeclaration MethodDeclarator() :
  */
 Hashtable FormalParameters() :
 {
-  String expr;
-  final StringBuffer buff = new StringBuffer("(");
   VariableDeclaration var;
   final Hashtable parameters = new Hashtable();
 }
@@ -1174,8 +1094,8 @@ Hashtable FormalParameters() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
             [ var = FormalParameter()
@@ -1190,8 +1110,8 @@ Hashtable FormalParameters() :
   } catch (ParseException e) {
     errorMessage = "')' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
  {return parameters;}
@@ -1219,32 +1139,23 @@ ConstantIdentifier Type() :
 {final int pos;}
 {
   <STRING>             {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.STRING,
-                                        pos,pos-6);}
+                        return new ConstantIdentifier(Types.STRING,pos,pos-6);}
 | <BOOL>               {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.BOOL,
-                                        pos,pos-4);}
+                        return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
 | <BOOLEAN>            {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.BOOLEAN,
-                                        pos,pos-7);}
+                        return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
 | <REAL>               {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.REAL,
-                                        pos,pos-4);}
+                        return new ConstantIdentifier(Types.REAL,pos,pos-4);}
 | <DOUBLE>             {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.DOUBLE,
-                                        pos,pos-5);}
+                        return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
 | <FLOAT>              {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.FLOAT,
-                                        pos,pos-5);}
+                        return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
 | <INT>                {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.INT,
-                                        pos,pos-3);}
+                        return new ConstantIdentifier(Types.INT,pos,pos-3);}
 | <INTEGER>            {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.INTEGER,
-                                        pos,pos-7);}
+                        return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
 | <OBJECT>             {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.OBJECT,
-                                        pos,pos-6);}
+                        return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
 }
 
 Expression Expression() :
@@ -1281,8 +1192,8 @@ VarAssignation varAssignation() :
       }
       errorMessage = "expression expected";
       errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
+      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd   = SimpleCharStream.getPosition() + 1;
       throw e;
     }
     {return new VarAssignation(varName.toCharArray(),
@@ -1433,8 +1344,8 @@ Expression EqualityExpression() :
     }
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {
@@ -1504,13 +1415,11 @@ 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;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   (
@@ -1535,8 +1444,7 @@ Expression UnaryExpression() :
   <BIT_AND> expr = UnaryExpressionNoPrefix()
   {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
 |
-  expr = AtUnaryExpression()
-  {return expr;}
+  expr = AtUnaryExpression() {return expr;}
 }
 
 Expression AtUnaryExpression() :
@@ -1604,8 +1512,8 @@ Expression UnaryExpressionNotPlusMinus() :
   } catch (ParseException e) {
     errorMessage = "')' expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return expr;}
@@ -1647,7 +1555,6 @@ Expression PrimaryExpression() :
 {
   final Token identifier;
   Expression expr;
-  final StringBuffer buff = new StringBuffer();
   final int pos = SimpleCharStream.getPosition();
 }
 {
@@ -1756,8 +1663,8 @@ AbstractSuffixExpression VariableSuffix(Expression prefix) :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return new ClassAccess(prefix,
@@ -1770,8 +1677,8 @@ AbstractSuffixExpression VariableSuffix(Expression prefix) :
   } catch (ParseException e) {
     errorMessage = "']' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
@@ -1788,7 +1695,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 +1706,7 @@ Literal Literal() :
 
 FunctionCall Arguments(Expression func) :
 {
-ArgumentDeclaration[] args = null;
+Expression[] args = null;
 }
 {
   <LPAREN> [ args = ArgumentList() ]
@@ -1808,74 +1715,44 @@ ArgumentDeclaration[] args = null;
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {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";
         errorLevel   = ERROR;
-        errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-        errorEnd     = jj_input_stream.getPosition() + 1;
+        errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+        errorEnd     = SimpleCharStream.getPosition() + 1;
         throw e;
       }
    )*
    {
-   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.
  */
@@ -1890,11 +1767,11 @@ Statement StatementNoBreak() :
   try {
     <SEMICOLON>
   } catch (ParseException e) {
-    if (e.currentToken.next.kind != 4) {
+    if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
       errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
+      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd   = SimpleCharStream.getPosition() + 1;
       throw e;
     }
   }
@@ -1909,8 +1786,8 @@ Statement StatementNoBreak() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return statement;}
@@ -1960,15 +1837,16 @@ HTMLBlock htmlBlock() :
   } catch (ParseException e) {
     errorMessage = "End of file unexpected, '<?php' expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition();
-    errorEnd     = jj_input_stream.getPosition();
+    errorStart   = SimpleCharStream.getPosition();
+    errorEnd     = SimpleCharStream.getPosition();
     throw e;
   }
   {
-  nbNodes = nodePtr-startIndex;
+  nbNodes    = nodePtr - startIndex;
   blockNodes = new AstNode[nbNodes];
   System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
-  return new HTMLBlock(nodes);}
+  nodePtr = startIndex;
+  return new HTMLBlock(blockNodes);}
 }
 
 /**
@@ -1977,9 +1855,8 @@ HTMLBlock htmlBlock() :
 InclusionStatement IncludeStatement() :
 {
   final Expression expr;
-  final Token token;
   final int keyword;
-  final int pos = jj_input_stream.getPosition();
+  final int pos = SimpleCharStream.getPosition();
   final InclusionStatement inclusionStatement;
 }
 {
@@ -1995,8 +1872,8 @@ InclusionStatement IncludeStatement() :
     }
     errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {inclusionStatement = new InclusionStatement(currentSegment,
@@ -2010,8 +1887,8 @@ InclusionStatement IncludeStatement() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return inclusionStatement;}
@@ -2040,8 +1917,8 @@ ListExpression ListExpression() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
     errorLevel   = ERROR;
-    errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   [
@@ -2055,8 +1932,8 @@ ListExpression ListExpression() :
     } catch (ParseException e) {
       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
       errorLevel   = ERROR;
-      errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd     = jj_input_stream.getPosition() + 1;
+      errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd     = SimpleCharStream.getPosition() + 1;
       throw e;
     }
     expr = VariableDeclaratorId()
@@ -2067,8 +1944,8 @@ ListExpression ListExpression() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   [ <ASSIGN> expression = Expression()
@@ -2105,24 +1982,23 @@ EchoStatement EchoStatement() :
   )*
   try {
     <SEMICOLON>
-    {
-    Expression[] exprs = new Expression[expressions.size()];
-    expressions.toArray(exprs);
-    return new EchoStatement(exprs,pos);}
   } catch (ParseException e) {
     if (e.currentToken.next.kind != 4) {
       errorMessage = "';' expected after 'echo' statement";
       errorLevel   = ERROR;
-      errorStart   = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd     = jj_input_stream.getPosition() + 1;
+      errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd     = SimpleCharStream.getPosition() + 1;
       throw e;
     }
   }
+  {Expression[] exprs = new Expression[expressions.size()];
+   expressions.toArray(exprs);
+   return new EchoStatement(exprs,pos);}
 }
 
 GlobalStatement GlobalStatement() :
 {
-   final int pos = jj_input_stream.getPosition();
+   final int pos = SimpleCharStream.getPosition();
    String expr;
    ArrayList vars = new ArrayList();
    GlobalStatement global;
@@ -2149,8 +2025,8 @@ GlobalStatement GlobalStatement() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2175,8 +2051,8 @@ StaticStatement StaticStatement() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2211,8 +2087,8 @@ Block Block() :
   } catch (ParseException e) {
     errorMessage = "'{' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   ( statement = BlockStatement() {list.add(statement);}
@@ -2222,8 +2098,8 @@ Block Block() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {
@@ -2237,9 +2113,19 @@ Statement BlockStatement() :
   final Statement statement;
 }
 {
-  statement = Statement()         {return statement;}
+  try {
+  statement = Statement()         {if (phpDocument == currentSegment) pushOnAstNodes(statement);
+                                   return statement;}
+  } catch (ParseException e) {
+    errorMessage = "statement expected";
+    errorLevel   = ERROR;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    throw e;
+  }
 | statement = ClassDeclaration()  {return statement;}
-| statement = MethodDeclaration() {return statement;}
+| statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
+                                   return statement;}
 }
 
 /**
@@ -2283,7 +2169,7 @@ VariableDeclaration LocalVariableDeclarator() :
     return new VariableDeclaration(currentSegment,
                                   varName.toCharArray(),
                                   pos,
-                                  jj_input_stream.getPosition());
+                                  SimpleCharStream.getPosition());
    }
     return new VariableDeclaration(currentSegment,
                                     varName.toCharArray(),
@@ -2336,8 +2222,8 @@ SwitchStatement SwitchStatement() :
   } catch (ParseException e) {
     errorMessage = "'(' expected after 'switch'";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2348,8 +2234,8 @@ SwitchStatement SwitchStatement() :
     }
     errorMessage = "expression expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2357,8 +2243,8 @@ SwitchStatement SwitchStatement() :
   } catch (ParseException e) {
     errorMessage = "')' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
@@ -2382,8 +2268,8 @@ AbstractCase[] switchStatementBrace() :
   } catch (ParseException e) {
     errorMessage = "'}' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2415,8 +2301,8 @@ AbstractCase[] switchStatementColon(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "'endswitch' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2428,8 +2314,8 @@ AbstractCase[] switchStatementColon(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'endswitch' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2463,7 +2349,6 @@ AbstractCase switchLabel0() :
  */
 Expression SwitchLabel() :
 {
-  final Token token;
   final Expression expr;
 }
 {
@@ -2474,8 +2359,8 @@ Expression SwitchLabel() :
     if (errorMessage != null) throw e;
     errorMessage = "expression expected after 'case' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2484,8 +2369,8 @@ Expression SwitchLabel() :
   } catch (ParseException e) {
     errorMessage = "':' expected after case expression";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 |
@@ -2496,8 +2381,8 @@ Expression SwitchLabel() :
   } catch (ParseException e) {
     errorMessage = "':' expected after 'default' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2514,8 +2399,8 @@ Break BreakStatement() :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'break' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return new Break(expression, start, SimpleCharStream.getPosition());}
@@ -2523,7 +2408,7 @@ Break BreakStatement() :
 
 IfStatement IfStatement() :
 {
-  final int pos = jj_input_stream.getPosition();
+  final int pos = SimpleCharStream.getPosition();
   Expression condition;
   IfStatement ifStatement;
 }
@@ -2543,21 +2428,21 @@ Expression Condition(final String keyword) :
   } catch (ParseException e) {
     errorMessage = "'(' expected after " + keyword + " keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length();
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
     errorEnd   = errorStart +1;
     processParseException(e);
   }
   condition = Expression()
   try {
      <RPAREN>
-     {return condition;}
   } catch (ParseException e) {
     errorMessage = "')' expected after " + keyword + " keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    processParseException(e);
   }
+  {return condition;}
 }
 
 IfStatement IfStatement0(Expression condition, final int start,final int end) :
@@ -2597,8 +2482,8 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) :
   } catch (ParseException e) {
     errorMessage = "'endif' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2606,8 +2491,8 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'endif' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
     {
@@ -2647,8 +2532,8 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) :
       }
       errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
       errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
+      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+      errorEnd   = SimpleCharStream.getPosition() + 1;
       throw e;
     }
   ]
@@ -2746,8 +2631,8 @@ Statement WhileStatement0(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "'endwhile' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2759,8 +2644,8 @@ Statement WhileStatement0(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'endwhile' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 |
@@ -2782,8 +2667,8 @@ DoStatement DoStatement() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2792,7 +2677,6 @@ ForeachStatement ForeachStatement() :
 {
   Statement statement;
   Expression expression;
-  final StringBuffer buff = new StringBuffer();
   final int pos = SimpleCharStream.getPosition();
   ArrayVariableDeclaration variable;
 }
@@ -2803,8 +2687,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "'(' expected after 'foreach' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2812,8 +2696,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "variable expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2821,8 +2705,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "'as' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2830,8 +2714,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "variable expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2839,8 +2723,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "')' expected after 'foreach' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   try {
@@ -2849,8 +2733,8 @@ ForeachStatement ForeachStatement() :
     if (errorMessage != null) throw e;
     errorMessage = "statement expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   {return new ForeachStatement(expression,
@@ -2879,8 +2763,8 @@ final int startBlock, endBlock;
   } catch (ParseException e) {
     errorMessage = "'(' expected after 'for' keyword";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
      [ initializations = ForInit() ] <SEMICOLON>
@@ -2911,8 +2795,8 @@ final int startBlock, endBlock;
       } catch (ParseException e) {
         errorMessage = "'endfor' expected";
         errorLevel   = ERROR;
-        errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-        errorEnd   = jj_input_stream.getPosition() + 1;
+        errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+        errorEnd   = SimpleCharStream.getPosition() + 1;
         throw e;
       }
       try {
@@ -2924,8 +2808,8 @@ final int startBlock, endBlock;
       } catch (ParseException e) {
         errorMessage = "';' expected after 'endfor' keyword";
         errorLevel   = ERROR;
-        errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-        errorEnd   = jj_input_stream.getPosition() + 1;
+        errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+        errorEnd   = SimpleCharStream.getPosition() + 1;
         throw e;
       }
     )
@@ -2971,8 +2855,8 @@ Continue ContinueStatement() :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'continue' statement";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -2990,8 +2874,8 @@ ReturnStatement ReturnStatement() :
   } catch (ParseException e) {
     errorMessage = "';' expected after 'return' statement";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
\ No newline at end of file