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 /** The file that is parsed. */
54 private static IFile fileToParse;
56 /** The current segment */
57 private static PHPSegmentWithChildren currentSegment;
59 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
60 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
61 PHPOutlineInfo outlineInfo;
63 /** The error level of the current ParseException. */
64 private static int errorLevel = ERROR;
65 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
66 private static String errorMessage;
68 private static int errorStart = -1;
69 private static int errorEnd = -1;
74 public final void setFileToParse(final IFile fileToParse) {
75 this.fileToParse = fileToParse;
78 public PHPParser(final IFile fileToParse) {
79 this(new StringReader(""));
80 this.fileToParse = fileToParse;
83 public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
84 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
85 final StringReader stream = new StringReader(strEval);
86 if (jj_input_stream == null) {
87 jj_input_stream = new SimpleCharStream(stream, 1, 1);
89 ReInit(new StringReader(strEval));
93 public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
94 final StringReader stream = new StringReader(strEval);
95 if (jj_input_stream == null) {
96 jj_input_stream = new SimpleCharStream(stream, 1, 1);
102 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
103 outlineInfo = new PHPOutlineInfo(parent);
104 currentSegment = outlineInfo.getDeclarations();
105 final StringReader stream = new StringReader(s);
106 if (jj_input_stream == null) {
107 jj_input_stream = new SimpleCharStream(stream, 1, 1);
112 } catch (ParseException e) {
113 processParseException(e);
119 * This method will process the parse exception.
120 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
121 * @param e the ParseException
123 private static void processParseException(final ParseException e) {
124 if (errorMessage == null) {
125 PHPeclipsePlugin.log(e);
126 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
133 * Create marker for the parse error
134 * @param e the ParseException
136 private static void setMarker(final ParseException e) {
138 if (errorStart == -1) {
139 setMarker(fileToParse,
141 jj_input_stream.tokenBegin,
142 jj_input_stream.tokenBegin + e.currentToken.image.length(),
144 "Line " + e.currentToken.beginLine);
146 setMarker(fileToParse,
151 "Line " + e.currentToken.beginLine);
155 } catch (CoreException e2) {
156 PHPeclipsePlugin.log(e2);
161 * Create markers according to the external parser output
163 private static void createMarkers(final String output, final IFile file) throws CoreException {
164 // delete all markers
165 file.deleteMarkers(IMarker.PROBLEM, false, 0);
170 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
171 // newer php error output (tested with 4.2.3)
172 scanLine(output, file, indx, brIndx);
177 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
178 // older php error output (tested with 4.2.3)
179 scanLine(output, file, indx, brIndx);
185 private static void scanLine(final String output,
188 final int brIndx) throws CoreException {
190 StringBuffer lineNumberBuffer = new StringBuffer(10);
192 current = output.substring(indx, brIndx);
194 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
195 int onLine = current.indexOf("on line <b>");
197 lineNumberBuffer.delete(0, lineNumberBuffer.length());
198 for (int i = onLine; i < current.length(); i++) {
199 ch = current.charAt(i);
200 if ('0' <= ch && '9' >= ch) {
201 lineNumberBuffer.append(ch);
205 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
207 Hashtable attributes = new Hashtable();
209 current = current.replaceAll("\n", "");
210 current = current.replaceAll("<b>", "");
211 current = current.replaceAll("</b>", "");
212 MarkerUtilities.setMessage(attributes, current);
214 if (current.indexOf(PARSE_ERROR_STRING) != -1)
215 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
216 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
217 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
219 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
220 MarkerUtilities.setLineNumber(attributes, lineNumber);
221 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
226 public final void parse(final String s) throws CoreException {
227 final StringReader stream = new StringReader(s);
228 if (jj_input_stream == null) {
229 jj_input_stream = new SimpleCharStream(stream, 1, 1);
234 } catch (ParseException e) {
235 processParseException(e);
240 * Call the php parse command ( php -l -f <filename> )
241 * and create markers according to the external parser output
243 public static void phpExternalParse(final IFile file) {
244 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
245 final String filename = file.getLocation().toString();
247 final String[] arguments = { filename };
248 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
249 final String command = form.format(arguments);
251 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
254 // parse the buffer to find the errors and warnings
255 createMarkers(parserResult, file);
256 } catch (CoreException e) {
257 PHPeclipsePlugin.log(e);
261 public static final void parse() throws ParseException {
266 PARSER_END(PHPParser)
270 <PHPSTARTSHORT : "<?"> : PHPPARSING
271 | <PHPSTARTLONG : "<?php"> : PHPPARSING
272 | <PHPECHOSTART : "<?="> : PHPPARSING
277 <PHPEND :"?>"> : DEFAULT
299 <PHPPARSING> SPECIAL_TOKEN :
301 "//" : IN_SINGLE_LINE_COMMENT
303 "#" : IN_SINGLE_LINE_COMMENT
305 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
307 "/*" : IN_MULTI_LINE_COMMENT
310 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
312 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
315 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
317 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
323 <FORMAL_COMMENT: "*/" > : PHPPARSING
326 <IN_MULTI_LINE_COMMENT>
329 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
332 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
342 | <FUNCTION : "function">
345 | <ELSEIF : "elseif">
351 /* LANGUAGE CONSTRUCT */
356 | <INCLUDE : "include">
357 | <REQUIRE : "require">
358 | <INCLUDE_ONCE : "include_once">
359 | <REQUIRE_ONCE : "require_once">
360 | <GLOBAL : "global">
361 | <STATIC : "static">
362 | <CLASSACCESS : "->">
363 | <STATICCLASSACCESS : "::">
364 | <ARRAYASSIGN : "=>">
371 /* RESERVED WORDS AND LITERALS */
377 | <CONTINUE : "continue">
378 | <_DEFAULT : "default">
380 | <EXTENDS : "extends">
385 | <RETURN : "return">
387 | <SWITCH : "switch">
392 | <ENDWHILE : "endwhile">
394 | <ENDFOR : "endfor">
395 | <FOREACH : "foreach">
404 | <OBJECT : "object">
406 | <BOOLEAN : "boolean">
408 | <DOUBLE : "double">
411 | <INTEGER : "integer">
425 <DECIMAL_LITERAL> (["l","L"])?
426 | <HEX_LITERAL> (["l","L"])?
427 | <OCTAL_LITERAL> (["l","L"])?
430 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
432 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
434 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
436 < FLOATING_POINT_LITERAL:
437 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
438 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
439 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
440 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
443 < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
445 < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
480 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
483 ["a"-"z"] | ["A"-"Z"]
491 "_" | ["\u007f"-"\u00ff"]
521 | <BANGDOUBLEEQUAL : "!==">
522 | <TRIPLEEQUAL : "===">
529 | <PLUSASSIGN : "+=">
530 | <MINUSASSIGN : "-=">
531 | <STARASSIGN : "*=">
532 | <SLASHASSIGN : "/=">
538 | <TILDEEQUAL : "~=">
562 | <RSIGNEDSHIFT : ">>">
563 | <RUNSIGNEDSHIFT : ">>>">
564 | <LSHIFTASSIGN : "<<=">
565 | <RSIGNEDSHIFTASSIGN : ">>=">
570 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
586 } catch (TokenMgrError e) {
587 errorMessage = e.getMessage();
589 throw generateParseException();
595 final int start = jj_input_stream.bufpos;
598 <PHPECHOSTART> Expression() [ <SEMICOLON> ] <PHPEND>
603 setMarker(fileToParse,
604 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
606 jj_input_stream.bufpos,
608 "Line " + token.beginLine);
609 } catch (CoreException e) {
610 PHPeclipsePlugin.log(e);
616 } catch (ParseException e) {
617 errorMessage = "'?>' expected";
629 void ClassDeclaration() :
631 final PHPClassDeclaration classDeclaration;
632 final Token className;
638 {pos = jj_input_stream.bufpos;}
639 className = <IDENTIFIER>
640 } catch (ParseException e) {
641 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
649 } catch (ParseException e) {
650 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
656 if (currentSegment != null) {
657 classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
658 currentSegment.add(classDeclaration);
659 currentSegment = classDeclaration;
664 if (currentSegment != null) {
665 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
675 } catch (ParseException e) {
676 errorMessage = "'{' expected";
680 ( ClassBodyDeclaration() )*
683 } catch (ParseException e) {
684 errorMessage = "'var', 'function' or '}' expected";
690 void ClassBodyDeclaration() :
698 void FieldDeclaration() :
700 PHPVarDeclaration variableDeclaration;
703 <VAR> variableDeclaration = VariableDeclarator()
705 if (currentSegment != null) {
706 currentSegment.add(variableDeclaration);
710 variableDeclaration = VariableDeclarator()
712 if (currentSegment != null) {
713 currentSegment.add(variableDeclaration);
719 } catch (ParseException e) {
720 errorMessage = "';' expected after variable declaration";
726 PHPVarDeclaration VariableDeclarator() :
728 final String varName;
730 final int pos = jj_input_stream.bufpos;
733 varName = VariableDeclaratorId()
737 varValue = VariableInitializer()
738 {return new PHPVarDeclaration(currentSegment,varName,pos,varValue);}
739 } catch (ParseException e) {
740 errorMessage = "Literal expression expected in variable initializer";
745 {return new PHPVarDeclaration(currentSegment,varName,pos);}
748 String VariableDeclaratorId() :
751 final StringBuffer buff = new StringBuffer();
757 ( LOOKAHEAD(2) expr = VariableSuffix()
760 {return buff.toString();}
761 } catch (ParseException e) {
762 errorMessage = "'$' expected for variable identifier";
774 token = <DOLLAR_ID> [<LBRACE> expr = Expression() <RBRACE>]
779 return token + "{" + expr + "}";
782 <DOLLAR> expr = VariableName()
786 String VariableName():
792 <LBRACE> expr = Expression() <RBRACE>
793 {return "{"+expr+"}";}
795 token = <IDENTIFIER> [<LBRACE> expr = Expression() <RBRACE>]
800 return token + "{" + expr + "}";
803 <DOLLAR> expr = VariableName()
806 token = <DOLLAR_ID> [expr = VariableName()]
811 return token.image + expr;
815 String VariableInitializer() :
824 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
825 {return "-" + token.image;}
827 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
828 {return "+" + token.image;}
830 expr = ArrayDeclarator()
834 {return token.image;}
837 String ArrayVariable() :
840 final StringBuffer buff = new StringBuffer();
845 [<ARRAYASSIGN> expr = Expression()
846 {buff.append("=>").append(expr);}]
847 {return buff.toString();}
850 String ArrayInitializer() :
853 final StringBuffer buff = new StringBuffer("(");
856 <LPAREN> [ expr = ArrayVariable()
858 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
859 {buff.append(",").append(expr);}
864 return buff.toString();
868 void MethodDeclaration() :
870 final PHPFunctionDeclaration functionDeclaration;
875 functionDeclaration = MethodDeclarator()
876 } catch (ParseException e) {
877 if (errorMessage != null) {
880 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
885 if (currentSegment != null) {
886 currentSegment.add(functionDeclaration);
887 currentSegment = functionDeclaration;
892 if (currentSegment != null) {
893 currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
898 PHPFunctionDeclaration MethodDeclarator() :
900 final Token identifier;
901 final StringBuffer methodDeclaration = new StringBuffer();
902 final String formalParameters;
903 final int pos = jj_input_stream.bufpos;
906 [ <BIT_AND> {methodDeclaration.append("&");} ]
907 identifier = <IDENTIFIER>
908 {methodDeclaration.append(identifier);}
909 formalParameters = FormalParameters()
911 methodDeclaration.append(formalParameters);
912 return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);
916 String FormalParameters() :
919 final StringBuffer buff = new StringBuffer("(");
924 } catch (ParseException e) {
925 errorMessage = "Formal parameter expected after function identifier";
927 jj_consume_token(token.kind);
929 [ expr = FormalParameter()
932 <COMMA> expr = FormalParameter()
933 {buff.append(",").append(expr);}
938 } catch (ParseException e) {
939 errorMessage = "')' expected";
945 return buff.toString();
949 String FormalParameter() :
951 final PHPVarDeclaration variableDeclaration;
952 final StringBuffer buff = new StringBuffer();
955 [<BIT_AND> {buff.append("&");}] variableDeclaration = VariableDeclarator()
957 buff.append(variableDeclaration.toString());
958 return buff.toString();
993 String Expression() :
996 final String assignOperator;
1000 expr = PrintExpression()
1003 expr = ListExpression()
1006 expr = ConditionalExpression()
1008 assignOperator = AssignmentOperator()
1010 expr2 = Expression()
1011 {return expr + assignOperator + expr2;}
1012 } catch (ParseException e) {
1013 errorMessage = "expression expected";
1021 String AssignmentOperator() :
1038 | <RSIGNEDSHIFTASSIGN>
1052 String ConditionalExpression() :
1055 String expr2 = null;
1056 String expr3 = null;
1059 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1061 if (expr3 == null) {
1064 return expr + "?" + expr2 + ":" + expr3;
1069 String ConditionalOrExpression() :
1073 final StringBuffer buff = new StringBuffer();
1076 expr = ConditionalAndExpression()
1077 {buff.append(expr);}
1079 (operator = <SC_OR> | operator = <_ORL>) expr = ConditionalAndExpression()
1081 buff.append(operator.image);
1086 return buff.toString();
1090 String ConditionalAndExpression() :
1094 final StringBuffer buff = new StringBuffer();
1097 expr = ConcatExpression()
1098 {buff.append(expr);}
1100 (operator = <SC_AND> | operator = <_ANDL>) expr = ConcatExpression()
1102 buff.append(operator.image);
1106 {return buff.toString();}
1109 String ConcatExpression() :
1112 final StringBuffer buff = new StringBuffer();
1115 expr = InclusiveOrExpression()
1116 {buff.append(expr);}
1118 <DOT> expr = InclusiveOrExpression()
1119 {buff.append(".").append(expr);}
1121 {return buff.toString();}
1124 String InclusiveOrExpression() :
1127 final StringBuffer buff = new StringBuffer();
1130 expr = ExclusiveOrExpression()
1131 {buff.append(expr);}
1133 <BIT_OR> expr = ExclusiveOrExpression()
1134 {buff.append("|").append(expr);}
1136 {return buff.toString();}
1139 String ExclusiveOrExpression() :
1142 final StringBuffer buff = new StringBuffer();
1145 expr = AndExpression()
1150 <XOR> expr = AndExpression()
1157 return buff.toString();
1161 String AndExpression() :
1164 final StringBuffer buff = new StringBuffer();
1167 expr = EqualityExpression()
1172 <BIT_AND> expr = EqualityExpression()
1174 buff.append("&").append(expr);
1177 {return buff.toString();}
1180 String EqualityExpression() :
1184 final StringBuffer buff = new StringBuffer();
1187 expr = RelationalExpression()
1188 {buff.append(expr);}
1193 | operator = <BANGDOUBLEEQUAL>
1194 | operator = <TRIPLEEQUAL>
1196 expr = RelationalExpression()
1198 buff.append(operator.image);
1202 {return buff.toString();}
1205 String RelationalExpression() :
1209 final StringBuffer buff = new StringBuffer();
1212 expr = ShiftExpression()
1213 {buff.append(expr);}
1215 ( operator = <LT> | operator = <GT> | operator = <LE> | operator = <GE> ) expr = ShiftExpression()
1216 {buff.append(operator.image).append(expr);}
1218 {return buff.toString();}
1221 String ShiftExpression() :
1225 final StringBuffer buff = new StringBuffer();
1228 expr = AdditiveExpression()
1229 {buff.append(expr);}
1231 (operator = <LSHIFT> | operator = <RSIGNEDSHIFT> | operator = <RUNSIGNEDSHIFT> ) expr = AdditiveExpression()
1233 buff.append(operator.image);
1237 {return buff.toString();}
1240 String AdditiveExpression() :
1244 final StringBuffer buff = new StringBuffer();
1247 expr = MultiplicativeExpression()
1248 {buff.append(expr);}
1250 ( operator = <PLUS> | operator = <MINUS> ) expr = MultiplicativeExpression()
1252 buff.append(operator.image);
1256 {return buff.toString();}
1259 String MultiplicativeExpression() :
1263 final StringBuffer buff = new StringBuffer();}
1265 expr = UnaryExpression()
1266 {buff.append(expr);}
1268 ( operator = <STAR> | operator = <SLASH> | operator = <REM> ) expr = UnaryExpression()
1270 buff.append(operator.image);
1274 {return buff.toString();}
1278 * An unary expression starting with @, & or nothing
1280 String UnaryExpression() :
1284 final StringBuffer buff = new StringBuffer();
1287 token = <BIT_AND> expr = UnaryExpressionNoPrefix()
1289 if (token == null) {
1292 return token.image + expr;
1295 (<AT> {buff.append("@");})* expr = UnaryExpressionNoPrefix()
1296 {return buff.append(expr).toString();}
1299 String UnaryExpressionNoPrefix() :
1305 ( token = <PLUS> | token = <MINUS> ) expr = UnaryExpression()
1307 return token.image + expr;
1310 expr = PreIncrementExpression()
1313 expr = PreDecrementExpression()
1316 expr = UnaryExpressionNotPlusMinus()
1321 String PreIncrementExpression() :
1326 <INCR> expr = PrimaryExpression()
1330 String PreDecrementExpression() :
1335 <DECR> expr = PrimaryExpression()
1339 String UnaryExpressionNotPlusMinus() :
1344 <BANG> expr = UnaryExpression()
1345 {return "!" + expr;}
1347 LOOKAHEAD( <LPAREN> Type() <RPAREN> )
1348 expr = CastExpression()
1351 expr = PostfixExpression()
1357 <LPAREN> expr = Expression()
1360 } catch (ParseException e) {
1361 errorMessage = "')' expected";
1365 {return "("+expr+")";}
1368 String CastExpression() :
1370 final String type, expr;
1373 <LPAREN> type = Type() <RPAREN> expr = UnaryExpression()
1374 {return "(" + type + ")" + expr;}
1377 String PostfixExpression() :
1380 Token operator = null;
1383 expr = PrimaryExpression() [ operator = <INCR> | operator = <DECR> ]
1385 if (operator == null) {
1388 return expr + operator.image;
1392 String PrimaryExpression() :
1394 final Token identifier;
1396 final StringBuffer buff = new StringBuffer();
1400 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1401 {buff.append(identifier.image).append("::").append(expr);}
1403 expr = PrimarySuffix()
1404 {buff.append(expr);}
1406 {return buff.toString();}
1408 expr = PrimaryPrefix() {buff.append(expr);}
1409 ( expr = PrimarySuffix() {buff.append(expr);} )*
1410 {return buff.toString();}
1412 expr = ArrayDeclarator()
1413 {return "array" + expr;}
1416 String ArrayDeclarator() :
1421 <ARRAY> expr = ArrayInitializer()
1422 {return "array" + expr;}
1425 String PrimaryPrefix() :
1431 token = <IDENTIFIER>
1432 {return token.image;}
1434 <NEW> expr = ClassIdentifier()
1436 return "new " + expr;
1439 expr = VariableDeclaratorId()
1443 String ClassIdentifier():
1449 token = <IDENTIFIER>
1450 {return token.image;}
1452 expr = VariableDeclaratorId()
1456 String PrimarySuffix() :
1464 expr = VariableSuffix()
1468 String VariableSuffix() :
1475 expr = VariableName()
1476 } catch (ParseException e) {
1477 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1481 {return "->" + expr;}
1483 <LBRACKET> [ expr = Expression() ]
1486 } catch (ParseException e) {
1487 errorMessage = "']' expected";
1495 return "[" + expr + "]";
1505 token = <INTEGER_LITERAL>
1506 {return token.image;}
1508 token = <FLOATING_POINT_LITERAL>
1509 {return token.image;}
1511 token = <STRING_LITERAL>
1512 {return token.image;}
1514 expr = BooleanLiteral()
1517 expr = NullLiteral()
1521 String BooleanLiteral() :
1531 String NullLiteral() :
1538 String Arguments() :
1543 <LPAREN> [ expr = ArgumentList() ]
1546 } catch (ParseException e) {
1547 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1555 return "(" + expr + ")";
1559 String ArgumentList() :
1562 final StringBuffer buff = new StringBuffer();
1566 {buff.append(expr);}
1570 } catch (ParseException e) {
1571 errorMessage = "expression expected after a comma in argument list";
1576 buff.append(",").append(expr);
1579 {return buff.toString();}
1583 * A Statement without break
1585 void StatementNoBreak() :
1591 (<SEMICOLON> | <PHPEND>)
1592 } catch (ParseException e) {
1593 errorMessage = "';' expected";
1605 StatementExpression()
1608 } catch (ParseException e) {
1609 errorMessage = "';' expected after expression";
1632 [<AT>] IncludeStatement()
1640 * A Normal statement
1650 void IncludeStatement() :
1653 final int pos = jj_input_stream.bufpos;
1659 if (currentSegment != null) {
1660 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require",pos,expr));
1664 (<SEMICOLON> | "?>")
1665 } catch (ParseException e) {
1666 errorMessage = "';' expected";
1674 if (currentSegment != null) {
1675 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "require_once",pos,expr));
1679 (<SEMICOLON> | "?>")
1680 } catch (ParseException e) {
1681 errorMessage = "';' expected";
1689 if (currentSegment != null) {
1690 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include",pos,expr));
1694 (<SEMICOLON> | "?>")
1695 } catch (ParseException e) {
1696 errorMessage = "';' expected";
1704 if (currentSegment != null) {
1705 currentSegment.add(new PHPReqIncDeclaration(currentSegment, "include_once",pos,expr));
1709 (<SEMICOLON> | "?>")
1710 } catch (ParseException e) {
1711 errorMessage = "';' expected";
1717 String PrintExpression() :
1719 final StringBuffer buff = new StringBuffer("print ");
1723 <PRINT> expr = Expression()
1726 return buff.toString();
1730 String ListExpression() :
1732 final StringBuffer buff = new StringBuffer("list(");
1739 } catch (ParseException e) {
1740 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1745 expr = VariableDeclaratorId()
1746 {buff.append(expr);}
1751 } catch (ParseException e) {
1752 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1756 expr = VariableDeclaratorId()
1757 {buff.append(",").append(expr);}
1762 } catch (ParseException e) {
1763 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1767 [ <ASSIGN> expr = Expression() {buff.append("(").append(expr);}]
1768 {return buff.toString();}
1771 void EchoStatement() :
1774 <ECHO> Expression() (<COMMA> Expression())*
1776 (<SEMICOLON> | "?>")
1777 } catch (ParseException e) {
1778 errorMessage = "';' expected after 'echo' statement";
1784 void GlobalStatement() :
1787 <GLOBAL> VariableDeclaratorId() (<COMMA> VariableDeclaratorId())*
1789 (<SEMICOLON> | "?>")
1790 } catch (ParseException e) {
1791 errorMessage = "';' expected";
1797 void StaticStatement() :
1800 <STATIC> VariableDeclarator() (<COMMA> VariableDeclarator())*
1802 (<SEMICOLON> | "?>")
1803 } catch (ParseException e) {
1804 errorMessage = "';' expected";
1810 void LabeledStatement() :
1813 <IDENTIFIER> <COLON> Statement()
1821 } catch (ParseException e) {
1822 errorMessage = "'{' expected";
1826 ( BlockStatement() )*
1829 } catch (ParseException e) {
1830 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
1836 void BlockStatement() :
1847 * A Block statement that will not contain any 'break'
1849 void BlockStatementNoBreak() :
1859 void LocalVariableDeclaration() :
1862 LocalVariableDeclarator() ( <COMMA> LocalVariableDeclarator() )*
1865 void LocalVariableDeclarator() :
1868 VariableDeclaratorId() [ <ASSIGN> Expression() ]
1871 void EmptyStatement() :
1877 void StatementExpression() :
1880 PreIncrementExpression()
1882 PreDecrementExpression()
1890 AssignmentOperator() Expression()
1894 void SwitchStatement() :
1896 Token breakToken = null;
1903 } catch (ParseException e) {
1904 errorMessage = "'(' expected after 'switch'";
1911 } catch (ParseException e) {
1912 errorMessage = "')' expected";
1918 } catch (ParseException e) {
1919 errorMessage = "'{' expected";
1924 line = SwitchLabel()
1925 ( BlockStatementNoBreak() )*
1926 [ breakToken = <BREAK>
1929 } catch (ParseException e) {
1930 errorMessage = "';' expected after 'break' keyword";
1937 if (breakToken == null) {
1938 setMarker(fileToParse,
1939 "You should use put a 'break' at the end of your statement",
1944 } catch (CoreException e) {
1945 PHPeclipsePlugin.log(e);
1951 } catch (ParseException e) {
1952 errorMessage = "'}' expected";
1966 } catch (ParseException e) {
1967 if (errorMessage != null) throw e;
1968 errorMessage = "expression expected after 'case' keyword";
1974 } catch (ParseException e) {
1975 errorMessage = "':' expected after case expression";
1979 {return token.beginLine;}
1984 } catch (ParseException e) {
1985 errorMessage = "':' expected after 'default' keyword";
1989 {return token.beginLine;}
1992 void IfStatement() :
1995 final int pos = jj_input_stream.bufpos;
1998 token = <IF> Condition("if") IfStatement0(pos,pos+token.image.length())
2001 void Condition(final String keyword) :
2006 } catch (ParseException e) {
2007 errorMessage = "'(' expected after " + keyword + " keyword";
2014 } catch (ParseException e) {
2015 errorMessage = "')' expected after " + keyword + " keyword";
2021 void IfStatement0(final int start,final int end) :
2024 <COLON> (Statement())* (ElseIfStatementColon())* [ElseStatementColon()]
2027 setMarker(fileToParse,
2028 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2032 "Line " + token.beginLine);
2033 } catch (CoreException e) {
2034 PHPeclipsePlugin.log(e);
2038 } catch (ParseException e) {
2039 errorMessage = "'endif' expected";
2045 } catch (ParseException e) {
2046 errorMessage = "';' expected after 'endif' keyword";
2051 Statement() ( LOOKAHEAD(1) ElseIfStatement() )* [ LOOKAHEAD(1) <ELSE> Statement() ]
2054 void ElseIfStatementColon() :
2057 <ELSEIF> Condition("elseif") <COLON> (Statement())*
2060 void ElseStatementColon() :
2063 <ELSE> <COLON> (Statement())*
2066 void ElseIfStatement() :
2069 <ELSEIF> Condition("elseif") Statement()
2072 void WhileStatement() :
2075 final int pos = jj_input_stream.bufpos;
2078 token = <WHILE> Condition("while") WhileStatement0(pos,pos + token.image.length())
2081 void WhileStatement0(final int start, final int end) :
2084 <COLON> (Statement())*
2086 setMarker(fileToParse,
2087 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2091 "Line " + token.beginLine);
2092 } catch (CoreException e) {
2093 PHPeclipsePlugin.log(e);
2097 } catch (ParseException e) {
2098 errorMessage = "'endwhile' expected";
2103 (<SEMICOLON> | "?>")
2104 } catch (ParseException e) {
2105 errorMessage = "';' expected after 'endwhile' keyword";
2113 void DoStatement() :
2116 <DO> Statement() <WHILE> Condition("while")
2118 (<SEMICOLON> | "?>")
2119 } catch (ParseException e) {
2120 errorMessage = "';' expected";
2126 void ForeachStatement() :
2132 } catch (ParseException e) {
2133 errorMessage = "'(' expected after 'foreach' keyword";
2139 } catch (ParseException e) {
2140 errorMessage = "variable expected";
2144 [ VariableSuffix() ]
2147 } catch (ParseException e) {
2148 errorMessage = "'as' expected";
2154 } catch (ParseException e) {
2155 errorMessage = "variable expected";
2159 [ <ARRAYASSIGN> Expression() ]
2162 } catch (ParseException e) {
2163 errorMessage = "')' expected after 'foreach' keyword";
2169 } catch (ParseException e) {
2170 if (errorMessage != null) throw e;
2171 errorMessage = "statement expected";
2177 void ForStatement() :
2180 final int pos = jj_input_stream.bufpos;
2186 } catch (ParseException e) {
2187 errorMessage = "'(' expected after 'for' keyword";
2191 [ ForInit() ] <SEMICOLON> [ Expression() ] <SEMICOLON> [ StatementExpressionList() ] <RPAREN>
2195 <COLON> (Statement())*
2198 setMarker(fileToParse,
2199 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2201 pos+token.image.length(),
2203 "Line " + token.beginLine);
2204 } catch (CoreException e) {
2205 PHPeclipsePlugin.log(e);
2210 } catch (ParseException e) {
2211 errorMessage = "'endfor' expected";
2217 } catch (ParseException e) {
2218 errorMessage = "';' expected after 'endfor' keyword";
2228 LOOKAHEAD(LocalVariableDeclaration())
2229 LocalVariableDeclaration()
2231 StatementExpressionList()
2234 void StatementExpressionList() :
2237 StatementExpression() ( <COMMA> StatementExpression() )*
2240 void BreakStatement() :
2243 <BREAK> [ <IDENTIFIER> ]
2246 } catch (ParseException e) {
2247 errorMessage = "';' expected after 'break' statement";
2253 void ContinueStatement() :
2256 <CONTINUE> [ <IDENTIFIER> ]
2259 } catch (ParseException e) {
2260 errorMessage = "';' expected after 'continue' statement";
2266 void ReturnStatement() :
2269 <RETURN> [ Expression() ]
2272 } catch (ParseException e) {
2273 errorMessage = "';' expected after 'return' statement";