*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index 438fa59..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
@@ -123,8 +124,9 @@ public final class PHPParser extends PHPParserSuperclass {
   }
 
   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);
@@ -133,10 +135,11 @@ public final class PHPParser extends PHPParserSuperclass {
     init();
     try {
       parse();
-      phpDocument = new PHPDocument(null);
       phpDocument.nodes = new AstNode[nodes.length];
       System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
-      PHPeclipsePlugin.log(1,phpDocument.toString());
+      if (PHPeclipsePlugin.DEBUG) {
+        PHPeclipsePlugin.log(1,phpDocument.toString());
+      }
     } catch (ParseException e) {
       processParseException(e);
     }
@@ -152,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);
@@ -168,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 {
@@ -631,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) {
@@ -655,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);
   }
 }
 
@@ -687,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);
     }
@@ -768,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()
 }
 
 /**
@@ -799,21 +807,22 @@ FieldDeclaration FieldDeclaration() :
     errorLevel   = ERROR;
     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd     = SimpleCharStream.getPosition() + 1;
-    throw e;
+    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;
   Expression initializer = null;
-  final int pos = jj_input_stream.getPosition();
+  final int pos = SimpleCharStream.getPosition();
 }
 {
   varName = VariableDeclaratorId()
@@ -824,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;
     }
   ]
@@ -834,7 +843,7 @@ VariableDeclaration VariableDeclarator() :
     return new VariableDeclaration(currentSegment,
                                   varName.toCharArray(),
                                   pos,
-                                  jj_input_stream.getPosition());
+                                  SimpleCharStream.getPosition());
   }
     return new VariableDeclaration(currentSegment,
                                     varName.toCharArray(),
@@ -869,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;
   }
 }
@@ -889,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():
@@ -908,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>]
@@ -919,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();
   }
@@ -1016,8 +1025,8 @@ MethodDeclaration MethodDeclaration() :
     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;
   }
   {
@@ -1025,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();
     }
@@ -1049,12 +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,
@@ -1076,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()
@@ -1092,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;}
@@ -1121,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() :
@@ -1183,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(),
@@ -1335,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;
   }
   {
@@ -1409,8 +1418,8 @@ Expression MultiplicativeExpression() :
     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;
   }
   (
@@ -1503,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;}
@@ -1654,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,
@@ -1668,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());}
@@ -1706,8 +1715,8 @@ Expression[] 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());}
@@ -1733,8 +1742,8 @@ final ArrayList list = new ArrayList();
       } 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;
       }
    )*
@@ -1758,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;
     }
   }
@@ -1777,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;}
@@ -1828,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 - 1;
+  nbNodes    = nodePtr - startIndex;
   blockNodes = new AstNode[nbNodes];
   System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
-  return new HTMLBlock(nodes);}
+  nodePtr = startIndex;
+  return new HTMLBlock(blockNodes);}
 }
 
 /**
@@ -1846,7 +1856,7 @@ InclusionStatement IncludeStatement() :
 {
   final Expression expr;
   final int keyword;
-  final int pos = jj_input_stream.getPosition();
+  final int pos = SimpleCharStream.getPosition();
   final InclusionStatement inclusionStatement;
 }
 {
@@ -1862,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,
@@ -1877,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;}
@@ -1907,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;
   }
   [
@@ -1922,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()
@@ -1934,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()
@@ -1972,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;
@@ -2016,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;
   }
 }
@@ -2042,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;
   }
 }
@@ -2078,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);}
@@ -2089,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;
   }
   {
@@ -2104,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;}
 }
 
 /**
@@ -2150,7 +2169,7 @@ VariableDeclaration LocalVariableDeclarator() :
     return new VariableDeclaration(currentSegment,
                                   varName.toCharArray(),
                                   pos,
-                                  jj_input_stream.getPosition());
+                                  SimpleCharStream.getPosition());
    }
     return new VariableDeclaration(currentSegment,
                                     varName.toCharArray(),
@@ -2203,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 {
@@ -2215,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 {
@@ -2224,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))
@@ -2249,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;
   }
 }
@@ -2282,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 {
@@ -2295,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;
   }
 }
@@ -2340,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 {
@@ -2350,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;
   }
 |
@@ -2362,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;
   }
 }
@@ -2380,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());}
@@ -2389,7 +2408,7 @@ Break BreakStatement() :
 
 IfStatement IfStatement() :
 {
-  final int pos = jj_input_stream.getPosition();
+  final int pos = SimpleCharStream.getPosition();
   Expression condition;
   IfStatement ifStatement;
 }
@@ -2409,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) :
@@ -2463,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 {
@@ -2472,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;
   }
     {
@@ -2513,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;
     }
   ]
@@ -2612,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 {
@@ -2625,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;
   }
 |
@@ -2648,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;
   }
 }
@@ -2668,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 {
@@ -2677,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 {
@@ -2686,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 {
@@ -2695,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 {
@@ -2704,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 {
@@ -2714,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,
@@ -2744,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>
@@ -2776,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 {
@@ -2789,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;
       }
     )
@@ -2836,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;
   }
 }
@@ -2855,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