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.util.Enumeration;
33 import java.util.ArrayList;
34 import java.io.StringReader;
36 import java.text.MessageFormat;
38 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
39 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
40 import net.sourceforge.phpdt.internal.compiler.ast.*;
41 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
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 OutlineableWithChildren 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 static PHPOutlineInfo outlineInfo;
63 public static MethodDeclaration currentFunction;
64 private static boolean assigning;
66 /** The error level of the current ParseException. */
67 private static int errorLevel = ERROR;
68 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
69 private static String errorMessage;
71 private static int errorStart = -1;
72 private static int errorEnd = -1;
73 private static PHPDocument phpDocument;
75 * The point where html starts.
76 * It will be used by the token manager to create HTMLCode objects
78 public static int htmlStart;
81 private final static int AstStackIncrement = 100;
82 /** The stack of node. */
83 private static AstNode[] nodes;
84 /** The cursor in expression stack. */
85 private static int nodePtr;
87 public final void setFileToParse(final IFile fileToParse) {
88 this.fileToParse = fileToParse;
94 public PHPParser(final IFile fileToParse) {
95 this(new StringReader(""));
96 this.fileToParse = fileToParse;
100 * Reinitialize the parser.
102 private static final void init() {
103 nodes = new AstNode[AstStackIncrement];
109 * Add an php node on the stack.
110 * @param node the node that will be added to the stack
112 private static final void pushOnAstNodes(AstNode node) {
114 nodes[++nodePtr] = node;
115 } catch (IndexOutOfBoundsException e) {
116 int oldStackLength = nodes.length;
117 AstNode[] oldStack = nodes;
118 nodes = new AstNode[oldStackLength + AstStackIncrement];
119 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
120 nodePtr = oldStackLength;
121 nodes[nodePtr] = node;
125 public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
126 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
127 final StringReader stream = new StringReader(strEval);
128 if (jj_input_stream == null) {
129 jj_input_stream = new SimpleCharStream(stream, 1, 1);
131 ReInit(new StringReader(strEval));
136 public static final void htmlParserTester(final File fileName) throws CoreException, ParseException {
138 final Reader stream = new FileReader(fileName);
139 if (jj_input_stream == null) {
140 jj_input_stream = new SimpleCharStream(stream, 1, 1);
145 } catch (FileNotFoundException e) {
146 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
150 public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
151 final StringReader stream = new StringReader(strEval);
152 if (jj_input_stream == null) {
153 jj_input_stream = new SimpleCharStream(stream, 1, 1);
160 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
161 currentSegment = new PHPDocument(parent);
162 outlineInfo = new PHPOutlineInfo(parent);
163 final StringReader stream = new StringReader(s);
164 if (jj_input_stream == null) {
165 jj_input_stream = new SimpleCharStream(stream, 1, 1);
171 //PHPeclipsePlugin.log(1,phpDocument.toString());
172 } catch (ParseException e) {
173 processParseException(e);
179 * This method will process the parse exception.
180 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
181 * @param e the ParseException
183 private static void processParseException(final ParseException e) {
184 if (errorMessage == null) {
185 PHPeclipsePlugin.log(e);
186 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
187 errorStart = jj_input_stream.getPosition();
188 errorEnd = errorStart + 1;
195 * Create marker for the parse error
196 * @param e the ParseException
198 private static void setMarker(final ParseException e) {
200 if (errorStart == -1) {
201 setMarker(fileToParse,
203 jj_input_stream.tokenBegin,
204 jj_input_stream.tokenBegin + e.currentToken.image.length(),
206 "Line " + e.currentToken.beginLine);
208 setMarker(fileToParse,
213 "Line " + e.currentToken.beginLine);
217 } catch (CoreException e2) {
218 PHPeclipsePlugin.log(e2);
223 * Create markers according to the external parser output
225 private static void createMarkers(final String output, final IFile file) throws CoreException {
226 // delete all markers
227 file.deleteMarkers(IMarker.PROBLEM, false, 0);
232 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
233 // newer php error output (tested with 4.2.3)
234 scanLine(output, file, indx, brIndx);
239 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
240 // older php error output (tested with 4.2.3)
241 scanLine(output, file, indx, brIndx);
247 private static void scanLine(final String output,
250 final int brIndx) throws CoreException {
252 StringBuffer lineNumberBuffer = new StringBuffer(10);
254 current = output.substring(indx, brIndx);
256 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
257 int onLine = current.indexOf("on line <b>");
259 lineNumberBuffer.delete(0, lineNumberBuffer.length());
260 for (int i = onLine; i < current.length(); i++) {
261 ch = current.charAt(i);
262 if ('0' <= ch && '9' >= ch) {
263 lineNumberBuffer.append(ch);
267 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
269 Hashtable attributes = new Hashtable();
271 current = current.replaceAll("\n", "");
272 current = current.replaceAll("<b>", "");
273 current = current.replaceAll("</b>", "");
274 MarkerUtilities.setMessage(attributes, current);
276 if (current.indexOf(PARSE_ERROR_STRING) != -1)
277 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
278 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
279 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
281 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
282 MarkerUtilities.setLineNumber(attributes, lineNumber);
283 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
288 public final void parse(final String s) throws CoreException {
289 final StringReader stream = new StringReader(s);
290 if (jj_input_stream == null) {
291 jj_input_stream = new SimpleCharStream(stream, 1, 1);
297 } catch (ParseException e) {
298 processParseException(e);
303 * Call the php parse command ( php -l -f <filename> )
304 * and create markers according to the external parser output
306 public static void phpExternalParse(final IFile file) {
307 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
308 final String filename = file.getLocation().toString();
310 final String[] arguments = { filename };
311 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
312 final String command = form.format(arguments);
314 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
317 // parse the buffer to find the errors and warnings
318 createMarkers(parserResult, file);
319 } catch (CoreException e) {
320 PHPeclipsePlugin.log(e);
325 * Put a new html block in the stack.
327 public static final void createNewHTMLCode() {
328 final int currentPosition = SimpleCharStream.getPosition();
329 if (currentPosition == htmlStart) {
332 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition).toCharArray();
333 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
336 private static final void parse() throws ParseException {
341 PARSER_END(PHPParser)
345 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
346 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
347 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
352 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
355 /* Skip any character if we are not in php mode */
373 <PHPPARSING> SPECIAL_TOKEN :
375 "//" : IN_SINGLE_LINE_COMMENT
377 "#" : IN_SINGLE_LINE_COMMENT
379 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
381 "/*" : IN_MULTI_LINE_COMMENT
384 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
386 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
389 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
391 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
397 <FORMAL_COMMENT: "*/" > : PHPPARSING
400 <IN_MULTI_LINE_COMMENT>
403 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
406 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
416 | <FUNCTION : "function">
419 | <ELSEIF : "elseif">
426 /* LANGUAGE CONSTRUCT */
431 | <INCLUDE : "include">
432 | <REQUIRE : "require">
433 | <INCLUDE_ONCE : "include_once">
434 | <REQUIRE_ONCE : "require_once">
435 | <GLOBAL : "global">
436 | <STATIC : "static">
437 | <CLASSACCESS : "->">
438 | <STATICCLASSACCESS : "::">
439 | <ARRAYASSIGN : "=>">
442 /* RESERVED WORDS AND LITERALS */
448 | <CONTINUE : "continue">
449 | <_DEFAULT : "default">
451 | <EXTENDS : "extends">
456 | <RETURN : "return">
458 | <SWITCH : "switch">
463 | <ENDWHILE : "endwhile">
464 | <ENDSWITCH: "endswitch">
466 | <ENDFOR : "endfor">
467 | <FOREACH : "foreach">
475 | <OBJECT : "object">
477 | <BOOLEAN : "boolean">
479 | <DOUBLE : "double">
482 | <INTEGER : "integer">
512 | <RSIGNEDSHIFT : ">>">
513 | <RUNSIGNEDSHIFT : ">>>">
522 <DECIMAL_LITERAL> (["l","L"])?
523 | <HEX_LITERAL> (["l","L"])?
524 | <OCTAL_LITERAL> (["l","L"])?
527 < #DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
529 < #HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
531 < #OCTAL_LITERAL: "0" (["0"-"7"])* >
533 < FLOATING_POINT_LITERAL:
534 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
535 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
536 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
537 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
540 < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
542 < STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
576 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
579 ["a"-"z"] | ["A"-"Z"]
587 "_" | ["\u007f"-"\u00ff"]
612 | <EQUAL_EQUAL : "==">
617 | <BANGDOUBLEEQUAL : "!==">
618 | <TRIPLEEQUAL : "===">
625 | <PLUSASSIGN : "+=">
626 | <MINUSASSIGN : "-=">
627 | <STARASSIGN : "*=">
628 | <SLASHASSIGN : "/=">
634 | <TILDEEQUAL : "~=">
635 | <LSHIFTASSIGN : "<<=">
636 | <RSIGNEDSHIFTASSIGN : ">>=">
641 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
649 {PHPParser.createNewHTMLCode();}
658 } catch (TokenMgrError e) {
659 PHPeclipsePlugin.log(e);
660 errorStart = SimpleCharStream.getPosition();
661 errorEnd = errorStart + 1;
662 errorMessage = e.getMessage();
664 throw generateParseException();
669 * A php block is a <?= expression [;]?>
670 * or <?php somephpcode ?>
671 * or <? somephpcode ?>
675 final int start = jj_input_stream.getPosition();
683 setMarker(fileToParse,
684 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
686 jj_input_stream.getPosition(),
688 "Line " + token.beginLine);
689 } catch (CoreException e) {
690 PHPeclipsePlugin.log(e);
696 } catch (ParseException e) {
697 errorMessage = "'?>' expected";
699 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
700 errorEnd = jj_input_stream.getPosition() + 1;
705 PHPEchoBlock phpEchoBlock() :
707 final Expression expr;
708 final int pos = SimpleCharStream.getPosition();
709 PHPEchoBlock echoBlock;
712 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
714 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
715 pushOnAstNodes(echoBlock);
725 ClassDeclaration ClassDeclaration() :
727 final ClassDeclaration classDeclaration;
728 final Token className;
729 Token superclassName = null;
735 {pos = jj_input_stream.getPosition();}
736 className = <IDENTIFIER>
737 } catch (ParseException e) {
738 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
740 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
741 errorEnd = jj_input_stream.getPosition() + 1;
747 superclassName = <IDENTIFIER>
748 } catch (ParseException e) {
749 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
751 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
752 errorEnd = jj_input_stream.getPosition() + 1;
757 if (superclassName == null) {
758 classDeclaration = new ClassDeclaration(currentSegment,
759 className.image.toCharArray(),
763 classDeclaration = new ClassDeclaration(currentSegment,
764 className.image.toCharArray(),
765 superclassName.image.toCharArray(),
769 currentSegment.add(classDeclaration);
770 currentSegment = classDeclaration;
772 ClassBody(classDeclaration)
773 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
774 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
775 pushOnAstNodes(classDeclaration);
776 return classDeclaration;}
779 void ClassBody(ClassDeclaration classDeclaration) :
784 } catch (ParseException e) {
785 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
787 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
788 errorEnd = jj_input_stream.getPosition() + 1;
791 ( ClassBodyDeclaration(classDeclaration) )*
794 } catch (ParseException e) {
795 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
797 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
798 errorEnd = jj_input_stream.getPosition() + 1;
804 * A class can contain only methods and fields.
806 void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
808 MethodDeclaration method;
809 FieldDeclaration field;
812 method = MethodDeclaration() {classDeclaration.addMethod(method);}
813 | field = FieldDeclaration() {classDeclaration.addVariable(field);}
817 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
819 FieldDeclaration FieldDeclaration() :
821 VariableDeclaration variableDeclaration;
822 final ArrayList list = new ArrayList();
823 final int pos = SimpleCharStream.getPosition();
826 <VAR> variableDeclaration = VariableDeclarator()
828 list.add(variableDeclaration);
829 outlineInfo.addVariable(new String(variableDeclaration.name));
830 currentSegment.add(variableDeclaration);
833 variableDeclaration = VariableDeclarator()
834 {list.add(variableDeclaration);
835 outlineInfo.addVariable(new String(variableDeclaration.name));
836 currentSegment.add(variableDeclaration);}
840 } catch (ParseException e) {
841 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
843 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
844 errorEnd = jj_input_stream.getPosition() + 1;
847 {return new FieldDeclaration((VariableDeclaration[]) list.toArray(),
849 SimpleCharStream.getPosition());}
852 VariableDeclaration VariableDeclarator() :
854 final String varName, varValue;
855 Expression initializer = null;
856 final int pos = jj_input_stream.getPosition();
859 varName = VariableDeclaratorId()
863 initializer = VariableInitializer()
864 } catch (ParseException e) {
865 errorMessage = "Literal expression expected in variable initializer";
867 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
868 errorEnd = jj_input_stream.getPosition() + 1;
873 if (initializer == null) {
874 return new VariableDeclaration(currentSegment,
875 varName.toCharArray(),
877 jj_input_stream.getPosition());
879 return new VariableDeclaration(currentSegment,
880 varName.toCharArray(),
888 * @return the variable name (with suffix)
890 String VariableDeclaratorId() :
893 Expression expression;
894 final StringBuffer buff = new StringBuffer();
895 final int pos = SimpleCharStream.getPosition();
896 ConstantIdentifier ex;
900 expr = Variable() {buff.append(expr);}
902 {ex = new ConstantIdentifier(expr.toCharArray(),
904 SimpleCharStream.getPosition());}
905 expression = VariableSuffix(ex)
906 {buff.append(expression.toStringExpression());}
908 {return buff.toString();}
909 } catch (ParseException e) {
910 errorMessage = "'$' expected for variable identifier";
912 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
913 errorEnd = jj_input_stream.getPosition() + 1;
920 final StringBuffer buff;
921 Expression expression = null;
926 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
928 if (expression == null && !assigning) {
929 return token.image.substring(1);
931 buff = new StringBuffer(token.image);
933 buff.append(expression.toStringExpression());
935 return buff.toString();
938 <DOLLAR> expr = VariableName()
942 String VariableName():
944 final StringBuffer buff;
946 Expression expression = null;
950 <LBRACE> expression = Expression() <RBRACE>
951 {buff = new StringBuffer('{');
952 buff.append(expression.toStringExpression());
954 return buff.toString();}
956 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
958 if (expression == null) {
961 buff = new StringBuffer(token.image);
963 buff.append(expression.toStringExpression());
965 return buff.toString();
968 <DOLLAR> expr = VariableName()
970 buff = new StringBuffer('$');
972 return buff.toString();
975 token = <DOLLAR_ID> {return token.image;}
978 Expression VariableInitializer() :
980 final Expression expr;
982 final int pos = SimpleCharStream.getPosition();
988 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
989 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
991 SimpleCharStream.getPosition()),
995 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
996 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
998 SimpleCharStream.getPosition()),
1002 expr = ArrayDeclarator()
1005 token = <IDENTIFIER>
1006 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
1009 ArrayVariableDeclaration ArrayVariable() :
1012 Expression expr2 = null;
1015 expr = Expression() [<ARRAYASSIGN> expr2 = Expression()]
1016 {return new ArrayVariableDeclaration(expr,expr2);}
1019 ArrayVariableDeclaration[] ArrayInitializer() :
1021 ArrayVariableDeclaration expr;
1022 final ArrayList list = new ArrayList();
1025 <LPAREN> [ expr = ArrayVariable()
1027 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
1031 [<COMMA> {list.add(null);}]
1033 {return (ArrayVariableDeclaration[]) list.toArray();}
1037 * A Method Declaration.
1038 * <b>function</b> MetodDeclarator() Block()
1040 MethodDeclaration MethodDeclaration() :
1042 final MethodDeclaration functionDeclaration;
1043 Token functionToken;
1047 functionToken = <FUNCTION>
1049 functionDeclaration = MethodDeclarator()
1050 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1051 } catch (ParseException e) {
1052 if (errorMessage != null) {
1055 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1057 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1058 errorEnd = jj_input_stream.getPosition() + 1;
1062 if (currentSegment != null) {
1063 currentSegment.add(functionDeclaration);
1064 currentSegment = functionDeclaration;
1066 currentFunction = functionDeclaration;
1070 functionDeclaration.statements = block.statements;
1071 currentFunction = null;
1072 if (currentSegment != null) {
1073 currentSegment = (OutlineableWithChildren) currentSegment.getParent();
1075 return functionDeclaration;
1080 * A MethodDeclarator.
1081 * [&] IDENTIFIER(parameters ...).
1082 * @return a function description for the outline
1084 MethodDeclaration MethodDeclarator() :
1086 final Token identifier;
1087 Token reference = null;
1088 final Hashtable formalParameters;
1089 final int pos = SimpleCharStream.getPosition();
1092 [ reference = <BIT_AND> ]
1093 identifier = <IDENTIFIER>
1094 formalParameters = FormalParameters()
1095 {return new MethodDeclaration(currentSegment,
1096 identifier.image.toCharArray(),
1100 SimpleCharStream.getPosition());}
1104 * FormalParameters follows method identifier.
1105 * (FormalParameter())
1107 Hashtable FormalParameters() :
1110 final StringBuffer buff = new StringBuffer("(");
1111 VariableDeclaration var;
1112 final Hashtable parameters = new Hashtable();
1117 } catch (ParseException e) {
1118 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1120 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1121 errorEnd = jj_input_stream.getPosition() + 1;
1124 [ var = FormalParameter()
1125 {parameters.put(new String(var.name),var);}
1127 <COMMA> var = FormalParameter()
1128 {parameters.put(new String(var.name),var);}
1133 } catch (ParseException e) {
1134 errorMessage = "')' expected";
1136 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1137 errorEnd = jj_input_stream.getPosition() + 1;
1140 {return parameters;}
1144 * A formal parameter.
1145 * $varname[=value] (,$varname[=value])
1147 VariableDeclaration FormalParameter() :
1149 final VariableDeclaration variableDeclaration;
1153 [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
1155 if (token != null) {
1156 variableDeclaration.setReference(true);
1158 return variableDeclaration;}
1161 ConstantIdentifier Type() :
1164 <STRING> {pos = SimpleCharStream.getPosition();
1165 return new ConstantIdentifier(Types.STRING,
1167 | <BOOL> {pos = SimpleCharStream.getPosition();
1168 return new ConstantIdentifier(Types.BOOL,
1170 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1171 return new ConstantIdentifier(Types.BOOLEAN,
1173 | <REAL> {pos = SimpleCharStream.getPosition();
1174 return new ConstantIdentifier(Types.REAL,
1176 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1177 return new ConstantIdentifier(Types.DOUBLE,
1179 | <FLOAT> {pos = SimpleCharStream.getPosition();
1180 return new ConstantIdentifier(Types.FLOAT,
1182 | <INT> {pos = SimpleCharStream.getPosition();
1183 return new ConstantIdentifier(Types.INT,
1185 | <INTEGER> {pos = SimpleCharStream.getPosition();
1186 return new ConstantIdentifier(Types.INTEGER,
1188 | <OBJECT> {pos = SimpleCharStream.getPosition();
1189 return new ConstantIdentifier(Types.OBJECT,
1193 Expression Expression() :
1195 final Expression expr;
1198 expr = PrintExpression() {return expr;}
1199 | expr = ListExpression() {return expr;}
1200 | LOOKAHEAD(varAssignation())
1201 expr = varAssignation() {return expr;}
1202 | expr = ConditionalExpression() {return expr;}
1206 * A Variable assignation.
1207 * varName (an assign operator) any expression
1209 VarAssignation varAssignation() :
1212 final Expression expression;
1213 final int assignOperator;
1214 final int pos = SimpleCharStream.getPosition();
1217 varName = VariableDeclaratorId()
1218 assignOperator = AssignmentOperator()
1220 expression = Expression()
1221 } catch (ParseException e) {
1222 if (errorMessage != null) {
1225 errorMessage = "expression expected";
1227 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1228 errorEnd = jj_input_stream.getPosition() + 1;
1231 {return new VarAssignation(varName.toCharArray(),
1235 SimpleCharStream.getPosition());}
1238 int AssignmentOperator() :
1241 <ASSIGN> {return VarAssignation.EQUAL;}
1242 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1243 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1244 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1245 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1246 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1247 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1248 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1249 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1250 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1251 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1252 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1253 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1256 Expression ConditionalExpression() :
1258 final Expression expr;
1259 Expression expr2 = null;
1260 Expression expr3 = null;
1263 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1265 if (expr3 == null) {
1268 return new ConditionalExpression(expr,expr2,expr3);
1272 Expression ConditionalOrExpression() :
1274 Expression expr,expr2;
1278 expr = ConditionalAndExpression()
1281 <OR_OR> {operator = OperatorIds.OR_OR;}
1282 | <_ORL> {operator = OperatorIds.ORL;}
1283 ) expr2 = ConditionalAndExpression()
1285 expr = new BinaryExpression(expr,expr2,operator);
1291 Expression ConditionalAndExpression() :
1293 Expression expr,expr2;
1297 expr = ConcatExpression()
1299 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1300 | <_ANDL> {operator = OperatorIds.ANDL;})
1301 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1306 Expression ConcatExpression() :
1308 Expression expr,expr2;
1311 expr = InclusiveOrExpression()
1313 <DOT> expr2 = InclusiveOrExpression()
1314 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1319 Expression InclusiveOrExpression() :
1321 Expression expr,expr2;
1324 expr = ExclusiveOrExpression()
1325 (<BIT_OR> expr2 = ExclusiveOrExpression()
1326 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1331 Expression ExclusiveOrExpression() :
1333 Expression expr,expr2;
1336 expr = AndExpression()
1338 <XOR> expr2 = AndExpression()
1339 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1344 Expression AndExpression() :
1346 Expression expr,expr2;
1349 expr = EqualityExpression()
1351 <BIT_AND> expr2 = EqualityExpression()
1352 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1357 Expression EqualityExpression() :
1359 Expression expr,expr2;
1363 expr = RelationalExpression()
1365 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1366 | <DIF> {operator = OperatorIds.DIF;}
1367 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1368 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1369 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1372 expr2 = RelationalExpression()
1373 } catch (ParseException e) {
1374 if (errorMessage != null) {
1377 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1379 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1380 errorEnd = jj_input_stream.getPosition() + 1;
1384 expr = new BinaryExpression(expr,expr2,operator);
1390 Expression RelationalExpression() :
1392 Expression expr,expr2;
1396 expr = ShiftExpression()
1398 ( <LT> {operator = OperatorIds.LESS;}
1399 | <GT> {operator = OperatorIds.GREATER;}
1400 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1401 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1402 expr2 = ShiftExpression()
1403 {expr = new BinaryExpression(expr,expr2,operator);}
1408 Expression ShiftExpression() :
1410 Expression expr,expr2;
1414 expr = AdditiveExpression()
1416 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1417 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1418 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1419 expr2 = AdditiveExpression()
1420 {expr = new BinaryExpression(expr,expr2,operator);}
1425 Expression AdditiveExpression() :
1427 Expression expr,expr2;
1431 expr = MultiplicativeExpression()
1433 ( <PLUS> {operator = OperatorIds.PLUS;}
1434 | <MINUS> {operator = OperatorIds.MINUS;} )
1435 expr2 = MultiplicativeExpression()
1436 {expr = new BinaryExpression(expr,expr2,operator);}
1441 Expression MultiplicativeExpression() :
1443 Expression expr,expr2;
1448 expr = UnaryExpression()
1449 } catch (ParseException e) {
1450 if (errorMessage != null) {
1453 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1455 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1456 errorEnd = jj_input_stream.getPosition() + 1;
1460 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1461 | <SLASH> {operator = OperatorIds.DIVIDE;}
1462 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1463 expr2 = UnaryExpression()
1464 {expr = new BinaryExpression(expr,expr2,operator);}
1470 * An unary expression starting with @, & or nothing
1472 Expression UnaryExpression() :
1475 final int pos = SimpleCharStream.getPosition();
1478 <BIT_AND> expr = UnaryExpressionNoPrefix()
1479 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1481 expr = AtUnaryExpression()
1485 Expression AtUnaryExpression() :
1488 final int pos = SimpleCharStream.getPosition();
1492 expr = AtUnaryExpression()
1493 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1495 expr = UnaryExpressionNoPrefix()
1500 Expression UnaryExpressionNoPrefix() :
1504 final int pos = SimpleCharStream.getPosition();
1507 ( <PLUS> {operator = OperatorIds.PLUS;}
1508 | <MINUS> {operator = OperatorIds.MINUS;})
1509 expr = UnaryExpression()
1510 {return new PrefixedUnaryExpression(expr,operator,pos);}
1512 expr = PreIncDecExpression()
1515 expr = UnaryExpressionNotPlusMinus()
1520 Expression PreIncDecExpression() :
1522 final Expression expr;
1524 final int pos = SimpleCharStream.getPosition();
1527 ( <INCR> {operator = OperatorIds.PLUS_PLUS;}
1528 | <DECR> {operator = OperatorIds.MINUS_MINUS;})
1529 expr = PrimaryExpression()
1530 {return new PrefixedUnaryExpression(expr,operator,pos);}
1533 Expression UnaryExpressionNotPlusMinus() :
1536 final int pos = SimpleCharStream.getPosition();
1539 <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1540 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1541 expr = CastExpression() {return expr;}
1542 | expr = PostfixExpression() {return expr;}
1543 | expr = Literal() {return expr;}
1544 | <LPAREN> expr = Expression()
1547 } catch (ParseException e) {
1548 errorMessage = "')' expected";
1550 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1551 errorEnd = jj_input_stream.getPosition() + 1;
1557 CastExpression CastExpression() :
1559 final ConstantIdentifier type;
1560 final Expression expr;
1561 final int pos = SimpleCharStream.getPosition();
1566 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1567 <RPAREN> expr = UnaryExpression()
1568 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1571 Expression PostfixExpression() :
1575 final int pos = SimpleCharStream.getPosition();
1578 expr = PrimaryExpression()
1579 [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
1580 | <DECR> {operator = OperatorIds.MINUS_MINUS;}]
1582 if (operator == -1) {
1585 return new PostfixedUnaryExpression(expr,operator,pos);
1589 Expression PrimaryExpression() :
1591 final Token identifier;
1593 final StringBuffer buff = new StringBuffer();
1594 final int pos = SimpleCharStream.getPosition();
1598 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1599 {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
1601 SimpleCharStream.getPosition()),
1603 ClassAccess.STATIC);}
1604 (expr = PrimarySuffix(expr))*
1607 expr = PrimaryPrefix()
1608 (expr = PrimarySuffix(expr))*
1611 expr = ArrayDeclarator()
1615 ArrayInitializer ArrayDeclarator() :
1617 final ArrayVariableDeclaration[] vars;
1618 final int pos = SimpleCharStream.getPosition();
1621 <ARRAY> vars = ArrayInitializer()
1622 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1625 Expression PrimaryPrefix() :
1627 final Expression expr;
1630 final int pos = SimpleCharStream.getPosition();
1633 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1635 SimpleCharStream.getPosition());}
1636 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1639 | var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(),
1641 SimpleCharStream.getPosition());}
1644 PrefixedUnaryExpression classInstantiation() :
1647 final StringBuffer buff;
1648 final int pos = SimpleCharStream.getPosition();
1651 <NEW> expr = ClassIdentifier()
1653 {buff = new StringBuffer(expr.toStringExpression());}
1654 expr = PrimaryExpression()
1655 {buff.append(expr.toStringExpression());
1656 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1658 SimpleCharStream.getPosition());}
1660 {return new PrefixedUnaryExpression(expr,
1665 ConstantIdentifier ClassIdentifier():
1669 final int pos = SimpleCharStream.getPosition();
1672 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1674 SimpleCharStream.getPosition());}
1675 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1677 SimpleCharStream.getPosition());}
1680 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
1682 final AbstractSuffixExpression expr;
1685 expr = Arguments(prefix) {return expr;}
1686 | expr = VariableSuffix(prefix) {return expr;}
1689 AbstractSuffixExpression VariableSuffix(Expression prefix) :
1692 final int pos = SimpleCharStream.getPosition();
1693 Expression expression = null;
1698 expr = VariableName()
1699 } catch (ParseException e) {
1700 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1702 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1703 errorEnd = jj_input_stream.getPosition() + 1;
1706 {return new ClassAccess(prefix,
1707 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1708 ClassAccess.NORMAL);}
1710 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1713 } catch (ParseException e) {
1714 errorMessage = "']' expected";
1716 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1717 errorEnd = jj_input_stream.getPosition() + 1;
1720 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1729 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1730 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1731 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1732 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1733 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1734 return new StringLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1735 | <TRUE> {pos = SimpleCharStream.getPosition();
1736 return new TrueLiteral(pos-4,pos);}
1737 | <FALSE> {pos = SimpleCharStream.getPosition();
1738 return new FalseLiteral(pos-4,pos);}
1739 | <NULL> {pos = SimpleCharStream.getPosition();
1740 return new NullLiteral(pos-4,pos);}
1743 FunctionCall Arguments(Expression func) :
1745 ArgumentDeclaration[] args = null;
1748 <LPAREN> [ args = ArgumentList() ]
1751 } catch (ParseException e) {
1752 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1754 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1755 errorEnd = jj_input_stream.getPosition() + 1;
1758 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1761 ArgumentDeclaration[] ArgumentList() :
1764 final ArrayList list = new ArrayList();
1773 } catch (ParseException e) {
1774 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1776 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1777 errorEnd = jj_input_stream.getPosition() + 1;
1781 {return (ArgumentDeclaration[]) list.toArray();}
1785 * A Statement without break.
1787 Statement StatementNoBreak() :
1789 final Statement statement;
1794 statement = Expression()
1797 } catch (ParseException e) {
1798 if (e.currentToken.next.kind != 4) {
1799 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1801 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1802 errorEnd = jj_input_stream.getPosition() + 1;
1808 statement = LabeledStatement() {return statement;}
1809 | statement = Block() {return statement;}
1810 | statement = EmptyStatement() {return statement;}
1811 | statement = StatementExpression()
1814 } catch (ParseException e) {
1815 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1817 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1818 errorEnd = jj_input_stream.getPosition() + 1;
1822 | statement = SwitchStatement() {return statement;}
1823 | statement = IfStatement() {return statement;}
1824 | statement = WhileStatement() {return statement;}
1825 | statement = DoStatement() {return statement;}
1826 | statement = ForStatement() {return statement;}
1827 | statement = ForeachStatement() {return statement;}
1828 | statement = ContinueStatement() {return statement;}
1829 | statement = ReturnStatement() {return statement;}
1830 | statement = EchoStatement() {return statement;}
1831 | [token=<AT>] statement = IncludeStatement()
1832 {if (token != null) {
1833 ((InclusionStatement)statement).silent = true;
1836 | statement = StaticStatement() {return statement;}
1837 | statement = GlobalStatement() {return statement;}
1841 * A Normal statement.
1843 Statement Statement() :
1845 final Statement statement;
1848 statement = StatementNoBreak() {return statement;}
1849 | statement = BreakStatement() {return statement;}
1853 * An html block inside a php syntax.
1855 HTMLBlock htmlBlock() :
1857 final int startIndex = nodePtr;
1858 AstNode[] blockNodes;
1862 <PHPEND> (phpEchoBlock())*
1864 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1865 } catch (ParseException e) {
1866 errorMessage = "End of file unexpected, '<?php' expected";
1868 errorStart = jj_input_stream.getPosition();
1869 errorEnd = jj_input_stream.getPosition();
1873 nbNodes = nodePtr-startIndex;
1874 blockNodes = new AstNode[nbNodes];
1875 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1876 return new HTMLBlock(nodes);}
1880 * An include statement. It's "include" an expression;
1882 InclusionStatement IncludeStatement() :
1884 final Expression expr;
1887 final int pos = jj_input_stream.getPosition();
1888 final InclusionStatement inclusionStatement;
1891 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1892 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1893 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1894 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1897 } catch (ParseException e) {
1898 if (errorMessage != null) {
1901 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1903 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1904 errorEnd = jj_input_stream.getPosition() + 1;
1907 {inclusionStatement = new InclusionStatement(currentSegment,
1911 currentSegment.add(inclusionStatement);
1915 } catch (ParseException e) {
1916 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1918 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1919 errorEnd = jj_input_stream.getPosition() + 1;
1922 {return inclusionStatement;}
1925 PrintExpression PrintExpression() :
1927 final Expression expr;
1928 final int pos = SimpleCharStream.getPosition();
1931 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1934 ListExpression ListExpression() :
1937 Expression expression = null;
1938 ArrayList list = new ArrayList();
1939 final int pos = SimpleCharStream.getPosition();
1945 } catch (ParseException e) {
1946 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1948 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1949 errorEnd = jj_input_stream.getPosition() + 1;
1953 expr = VariableDeclaratorId()
1956 {if (expr == null) list.add(null);}
1960 } catch (ParseException e) {
1961 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1963 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1964 errorEnd = jj_input_stream.getPosition() + 1;
1967 expr = VariableDeclaratorId()
1972 } catch (ParseException e) {
1973 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1975 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1976 errorEnd = jj_input_stream.getPosition() + 1;
1979 [ <ASSIGN> expression = Expression()
1980 {return new ListExpression((String[]) list.toArray(),expression,pos,SimpleCharStream.getPosition());}]
1981 {return new ListExpression((String[]) list.toArray(),null,pos,SimpleCharStream.getPosition());}
1985 * An echo statement.
1986 * echo anyexpression (, otherexpression)*
1988 EchoStatement EchoStatement() :
1990 final ArrayList expressions = new ArrayList();
1992 final int pos = SimpleCharStream.getPosition();
1995 <ECHO> expr = Expression()
1996 {expressions.add(expr);}
1998 <COMMA> expr = Expression()
1999 {expressions.add(expr);}
2003 {return new EchoStatement((Expression[]) expressions.toArray(),pos);}
2004 } catch (ParseException e) {
2005 if (e.currentToken.next.kind != 4) {
2006 errorMessage = "';' expected after 'echo' statement";
2008 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2009 errorEnd = jj_input_stream.getPosition() + 1;
2015 GlobalStatement GlobalStatement() :
2017 final int pos = jj_input_stream.getPosition();
2019 ArrayList vars = new ArrayList();
2020 GlobalStatement global;
2024 expr = VariableDeclaratorId()
2027 expr = VariableDeclaratorId()
2032 {global = new GlobalStatement(currentSegment,
2033 (String[]) vars.toArray(),
2035 SimpleCharStream.getPosition());
2036 currentSegment.add(global);
2038 } catch (ParseException e) {
2039 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2041 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2042 errorEnd = jj_input_stream.getPosition() + 1;
2047 StaticStatement StaticStatement() :
2049 final int pos = SimpleCharStream.getPosition();
2050 final ArrayList vars = new ArrayList();
2051 VariableDeclaration expr;
2054 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2055 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2058 {return new StaticStatement((String[])vars.toArray(),
2060 SimpleCharStream.getPosition());}
2061 } catch (ParseException e) {
2062 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2064 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2065 errorEnd = jj_input_stream.getPosition() + 1;
2070 LabeledStatement LabeledStatement() :
2072 final int pos = SimpleCharStream.getPosition();
2074 final Statement statement;
2077 label = <IDENTIFIER> <COLON> statement = Statement()
2078 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2090 final int pos = SimpleCharStream.getPosition();
2095 } catch (ParseException e) {
2096 errorMessage = "'{' expected";
2098 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2099 errorEnd = jj_input_stream.getPosition() + 1;
2102 ( BlockStatement() | htmlBlock())*
2105 } catch (ParseException e) {
2106 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2108 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2109 errorEnd = jj_input_stream.getPosition() + 1;
2114 Statement BlockStatement() :
2116 final Statement statement;
2119 statement = Statement() {return statement;}
2120 | statement = ClassDeclaration() {return statement;}
2121 | statement = MethodDeclaration() {return statement;}
2125 * A Block statement that will not contain any 'break'
2127 Statement BlockStatementNoBreak() :
2129 final Statement statement;
2132 statement = StatementNoBreak() {return statement;}
2133 | statement = ClassDeclaration() {return statement;}
2134 | statement = MethodDeclaration() {return statement;}
2137 VariableDeclaration[] LocalVariableDeclaration() :
2139 final ArrayList list = new ArrayList();
2140 VariableDeclaration var;
2143 var = LocalVariableDeclarator()
2145 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2146 {return (VariableDeclaration[]) list.toArray();}
2149 VariableDeclaration LocalVariableDeclarator() :
2151 final String varName;
2152 Expression initializer = null;
2153 final int pos = SimpleCharStream.getPosition();
2156 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2158 if (initializer == null) {
2159 return new VariableDeclaration(currentSegment,
2160 varName.toCharArray(),
2162 jj_input_stream.getPosition());
2164 return new VariableDeclaration(currentSegment,
2165 varName.toCharArray(),
2171 EmptyStatement EmptyStatement() :
2177 {pos = SimpleCharStream.getPosition();
2178 return new EmptyStatement(pos-1,pos);}
2181 Statement StatementExpression() :
2186 expr = PreIncDecExpression() {return expr;}
2188 expr = PrimaryExpression()
2189 [ <INCR> {expr = new PostfixedUnaryExpression(expr,
2190 OperatorIds.PLUS_PLUS,
2191 SimpleCharStream.getPosition());}
2192 | <DECR> {expr = new PostfixedUnaryExpression(expr,
2193 OperatorIds.MINUS_MINUS,
2194 SimpleCharStream.getPosition());}
2195 | AssignmentOperator() Expression() ]
2198 SwitchStatement SwitchStatement() :
2200 final Expression variable;
2201 final AbstractCase[] cases;
2202 final int pos = SimpleCharStream.getPosition();
2208 } catch (ParseException e) {
2209 errorMessage = "'(' expected after 'switch'";
2211 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2212 errorEnd = jj_input_stream.getPosition() + 1;
2216 variable = Expression()
2217 } catch (ParseException e) {
2218 if (errorMessage != null) {
2221 errorMessage = "expression expected";
2223 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2224 errorEnd = jj_input_stream.getPosition() + 1;
2229 } catch (ParseException e) {
2230 errorMessage = "')' expected";
2232 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2233 errorEnd = jj_input_stream.getPosition() + 1;
2236 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2237 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2240 AbstractCase[] switchStatementBrace() :
2243 final ArrayList cases = new ArrayList();
2247 ( cas = switchLabel0() {cases.add(cas);})*
2250 {return (AbstractCase[]) cases.toArray();}
2251 } catch (ParseException e) {
2252 errorMessage = "'}' expected";
2254 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2255 errorEnd = jj_input_stream.getPosition() + 1;
2260 * A Switch statement with : ... endswitch;
2261 * @param start the begin offset of the switch
2262 * @param end the end offset of the switch
2264 AbstractCase[] switchStatementColon(final int start, final int end) :
2267 final ArrayList cases = new ArrayList();
2272 setMarker(fileToParse,
2273 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2277 "Line " + token.beginLine);
2278 } catch (CoreException e) {
2279 PHPeclipsePlugin.log(e);
2281 ( cas = switchLabel0() {cases.add(cas);})*
2284 } catch (ParseException e) {
2285 errorMessage = "'endswitch' expected";
2287 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2288 errorEnd = jj_input_stream.getPosition() + 1;
2293 {return (AbstractCase[]) cases.toArray();}
2294 } catch (ParseException e) {
2295 errorMessage = "';' expected after 'endswitch' keyword";
2297 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2298 errorEnd = jj_input_stream.getPosition() + 1;
2303 AbstractCase switchLabel0() :
2305 final Expression expr;
2306 Statement statement;
2307 final ArrayList stmts = new ArrayList();
2308 final int pos = SimpleCharStream.getPosition();
2311 expr = SwitchLabel()
2312 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2313 | statement = htmlBlock() {stmts.add(statement);})*
2314 [ statement = BreakStatement() {stmts.add(statement);}]
2315 {if (expr == null) {//it's a default
2316 return new DefaultCase((Statement[]) stmts.toArray(),pos,SimpleCharStream.getPosition());
2318 return new Case(expr,(Statement[]) stmts.toArray(),pos,SimpleCharStream.getPosition());}
2323 * case Expression() :
2325 * @return the if it was a case and null if not
2327 Expression SwitchLabel() :
2330 final Expression expr;
2336 } catch (ParseException e) {
2337 if (errorMessage != null) throw e;
2338 errorMessage = "expression expected after 'case' keyword";
2340 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2341 errorEnd = jj_input_stream.getPosition() + 1;
2347 } catch (ParseException e) {
2348 errorMessage = "':' expected after case expression";
2350 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2351 errorEnd = jj_input_stream.getPosition() + 1;
2359 } catch (ParseException e) {
2360 errorMessage = "':' expected after 'default' keyword";
2362 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2363 errorEnd = jj_input_stream.getPosition() + 1;
2368 Break BreakStatement() :
2370 Expression expression = null;
2371 final int start = SimpleCharStream.getPosition();
2374 <BREAK> [ expression = Expression() ]
2377 } catch (ParseException e) {
2378 errorMessage = "';' expected after 'break' keyword";
2380 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2381 errorEnd = jj_input_stream.getPosition() + 1;
2384 {return new Break(expression, start, SimpleCharStream.getPosition());}
2387 IfStatement IfStatement() :
2389 final int pos = jj_input_stream.getPosition();
2390 Expression condition;
2391 IfStatement ifStatement;
2394 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2395 {return ifStatement;}
2399 Expression Condition(final String keyword) :
2401 final Expression condition;
2406 } catch (ParseException e) {
2407 errorMessage = "'(' expected after " + keyword + " keyword";
2409 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length();
2410 errorEnd = errorStart +1;
2411 processParseException(e);
2413 condition = Expression()
2417 } catch (ParseException e) {
2418 errorMessage = "')' expected after " + keyword + " keyword";
2420 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2421 errorEnd = jj_input_stream.getPosition() + 1;
2426 IfStatement IfStatement0(Expression condition, final int start,final int end) :
2428 Statement statement;
2429 ElseIf elseifStatement;
2430 Else elseStatement = null;
2431 ArrayList stmts = new ArrayList();
2432 ArrayList elseifs = new ArrayList();
2433 int pos = SimpleCharStream.getPosition();
2437 ( statement = Statement() {stmts.add(statement);}
2438 | statement = htmlBlock() {stmts.add(statement);})*
2439 (elseifStatement = ElseIfStatementColon() {elseifs.add(elseifStatement);})*
2440 [elseStatement = ElseStatementColon()]
2443 setMarker(fileToParse,
2444 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2448 "Line " + token.beginLine);
2449 } catch (CoreException e) {
2450 PHPeclipsePlugin.log(e);
2454 } catch (ParseException e) {
2455 errorMessage = "'endif' expected";
2457 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2458 errorEnd = jj_input_stream.getPosition() + 1;
2463 {return new IfStatement(condition,
2464 (ElseIf[]) elseifs.toArray(),
2467 SimpleCharStream.getPosition());}
2468 } catch (ParseException e) {
2469 errorMessage = "';' expected after 'endif' keyword";
2471 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2472 errorEnd = jj_input_stream.getPosition() + 1;
2476 (statement = Statement() | statement = htmlBlock())
2477 {stmts.add(statement);}
2478 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseifs.add(elseifStatement);})*
2482 {pos = SimpleCharStream.getPosition();}
2483 statement = Statement()
2484 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2485 } catch (ParseException e) {
2486 if (errorMessage != null) {
2489 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2491 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2492 errorEnd = jj_input_stream.getPosition() + 1;
2496 {return new IfStatement(condition,
2497 (ElseIf[]) elseifs.toArray(),
2500 SimpleCharStream.getPosition());}
2503 ElseIf ElseIfStatementColon() :
2505 Expression condition;
2506 Statement statement;
2507 final ArrayList list = new ArrayList();
2508 final int pos = SimpleCharStream.getPosition();
2511 <ELSEIF> condition = Condition("elseif")
2512 <COLON> ( statement = Statement() {list.add(statement);}
2513 | statement = htmlBlock() {list.add(statement);})*
2514 {return new ElseIf(condition,(Statement[]) list.toArray(),pos,SimpleCharStream.getPosition());}
2517 Else ElseStatementColon() :
2519 Statement statement;
2520 final ArrayList list = new ArrayList();
2521 final int pos = SimpleCharStream.getPosition();
2524 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2525 | statement = htmlBlock() {list.add(statement);})*
2526 {return new Else((Statement[]) list.toArray(),pos,SimpleCharStream.getPosition());}
2529 ElseIf ElseIfStatement() :
2531 Expression condition;
2532 Statement statement;
2533 final ArrayList list = new ArrayList();
2534 final int pos = SimpleCharStream.getPosition();
2537 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2538 {return new ElseIf(condition,(Statement[]) list.toArray(),pos,SimpleCharStream.getPosition());}
2541 WhileStatement WhileStatement() :
2543 final Expression condition;
2544 final Statement action;
2545 final int pos = SimpleCharStream.getPosition();
2549 condition = Condition("while")
2550 action = WhileStatement0(pos,pos + 5)
2551 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2554 Statement WhileStatement0(final int start, final int end) :
2556 Statement statement;
2557 final ArrayList stmts = new ArrayList();
2558 final int pos = SimpleCharStream.getPosition();
2561 <COLON> (statement = Statement() {stmts.add(statement);})*
2563 setMarker(fileToParse,
2564 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2568 "Line " + token.beginLine);
2569 } catch (CoreException e) {
2570 PHPeclipsePlugin.log(e);
2574 } catch (ParseException e) {
2575 errorMessage = "'endwhile' expected";
2577 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2578 errorEnd = jj_input_stream.getPosition() + 1;
2583 {return new Block((Statement[]) stmts.toArray(),pos,SimpleCharStream.getPosition());}
2584 } catch (ParseException e) {
2585 errorMessage = "';' expected after 'endwhile' keyword";
2587 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2588 errorEnd = jj_input_stream.getPosition() + 1;
2592 statement = Statement()
2596 DoStatement DoStatement() :
2598 final Statement action;
2599 final Expression condition;
2600 final int pos = SimpleCharStream.getPosition();
2603 <DO> action = Statement() <WHILE> condition = Condition("while")
2606 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2607 } catch (ParseException e) {
2608 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2610 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2611 errorEnd = jj_input_stream.getPosition() + 1;
2616 ForeachStatement ForeachStatement() :
2618 Statement statement;
2619 Expression expression;
2620 final StringBuffer buff = new StringBuffer();
2621 final int pos = SimpleCharStream.getPosition();
2622 ArrayVariableDeclaration variable;
2628 } catch (ParseException e) {
2629 errorMessage = "'(' expected after 'foreach' keyword";
2631 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2632 errorEnd = jj_input_stream.getPosition() + 1;
2636 expression = Expression()
2637 } catch (ParseException e) {
2638 errorMessage = "variable expected";
2640 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2641 errorEnd = jj_input_stream.getPosition() + 1;
2646 } catch (ParseException e) {
2647 errorMessage = "'as' expected";
2649 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2650 errorEnd = jj_input_stream.getPosition() + 1;
2654 variable = ArrayVariable()
2655 } catch (ParseException e) {
2656 errorMessage = "variable expected";
2658 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2659 errorEnd = jj_input_stream.getPosition() + 1;
2664 } catch (ParseException e) {
2665 errorMessage = "')' expected after 'foreach' keyword";
2667 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2668 errorEnd = jj_input_stream.getPosition() + 1;
2672 statement = Statement()
2673 } catch (ParseException e) {
2674 if (errorMessage != null) throw e;
2675 errorMessage = "statement expected";
2677 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2678 errorEnd = jj_input_stream.getPosition() + 1;
2681 {return new ForeachStatement(expression,
2685 SimpleCharStream.getPosition());}
2689 ForStatement ForStatement() :
2692 final int pos = SimpleCharStream.getPosition();
2693 Statement[] initializations = null;
2694 Expression condition = null;
2695 Statement[] increments = null;
2697 final ArrayList list = new ArrayList();
2698 final int startBlock, endBlock;
2704 } catch (ParseException e) {
2705 errorMessage = "'(' expected after 'for' keyword";
2707 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2708 errorEnd = jj_input_stream.getPosition() + 1;
2711 [ initializations = ForInit() ] <SEMICOLON>
2712 [ condition = Expression() ] <SEMICOLON>
2713 [ increments = StatementExpressionList() ] <RPAREN>
2715 action = Statement()
2716 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2719 {startBlock = SimpleCharStream.getPosition();}
2720 (action = Statement() {list.add(action);})*
2723 setMarker(fileToParse,
2724 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2726 pos+token.image.length(),
2728 "Line " + token.beginLine);
2729 } catch (CoreException e) {
2730 PHPeclipsePlugin.log(e);
2733 {endBlock = SimpleCharStream.getPosition();}
2736 } catch (ParseException e) {
2737 errorMessage = "'endfor' expected";
2739 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2740 errorEnd = jj_input_stream.getPosition() + 1;
2745 {return new ForStatement(initializations,condition,increments,new Block((Statement[])list.toArray(),startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2746 } catch (ParseException e) {
2747 errorMessage = "';' expected after 'endfor' keyword";
2749 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2750 errorEnd = jj_input_stream.getPosition() + 1;
2756 Statement[] ForInit() :
2758 Statement[] statements;
2761 LOOKAHEAD(LocalVariableDeclaration())
2762 statements = LocalVariableDeclaration()
2763 {return statements;}
2765 statements = StatementExpressionList()
2766 {return statements;}
2769 Statement[] StatementExpressionList() :
2771 final ArrayList list = new ArrayList();
2775 expr = StatementExpression() {list.add(expr);}
2776 (<COMMA> StatementExpression() {list.add(expr);})*
2777 {return (Statement[]) list.toArray();}
2780 Continue ContinueStatement() :
2782 Expression expr = null;
2783 final int pos = SimpleCharStream.getPosition();
2786 <CONTINUE> [ expr = Expression() ]
2789 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2790 } catch (ParseException e) {
2791 errorMessage = "';' expected after 'continue' statement";
2793 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2794 errorEnd = jj_input_stream.getPosition() + 1;
2799 ReturnStatement ReturnStatement() :
2801 Expression expr = null;
2802 final int pos = SimpleCharStream.getPosition();
2805 <RETURN> [ expr = Expression() ]
2808 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2809 } catch (ParseException e) {
2810 errorMessage = "';' expected after 'return' statement";
2812 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2813 errorEnd = jj_input_stream.getPosition() + 1;