3.x RC1 compatibility
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index e8ab5f2..b61df9a 100644 (file)
@@ -3,7 +3,7 @@ options {
   LOOKAHEAD = 1;
   CHOICE_AMBIGUITY_CHECK = 2;
   OTHER_AMBIGUITY_CHECK = 1;
-  STATIC = true;
+  STATIC = false;
   DEBUG_PARSER = false;
   DEBUG_LOOKAHEAD = false;
   DEBUG_TOKEN_MANAGER = false;
@@ -101,24 +101,26 @@ public final class PHPParser extends PHPParserSuperclass {
     PHPParser.fileToParse = fileToParse;
   }
 
-  public static final void phpParserTester(final String strEval) throws ParseException {
+  public final void phpParserTester(final String strEval) throws ParseException {
     final StringReader stream = new StringReader(strEval);
     if (jj_input_stream == null) {
       jj_input_stream = new SimpleCharStream(stream, 1, 1);
+      token_source = new PHPParserTokenManager(jj_input_stream);
     }
     ReInit(new StringReader(strEval));
     init();
     phpDocument = new PHPDocument(null,"_root".toCharArray());
     currentSegment = phpDocument;
     outlineInfo = new PHPOutlineInfo(null, currentSegment);
-    PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
+    token_source.SwitchTo(PHPParserTokenManager.PHPPARSING);
     phpTest();
   }
 
-  public static final void htmlParserTester(final File fileName) throws FileNotFoundException, ParseException {
+  public final void htmlParserTester(final File fileName) throws FileNotFoundException, ParseException {
     final Reader stream = new FileReader(fileName);
     if (jj_input_stream == null) {
       jj_input_stream = new SimpleCharStream(stream, 1, 1);
+      token_source = new PHPParserTokenManager(jj_input_stream);
     }
     ReInit(stream);
     init();
@@ -128,10 +130,11 @@ public final class PHPParser extends PHPParserSuperclass {
     phpFile();
   }
 
-  public static final void htmlParserTester(final String strEval) throws ParseException {
+  public final void htmlParserTester(final String strEval) throws ParseException {
     final StringReader stream = new StringReader(strEval);
     if (jj_input_stream == null) {
       jj_input_stream = new SimpleCharStream(stream, 1, 1);
+      token_source = new PHPParserTokenManager(jj_input_stream);
     }
     ReInit(stream);
     init();
@@ -174,6 +177,7 @@ public final class PHPParser extends PHPParserSuperclass {
     final StringReader stream = new StringReader(s);
     if (jj_input_stream == null) {
       jj_input_stream = new SimpleCharStream(stream, 1, 1);
+      token_source = new PHPParserTokenManager(jj_input_stream);
     }
     ReInit(stream);
     init();
@@ -232,14 +236,14 @@ public final class PHPParser extends PHPParserSuperclass {
                   e.currentToken.sourceStart,
                   e.currentToken.sourceEnd,
                   errorLevel,
-                  "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+":"+e.currentToken.sourceEnd);
+                  "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+':'+e.currentToken.sourceEnd);
       } else {
         setMarker(fileToParse,
                   errorMessage,
                   errorStart,
                   errorEnd,
                   errorLevel,
-                  "Line " + e.currentToken.beginLine+", "+errorStart+":"+errorEnd);
+                  "Line " + e.currentToken.beginLine+", "+errorStart+':'+errorEnd);
         errorStart = -1;
         errorEnd = -1;
       }
@@ -293,6 +297,7 @@ public final class PHPParser extends PHPParserSuperclass {
     final StringReader stream = new StringReader(s);
     if (jj_input_stream == null) {
       jj_input_stream = new SimpleCharStream(stream, 1, 1);
+      token_source = new PHPParserTokenManager(jj_input_stream);
     }
     ReInit(stream);
     init();
@@ -328,36 +333,36 @@ public final class PHPParser extends PHPParserSuperclass {
   /**
    * Put a new html block in the stack.
    */
-  public static final void createNewHTMLCode() {
+  public final void createNewHTMLCode() {
     final int currentPosition = token.sourceStart;
     if (currentPosition == htmlStart ||
-          currentPosition > SimpleCharStream.currentBuffer.length()) {
+          currentPosition < htmlStart ||
+          currentPosition > jj_input_stream.getCurrentBuffer().length()) {
       return;
     }
-    final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
-    pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
+    final String html = jj_input_stream.getCurrentBuffer().substring(htmlStart, currentPosition);
+    pushOnAstNodes(new HTMLCode(html, htmlStart,currentPosition));
   }
 
   /** Create a new task. */
-  public static final void createNewTask() {
-    final int currentPosition = token.sourceStart;
-    final String  todo = SimpleCharStream.currentBuffer.substring(currentPosition-3,
-                                                                  SimpleCharStream.currentBuffer.indexOf("\n",
-                                                                                                         currentPosition)-1);
+  public final void createNewTask(final int todoStart) {
+    final String  todo = jj_input_stream.getCurrentBuffer().substring(todoStart,
+                                                                  jj_input_stream.getCurrentBuffer().indexOf("\n",
+                                                                                                         todoStart)-1);
     if (!PARSER_DEBUG) {
       try {
         setMarker(fileToParse,
                   todo,
-                  SimpleCharStream.getBeginLine(),
+                  jj_input_stream.getBeginLine(),
                   TASK,
-                  "Line "+SimpleCharStream.getBeginLine());
+                  "Line "+jj_input_stream.getBeginLine());
       } catch (CoreException e) {
         PHPeclipsePlugin.log(e);
       }
     }
   }
 
-  private static final void parse() throws ParseException {
+  private final void parse() throws ParseException {
          phpFile();
   }
 }
@@ -370,22 +375,22 @@ TOKEN_MGR_DECLS:
   // CharStream class to set corresponding fields in each Token (which was
   // also extended with new fields). By default Jack doesn't supply absolute
   // offsets, just line/column offsets
-  static void CommonTokenAction(Token t) {
-    t.sourceStart = input_stream.beginOffset;
-    t.sourceEnd = input_stream.endOffset;
+  void CommonTokenAction(Token t) {
+    t.sourceStart = input_stream.getBeginOffset();
+    t.sourceEnd = input_stream.getBeginOffset();
   } // CommonTokenAction
 } // TOKEN_MGR_DECLS
 
 <DEFAULT> TOKEN :
 {
-  <PHPSTARTSHORT : "<?">    {PHPParser.createNewHTMLCode();} : PHPPARSING
-| <PHPSTARTLONG  : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
-| <PHPECHOSTART  : "<?=">   {PHPParser.createNewHTMLCode();} : PHPPARSING
+  <PHPSTARTSHORT : "<?">    : PHPPARSING
+| <PHPSTARTLONG  : "<?php"> : PHPPARSING
+| <PHPECHOSTART  : "<?=">   : PHPPARSING
 }
 
-<PHPPARSING, IN_SINGLE_LINE_COMMENT> TOKEN :
+<PHPPARSING, IN_SINGLE_LINE_COMMENT,IN_VARIABLE> TOKEN :
 {
-  <PHPEND :"?>"> {PHPParser.htmlStart = PHPParser.token.sourceEnd;} : DEFAULT
+  <PHPEND :"?>"> : DEFAULT
 }
 
 /* Skip any character if we are not in php mode */
@@ -405,6 +410,14 @@ TOKEN_MGR_DECLS:
 | "\f"
 }
 
+<IN_VARIABLE> SPECIAL_TOKEN :
+{
+  " " : PHPPARSING
+| "\t" : PHPPARSING
+| "\n" : PHPPARSING
+| "\r" : PHPPARSING
+| "\f" : PHPPARSING
+}
 /* COMMENTS */
 <PHPPARSING> SPECIAL_TOKEN :
 {
@@ -422,9 +435,14 @@ TOKEN_MGR_DECLS:
 
 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
 {
- "todo" {PHPParser.createNewTask();}
+ "todo"
 }
 
+void todo() :
+{Token todoToken;}
+{
+  todoToken = "TODO" {createNewTask(todoToken.sourceStart);}
+}
 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
 {
   "*/" : PHPPARSING
@@ -467,9 +485,13 @@ MORE :
 | <GLOBAL             : "global">
 | <DEFINE             : "define">
 | <STATIC             : "static">
-| <CLASSACCESS        : "->">
-| <STATICCLASSACCESS  : "::">
-| <ARRAYASSIGN        : "=>">
+}
+
+<PHPPARSING,IN_VARIABLE> TOKEN :
+{
+  <CLASSACCESS        : "->"> : PHPPARSING
+| <STATICCLASSACCESS  : "::"> : PHPPARSING
+| <ARRAYASSIGN        : "=>"> : PHPPARSING
 }
 
 /* RESERVED WORDS AND LITERALS */
@@ -516,36 +538,35 @@ MORE :
 }
 
 //Misc token
-<PHPPARSING> TOKEN :
+<PHPPARSING,IN_VARIABLE> TOKEN :
 {
-  <AT                 : "@">
-| <DOLLAR             : "$">
-| <BANG               : "!">
-| <TILDE              : "~">
-| <HOOK               : "?">
-| <COLON              : ":">
+  <AT                 : "@"> : PHPPARSING
+| <BANG               : "!"> : PHPPARSING
+| <TILDE              : "~"> : PHPPARSING
+| <HOOK               : "?"> : PHPPARSING
+| <COLON              : ":"> : PHPPARSING
 }
 
 /* OPERATORS */
-<PHPPARSING> TOKEN :
-{
-  <OR_OR              : "||">
-| <AND_AND            : "&&">
-| <PLUS_PLUS          : "++">
-| <MINUS_MINUS        : "--">
-| <PLUS               : "+">
-| <MINUS              : "-">
-| <STAR               : "*">
-| <SLASH              : "/">
-| <BIT_AND            : "&">
-| <BIT_OR             : "|">
-| <XOR                : "^">
-| <REMAINDER          : "%">
-| <LSHIFT             : "<<">
-| <RSIGNEDSHIFT       : ">>">
-| <RUNSIGNEDSHIFT     : ">>>">
-| <_ORL               : "OR">
-| <_ANDL              : "AND">
+<PHPPARSING,IN_VARIABLE> TOKEN :
+{
+  <OR_OR              : "||"> : PHPPARSING
+| <AND_AND            : "&&"> : PHPPARSING
+| <PLUS_PLUS          : "++"> : PHPPARSING
+| <MINUS_MINUS        : "--"> : PHPPARSING
+| <PLUS               : "+"> : PHPPARSING
+| <MINUS              : "-"> : PHPPARSING
+| <STAR               : "*"> : PHPPARSING
+| <SLASH              : "/"> : PHPPARSING
+| <BIT_AND            : "&"> : PHPPARSING
+| <BIT_OR             : "|"> : PHPPARSING
+| <XOR                : "^"> : PHPPARSING
+| <REMAINDER          : "%">  : PHPPARSING
+| <LSHIFT             : "<<"> : PHPPARSING
+| <RSIGNEDSHIFT       : ">>"> : PHPPARSING
+| <RUNSIGNEDSHIFT     : ">>>"> : PHPPARSING
+| <_ORL               : "OR"> : PHPPARSING
+| <_ANDL              : "AND"> : PHPPARSING
 }
 
 /* LITERALS */
@@ -572,16 +593,80 @@ MORE :
 |
   <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
 |
-  <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
-|   <STRING_1: "\"" ( ~["\"","\\"] | "\\" ~[] )* "\"">
+  <STRING_LITERAL: (<STRING_2> | <STRING_3>)>
+//|   <STRING_1: "\"" ( ~["\"","\\"] | "\\" ~[] )* "\"">
 |   <STRING_2: "'"  ( ~["'","\\"]  | "\\" ~[] )* "'">
 |   <STRING_3: "`"  ( ~["`","\\"]  | "\\" ~[] )* "`">
 }
 
-/* IDENTIFIERS */
+<IN_STRING,DOLLAR_IN_STRING> SKIP :
+{
+  <ESCAPED : ("\\" ~[])> : IN_STRING
+}
 
 <PHPPARSING> TOKEN :
 {
+  <DOUBLEQUOTE : "\""> : IN_STRING
+}
+
+
+<IN_STRING> TOKEN :
+{
+  <DOLLARS : "$"> : DOLLAR_IN_STRING
+}
+
+<IN_STRING,DOLLAR_IN_STRING> TOKEN :
+{
+  <DOUBLEQUOTE2 : "\""> : PHPPARSING
+}
+
+<DOLLAR_IN_STRING> TOKEN :
+{
+  <LBRACE1 : "{"> : DOLLAR_IN_STRING_EXPR
+}
+
+<IN_STRING> SPECIAL_TOKEN :
+{
+    <"{"> : SKIPSTRING
+}
+
+<SKIPSTRING> SPECIAL_TOKEN :
+{
+    <"}"> : IN_STRING
+}
+
+<SKIPSTRING> SKIP :
+{
+    <~[]>
+}
+
+<DOLLAR_IN_STRING_EXPR> TOKEN :
+{
+  <RBRACE1 : "}"> : DOLLAR_IN_STRING
+}
+
+<DOLLAR_IN_STRING_EXPR> TOKEN :
+{
+  <ID : (~["}"])*>
+}
+
+<IN_STRING> SKIP :
+{
+  <~[]>
+}
+
+<DOLLAR_IN_STRING_EXPR,IN_STRING> SKIP :
+{
+  <~[]>
+}
+/* IDENTIFIERS */
+
+
+<PHPPARSING,IN_VARIABLE> TOKEN : {<DOLLAR : "$"> : IN_VARIABLE}
+
+
+<PHPPARSING, IN_VARIABLE, DOLLAR_IN_STRING> TOKEN :
+{
   <IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
 |
   < #LETTER:
@@ -597,57 +682,56 @@ MORE :
   >
 }
 
+<DOLLAR_IN_STRING> SPECIAL_TOKEN :
+{
+ < ~[] > : IN_STRING
+}
 /* SEPARATORS */
 
-<PHPPARSING> TOKEN :
+<PHPPARSING,IN_VARIABLE> TOKEN :
 {
-  <LPAREN    : "(">
-| <RPAREN    : ")">
-| <LBRACE    : "{">
-| <RBRACE    : "}">
-| <LBRACKET  : "[">
-| <RBRACKET  : "]">
-| <SEMICOLON : ";">
-| <COMMA     : ",">
-| <DOT       : ".">
+  <LPAREN    : "("> : PHPPARSING
+| <RPAREN    : ")"> : PHPPARSING
+| <LBRACE    : "{"> : PHPPARSING
+| <RBRACE    : "}"> : PHPPARSING
+| <LBRACKET  : "["> : PHPPARSING
+| <RBRACKET  : "]"> : PHPPARSING
+| <SEMICOLON : ";"> : PHPPARSING
+| <COMMA     : ","> : PHPPARSING
+| <DOT       : "."> : PHPPARSING
 }
 
 
 /* COMPARATOR */
-<PHPPARSING> TOKEN :
+<PHPPARSING,IN_VARIABLE> TOKEN :
 {
-  <GT                 : ">">
-| <LT                 : "<">
-| <EQUAL_EQUAL        : "==">
-| <LE                 : "<=">
-| <GE                 : ">=">
-| <NOT_EQUAL          : "!=">
-| <DIF                : "<>">
-| <BANGDOUBLEEQUAL    : "!==">
-| <TRIPLEEQUAL        : "===">
+  <GT                 : ">"> : PHPPARSING
+| <LT                 : "<"> : PHPPARSING
+| <EQUAL_EQUAL        : "=="> : PHPPARSING
+| <LE                 : "<="> : PHPPARSING
+| <GE                 : ">="> : PHPPARSING
+| <NOT_EQUAL          : "!="> : PHPPARSING
+| <DIF                : "<>"> : PHPPARSING
+| <BANGDOUBLEEQUAL    : "!=="> : PHPPARSING
+| <TRIPLEEQUAL        : "==="> : PHPPARSING
 }
 
 /* ASSIGNATION */
-<PHPPARSING> TOKEN :
-{
-  <ASSIGN             : "=">
-| <PLUSASSIGN         : "+=">
-| <MINUSASSIGN        : "-=">
-| <STARASSIGN         : "*=">
-| <SLASHASSIGN        : "/=">
-| <ANDASSIGN          : "&=">
-| <ORASSIGN           : "|=">
-| <XORASSIGN          : "^=">
-| <DOTASSIGN          : ".=">
-| <REMASSIGN          : "%=">
-| <TILDEEQUAL         : "~=">
-| <LSHIFTASSIGN       : "<<=">
-| <RSIGNEDSHIFTASSIGN : ">>=">
-}
-
-<PHPPARSING> TOKEN :
-{
-  <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
+<PHPPARSING,IN_VARIABLE> TOKEN :
+{
+  <ASSIGN             : "="> : PHPPARSING
+| <PLUSASSIGN         : "+="> : PHPPARSING
+| <MINUSASSIGN        : "-="> : PHPPARSING
+| <STARASSIGN         : "*="> : PHPPARSING
+| <SLASHASSIGN        : "/="> : PHPPARSING
+| <ANDASSIGN          : "&="> : PHPPARSING
+| <ORASSIGN           : "|="> : PHPPARSING
+| <XORASSIGN          : "^="> : PHPPARSING
+| <DOTASSIGN          : ".="> : PHPPARSING
+| <REMASSIGN          : "%="> : PHPPARSING
+| <TILDEEQUAL         : "~="> : PHPPARSING
+| <LSHIFTASSIGN       : "<<="> : PHPPARSING
+| <RSIGNEDSHIFTASSIGN : ">>="> : PHPPARSING
 }
 
 void phpTest() :
@@ -662,11 +746,11 @@ void phpFile() :
 {
   try {
     (PhpBlock())*
-    {PHPParser.createNewHTMLCode();}
+    {createNewHTMLCode();}
   } catch (TokenMgrError e) {
     PHPeclipsePlugin.log(e);
-    errorStart   = SimpleCharStream.beginOffset;
-    errorEnd     = SimpleCharStream.endOffset;
+    errorStart   = jj_input_stream.getBeginOffset();
+    errorEnd     = jj_input_stream.getEndOffset();
     errorMessage = e.getMessage();
     errorLevel   = ERROR;
     throw generateParseException();
@@ -681,7 +765,7 @@ void phpFile() :
 void PhpBlock() :
 {
   final PHPEchoBlock phpEchoBlock;
-  final Token token;
+  final Token token,phpEnd;
 }
 {
   phpEchoBlock = phpEchoBlock()
@@ -700,14 +784,16 @@ void PhpBlock() :
       PHPeclipsePlugin.log(e);
     }}
   ]
+  {createNewHTMLCode();}
   Php()
   try {
-    <PHPEND>
+    phpEnd = <PHPEND>
+   {htmlStart = phpEnd.sourceEnd;}
   } catch (ParseException e) {
     errorMessage = "'?>' expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
 }
@@ -719,8 +805,11 @@ PHPEchoBlock phpEchoBlock() :
   final Token token, token2;
 }
 {
-  token = <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] token2 = <PHPEND>
+  token = <PHPECHOSTART> {createNewHTMLCode();}
+  expr = Expression() [ <SEMICOLON> ] token2 = <PHPEND>
   {
+  htmlStart = token2.sourceEnd;
+
   echoBlock = new PHPEchoBlock(expr,token.sourceStart,token2.sourceEnd);
   pushOnAstNodes(echoBlock);
   return echoBlock;}
@@ -739,6 +828,7 @@ ClassDeclaration ClassDeclaration() :
   final Token superclassName, token, extendsToken;
   String classNameImage = SYNTAX_ERROR_CHAR;
   String superclassNameImage = null;
+  final int classEnd;
 }
 {
   token = <CLASS>
@@ -791,34 +881,38 @@ ClassDeclaration ClassDeclaration() :
       currentSegment.add(classDeclaration);
       currentSegment = classDeclaration;
   }
-  ClassBody(classDeclaration)
+  classEnd = ClassBody(classDeclaration)
   {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
-   classDeclaration.sourceEnd = SimpleCharStream.getPosition();
+   classDeclaration.sourceEnd = classEnd;
    pushOnAstNodes(classDeclaration);
    return classDeclaration;}
 }
 
-void ClassBody(final ClassDeclaration classDeclaration) :
-{}
+int ClassBody(final ClassDeclaration classDeclaration) :
+{
+Token token;
+}
 {
   try {
     <LBRACE>
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   ( ClassBodyDeclaration(classDeclaration) )*
   try {
-    <RBRACE>
+    token = <RBRACE>
+    {return token.sourceEnd;}
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
+    return this.token.sourceEnd;
   }
 }
 
@@ -853,7 +947,6 @@ FieldDeclaration FieldDeclaration() :
   token = <VAR> variableDeclaration = VariableDeclaratorNoSuffix()
   {
     arrayList.add(variableDeclaration);
-    outlineInfo.addVariable(variableDeclaration.name());
     pos = variableDeclaration.sourceEnd;
   }
   (
@@ -894,12 +987,20 @@ FieldDeclaration FieldDeclaration() :
  */
 VariableDeclaration VariableDeclaratorNoSuffix() :
 {
-  final Token varName;
-  Expression initializer = null;
+  final Token token, lbrace,rbrace;
+  Expression expr, initializer = null;
   Token assignToken;
+  Variable variable;
 }
 {
-  varName = <DOLLAR_ID>
+  <DOLLAR>
+  (
+     token = <IDENTIFIER>
+     {variable = new Variable(token.image,token.sourceStart,token.sourceEnd);}
+   |
+     lbrace = <LBRACE> expr = Expression() rbrace = <RBRACE>
+     {variable = new Variable(expr,lbrace.sourceStart,rbrace.sourceEnd);}
+  )
   [
     assignToken = <ASSIGN>
     try {
@@ -915,19 +1016,15 @@ VariableDeclaration VariableDeclaratorNoSuffix() :
   {
   if (initializer == null) {
     return new VariableDeclaration(currentSegment,
-                                   new Variable(varName.image.substring(1),
-                                                varName.sourceStart+1,
-                                                varName.sourceEnd+1),
-                                   varName.sourceStart+1,
-                                   varName.sourceEnd+1);
+                                   variable,
+                                   variable.sourceStart,
+                                   variable.sourceEnd);
   }
   return new VariableDeclaration(currentSegment,
-                                 new Variable(varName.image.substring(1),
-                                              varName.sourceStart+1,
-                                              varName.sourceEnd+1),
+                                 variable,
                                  initializer,
                                  VariableDeclaration.EQUAL,
-                                 varName.sourceStart+1);
+                                 variable.sourceStart);
   }
 }
 
@@ -975,175 +1072,62 @@ VariableDeclaration VariableDeclarator() :
  */
 AbstractVariable VariableDeclaratorId() :
 {
-  final Variable var;
-  AbstractVariable expression = null;
+  AbstractVariable var;
 }
 {
   try {
     var = Variable()
     (
       LOOKAHEAD(2)
-      expression = VariableSuffix(var)
+      var = VariableSuffix(var)
     )*
     {
-     if (expression == null) {
-       return var;
-     }
-     return expression;
+     return var;
     }
   } catch (ParseException e) {
     errorMessage = "'$' expected for variable identifier";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
 }
 
-/**
- * Return a variablename without the $.
- * @return a variable name
- *//*
-Variable Variable():
-{
-  final StringBuffer buff;
-  Expression expression = null;
-  final Token token;
-  Variable expr;
-  final int pos;
-}
-{
-  token = <DOLLAR_ID>
-  [<LBRACE> expression = Expression() <RBRACE>]
-  {
-    if (expression == null) {
-      return new Variable(token.image.substring(1),
-                          token.sourceStart+1,
-                          token.sourceEnd+1);
-    }
-    String s = expression.toStringExpression();
-    buff = new StringBuffer(token.image.length()+s.length()+2);
-    buff.append(token.image);
-    buff.append("{");
-    buff.append(s);
-    buff.append("}");
-    s = buff.toString();
-    return new Variable(s,token.sourceStart+1,token.sourceEnd+1);
-  }
-|
-  token = <DOLLAR>
-  expr = VariableName()
-  {return new Variable(expr,token.sourceStart,expr.sourceEnd);}
-}   */
-
 Variable Variable() :
 {
   Variable variable = null;
   final Token token;
 }
 {
- token = <DOLLAR_ID> [variable = Var(token)]
-  {
-    if (variable == null) {
-      return new Variable(token.image.substring(1),token.sourceStart+1,token.sourceEnd+1);
-    }
-    final StringBuffer buff = new StringBuffer();
-    buff.append(token.image.substring(1));
-    buff.append(variable.toStringExpression());
-    return new Variable(buff.toString(),token.sourceStart+1,variable.sourceEnd+1);
-  }
-|
-  token = <DOLLAR> variable = Var(token)
+  token = <DOLLAR> variable = Var()
   {
-    return new Variable(variable,token.sourceStart,variable.sourceEnd);
+    return variable;
   }
 }
 
-Variable Var(final Token dollar) :
+Variable Var() :
 {
   Variable variable = null;
-  final Token token;
+  final Token token,token2;
   ConstantIdentifier constant;
+  Expression expression;
 }
 {
-  token = <DOLLAR_ID> [variable = Var(token)]
-  {if (variable == null) {
-     return new Variable(token.image.substring(1),token.sourceStart+1,token.sourceEnd+1);
-   }
-   final StringBuffer buff = new StringBuffer();
-   buff.append(token.image.substring(1));
-   buff.append(variable.toStringExpression());
-   return new Variable(buff.toString(),dollar.sourceStart,variable.sourceEnd);
-   }
-|
-  LOOKAHEAD(<DOLLAR> <DOLLAR>)
-  token = <DOLLAR> variable = Var(token)
-  {return new Variable(variable,dollar.sourceStart,variable.sourceEnd);}
+  token = <DOLLAR> variable = Var()
+  {return new Variable(variable,variable.sourceStart,variable.sourceEnd);}
 |
-  constant = VariableName()
-  {return new Variable(constant.name,dollar.sourceStart,constant.sourceEnd);}
-}
-
-/**
- * A Variable name (without the $)
- * @return a variable name String
- */
-ConstantIdentifier VariableName():
-{
-  final StringBuffer buff;
-  String expr;
-  Expression expression = null;
-  final Token token;
-  Token token2 = null;
-}
-{
   token = <LBRACE> expression = Expression() token2 = <RBRACE>
-  {expr = expression.toStringExpression();
-   buff = new StringBuffer(expr.length()+2);
-   buff.append("{");
-   buff.append(expr);
-   buff.append("}");
-   expr = buff.toString();
-   return new ConstantIdentifier(expr,
-                                 token.sourceStart,
-                                 token2.sourceEnd);
-
-   }
-|
-  token = <IDENTIFIER>
-  [<LBRACE> expression = Expression() token2 = <RBRACE>]
-  {
-    if (expression == null) {
-      return new ConstantIdentifier(token.image,
-                                    token.sourceStart,
-                                    token.sourceEnd);
-    }
-    expr = expression.toStringExpression();
-    buff = new StringBuffer(token.image.length()+expr.length()+2);
-    buff.append(token.image);
-    buff.append("{");
-    buff.append(expr);
-    buff.append("}");
-    expr = buff.toString();
-    return new ConstantIdentifier(expr,
-                                  token.sourceStart,
-                                  token2.sourceEnd);
-  }
-/*|
-  <DOLLAR>
-  var = VariableName()
   {
-    return new Variable(var,
-                        var.sourceStart-1,
-                        var.sourceEnd);
+   return new Variable(expression,
+                       token.sourceStart,
+                       token2.sourceEnd);
   }
 |
-  token = <DOLLAR_ID>
+  token = <IDENTIFIER>
   {
-  return new Variable(token.image,
-                      token.sourceStart+1,
-                      token.sourceEnd+1);
-  } */
+   outlineInfo.addVariable('$' + token.image);
+   return new Variable(token.image,token.sourceStart,token.sourceEnd);
+  }
 }
 
 Expression VariableInitializer() :
@@ -1182,7 +1166,7 @@ final Expression expr,expr2;
     <ARRAYASSIGN> expr2 = Expression()
     {return new ArrayVariableDeclaration(expr,expr2);}
   ]
-  {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
+  {return new ArrayVariableDeclaration(expr,jj_input_stream.getPosition());}
 }
 
 ArrayVariableDeclaration[] ArrayInitializer() :
@@ -1229,8 +1213,8 @@ MethodDeclaration MethodDeclaration() :
     if (errorMessage != null)  throw e;
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
   {currentSegment = functionDeclaration;}
@@ -1249,7 +1233,7 @@ MethodDeclaration MethodDeclarator(final int start) :
 {
   Token identifier = null;
   Token reference = null;
-  final Hashtable formalParameters = new Hashtable();
+  final ArrayList formalParameters = new ArrayList();
   String identifierChar = SYNTAX_ERROR_CHAR;
   int end = start;
 }
@@ -1298,11 +1282,11 @@ MethodDeclaration MethodDeclarator(final int start) :
  * FormalParameters follows method identifier.
  * (FormalParameter())
  */
-int FormalParameters(final Hashtable parameters) :
+int FormalParameters(final ArrayList parameters) :
 {
   VariableDeclaration var;
   final Token token;
-  Token tok = PHPParser.token;
+  Token tok = this.token;
   int end = tok.sourceEnd;
 }
 {
@@ -1318,10 +1302,10 @@ int FormalParameters(final Hashtable parameters) :
   }
   [
     var = FormalParameter()
-    {parameters.put(var.name(),var);end = var.sourceEnd;}
+    {parameters.add(var);end = var.sourceEnd;}
     (
       <COMMA> var = FormalParameter()
-      {parameters.put(var.name(),var);end = var.sourceEnd;}
+      {parameters.add(var);end = var.sourceEnd;}
     )*
   ]
   try {
@@ -1349,6 +1333,7 @@ VariableDeclaration FormalParameter() :
 {
   [token = <BIT_AND>] variableDeclaration = VariableDeclaratorNoSuffix()
   {
+    outlineInfo.addVariable('$'+variableDeclaration.name());
     if (token != null) {
       variableDeclaration.setReference(true);
     }
@@ -1388,7 +1373,7 @@ Expression Expression() :
       }
       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
       errorLevel   = ERROR;
-      errorEnd   = SimpleCharStream.getPosition();
+      errorEnd   = jj_input_stream.getPosition();
       throw e;
     }
   ]
@@ -1658,10 +1643,10 @@ Expression MultiplicativeExpression() :
     expr = UnaryExpression()
   } catch (ParseException e) {
     if (errorMessage != null) throw e;
-    errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
+    errorMessage = "unexpected token '"+e.currentToken.next.image+'\'';
     errorLevel   = ERROR;
-    errorStart = PHPParser.token.sourceStart;
-    errorEnd   = PHPParser.token.sourceEnd;
+    errorStart = this.token.sourceStart;
+    errorEnd   = this.token.sourceEnd;
     throw e;
   }
   (
@@ -1685,7 +1670,29 @@ Expression UnaryExpression() :
  /* <BIT_AND> expr = UnaryExpressionNoPrefix()             //why did I had that ?
   {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
 |      */
-  expr = AtNotUnaryExpression() {return expr;}
+  expr = AtNotTildeUnaryExpression() {return expr;}
+}
+
+Expression AtNotTildeUnaryExpression() :
+{
+  final Expression expr;
+  final Token token;
+}
+{
+  token = <AT>
+  expr = AtNotTildeUnaryExpression()
+  {return new PrefixedUnaryExpression(expr,OperatorIds.AT,token.sourceStart);}
+|
+  token = <TILDE>
+  expr = AtNotTildeUnaryExpression()
+  {return new PrefixedUnaryExpression(expr,OperatorIds.TWIDDLE,token.sourceStart);}
+|
+  token = <BANG>
+  expr = AtNotUnaryExpression()
+  {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,token.sourceStart);}
+|
+  expr = UnaryExpressionNoPrefix()
+  {return expr;}
 }
 
 /**
@@ -1716,11 +1723,11 @@ Expression UnaryExpressionNoPrefix() :
   final Token token;
 }
 {
-  token = <PLUS> expr = AtNotUnaryExpression()   {return new PrefixedUnaryExpression(expr,
+  token = <PLUS> expr = AtNotTildeUnaryExpression()   {return new PrefixedUnaryExpression(expr,
                                                                                      OperatorIds.PLUS,
                                                                                      token.sourceStart);}
 |
-  token = <MINUS> expr = AtNotUnaryExpression()  {return new PrefixedUnaryExpression(expr,
+  token = <MINUS> expr = AtNotTildeUnaryExpression()  {return new PrefixedUnaryExpression(expr,
                                                                                      OperatorIds.MINUS,
                                                                                      token.sourceStart);}
 |
@@ -1889,7 +1896,7 @@ ArrayInitializer ArrayDeclarator() :
   token = <ARRAY> vars = ArrayInitializer()
   {return new ArrayInitializer(vars,
                                token.sourceStart,
-                               PHPParser.token.sourceEnd);}
+                               this.token.sourceEnd);}
 }
 
 Expression ClassIdentifier():
@@ -1909,14 +1916,26 @@ Expression ClassIdentifier():
 AbstractVariable VariableSuffix(final AbstractVariable prefix) :
 {
   Expression expression = null;
-  final Token classAccessToken;
+  final Token classAccessToken,lbrace,rbrace;
   Token token;
   int pos;
 }
 {
   classAccessToken = <CLASSACCESS>
   try {
-    ( expression = VariableName() | expression = Variable() )
+    (
+      lbrace = <LBRACE> expression = Expression() rbrace = <RBRACE>
+                {
+                 expression = new Variable(expression,
+                                           lbrace.sourceStart,
+                                           rbrace.sourceEnd);
+                }
+      |
+        token = <IDENTIFIER>
+        {expression = new ConstantIdentifier(token.image,token.sourceStart,token.sourceEnd);}
+      |
+        expression = Variable()
+    )
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
     errorLevel   = ERROR;
@@ -1942,11 +1961,27 @@ AbstractVariable VariableSuffix(final AbstractVariable prefix) :
     processParseExceptionDebug(e);
   }
   {return new ArrayDeclarator(prefix,expression,pos);}
+|
+  token = <LBRACE> {pos = token.sourceEnd+1;}
+  [  expression = Expression() {pos = expression.sourceEnd+1;}
+   | expression = Type()       {pos = expression.sourceEnd+1;}]  //Not good
+  try {
+    token = <RBRACE>
+    {pos = token.sourceEnd;}
+  } catch (ParseException e) {
+    errorMessage = "']' expected";
+    errorLevel   = ERROR;
+    errorStart = pos;
+    errorEnd   = pos;
+    processParseExceptionDebug(e);
+  }
+  {return new ArrayDeclarator(prefix,expression,pos);}//todo : check braces here
 }
 
 Literal Literal() :
 {
   final Token token;
+  StringLiteral literal;
 }
 {
   token = <INTEGER_LITERAL>        {return new NumberLiteral(token);}
@@ -1955,26 +1990,70 @@ Literal Literal() :
 | token = <TRUE>                   {return new TrueLiteral(token);}
 | token = <FALSE>                  {return new FalseLiteral(token);}
 | token = <NULL>                   {return new NullLiteral(token);}
+| literal = evaluableString()        {return literal;}
+}
+
+StringLiteral evaluableString() :
+{
+  ArrayList list = new ArrayList();
+  Token start,end;
+  Token token,lbrace,rbrace;
+  AbstractVariable var;
+  Expression expr;
+}
+{
+  start = <DOUBLEQUOTE>
+  (
+   <DOLLARS>
+       (
+        token = <IDENTIFIER> {list.add(new Variable(token.image,
+                                                    token.sourceStart,
+                                                    token.sourceEnd));}
+        |
+         lbrace = <LBRACE1>
+         token = <ID>
+         {list.add(new Variable(token.image,
+                                token.sourceStart,
+                                token.sourceEnd));}
+         rbrace = <RBRACE1>
+       )
+   )*
+  end = <DOUBLEQUOTE2>
+  {
+  AbstractVariable[] vars = new AbstractVariable[list.size()];
+  list.toArray(vars);
+  return new StringLiteral(jj_input_stream.getCurrentBuffer().substring(start.sourceEnd,end.sourceStart),
+                           start.sourceStart,
+                           end.sourceEnd,
+                           vars);
+  }
 }
 
 FunctionCall Arguments(final Expression func) :
 {
 Expression[] args = null;
-final Token token;
+final Token token,lparen;
 }
 {
-  <LPAREN> [ args = ArgumentList() ]
+  lparen = <LPAREN> [ args = ArgumentList() ]
   try {
     token = <RPAREN>
     {return new FunctionCall(func,args,token.sourceEnd);}
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
     errorLevel   = ERROR;
-    errorStart = args[args.length-1].sourceEnd+1;
-    errorEnd   = args[args.length-1].sourceEnd+1;
+    if (args == null) {
+        errorStart = lparen.sourceEnd+1;
+        errorEnd   = lparen.sourceEnd+2;
+    } else {
+        errorStart = args[args.length-1].sourceEnd+1;
+        errorEnd   = args[args.length-1].sourceEnd+2;
+    }
     processParseExceptionDebug(e);
   }
-  {return new FunctionCall(func,args,args[args.length-1].sourceEnd);}
+  {
+  int sourceEnd = (args == null && args.length != 0) ? lparen.sourceEnd+1 : args[args.length-1].sourceEnd;
+  return new FunctionCall(func,args,sourceEnd);}
 }
 
 /**
@@ -2162,22 +2241,29 @@ HTMLBlock htmlBlock() :
   final int startIndex = nodePtr;
   final AstNode[] blockNodes;
   final int nbNodes;
+  final Token phpEnd;
 }
 {
-  <PHPEND> (phpEchoBlock())*
+  phpEnd = <PHPEND>
+  {htmlStart = phpEnd.sourceEnd;}
+  (phpEchoBlock())*
   try {
     (<PHPSTARTLONG> | <PHPSTARTSHORT>)
+    {createNewHTMLCode();}
   } catch (ParseException e) {
     errorMessage = "unexpected end of file , '<?php' expected";
     errorLevel   = ERROR;
-    errorStart   = SimpleCharStream.getPosition();
-    errorEnd     = SimpleCharStream.getPosition();
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
   {
   nbNodes    = nodePtr - startIndex;
+  if (nbNodes == 0) {
+    return null;
+  }
   blockNodes = new AstNode[nbNodes];
-  System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
+  System.arraycopy(nodes,startIndex+1,blockNodes,0,nbNodes);
   nodePtr = startIndex;
   return new HTMLBlock(blockNodes);}
 }
@@ -2200,35 +2286,37 @@ InclusionStatement IncludeStatement() :
        | token = <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;pos=token.sourceEnd;})
   try {
     expr = Expression()
-    {pos=expr.sourceEnd;}
+    {pos = expr.sourceEnd;}
   } catch (ParseException e) {
     if (errorMessage != null) {
       throw e;
     }
     errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
     errorLevel   = ERROR;
-    errorStart   = pos+1;
-    errorEnd     = pos+1;
+    errorStart   = e.currentToken.next.sourceStart;
+    errorEnd     = e.currentToken.next.sourceEnd;
     expr = new ConstantIdentifier(SYNTAX_ERROR_CHAR,pos,pos);
     processParseExceptionDebug(e);
   }
-  {inclusionStatement = new InclusionStatement(currentSegment,
-                                               keyword,
-                                               expr,
-                                               token.sourceStart);
-   currentSegment.add(inclusionStatement);
-  }
   try {
     token2 = <SEMICOLON>
+    {pos=token2.sourceEnd;}
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
     errorLevel   = ERROR;
-    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd     = SimpleCharStream.getPosition() + 1;
-    throw e;
+    errorStart   = e.currentToken.next.sourceStart;
+    errorEnd     = e.currentToken.next.sourceEnd;
+    processParseExceptionDebug(e);
+  }
+  {
+   inclusionStatement = new InclusionStatement(currentSegment,
+                                               keyword,
+                                               expr,
+                                               token.sourceStart,
+                                               pos);
+   currentSegment.add(inclusionStatement);
+   return inclusionStatement;
   }
-  {inclusionStatement.sourceEnd = token2.sourceEnd;
-  return inclusionStatement;}
 }
 
 PrintExpression PrintExpression() :
@@ -2441,14 +2529,20 @@ Block Block() :
   } catch (ParseException e) {
     errorMessage = "'{' expected";
     errorLevel   = ERROR;
-    pos = PHPParser.token.sourceEnd+1;
+    pos = this.token.sourceEnd+1;
     start=pos;
     errorStart = pos;
     errorEnd   = pos;
     processParseExceptionDebug(e);
   }
   ( statement = BlockStatement() {list.add(statement);pos = statement.sourceEnd+1;}
-  | statement = htmlBlock()      {list.add(statement);pos = statement.sourceEnd+1;})*
+  | statement = htmlBlock()      {if (statement != null) {
+                                    list.add(statement);
+                                    pos = statement.sourceEnd+1;
+                                  }
+                                  pos = this.token.sourceEnd+1;
+                                 }
+  )*
   try {
     token2 = <RBRACE>
     {pos = token2.sourceEnd+1;}
@@ -2623,7 +2717,7 @@ SwitchStatement SwitchStatement() :
   {return new SwitchStatement(variable,
                               cases,
                               switchToken.sourceStart,
-                              PHPParser.token.sourceEnd);}
+                              this.token.sourceEnd);}
 }
 
 AbstractCase[] switchStatementBrace() :
@@ -2652,6 +2746,7 @@ AbstractCase[] switchStatementBrace() :
     return abcase;
   }
 }
+
 /**
  * A Switch statement with : ... endswitch;
  * @param start the begin offset of the switch
@@ -2707,19 +2802,22 @@ AbstractCase switchLabel0() :
   final Expression expr;
   Statement statement;
   final ArrayList stmts = new ArrayList();
-  final Token token = PHPParser.token;
+  final Token token = this.token;
+  final int start = this.token.next.sourceStart;
 }
 {
   expr = SwitchLabel()
   ( statement = BlockStatementNoBreak() {stmts.add(statement);}
-  | statement = htmlBlock()             {stmts.add(statement);})*
-  [ statement = BreakStatement()        {stmts.add(statement);}]
+  | statement = htmlBlock()             {if (statement != null) {stmts.add(statement);}}
+  | statement = BreakStatement()        {stmts.add(statement);})*
+  //[ statement = BreakStatement()        {stmts.add(statement);}]
   {
     final int listSize = stmts.size();
     final Statement[] stmtsArray = new Statement[listSize];
     stmts.toArray(stmtsArray);
     if (expr == null) {//it's a default
-      return new DefaultCase(stmtsArray,token.sourceStart,stmtsArray[listSize-1].sourceEnd);
+      final int end = this.token.next.sourceStart;
+      return new DefaultCase(stmtsArray,start,end);
     }
     if (listSize != 0) {
       return new Case(expr,stmtsArray,expr.sourceStart,stmtsArray[listSize-1].sourceEnd);
@@ -2753,7 +2851,6 @@ Expression SwitchLabel() :
   }
   try {
     token = <COLON>
-    {return expr;}
   } catch (ParseException e) {
     errorMessage = "':' expected after case expression";
     errorLevel   = ERROR;
@@ -2761,11 +2858,11 @@ Expression SwitchLabel() :
     errorEnd   = expr.sourceEnd+1;
     processParseExceptionDebug(e);
   }
+  {return expr;}
 |
   token = <_DEFAULT>
   try {
     <COLON>
-    {return null;}
   } catch (ParseException e) {
     errorMessage = "':' expected after 'default' keyword";
     errorLevel   = ERROR;
@@ -2773,6 +2870,7 @@ Expression SwitchLabel() :
     errorEnd   = token.sourceEnd+1;
     processParseExceptionDebug(e);
   }
+  {return null;}
 }
 
 Break BreakStatement() :
@@ -2820,8 +2918,8 @@ Expression Condition(final String keyword) :
   } catch (ParseException e) {
     errorMessage = "'(' expected after " + keyword + " keyword";
     errorLevel   = ERROR;
-    errorStart = PHPParser.token.sourceEnd + 1;
-    errorEnd   = PHPParser.token.sourceEnd + 1;
+    errorStart = this.token.sourceEnd + 1;
+    errorEnd   = this.token.sourceEnd + 1;
     processParseExceptionDebug(e);
   }
   condition = Expression()
@@ -2847,15 +2945,15 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e
   final ArrayList stmts;
   final ArrayList elseIfList = new ArrayList();
   final ElseIf[] elseIfs;
-  int pos = SimpleCharStream.getPosition();
+  int pos = jj_input_stream.getPosition();
   final int endStatements;
 }
 {
   <COLON>
   {stmts = new ArrayList();}
   (  statement = Statement() {stmts.add(statement);}
-   | statement = htmlBlock() {stmts.add(statement);})*
-   {endStatements = SimpleCharStream.getPosition();}
+   | statement = htmlBlock() {if (statement != null) {stmts.add(statement);}})*
+   {endStatements = jj_input_stream.getPosition();}
    (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
    [elseStatement = ElseStatementColon()]
 
@@ -2874,8 +2972,8 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e
   } catch (ParseException e) {
     errorMessage = "'endif' expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
   try {
@@ -2883,8 +2981,8 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e
   } catch (ParseException e) {
     errorMessage = "';' expected after 'endif' keyword";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
     {
@@ -2896,7 +2994,7 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e
                               elseIfs,
                               elseStatement,
                               pos,
-                              SimpleCharStream.getPosition());
+                              jj_input_stream.getPosition());
     } else {
       statementsArray = new Statement[stmts.size()];
       stmts.toArray(statementsArray);
@@ -2905,7 +3003,7 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e
                              elseIfs,
                              elseStatement,
                              pos,
-                             SimpleCharStream.getPosition());
+                             jj_input_stream.getPosition());
     }
     }
 
@@ -2915,17 +3013,17 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e
   [ LOOKAHEAD(1)
     <ELSE>
     try {
-      {pos = SimpleCharStream.getPosition();}
+      {pos = jj_input_stream.getPosition();}
       statement = Statement()
-      {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
+      {elseStatement = new Else(statement,pos,jj_input_stream.getPosition());}
     } catch (ParseException e) {
       if (errorMessage != null) {
         throw e;
       }
       errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
       errorLevel   = ERROR;
-      errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = SimpleCharStream.getPosition() + 1;
+      errorStart = e.currentToken.sourceStart;
+      errorEnd   = e.currentToken.sourceEnd;
       throw e;
     }
   ]
@@ -2937,7 +3035,7 @@ IfStatement IfStatement0(final Expression condition, final int start,final int e
                            elseIfs,
                            elseStatement,
                            pos,
-                           SimpleCharStream.getPosition());}
+                           jj_input_stream.getPosition());}
 }
 
 ElseIf ElseIfStatementColon() :
@@ -2950,7 +3048,7 @@ ElseIf ElseIfStatementColon() :
 {
   elseifToken = <ELSEIF> condition = Condition("elseif")
   <COLON> (  statement = Statement() {list.add(statement);}
-           | statement = htmlBlock() {list.add(statement);})*
+           | statement = htmlBlock() {if (statement != null) {list.add(statement);}})*
   {
   final int sizeList = list.size();
   final Statement[] stmtsArray = new Statement[sizeList];
@@ -2968,7 +3066,7 @@ Else ElseStatementColon() :
 }
 {
   elseToken = <ELSE> <COLON> (  statement = Statement() {list.add(statement);}
-                  | statement = htmlBlock() {list.add(statement);})*
+                  | statement = htmlBlock() {if (statement != null) {list.add(statement);}})*
   {
   final int sizeList = list.size();
   final Statement[] stmtsArray = new Statement[sizeList];
@@ -3006,7 +3104,7 @@ Statement WhileStatement0(final int start, final int end) :
 {
   Statement statement;
   final ArrayList stmts = new ArrayList();
-  final int pos = SimpleCharStream.getPosition();
+  final int pos = jj_input_stream.getPosition();
 }
 {
   <COLON> (statement = Statement() {stmts.add(statement);})*
@@ -3025,8 +3123,8 @@ Statement WhileStatement0(final int start, final int end) :
   } catch (ParseException e) {
     errorMessage = "'endwhile' expected";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
   try {
@@ -3034,12 +3132,12 @@ Statement WhileStatement0(final int start, final int end) :
     {
     final Statement[] stmtsArray = new Statement[stmts.size()];
     stmts.toArray(stmtsArray);
-    return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
+    return new Block(stmtsArray,pos,jj_input_stream.getPosition());}
   } catch (ParseException e) {
     errorMessage = "';' expected after 'endwhile' keyword";
     errorLevel   = ERROR;
-    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = SimpleCharStream.getPosition() + 1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     throw e;
   }
 |
@@ -3092,8 +3190,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "'(' expected after 'foreach' keyword";
     errorLevel   = ERROR;
-    errorStart = foreachToken.sourceEnd+1;
-    errorEnd   = foreachToken.sourceEnd+1;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
     {pos = foreachToken.sourceEnd+1;}
   }
@@ -3103,8 +3201,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "variable expected";
     errorLevel   = ERROR;
-    errorStart = pos;
-    errorEnd   = pos;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   try {
@@ -3113,8 +3211,8 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "'as' expected";
     errorLevel   = ERROR;
-    errorStart = pos;
-    errorEnd   = pos;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   try {
@@ -3124,8 +3222,8 @@ ForeachStatement ForeachStatement() :
     if (errorMessage != null) throw e;
     errorMessage = "variable expected";
     errorLevel   = ERROR;
-    errorStart = pos;
-    errorEnd   = pos;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   try {
@@ -3134,26 +3232,27 @@ ForeachStatement ForeachStatement() :
   } catch (ParseException e) {
     errorMessage = "')' expected after 'foreach' keyword";
     errorLevel   = ERROR;
-    errorStart = pos;
-    errorEnd   = pos;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
   try {
     statement = Statement()
-    {pos = rparenToken.sourceEnd+1;}
+    {pos = statement.sourceEnd+1;}
   } catch (ParseException e) {
     if (errorMessage != null) throw e;
     errorMessage = "statement expected";
     errorLevel   = ERROR;
-    errorStart = pos;
-    errorEnd   = pos;
+    errorStart = e.currentToken.sourceStart;
+    errorEnd   = e.currentToken.sourceEnd;
     processParseExceptionDebug(e);
   }
-  {return new ForeachStatement(expression,
+  {
+   return new ForeachStatement(expression,
                                variable,
                                statement,
                                foreachToken.sourceStart,
-                               statement.sourceEnd);}
+                               pos);}
 
 }