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.
private static void processParseException(final ParseException e) {
if (PARSER_DEBUG) {
e.printStackTrace();
- return;
+ Assert.assertTrue(false);
}
if (errorMessage == null) {
PHPeclipsePlugin.log(e);
}
}
- 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);
{
<VAR> variableDeclaration = VariableDeclaratorNoSuffix()
{arrayList.add(variableDeclaration);
- outlineInfo.addVariable(new String(variableDeclaration.name));}
+ outlineInfo.addVariable(new String(variableDeclaration.name()));}
(
<COMMA> variableDeclaration = VariableDeclaratorNoSuffix()
{arrayList.add(variableDeclaration);
- outlineInfo.addVariable(new String(variableDeclaration.name));}
+ outlineInfo.addVariable(new String(variableDeclaration.name()));}
)*
try {
<SEMICOLON>
/**
* a strict variable declarator : there cannot be a suffix here.
+ * It will be used by fields and formal parameters
*/
VariableDeclaration VariableDeclaratorNoSuffix() :
{
{
if (initializer == null) {
return new VariableDeclaration(currentSegment,
- varName.image.substring(1).toCharArray(),
+ new Variable(varName.image.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
pos,
SimpleCharStream.getPosition());
}
return new VariableDeclaration(currentSegment,
- varName.image.substring(1).toCharArray(),
+ 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;
{
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,
- VariableDeclaration.EQUAL,
- pos);
+ new Variable(varName.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.length()-1,SimpleCharStream.getPosition()),
+ initializer,
+ VariableDeclaration.EQUAL,
+ pos);
}
}
}
[
var = FormalParameter()
- {parameters.put(new String(var.name),var);}
+ {parameters.put(new String(var.name()),var);}
(
<COMMA> var = FormalParameter()
- {parameters.put(new String(var.name),var);}
+ {parameters.put(new String(var.name()),var);}
)*
]
try {
final Expression expr;
Expression initializer = null;
final int pos = SimpleCharStream.getPosition();
-}
-{
- expr = ConditionalExpression() {return expr;}
-| expr = ExpressionWBang() {return expr;}
-}
-
-Expression ExpressionWBang() :
-{
- final Expression expr;
- final int pos = SimpleCharStream.getPosition();
-}
-{
- <BANG> expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
-| expr = ExpressionNoBang() {return expr;}
-}
-
-Expression ExpressionNoBang() :
-{
- Expression expr = null;
int assignOperator = -1;
- String var;
- final int pos = SimpleCharStream.getPosition();
}
{
- expr = PrintExpression() {return expr;}
-| expr = ListExpression() {return expr;}
-|
- var = VariableDeclaratorId()
+ LOOKAHEAD(1)
+ expr = ConditionalExpression()
[
assignOperator = AssignmentOperator()
try {
- expr = Expression()
+ initializer = Expression()
} catch (ParseException e) {
if (errorMessage != null) {
throw e;
}
]
{
+ char[] varName = expr.toStringExpression().substring(1).toCharArray();
if (assignOperator == -1) {
- return new VariableDeclaration(currentSegment,
- var.toCharArray(),
- pos,
- SimpleCharStream.getPosition());
+ return new VariableDeclaration(currentSegment,
+ new Variable(varName,SimpleCharStream.getPosition()-varName.length-1,SimpleCharStream.getPosition()),
+ pos,
+ SimpleCharStream.getPosition());
+ return expr;
}
return new VariableDeclaration(currentSegment,
- var.toCharArray(),
- expr,
+ 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();
+}
+{
+ <BANG> 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;}
}
/**
<BIT_AND> 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() :
{
final Expression expr;
final int pos = SimpleCharStream.getPosition();
}
{
<AT>
- expr = AtUnaryExpression()
+ expr = AtNotUnaryExpression()
{return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
|
+ <BANG>
+ expr = AtNotUnaryExpression()
+ {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
+|
expr = UnaryExpressionNoPrefix()
{return expr;}
}
|
expr = UnaryExpressionNotPlusMinus()
{return expr;}
+/*|
+ LOOKAHEAD(2)
+ expr = PrintExpression() {return expr;}*/
}
final int pos = SimpleCharStream.getPosition();
}
{
- identifier = <IDENTIFIER>
- {expr = new ConstantIdentifier(token.image.toCharArray(),
- pos,
- SimpleCharStream.getPosition());}
+ expr = PrimaryPrefix()
(expr = PrimarySuffix(expr))*
+ [ expr = Arguments(expr) ]
{return expr;}
|
- expr = ArrayDeclarator()
+ <NEW> expr = ClassIdentifier()
+ {expr = new PrefixedUnaryExpression(expr,
+ OperatorIds.NEW,
+ pos);
+ }
+ [ expr = Arguments(expr) ]
{return expr;}
|
- <NEW> expr = ClassIdentifier()
- {expr = new PrefixedUnaryExpression(expr,OperatorIds.NEW,pos);}
- [expr = Arguments(expr)]
+ expr = ArrayDeclarator()
{return expr;}
}
+Expression PrimaryPrefix() :
+{
+ final Expression expr;
+ final Token token;
+ final String var;
+ final int pos = SimpleCharStream.getPosition();
+}
+{
+ token = <IDENTIFIER> {return new ConstantIdentifier(token.image.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 = Arguments(prefix) {return suffix;}
-| suffix = VariableSuffix(prefix) {return suffix;}
+ suffix = VariableSuffix(prefix) {return suffix;}
| <STATICCLASSACCESS> expr = ClassIdentifier()
{suffix = new ClassAccess(prefix,
expr,
/**
* A Statement without break.
+ * @return a statement
*/
Statement StatementNoBreak() :
{
}
{
LOOKAHEAD(2)
- statement = Expression()
- try {
- <SEMICOLON>
- } catch (ParseException e) {
- if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
- errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
- errorLevel = ERROR;
- errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
- }
- }
- {return statement;}
+ statement = expressionStatement() {return statement;}
| LOOKAHEAD(1)
- statement = LabeledStatement() {return statement;}
-| statement = Block() {return statement;}
-| statement = EmptyStatement() {return statement;}
-/*| statement = StatementExpression()
- try {
- <SEMICOLON>
- } catch (ParseException e) {
- errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
- errorLevel = ERROR;
- errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
- errorEnd = SimpleCharStream.getPosition() + 1;
- throw e;
- }
- {return statement;} */
+ 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 = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
}
+/**
+ * A statement expression.
+ * expression ;
+ * @return an expression
+ */
+Statement expressionStatement() :
+{
+ final Statement statement;
+}
+{
+ statement = Expression()
+ try {
+ <SEMICOLON>
+ } catch (ParseException e) {
+ if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
+ errorLevel = ERROR;
+ errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = SimpleCharStream.getPosition() + 1;
+ throw e;
+ }
+ }
+ {return statement;}
+}
+
Define defineStatement() :
{
final int start = SimpleCharStream.getPosition();
VariableDeclaration expr;
}
{
- <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
- (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
+ <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name()));}
+ (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name()));})*
try {
<SEMICOLON>
{
return statement;}
}
+/**
+ * used only by ForInit()
+ */
VariableDeclaration[] LocalVariableDeclaration() :
{
final ArrayList list = new ArrayList();
return vars;}
}
+/**
+ * used only by LocalVariableDeclaration().
+ */
VariableDeclaration LocalVariableDeclarator() :
{
final String varName;
{
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);
return new EmptyStatement(pos-1,pos);}
}
+/**
+ * used only by StatementExpressionList() which is used only by ForInit() and ForStatement()
+ */
Expression StatementExpression() :
{
final Expression expr,expr2;