import org.eclipse.jface.preference.IPreferenceStore;
import java.util.Hashtable;
+import java.util.Enumeration;
import java.io.StringReader;
+import java.io.*;
import java.text.MessageFormat;
import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
-import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
-import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren;
-import net.sourceforge.phpdt.internal.compiler.parser.PHPFunctionDeclaration;
-import net.sourceforge.phpdt.internal.compiler.parser.PHPClassDeclaration;
-import net.sourceforge.phpdt.internal.compiler.parser.PHPVarDeclaration;
-import net.sourceforge.phpdt.internal.compiler.parser.PHPReqIncDeclaration;
+import net.sourceforge.phpdt.internal.compiler.parser.*;
+import net.sourceforge.phpdt.internal.compiler.ast.*;
/**
* A new php parser.
- * This php parser is inspired by the Java 1.2 grammar example
+ * This php parser is inspired by the Java 1.2 grammar example
* given with JavaCC. You can get JavaCC at http://www.webgain.com
* You can test the parser with the PHPParserTestCase2.java
* @author Matthieu Casanova
*/
public final class PHPParser extends PHPParserSuperclass {
+ /** 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$
private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
- PHPOutlineInfo outlineInfo;
+ static PHPOutlineInfo outlineInfo;
+
+ private static PHPFunctionDeclaration currentFunction;
+ 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 */
private static String errorMessage;
- public PHPParser() {
- }
+ private static int errorStart = -1;
+ private static int errorEnd = -1;
+
+ //ast stack
+ private final static int AstStackIncrement = 100;
+ /** The stack of node. */
+ private static AstNode[] astStack;
+ /** The cursor in expression stack. */
+ private static int expressionPtr;
public final void setFileToParse(final IFile fileToParse) {
this.fileToParse = fileToParse;
}
+ public PHPParser() {
+ }
+
public PHPParser(final IFile fileToParse) {
this(new StringReader(""));
this.fileToParse = fileToParse;
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
ReInit(new StringReader(strEval));
+ astStack = new AstNode[AstStackIncrement];
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);
+ astStack = new AstNode[AstStackIncrement];
+ 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);
+ astStack = new AstNode[AstStackIncrement];
phpFile();
}
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
ReInit(stream);
+ astStack = new AstNode[AstStackIncrement];
try {
parse();
} catch (ParseException e) {
if (errorMessage == null) {
PHPeclipsePlugin.log(e);
errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
+ errorStart = jj_input_stream.getPosition();
+ errorEnd = errorStart + 1;
}
setMarker(e);
errorMessage = null;
*/
private static void setMarker(final ParseException e) {
try {
- setMarker(fileToParse,
- errorMessage,
- jj_input_stream.tokenBegin,
- jj_input_stream.tokenBegin + e.currentToken.image.length(),
- errorLevel,
- "Line " + e.currentToken.beginLine);
+ if (errorStart == -1) {
+ setMarker(fileToParse,
+ errorMessage,
+ jj_input_stream.tokenBegin,
+ jj_input_stream.tokenBegin + e.currentToken.image.length(),
+ errorLevel,
+ "Line " + e.currentToken.beginLine);
+ } else {
+ setMarker(fileToParse,
+ errorMessage,
+ errorStart,
+ errorEnd,
+ errorLevel,
+ "Line " + e.currentToken.beginLine);
+ errorStart = -1;
+ errorEnd = -1;
+ }
} catch (CoreException e2) {
PHPeclipsePlugin.log(e2);
}
jj_input_stream = new SimpleCharStream(stream, 1, 1);
}
ReInit(stream);
+ astStack = new AstNode[AstStackIncrement];
try {
parse();
} catch (ParseException e) {
}
}
- public static final void parse() throws ParseException {
+ private static final void parse() throws ParseException {
phpFile();
}
}
<DEFAULT> TOKEN :
{
- <PHPSTARTSHORT : "<?"> : PHPPARSING
+ <PHPSTARTSHORT : "<?"> : PHPPARSING
| <PHPSTARTLONG : "<?php"> : PHPPARSING
-| <PHPECHOSTART : "<?="> : PHPPARSING
+| <PHPECHOSTART : "<?="> : PHPPARSING
}
<PHPPARSING> TOKEN :
<PHPEND :"?>"> : DEFAULT
}
+/* Skip any character if we are not in php mode */
<DEFAULT> SKIP :
{
< ~[] >
/* WHITE SPACE */
-
<PHPPARSING> SKIP :
{
" "
}
/* COMMENTS */
-
<PHPPARSING> SPECIAL_TOKEN :
{
"//" : IN_SINGLE_LINE_COMMENT
|
+ "#" : IN_SINGLE_LINE_COMMENT
+|
<"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
|
"/*" : IN_MULTI_LINE_COMMENT
| <ELSE : "else">
| <ARRAY : "array">
| <BREAK : "break">
+| <LIST : "list">
}
/* LANGUAGE CONSTRUCT */
| <ARRAYASSIGN : "=>">
}
-<PHPPARSING> TOKEN :
-{
- <LIST : "list">
-}
/* RESERVED WORDS AND LITERALS */
<PHPPARSING> TOKEN :
| <FALSE : "false">
| <WHILE : "while">
| <ENDWHILE : "endwhile">
+| <ENDSWITCH: "endswitch">
| <ENDIF : "endif">
| <ENDFOR : "endfor">
| <FOREACH : "foreach">
}
/* TYPES */
-
<PHPPARSING> TOKEN :
{
<STRING : "string">
}
/* LITERALS */
-
<PHPPARSING> TOKEN :
{
< INTEGER_LITERAL:
| < STRING_1:
"\""
(
- ~["\""]
- |
- "\\\""
+ ~["\"","{","}"]
+ | "\\\""
+ | "\\"
+ | "{" ~["\""] "}"
)*
"\""
>
| < STRING_2:
"'"
(
- ~["'"]
- |
- "\\'"
+ ~["'"]
+ | "\\'"
)*
"'"
"`"
(
~["`"]
- |
- "\\`"
+ | "\\`"
)*
"`"
>
<AT : "@">
| <DOLLAR : "$">
| <BANG : "!">
+| <TILDE : "~">
| <HOOK : "?">
| <COLON : ":">
| <SC_OR : "||">
(PhpBlock())*
<EOF>
} catch (TokenMgrError e) {
+ PHPeclipsePlugin.log(e);
+ errorStart = SimpleCharStream.getPosition();
+ errorEnd = errorStart + 1;
errorMessage = e.getMessage();
errorLevel = ERROR;
throw generateParseException();
}
}
+/**
+ * A php block is a <?= expression [;]?>
+ * or <?php somephpcode ?>
+ * or <? somephpcode ?>
+ */
void PhpBlock() :
{
- final int start = jj_input_stream.bufpos;
+ final int start = jj_input_stream.getPosition();
}
{
- <PHPECHOSTART> Expression() [ <SEMICOLON> ] <PHPEND>
+ phpEchoBlock()
|
[ <PHPSTARTLONG>
| <PHPSTARTSHORT>
setMarker(fileToParse,
"You should use '<?php' instead of '<?' it will avoid some problems with XML",
start,
- jj_input_stream.bufpos,
+ jj_input_stream.getPosition(),
INFO,
"Line " + token.beginLine);
} catch (CoreException e) {
} catch (ParseException e) {
errorMessage = "'?>' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
+void phpEchoBlock() :
+{}
+{
+ <PHPECHOSTART> Expression() [ <SEMICOLON> ] <PHPEND>
+}
+
void Php() :
{}
{
{
final PHPClassDeclaration classDeclaration;
final Token className;
- final int pos = jj_input_stream.bufpos;
+ final int pos;
}
{
- <CLASS> className = <IDENTIFIER> [ <EXTENDS> <IDENTIFIER> ]
+ <CLASS>
+ try {
+ {pos = jj_input_stream.getPosition();}
+ className = <IDENTIFIER>
+ } catch (ParseException e) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
+ [
+ <EXTENDS>
+ try {
+ <IDENTIFIER>
+ } catch (ParseException e) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
+ ]
{
if (currentSegment != null) {
classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
try {
<LBRACE>
} catch (ParseException e) {
- errorMessage = "'{' expected";
+ 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;
throw e;
}
( ClassBodyDeclaration() )*
try {
<RBRACE>
} catch (ParseException e) {
- errorMessage = "'var', 'function' or '}' expected";
+ 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;
throw e;
}
}
+/**
+ * A class can contain only methods and fields.
+ */
void ClassBodyDeclaration() :
{}
{
MethodDeclaration()
-|
- FieldDeclaration()
+| FieldDeclaration()
}
+/**
+ * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
+ */
void FieldDeclaration() :
{
PHPVarDeclaration variableDeclaration;
{
<VAR> variableDeclaration = VariableDeclarator()
{
+ outlineInfo.addVariable(variableDeclaration.getVariable().getName());
if (currentSegment != null) {
currentSegment.add(variableDeclaration);
}
try {
<SEMICOLON>
} catch (ParseException e) {
- errorMessage = "';' expected after variable declaration";
+ 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;
throw e;
}
}
PHPVarDeclaration VariableDeclarator() :
{
- final String varName;
- String varValue;
- final int pos = jj_input_stream.bufpos;
+ final String varName, varValue;
+ final int pos = jj_input_stream.getPosition();
}
{
varName = VariableDeclaratorId()
} 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;
}
]
}
{
try {
- expr = Variable()
- {buff.append(expr);}
- ( LOOKAHEAD(2) expr = VariableSuffix()
- {buff.append(expr);}
+ expr = Variable() {buff.append(expr);}
+ ( LOOKAHEAD(2)
+ expr = VariableSuffix() {buff.append(expr);}
)*
{return buff.toString();}
} catch (ParseException e) {
errorMessage = "'$' expected for variable identifier";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
{
token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
{
- if (expr == null) {
- return token.image;
+ 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.substring(1);
}
return token + "{" + expr + "}";
}
|
<DOLLAR> expr = VariableName()
- {return "$" + expr;}
+ {return expr;}
}
String VariableName():
token = <IDENTIFIER> [<LBRACE> expr = Expression() <RBRACE>]
{
if (expr == null) {
+ if (currentFunction != null) {
+ PHPVarDeclaration var = currentFunction.getParameter(token.image);
+ if (var != null) {
+ var.getVariable().setUsed(true);
+ }
+ }
return token.image;
}
return token + "{" + expr + "}";
}
|
<DOLLAR> expr = VariableName()
- {return "$" + expr;}
+ {
+ if (currentFunction != null) {
+ PHPVarDeclaration var = currentFunction.getParameter(expr);
+ if (var != null) {
+ var.getVariable().setUsed(true);
+ }
+ }
+ return "$" + expr;
+ }
|
+ token = <DOLLAR_ID>
+ {
+ if (currentFunction != null) {
+ PHPVarDeclaration var = currentFunction.getParameter(token.image.substring(1));
+ if (var != null) {
+ var.getVariable().setUsed(true);
+ }
+ }
+ return token.image + expr;
+ }
+/*| pas besoin ?
token = <DOLLAR_ID> [expr = VariableName()]
{
if (expr == null) {
return token.image;
}
return token.image + expr;
- }
+ }*/
}
String VariableInitializer() :
{buff.append(expr);}
( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
{buff.append(",").append(expr);}
- )* ]
+ )*
+ ]
+ [<COMMA> {buff.append(",");}]
<RPAREN>
{
buff.append(")");
}
}
+/**
+ * A Method Declaration.
+ * <b>function</b> MetodDeclarator() Block()
+ */
void MethodDeclaration() :
{
final PHPFunctionDeclaration functionDeclaration;
+ Token functionToken;
}
{
- <FUNCTION> functionDeclaration = MethodDeclarator()
+ functionToken = <FUNCTION>
+ try {
+ functionDeclaration = MethodDeclarator()
+ {outlineInfo.addVariable(functionDeclaration.getName());}
+ } catch (ParseException e) {
+ if (errorMessage != null) {
+ throw e;
+ }
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
{
if (currentSegment != null) {
currentSegment.add(functionDeclaration);
currentSegment = functionDeclaration;
}
+ currentFunction = functionDeclaration;
}
Block()
{
+ Hashtable parameters = currentFunction.getParameters();
+ Enumeration vars = parameters.elements();
+ while (vars.hasMoreElements()) {
+ PHPVarDeclaration o = (PHPVarDeclaration) vars.nextElement();
+ if (!o.getVariable().isUsed()) {
+ try {
+ setMarker(fileToParse,
+ "Parameter "+o.getVariable().getName()+" is never used in function",
+ functionToken.beginLine,
+ WARNING,
+ "Line " + token.beginLine);
+ } catch (CoreException e) {
+ PHPeclipsePlugin.log(e);
+ }
+ }
+ }
+ currentFunction = null;
if (currentSegment != null) {
currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
}
}
}
+/**
+ * A MethodDeclarator.
+ * [&] IDENTIFIER(parameters ...).
+ * @return a function description for the outline
+ */
PHPFunctionDeclaration MethodDeclarator() :
{
final Token identifier;
final StringBuffer methodDeclaration = new StringBuffer();
- final String formalParameters;
- final int pos = jj_input_stream.bufpos;
+ final Hashtable formalParameters;
+ final int pos = jj_input_stream.getPosition();
}
{
[ <BIT_AND> {methodDeclaration.append("&");} ]
identifier = <IDENTIFIER>
- {methodDeclaration.append(identifier);}
- formalParameters = FormalParameters()
+ formalParameters = FormalParameters()
{
- methodDeclaration.append(formalParameters);
- return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);
+ methodDeclaration.append(identifier);
+ return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos,formalParameters);
}
}
-String FormalParameters() :
+/**
+ * FormalParameters follows method identifier.
+ * (FormalParameter())
+ */
+Hashtable FormalParameters() :
{
String expr;
final StringBuffer buff = new StringBuffer("(");
+ PHPVarDeclaration var;
+ final Hashtable parameters = new Hashtable();
}
{
try {
<LPAREN>
} catch (ParseException e) {
- errorMessage = "Formal parameter expected after function identifier";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
errorLevel = ERROR;
- jj_consume_token(token.kind);
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
}
- [ expr = FormalParameter()
- {buff.append(expr);}
- (
- <COMMA> expr = FormalParameter()
- {buff.append(",").append(expr);}
- )*
+ [ var = FormalParameter()
+ {parameters.put(var.getVariable().getName(),var);}
+ (
+ <COMMA> var = FormalParameter()
+ {parameters.put(var.getVariable().getName(),var);}
+ )*
]
try {
<RPAREN>
} catch (ParseException e) {
errorMessage = "')' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
- {
- buff.append(")");
- return buff.toString();
- }
+ {return parameters;}
}
-String FormalParameter() :
+/**
+ * A formal parameter.
+ * $varname[=value] (,$varname[=value])
+ */
+PHPVarDeclaration FormalParameter() :
{
final PHPVarDeclaration variableDeclaration;
- final StringBuffer buff = new StringBuffer();
+ Token token = null;
}
{
- [<BIT_AND> {buff.append("&");}] variableDeclaration = VariableDeclarator()
+ [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
{
- buff.append(variableDeclaration.toString());
- return buff.toString();
+ if (token != null) {
+ variableDeclaration.getVariable().setReference(true);
+ }
+ return variableDeclaration;
}
}
String Type() :
{}
{
- <STRING>
- {return "string";}
-|
- <BOOL>
- {return "bool";}
-|
- <BOOLEAN>
- {return "boolean";}
-|
- <REAL>
- {return "real";}
-|
- <DOUBLE>
- {return "double";}
-|
- <FLOAT>
- {return "float";}
-|
- <INT>
- {return "int";}
-|
- <INTEGER>
- {return "integer";}
-|
- <OBJECT>
- {return "object";}
+ <STRING> {return "string";}
+| <BOOL> {return "bool";}
+| <BOOLEAN> {return "boolean";}
+| <REAL> {return "real";}
+| <DOUBLE> {return "double";}
+| <FLOAT> {return "float";}
+| <INT> {return "int";}
+| <INTEGER> {return "integer";}
+| <OBJECT> {return "object";}
}
String Expression() :
final String expr2;
}
{
- expr = PrintExpression()
- {return expr;}
-|
- expr = ListExpression()
- {return expr;}
-|
- expr = ConditionalExpression()
- [
- assignOperator = AssignmentOperator()
+ 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
+ */
+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;
+ }
errorMessage = "expression expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
- ]
- {return expr;}
+ {return varName + assignOperator + expr2;}
}
String AssignmentOperator() :
{}
{
- <ASSIGN>
-{return "=";}
-| <STARASSIGN>
-{return "*=";}
-| <SLASHASSIGN>
-{return "/=";}
-| <REMASSIGN>
-{return "%=";}
-| <PLUSASSIGN>
-{return "+=";}
-| <MINUSASSIGN>
-{return "-=";}
-| <LSHIFTASSIGN>
-{return "<<=";}
-| <RSIGNEDSHIFTASSIGN>
-{return ">>=";}
-| <ANDASSIGN>
-{return "&=";}
-| <XORASSIGN>
-{return "|=";}
-| <ORASSIGN>
-{return "|=";}
-| <DOTASSIGN>
-{return ".=";}
-| <TILDEEQUAL>
-{return "~=";}
+ <ASSIGN> {return "=";}
+| <STARASSIGN> {return "*=";}
+| <SLASHASSIGN> {return "/=";}
+| <REMASSIGN> {return "%=";}
+| <PLUSASSIGN> {return "+=";}
+| <MINUSASSIGN> {return "-=";}
+| <LSHIFTASSIGN> {return "<<=";}
+| <RSIGNEDSHIFTASSIGN> {return ">>=";}
+| <ANDASSIGN> {return "&=";}
+| <XORASSIGN> {return "|=";}
+| <ORASSIGN> {return "|=";}
+| <DOTASSIGN> {return ".=";}
+| <TILDEEQUAL> {return "~=";}
}
String ConditionalExpression() :
| operator = <BANGDOUBLEEQUAL>
| operator = <TRIPLEEQUAL>
)
- expr = RelationalExpression()
+ try {
+ expr = RelationalExpression()
+ } catch (ParseException e) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected after '"+operator.image+"'";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
{
buff.append(operator.image);
buff.append(expr);
Token operator;
final StringBuffer buff = new StringBuffer();}
{
- expr = UnaryExpression()
+ try {
+ expr = UnaryExpression()
+ } catch (ParseException e) {
+ errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
{buff.append(expr);}
(
- ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr = UnaryExpression()
- {
- buff.append(operator.image);
- buff.append(expr);
- }
+ ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr = UnaryExpression()
+ {
+ buff.append(operator.image);
+ buff.append(expr);
+ }
)*
{return buff.toString();}
}
}
return token.image + expr;
}
-|
- (<AT> {buff.append("@");})* expr = UnaryExpressionNoPrefix()
+| (<AT> {buff.append("@");})*
+ expr = UnaryExpressionNoPrefix()
{return buff.append(expr).toString();}
}
return token.image + expr;
}
|
- expr = PreIncrementExpression()
- {return expr;}
-|
- expr = PreDecrementExpression()
+ expr = PreIncDecExpression()
{return expr;}
|
expr = UnaryExpressionNotPlusMinus()
}
-String PreIncrementExpression() :
-{
-final String expr;
-}
-{
- <INCR> expr = PrimaryExpression()
- {return "++"+expr;}
-}
-
-String PreDecrementExpression() :
+String PreIncDecExpression() :
{
final String expr;
+final Token token;
}
{
- <DECR> expr = PrimaryExpression()
- {return "--"+expr;}
+ (token = <INCR> | token = <DECR>) expr = PrimaryExpression()
+ {return token.image + expr;}
}
String UnaryExpressionNotPlusMinus() :
final String expr;
}
{
- <BANG> expr = UnaryExpression()
- {return "!" + expr;}
-|
- LOOKAHEAD( <LPAREN> Type() <RPAREN> )
- expr = CastExpression()
- {return expr;}
-|
- expr = PostfixExpression()
- {return expr;}
-|
- expr = Literal()
- {return expr;}
-|
- <LPAREN> expr = Expression()
+ <BANG> expr = UnaryExpression() {return "!" + expr;}
+| LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
+ expr = CastExpression() {return expr;}
+| expr = PostfixExpression() {return expr;}
+| expr = Literal() {return expr;}
+| <LPAREN> expr = Expression()
try {
<RPAREN>
} catch (ParseException e) {
errorMessage = "')' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
{return "("+expr+")";}
final String type, expr;
}
{
- <LPAREN> type = Type() <RPAREN> expr = UnaryExpression()
+ <LPAREN> (type = Type() | <ARRAY> {type = "array";}) <RPAREN> expr = UnaryExpression()
{return "(" + type + ")" + expr;}
}
final Token token;
}
{
- token = <IDENTIFIER>
- {return token.image;}
-|
+ token = <IDENTIFIER> {return token.image;}
+| <NEW> expr = ClassIdentifier() {return "new " + expr;}
+| expr = VariableDeclaratorId() {return expr;}
+}
+
+String classInstantiation() :
+{
+ String expr;
+ final StringBuffer buff = new StringBuffer("new ");
+}
+{
<NEW> expr = ClassIdentifier()
- {
- return "new " + expr;
- }
-|
- expr = VariableDeclaratorId()
- {return expr;}
+ {buff.append(expr);}
+ [
+ expr = PrimaryExpression()
+ {buff.append(expr);}
+ ]
+ {return buff.toString();}
}
String ClassIdentifier():
final Token token;
}
{
- token = <IDENTIFIER>
- {return token.image;}
-|
- expr = VariableDeclaratorId()
- {return expr;}
+ token = <IDENTIFIER> {return token.image;}
+| expr = VariableDeclaratorId() {return expr;}
}
String PrimarySuffix() :
final String expr;
}
{
- expr = Arguments()
- {return expr;}
-|
- expr = VariableSuffix()
- {return expr;}
+ expr = Arguments() {return expr;}
+| expr = VariableSuffix() {return expr;}
}
String VariableSuffix() :
String expr = null;
}
{
- <CLASSACCESS> expr = VariableName()
+ <CLASSACCESS>
+ try {
+ expr = VariableName()
+ } catch (ParseException e) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
{return "->" + expr;}
-|
- <LBRACKET> [ expr = Expression() ]
+|
+ <LBRACKET> [ expr = Expression() | expr = Type() ] //Not good
try {
<RBRACKET>
} catch (ParseException e) {
errorMessage = "']' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
{
final Token token;
}
{
- token = <INTEGER_LITERAL>
- {return token.image;}
-|
- token = <FLOATING_POINT_LITERAL>
- {return token.image;}
-|
- token = <STRING_LITERAL>
- {return token.image;}
-|
- expr = BooleanLiteral()
- {return expr;}
-|
- expr = NullLiteral()
- {return expr;}
+ token = <INTEGER_LITERAL> {return token.image;}
+| token = <FLOATING_POINT_LITERAL> {return token.image;}
+| token = <STRING_LITERAL> {return token.image;}
+| expr = BooleanLiteral() {return expr;}
+| <NULL> {return "null";}
}
String BooleanLiteral() :
{}
{
- <TRUE>
- {return "true";}
-|
- <FALSE>
- {return "false";}
-}
-
-String NullLiteral() :
-{}
-{
- <NULL>
- {return "null";}
+ <TRUE> {return "true";}
+| <FALSE> {return "false";}
}
String Arguments() :
try {
<RPAREN>
} catch (ParseException e) {
- errorMessage = "')' expected to close the argument list";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
{
try {
expr = Expression()
} catch (ParseException e) {
- errorMessage = "expression expected after a comma in argument list";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
- {
- buff.append(",").append(expr);
- }
+ {buff.append(",").append(expr);}
)*
{return buff.toString();}
}
-/*
- * Statement syntax follows.
+/**
+ * A Statement without break.
*/
-
void StatementNoBreak() :
{}
{
LOOKAHEAD(2)
Expression()
try {
- (<SEMICOLON> | <PHPEND>)
+ <SEMICOLON>
} catch (ParseException e) {
- errorMessage = "';' expected";
- errorLevel = ERROR;
- throw e;
+ if (e.currentToken.next.kind != 4) {
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
}
-|
- LOOKAHEAD(2)
+| LOOKAHEAD(2)
LabeledStatement()
-|
- Block()
-|
- EmptyStatement()
-|
- StatementExpression()
+| Block()
+| EmptyStatement()
+| StatementExpression()
try {
<SEMICOLON>
} catch (ParseException e) {
- errorMessage = "';' expected after expression";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
-|
- SwitchStatement()
-|
- IfStatement()
-|
- WhileStatement()
-|
- DoStatement()
-|
- ForStatement()
-|
- ForeachStatement()
-|
- ContinueStatement()
-|
- ReturnStatement()
-|
- EchoStatement()
-|
- [<AT>] IncludeStatement()
-|
- StaticStatement()
-|
- GlobalStatement()
+| SwitchStatement()
+| IfStatement()
+| WhileStatement()
+| DoStatement()
+| ForStatement()
+| ForeachStatement()
+| ContinueStatement()
+| ReturnStatement()
+| EchoStatement()
+| [<AT>] IncludeStatement()
+| StaticStatement()
+| GlobalStatement()
}
+/**
+ * A Normal statement.
+ */
void Statement() :
{}
{
StatementNoBreak()
-|
- BreakStatement()
+| BreakStatement()
}
-void IncludeStatement() :
-{
- final String expr;
- final int pos = jj_input_stream.bufpos;
-}
+/**
+ * An html block inside a php syntax.
+ */
+void htmlBlock() :
+{}
{
- <REQUIRE>
- expr = Expression()
- {
- if (currentSegment != null) {
- currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr));
- }
- }
- try {
- (<SEMICOLON> | "?>")
- } catch (ParseException e) {
- errorMessage = "';' expected";
- errorLevel = ERROR;
- throw e;
- }
-|
- <REQUIRE_ONCE>
- expr = Expression()
- {
- if (currentSegment != null) {
- currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr));
- }
- }
+ <PHPEND> (phpEchoBlock())*
try {
- (<SEMICOLON> | "?>")
+ (<PHPSTARTLONG> | <PHPSTARTSHORT>)
} catch (ParseException e) {
- errorMessage = "';' expected";
+ errorMessage = "End of file unexpected, '<?php' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition();
+ errorEnd = jj_input_stream.getPosition();
throw e;
}
-|
- <INCLUDE>
- expr = Expression()
- {
- if (currentSegment != null) {
- currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr));
+}
+
+/**
+ * An include statement. It's "include" an expression;
+ */
+void IncludeStatement() :
+{
+ final String expr;
+ final Token token;
+ final int pos = jj_input_stream.getPosition();
+}
+{
+ ( token = <REQUIRE>
+ | token = <REQUIRE_ONCE>
+ | token = <INCLUDE>
+ | token = <INCLUDE_ONCE> )
+ try {
+ expr = Expression()
+ } catch (ParseException e) {
+ if (errorMessage != null) {
+ throw e;
+ }
+ errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
}
- }
- try {
- (<SEMICOLON> | "?>")
- } catch (ParseException e) {
- errorMessage = "';' expected";
- errorLevel = ERROR;
- throw e;
- }
-|
- <INCLUDE_ONCE>
- expr = Expression()
{
if (currentSegment != null) {
- currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr));
+ currentSegment.add(new PHPReqIncDeclaration(currentSegment, token.image,pos,expr));
}
}
try {
- (<SEMICOLON> | "?>")
+ <SEMICOLON>
} catch (ParseException e) {
- errorMessage = "';' expected";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
String PrintExpression() :
{
- final StringBuffer buff = new StringBuffer("print ");
final String expr;
}
{
- <PRINT> expr = Expression()
- {
- buff.append(expr);
- return buff.toString();
- }
+ <PRINT> expr = Expression() {return "print " + expr;}
}
String ListExpression() :
String expr;
}
{
- <LIST> <LPAREN>
+ <LIST>
+ try {
+ <LPAREN>
+ } 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;
+ throw e;
+ }
[
expr = VariableDeclaratorId()
{buff.append(expr);}
]
- <COMMA>
- {buff.append(",");}
- [
+ (
+ try {
+ <COMMA>
+ } 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;
+ throw e;
+ }
expr = VariableDeclaratorId()
- {buff.append(expr);}
- ]
+ {buff.append(",").append(expr);}
+ )*
{buff.append(")");}
- <RPAREN>
+ try {
+ <RPAREN>
+ } 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;
+ throw e;
+ }
[ <ASSIGN> expr = Expression() {buff.append("(").append(expr);}]
{return buff.toString();}
}
+/**
+ * An echo statement.
+ * echo anyexpression (, otherexpression)*
+ */
void EchoStatement() :
{}
{
<ECHO> Expression() (<COMMA> Expression())*
try {
- (<SEMICOLON> | "?>")
+ <SEMICOLON>
} catch (ParseException e) {
- errorMessage = "';' expected after 'echo' statement";
- errorLevel = ERROR;
- throw e;
+ if (e.currentToken.next.kind != 4) {
+ errorMessage = "';' expected after 'echo' statement";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
}
}
void GlobalStatement() :
-{}
{
- <GLOBAL> VariableDeclaratorId() (<COMMA> VariableDeclaratorId())*
+ final int pos = jj_input_stream.getPosition();
+ String expr;
+}
+{
+ <GLOBAL>
+ expr = VariableDeclaratorId()
+ {if (currentSegment != null) {
+ currentSegment.add(new PHPGlobalDeclaration(currentSegment, "global",pos,expr));
+ }}
+ (<COMMA>
+ expr = VariableDeclaratorId()
+ {if (currentSegment != null) {
+ currentSegment.add(new PHPGlobalDeclaration(currentSegment, "global",pos,expr));
+ }}
+ )*
try {
- (<SEMICOLON> | "?>")
+ <SEMICOLON>
} catch (ParseException e) {
- errorMessage = "';' expected";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
{
<STATIC> VariableDeclarator() (<COMMA> VariableDeclarator())*
try {
- (<SEMICOLON> | "?>")
+ <SEMICOLON>
} catch (ParseException e) {
- errorMessage = "';' expected";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
} catch (ParseException e) {
errorMessage = "'{' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
- ( BlockStatement() )*
+ ( BlockStatement() | htmlBlock())*
try {
<RBRACE>
} catch (ParseException e) {
- errorMessage = "unexpected token : "+ e.currentToken.image +", '}' expected";
+ errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
{}
{
Statement()
-|
- ClassDeclaration()
-|
- MethodDeclaration()
+| ClassDeclaration()
+| MethodDeclaration()
}
+/**
+ * A Block statement that will not contain any 'break'
+ */
void BlockStatementNoBreak() :
{}
{
StatementNoBreak()
-|
- ClassDeclaration()
-|
- MethodDeclaration()
+| ClassDeclaration()
+| MethodDeclaration()
}
void LocalVariableDeclaration() :
void StatementExpression() :
{}
{
- PreIncrementExpression()
-|
- PreDecrementExpression()
+ PreIncDecExpression()
|
PrimaryExpression()
- [
- <INCR>
- |
- <DECR>
- |
- AssignmentOperator() Expression()
- ]
+ [ <INCR>
+ | <DECR>
+ | AssignmentOperator() Expression() ]
}
void SwitchStatement() :
{
- Token breakToken = null;
- int line;
+ final int pos = jj_input_stream.getPosition();
}
{
<SWITCH>
} catch (ParseException e) {
errorMessage = "'(' expected after 'switch'";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
+ try {
+ Expression()
+ } catch (ParseException e) {
+ if (errorMessage != null) {
+ throw e;
+ }
+ errorMessage = "expression expected";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
- Expression()
try {
<RPAREN>
} catch (ParseException e) {
errorMessage = "')' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
- try {
+ (switchStatementBrace() | switchStatementColon(pos, pos + 6))
+}
+
+void switchStatementBrace() :
+{}
+{
<LBRACE>
+ ( switchLabel0() )*
+ try {
+ <RBRACE>
} catch (ParseException e) {
- errorMessage = "'{' expected";
+ errorMessage = "'}' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
- (
- line = SwitchLabel()
- ( BlockStatementNoBreak() )*
- [ breakToken = <BREAK>
- try {
- <SEMICOLON>
- } catch (ParseException e) {
- errorMessage = "';' expected after 'break' keyword";
- errorLevel = ERROR;
- throw e;
- }
- ]
- {
- try {
- if (breakToken == null) {
- setMarker(fileToParse,
- "You should use put a 'break' at the end of your statement",
- line,
- INFO,
- "Line " + line);
- }
- } catch (CoreException e) {
- PHPeclipsePlugin.log(e);
- }
+}
+/**
+ * A Switch statement with : ... endswitch;
+ * @param start the begin offset of the switch
+ * @param end the end offset of the switch
+ */
+void switchStatementColon(final int start, final int end) :
+{}
+{
+ <COLON>
+ {try {
+ setMarker(fileToParse,
+ "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
+ start,
+ end,
+ INFO,
+ "Line " + token.beginLine);
+ } catch (CoreException e) {
+ PHPeclipsePlugin.log(e);
+ }}
+ (switchLabel0())*
+ try {
+ <ENDSWITCH>
+ } catch (ParseException e) {
+ errorMessage = "'endswitch' expected";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
+ try {
+ <SEMICOLON>
+ } catch (ParseException e) {
+ errorMessage = "';' expected after 'endswitch' keyword";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
+}
+
+void switchLabel0() :
+{
+ Token breakToken = null;
+ final int line;
+}
+{
+ line = SwitchLabel()
+ ( BlockStatementNoBreak() | htmlBlock() )*
+ [ breakToken = BreakStatement() ]
+ {
+ try {
+ if (breakToken == null) {
+ setMarker(fileToParse,
+ "You should use put a 'break' at the end of your statement",
+ line,
+ INFO,
+ "Line " + line);
}
- )*
+ } catch (CoreException e) {
+ PHPeclipsePlugin.log(e);
+ }
+ }
+}
+
+Token BreakStatement() :
+{
+ final Token token;
+}
+{
+ token = <BREAK> [ Expression() ]
try {
- <RBRACE>
+ <SEMICOLON>
} catch (ParseException e) {
- errorMessage = "'}' expected";
+ errorMessage = "';' expected after 'break' keyword";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
+ {return token;}
}
int SwitchLabel() :
if (errorMessage != null) throw e;
errorMessage = "expression expected after 'case' keyword";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
try {
} catch (ParseException e) {
errorMessage = "':' expected after case expression";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
{return token.beginLine;}
} catch (ParseException e) {
errorMessage = "':' expected after 'default' keyword";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
{return token.beginLine;}
void IfStatement() :
{
final Token token;
- final int pos = jj_input_stream.bufpos;
+ final int pos = jj_input_stream.getPosition();
}
{
token = <IF> Condition("if") IfStatement0(pos,pos+token.image.length())
} catch (ParseException e) {
errorMessage = "'(' expected after " + keyword + " keyword";
errorLevel = ERROR;
- throw e;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length();
+ errorEnd = errorStart +1;
+ processParseException(e);
}
Expression()
try {
} catch (ParseException e) {
errorMessage = "')' expected after " + keyword + " keyword";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
void IfStatement0(final int start,final int end) :
{}
{
- <COLON> (Statement())* (ElseIfStatementColon())* [ElseStatementColon()]
+ <COLON> (Statement() | htmlBlock())* (ElseIfStatementColon())* [ElseStatementColon()]
{try {
setMarker(fileToParse,
} catch (ParseException e) {
errorMessage = "'endif' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
try {
} catch (ParseException e) {
errorMessage = "';' expected after 'endif' keyword";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
|
- Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) <ELSE> Statement() ]
+ (Statement() | htmlBlock())
+ ( LOOKAHEAD(1) ElseIfStatement() )*
+ [ LOOKAHEAD(1)
+ <ELSE>
+ try {
+ Statement()
+ } catch (ParseException e) {
+ if (errorMessage != null) {
+ throw e;
+ }
+ errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
+ errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
+ throw e;
+ }
+ ]
}
void ElseIfStatementColon() :
{}
{
- <ELSEIF> Condition("elseif") <COLON> (Statement())*
+ <ELSEIF> Condition("elseif") <COLON> (Statement() | htmlBlock())*
}
void ElseStatementColon() :
{}
{
- <ELSE> <COLON> (Statement())*
+ <ELSE> <COLON> (Statement() | htmlBlock())*
}
void ElseIfStatement() :
void WhileStatement() :
{
final Token token;
- final int pos = jj_input_stream.bufpos;
+ final int pos = jj_input_stream.getPosition();
}
{
token = <WHILE> Condition("while") WhileStatement0(pos,pos + token.image.length())
} catch (ParseException e) {
errorMessage = "'endwhile' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
try {
- (<SEMICOLON> | "?>")
+ <SEMICOLON>
} catch (ParseException e) {
errorMessage = "';' expected after 'endwhile' keyword";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
|
{
<DO> Statement() <WHILE> Condition("while")
try {
- (<SEMICOLON> | "?>")
+ <SEMICOLON>
} catch (ParseException e) {
- errorMessage = "';' expected";
+ errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
} catch (ParseException e) {
errorMessage = "'(' expected after 'foreach' keyword";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
try {
} catch (ParseException e) {
errorMessage = "variable expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
- [ VariableSuffix() ]
+ ( VariableSuffix() )*
try {
<AS>
} catch (ParseException e) {
errorMessage = "'as' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
try {
} catch (ParseException e) {
errorMessage = "variable expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
[ <ARRAYASSIGN> Expression() ]
} catch (ParseException e) {
errorMessage = "')' expected after 'foreach' keyword";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
try {
if (errorMessage != null) throw e;
errorMessage = "statement expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
void ForStatement() :
{
final Token token;
-final int pos = jj_input_stream.bufpos;
+final int pos = jj_input_stream.getPosition();
}
{
token = <FOR>
} catch (ParseException e) {
errorMessage = "'(' expected after 'for' keyword";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
[ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ StatementExpressionList() ] <RPAREN>
} catch (ParseException e) {
errorMessage = "'endfor' expected";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
try {
} catch (ParseException e) {
errorMessage = "';' expected after 'endfor' keyword";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
)
StatementExpression() ( <COMMA> StatementExpression() )*
}
-void BreakStatement() :
-{}
-{
- <BREAK> [ <IDENTIFIER> ]
- try {
- <SEMICOLON>
- } catch (ParseException e) {
- errorMessage = "';' expected after 'break' statement";
- errorLevel = ERROR;
- throw e;
- }
-}
-
void ContinueStatement() :
{}
{
- <CONTINUE> [ <IDENTIFIER> ]
+ <CONTINUE> [ Expression() ]
try {
<SEMICOLON>
} catch (ParseException e) {
errorMessage = "';' expected after 'continue' statement";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
} catch (ParseException e) {
errorMessage = "';' expected after 'return' statement";
errorLevel = ERROR;
+ errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
+ errorEnd = jj_input_stream.getPosition() + 1;
throw e;
}
}
\ No newline at end of file