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 2b4a1e9..d45ca07 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;
@@ -69,7 +73,7 @@ public final class PHPParser extends PHPParserSuperclass {
   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'};
+  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,8 +87,10 @@ public final class PHPParser extends PHPParserSuperclass {
   /** The cursor in expression stack. */
   private static int nodePtr;
 
+  private static final boolean PARSER_DEBUG = true;
+
   public final void setFileToParse(final IFile fileToParse) {
-    this.fileToParse = fileToParse;
+    PHPParser.fileToParse = fileToParse;
   }
 
   public PHPParser() {
@@ -92,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();
   }
 
   /**
@@ -108,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;
@@ -144,6 +190,12 @@ public final class PHPParser extends PHPParserSuperclass {
     return outlineInfo;
   }
 
+  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
@@ -153,15 +205,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 = SimpleCharStream.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) {
@@ -169,8 +222,8 @@ public final class PHPParser extends PHPParserSuperclass {
       if (errorStart == -1) {
         setMarker(fileToParse,
                   errorMessage,
-                  SimpleCharStream.tokenBegin,
-                  SimpleCharStream.tokenBegin + e.currentToken.image.length(),
+                  e.currentToken.sourceStart,
+                  e.currentToken.sourceEnd,
                   errorLevel,
                   "Line " + e.currentToken.beginLine);
       } else {
@@ -188,42 +241,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++) {
@@ -233,9 +261,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("", "");
@@ -254,7 +282,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);
@@ -294,14 +322,34 @@ 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 > SimpleCharStream.currentBuffer.length()) {
       return;
     }
     final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
     pushOnAstNodes(new HTMLCode(chars, 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);
+    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();
   }
@@ -309,6 +357,18 @@ 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
@@ -316,9 +376,9 @@ PARSER_END(PHPParser)
 |    {PHPParser.createNewHTMLCode();} : PHPPARSING
 }
 
- TOKEN :
+ TOKEN :
 {
-  "> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
+  "> {PHPParser.htmlStart = PHPParser.token.sourceEnd;} : DEFAULT
 }
 
 /* Skip any character if we are not in php mode */
@@ -342,34 +402,30 @@ PARSER_END(PHPParser)
  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" {PHPParser.createNewTask();}
 }
 
-
-SPECIAL_TOKEN :
+ SPECIAL_TOKEN :
 {
-   : PHPPARSING
+  "*/" : PHPPARSING
 }
 
-
-SPECIAL_TOKEN :
+ SPECIAL_TOKEN :
 {
-   : PHPPARSING
+  "*/" : PHPPARSING
 }
 
 
@@ -402,6 +458,7 @@ MORE :
 | 
 | 
 | 
+| 
 | 
 | ">
 | 
@@ -467,8 +524,8 @@ MORE :
 {
   
 | 
-| 
-| 
+| 
+| 
 | 
 | 
 | 
@@ -509,39 +566,16 @@ MORE :
   <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
 |
    |  | )>
-|    
-|    
-|   
+|   
+|   
+|   
 }
 
 /* IDENTIFIERS */
 
  TOKEN :
 {
-  < IDENTIFIER: (|) (||)* >
+  |) (||)* >
 |
   < #LETTER:
       ["a"-"z"] | ["A"-"Z"]
@@ -606,7 +640,14 @@ MORE :
 
  TOKEN :
 {
-  < DOLLAR_ID:    >
+   >
+}
+
+void phpTest() :
+{}
+{
+  Php()
+  
 }
 
 void phpFile() :
