X-Git-Url: http://secure.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj
index 0eb3056..92e62c8 100644
--- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj
+++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj
@@ -1,3 +1,4 @@
+
 options {
   LOOKAHEAD = 1;
   CHOICE_AMBIGUITY_CHECK = 2;
@@ -17,6 +18,7 @@ options {
   BUILD_TOKEN_MANAGER = true;
   SANITY_CHECK = true;
   FORCE_LA_CHECK = false;
+  COMMON_TOKEN_ACTION = true;
 }
 
 PARSER_BEGIN(PHPParser)
@@ -29,7 +31,6 @@ import org.eclipse.ui.texteditor.MarkerUtilities;
 import org.eclipse.jface.preference.IPreferenceStore;
 
 import java.util.Hashtable;
-import java.util.Enumeration;
 import java.util.ArrayList;
 import java.io.StringReader;
 import java.io.*;
@@ -39,7 +40,9 @@ import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpdt.internal.compiler.ast.*;
 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
+import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
+import net.sourceforge.phpdt.internal.corext.Assert;
 
 /**
  * A new php parser.
@@ -50,8 +53,9 @@ import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
  */
 public final class PHPParser extends PHPParserSuperclass {
 
-  /** The file that is parsed. */
-  private static IFile fileToParse;
+//todo : fix the variables names bug
+//todo : handle tilde operator
+
 
   /** The current segment. */
   private static OutlineableWithChildren currentSegment;
@@ -60,9 +64,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. */
   private static int errorLevel = ERROR;
   /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
@@ -71,6 +72,8 @@ public final class PHPParser extends PHPParserSuperclass {
   private static int errorStart = -1;
   private static int errorEnd = -1;
   private static PHPDocument phpDocument;
+
+  private static final String SYNTAX_ERROR_CHAR = "syntax error";
   /**
    * The point where html starts.
    * It will be used by the token manager to create HTMLCode objects
@@ -83,15 +86,11 @@ public final class PHPParser extends PHPParserSuperclass {
   private static AstNode[] nodes;
   /** The cursor in expression stack. */
   private static int nodePtr;
-  private static VariableDeclaration[] variableDeclarationStack;
-  private static int variableDeclarationPtr;
-  private static Statement[] statementStack;
-  private static int statementPtr;
-  private static ElseIf[] elseIfStack;
-  private static int elseIfPtr;
+
+  public static final boolean PARSER_DEBUG = true;
 
   public final void setFileToParse(final IFile fileToParse) {
-    this.fileToParse = fileToParse;
+    PHPParser.fileToParse = fileToParse;
   }
 
   public PHPParser() {
@@ -99,7 +98,47 @@ public final class PHPParser extends PHPParserSuperclass {
 
   public PHPParser(final IFile fileToParse) {
     this(new StringReader(""));
-    this.fileToParse = fileToParse;
+    PHPParser.fileToParse = fileToParse;
+  }
+
+  public static 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);
+    }
+    ReInit(new StringReader(strEval));
+    init();
+    phpDocument = new PHPDocument(null,"_root".toCharArray());
+    currentSegment = phpDocument;
+    outlineInfo = new PHPOutlineInfo(null, currentSegment);
+    PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
+    phpTest();
+  }
+
+  public static 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);
+    }
+    ReInit(stream);
+    init();
+    phpDocument = new PHPDocument(null,"_root".toCharArray());
+    currentSegment = phpDocument;
+    outlineInfo = new PHPOutlineInfo(null, currentSegment);
+    phpFile();
+  }
+
+  public static 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);
+    }
+    ReInit(stream);
+    init();
+    phpDocument = new PHPDocument(null,"_root".toCharArray());
+    currentSegment = phpDocument;
+    outlineInfo = new PHPOutlineInfo(null, currentSegment);
+    phpFile();
   }
 
   /**
@@ -107,11 +146,7 @@ public final class PHPParser extends PHPParserSuperclass {
    */
   private static final void init() {
     nodes = new AstNode[AstStackIncrement];
-    statementStack = new Statement[AstStackIncrement];
-    elseIfStack = new ElseIf[AstStackIncrement];
     nodePtr = -1;
-    statementPtr = -1;
-    elseIfPtr = -1;
     htmlStart = 0;
   }
 
