3 CHOICE_AMBIGUITY_CHECK = 2;
4 OTHER_AMBIGUITY_CHECK = 1;
7 DEBUG_LOOKAHEAD = false;
8 DEBUG_TOKEN_MANAGER = false;
9 OPTIMIZE_TOKEN_MANAGER = false;
10 ERROR_REPORTING = true;
11 JAVA_UNICODE_ESCAPE = false;
12 UNICODE_INPUT = false;
14 USER_TOKEN_MANAGER = false;
15 USER_CHAR_STREAM = false;
17 BUILD_TOKEN_MANAGER = true;
19 FORCE_LA_CHECK = false;
22 PARSER_BEGIN(PHPParser)
25 import org.eclipse.core.resources.IFile;
26 import org.eclipse.core.resources.IMarker;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.ui.texteditor.MarkerUtilities;
29 import org.eclipse.jface.preference.IPreferenceStore;
31 import java.util.Hashtable;
32 import java.io.StringReader;
33 import java.text.MessageFormat;
35 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
36 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
37 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
38 import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren;
39 import net.sourceforge.phpdt.internal.compiler.parser.PHPFunctionDeclaration;
40 import net.sourceforge.phpdt.internal.compiler.parser.PHPClassDeclaration;
41 import net.sourceforge.phpdt.internal.compiler.parser.PHPVarDeclaration;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPReqIncDeclaration;
46 * This php parser is inspired by the Java 1.2 grammar example
47 * given with JavaCC. You can get JavaCC at http://www.webgain.com
48 * You can test the parser with the PHPParserTestCase2.java
49 * @author Matthieu Casanova
51 public final class PHPParser extends PHPParserSuperclass {
53 private static IFile fileToParse;
55 /** The current segment */
56 private static PHPSegmentWithChildren currentSegment;
58 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
59 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
60 PHPOutlineInfo outlineInfo;
61 private static int errorLevel = ERROR;
62 private static String errorMessage;
67 public final void setFileToParse(final IFile fileToParse) {
68 this.fileToParse = fileToParse;
71 public PHPParser(final IFile fileToParse) {
72 this(new StringReader(""));
73 this.fileToParse = fileToParse;
76 public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
77 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
78 final StringReader stream = new StringReader(strEval);
79 if (jj_input_stream == null) {
80 jj_input_stream = new SimpleCharStream(stream, 1, 1);
82 ReInit(new StringReader(strEval));
86 public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
87 final StringReader stream = new StringReader(strEval);
88 if (jj_input_stream == null) {
89 jj_input_stream = new SimpleCharStream(stream, 1, 1);
95 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
96 outlineInfo = new PHPOutlineInfo(parent);
97 currentSegment = outlineInfo.getDeclarations();
98 final StringReader stream = new StringReader(s);
99 if (jj_input_stream == null) {
100 jj_input_stream = new SimpleCharStream(stream, 1, 1);
105 } catch (ParseException e) {
106 processParseException(e);
112 * This method will process the parse exception.
113 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
114 * @param e the ParseException
116 private static void processParseException(final ParseException e) {
117 if (errorMessage == null) {
118 PHPeclipsePlugin.log(e);
119 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
126 * Create marker for the parse error
127 * @param e the ParseException
129 private static void setMarker(final ParseException e) {
131 setMarker(fileToParse,
133 jj_input_stream.tokenBegin,
134 jj_input_stream.tokenBegin + e.currentToken.image.length(),
136 "Line " + e.currentToken.beginLine);
137 } catch (CoreException e2) {
138 PHPeclipsePlugin.log(e2);
143 * Create markers according to the external parser output
145 private static void createMarkers(final String output, final IFile file) throws CoreException {
146 // delete all markers
147 file.deleteMarkers(IMarker.PROBLEM, false, 0);
152 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
153 // newer php error output (tested with 4.2.3)
154 scanLine(output, file, indx, brIndx);
159 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
160 // older php error output (tested with 4.2.3)
161 scanLine(output, file, indx, brIndx);
167 private static void scanLine(final String output,
170 final int brIndx) throws CoreException {
172 StringBuffer lineNumberBuffer = new StringBuffer(10);
174 current = output.substring(indx, brIndx);
176 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
177 int onLine = current.indexOf("on line <b>");
179 lineNumberBuffer.delete(0, lineNumberBuffer.length());
180 for (int i = onLine; i < current.length(); i++) {
181 ch = current.charAt(i);
182 if ('0' <= ch && '9' >= ch) {
183 lineNumberBuffer.append(ch);
187 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
189 Hashtable attributes = new Hashtable();
191 current = current.replaceAll("\n", "");
192 current = current.replaceAll("<b>", "");
193 current = current.replaceAll("</b>", "");
194 MarkerUtilities.setMessage(attributes, current);
196 if (current.indexOf(PARSE_ERROR_STRING) != -1)
197 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
198 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
199 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
201 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
202 MarkerUtilities.setLineNumber(attributes, lineNumber);
203 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
208 public final void parse(final String s) throws CoreException {
209 final StringReader stream = new StringReader(s);
210 if (jj_input_stream == null) {
211 jj_input_stream = new SimpleCharStream(stream, 1, 1);
216 } catch (ParseException e) {
217 processParseException(e);
222 * Call the php parse command ( php -l -f <filename> )
223 * and create markers according to the external parser output
225 public static void phpExternalParse(final IFile file) {
226 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
227 final String filename = file.getLocation().toString();
229 final String[] arguments = { filename };
230 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
231 final String command = form.format(arguments);
233 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
236 // parse the buffer to find the errors and warnings
237 createMarkers(parserResult, file);
238 } catch (CoreException e) {
239 PHPeclipsePlugin.log(e);
243 public static final void parse() throws ParseException {
248 PARSER_END(PHPParser)
252 <PHPSTARTSHORT : "<?"> : PHPPARSING
253 | <PHPSTARTLONG : "<?php"> : PHPPARSING
254 | <PHPECHOSTART : "<?="> : PHPPARSING
259 <PHPEND :"?>"> : DEFAULT
281 <PHPPARSING> SPECIAL_TOKEN :
283 "//" : IN_SINGLE_LINE_COMMENT
285 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
287 "/*" : IN_MULTI_LINE_COMMENT
290 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
292 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
295 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
297 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
303 <FORMAL_COMMENT: "*/" > : PHPPARSING
306 <IN_MULTI_LINE_COMMENT>
309 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
312 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
322 | <FUNCTION : "function">
325 | <ELSEIF : "elseif">
331 /* LANGUAGE CONSTRUCT */
336 | <INCLUDE : "include">
337 | <REQUIRE : "require">
338 | <INCLUDE_ONCE : "include_once">
339 | <REQUIRE_ONCE : "require_once">
340 | <GLOBAL : "global">
341 | <STATIC : "static">
342 | <CLASSACCESS : "->">
343 | <STATICCLASSACCESS : "::">
344 | <ARRAYASSIGN : "=>">
351 /* RESERVED WORDS AND LITERALS */
357 | <CONTINUE : "continue">
358 | <_DEFAULT : "default">
360 | <EXTENDS : "extends">
365 | <RETURN : "return">
367 | <SWITCH : "switch">
372 | <ENDWHILE : "endwhile">
374 | <ENDFOR : "endfor">
375 | <FOREACH : "foreach">
384 | <OBJECT : "object">
386 | <BOOLEAN : "boolean">
388 | <DOUBLE : "double">
391 | <INTEGER : "integer">
405 <DECIMAL_LITERAL> (["l","L"])?
406 | <HEX_LITERAL> (["l","L"])?
407 | <OCTAL_LITERAL> (["l","L"])?
410 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
412 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
414 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
416 < FLOATING_POINT_LITERAL:
417 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
418 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
419 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
420 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
423 < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
425 < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
460 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
463 ["a"-"z"] | ["A"-"Z"]
471 "_" | ["\u007f"-"\u00ff"]
501 | <BANGDOUBLEEQUAL : "!==">
502 | <TRIPLEEQUAL : "===">
509 | <PLUSASSIGN : "+=">
510 | <MINUSASSIGN : "-=">
511 | <STARASSIGN : "*=">
512 | <SLASHASSIGN : "/=">
518 | <TILDEEQUAL : "~=">
542 | <RSIGNEDSHIFT : ">>">
543 | <RUNSIGNEDSHIFT : ">>>">
544 | <LSHIFTASSIGN : "<<=">
545 | <RSIGNEDSHIFTASSIGN : ">>=">
550 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
566 } catch (TokenMgrError e) {
567 errorMessage = e.getMessage();
569 throw generateParseException();
575 final int start = jj_input_stream.bufpos;
578 <PHPECHOSTART> Expression() [ <SEMICOLON> ] <PHPEND>
583 setMarker(fileToParse,
584 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
586 jj_input_stream.bufpos,
588 "Line " + token.beginLine);
589 } catch (CoreException e) {
590 PHPeclipsePlugin.log(e);
596 } catch (ParseException e) {
597 errorMessage = "'?>' expected";
609 void ClassDeclaration() :
611 final PHPClassDeclaration classDeclaration;
612 final Token className;
613 final int pos = jj_input_stream.bufpos;
616 <CLASS> className = <IDENTIFIER> [ <EXTENDS> <IDENTIFIER> ]
618 if (currentSegment != null) {
619 classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
620 currentSegment.add(classDeclaration);
621 currentSegment = classDeclaration;
626 if (currentSegment != null) {
627 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
637 } catch (ParseException e) {
638 errorMessage = "'{' expected";
642 ( ClassBodyDeclaration() )*
645 } catch (ParseException e) {
646 errorMessage = "'var', 'function' or '}' expected";
652 void ClassBodyDeclaration() :
660 void FieldDeclaration() :
662 PHPVarDeclaration variableDeclaration;
665 <VAR> variableDeclaration = VariableDeclarator()
667 if (currentSegment != null) {
668 currentSegment.add(variableDeclaration);
672 variableDeclaration = VariableDeclarator()
674 if (currentSegment != null) {
675 currentSegment.add(variableDeclaration);
681 } catch (ParseException e) {
682 errorMessage = "';' expected after variable declaration";
688 PHPVarDeclaration VariableDeclarator() :
690 final String varName;
692 final int pos = jj_input_stream.bufpos;
695 varName = VariableDeclaratorId()
699 varValue = VariableInitializer()
700 {return new PHPVarDeclaration(currentSegment,varName,pos,varValue);}
701 } catch (ParseException e) {
702 errorMessage = "Literal expression expected in variable initializer";
707 {return new PHPVarDeclaration(currentSegment,varName,pos);}
710 String VariableDeclaratorId() :
713 final StringBuffer buff = new StringBuffer();
719 ( LOOKAHEAD(2) expr = VariableSuffix()
722 {return buff.toString();}
723 } catch (ParseException e) {
724 errorMessage = "'$' expected for variable identifier";
736 token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
741 return token + "{" + expr + "}";
744 <DOLLAR> expr = VariableName()
748 String VariableName():
754 <LBRACE> expr = Expression() <RBRACE>
755 {return "{"+expr+"}";}
757 token = <IDENTIFIER> [<LBRACE> expr = Expression() <RBRACE>]
762 return token + "{" + expr + "}";
765 <DOLLAR> expr = VariableName()
768 token = <DOLLAR_ID> [expr = VariableName()]
773 return token.image + expr;
777 String VariableInitializer() :
786 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
787 {return "-" + token.image;}
789 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
790 {return "+" + token.image;}
792 expr = ArrayDeclarator()
796 {return token.image;}
799 String ArrayVariable() :
802 final StringBuffer buff = new StringBuffer();
807 [<ARRAYASSIGN> expr = Expression()
808 {buff.append("=>").append(expr);}]
809 {return buff.toString();}
812 String ArrayInitializer() :
815 final StringBuffer buff = new StringBuffer("(");
818 <LPAREN> [ expr = ArrayVariable()
820 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
821 {buff.append(",").append(expr);}
826 return buff.toString();
830 void MethodDeclaration() :
832 final PHPFunctionDeclaration functionDeclaration;
835 <FUNCTION> functionDeclaration = MethodDeclarator()
837 if (currentSegment != null) {
838 currentSegment.add(functionDeclaration);
839 currentSegment = functionDeclaration;
844 if (currentSegment != null) {
845 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
850 PHPFunctionDeclaration MethodDeclarator() :
852 final Token identifier;
853 final StringBuffer methodDeclaration = new StringBuffer();
854 final String formalParameters;
855 final int pos = jj_input_stream.bufpos;
858 [ <BIT_AND> {methodDeclaration.append("&");} ]
859 identifier = <IDENTIFIER>
860 {methodDeclaration.append(identifier);}
861 formalParameters = FormalParameters()
863 methodDeclaration.append(formalParameters);
864 return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);
868 String FormalParameters() :
871 final StringBuffer buff = new StringBuffer("(");
876 } catch (ParseException e) {
877 errorMessage = "Formal parameter expected after function identifier";
879 jj_consume_token(token.kind);
881 [ expr = FormalParameter()
884 <COMMA> expr = FormalParameter()
885 {buff.append(",").append(expr);}
890 } catch (ParseException e) {
891 errorMessage = "')' expected";
897 return buff.toString();
901 String FormalParameter() :
903 final PHPVarDeclaration variableDeclaration;
904 final StringBuffer buff = new StringBuffer();
907 [<BIT_AND> {buff.append("&");}] variableDeclaration = VariableDeclarator()
909 buff.append(variableDeclaration.toString());
910 return buff.toString();
945 String Expression() :
948 final String assignOperator;
952 expr = PrintExpression()
955 expr = ListExpression()
958 expr = ConditionalExpression()
960 assignOperator = AssignmentOperator()
963 {return expr + assignOperator + expr2;}
964 } catch (ParseException e) {
965 errorMessage = "expression expected";
973 String AssignmentOperator() :
990 | <RSIGNEDSHIFTASSIGN>
1004 String ConditionalExpression() :
1007 String expr2 = null;
1008 String expr3 = null;
1011 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1013 if (expr3 == null) {
1016 return expr + "?" + expr2 + ":" + expr3;
1021 String ConditionalOrExpression() :
1025 final StringBuffer buff = new StringBuffer();
1028 expr = ConditionalAndExpression()
1029 {buff.append(expr);}
1031 (operator = <SC_OR> | operator = <_ORL>) expr = ConditionalAndExpression()
1033 buff.append(operator.image);
1038 return buff.toString();
1042 String ConditionalAndExpression() :
1046 final StringBuffer buff = new StringBuffer();
1049 expr = ConcatExpression()
1050 {buff.append(expr);}
1052 (operator = <SC_AND> | operator = <_ANDL>) expr = ConcatExpression()
1054 buff.append(operator.image);
1058 {return buff.toString();}
1061 String ConcatExpression() :
1064 final StringBuffer buff = new StringBuffer();
1067 expr = InclusiveOrExpression()
1068 {buff.append(expr);}
1070 <DOT> expr = InclusiveOrExpression()
1071 {buff.append(".").append(expr);}
1073 {return buff.toString();}
1076 String InclusiveOrExpression() :
1079 final StringBuffer buff = new StringBuffer();
1082 expr = ExclusiveOrExpression()
1083 {buff.append(expr);}
1085 <BIT_OR> expr = ExclusiveOrExpression()
1086 {buff.append("|").append(expr);}
1088 {return buff.toString();}
1091 String ExclusiveOrExpression() :
1094 final StringBuffer buff = new StringBuffer();
1097 expr = AndExpression()
1102 <XOR> expr = AndExpression()
1109 return buff.toString();
1113 String AndExpression() :
1116 final StringBuffer buff = new StringBuffer();
1119 expr = EqualityExpression()
1124 <BIT_AND> expr = EqualityExpression()
1126 buff.append("&").append(expr);
1129 {return buff.toString();}
1132 String EqualityExpression() :
1136 final StringBuffer buff = new StringBuffer();
1139 expr = RelationalExpression()
1140 {buff.append(expr);}
1145 | operator = <BANGDOUBLEEQUAL>
1146 | operator = <TRIPLEEQUAL>
1148 expr = RelationalExpression()
1150 buff.append(operator.image);
1154 {return buff.toString();}
1157 String RelationalExpression() :
1161 final StringBuffer buff = new StringBuffer();
1164 expr = ShiftExpression()
1165 {buff.append(expr);}
1167 ( operator = <LT> | operator = <GT> | operator = <LE> | operator = <GE> ) expr = ShiftExpression()
1168 {buff.append(operator.image).append(expr);}
1170 {return buff.toString();}
1173 String ShiftExpression() :
1177 final StringBuffer buff = new StringBuffer();
1180 expr = AdditiveExpression()
1181 {buff.append(expr);}
1183 (operator = <LSHIFT> | operator = <RSIGNEDSHIFT> | operator = <RUNSIGNEDSHIFT> ) expr = AdditiveExpression()
1185 buff.append(operator.image);
1189 {return buff.toString();}
1192 String AdditiveExpression() :
1196 final StringBuffer buff = new StringBuffer();
1199 expr = MultiplicativeExpression()
1200 {buff.append(expr);}
1202 ( operator = <PLUS> | operator = <MINUS> ) expr = MultiplicativeExpression()
1204 buff.append(operator.image);
1208 {return buff.toString();}
1211 String MultiplicativeExpression() :
1215 final StringBuffer buff = new StringBuffer();}
1217 expr = UnaryExpression()
1218 {buff.append(expr);}
1220 ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr = UnaryExpression()
1222 buff.append(operator.image);
1226 {return buff.toString();}
1230 * An unary expression starting with @, & or nothing
1232 String UnaryExpression() :
1236 final StringBuffer buff = new StringBuffer();
1239 token = <BIT_AND> expr = UnaryExpressionNoPrefix()
1241 if (token == null) {
1244 return token.image + expr;
1247 (<AT> {buff.append("@");})* expr = UnaryExpressionNoPrefix()
1248 {return buff.append(expr).toString();}
1251 String UnaryExpressionNoPrefix() :
1257 ( token = <PLUS> | token = <MINUS> ) expr = UnaryExpression()
1259 return token.image + expr;
1262 expr = PreIncrementExpression()
1265 expr = PreDecrementExpression()
1268 expr = UnaryExpressionNotPlusMinus()
1273 String PreIncrementExpression() :
1278 <INCR> expr = PrimaryExpression()
1282 String PreDecrementExpression() :
1287 <DECR> expr = PrimaryExpression()
1291 String UnaryExpressionNotPlusMinus() :
1296 <BANG> expr = UnaryExpression()
1297 {return "!" + expr;}
1299 LOOKAHEAD( <LPAREN> Type() <RPAREN> )
1300 expr = CastExpression()
1303 expr = PostfixExpression()
1309 <LPAREN> expr = Expression()
1312 } catch (ParseException e) {
1313 errorMessage = "')' expected";
1317 {return "("+expr+")";}
1320 String CastExpression() :
1322 final String type, expr;
1325 <LPAREN> type = Type() <RPAREN> expr = UnaryExpression()
1326 {return "(" + type + ")" + expr;}
1329 String PostfixExpression() :
1332 Token operator = null;
1335 expr = PrimaryExpression() [ operator = <INCR> | operator = <DECR> ]
1337 if (operator == null) {
1340 return expr + operator.image;
1344 String PrimaryExpression() :
1346 final Token identifier;
1348 final StringBuffer buff = new StringBuffer();
1352 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1353 {buff.append(identifier.image).append("::").append(expr);}
1355 expr = PrimarySuffix()
1356 {buff.append(expr);}
1358 {return buff.toString();}
1360 expr = PrimaryPrefix() {buff.append(expr);}
1361 ( expr = PrimarySuffix() {buff.append(expr);} )*
1362 {return buff.toString();}
1364 expr = ArrayDeclarator()
1365 {return "array" + expr;}
1368 String ArrayDeclarator() :
1373 <ARRAY> expr = ArrayInitializer()
1374 {return "array" + expr;}
1377 String PrimaryPrefix() :
1383 token = <IDENTIFIER>
1384 {return token.image;}
1386 <NEW> expr = ClassIdentifier()
1388 return "new " + expr;
1391 expr = VariableDeclaratorId()
1395 String ClassIdentifier():
1401 token = <IDENTIFIER>
1402 {return token.image;}
1404 expr = VariableDeclaratorId()
1408 String PrimarySuffix() :
1416 expr = VariableSuffix()
1420 String VariableSuffix() :
1427 expr = VariableName()
1428 } catch (ParseException e) {
1429 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1433 {return "->" + expr;}
1435 <LBRACKET> [ expr = Expression() ]
1438 } catch (ParseException e) {
1439 errorMessage = "']' expected";
1447 return "[" + expr + "]";
1457 token = <INTEGER_LITERAL>
1458 {return token.image;}
1460 token = <FLOATING_POINT_LITERAL>
1461 {return token.image;}
1463 token = <STRING_LITERAL>
1464 {return token.image;}
1466 expr = BooleanLiteral()
1469 expr = NullLiteral()
1473 String BooleanLiteral() :
1483 String NullLiteral() :
1490 String Arguments() :
1495 <LPAREN> [ expr = ArgumentList() ]
1498 } catch (ParseException e) {
1499 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1507 return "(" + expr + ")";
1511 String ArgumentList() :
1514 final StringBuffer buff = new StringBuffer();
1518 {buff.append(expr);}
1522 } catch (ParseException e) {
1523 errorMessage = "expression expected after a comma in argument list";
1528 buff.append(",").append(expr);
1531 {return buff.toString();}
1535 * A Statement without break
1537 void StatementNoBreak() :
1543 (<SEMICOLON> | <PHPEND>)
1544 } catch (ParseException e) {
1545 errorMessage = "';' expected";
1557 StatementExpression()
1560 } catch (ParseException e) {
1561 errorMessage = "';' expected after expression";
1584 [<AT>] IncludeStatement()
1592 * A Normal statement
1602 void IncludeStatement() :
1605 final int pos = jj_input_stream.bufpos;
1611 if (currentSegment != null) {
1612 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr));
1616 (<SEMICOLON> | "?>")
1617 } catch (ParseException e) {
1618 errorMessage = "';' expected";
1626 if (currentSegment != null) {
1627 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr));
1631 (<SEMICOLON> | "?>")
1632 } catch (ParseException e) {
1633 errorMessage = "';' expected";
1641 if (currentSegment != null) {
1642 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr));
1646 (<SEMICOLON> | "?>")
1647 } catch (ParseException e) {
1648 errorMessage = "';' expected";
1656 if (currentSegment != null) {
1657 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr));
1661 (<SEMICOLON> | "?>")
1662 } catch (ParseException e) {
1663 errorMessage = "';' expected";
1669 String PrintExpression() :
1671 final StringBuffer buff = new StringBuffer("print ");
1675 <PRINT> expr = Expression()
1678 return buff.toString();
1682 String ListExpression() :
1684 final StringBuffer buff = new StringBuffer("list(");
1691 } catch (ParseException e) {
1692 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1697 expr = VariableDeclaratorId()
1698 {buff.append(expr);}
1703 } catch (ParseException e) {
1704 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1708 expr = VariableDeclaratorId()
1709 {buff.append(",").append(expr);}
1714 } catch (ParseException e) {
1715 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1719 [ <ASSIGN> expr = Expression() {buff.append("(").append(expr);}]
1720 {return buff.toString();}
1723 void EchoStatement() :
1726 <ECHO> Expression() (<COMMA> Expression())*
1728 (<SEMICOLON> | "?>")
1729 } catch (ParseException e) {
1730 errorMessage = "';' expected after 'echo' statement";
1736 void GlobalStatement() :
1739 <GLOBAL> VariableDeclaratorId() (<COMMA> VariableDeclaratorId())*
1741 (<SEMICOLON> | "?>")
1742 } catch (ParseException e) {
1743 errorMessage = "';' expected";
1749 void StaticStatement() :
1752 <STATIC> VariableDeclarator() (<COMMA> VariableDeclarator())*
1754 (<SEMICOLON> | "?>")
1755 } catch (ParseException e) {
1756 errorMessage = "';' expected";
1762 void LabeledStatement() :
1765 <IDENTIFIER> <COLON> Statement()
1773 } catch (ParseException e) {
1774 errorMessage = "'{' expected";
1778 ( BlockStatement() )*
1781 } catch (ParseException e) {
1782 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
1788 void BlockStatement() :
1799 * A Block statement that will not contain any 'break'
1801 void BlockStatementNoBreak() :
1811 void LocalVariableDeclaration() :
1814 LocalVariableDeclarator() ( <COMMA> LocalVariableDeclarator() )*
1817 void LocalVariableDeclarator() :
1820 VariableDeclaratorId() [ <ASSIGN> Expression() ]
1823 void EmptyStatement() :
1829 void StatementExpression() :
1832 PreIncrementExpression()
1834 PreDecrementExpression()
1842 AssignmentOperator() Expression()
1846 void SwitchStatement() :
1848 Token breakToken = null;
1855 } catch (ParseException e) {
1856 errorMessage = "'(' expected after 'switch'";
1863 } catch (ParseException e) {
1864 errorMessage = "')' expected";
1870 } catch (ParseException e) {
1871 errorMessage = "'{' expected";
1876 line = SwitchLabel()
1877 ( BlockStatementNoBreak() )*
1878 [ breakToken = <BREAK>
1881 } catch (ParseException e) {
1882 errorMessage = "';' expected after 'break' keyword";
1889 if (breakToken == null) {
1890 setMarker(fileToParse,
1891 "You should use put a 'break' at the end of your statement",
1896 } catch (CoreException e) {
1897 PHPeclipsePlugin.log(e);
1903 } catch (ParseException e) {
1904 errorMessage = "'}' expected";
1918 } catch (ParseException e) {
1919 if (errorMessage != null) throw e;
1920 errorMessage = "expression expected after 'case' keyword";
1926 } catch (ParseException e) {
1927 errorMessage = "':' expected after case expression";
1931 {return token.beginLine;}
1936 } catch (ParseException e) {
1937 errorMessage = "':' expected after 'default' keyword";
1941 {return token.beginLine;}
1944 void IfStatement() :
1947 final int pos = jj_input_stream.bufpos;
1950 token = <IF> Condition("if") IfStatement0(pos,pos+token.image.length())
1953 void Condition(final String keyword) :
1958 } catch (ParseException e) {
1959 errorMessage = "'(' expected after " + keyword + " keyword";
1966 } catch (ParseException e) {
1967 errorMessage = "')' expected after " + keyword + " keyword";
1973 void IfStatement0(final int start,final int end) :
1976 <COLON> (Statement())* (ElseIfStatementColon())* [ElseStatementColon()]
1979 setMarker(fileToParse,
1980 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
1984 "Line " + token.beginLine);
1985 } catch (CoreException e) {
1986 PHPeclipsePlugin.log(e);
1990 } catch (ParseException e) {
1991 errorMessage = "'endif' expected";
1997 } catch (ParseException e) {
1998 errorMessage = "';' expected after 'endif' keyword";
2003 Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) <ELSE> Statement() ]
2006 void ElseIfStatementColon() :
2009 <ELSEIF> Condition("elseif") <COLON> (Statement())*
2012 void ElseStatementColon() :
2015 <ELSE> <COLON> (Statement())*
2018 void ElseIfStatement() :
2021 <ELSEIF> Condition("elseif") Statement()
2024 void WhileStatement() :
2027 final int pos = jj_input_stream.bufpos;
2030 token = <WHILE> Condition("while") WhileStatement0(pos,pos + token.image.length())
2033 void WhileStatement0(final int start, final int end) :
2036 <COLON> (Statement())*
2038 setMarker(fileToParse,
2039 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2043 "Line " + token.beginLine);
2044 } catch (CoreException e) {
2045 PHPeclipsePlugin.log(e);
2049 } catch (ParseException e) {
2050 errorMessage = "'endwhile' expected";
2055 (<SEMICOLON> | "?>")
2056 } catch (ParseException e) {
2057 errorMessage = "';' expected after 'endwhile' keyword";
2065 void DoStatement() :
2068 <DO> Statement() <WHILE> Condition("while")
2070 (<SEMICOLON> | "?>")
2071 } catch (ParseException e) {
2072 errorMessage = "';' expected";
2078 void ForeachStatement() :
2084 } catch (ParseException e) {
2085 errorMessage = "'(' expected after 'foreach' keyword";
2091 } catch (ParseException e) {
2092 errorMessage = "variable expected";
2096 [ VariableSuffix() ]
2099 } catch (ParseException e) {
2100 errorMessage = "'as' expected";
2106 } catch (ParseException e) {
2107 errorMessage = "variable expected";
2111 [ <ARRAYASSIGN> Expression() ]
2114 } catch (ParseException e) {
2115 errorMessage = "')' expected after 'foreach' keyword";
2121 } catch (ParseException e) {
2122 if (errorMessage != null) throw e;
2123 errorMessage = "statement expected";
2129 void ForStatement() :
2132 final int pos = jj_input_stream.bufpos;
2138 } catch (ParseException e) {
2139 errorMessage = "'(' expected after 'for' keyword";
2143 [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ StatementExpressionList() ] <RPAREN>
2147 <COLON> (Statement())*
2150 setMarker(fileToParse,
2151 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2153 pos+token.image.length(),
2155 "Line " + token.beginLine);
2156 } catch (CoreException e) {
2157 PHPeclipsePlugin.log(e);
2162 } catch (ParseException e) {
2163 errorMessage = "'endfor' expected";
2169 } catch (ParseException e) {
2170 errorMessage = "';' expected after 'endfor' keyword";
2180 LOOKAHEAD(LocalVariableDeclaration())
2181 LocalVariableDeclaration()
2183 StatementExpressionList()
2186 void StatementExpressionList() :
2189 StatementExpression() ( <COMMA> StatementExpression() )*
2192 void BreakStatement() :
2195 <BREAK> [ <IDENTIFIER> ]
2198 } catch (ParseException e) {
2199 errorMessage = "';' expected after 'break' statement";
2205 void ContinueStatement() :
2208 <CONTINUE> [ <IDENTIFIER> ]
2211 } catch (ParseException e) {
2212 errorMessage = "';' expected after 'continue' statement";
2218 void ReturnStatement() :
2221 <RETURN> [ Expression() ]
2224 } catch (ParseException e) {
2225 errorMessage = "';' expected after 'return' statement";