import org.eclipse.jface.preference.IPreferenceStore;
import java.util.Hashtable;
-import java.util.ArrayList;
import java.util.Enumeration;
import java.io.StringReader;
import java.io.*;
/** The file that is parsed. */
private static IFile fileToParse;
- /** The current segment */
+ /** The current segment. */
private static PHPSegmentWithChildren currentSegment;
private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
PHPOutlineInfo outlineInfo;
private static PHPFunctionDeclaration currentFunction;
+ private static boolean assigning;
/** The error level of the current ParseException. */
private static int errorLevel = ERROR;
private static int errorStart = -1;
private static int errorEnd = -1;
- public PHPParser() {
- }
-
public final void setFileToParse(final IFile fileToParse) {
this.fileToParse = fileToParse;
}
+ public PHPParser() {
+ }
+
public PHPParser(final IFile fileToParse) {
this(new StringReader(""));
this.fileToParse = fileToParse;
<ASSIGN>
try {
varValue = VariableInitializer()
- {return new PHPVarDeclaration(currentSegment,varName.substring(1),pos,varValue);}
+ {return new PHPVarDeclaration(currentSegment,varName,pos,varValue);}
} catch (ParseException e) {
errorMessage = "Literal expression expected in variable initializer";
errorLevel = ERROR;
{
token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
{
- if (expr == null) {
+ if (expr == null && !assigning) {
if (currentFunction != null) {
PHPVarDeclaration var = currentFunction.getParameter(token.image.substring(1));
if (var != null) {
var.getVariable().setUsed(true);
}
}
- return token.image;
+ return token.image.substring(1);
}
return token + "{" + expr + "}";
}
|
<DOLLAR> expr = VariableName()
- {return "$" + expr;}
+ {return expr;}
}
String VariableName():
[token = <BIT_AND>] variableDeclaration = VariableDeclarator()
{
if (token != null) {
- variableDeclaration.getVariable().setPrefix("@");
+ variableDeclaration.getVariable().setReference(true);
}
return variableDeclaration;
}
expr = ListExpression()
{return expr;}
|
+ LOOKAHEAD(varAssignation())
+ expr = varAssignation()
+ {return expr;}
+|
expr = ConditionalExpression()
- [
- assignOperator = AssignmentOperator()
+ {return expr;}
+}
+
+/**
+ * A Variable assignation.
+ * varName (an assign operator) any expression
+ */
+String varAssignation() :
+{
+ String varName,assignOperator,expr2;
+ PHPVarDeclaration variable;
+ final int pos = SimpleCharStream.getPosition();
+}
+{
+ varName = VariableDeclaratorId()
+ assignOperator = AssignmentOperator()
try {
expr2 = Expression()
- {return expr + assignOperator + expr2;}
} catch (ParseException e) {
if (errorMessage != null) {
throw e;
errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
- ]
- {return expr;}
+ {return varName + assignOperator + expr2;}
}
String AssignmentOperator() :