X-Git-Url: http://git.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj
index ac77fff..f82c7cd 100644
--- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj
+++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj
@@ -29,7 +29,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,6 +38,7 @@ 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;
/**
@@ -47,6 +47,7 @@ import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
* given with JavaCC. You can get JavaCC at http://www.webgain.com
* You can test the parser with the PHPParserTestCase2.java
* @author Matthieu Casanova
+ * @version $Reference: 1.0$
*/
public final class PHPParser extends PHPParserSuperclass {
@@ -60,8 +61,6 @@ public final class PHPParser extends PHPParserSuperclass {
private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
static PHPOutlineInfo outlineInfo;
- 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 */
@@ -70,6 +69,8 @@ public final class PHPParser extends PHPParserSuperclass {
private static int errorStart = -1;
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'};
/**
* The point where html starts.
* It will be used by the token manager to create HTMLCode objects
@@ -108,12 +109,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;
@@ -188,31 +189,6 @@ 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,
@@ -295,13 +271,32 @@ public final class PHPParser extends PHPParserSuperclass {
*/
public static final void createNewHTMLCode() {
final int currentPosition = SimpleCharStream.getPosition();
- if (currentPosition == htmlStart) {
+ 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 = SimpleCharStream.getPosition();
+ final String todo = SimpleCharStream.currentBuffer.substring(currentPosition+1,
+ SimpleCharStream.currentBuffer.indexOf("\n",
+ currentPosition)-1);
+ try {
+ setMarker(fileToParse,
+ "todo : " + todo,
+ SimpleCharStream.getBeginLine(),
+ TASK,
+ "Line "+SimpleCharStream.getBeginLine());
+ } catch (CoreException e) {
+ PHPeclipsePlugin.log(e);
+ }
+ }
+
private static final void parse() throws ParseException {
phpFile();
}
@@ -342,34 +337,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
+| "?>" : DEFAULT
}
- SPECIAL_TOKEN :
+ SPECIAL_TOKEN :
{
- " > : DEFAULT
+ "todo" {PHPParser.createNewTask();}
}
-
-SPECIAL_TOKEN :
+ SPECIAL_TOKEN :
{
- : PHPPARSING
+ "*/" : PHPPARSING
}
-
-SPECIAL_TOKEN :
+ SPECIAL_TOKEN :
{
- : PHPPARSING
+ "*/" : PHPPARSING
}
@@ -402,6 +393,7 @@ MORE :
|
|
|
+|
|
| ">
|
@@ -467,8 +459,8 @@ MORE :
{
|
-|
-|
+|
+|
|
|
|
@@ -509,32 +501,9 @@ MORE :
<#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
|
| | )>
-|
-|
-|
+|
+|
+|
}
/* IDENTIFIERS */
@@ -606,7 +575,7 @@ MORE :
TOKEN :
{
- < DOLLAR_ID: >
+ >
}
void phpFile() :
@@ -614,7 +583,7 @@ void phpFile() :
{
try {
(PhpBlock())*
-
+ {PHPParser.createNewHTMLCode();}
} catch (TokenMgrError e) {
PHPeclipsePlugin.log(e);
errorStart = SimpleCharStream.getPosition();
@@ -633,9 +602,11 @@ void phpFile() :
void PhpBlock() :
{
final int start = SimpleCharStream.getPosition();
+ final PHPEchoBlock phpEchoBlock;
}
{
- phpEchoBlock()
+ phpEchoBlock = phpEchoBlock()
+ {pushOnAstNodes(phpEchoBlock);}
|
[
|
@@ -658,7 +629,7 @@ void PhpBlock() :
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
}
@@ -666,7 +637,7 @@ PHPEchoBlock phpEchoBlock() :
{
final Expression expr;
final int pos = SimpleCharStream.getPosition();
- PHPEchoBlock echoBlock;
+ final PHPEchoBlock echoBlock;
}
{
expr = Expression() [ ]
@@ -685,44 +656,48 @@ void Php() :
ClassDeclaration ClassDeclaration() :
{
final ClassDeclaration classDeclaration;
- final Token className;
- Token superclassName = null;
+ final Token className,superclassName;
final int pos;
+ char[] classNameImage = SYNTAX_ERROR_CHAR;
+ char[] superclassNameImage = null;
}
{
+ {pos = SimpleCharStream.getPosition();}
try {
- {pos = SimpleCharStream.getPosition();}
className =
+ {classNameImage = className.image.toCharArray();}
} 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;
- throw e;
+ processParseException(e);
}
[
try {
superclassName =
+ {superclassNameImage = superclassName.image.toCharArray();}
} 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;
- throw e;
+ processParseException(e);
+ superclassNameImage = SYNTAX_ERROR_CHAR;
}
]
{
- if (superclassName == null) {
+ if (superclassNameImage == null) {
classDeclaration = new ClassDeclaration(currentSegment,
- className.image.toCharArray(),
+ classNameImage,
pos,
0);
} else {
classDeclaration = new ClassDeclaration(currentSegment,
- className.image.toCharArray(),
- superclassName.image.toCharArray(),
+ classNameImage,
+ superclassNameImage,
pos,
0);
}
@@ -736,7 +711,7 @@ ClassDeclaration ClassDeclaration() :
return classDeclaration;}
}
-void ClassBody(ClassDeclaration classDeclaration) :
+void ClassBody(final ClassDeclaration classDeclaration) :
{}
{
try {
@@ -763,14 +738,14 @@ void ClassBody(ClassDeclaration classDeclaration) :
/**
* 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() {classDeclaration.addMethod(method);}
+| field = FieldDeclaration() {classDeclaration.addField(field);}
}
/**
@@ -779,19 +754,17 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
FieldDeclaration FieldDeclaration() :
{
VariableDeclaration variableDeclaration;
- VariableDeclaration[] list;
+ final VariableDeclaration[] list;
final ArrayList arrayList = new ArrayList();
final int pos = SimpleCharStream.getPosition();
}
{
variableDeclaration = VariableDeclarator()
{arrayList.add(variableDeclaration);
- outlineInfo.addVariable(new String(variableDeclaration.name));
- currentSegment.add(variableDeclaration);}
+ outlineInfo.addVariable(new String(variableDeclaration.name));}
( variableDeclaration = VariableDeclarator()
{arrayList.add(variableDeclaration);
- outlineInfo.addVariable(new String(variableDeclaration.name));
- currentSegment.add(variableDeclaration);}
+ outlineInfo.addVariable(new String(variableDeclaration.name));}
)*
try {
@@ -851,23 +824,26 @@ VariableDeclaration VariableDeclarator() :
*/
String VariableDeclaratorId() :
{
- String expr;
- Expression expression;
- final StringBuffer buff = new StringBuffer();
+ final String expr;
+ Expression expression = null;
final int pos = SimpleCharStream.getPosition();
ConstantIdentifier ex;
}
{
try {
- expr = Variable() {buff.append(expr);}
+ expr = Variable()
( LOOKAHEAD(2)
{ex = new ConstantIdentifier(expr.toCharArray(),
pos,
SimpleCharStream.getPosition());}
expression = VariableSuffix(ex)
- {buff.append(expression.toStringExpression());}
)*
- {return buff.toString();}
+ {
+ if (expression == null) {
+ return expr;
+ }
+ return expression.toStringExpression();
+ }
} catch (ParseException e) {
errorMessage = "'$' expected for variable identifier";
errorLevel = ERROR;
@@ -877,6 +853,10 @@ String VariableDeclaratorId() :
}
}
+/**
+ * Return a variablename without the $.
+ * @return a variable name
+ */
String Variable():
{
final StringBuffer buff;
@@ -887,7 +867,7 @@ String Variable():
{
token = [ expression = Expression() ]
{
- if (expression == null && !assigning) {
+ if (expression == null) {
return token.image.substring(1);
}
buff = new StringBuffer(token.image);
@@ -898,13 +878,17 @@ String Variable():
}
|
expr = VariableName()
- {return "$" + expr;}
+ {return expr;}
}
+/**
+ * A Variable name (without the $)
+ * @return a variable name String
+ */
String VariableName():
{
final StringBuffer buff;
- String expr = null;
+ final String expr;
Expression expression = null;
final Token token;
}
@@ -970,7 +954,7 @@ Expression VariableInitializer() :
ArrayVariableDeclaration ArrayVariable() :
{
-Expression expr,expr2;
+final Expression expr,expr2;
}
{
expr = Expression()
@@ -995,7 +979,7 @@ ArrayVariableDeclaration[] ArrayInitializer() :
[ {list.add(null);}]
{
- ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
+ final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
list.toArray(vars);
return vars;}
}
@@ -1008,6 +992,7 @@ MethodDeclaration MethodDeclaration() :
{
final MethodDeclaration functionDeclaration;
final Block block;
+ final OutlineableWithChildren seg = currentSegment;
}
{
@@ -1022,20 +1007,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;}
}
/**
@@ -1049,16 +1025,27 @@ MethodDeclaration MethodDeclarator() :
Token reference = null;
final Hashtable formalParameters;
final int pos = SimpleCharStream.getPosition();
+ char[] identifierChar = SYNTAX_ERROR_CHAR;
}
{
- [reference = ] identifier =
+ [reference = ]
+ try {
+ identifier =
+ {identifierChar = identifier.image.toCharArray();}
+ } 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);
+ }
formalParameters = FormalParameters()
{return new MethodDeclaration(currentSegment,
- identifier.image.toCharArray(),
- formalParameters,
- reference != null,
- pos,
- SimpleCharStream.getPosition());}
+ identifierChar,
+ formalParameters,
+ reference != null,
+ pos,
+ SimpleCharStream.getPosition());}
}
/**
@@ -1078,7 +1065,7 @@ Hashtable FormalParameters() :
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
[ var = FormalParameter()
{parameters.put(new String(var.name),var);}
@@ -1094,7 +1081,7 @@ Hashtable FormalParameters() :
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
{return parameters;}
}
@@ -1143,6 +1130,16 @@ ConstantIdentifier Type() :
Expression Expression() :
{
final Expression expr;
+ final int pos = SimpleCharStream.getPosition();
+}
+{
+ expr = Expression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
+| expr = ExpressionNoBang() {return expr;}
+}
+
+Expression ExpressionNoBang() :
+{
+ final Expression expr;
}
{
expr = PrintExpression() {return expr;}
@@ -1158,8 +1155,8 @@ Expression Expression() :
*/
VarAssignation varAssignation() :
{
- String varName;
- final Expression expression;
+ final String varName;
+ final Expression initializer;
final int assignOperator;
final int pos = SimpleCharStream.getPosition();
}
@@ -1167,7 +1164,7 @@ VarAssignation varAssignation() :
varName = VariableDeclaratorId()
assignOperator = AssignmentOperator()
try {
- expression = Expression()
+ initializer = Expression()
} catch (ParseException e) {
if (errorMessage != null) {
throw e;
@@ -1179,7 +1176,7 @@ VarAssignation varAssignation() :
throw e;
}
{return new VarAssignation(varName.toCharArray(),
- expression,
+ initializer,
assignOperator,
pos,
SimpleCharStream.getPosition());}
@@ -1419,7 +1416,7 @@ Expression MultiplicativeExpression() :
*/
Expression UnaryExpression() :
{
- Expression expr;
+ final Expression expr;
final int pos = SimpleCharStream.getPosition();
}
{
@@ -1431,7 +1428,7 @@ Expression UnaryExpression() :
Expression AtUnaryExpression() :
{
- Expression expr;
+ final Expression expr;
final int pos = SimpleCharStream.getPosition();
}
{
@@ -1446,8 +1443,8 @@ Expression AtUnaryExpression() :
Expression UnaryExpressionNoPrefix() :
{
- Expression expr;
- int operator;
+ final Expression expr;
+ final int operator;
final int pos = SimpleCharStream.getPosition();
}
{
@@ -1471,20 +1468,19 @@ final int operator;
final int pos = SimpleCharStream.getPosition();
}
{
- ( {operator = OperatorIds.PLUS_PLUS;}
- | {operator = OperatorIds.MINUS_MINUS;})
+ ( {operator = OperatorIds.PLUS_PLUS;}
+ | {operator = OperatorIds.MINUS_MINUS;})
expr = PrimaryExpression()
{return new PrefixedUnaryExpression(expr,operator,pos);}
}
Expression UnaryExpressionNotPlusMinus() :
{
- Expression expr;
- final int pos = SimpleCharStream.getPosition();
+ final Expression expr;
}
{
- expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
-| LOOKAHEAD( (Type() | ) )
+// expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
+ LOOKAHEAD( (Type() | ) )
expr = CastExpression() {return expr;}
| expr = PostfixExpression() {return expr;}
| expr = Literal() {return expr;}
@@ -1517,14 +1513,14 @@ final int pos = SimpleCharStream.getPosition();
Expression PostfixExpression() :
{
- Expression expr;
+ final Expression expr;
int operator = -1;
final int pos = SimpleCharStream.getPosition();
}
{
expr = PrimaryExpression()
- [ {operator = OperatorIds.PLUS_PLUS;}
- | {operator = OperatorIds.MINUS_MINUS;}]
+ [ {operator = OperatorIds.PLUS_PLUS;}
+ | {operator = OperatorIds.MINUS_MINUS;}]
{
if (operator == -1) {
return expr;
@@ -1547,17 +1543,26 @@ Expression PrimaryExpression() :
SimpleCharStream.getPosition()),
expr,
ClassAccess.STATIC);}
- (expr = PrimarySuffix(expr))*
+ (
+ LOOKAHEAD(PrimarySuffix())
+ expr = PrimarySuffix(expr))*
{return expr;}
|
expr = PrimaryPrefix()
- (expr = PrimarySuffix(expr))*
+ (
+ LOOKAHEAD(PrimarySuffix())
+ expr = PrimarySuffix(expr))*
{return expr;}
|
expr = ArrayDeclarator()
{return expr;}
}
+/**
+ * An array declarator.
+ * array(vars)
+ * @return an array
+ */
ArrayInitializer ArrayDeclarator() :
{
final ArrayVariableDeclaration[] vars;
@@ -1582,9 +1587,10 @@ Expression PrimaryPrefix() :
| expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
OperatorIds.NEW,
pos);}
-| var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(),
- pos,
- SimpleCharStream.getPosition());}
+| var = VariableDeclaratorId() {return new VariableDeclaration(currentSegment,
+ var.toCharArray(),
+ pos,
+ SimpleCharStream.getPosition());}
}
PrefixedUnaryExpression classInstantiation() :
@@ -1623,7 +1629,7 @@ ConstantIdentifier ClassIdentifier():
SimpleCharStream.getPosition());}
}
-AbstractSuffixExpression PrimarySuffix(Expression prefix) :
+AbstractSuffixExpression PrimarySuffix(final Expression prefix) :
{
final AbstractSuffixExpression expr;
}
@@ -1632,7 +1638,7 @@ AbstractSuffixExpression PrimarySuffix(Expression prefix) :
| expr = VariableSuffix(prefix) {return expr;}
}
-AbstractSuffixExpression VariableSuffix(Expression prefix) :
+AbstractSuffixExpression VariableSuffix(final Expression prefix) :
{
String expr = null;
final int pos = SimpleCharStream.getPosition();
@@ -1686,7 +1692,7 @@ Literal Literal() :
return new NullLiteral(pos-4,pos);}
}
-FunctionCall Arguments(Expression func) :
+FunctionCall Arguments(final Expression func) :
{
Expression[] args = null;
}
@@ -1730,7 +1736,7 @@ final ArrayList list = new ArrayList();
}
)*
{
- Expression[] arguments = new Expression[list.size()];
+ final Expression[] arguments = new Expression[list.size()];
list.toArray(arguments);
return arguments;}
}
@@ -1789,6 +1795,69 @@ Statement StatementNoBreak() :
return statement;}
| statement = StaticStatement() {return statement;}
| statement = GlobalStatement() {return statement;}
+| statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
+}
+
+Define defineStatement() :
+{
+ final int start = SimpleCharStream.getPosition();
+ Expression defineName,defineValue;
+}
+{
+
+ try {
+
+ } catch (ParseException e) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
+ errorLevel = ERROR;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseException(e);
+ }
+ try {
+ defineName = Expression()
+ } catch (ParseException e) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
+ errorLevel = ERROR;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ throw e;
+ }
+ try {
+
+ } catch (ParseException e) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
+ errorLevel = ERROR;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseException(e);
+ }
+ try {
+ ( defineValue = PrintExpression()
+ | LOOKAHEAD(varAssignation())
+ defineValue = varAssignation()
+ | defineValue = ConditionalExpression())
+ } catch (ParseException e) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
+ errorLevel = ERROR;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ throw e;
+ }
+ try {
+
+ } catch (ParseException e) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
+ errorLevel = ERROR;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseException(e);
+ }
+ {return new Define(currentSegment,
+ defineName,
+ defineValue,
+ start,
+ SimpleCharStream.getPosition());}
}
/**
@@ -1809,15 +1878,15 @@ Statement Statement() :
HTMLBlock htmlBlock() :
{
final int startIndex = nodePtr;
- AstNode[] blockNodes;
- int nbNodes;
+ final AstNode[] blockNodes;
+ final int nbNodes;
}
{
(phpEchoBlock())*
try {
( | )
} catch (ParseException e) {
- errorMessage = "End of file unexpected, '
@@ -1932,7 +2000,7 @@ ListExpression ListExpression() :
}
[ expression = Expression()
{
- String[] strings = new String[list.size()];
+ final String[] strings = new String[list.size()];
list.toArray(strings);
return new ListExpression(strings,
expression,
@@ -1940,7 +2008,7 @@ ListExpression ListExpression() :
SimpleCharStream.getPosition());}
]
{
- String[] strings = new String[list.size()];
+ final String[] strings = new String[list.size()];
list.toArray(strings);
return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
}
@@ -1973,7 +2041,7 @@ EchoStatement EchoStatement() :
throw e;
}
}
- {Expression[] exprs = new Expression[expressions.size()];
+ {final Expression[] exprs = new Expression[expressions.size()];
expressions.toArray(exprs);
return new EchoStatement(exprs,pos);}
}
@@ -1982,8 +2050,8 @@ GlobalStatement GlobalStatement() :
{
final int pos = SimpleCharStream.getPosition();
String expr;
- ArrayList vars = new ArrayList();
- GlobalStatement global;
+ final ArrayList vars = new ArrayList();
+ final GlobalStatement global;
}
{
@@ -1996,7 +2064,7 @@ GlobalStatement GlobalStatement() :
try {
{
- String[] strings = new String[vars.size()];
+ final String[] strings = new String[vars.size()];
vars.toArray(strings);
global = new GlobalStatement(currentSegment,
strings,
@@ -2025,7 +2093,7 @@ StaticStatement StaticStatement() :
try {
{
- String[] strings = new String[vars.size()];
+ final String[] strings = new String[vars.size()];
vars.toArray(strings);
return new StaticStatement(strings,
pos,
@@ -2085,7 +2153,7 @@ Block Block() :
throw e;
}
{
- Statement[] statements = new Statement[list.size()];
+ final Statement[] statements = new Statement[list.size()];
list.toArray(statements);
return new Block(statements,pos,SimpleCharStream.getPosition());}
}
@@ -2099,6 +2167,7 @@ Statement BlockStatement() :
statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
return statement;}
} catch (ParseException e) {
+ if (errorMessage != null) throw e;
errorMessage = "statement expected";
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
@@ -2107,6 +2176,7 @@ Statement BlockStatement() :
}
| statement = ClassDeclaration() {return statement;}
| statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
+ currentSegment.add((MethodDeclaration) statement);
return statement;}
}
@@ -2120,7 +2190,8 @@ Statement BlockStatementNoBreak() :
{
statement = StatementNoBreak() {return statement;}
| statement = ClassDeclaration() {return statement;}
-| statement = MethodDeclaration() {return statement;}
+| statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
+ return statement;}
}
VariableDeclaration[] LocalVariableDeclaration() :
@@ -2133,7 +2204,7 @@ VariableDeclaration[] LocalVariableDeclaration() :
{list.add(var);}
( var = LocalVariableDeclarator() {list.add(var);})*
{
- VariableDeclaration[] vars = new VariableDeclaration[list.size()];
+ final VariableDeclaration[] vars = new VariableDeclaration[list.size()];
list.toArray(vars);
return vars;}
}
@@ -2170,19 +2241,19 @@ EmptyStatement EmptyStatement() :
return new EmptyStatement(pos-1,pos);}
}
-Statement StatementExpression() :
+Expression StatementExpression() :
{
- Expression expr,expr2;
- int operator;
+ final Expression expr,expr2;
+ final int operator;
}
{
expr = PreIncDecExpression() {return expr;}
|
expr = PrimaryExpression()
- [ {return new PostfixedUnaryExpression(expr,
+ [ {return new PostfixedUnaryExpression(expr,
OperatorIds.PLUS_PLUS,
SimpleCharStream.getPosition());}
- | {return new PostfixedUnaryExpression(expr,
+ | {return new PostfixedUnaryExpression(expr,
OperatorIds.MINUS_MINUS,
SimpleCharStream.getPosition());}
| operator = AssignmentOperator() expr2 = Expression()
@@ -2244,7 +2315,7 @@ AbstractCase[] switchStatementBrace() :
try {
{
- AbstractCase[] abcase = new AbstractCase[cases.size()];
+ final AbstractCase[] abcase = new AbstractCase[cases.size()];
cases.toArray(abcase);
return abcase;}
} catch (ParseException e) {
@@ -2290,7 +2361,7 @@ AbstractCase[] switchStatementColon(final int start, final int end) :
try {
{
- AbstractCase[] abcase = new AbstractCase[cases.size()];
+ final AbstractCase[] abcase = new AbstractCase[cases.size()];
cases.toArray(abcase);
return abcase;}
} catch (ParseException e) {
@@ -2315,7 +2386,7 @@ AbstractCase switchLabel0() :
| statement = htmlBlock() {stmts.add(statement);})*
[ statement = BreakStatement() {stmts.add(statement);}]
{
- Statement[] stmtsArray = new Statement[stmts.size()];
+ final Statement[] stmtsArray = new Statement[stmts.size()];
stmts.toArray(stmtsArray);
if (expr == null) {//it's a default
return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
@@ -2391,8 +2462,8 @@ Break BreakStatement() :
IfStatement IfStatement() :
{
final int pos = SimpleCharStream.getPosition();
- Expression condition;
- IfStatement ifStatement;
+ final Expression condition;
+ final IfStatement ifStatement;
}
{
condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
@@ -2417,28 +2488,28 @@ Expression Condition(final String keyword) :
condition = Expression()
try {
- {return condition;}
} catch (ParseException e) {
errorMessage = "')' expected after " + keyword + " keyword";
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
+ {return condition;}
}
-IfStatement IfStatement0(Expression condition, final int start,final int end) :
+IfStatement IfStatement0(final Expression condition, final int start,final int end) :
{
Statement statement;
- Statement stmt;
+ final Statement stmt;
final Statement[] statementsArray;
ElseIf elseifStatement;
Else elseStatement = null;
- ArrayList stmts;
+ final ArrayList stmts;
final ArrayList elseIfList = new ArrayList();
- ElseIf[] elseIfs;
+ final ElseIf[] elseIfs;
int pos = SimpleCharStream.getPosition();
- int endStatements;
+ final int endStatements;
}
{
@@ -2492,10 +2563,10 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) :
stmts.toArray(statementsArray);
return new IfStatement(condition,
new Block(statementsArray,pos,endStatements),
- elseIfs,
- elseStatement,
- pos,
- SimpleCharStream.getPosition());
+ elseIfs,
+ elseStatement,
+ pos,
+ SimpleCharStream.getPosition());
}
}
@@ -2532,7 +2603,7 @@ IfStatement IfStatement0(Expression condition, final int start,final int end) :
ElseIf ElseIfStatementColon() :
{
- Expression condition;
+ final Expression condition;
Statement statement;
final ArrayList list = new ArrayList();
final int pos = SimpleCharStream.getPosition();
@@ -2542,7 +2613,7 @@ ElseIf ElseIfStatementColon() :
( statement = Statement() {list.add(statement);}
| statement = htmlBlock() {list.add(statement);})*
{
- Statement[] stmtsArray = new Statement[list.size()];
+ final Statement[] stmtsArray = new Statement[list.size()];
list.toArray(stmtsArray);
return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
}
@@ -2557,22 +2628,22 @@ Else ElseStatementColon() :
( statement = Statement() {list.add(statement);}
| statement = htmlBlock() {list.add(statement);})*
{
- Statement[] stmtsArray = new Statement[list.size()];
+ final Statement[] stmtsArray = new Statement[list.size()];
list.toArray(stmtsArray);
return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
}
ElseIf ElseIfStatement() :
{
- Expression condition;
- Statement statement;
+ final Expression condition;
+ final Statement statement;
final ArrayList list = new ArrayList();
final int pos = SimpleCharStream.getPosition();
}
{
condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
{
- Statement[] stmtsArray = new Statement[list.size()];
+ final Statement[] stmtsArray = new Statement[list.size()];
list.toArray(stmtsArray);
return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
}
@@ -2620,7 +2691,7 @@ Statement WhileStatement0(final int start, final int end) :
try {
{
- Statement[] stmtsArray = new Statement[stmts.size()];
+ final Statement[] stmtsArray = new Statement[stmts.size()];
stmts.toArray(stmtsArray);
return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
} catch (ParseException e) {
@@ -2731,9 +2802,9 @@ ForStatement ForStatement() :
{
final Token token;
final int pos = SimpleCharStream.getPosition();
-Statement[] initializations = null;
+Expression[] initializations = null;
Expression condition = null;
-Statement[] increments = null;
+Expression[] increments = null;
Statement action;
final ArrayList list = new ArrayList();
final int startBlock, endBlock;
@@ -2784,7 +2855,7 @@ final int startBlock, endBlock;
try {
{
- Statement[] stmtsArray = new Statement[list.size()];
+ final Statement[] stmtsArray = new Statement[list.size()];
list.toArray(stmtsArray);
return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
} catch (ParseException e) {
@@ -2797,31 +2868,31 @@ final int startBlock, endBlock;
)
}
-Statement[] ForInit() :
+Expression[] ForInit() :
{
- Statement[] statements;
+ final Expression[] exprs;
}
{
LOOKAHEAD(LocalVariableDeclaration())
- statements = LocalVariableDeclaration()
- {return statements;}
+ exprs = LocalVariableDeclaration()
+ {return exprs;}
|
- statements = StatementExpressionList()
- {return statements;}
+ exprs = StatementExpressionList()
+ {return exprs;}
}
-Statement[] StatementExpressionList() :
+Expression[] StatementExpressionList() :
{
final ArrayList list = new ArrayList();
- Statement expr;
+ final Expression expr;
}
{
expr = StatementExpression() {list.add(expr);}
( StatementExpression() {list.add(expr);})*
{
- Statement[] stmtsArray = new Statement[list.size()];
- list.toArray(stmtsArray);
- return stmtsArray;}
+ final Expression[] exprsArray = new Expression[list.size()];
+ list.toArray(exprsArray);
+ return exprsArray;}
}
Continue ContinueStatement() :