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;
*/
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;
}
}
}
- 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);
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);
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));
}
| <STRING_1:
"\""
(
- ~["\"","{","}"]
+ ~["\""]
| "\\\""
| "\\"
- | "{" ~["\""] "}"
)*
"\""
>
< DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
}
-void phpTest() :
-{}
-{
- Php()
- <EOF>
- {PHPParser.createNewHTMLCode();}
-}
-
void phpFile() :
{}
{
} 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) )*
} 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;
}
}
} 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;
}
VariableDeclaration VariableDeclarator() :
{
- final String varName, varValue;
+ final String varName;
Expression initializer = null;
final int pos = jj_input_stream.getPosition();
}
MethodDeclaration MethodDeclaration() :
{
final MethodDeclaration functionDeclaration;
- Token functionToken;
final Block block;
}
{
- functionToken = <FUNCTION>
+ <FUNCTION>
try {
functionDeclaration = MethodDeclarator()
{outlineInfo.addVariable(new String(functionDeclaration.name));}
*/
Hashtable FormalParameters() :
{
- String expr;
- final StringBuffer buff = new StringBuffer("(");
VariableDeclaration var;
final Hashtable parameters = new Hashtable();
}
{
<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() :
{
final Token identifier;
Expression expr;
- final StringBuffer buff = new StringBuffer();
final int pos = SimpleCharStream.getPosition();
}
{
| token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
| token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
- return new StringLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
+ return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
| <TRUE> {pos = SimpleCharStream.getPosition();
return new TrueLiteral(pos-4,pos);}
| <FALSE> {pos = SimpleCharStream.getPosition();
FunctionCall Arguments(Expression func) :
{
-ArgumentDeclaration[] args = null;
+Expression[] args = null;
}
{
<LPAREN> [ args = ArgumentList() ]
* argumentDeclaration() (, argumentDeclaration)*
* @return an array of arguments
*/
-ArgumentDeclaration[] ArgumentList() :
+Expression[] ArgumentList() :
{
-ArgumentDeclaration arg;
+Expression arg;
final ArrayList list = new ArrayList();
-ArgumentDeclaration argument;
}
{
- arg = argumentDeclaration()
+ arg = Expression()
{list.add(arg);}
( <COMMA>
try {
- arg = argumentDeclaration()
+ arg = Expression()
{list.add(arg);}
} catch (ParseException e) {
errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
}
)*
{
- ArgumentDeclaration[] args = new ArgumentDeclaration[list.size()];
- list.toArray(args);
- return args;}
+ Expression[] arguments = new Expression[list.size()];
+ list.toArray(arguments);
+ return arguments;}
}
/**
- * Here is an argument declaration.
- * It's [&]$variablename[=variableInitializer]
- */
-ArgumentDeclaration argumentDeclaration() :
-{
- boolean reference = false;
- String varName;
- Expression initializer = null;
- final int pos = SimpleCharStream.getPosition();
-}
-{
- [<BIT_AND> {reference = true;}]
- varName = VariableDeclaratorId()
- [
- <ASSIGN>
- 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;
- }
- ]
- {
- if (initializer == null) {
- return new ArgumentDeclaration(varName.toCharArray(),
- reference,
- pos);
- }
- return new ArgumentDeclaration(varName.toCharArray(),
- reference,
- initializer,
- pos);
- }
-}
-/**
* A Statement without break.
*/
Statement StatementNoBreak() :
InclusionStatement IncludeStatement() :
{
final Expression expr;
- final Token token;
final int keyword;
final int pos = jj_input_stream.getPosition();
final InclusionStatement inclusionStatement;
*/
Expression SwitchLabel() :
{
- final Token token;
final Expression expr;
}
{
{
Statement statement;
Expression expression;
- final StringBuffer buff = new StringBuffer();
final int pos = SimpleCharStream.getPosition();
ArrayVariableDeclaration variable;
}