@@ -614,7 +655,7 @@ void phpFile() :
 {
   try {
     (PhpBlock())*
-    
+    {PHPParser.createNewHTMLCode();}
   } catch (TokenMgrError e) {
     PHPeclipsePlugin.log(e);
     errorStart   = SimpleCharStream.getPosition();
@@ -632,20 +673,20 @@ void phpFile() :
  */
 void PhpBlock() :
 {
-  final int start = SimpleCharStream.getPosition();
   final PHPEchoBlock phpEchoBlock;
+  final Token token;
 }
 {
   phpEchoBlock = phpEchoBlock()
   {pushOnAstNodes(phpEchoBlock);}
 |
   [   
-    | 
+    | token = 
     {try {
       setMarker(fileToParse,
                 "You should use ' expr = Expression() [  ] 
+  token =  expr = Expression() [  ] token2 = 
   {
-  echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
+  echoBlock = new PHPEchoBlock(expr,token.sourceStart,token2.sourceEnd);
   pushOnAstNodes(echoBlock);
   return echoBlock;}
 }
@@ -687,51 +728,58 @@ void Php() :
 ClassDeclaration ClassDeclaration() :
 {
   final ClassDeclaration classDeclaration;
-  final Token className;
-  Token superclassName = null;
-  final int pos;
-  char[] classNameImage = SYNTAX_ERROR_CHAR;
-  char[] superclassNameImage = null;
+  Token className = null;
+  final Token superclassName, token;
+  String classNameImage = SYNTAX_ERROR_CHAR;
+  String superclassNameImage = null;
 }
 {
-  
-  {pos = SimpleCharStream.getPosition();}
+  token = 
   try {
     className = 
-    {classNameImage = className.image.toCharArray();}
+    {classNameImage = className.image;}
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
     errorLevel   = ERROR;
     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd     = SimpleCharStream.getPosition() + 1;
-    processParseException(e);
+    processParseExceptionDebug(e);
   }
   [
     
     try {
       superclassName = 
-      {superclassNameImage = superclassName.image.toCharArray();}
+      {superclassNameImage = superclassName.image;}
     } catch (ParseException e) {
       errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
       errorLevel   = ERROR;
       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
       errorEnd   = SimpleCharStream.getPosition() + 1;
-      processParseException(e);
+      processParseExceptionDebug(e);
       superclassNameImage = SYNTAX_ERROR_CHAR;
     }
   ]
   {
+    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,
                                               classNameImage,
-                                              pos,
-                                              0);
+                                              start,
+                                              end);
     } else {
       classDeclaration = new ClassDeclaration(currentSegment,
                                               classNameImage,
                                               superclassNameImage,
-                                              pos,
-                                              0);
+                                              start,
+                                              end);
     }
       currentSegment.add(classDeclaration);
       currentSegment = classDeclaration;
@@ -743,89 +791,142 @@ ClassDeclaration ClassDeclaration() :
    return classDeclaration;}
 }
 
-void ClassBody(ClassDeclaration classDeclaration) :
+void ClassBody(final ClassDeclaration classDeclaration) :
 {}
 {
   try {
     
   } catch (ParseException e) {
-    errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
+    errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected";
     errorLevel   = ERROR;
     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd   = SimpleCharStream.getPosition() + 1;
-    throw e;
+    processParseExceptionDebug(e);
   }
   ( ClassBodyDeclaration(classDeclaration) )*
   try {
     
   } 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 = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd   = SimpleCharStream.getPosition() + 1;
-    throw e;
+    processParseExceptionDebug(e);
   }
 }
 
 /**
  * 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() {method.setParent(classDeclaration);}
-| field = FieldDeclaration()
+  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;
 }
 {
-   variableDeclaration = VariableDeclarator()
+  token =  variableDeclaration = VariableDeclaratorNoSuffix()
   {arrayList.add(variableDeclaration);
-   outlineInfo.addVariable(new String(variableDeclaration.name));
-   currentSegment.add(variableDeclaration);}
-  (  variableDeclaration = VariableDeclarator()
+   outlineInfo.addVariable(variableDeclaration.name());}
+  (
+     variableDeclaration = VariableDeclaratorNoSuffix()
       {arrayList.add(variableDeclaration);
-       outlineInfo.addVariable(new String(variableDeclaration.name));
-       currentSegment.add(variableDeclaration);}
+       outlineInfo.addVariable(variableDeclaration.name());}
   )*
   try {
-    
+    token2 = 
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
     errorLevel   = ERROR;
     errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd     = SimpleCharStream.getPosition() + 1;
-    processParseException(e);
+    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 varName;
+  Expression initializer = null;
+  Token assignToken;
+}
+{
+  varName = 
+  [
+    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,
+                                   new Variable(varName.image.substring(1),
+                                                varName.sourceStart+1,
+                                                varName.sourceEnd+1),
+                                   varName.sourceStart+1,
+                                   varName.sourceEnd+1);
+  }
+  return new VariableDeclaration(currentSegment,
+                                 new Variable(varName.image.substring(1),
+                                              varName.sourceStart+1,
+                                              varName.sourceEnd+1),
+                                 initializer,
+                                 VariableDeclaration.EQUAL,
+                                 varName.sourceStart+1);
+  }
+}
+
+/**
+ * this will be used by static statement
+ */
 VariableDeclaration VariableDeclarator() :
 {
-  final String varName;
+  final AbstractVariable variable;
   Expression initializer = null;
-  final int pos = SimpleCharStream.getPosition();
 }
 {
-  varName = VariableDeclaratorId()
+  variable = VariableDeclaratorId()
   [
     
     try {
@@ -835,20 +936,21 @@ VariableDeclaration VariableDeclarator() :
       errorLevel   = ERROR;
       errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
       errorEnd   = SimpleCharStream.getPosition() + 1;
-      throw e;
+      processParseExceptionDebug(e);
     }
   ]
   {
   if (initializer == null) {
     return new VariableDeclaration(currentSegment,
-                                  varName.toCharArray(),
-                                  pos,
-                                  SimpleCharStream.getPosition());
+                                   variable,
+                                   variable.sourceStart,
+                                   variable.sourceEnd);
   }
     return new VariableDeclaration(currentSegment,
-                                    varName.toCharArray(),
-                                    initializer,
-                                    pos);
+                                   variable,
+                                   initializer,
+                                   VariableDeclaration.EQUAL,
+                                   variable.sourceStart);
   }
 }
 
