first version of external tools
[phpeclipse.git] / net.sourceforge.phpeclipse / src / test / PHPParser.jj
index 95618cb..438fa59 100644 (file)
@@ -83,12 +83,6 @@ public final class PHPParser extends PHPParserSuperclass {
   private static AstNode[] nodes;
   /** The cursor in expression stack. */
   private static int nodePtr;
-  private static VariableDeclaration[] variableDeclarationStack;
-  private static int variableDeclarationPtr;
-  private static Statement[] statementStack;
-  private static int statementPtr;
-  private static ElseIf[] elseIfStack;
-  private static int elseIfPtr;
 
   public final void setFileToParse(final IFile fileToParse) {
     this.fileToParse = fileToParse;
@@ -107,11 +101,7 @@ public final class PHPParser extends PHPParserSuperclass {
    */
   private static final void init() {
     nodes = new AstNode[AstStackIncrement];
-    statementStack = new Statement[AstStackIncrement];
-    elseIfStack = new ElseIf[AstStackIncrement];
     nodePtr = -1;
-    statementPtr = -1;
-    elseIfPtr = -1;
     htmlStart = 0;
   }
 
@@ -132,80 +122,6 @@ 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);
@@ -218,7 +134,8 @@ public final class PHPParser extends PHPParserSuperclass {
     try {
       parse();
       phpDocument = new PHPDocument(null);
-      phpDocument.nodes = nodes;
+      phpDocument.nodes = new AstNode[nodes.length];
+      System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
       PHPeclipsePlugin.log(1,phpDocument.toString());
     } catch (ParseException e) {
       processParseException(e);
@@ -380,7 +297,7 @@ public final class PHPParser extends PHPParserSuperclass {
     if (currentPosition == htmlStart) {
       return;
     }
-    final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition).toCharArray();
+    final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
     pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
   }
 
@@ -594,10 +511,9 @@ MORE :
 |    <STRING_1:
       "\""
       (
-          ~["\"","{","}"]
+          ~["\""]
         | "\\\""
         | "\\"
-        | "{" ~["\""] "}"
       )*
       "\""
     >
@@ -692,14 +608,6 @@ MORE :
   < DOLLAR_ID: <DOLLAR> <IDENTIFIER>  >
 }
 
-void phpTest() :
-{}
-{
-  Php()
-  <EOF>
-  {PHPParser.createNewHTMLCode();}
-}
-
 void phpFile() :
 {}
 {
@@ -835,8 +743,8 @@ void ClassBody(ClassDeclaration classDeclaration) :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
   ( ClassBodyDeclaration(classDeclaration) )*
@@ -845,8 +753,8 @@ void ClassBody(ClassDeclaration classDeclaration) :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd   = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 }
@@ -889,8 +797,8 @@ FieldDeclaration FieldDeclaration() :
   } catch (ParseException e) {
     errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
     errorLevel   = ERROR;
-    errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
-    errorEnd   = jj_input_stream.getPosition() + 1;
+    errorStart   = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+    errorEnd     = SimpleCharStream.getPosition() + 1;
     throw e;
   }
 
@@ -903,7 +811,7 @@ FieldDeclaration FieldDeclaration() :
 
 VariableDeclaration VariableDeclarator() :
 {
-  final String varName, varValue;
+  final String varName;
   Expression initializer = null;
   final int pos = jj_input_stream.getPosition();
 }
@@ -1097,11 +1005,10 @@ ArrayVariableDeclaration[] ArrayInitializer() :
 MethodDeclaration MethodDeclaration() :
 {
   final MethodDeclaration functionDeclaration;
-  Token functionToken;
   final Block block;
 }
 {
-  functionToken = <FUNCTION>
+  <FUNCTION>
   try {
     functionDeclaration = MethodDeclarator()
     {outlineInfo.addVariable(new String(functionDeclaration.name));}
@@ -1160,8 +1067,6 @@ MethodDeclaration MethodDeclarator() :
  */
 Hashtable FormalParameters() :
 {
-  String expr;
-  final StringBuffer buff = new StringBuffer("(");
   VariableDeclaration var;
   final Hashtable parameters = new Hashtable();
 }
@@ -1217,31 +1122,31 @@ ConstantIdentifier Type() :
 {
   <STRING>             {pos = SimpleCharStream.getPosition();
                         return new ConstantIdentifier(Types.STRING,
-                                        pos,pos-6);}
+                                                      pos,pos-6);}
 | <BOOL>               {pos = SimpleCharStream.getPosition();
                         return new ConstantIdentifier(Types.BOOL,
-                                        pos,pos-4);}
+                                                      pos,pos-4);}
 | <BOOLEAN>            {pos = SimpleCharStream.getPosition();
                         return new ConstantIdentifier(Types.BOOLEAN,
-                                        pos,pos-7);}
+                                                      pos,pos-7);}
 | <REAL>               {pos = SimpleCharStream.getPosition();
                         return new ConstantIdentifier(Types.REAL,
-                                        pos,pos-4);}
+                                                      pos,pos-4);}
 | <DOUBLE>             {pos = SimpleCharStream.getPosition();
                         return new ConstantIdentifier(Types.DOUBLE,
-                                        pos,pos-5);}
+                                                      pos,pos-5);}
 | <FLOAT>              {pos = SimpleCharStream.getPosition();
                         return new ConstantIdentifier(Types.FLOAT,
-                                        pos,pos-5);}
+                                                      pos,pos-5);}
 | <INT>                {pos = SimpleCharStream.getPosition();
                         return new ConstantIdentifier(Types.INT,
-                                        pos,pos-3);}
+                                                      pos,pos-3);}
 | <INTEGER>            {pos = SimpleCharStream.getPosition();
                         return new ConstantIdentifier(Types.INTEGER,
-                                        pos,pos-7);}
+                                                      pos,pos-7);}
 | <OBJECT>             {pos = SimpleCharStream.getPosition();
                         return new ConstantIdentifier(Types.OBJECT,
-                                        pos,pos-6);}
+                                                      pos,pos-6);}
 }
 
 Expression Expression() :
@@ -1641,7 +1546,6 @@ Expression PrimaryExpression() :
 {
   final Token identifier;
   Expression expr;
-  final StringBuffer buff = new StringBuffer();
   final int pos = SimpleCharStream.getPosition();
 }
 {
@@ -1941,7 +1845,6 @@ HTMLBlock htmlBlock() :
 InclusionStatement IncludeStatement() :
 {
   final Expression expr;
-  final Token token;
   final int keyword;
   final int pos = jj_input_stream.getPosition();
   final InclusionStatement inclusionStatement;
@@ -2427,7 +2330,6 @@ AbstractCase switchLabel0() :
  */
 Expression SwitchLabel() :
 {
-  final Token token;
   final Expression expr;
 }
 {
@@ -2756,7 +2658,6 @@ ForeachStatement ForeachStatement() :
 {
   Statement statement;
   Expression expression;
-  final StringBuffer buff = new StringBuffer();
   final int pos = SimpleCharStream.getPosition();
   ArrayVariableDeclaration variable;
 }