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 cb90b27..530693d 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,7 +38,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 junit.framework.Assert;
/**
* A new php parser.
@@ -50,9 +51,6 @@ import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
*/
public final class PHPParser extends PHPParserSuperclass {
- /** The file that is parsed. */
- private static IFile fileToParse;
-
/** The current segment. */
private static OutlineableWithChildren currentSegment;
@@ -60,8 +58,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 */
@@ -85,8 +81,10 @@ public final class PHPParser extends PHPParserSuperclass {
/** The cursor in expression stack. */
private static int nodePtr;
+ private static final boolean PARSER_DEBUG = false;
+
public final void setFileToParse(final IFile fileToParse) {
- this.fileToParse = fileToParse;
+ PHPParser.fileToParse = fileToParse;
}
public PHPParser() {
@@ -94,7 +92,7 @@ public final class PHPParser extends PHPParserSuperclass {
public PHPParser(final IFile fileToParse) {
this(new StringReader(""));
- this.fileToParse = fileToParse;
+ PHPParser.fileToParse = fileToParse;
}
/**
@@ -110,12 +108,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;
@@ -152,6 +150,10 @@ public final class PHPParser extends PHPParserSuperclass {
* @param e the ParseException
*/
private static void processParseException(final ParseException e) {
+ if (PARSER_DEBUG) {
+ e.printStackTrace();
+ Assert.assertTrue(false);
+ }
if (errorMessage == null) {
PHPeclipsePlugin.log(e);
errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
@@ -160,10 +162,11 @@ public final class PHPParser extends PHPParserSuperclass {
}
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) {
@@ -190,42 +193,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++) {
@@ -235,9 +213,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("", "");
@@ -256,7 +234,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);
@@ -297,13 +275,31 @@ 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-3,
+ SimpleCharStream.currentBuffer.indexOf("\n",
+ currentPosition)-1);
+ PHPeclipsePlugin.log(1,SimpleCharStream.currentBuffer.toString());
+ try {
+ setMarker(fileToParse,
+ todo,
+ SimpleCharStream.getBeginLine(),
+ TASK,
+ "Line "+SimpleCharStream.getBeginLine());
+ } catch (CoreException e) {
+ PHPeclipsePlugin.log(e);
+ }
+ }
+
private static final void parse() throws ParseException {
phpFile();
}
@@ -344,34 +340,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
}
@@ -404,6 +396,7 @@ MORE :
|
|
|
+|
|
| ">
|
@@ -469,8 +462,8 @@ MORE :
{
|
-|
-|
+|
+|
|
|
|
@@ -511,39 +504,16 @@ MORE :
<#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
|
| | )>
-|
-|
-|
+|
+|
+|
}
/* IDENTIFIERS */
TOKEN :
{
- < IDENTIFIER: (|) (||)* >
+ |) (||)* >
|
< #LETTER:
["a"-"z"] | ["A"-"Z"]
@@ -608,7 +578,7 @@ MORE :
TOKEN :
{
- < DOLLAR_ID: >
+ >
}
void phpFile() :
@@ -616,7 +586,7 @@ void phpFile() :
{
try {
(PhpBlock())*
-
+ {PHPParser.createNewHTMLCode();}
} catch (TokenMgrError e) {
PHPeclipsePlugin.log(e);
errorStart = SimpleCharStream.getPosition();
@@ -635,9 +605,11 @@ void phpFile() :
void PhpBlock() :
{
final int start = SimpleCharStream.getPosition();
+ final PHPEchoBlock phpEchoBlock;
}
{
- phpEchoBlock()
+ phpEchoBlock = phpEchoBlock()
+ {pushOnAstNodes(phpEchoBlock);}
|
[
|
@@ -668,7 +640,7 @@ PHPEchoBlock phpEchoBlock() :
{
final Expression expr;
final int pos = SimpleCharStream.getPosition();
- PHPEchoBlock echoBlock;
+ final PHPEchoBlock echoBlock;
}
{
expr = Expression() [ ]
@@ -687,8 +659,7 @@ 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;
@@ -710,7 +681,7 @@ ClassDeclaration ClassDeclaration() :
try {
superclassName =
- {superclassNameImage = superclassName .image.toCharArray();}
+ {superclassNameImage = superclassName.image.toCharArray();}
} catch (ParseException e) {
errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
errorLevel = ERROR;
@@ -743,62 +714,63 @@ 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;
+ processParseException(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;
+ processParseException(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();
}
{
- variableDeclaration = VariableDeclarator()
+ variableDeclaration = VariableDeclaratorNoSuffix()
{arrayList.add(variableDeclaration);
- outlineInfo.addVariable(new String(variableDeclaration.name));
- currentSegment.add(variableDeclaration);}
- ( variableDeclaration = VariableDeclarator()
+ outlineInfo.addVariable(new String(variableDeclaration.name()));}
+ (
+ variableDeclaration = VariableDeclaratorNoSuffix()
{arrayList.add(variableDeclaration);
- outlineInfo.addVariable(new String(variableDeclaration.name));
- currentSegment.add(variableDeclaration);}
+ outlineInfo.addVariable(new String(variableDeclaration.name()));}
)*
try {
@@ -818,6 +790,48 @@ FieldDeclaration FieldDeclaration() :
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;
+ final int pos = SimpleCharStream.getPosition();
+}
+{
+ varName =
+ [
+
+ try {
+ initializer = VariableInitializer()
+ } catch (ParseException e) {
+ errorMessage = "Literal expression expected in variable initializer";
+ errorLevel = ERROR;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ processParseException(e);
+ }
+ ]
+ {
+ if (initializer == null) {
+ return new VariableDeclaration(currentSegment,
+ new Variable(varName.image.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
+ pos,
+ SimpleCharStream.getPosition());
+ }
+ return new VariableDeclaration(currentSegment,
+ new Variable(varName.image.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
+ initializer,
+ VariableDeclaration.EQUAL,
+ pos);
+ }
+}
+
+/**
+ * this will be used by static statement
+ */
VariableDeclaration VariableDeclarator() :
{
final String varName;
@@ -835,20 +849,21 @@ VariableDeclaration VariableDeclarator() :
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
]
{
if (initializer == null) {
return new VariableDeclaration(currentSegment,
- varName.toCharArray(),
+ new Variable(varName.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.length()-1,SimpleCharStream.getPosition()),
pos,
SimpleCharStream.getPosition());
}
return new VariableDeclaration(currentSegment,
- varName.toCharArray(),
- initializer,
- pos);
+ new Variable(varName.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.length()-1,SimpleCharStream.getPosition()),
+ initializer,
+ VariableDeclaration.EQUAL,
+ pos);
}
}
@@ -858,23 +873,27 @@ VariableDeclaration VariableDeclarator() :
*/
String VariableDeclaratorId() :
{
- String expr;
- Expression expression;
- final StringBuffer buff = new StringBuffer();
+ final String var;
+ Expression expression = null;
final int pos = SimpleCharStream.getPosition();
ConstantIdentifier ex;
}
{
try {
- expr = Variable() {buff.append(expr);}
- ( LOOKAHEAD(2)
- {ex = new ConstantIdentifier(expr.toCharArray(),
+ var = Variable()
+ (
+ LOOKAHEAD(2)
+ {ex = new ConstantIdentifier(var.toCharArray(),
pos,
SimpleCharStream.getPosition());}
expression = VariableSuffix(ex)
- {buff.append(expression.toStringExpression());}
)*
- {return buff.toString();}
+ {
+ if (expression == null) {
+ return var;
+ }
+ return expression.toStringExpression();
+ }
} catch (ParseException e) {
errorMessage = "'$' expected for variable identifier";
errorLevel = ERROR;
@@ -884,6 +903,10 @@ String VariableDeclaratorId() :
}
}
+/**
+ * Return a variablename without the $.
+ * @return a variable name
+ */
String Variable():
{
final StringBuffer buff;
@@ -894,7 +917,7 @@ String Variable():
{
token = [ expression = Expression() ]
{
- if (expression == null && !assigning) {
+ if (expression == null) {
return token.image.substring(1);
}
buff = new StringBuffer(token.image);
@@ -905,13 +928,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;
}
@@ -977,12 +1004,13 @@ Expression VariableInitializer() :
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());}
}
@@ -993,16 +1021,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;}
}
@@ -1015,6 +1047,7 @@ MethodDeclaration MethodDeclaration() :
{
final MethodDeclaration functionDeclaration;
final Block block;
+ final OutlineableWithChildren seg = currentSegment;
}
{
@@ -1029,20 +1062,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;}
}
/**
@@ -1071,12 +1095,13 @@ MethodDeclaration MethodDeclarator() :
processParseException(e);
}
formalParameters = FormalParameters()
- {return new MethodDeclaration(currentSegment,
- identifierChar,
- formalParameters,
- reference != null,
- pos,
- SimpleCharStream.getPosition());}
+ {MethodDeclaration method = new MethodDeclaration(currentSegment,
+ identifierChar,
+ formalParameters,
+ reference != null,
+ pos,
+ SimpleCharStream.getPosition());
+ return method;}
}
/**
@@ -1096,15 +1121,16 @@ 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);}
- (
- 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 {
} catch (ParseException e) {
@@ -1112,7 +1138,7 @@ Hashtable FormalParameters() :
errorLevel = ERROR;
errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
+ processParseException(e);
}
{return parameters;}
}
@@ -1127,7 +1153,7 @@ VariableDeclaration FormalParameter() :
Token token = null;
}
{
- [token = ] variableDeclaration = VariableDeclarator()
+ [token = ] variableDeclaration = VariableDeclaratorNoSuffix()
{
if (token != null) {
variableDeclaration.setReference(true);
@@ -1161,64 +1187,85 @@ ConstantIdentifier Type() :
Expression Expression() :
{
final Expression expr;
-}
-{
- expr = PrintExpression() {return expr;}
-| expr = ListExpression() {return expr;}
-| LOOKAHEAD(varAssignation())
- expr = varAssignation() {return expr;}
-| expr = ConditionalExpression() {return expr;}
-}
-
-/**
- * A Variable assignation.
- * varName (an assign operator) any expression
- */
-VarAssignation varAssignation() :
-{
- String varName;
- final Expression expression;
- final int assignOperator;
+ Expression initializer = null;
final int pos = SimpleCharStream.getPosition();
+ int assignOperator = -1;
}
{
- varName = VariableDeclaratorId()
- assignOperator = AssignmentOperator()
+ LOOKAHEAD(1)
+ expr = ConditionalExpression()
+ [
+ assignOperator = AssignmentOperator()
try {
- expression = Expression()
+ initializer = Expression()
} catch (ParseException e) {
if (errorMessage != null) {
throw e;
}
- errorMessage = "expression expected";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
errorLevel = ERROR;
- errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = SimpleCharStream.getPosition() + 1;
+ errorEnd = SimpleCharStream.getPosition();
throw e;
}
- {return new VarAssignation(varName.toCharArray(),
- expression,
- assignOperator,
- pos,
- SimpleCharStream.getPosition());}
+ ]
+ {
+ char[] varName = expr.toStringExpression().substring(1).toCharArray();
+ if (assignOperator == -1) {
+ return new VariableDeclaration(currentSegment,
+ new Variable(varName,SimpleCharStream.getPosition()-varName.length-1,SimpleCharStream.getPosition()),
+ pos,
+ SimpleCharStream.getPosition());
+ return expr;
+ }
+ return new VariableDeclaration(currentSegment,
+ new Variable(varName,SimpleCharStream.getPosition()-varName.length-1,SimpleCharStream.getPosition()),
+ initializer,
+ assignOperator,
+ pos);
+ }
+ {return expr;}
+| expr = ExpressionWBang() {return expr;}
}
+Expression ExpressionWBang() :
+{
+ final Expression expr;
+ final int pos = SimpleCharStream.getPosition();
+}
+{
+ expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
+| expr = ExpressionNoBang() {return expr;}
+}
+
+Expression ExpressionNoBang() :
+{
+ Expression expr;
+}
+{
+ expr = PrintExpression() {return expr;}
+| expr = ListExpression() {return expr;}
+}
+
+/**
+ * Any assignement operator.
+ * @return the assignement operator id
+ */
int AssignmentOperator() :
{}
{
- {return VarAssignation.EQUAL;}
-| {return VarAssignation.STAR_EQUAL;}
-| {return VarAssignation.SLASH_EQUAL;}
-| {return VarAssignation.REM_EQUAL;}
-| {return VarAssignation.PLUS_EQUAL;}
-| {return VarAssignation.MINUS_EQUAL;}
-| {return VarAssignation.LSHIFT_EQUAL;}
-| {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
-| {return VarAssignation.AND_EQUAL;}
-| {return VarAssignation.XOR_EQUAL;}
-| {return VarAssignation.OR_EQUAL;}
-| {return VarAssignation.DOT_EQUAL;}
-| {return VarAssignation.TILDE_EQUAL;}
+ {return VariableDeclaration.EQUAL;}
+| {return VariableDeclaration.STAR_EQUAL;}
+| {return VariableDeclaration.SLASH_EQUAL;}
+| {return VariableDeclaration.REM_EQUAL;}
+| {return VariableDeclaration.PLUS_EQUAL;}
+| {return VariableDeclaration.MINUS_EQUAL;}
+| {return VariableDeclaration.LSHIFT_EQUAL;}
+| {return VariableDeclaration.RSIGNEDSHIFT_EQUAL;}
+| {return VariableDeclaration.AND_EQUAL;}
+| {return VariableDeclaration.XOR_EQUAL;}
+| {return VariableDeclaration.OR_EQUAL;}
+| {return VariableDeclaration.DOT_EQUAL;}
+| {return VariableDeclaration.TILDE_EQUAL;}
}
Expression ConditionalExpression() :
@@ -1248,7 +1295,8 @@ Expression ConditionalOrExpression() :
(
{operator = OperatorIds.OR_OR;}
| <_ORL> {operator = OperatorIds.ORL;}
- ) expr2 = ConditionalAndExpression()
+ )
+ expr2 = ConditionalAndExpression()
{
expr = new BinaryExpression(expr,expr2,operator);
}
@@ -1316,6 +1364,7 @@ Expression AndExpression() :
{
expr = EqualityExpression()
(
+ LOOKAHEAD(1)
expr2 = EqualityExpression()
{expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
)*
@@ -1398,6 +1447,7 @@ Expression AdditiveExpression() :
{
expr = MultiplicativeExpression()
(
+ LOOKAHEAD(1)
( {operator = OperatorIds.PLUS;}
| {operator = OperatorIds.MINUS;} )
expr2 = MultiplicativeExpression()
@@ -1437,26 +1487,34 @@ Expression MultiplicativeExpression() :
*/
Expression UnaryExpression() :
{
- Expression expr;
+ final Expression expr;
final int pos = SimpleCharStream.getPosition();
}
{
expr = UnaryExpressionNoPrefix()
{return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
|
- expr = AtUnaryExpression() {return expr;}
+ expr = AtNotUnaryExpression() {return expr;}
}
-Expression AtUnaryExpression() :
+/**
+ * An expression prefixed (or not) by one or more @ and !.
+ * @return the expression
+ */
+Expression AtNotUnaryExpression() :
{
- Expression expr;
+ final Expression expr;
final int pos = SimpleCharStream.getPosition();
}
{
- expr = AtUnaryExpression()
+ expr = AtNotUnaryExpression()
{return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
|
+
+ expr = AtNotUnaryExpression()
+ {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
+|
expr = UnaryExpressionNoPrefix()
{return expr;}
}
@@ -1464,14 +1522,17 @@ Expression AtUnaryExpression() :
Expression UnaryExpressionNoPrefix() :
{
- Expression expr;
- int operator;
+ final Expression expr;
+ final int operator;
final int pos = SimpleCharStream.getPosition();
}
{
- ( {operator = OperatorIds.PLUS;}
- | {operator = OperatorIds.MINUS;})
- expr = UnaryExpression()
+ (
+ {operator = OperatorIds.PLUS;}
+ |
+ {operator = OperatorIds.MINUS;}
+ )
+ expr = UnaryExpression()
{return new PrefixedUnaryExpression(expr,operator,pos);}
|
expr = PreIncDecExpression()
@@ -1479,6 +1540,9 @@ Expression UnaryExpressionNoPrefix() :
|
expr = UnaryExpressionNotPlusMinus()
{return expr;}
+/*|
+ LOOKAHEAD(2)
+ expr = PrintExpression() {return expr;}*/
}
@@ -1489,20 +1553,22 @@ final int operator;
final int pos = SimpleCharStream.getPosition();
}
{
- ( {operator = OperatorIds.PLUS_PLUS;}
- | {operator = OperatorIds.MINUS_MINUS;})
- expr = PrimaryExpression()
+ (
+ {operator = OperatorIds.PLUS_PLUS;}
+ |
+ {operator = OperatorIds.MINUS_MINUS;}
+ )
+ expr = PrimaryExpression()
{return new PrefixedUnaryExpression(expr,operator,pos);}
}
Expression UnaryExpressionNotPlusMinus() :
{
- Expression expr;
+ final Expression expr;
final int pos = SimpleCharStream.getPosition();
}
{
- expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
-| LOOKAHEAD( (Type() | ) )
+ LOOKAHEAD( (Type() | ) )
expr = CastExpression() {return expr;}
| expr = PostfixExpression() {return expr;}
| expr = Literal() {return expr;}
@@ -1527,22 +1593,28 @@ final int pos = SimpleCharStream.getPosition();
}
{
- (type = Type()
- | {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
+ (
+ type = Type()
+ |
+ {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());}
+ )
expr = UnaryExpression()
{return new CastExpression(type,expr,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;
@@ -1553,39 +1625,30 @@ Expression PostfixExpression() :
Expression PrimaryExpression() :
{
- final Token identifier;
Expression expr;
+ int assignOperator = -1;
+ final Token identifier;
+ final String var;
final int pos = SimpleCharStream.getPosition();
}
{
- LOOKAHEAD(2)
- identifier = expr = ClassIdentifier()
- {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
- pos,
- SimpleCharStream.getPosition()),
- expr,
- ClassAccess.STATIC);}
+ expr = PrimaryPrefix()
(expr = PrimarySuffix(expr))*
+ [ expr = Arguments(expr) ]
{return expr;}
|
- expr = PrimaryPrefix()
- (expr = PrimarySuffix(expr))*
+ expr = ClassIdentifier()
+ {expr = new PrefixedUnaryExpression(expr,
+ OperatorIds.NEW,
+ pos);
+ }
+ [ expr = Arguments(expr) ]
{return expr;}
|
expr = ArrayDeclarator()
{return expr;}
}
-ArrayInitializer ArrayDeclarator() :
-{
- final ArrayVariableDeclaration[] vars;
- final int pos = SimpleCharStream.getPosition();
-}
-{
- vars = ArrayInitializer()
- {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
-}
-
Expression PrimaryPrefix() :
{
final Expression expr;
@@ -1597,12 +1660,39 @@ Expression PrimaryPrefix() :
token = {return new ConstantIdentifier(token.image.toCharArray(),
pos,
SimpleCharStream.getPosition());}
-| expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
- OperatorIds.NEW,
- pos);}
-| var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(),
- pos,
- SimpleCharStream.getPosition());}
+|
+ var = VariableDeclaratorId() {return new Variable(var.toCharArray(),
+ pos,
+ SimpleCharStream.getPosition());}
+}
+
+AbstractSuffixExpression PrimarySuffix(final Expression prefix) :
+{
+ final AbstractSuffixExpression suffix;
+ final Expression expr;
+}
+{
+ suffix = VariableSuffix(prefix) {return suffix;}
+| expr = ClassIdentifier()
+ {suffix = new ClassAccess(prefix,
+ expr,
+ ClassAccess.STATIC);
+ return suffix;}
+}
+
+/**
+ * An array declarator.
+ * array(vars)
+ * @return an array
+ */
+ArrayInitializer ArrayDeclarator() :
+{
+ final ArrayVariableDeclaration[] vars;
+ final int pos = SimpleCharStream.getPosition();
+}
+{
+ vars = ArrayInitializer()
+ {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
}
PrefixedUnaryExpression classInstantiation() :
@@ -1631,26 +1721,19 @@ ConstantIdentifier ClassIdentifier():
final String expr;
final Token token;
final int pos = SimpleCharStream.getPosition();
+ final ConstantIdentifier type;
}
{
token = {return new ConstantIdentifier(token.image.toCharArray(),
pos,
SimpleCharStream.getPosition());}
+| type = Type() {return type;}
| expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
pos,
SimpleCharStream.getPosition());}
}
-AbstractSuffixExpression PrimarySuffix(Expression prefix) :
-{
- final AbstractSuffixExpression expr;
-}
-{
- expr = Arguments(prefix) {return expr;}
-| expr = VariableSuffix(prefix) {return expr;}
-}
-
-AbstractSuffixExpression VariableSuffix(Expression prefix) :
+AbstractSuffixExpression VariableSuffix(final Expression prefix) :
{
String expr = null;
final int pos = SimpleCharStream.getPosition();
@@ -1704,7 +1787,7 @@ Literal Literal() :
return new NullLiteral(pos-4,pos);}
}
-FunctionCall Arguments(Expression func) :
+FunctionCall Arguments(final Expression func) :
{
Expression[] args = null;
}
@@ -1748,13 +1831,14 @@ final ArrayList list = new ArrayList();
}
)*
{
- Expression[] arguments = new Expression[list.size()];
+ final Expression[] arguments = new Expression[list.size()];
list.toArray(arguments);
return arguments;}
}
/**
* A Statement without break.
+ * @return a statement
*/
Statement StatementNoBreak() :
{
@@ -1763,6 +1847,40 @@ Statement StatementNoBreak() :
}
{
LOOKAHEAD(2)
+ statement = expressionStatement() {return statement;}
+| LOOKAHEAD(1)
+ statement = LabeledStatement() {return statement;}
+| statement = Block() {return statement;}
+| statement = EmptyStatement() {return statement;}
+| statement = SwitchStatement() {return statement;}
+| statement = IfStatement() {return statement;}
+| statement = WhileStatement() {return statement;}
+| statement = DoStatement() {return statement;}
+| statement = ForStatement() {return statement;}
+| statement = ForeachStatement() {return statement;}
+| statement = ContinueStatement() {return statement;}
+| statement = ReturnStatement() {return statement;}
+| statement = EchoStatement() {return statement;}
+| [token=] statement = IncludeStatement()
+ {if (token != null) {
+ ((InclusionStatement)statement).silent = true;
+ }
+ return statement;}
+| statement = StaticStatement() {return statement;}
+| statement = GlobalStatement() {return statement;}
+| statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
+}
+
+/**
+ * A statement expression.
+ * expression ;
+ * @return an expression
+ */
+Statement expressionStatement() :
+{
+ final Statement statement;
+}
+{
statement = Expression()
try {
@@ -1776,37 +1894,65 @@ Statement StatementNoBreak() :
}
}
{return statement;}
-| LOOKAHEAD(2)
- statement = LabeledStatement() {return statement;}
-| statement = Block() {return statement;}
-| statement = EmptyStatement() {return statement;}
-| statement = StatementExpression()
+}
+
+Define defineStatement() :
+{
+ final int start = SimpleCharStream.getPosition();
+ Expression defineName,defineValue;
+}
+{
+
try {
-
+
} catch (ParseException e) {
- errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
+ 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;
}
- {return statement;}
-| statement = SwitchStatement() {return statement;}
-| statement = IfStatement() {return statement;}
-| statement = WhileStatement() {return statement;}
-| statement = DoStatement() {return statement;}
-| statement = ForStatement() {return statement;}
-| statement = ForeachStatement() {return statement;}
-| statement = ContinueStatement() {return statement;}
-| statement = ReturnStatement() {return statement;}
-| statement = EchoStatement() {return statement;}
-| [token=] statement = IncludeStatement()
- {if (token != null) {
- ((InclusionStatement)statement).silent = true;
+ 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 statement;}
-| statement = StaticStatement() {return statement;}
-| statement = GlobalStatement() {return statement;}
+ try {
+ defineValue = 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);
+ }
+ {return new Define(currentSegment,
+ defineName,
+ defineValue,
+ start,
+ SimpleCharStream.getPosition());}
}
/**
@@ -1827,15 +1973,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, '
@@ -1950,7 +2095,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,
@@ -1958,7 +2103,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());}
}
@@ -1991,7 +2136,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);}
}
@@ -2000,8 +2145,8 @@ GlobalStatement GlobalStatement() :
{
final int pos = SimpleCharStream.getPosition();
String expr;
- ArrayList vars = new ArrayList();
- GlobalStatement global;
+ final ArrayList vars = new ArrayList();
+ final GlobalStatement global;
}
{
@@ -2014,7 +2159,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,
@@ -2038,12 +2183,12 @@ StaticStatement StaticStatement() :
VariableDeclaration expr;
}
{
- expr = VariableDeclarator() {vars.add(new String(expr.name));}
- ( expr = VariableDeclarator() {vars.add(new String(expr.name));})*
+ expr = VariableDeclarator() {vars.add(new String(expr.name()));}
+ ( expr = VariableDeclarator() {vars.add(new String(expr.name()));})*
try {
{
- String[] strings = new String[vars.size()];
+ final String[] strings = new String[vars.size()];
vars.toArray(strings);
return new StaticStatement(strings,
pos,
@@ -2103,7 +2248,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());}
}
@@ -2113,18 +2258,12 @@ Statement BlockStatement() :
final Statement statement;
}
{
- try {
statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
return statement;}
- } catch (ParseException e) {
- errorMessage = "statement expected";
- errorLevel = ERROR;
- errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
- }
| statement = ClassDeclaration() {return statement;}
| statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
+ currentSegment.add((MethodDeclaration) statement);
+ ((MethodDeclaration) statement).analyzeCode();
return statement;}
}
@@ -2138,9 +2277,14 @@ Statement BlockStatementNoBreak() :
{
statement = StatementNoBreak() {return statement;}
| statement = ClassDeclaration() {return statement;}
-| statement = MethodDeclaration() {return statement;}
+| statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
+ ((MethodDeclaration) statement).analyzeCode();
+ return statement;}
}
+/**
+ * used only by ForInit()
+ */
VariableDeclaration[] LocalVariableDeclaration() :
{
final ArrayList list = new ArrayList();
@@ -2151,11 +2295,14 @@ 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;}
}
+/**
+ * used only by LocalVariableDeclaration().
+ */
VariableDeclaration LocalVariableDeclarator() :
{
final String varName;
@@ -2167,13 +2314,14 @@ VariableDeclaration LocalVariableDeclarator() :
{
if (initializer == null) {
return new VariableDeclaration(currentSegment,
- varName.toCharArray(),
+ new Variable(varName.toCharArray(),SimpleCharStream.getPosition()-varName.length(),SimpleCharStream.getPosition()),
pos,
SimpleCharStream.getPosition());
}
return new VariableDeclaration(currentSegment,
- varName.toCharArray(),
+ new Variable(varName.toCharArray(),SimpleCharStream.getPosition()-varName.length(),SimpleCharStream.getPosition()),
initializer,
+ VariableDeclaration.EQUAL,
pos);
}
}
@@ -2188,23 +2336,24 @@ EmptyStatement EmptyStatement() :
return new EmptyStatement(pos-1,pos);}
}
-Statement StatementExpression() :
+/**
+ * used only by StatementExpressionList() which is used only by ForInit() and ForStatement()
+ */
+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()
- {return new BinaryExpression(expr,expr2,operator);}
]
{return expr;}
}
@@ -2262,7 +2411,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) {
@@ -2308,7 +2457,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) {
@@ -2333,7 +2482,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());
@@ -2409,8 +2558,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)
@@ -2445,18 +2594,18 @@ Expression Condition(final String keyword) :
{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;
}
{
@@ -2510,10 +2659,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());
}
}
@@ -2550,7 +2699,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();
@@ -2560,7 +2709,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());}
}
@@ -2575,22 +2724,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());}
}
@@ -2638,7 +2787,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) {
@@ -2749,9 +2898,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;
@@ -2802,7 +2951,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) {
@@ -2815,31 +2964,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() :