@@ -856,25 +958,24 @@ 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;
@@ -884,109 +985,187 @@ String VariableDeclaratorId() :
   }
 }
 
-String Variable():
+/**
+ * Return a variablename without the $.
+ * @return a variable name
+ *//*
+Variable Variable():
 {
   final StringBuffer buff;
   Expression expression = null;
   final Token token;
-  final String expr;
+  Variable expr;
+  final int pos;
 }
 {
-  token =  [ expression = Expression() ]
+  token = 
+  [ expression = Expression() ]
   {
     if (expression == null) {
-      return token.image.substring(1);
+      return new Variable(token.image.substring(1),
+                          token.sourceStart+1,
+                          token.sourceEnd+1);
     }
-    buff = new StringBuffer(token.image);
+    String s = expression.toStringExpression();
+    buff = new StringBuffer(token.image.length()+s.length()+2);
+    buff.append(token.image);
     buff.append("{");
-    buff.append(expression.toStringExpression());
+    buff.append(s);
     buff.append("}");
-    return buff.toString();
+    s = buff.toString();
+    return new Variable(s,token.sourceStart+1,token.sourceEnd+1);
   }
 |
-   expr = VariableName()
-  {return "$" + expr;}
+  token = 
+  expr = VariableName()
+  {return new Variable(expr,token.sourceStart,expr.sourceEnd);}
+}   */
+
+Variable Variable() :
+{
+  Variable variable = null;
+  final Token token;
+}
+{
+ token =  [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 =  variable = Var(token)
+  {
+    return new Variable(variable,token.sourceStart,variable.sourceEnd);
+  }
+}
+
+Variable Var(final Token dollar) :
+{
+  Variable variable = null;
+  final Token token;
+  ConstantIdentifier constant;
+}
+{
+  token =  [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( )
+  token =  variable = Var(token)
+  {return new Variable(variable,dollar.sourceStart,variable.sourceEnd);}
+|
+  constant = VariableName()
+  {return new Variable(constant.name,dollar.sourceStart,constant.sourceEnd);}
 }
 
 /**
  * A Variable name (without the $)
  * @return a variable name String
  */
-String VariableName():
+ConstantIdentifier VariableName():
 {
   final StringBuffer buff;
-  String expr = null;
+  String expr;
   Expression expression = null;
   final Token token;
+  Token token2 = null;
 }
 {
-   expression = Expression() 
-  {buff = new StringBuffer("{");
-   buff.append(expression.toStringExpression());
+  token =  expression = Expression() token2 = 
+  {expr = expression.toStringExpression();
+   buff = new StringBuffer(expr.length()+2);
+   buff.append("{");
+   buff.append(expr);
    buff.append("}");
-   return buff.toString();}
+   expr = buff.toString();
+   return new ConstantIdentifier(expr,
+                                 token.sourceStart,
+                                 token2.sourceEnd);
+
+   }
 |
-  token =  [ expression = Expression() ]
+  token = 
+  [ expression = Expression() token2 = ]
   {
     if (expression == null) {
-      return token.image;
+      return new ConstantIdentifier(token.image,
+                                    token.sourceStart,
+                                    token.sourceEnd);
     }
-    buff = new StringBuffer(token.image);
+    expr = expression.toStringExpression();
+    buff = new StringBuffer(token.image.length()+expr.length()+2);
+    buff.append(token.image);
     buff.append("{");
-    buff.append(expression.toStringExpression());
+    buff.append(expr);
     buff.append("}");
-    return buff.toString();
-  }
-|
-   expr = VariableName()
+    expr = buff.toString();
+    return new ConstantIdentifier(expr,
+                                  token.sourceStart,
+                                  token2.sourceEnd);
+  }
+/*|
+  
+  var = VariableName()
   {
-    buff = new StringBuffer("$");
-    buff.append(expr);
-    return buff.toString();
+    return new Variable(var,
+                        var.sourceStart-1,
+                        var.sourceEnd);
   }
 |
-  token =  {return token.image;}
+  token = 
+  {
+  return new Variable(token.image,
+                      token.sourceStart+1,
+                      token.sourceEnd+1);
+  } */
 }
 
 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());}
 }