@@ -119,12 +154,12 @@ public final class PHPParser extends PHPParserSuperclass {
    * Add an php node on the stack.
    * @param node the node that will be added to the stack
    */
-  private static final void pushOnAstNodes(AstNode node) {
+  private static final void pushOnAstNodes(final AstNode node) {
     try {
       nodes[++nodePtr] = node;
     } catch (IndexOutOfBoundsException e) {
-      int oldStackLength = nodes.length;
-      AstNode[] oldStack = nodes;
+      final int oldStackLength = nodes.length;
+      final AstNode[] oldStack = nodes;
       nodes = new AstNode[oldStackLength + AstStackIncrement];
       System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
       nodePtr = oldStackLength;
@@ -132,83 +167,10 @@ public final class PHPParser extends PHPParserSuperclass {
     }
   }
 
-  private static final void pushOnVariableDeclarationStack(VariableDeclaration var) {
-    try {
-      variableDeclarationStack[++variableDeclarationPtr] = var;
-    } catch (IndexOutOfBoundsException e) {
-      int oldStackLength = variableDeclarationStack.length;
-      VariableDeclaration[] oldStack = variableDeclarationStack;
-      variableDeclarationStack = new VariableDeclaration[oldStackLength + AstStackIncrement];
-      System.arraycopy(oldStack, 0, variableDeclarationStack, 0, oldStackLength);
-      variableDeclarationPtr = oldStackLength;
-      variableDeclarationStack[variableDeclarationPtr] = var;
-    }
-  }
-
-  private static final void pushOnStatementStack(Statement statement) {
-    try {
-      statementStack[++statementPtr] = statement;
-    } catch (IndexOutOfBoundsException e) {
-      int oldStackLength = statementStack.length;
-      Statement[] oldStack = statementStack;
-      statementStack = new Statement[oldStackLength + AstStackIncrement];
-      System.arraycopy(oldStack, 0, statementStack, 0, oldStackLength);
-      statementPtr = oldStackLength;
-      statementStack[statementPtr] = statement;
-    }
-  }
-
-  private static final void pushOnElseIfStack(ElseIf elseIf) {
-    try {
-      elseIfStack[++elseIfPtr] = elseIf;
-    } catch (IndexOutOfBoundsException e) {
-      int oldStackLength = elseIfStack.length;
-      ElseIf[] oldStack = elseIfStack;
-      elseIfStack = new ElseIf[oldStackLength + AstStackIncrement];
-      System.arraycopy(oldStack, 0, elseIfStack, 0, oldStackLength);
-      elseIfPtr = oldStackLength;
-      elseIfStack[elseIfPtr] = elseIf;
-    }
-  }
-
-  public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
-    PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
-    final StringReader stream = new StringReader(strEval);
-    if (jj_input_stream == null) {
-      jj_input_stream = new SimpleCharStream(stream, 1, 1);
-    }
-    ReInit(new StringReader(strEval));
-    init();
-    phpTest();
-  }
-
-  public static final void htmlParserTester(final File fileName) throws CoreException, ParseException {
-    try {
-      final Reader stream = new FileReader(fileName);
-      if (jj_input_stream == null) {
-        jj_input_stream = new SimpleCharStream(stream, 1, 1);
-      }
-      ReInit(stream);
-      init();
-      phpFile();
-    } catch (FileNotFoundException e) {
-      e.printStackTrace();  //To change body of catch statement use Options | File Templates.
-    }
-  }
-
-  public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
-    final StringReader stream = new StringReader(strEval);
-    if (jj_input_stream == null) {
-      jj_input_stream = new SimpleCharStream(stream, 1, 1);
-    }
-    ReInit(stream);
-    init();
-    phpFile();
-  }
-
   public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
-    currentSegment = new PHPDocument(parent);
-    outlineInfo = new PHPOutlineInfo(parent);
+    phpDocument = new PHPDocument(parent,"_root".toCharArray());
+    currentSegment = phpDocument;
+    outlineInfo = new PHPOutlineInfo(parent, currentSegment);
     final StringReader stream = new StringReader(s);
     if (jj_input_stream == null) {
       jj_input_stream = new SimpleCharStream(stream, 1, 1);
@@ -217,9 +179,11 @@ public final class PHPParser extends PHPParserSuperclass {
     init();
     try {
       parse();
-      phpDocument = new PHPDocument(null);
-      phpDocument.nodes = nodes;
-      PHPeclipsePlugin.log(1,phpDocument.toString());
+      phpDocument.nodes = new AstNode[nodes.length];
+      System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
+      if (PHPeclipsePlugin.DEBUG) {
+        PHPeclipsePlugin.log(1,phpDocument.toString());
+      }
     } catch (ParseException e) {
       processParseException(e);
     }
@@ -227,6 +191,19 @@ public final class PHPParser extends PHPParserSuperclass {
   }
 
   /**
+   * This function will throw the exception if we are in debug mode
+   * and process it if we are in production mode.
+   * this should be fast since the PARSER_DEBUG is static final so the difference will be at compile time
+   * @param e the exception
+   * @throws ParseException the thrown exception
+   */
+  private static void processParseExceptionDebug(final ParseException e) throws ParseException {
+    if (PARSER_DEBUG) {
+      throw e;
+    }
+    processParseException(e);
+  }
+  /**
    * This method will process the parse exception.
    * If the error message is null, the parse exception wasn't catched and a trace is written in the log
    * @param e the ParseException
@@ -235,15 +212,16 @@ 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();
-      errorEnd   = errorStart + 1;
+      errorStart = e.currentToken.sourceStart;
+      errorEnd   = e.currentToken.sourceEnd;
     }
     setMarker(e);
     errorMessage = null;
+  //  if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e);
   }
 
   /**
-   * Create marker for the parse error
+   * Create marker for the parse error.
    * @param e the ParseException
    */
   private static void setMarker(final ParseException e) {
@@ -251,17 +229,17 @@ public final class PHPParser extends PHPParserSuperclass {
       if (errorStart == -1) {
         setMarker(fileToParse,
                   errorMessage,
-                  jj_input_stream.tokenBegin,
-                  jj_input_stream.tokenBegin + e.currentToken.image.length(),
+                  e.currentToken.sourceStart,
+                  e.currentToken.sourceEnd,
                   errorLevel,
-                  "Line " + e.currentToken.beginLine);
+                  "Line " + e.currentToken.beginLine+", "+e.currentToken.sourceStart+":"+e.currentToken.sourceEnd);
       } else {
         setMarker(fileToParse,
                   errorMessage,
                   errorStart,
                   errorEnd,
                   errorLevel,
-                  "Line " + e.currentToken.beginLine);
+                  "Line " + e.currentToken.beginLine+", "+errorStart+":"+errorEnd);
         errorStart = -1;
         errorEnd = -1;
       }
@@ -270,42 +248,17 @@ public final class PHPParser extends PHPParserSuperclass {
     }
   }
 
-  /**
-   * Create markers according to the external parser output
-   */
-  private static void createMarkers(final String output, final IFile file) throws CoreException {
-    // delete all markers
-    file.deleteMarkers(IMarker.PROBLEM, false, 0);
-
-    int indx = 0;
-    int brIndx;
-    boolean flag = true;
-    while ((brIndx = output.indexOf("
", indx)) != -1) {
-      // newer php error output (tested with 4.2.3)
-      scanLine(output, file, indx, brIndx);
-      indx = brIndx + 6;
-      flag = false;
-    }
-    if (flag) {
-      while ((brIndx = output.indexOf("
", indx)) != -1) {
-        // older php error output (tested with 4.2.3)
-        scanLine(output, file, indx, brIndx);
-        indx = brIndx + 4;
-      }
-    }
-  }
-
   private static void scanLine(final String output,
                                final IFile file,
                                final int indx,
                                final int brIndx) throws CoreException {
     String current;
-    StringBuffer lineNumberBuffer = new StringBuffer(10);
+    final StringBuffer lineNumberBuffer = new StringBuffer(10);
     char ch;
     current = output.substring(indx, brIndx);
 
     if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
-      int onLine = current.indexOf("on line ");
+      final int onLine = current.indexOf("on line ");
       if (onLine != -1) {
         lineNumberBuffer.delete(0, lineNumberBuffer.length());
         for (int i = onLine; i < current.length(); i++) {
@@ -315,9 +268,9 @@ public final class PHPParser extends PHPParserSuperclass {
           }
         }
 
-        int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
+        final int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
 
-        Hashtable attributes = new Hashtable();
+        final Hashtable attributes = new Hashtable();
 
         current = current.replaceAll("\n", "");
         current = current.replaceAll("", "");
@@ -336,7 +289,7 @@ public final class PHPParser extends PHPParserSuperclass {
     }
   }
 
-  public final void parse(final String s) throws CoreException {
+  public final void parse(final String s) {
     final StringReader stream = new StringReader(s);
     if (jj_input_stream == null) {
       jj_input_stream = new SimpleCharStream(stream, 1, 1);
@@ -376,14 +329,35 @@ public final class PHPParser extends PHPParserSuperclass {
    * Put a new html block in the stack.
    */
   public static final void createNewHTMLCode() {
-    final int currentPosition = SimpleCharStream.getPosition();
-    if (currentPosition == htmlStart) {
+    final int currentPosition = token.sourceStart;
+    if (currentPosition == htmlStart ||
+          currentPosition < htmlStart ||
+          currentPosition > SimpleCharStream.currentBuffer.length()) {
       return;
     }
-    final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition).toCharArray();
+    final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,
+                                                                  currentPosition).toCharArray();
     pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
   }
 
+  /** Create a new task. */
+  public static final void createNewTask(final int todoStart) {
+    final String  todo = SimpleCharStream.currentBuffer.substring(todoStart,
+                                                                  SimpleCharStream.currentBuffer.indexOf("\n",
+                                                                                                         todoStart)-1);
+    if (!PARSER_DEBUG) {
+      try {
+        setMarker(fileToParse,
+                  todo,
+                  SimpleCharStream.getBeginLine(),
+                  TASK,
+                  "Line "+SimpleCharStream.getBeginLine());
+      } catch (CoreException e) {
+        PHPeclipsePlugin.log(e);
+      }
+    }
+  }
+
   private static final void parse() throws ParseException {
 	  phpFile();
   }
@@ -391,16 +365,28 @@ public final class PHPParser extends PHPParserSuperclass {
 
 PARSER_END(PHPParser)
 
+TOKEN_MGR_DECLS:
+{
+  // CommonTokenAction: use the begins/ends fields added to the Jack
+  // 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;
+  } // CommonTokenAction
+} // TOKEN_MGR_DECLS
+
  TOKEN :
 {
-      {PHPParser.createNewHTMLCode();} : PHPPARSING
-|  {PHPParser.createNewHTMLCode();} : PHPPARSING
-|    {PHPParser.createNewHTMLCode();} : PHPPARSING
+      : PHPPARSING
+|  : PHPPARSING
+|    : PHPPARSING
 }
 
- TOKEN :
+ TOKEN :
 {
-  "> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
+  "> : DEFAULT
 }
 
 /* Skip any character if we are not in php mode */
@@ -420,38 +406,47 @@ PARSER_END(PHPParser)
 | "\f"
 }
 
+ SPECIAL_TOKEN :
+{
+  " " : PHPPARSING
+| "\t" : PHPPARSING
+| "\n" : PHPPARSING
+| "\r" : PHPPARSING
+| "\f" : PHPPARSING
+}
 /* COMMENTS */
  SPECIAL_TOKEN :
 {
   "//" : IN_SINGLE_LINE_COMMENT
-|
-  "#"  : IN_SINGLE_LINE_COMMENT
-|
-  <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
-|
-  "/*" : IN_MULTI_LINE_COMMENT
+| "#"  : IN_SINGLE_LINE_COMMENT
+| <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
+| "/*" : IN_MULTI_LINE_COMMENT
 }
 
  SPECIAL_TOKEN :
 {
    : PHPPARSING
+| < ~[] >
 }
 
- SPECIAL_TOKEN :
+ SPECIAL_TOKEN :
 {
-  " > : DEFAULT
+ "todo"
 }
 
-
-SPECIAL_TOKEN :
+void todo() :
+{Token todoToken;}
 {
-   : PHPPARSING
+  todoToken = "TODO" {createNewTask(todoToken.sourceStart);}
+}
+ SPECIAL_TOKEN :
+{
+  "*/" : PHPPARSING
 }
 
-
-SPECIAL_TOKEN :
+ SPECIAL_TOKEN :
 {
-   : PHPPARSING
+  "*/" : PHPPARSING
 }
 
 
@@ -484,10 +479,15 @@ MORE :
 | 
 | 
 | 
+| 
 | 
-| ">
-| 
-| ">
+}
+
+ TOKEN :
+{
+  "> : PHPPARSING
+|  : PHPPARSING
+| "> : PHPPARSING
 }
 
 /* RESERVED WORDS AND LITERALS */
@@ -534,97 +534,76 @@ MORE :
 }
 
 //Misc token
- TOKEN :
+ TOKEN :
 {
-  
-| 
-| 
-| 
-| 
-| 
+   : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
 }
 
 /* OPERATORS */
- TOKEN :
-{
-  
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| >">
-| >>">
-| <_ORL               : "OR">
-| <_ANDL              : "AND">
+ TOKEN :
+{
+   : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|   : PHPPARSING
+|  : PHPPARSING
+| >"> : PHPPARSING
+| >>"> : PHPPARSING
+| <_ORL               : "OR"> : PHPPARSING
+| <_ANDL              : "AND"> : PHPPARSING
 }
 
 /* LITERALS */
  TOKEN :
 {
-  < INTEGER_LITERAL:
+   (["l","L"])?
       |  (["l","L"])?
       |  (["l","L"])?
   >
 |
-  < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
+  <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
 |
-  < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
+  <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
 |
-  < #OCTAL_LITERAL: "0" (["0"-"7"])* >
+  <#OCTAL_LITERAL: "0" (["0"-"7"])* >
 |
-  < FLOATING_POINT_LITERAL:
+  )? (["f","F","d","D"])?
       | "." (["0"-"9"])+ ()? (["f","F","d","D"])?
       | (["0"-"9"])+  (["f","F","d","D"])?
       | (["0"-"9"])+ ()? ["f","F","d","D"]
   >
 |
-  < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
+  <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
 |
-  < STRING_LITERAL: ( |  | )>
-|    < STRING_1:
-      "\""
-      (
-          ~["\"","{","}"]
-        | "\\\""
-        | "\\"
-        | "{" ~["\""] "}"
-      )*
-      "\""
-    >
-|    < STRING_2:
-      "'"
-      (
-         ~["'"]
-       | "\\'"
-      )*
-
-      "'"
-    >
-|   < STRING_3:
-      "`"
-      (
-        ~["`"]
-      | "\\`"
-      )*
-      "`"
-    >
+   |  | )>
+|   
+|   
+|   
 }
 
 /* IDENTIFIERS */
 
- TOKEN :
+
+ TOKEN : { : IN_VARIABLE}
+
+
+ TOKEN :
 {
-  < IDENTIFIER: (|) (||)* >
+  |) (||)* >
 |
   < #LETTER:
       ["a"-"z"] | ["A"-"Z"]
@@ -641,55 +620,50 @@ MORE :
 
 /* SEPARATORS */
 
- TOKEN :
+ TOKEN :
 {
-  
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| 
+   : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
 }
 
 
 /* COMPARATOR */
- TOKEN :
+ TOKEN :
 {
-  ">
-| 
-| 
-| 
-| =">
-| 
-| ">
-| 
-| 
+  "> : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+| ="> : PHPPARSING
+|  : PHPPARSING
+| "> : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
 }
 
 /* ASSIGNATION */
- TOKEN :
-{
-  
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| 
-| >=">
-}
-
- TOKEN :
-{
-  < DOLLAR_ID:    >
+ TOKEN :
+{
+   : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+|  : PHPPARSING
+| >="> : PHPPARSING
 }
 
 void phpTest() :
@@ -697,7 +671,6 @@ void phpTest() :
 {
   Php()
   
-  {PHPParser.createNewHTMLCode();}
 }
 
 void phpFile() :
@@ -705,11 +678,11 @@ void phpFile() :
 {
   try {
     (PhpBlock())*
-    
+    {PHPParser.createNewHTMLCode();}
   } catch (TokenMgrError e) {
     PHPeclipsePlugin.log(e);
-    errorStart   = SimpleCharStream.getPosition();
-    errorEnd     = errorStart + 1;
+    errorStart   = SimpleCharStream.beginOffset;
+    errorEnd     = SimpleCharStream.endOffset;
     errorMessage = e.getMessage();
     errorLevel   = ERROR;
     throw generateParseException();
@@ -723,46 +696,53 @@ void phpFile() :
  */
 void PhpBlock() :
 {
-  final int start = jj_input_stream.getPosition();
+  final PHPEchoBlock phpEchoBlock;
+  final Token token,phpEnd;
 }
 {
-  phpEchoBlock()
+  phpEchoBlock = phpEchoBlock()
+  {pushOnAstNodes(phpEchoBlock);}
 |
-  [ 
-    | 
+  [   
+    | token = 
     {try {
       setMarker(fileToParse,
                 "You should use '
+    phpEnd = 
+   {htmlStart = phpEnd.sourceEnd;}
   } 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;
+    processParseExceptionDebug(e);
   }
 }
 
 PHPEchoBlock phpEchoBlock() :
 {
   final Expression expr;
-  final int pos = SimpleCharStream.getPosition();
-  PHPEchoBlock echoBlock;
+  final PHPEchoBlock echoBlock;
+  final Token token, token2;
 }
 {
-   expr = Expression() [  ] 
+  token =  {PHPParser.createNewHTMLCode();}
+  expr = Expression() [  ] token2 = 
   {
-  echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
+  htmlStart = token2.sourceEnd;
+
+  echoBlock = new PHPEchoBlock(expr,token.sourceStart,token2.sourceEnd);
   pushOnAstNodes(echoBlock);
   return echoBlock;}
 }
@@ -776,162 +756,246 @@ void Php() :
 ClassDeclaration ClassDeclaration() :
 {
   final ClassDeclaration classDeclaration;
-  final Token className;
-  Token superclassName = null;
-  final int pos;
+  Token className = null;
+  final Token superclassName, token, extendsToken;
+  String classNameImage = SYNTAX_ERROR_CHAR;
+  String superclassNameImage = null;
+  final int classEnd;
 }
 {
-  
+  token = 
   try {
-    {pos = jj_input_stream.getPosition();}
     className = 
+    {classNameImage = className.image;}
   } 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   = token.sourceEnd+1;
+    errorEnd     = token.sourceEnd+1;
+    processParseExceptionDebug(e);
   }
   [
-    
+    extendsToken = 
     try {
       superclassName = 
+      {superclassNameImage = superclassName.image;}
     } 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 = extendsToken.sourceEnd+1;
+      errorEnd   = extendsToken.sourceEnd+1;
+      processParseExceptionDebug(e);
+      superclassNameImage = SYNTAX_ERROR_CHAR;
     }
   ]
   {
-    if (superclassName == null) {
+    int start, end;
+    if (className == null) {
+      start = token.sourceStart;
+      end = token.sourceEnd;
+    } else {
+      start = className.sourceStart;
+      end = className.sourceEnd;
+    }
+    if (superclassNameImage == null) {
+
       classDeclaration = new ClassDeclaration(currentSegment,
-                                              className.image.toCharArray(),
-                                              pos,
-                                              0);
+                                              classNameImage,
+                                              start,
+                                              end);
     } else {
       classDeclaration = new ClassDeclaration(currentSegment,
-                                              className.image.toCharArray(),
-                                              superclassName.image.toCharArray(),
-                                              pos,
-                                              0);
+                                              classNameImage,
+                                              superclassNameImage,
+                                              start,
+                                              end);
     }
       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(ClassDeclaration classDeclaration) :
-{}
+int ClassBody(final ClassDeclaration classDeclaration) :
+{
+Token token;
+}
 {
   try {
     
   } catch (ParseException e) {
-    errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
+    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;
-    throw e;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    processParseExceptionDebug(e);
   }
   ( ClassBodyDeclaration(classDeclaration) )*
   try {
-    
+    token = 
+    {return token.sourceEnd;}
   } catch (ParseException e) {
-    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
+    processParseExceptionDebug(e);
+    return PHPParser.token.sourceEnd;
   }
 }
 
 /**
  * A class can contain only methods and fields.
  */
-void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
+void ClassBodyDeclaration(final ClassDeclaration classDeclaration) :
 {
-  MethodDeclaration method;
-  FieldDeclaration field;
+  final MethodDeclaration method;
+  final FieldDeclaration field;
 }
 {
-  method = MethodDeclaration() {classDeclaration.addMethod(method);}
-| field = FieldDeclaration()   {classDeclaration.addVariable(field);}
+  method = MethodDeclaration() {method.analyzeCode();
+                                classDeclaration.addMethod(method);}
+| field = FieldDeclaration()   {classDeclaration.addField(field);}
 }
 
 /**
  * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
+ * it is only used by ClassBodyDeclaration()
  */
 FieldDeclaration FieldDeclaration() :
 {
   VariableDeclaration variableDeclaration;
-  VariableDeclaration[] list;
+  final VariableDeclaration[] list;
   final ArrayList arrayList = new ArrayList();
-  final int pos = SimpleCharStream.getPosition();
+  final Token token;
+  Token token2 = null;
+  int pos;
 }
 {
-   variableDeclaration = VariableDeclarator()
-  {arrayList.add(variableDeclaration);
-   outlineInfo.addVariable(new String(variableDeclaration.name));
-   currentSegment.add(variableDeclaration);}
-  (  variableDeclaration = VariableDeclarator()
-      {arrayList.add(variableDeclaration);
-       outlineInfo.addVariable(new String(variableDeclaration.name));
-       currentSegment.add(variableDeclaration);}
+  token =  variableDeclaration = VariableDeclaratorNoSuffix()
+  {
+    arrayList.add(variableDeclaration);
+    outlineInfo.addVariable(variableDeclaration.name());
+    pos = variableDeclaration.sourceEnd;
+  }
+  (
+     variableDeclaration = VariableDeclaratorNoSuffix()
+      {
+        arrayList.add(variableDeclaration);
+        outlineInfo.addVariable(variableDeclaration.name());
+        pos = variableDeclaration.sourceEnd;
+      }
   )*
   try {
-    
+    token2 = 
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
-    throw e;
+    errorStart   = pos+1;
+    errorEnd     = pos+1;
+    processParseExceptionDebug(e);
   }
 
   {list = new VariableDeclaration[arrayList.size()];
    arrayList.toArray(list);
+   int end;
+   if (token2 == null) {
+     end = list[list.length-1].sourceEnd;
+   } else {
+     end = token2.sourceEnd;
+   }
    return new FieldDeclaration(list,
-                               pos,
-                               SimpleCharStream.getPosition());}
+                               token.sourceStart,
+                               end,
+                               currentSegment);}
 }
 
+/**
+ * a strict variable declarator : there cannot be a suffix here.
+ * It will be used by fields and formal parameters
+ */
+VariableDeclaration VariableDeclaratorNoSuffix() :
+{
+  final Token token, lbrace,rbrace;
+  Expression expr, initializer = null;
+  Token assignToken;
+  Variable variable;
+}
+{
+  
+  (
+     token = 
+     {variable = new Variable(token.image,token.sourceStart,token.sourceEnd);}
+   |
+     lbrace =  expr = Expression() rbrace = 
+     {variable = new Variable(expr,lbrace.sourceStart,rbrace.sourceEnd);}
+  )
+  [
+    assignToken = 
+    try {
+      initializer = VariableInitializer()
+    } catch (ParseException e) {
+      errorMessage = "Literal expression expected in variable initializer";
+      errorLevel   = ERROR;
+      errorStart = assignToken.sourceEnd +1;
+      errorEnd   = assignToken.sourceEnd +1;
+      processParseExceptionDebug(e);
+    }
+  ]
+  {
+  if (initializer == null) {
+    return new VariableDeclaration(currentSegment,
+                                   variable,
+                                   variable.sourceStart,
+                                   variable.sourceEnd);
+  }
+  return new VariableDeclaration(currentSegment,
+                                 variable,
+                                 initializer,
+                                 VariableDeclaration.EQUAL,
+                                 variable.sourceStart);
+  }
+}
+
+/**
+ * this will be used by static statement
+ */
 VariableDeclaration VariableDeclarator() :
 {
-  final String varName, varValue;
+  final AbstractVariable variable;
   Expression initializer = null;
-  final int pos = jj_input_stream.getPosition();
+  final Token token;
 }
 {
-  varName = VariableDeclaratorId()
+  variable = VariableDeclaratorId()
   [
-    
+    token = 
     try {
       initializer = VariableInitializer()
     } catch (ParseException e) {
       errorMessage = "Literal expression expected in variable initializer";
       errorLevel   = ERROR;
-      errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-      errorEnd   = jj_input_stream.getPosition() + 1;
-      throw e;
+      errorStart = token.sourceEnd+1;
+      errorEnd   = token.sourceEnd+1;
+      processParseExceptionDebug(e);
     }
   ]
   {
   if (initializer == null) {
     return new VariableDeclaration(currentSegment,
-                                  varName.toCharArray(),
-                                  pos,
-                                  jj_input_stream.getPosition());
+                                   variable,
+                                   variable.sourceStart,
+                                   variable.sourceEnd);
   }
     return new VariableDeclaration(currentSegment,
-                                    varName.toCharArray(),
-                                    initializer,
-                                    pos);
+                                   variable,
+                                   initializer,
+                                   VariableDeclaration.EQUAL,
+                                   variable.sourceStart);
   }
 }
 
@@ -939,133 +1003,102 @@ VariableDeclaration VariableDeclarator() :
  * A Variable name.
  * @return the variable name (with suffix)
  */
-String VariableDeclaratorId() :
+AbstractVariable VariableDeclaratorId() :
 {
-  String expr;
-  Expression expression;
-  final StringBuffer buff = new StringBuffer();
-  final int pos = SimpleCharStream.getPosition();
-  ConstantIdentifier ex;
+  final Variable var;
+  AbstractVariable expression = null;
 }
 {
   try {
-    expr = Variable()   {buff.append(expr);}
-    ( LOOKAHEAD(2)
-      {ex = new ConstantIdentifier(expr.toCharArray(),
-                                   pos,
-                                   SimpleCharStream.getPosition());}
-      expression = VariableSuffix(ex)
-      {buff.append(expression.toStringExpression());}
+    var = Variable()
+    (
+      LOOKAHEAD(2)
+      expression = VariableSuffix(var)
     )*
-    {return buff.toString();}
+    {
+     if (expression == null) {
+       return var;
+     }
+     return expression;
+    }
   } 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;
   }
 }
 
-String Variable():
+Variable Variable() :
 {
-  final StringBuffer buff;
-  Expression expression = null;
+  Variable variable = null;
   final Token token;
-  final String expr;
 }
 {
-  token =  [ expression = Expression() ]
+  token =  variable = Var()
   {
-    if (expression == null && !assigning) {
-      return token.image.substring(1);
-    }
-    buff = new StringBuffer(token.image);
-    buff.append('{');
-    buff.append(expression.toStringExpression());
-    buff.append('}');
-    return buff.toString();
+    return variable;
   }
-|
-   expr = VariableName()
-  {return expr;}
 }
 
-String VariableName():
+Variable Var() :
 {
-  final StringBuffer buff;
-  String expr = null;
-  Expression expression = null;
-  final Token token;
+  Variable variable = null;
+  final Token token,token2;
+  ConstantIdentifier constant;
+  Expression expression;
 }
 {
-   expression = Expression() 
-  {buff = new StringBuffer('{');
-   buff.append(expression.toStringExpression());
-   buff.append('}');
-   return buff.toString();}
+  token =  variable = Var()
+  {return new Variable(variable,variable.sourceStart,variable.sourceEnd);}
 |
-  token =  [ expression = Expression() ]
+  token =  expression = Expression() token2 = 
   {
-    if (expression == null) {
-      return token.image;
-    }
-    buff = new StringBuffer(token.image);
-    buff.append('{');
-    buff.append(expression.toStringExpression());
-    buff.append('}');
-    return buff.toString();
-  }
-|
-   expr = VariableName()
-  {
-    buff = new StringBuffer('$');
-    buff.append(expr);
-    return buff.toString();
+   return new Variable(expression,
+                       token.sourceStart,
+                       token2.sourceEnd);
   }
 |
-  token =  {return token.image;}
+  token = 
+  {return new Variable(token.image,token.sourceStart,token.sourceEnd);}
 }
 
 Expression VariableInitializer() :
 {
   final Expression expr;
-  final Token token;
-  final int pos = SimpleCharStream.getPosition();
+  final Token token, token2;
 }
 {
   expr = Literal()
   {return expr;}
 |
-   (token =  | token = )
-  {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
-                                                        pos,
-                                                        SimpleCharStream.getPosition()),
+  token2 =  (token =  | token = )
+  {return new PrefixedUnaryExpression(new NumberLiteral(token),
                                       OperatorIds.MINUS,
-                                      pos);}
+                                      token2.sourceStart);}
 |
-   (token =  | token = )
-  {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
-                                                        pos,
-                                                        SimpleCharStream.getPosition()),
+  token2 =  (token =  | token = )
+  {return new PrefixedUnaryExpression(new NumberLiteral(token),
                                       OperatorIds.PLUS,
-                                      pos);}
+                                      token2.sourceStart);}
 |
   expr = ArrayDeclarator()
   {return expr;}
 |
   token = 
-  {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
+  {return new ConstantIdentifier(token);}
 }
 
 ArrayVariableDeclaration ArrayVariable() :
 {
-Expression expr,expr2;
+final Expression expr,expr2;
 }
 {
   expr = Expression()
-  [ expr2 = Expression()
-  {return new ArrayVariableDeclaration(expr,expr2);}
+  [
+     expr2 = Expression()
+    {return new ArrayVariableDeclaration(expr,expr2);}
   ]
   {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
 }
@@ -1076,16 +1109,20 @@ ArrayVariableDeclaration[] ArrayInitializer() :
   final ArrayList list = new ArrayList();
 }
 {
-   [ expr = ArrayVariable()
-            {list.add(expr);}
-            ( LOOKAHEAD(2)