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 : "=>">
347 /* RESERVED WORDS AND LITERALS */
353 | <CONTINUE : "continue">
354 | <_DEFAULT : "default">
356 | <EXTENDS : "extends">
361 | <RETURN : "return">
363 | <SWITCH : "switch">
368 | <ENDWHILE : "endwhile">
370 | <ENDFOR : "endfor">
371 | <FOREACH : "foreach">
380 | <OBJECT : "object">
382 | <BOOLEAN : "boolean">
384 | <DOUBLE : "double">
387 | <INTEGER : "integer">
401 <DECIMAL_LITERAL> (["l","L"])?
402 | <HEX_LITERAL> (["l","L"])?
403 | <OCTAL_LITERAL> (["l","L"])?
406 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
408 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
410 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
412 < FLOATING_POINT_LITERAL:
413 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
414 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
415 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
416 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
419 < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
421 < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
456 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
459 ["a"-"z"] | ["A"-"Z"]
467 "_" | ["\u007f"-"\u00ff"]
497 | <BANGDOUBLEEQUAL : "!==">
498 | <TRIPLEEQUAL : "===">
505 | <PLUSASSIGN : "+=">
506 | <MINUSASSIGN : "-=">
507 | <STARASSIGN : "*=">
508 | <SLASHASSIGN : "/=">
514 | <TILDEEQUAL : "~=">
538 | <RSIGNEDSHIFT : ">>">
539 | <RUNSIGNEDSHIFT : ">>>">
540 | <LSHIFTASSIGN : "<<=">
541 | <RSIGNEDSHIFTASSIGN : ">>=">
546 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
562 } catch (TokenMgrError e) {
563 errorMessage = e.getMessage();
565 throw generateParseException();
571 final int start = jj_input_stream.bufpos;
574 <PHPECHOSTART> Expression() [ <SEMICOLON> ] <PHPEND>
579 setMarker(fileToParse,
580 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
582 jj_input_stream.bufpos,
584 "Line " + token.beginLine);
585 } catch (CoreException e) {
586 PHPeclipsePlugin.log(e);
591 } catch (ParseException e) {
592 errorMessage = "'?>' expected";
604 void ClassDeclaration() :
606 final PHPClassDeclaration classDeclaration;
607 final Token className;
608 final int pos = jj_input_stream.bufpos;
611 <CLASS> className = <IDENTIFIER> [ <EXTENDS> <IDENTIFIER> ]
613 if (currentSegment != null) {
614 classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
615 currentSegment.add(classDeclaration);
616 currentSegment = classDeclaration;
621 if (currentSegment != null) {
622 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
632 } catch (ParseException e) {
633 errorMessage = "'{' expected";
637 ( ClassBodyDeclaration() )*
640 } catch (ParseException e) {
641 errorMessage = "'var', 'function' or '}' expected";
647 void ClassBodyDeclaration() :
655 void FieldDeclaration() :
657 PHPVarDeclaration variableDeclaration;
660 <VAR> variableDeclaration = VariableDeclarator()
662 if (currentSegment != null) {
663 currentSegment.add(variableDeclaration);
667 variableDeclaration = VariableDeclarator()
669 if (currentSegment != null) {
670 currentSegment.add(variableDeclaration);
676 } catch (ParseException e) {
677 errorMessage = "';' expected after variable declaration";
683 PHPVarDeclaration VariableDeclarator() :
685 final String varName;
686 String varValue = null;
687 final int pos = jj_input_stream.bufpos;
690 varName = VariableDeclaratorId()
694 varValue = VariableInitializer()
695 {return new PHPVarDeclaration(currentSegment,varName,pos,varValue);}
696 } catch (ParseException e) {
697 errorMessage = "Literal expression expected in variable initializer";
702 {return new PHPVarDeclaration(currentSegment,varName,pos);}
705 String VariableDeclaratorId() :
708 final StringBuffer buff = new StringBuffer();
714 ( LOOKAHEAD(2) expr = VariableSuffix()
717 {return buff.toString();}
718 } catch (ParseException e) {
719 errorMessage = "'$' expected for variable identifier";
731 token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
736 return token + "{" + expr + "}";
739 <DOLLAR> expr = VariableName()
743 String VariableName():
749 <LBRACE> expr = Expression() <RBRACE>
750 {return "{"+expr+"}";}
752 token = <IDENTIFIER> [<LBRACE> expr = Expression() <RBRACE>]
757 return token + "{" + expr + "}";
760 <DOLLAR> expr = VariableName()
763 token = <DOLLAR_ID> [expr = VariableName()]
768 return token.image + expr;
772 String VariableInitializer() :
781 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
782 {return "-" + token.image;}
784 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
785 {return "+" + token.image;}
787 expr = ArrayDeclarator()
791 {return token.image;}
794 String ArrayVariable() :
797 final StringBuffer buff = new StringBuffer();
802 [<ARRAYASSIGN> expr = Expression()
803 {buff.append("=>").append(expr);}]
804 {return buff.toString();}
807 String ArrayInitializer() :
810 final StringBuffer buff = new StringBuffer("(");
813 <LPAREN> [ expr = ArrayVariable()
815 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
816 {buff.append(",").append(expr);}
821 return buff.toString();
825 void MethodDeclaration() :
827 final PHPFunctionDeclaration functionDeclaration;
830 <FUNCTION> functionDeclaration = MethodDeclarator()
832 if (currentSegment != null) {
833 currentSegment.add(functionDeclaration);
834 currentSegment = functionDeclaration;
839 if (currentSegment != null) {
840 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
845 PHPFunctionDeclaration MethodDeclarator() :
847 final Token identifier;
848 final StringBuffer methodDeclaration = new StringBuffer();
849 final String formalParameters;
850 final int pos = jj_input_stream.bufpos;
853 [ <BIT_AND> {methodDeclaration.append("&");} ]
854 identifier = <IDENTIFIER>
855 {methodDeclaration.append(identifier);}
856 formalParameters = FormalParameters()
858 methodDeclaration.append(formalParameters);
859 return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);
863 String FormalParameters() :
866 final StringBuffer buff = new StringBuffer("(");
871 } catch (ParseException e) {
872 errorMessage = "Formal parameter expected after function identifier";
874 jj_consume_token(token.kind);
876 [ expr = FormalParameter()
879 <COMMA> expr = FormalParameter()
880 {buff.append(",").append(expr);}
885 } catch (ParseException e) {
886 errorMessage = "')' expected";
892 return buff.toString();
896 String FormalParameter() :
898 final PHPVarDeclaration variableDeclaration;
899 final StringBuffer buff = new StringBuffer();
902 [<BIT_AND> {buff.append("&");}] variableDeclaration = VariableDeclarator()
904 buff.append(variableDeclaration.toString());
905 return buff.toString();
940 String Expression() :
943 final String assignOperator;
947 expr = PrintExpression()
950 expr = ConditionalExpression()
952 assignOperator = AssignmentOperator()
955 {return expr + assignOperator + expr2;}
956 } catch (ParseException e) {
957 errorMessage = "expression expected";
965 String AssignmentOperator() :
982 | <RSIGNEDSHIFTASSIGN>
996 String ConditionalExpression() :
1000 String expr3 = null;
1003 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1005 if (expr3 == null) {
1008 return expr + "?" + expr2 + ":" + expr3;
1013 String ConditionalOrExpression() :
1017 final StringBuffer buff = new StringBuffer();
1020 expr = ConditionalAndExpression()
1021 {buff.append(expr);}
1023 (operator = <SC_OR> | operator = <_ORL>) expr = ConditionalAndExpression()
1025 buff.append(operator.image);
1030 return buff.toString();
1034 String ConditionalAndExpression() :
1038 final StringBuffer buff = new StringBuffer();
1041 expr = ConcatExpression()
1042 {buff.append(expr);}
1044 (operator = <SC_AND> | operator = <_ANDL>) expr = ConcatExpression()
1046 buff.append(operator.image);
1050 {return buff.toString();}
1053 String ConcatExpression() :
1056 final StringBuffer buff = new StringBuffer();
1059 expr = InclusiveOrExpression()
1060 {buff.append(expr);}
1062 <DOT> expr = InclusiveOrExpression()
1063 {buff.append(".").append(expr);}
1065 {return buff.toString();}
1068 String InclusiveOrExpression() :
1071 final StringBuffer buff = new StringBuffer();
1074 expr = ExclusiveOrExpression()
1075 {buff.append(expr);}
1077 <BIT_OR> expr = ExclusiveOrExpression()
1078 {buff.append("|").append(expr);}
1080 {return buff.toString();}
1083 String ExclusiveOrExpression() :
1086 final StringBuffer buff = new StringBuffer();
1089 expr = AndExpression()
1094 <XOR> expr = AndExpression()
1101 return buff.toString();
1105 String AndExpression() :
1108 final StringBuffer buff = new StringBuffer();
1111 expr = EqualityExpression()
1116 <BIT_AND> expr = EqualityExpression()
1118 buff.append("&").append(expr);
1121 {return buff.toString();}
1124 String EqualityExpression() :
1128 final StringBuffer buff = new StringBuffer();
1131 expr = RelationalExpression()
1132 {buff.append(expr);}
1137 | operator = <BANGDOUBLEEQUAL>
1138 | operator = <TRIPLEEQUAL>
1140 expr = RelationalExpression()
1142 buff.append(operator.image);
1146 {return buff.toString();}
1149 String RelationalExpression() :
1153 final StringBuffer buff = new StringBuffer();
1156 expr = ShiftExpression()
1157 {buff.append(expr);}
1159 ( operator = <LT> | operator = <GT> | operator = <LE> | operator = <GE> ) expr = ShiftExpression()
1160 {buff.append(operator.image).append(expr);}
1162 {return buff.toString();}
1165 String ShiftExpression() :
1169 final StringBuffer buff = new StringBuffer();
1172 expr = AdditiveExpression()
1173 {buff.append(expr);}
1175 (operator = <LSHIFT> | operator = <RSIGNEDSHIFT> | operator = <RUNSIGNEDSHIFT> ) expr = AdditiveExpression()
1177 buff.append(operator.image);
1181 {return buff.toString();}
1184 String AdditiveExpression() :
1188 final StringBuffer buff = new StringBuffer();
1191 expr = MultiplicativeExpression()
1192 {buff.append(expr);}
1194 ( operator = <PLUS> | operator = <MINUS> ) expr = MultiplicativeExpression()
1196 buff.append(operator.image);
1200 {return buff.toString();}
1203 String MultiplicativeExpression() :
1207 final StringBuffer buff = new StringBuffer();}
1209 expr = UnaryExpression()
1210 {buff.append(expr);}
1212 ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr = UnaryExpression()
1214 buff.append(operator.image);
1218 {return buff.toString();}
1222 * An unary expression starting with @, & or nothing
1224 String UnaryExpression() :
1228 final StringBuffer buff = new StringBuffer();
1231 token = <BIT_AND> expr = UnaryExpressionNoPrefix()
1233 if (token == null) {
1236 return token.image + expr;
1239 (<AT> {buff.append("@");})* expr = UnaryExpressionNoPrefix()
1240 {return buff.append(expr).toString();}
1243 String UnaryExpressionNoPrefix() :
1249 ( token = <PLUS> | token = <MINUS> ) expr = UnaryExpression()
1251 return token.image + expr;
1254 expr = PreIncrementExpression()
1257 expr = PreDecrementExpression()
1260 expr = UnaryExpressionNotPlusMinus()
1265 String PreIncrementExpression() :
1270 <INCR> expr = PrimaryExpression()
1274 String PreDecrementExpression() :
1279 <DECR> expr = PrimaryExpression()
1283 String UnaryExpressionNotPlusMinus() :
1288 <BANG> expr = UnaryExpression()
1289 {return "!" + expr;}
1291 LOOKAHEAD( <LPAREN> Type() <RPAREN> )
1292 expr = CastExpression()
1295 expr = PostfixExpression()
1301 <LPAREN> expr = Expression()<RPAREN>
1302 {return "("+expr+")";}
1305 String CastExpression() :
1307 final String type, expr;
1310 <LPAREN> type = Type() <RPAREN> expr = UnaryExpression()
1311 {return "(" + type + ")" + expr;}
1314 String PostfixExpression() :
1317 Token operator = null;
1320 expr = PrimaryExpression() [ operator = <INCR> | operator = <DECR> ]
1322 if (operator == null) {
1325 return expr + operator.image;
1329 String PrimaryExpression() :
1331 final Token identifier;
1333 final StringBuffer buff = new StringBuffer();
1337 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1338 {buff.append(identifier.image).append("::").append(expr);}
1340 expr = PrimarySuffix()
1341 {buff.append(expr);}
1343 {return buff.toString();}
1345 expr = PrimaryPrefix() {buff.append(expr);}
1346 ( expr = PrimarySuffix() {buff.append(expr);} )*
1347 {return buff.toString();}
1349 expr = ArrayDeclarator()
1350 {return "array" + expr;}
1353 String ArrayDeclarator() :
1358 <ARRAY> expr = ArrayInitializer()
1359 {return "array" + expr;}
1362 String PrimaryPrefix() :
1368 token = <IDENTIFIER>
1369 {return token.image;}
1371 <NEW> expr = ClassIdentifier()
1373 return "new " + expr;
1376 expr = VariableDeclaratorId()
1380 String ClassIdentifier():
1386 token = <IDENTIFIER>
1387 {return token.image;}
1389 expr = VariableDeclaratorId()
1393 String PrimarySuffix() :
1401 expr = VariableSuffix()
1405 String VariableSuffix() :
1410 <CLASSACCESS> expr = VariableName()
1411 {return "->" + expr;}
1413 <LBRACKET> [ expr = Expression() ]
1416 } catch (ParseException e) {
1417 errorMessage = "']' expected";
1425 return "[" + expr + "]";
1435 token = <INTEGER_LITERAL>
1436 {return token.image;}
1438 token = <FLOATING_POINT_LITERAL>
1439 {return token.image;}
1441 token = <STRING_LITERAL>
1442 {return token.image;}
1444 expr = BooleanLiteral()
1447 expr = NullLiteral()
1451 String BooleanLiteral() :
1461 String NullLiteral() :
1468 String Arguments() :
1473 <LPAREN> [ expr = ArgumentList() ]
1476 } catch (ParseException e) {
1477 errorMessage = "')' expected to close the argument list";
1485 return "(" + expr + ")";
1489 String ArgumentList() :
1492 final StringBuffer buff = new StringBuffer();
1496 {buff.append(expr);}
1500 } catch (ParseException e) {
1501 errorMessage = "expression expected after a comma in argument list";
1506 buff.append(",").append(expr);
1509 {return buff.toString();}
1513 * Statement syntax follows.
1522 (<SEMICOLON> | <PHPEND>)
1523 } catch (ParseException e) {
1524 errorMessage = "';' expected";
1536 StatementExpression()
1539 } catch (ParseException e) {
1540 errorMessage = "';' expected after expression";
1565 [<AT>] IncludeStatement()
1572 void IncludeStatement() :
1575 final int pos = jj_input_stream.bufpos;
1581 if (currentSegment != null) {
1582 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr));
1586 (<SEMICOLON> | "?>")
1587 } catch (ParseException e) {
1588 errorMessage = "';' expected";
1596 if (currentSegment != null) {
1597 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr));
1601 (<SEMICOLON> | "?>")
1602 } catch (ParseException e) {
1603 errorMessage = "';' expected";
1611 if (currentSegment != null) {
1612 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr));
1616 (<SEMICOLON> | "?>")
1617 } catch (ParseException e) {
1618 errorMessage = "';' expected";
1626 if (currentSegment != null) {
1627 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr));
1631 (<SEMICOLON> | "?>")
1632 } catch (ParseException e) {
1633 errorMessage = "';' expected";
1639 String PrintExpression() :
1641 final StringBuffer buff = new StringBuffer("print ");
1645 <PRINT> expr = Expression()
1648 return buff.toString();
1652 void EchoStatement() :
1655 <ECHO> Expression() (<COMMA> Expression())*
1657 (<SEMICOLON> | "?>")
1658 } catch (ParseException e) {
1659 errorMessage = "';' expected after 'echo' statement";
1665 void GlobalStatement() :
1668 <GLOBAL> VariableDeclaratorId() (<COMMA> VariableDeclaratorId())*
1670 (<SEMICOLON> | "?>")
1671 } catch (ParseException e) {
1672 errorMessage = "';' expected";
1678 void StaticStatement() :
1681 <STATIC> VariableDeclarator() (<COMMA> VariableDeclarator())*
1683 (<SEMICOLON> | "?>")
1684 } catch (ParseException e) {
1685 errorMessage = "';' expected";
1691 void LabeledStatement() :
1694 <IDENTIFIER> <COLON> Statement()
1702 } catch (ParseException e) {
1703 errorMessage = "'{' expected";
1707 ( BlockStatement() )*
1711 void BlockStatement() :
1721 void LocalVariableDeclaration() :
1724 LocalVariableDeclarator() ( <COMMA> LocalVariableDeclarator() )*
1727 void LocalVariableDeclarator() :
1730 VariableDeclaratorId() [ <ASSIGN> Expression() ]
1733 void EmptyStatement() :
1739 void StatementExpression() :
1742 PreIncrementExpression()
1744 PreDecrementExpression()
1752 AssignmentOperator() Expression()
1756 void SwitchStatement() :
1759 <SWITCH> <LPAREN> Expression() <RPAREN> <LBRACE>
1760 ( SwitchLabel() ( BlockStatement() )* )*
1764 void SwitchLabel() :
1767 <CASE> Expression() <COLON>
1772 void IfStatement() :
1775 final int pos = jj_input_stream.bufpos;
1778 token = <IF> Condition("if") IfStatement0(pos,pos+token.image.length())
1781 void Condition(final String keyword) :
1786 } catch (ParseException e) {
1787 errorMessage = "'(' expected after " + keyword + " keyword";
1794 } catch (ParseException e) {
1795 errorMessage = "')' expected after " + keyword + " keyword";
1801 void IfStatement0(final int start,final int end) :
1805 <COLON> (Statement())* (ElseIfStatementColon())* [ElseStatementColon()]
1808 setMarker(fileToParse,
1809 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
1813 "Line " + token.beginLine);
1814 } catch (CoreException e) {
1815 PHPeclipsePlugin.log(e);
1819 } catch (ParseException e) {
1820 errorMessage = "'endif' expected";
1826 } catch (ParseException e) {
1827 errorMessage = "';' expected 'endif' keyword";
1832 Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) <ELSE> Statement() ]
1835 void ElseIfStatementColon() :
1838 <ELSEIF> Condition("elseif") <COLON> (Statement())*
1841 void ElseStatementColon() :
1844 <ELSE> <COLON> (Statement())*
1847 void ElseIfStatement() :
1850 <ELSEIF> Condition("elseif") Statement()
1853 void WhileStatement() :
1856 final int pos = jj_input_stream.bufpos;
1859 token = <WHILE> Condition("while") WhileStatement0(pos,pos + token.image.length())
1862 void WhileStatement0(final int start, final int end) :
1865 <COLON> (Statement())*
1867 setMarker(fileToParse,
1868 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
1872 "Line " + token.beginLine);
1873 } catch (CoreException e) {
1874 PHPeclipsePlugin.log(e);
1878 } catch (ParseException e) {
1879 errorMessage = "'endwhile' expected";
1884 (<SEMICOLON> | "?>")
1885 } catch (ParseException e) {
1886 errorMessage = "';' expected after 'endwhile' keyword";
1894 void DoStatement() :
1897 <DO> Statement() <WHILE> Condition("while")
1899 (<SEMICOLON> | "?>")
1900 } catch (ParseException e) {
1901 errorMessage = "';' expected";
1907 void ForeachStatement() :
1913 } catch (ParseException e) {
1914 errorMessage = "'(' expected after 'foreach' keyword";
1920 } catch (ParseException e) {
1921 errorMessage = "variable expected";
1925 [ VariableSuffix() ]
1928 } catch (ParseException e) {
1929 errorMessage = "'as' expected";
1935 } catch (ParseException e) {
1936 errorMessage = "variable expected";
1940 [ <ARRAYASSIGN> Expression() ]
1943 } catch (ParseException e) {
1944 errorMessage = "')' expected after 'foreach' keyword";
1950 } catch (ParseException e) {
1951 if (errorMessage != null) throw e;
1952 errorMessage = "statement expected";
1958 void ForStatement() :
1961 final int pos = jj_input_stream.bufpos;
1967 } catch (ParseException e) {
1968 errorMessage = "'(' expected after 'for' keyword";
1972 [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ ForUpdate() ] <RPAREN>
1976 <COLON> (Statement())*
1979 setMarker(fileToParse,
1980 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
1982 pos+token.image.length(),
1984 "Line " + token.beginLine);
1985 } catch (CoreException e) {
1986 PHPeclipsePlugin.log(e);
1991 } catch (ParseException e) {
1992 errorMessage = "'endfor' expected";
1998 } catch (ParseException e) {
1999 errorMessage = "';' expected 'endfor' keyword";
2009 LOOKAHEAD(LocalVariableDeclaration())
2010 LocalVariableDeclaration()
2012 StatementExpressionList()
2015 void StatementExpressionList() :
2018 StatementExpression() ( <COMMA> StatementExpression() )*
2024 StatementExpressionList()
2027 void BreakStatement() :
2030 <BREAK> [ <IDENTIFIER> ] <SEMICOLON>
2033 void ContinueStatement() :
2036 <CONTINUE> [ <IDENTIFIER> ] <SEMICOLON>
2039 void ReturnStatement() :
2042 <RETURN> [ Expression() ] <SEMICOLON>