@@ -997,16 +1176,20 @@ ArrayVariableDeclaration[] ArrayInitializer() :
   final ArrayList list = new ArrayList();
 }
 {
-   [ expr = ArrayVariable()
-            {list.add(expr);}
-            ( LOOKAHEAD(2)  expr = ArrayVariable()
-            {list.add(expr);}
-            )*
-           ]
-           [ {list.add(null);}]
+  
+    [
+      expr = ArrayVariable()
+      {list.add(expr);}
+      ( LOOKAHEAD(2)  expr = ArrayVariable()
+      {list.add(expr);}
+      )*
+    ]
+    [
+       {list.add(null);}
+    ]
   
   {
-  ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
+  final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
   list.toArray(vars);
   return vars;}
 }
@@ -1019,11 +1202,13 @@ MethodDeclaration MethodDeclaration() :
 {
   final MethodDeclaration functionDeclaration;
   final Block block;
+  final OutlineableWithChildren seg = currentSegment;
+  final Token token;
 }
 {
-  
+  token = 
   try {
-    functionDeclaration = MethodDeclarator()
+    functionDeclaration = MethodDeclarator(token.sourceStart)
     {outlineInfo.addVariable(new String(functionDeclaration.name));}
   } catch (ParseException e) {
     if (errorMessage != null)  throw e;
@@ -1033,20 +1218,11 @@ MethodDeclaration MethodDeclaration() :
     errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
-  {
-    if (currentSegment != null) {
-      currentSegment.add(functionDeclaration);
-      currentSegment = functionDeclaration;
-    }
-  }
+  {currentSegment = functionDeclaration;}
   block = Block()
-  {
-    functionDeclaration.statements = block.statements;
-    if (currentSegment != null) {
-      currentSegment = (OutlineableWithChildren) currentSegment.getParent();
-    }
-    return functionDeclaration;
-  }
+  {functionDeclaration.statements = block.statements;
+   currentSegment = seg;
+   return functionDeclaration;}
 }
 
 /**
@@ -1054,43 +1230,61 @@ MethodDeclaration MethodDeclaration() :
  * [&] IDENTIFIER(parameters ...).
  * @return a function description for the outline
  */
-MethodDeclaration MethodDeclarator() :
+MethodDeclaration MethodDeclarator(final int start) :
 {
-  final Token identifier;
+  Token identifier = null;
   Token reference = null;
-  final Hashtable formalParameters;
-  final int pos = SimpleCharStream.getPosition();
-  char[] identifierChar = SYNTAX_ERROR_CHAR;
+  final Hashtable formalParameters = new Hashtable();
+  String identifierChar = SYNTAX_ERROR_CHAR;
+  final int end;
 }
 {
   [reference = ]
   try {
     identifier = 
-    {identifierChar = identifier.image.toCharArray();}
+    {identifierChar = identifier.image;}
   } 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);
+    processParseExceptionDebug(e);
+  }
+  end = FormalParameters(formalParameters)
+  {
+  int nameStart, nameEnd;
+  if (identifier == null) {
+    if (reference == null) {
+      nameStart = start + 9;
+      nameEnd = start + 10;
+    } else {
+      nameStart = reference.sourceEnd + 1;
+      nameEnd = reference.sourceEnd + 2;
+    }
+  } else {
+      nameStart = identifier.sourceStart;
+      nameEnd = identifier.sourceEnd;
+  }
+  return new MethodDeclaration(currentSegment,
+                               identifierChar,
+                               formalParameters,
+                               reference != null,
+                               nameStart,
+                               nameEnd,
+                               start,
+                               end);
   }
-  formalParameters = FormalParameters()
-  {return new MethodDeclaration(currentSegment,
-                                 identifierChar,
-                                 formalParameters,
-                                 reference != null,
-                                 pos,
-                                 SimpleCharStream.getPosition());}
 }
 
 /**
  * FormalParameters follows method identifier.
  * (FormalParameter())
  */
-Hashtable FormalParameters() :
+int FormalParameters(final Hashtable parameters) :
 {
   VariableDeclaration var;
-  final Hashtable parameters = new Hashtable();
+  final Token token;
+  int end;
 }
 {
   try {
@@ -1100,25 +1294,28 @@ Hashtable FormalParameters() :
     errorLevel   = ERROR;
     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd   = SimpleCharStream.getPosition() + 1;
-    throw e;
+    processParseExceptionDebug(e);
   }
-            [ var = FormalParameter()
-              {parameters.put(new String(var.name),var);}
-              (
-                 var = FormalParameter()
-                {parameters.put(new String(var.name),var);}
-              )*
-            ]
+  [
+    var = FormalParameter()
+    {parameters.put(new String(var.name()),var);}
+    (
+       var = FormalParameter()
+      {parameters.put(new String(var.name()),var);}
+    )*
+  ]
   try {
-    
+    token = 
+    {end = token.sourceEnd;}
   } catch (ParseException e) {
     errorMessage = "')' expected";
     errorLevel   = ERROR;
     errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
     errorEnd   = SimpleCharStream.getPosition() + 1;
-    throw e;
+    processParseExceptionDebug(e);
+    end = e.currentToken.sourceStart;
   }
- {return parameters;}
+ {return end;}
 }
 
 /**
@@ -1131,7 +1328,7 @@ VariableDeclaration FormalParameter() :
   Token token = null;
 }
 {
-  [token = ] variableDeclaration = VariableDeclarator()
+  [token = ] variableDeclaration = VariableDeclaratorNoSuffix()
   {
     if (token != null) {
       variableDeclaration.setReference(true);
@@ -1140,89 +1337,105 @@ VariableDeclaration FormalParameter() :
 }
 
 ConstantIdentifier Type() :
-{final int pos;}
-{
-               {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.STRING,pos,pos-6);}
-|                {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
-|             {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
-|                {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.REAL,pos,pos-4);}
-|              {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
-|               {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
-|                 {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.INT,pos,pos-3);}
-|             {pos = SimpleCharStream.getPosition();
-                        return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
-|