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.ArrayList;
33 import java.io.StringReader;
35 import java.text.MessageFormat;
37 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
38 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
39 import net.sourceforge.phpdt.internal.compiler.ast.*;
40 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
41 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
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
50 * @version $Reference: 1.0$
52 public final class PHPParser extends PHPParserSuperclass {
54 /** The file that is parsed. */
55 private static IFile fileToParse;
57 /** The current segment. */
58 private static OutlineableWithChildren currentSegment;
60 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
61 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
62 static PHPOutlineInfo outlineInfo;
64 /** The error level of the current ParseException. */
65 private static int errorLevel = ERROR;
66 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
67 private static String errorMessage;
69 private static int errorStart = -1;
70 private static int errorEnd = -1;
71 private static PHPDocument phpDocument;
73 private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
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(final AstNode node) {
114 nodes[++nodePtr] = node;
115 } catch (IndexOutOfBoundsException e) {
116 final int oldStackLength = nodes.length;
117 final 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 final PHPOutlineInfo parseInfo(final Object parent, final String s) {
126 phpDocument = new PHPDocument(parent,"_root".toCharArray());
127 currentSegment = phpDocument;
128 outlineInfo = new PHPOutlineInfo(parent, currentSegment);
129 final StringReader stream = new StringReader(s);
130 if (jj_input_stream == null) {
131 jj_input_stream = new SimpleCharStream(stream, 1, 1);
137 phpDocument.nodes = new AstNode[nodes.length];
138 System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
139 if (PHPeclipsePlugin.DEBUG) {
140 PHPeclipsePlugin.log(1,phpDocument.toString());
142 } catch (ParseException e) {
143 processParseException(e);
149 * This method will process the parse exception.
150 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
151 * @param e the ParseException
153 private static void processParseException(final ParseException e) {
154 if (errorMessage == null) {
155 PHPeclipsePlugin.log(e);
156 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
157 errorStart = SimpleCharStream.getPosition();
158 errorEnd = errorStart + 1;
162 // if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e);
166 * Create marker for the parse error.
167 * @param e the ParseException
169 private static void setMarker(final ParseException e) {
171 if (errorStart == -1) {
172 setMarker(fileToParse,
174 SimpleCharStream.tokenBegin,
175 SimpleCharStream.tokenBegin + e.currentToken.image.length(),
177 "Line " + e.currentToken.beginLine);
179 setMarker(fileToParse,
184 "Line " + e.currentToken.beginLine);
188 } catch (CoreException e2) {
189 PHPeclipsePlugin.log(e2);
193 private static void scanLine(final String output,
196 final int brIndx) throws CoreException {
198 final StringBuffer lineNumberBuffer = new StringBuffer(10);
200 current = output.substring(indx, brIndx);
202 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
203 final int onLine = current.indexOf("on line <b>");
205 lineNumberBuffer.delete(0, lineNumberBuffer.length());
206 for (int i = onLine; i < current.length(); i++) {
207 ch = current.charAt(i);
208 if ('0' <= ch && '9' >= ch) {
209 lineNumberBuffer.append(ch);
213 final int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
215 final Hashtable attributes = new Hashtable();
217 current = current.replaceAll("\n", "");
218 current = current.replaceAll("<b>", "");
219 current = current.replaceAll("</b>", "");
220 MarkerUtilities.setMessage(attributes, current);
222 if (current.indexOf(PARSE_ERROR_STRING) != -1)
223 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
224 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
225 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
227 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
228 MarkerUtilities.setLineNumber(attributes, lineNumber);
229 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
234 public final void parse(final String s) throws CoreException {
235 final StringReader stream = new StringReader(s);
236 if (jj_input_stream == null) {
237 jj_input_stream = new SimpleCharStream(stream, 1, 1);
243 } catch (ParseException e) {
244 processParseException(e);
249 * Call the php parse command ( php -l -f <filename> )
250 * and create markers according to the external parser output
252 public static void phpExternalParse(final IFile file) {
253 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
254 final String filename = file.getLocation().toString();
256 final String[] arguments = { filename };
257 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
258 final String command = form.format(arguments);
260 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
263 // parse the buffer to find the errors and warnings
264 createMarkers(parserResult, file);
265 } catch (CoreException e) {
266 PHPeclipsePlugin.log(e);
271 * Put a new html block in the stack.
273 public static final void createNewHTMLCode() {
274 final int currentPosition = SimpleCharStream.getPosition();
275 if (currentPosition == htmlStart || currentPosition > SimpleCharStream.currentBuffer.length()) {
278 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
279 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
282 /** Create a new task. */
283 public static final void createNewTask() {
284 final int currentPosition = SimpleCharStream.getPosition();
285 final String todo = SimpleCharStream.currentBuffer.substring(currentPosition-3,
286 SimpleCharStream.currentBuffer.indexOf("\n",
288 PHPeclipsePlugin.log(1,SimpleCharStream.currentBuffer.toString());
290 setMarker(fileToParse,
292 SimpleCharStream.getBeginLine(),
294 "Line "+SimpleCharStream.getBeginLine());
295 } catch (CoreException e) {
296 PHPeclipsePlugin.log(e);
300 private static final void parse() throws ParseException {
305 PARSER_END(PHPParser)
309 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
310 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
311 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
316 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
319 /* Skip any character if we are not in php mode */
337 <PHPPARSING> SPECIAL_TOKEN :
339 "//" : IN_SINGLE_LINE_COMMENT
340 | "#" : IN_SINGLE_LINE_COMMENT
341 | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
342 | "/*" : IN_MULTI_LINE_COMMENT
345 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
347 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
351 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
353 "todo" {PHPParser.createNewTask();}
356 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
361 <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
366 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
376 | <FUNCTION : "function">
379 | <ELSEIF : "elseif">
386 /* LANGUAGE CONSTRUCT */
391 | <INCLUDE : "include">
392 | <REQUIRE : "require">
393 | <INCLUDE_ONCE : "include_once">
394 | <REQUIRE_ONCE : "require_once">
395 | <GLOBAL : "global">
396 | <DEFINE : "define">
397 | <STATIC : "static">
398 | <CLASSACCESS : "->">
399 | <STATICCLASSACCESS : "::">
400 | <ARRAYASSIGN : "=>">
403 /* RESERVED WORDS AND LITERALS */
409 | <CONTINUE : "continue">
410 | <_DEFAULT : "default">
412 | <EXTENDS : "extends">
417 | <RETURN : "return">
419 | <SWITCH : "switch">
424 | <ENDWHILE : "endwhile">
425 | <ENDSWITCH: "endswitch">
427 | <ENDFOR : "endfor">
428 | <FOREACH : "foreach">
436 | <OBJECT : "object">
438 | <BOOLEAN : "boolean">
440 | <DOUBLE : "double">
443 | <INTEGER : "integer">
463 | <MINUS_MINUS : "--">
473 | <RSIGNEDSHIFT : ">>">
474 | <RUNSIGNEDSHIFT : ">>>">
483 <DECIMAL_LITERAL> (["l","L"])?
484 | <HEX_LITERAL> (["l","L"])?
485 | <OCTAL_LITERAL> (["l","L"])?
488 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
490 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
492 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
494 <FLOATING_POINT_LITERAL:
495 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
496 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
497 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
498 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
501 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
503 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
504 | <STRING_1: "\"" ( ~["\"","\\"] | "\\" ~[] )* "\"">
505 | <STRING_2: "'" ( ~["'","\\"] | "\\" ~[] )* "'">
506 | <STRING_3: "`" ( ~["`","\\"] | "\\" ~[] )* "`">
513 <IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
516 ["a"-"z"] | ["A"-"Z"]
524 "_" | ["\u007f"-"\u00ff"]
549 | <EQUAL_EQUAL : "==">
554 | <BANGDOUBLEEQUAL : "!==">
555 | <TRIPLEEQUAL : "===">
562 | <PLUSASSIGN : "+=">
563 | <MINUSASSIGN : "-=">
564 | <STARASSIGN : "*=">
565 | <SLASHASSIGN : "/=">
571 | <TILDEEQUAL : "~=">
572 | <LSHIFTASSIGN : "<<=">
573 | <RSIGNEDSHIFTASSIGN : ">>=">
578 <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
586 {PHPParser.createNewHTMLCode();}
587 } catch (TokenMgrError e) {
588 PHPeclipsePlugin.log(e);
589 errorStart = SimpleCharStream.getPosition();
590 errorEnd = errorStart + 1;
591 errorMessage = e.getMessage();
593 throw generateParseException();
598 * A php block is a <?= expression [;]?>
599 * or <?php somephpcode ?>
600 * or <? somephpcode ?>
604 final int start = SimpleCharStream.getPosition();
605 final PHPEchoBlock phpEchoBlock;
608 phpEchoBlock = phpEchoBlock()
609 {pushOnAstNodes(phpEchoBlock);}
614 setMarker(fileToParse,
615 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
617 SimpleCharStream.getPosition(),
619 "Line " + token.beginLine);
620 } catch (CoreException e) {
621 PHPeclipsePlugin.log(e);
627 } catch (ParseException e) {
628 errorMessage = "'?>' expected";
630 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
631 errorEnd = SimpleCharStream.getPosition() + 1;
632 processParseException(e);
636 PHPEchoBlock phpEchoBlock() :
638 final Expression expr;
639 final int pos = SimpleCharStream.getPosition();
640 final PHPEchoBlock echoBlock;
643 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
645 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
646 pushOnAstNodes(echoBlock);
656 ClassDeclaration ClassDeclaration() :
658 final ClassDeclaration classDeclaration;
659 final Token className,superclassName;
661 char[] classNameImage = SYNTAX_ERROR_CHAR;
662 char[] superclassNameImage = null;
666 {pos = SimpleCharStream.getPosition();}
668 className = <IDENTIFIER>
669 {classNameImage = className.image.toCharArray();}
670 } catch (ParseException e) {
671 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
673 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
674 errorEnd = SimpleCharStream.getPosition() + 1;
675 processParseException(e);
680 superclassName = <IDENTIFIER>
681 {superclassNameImage = superclassName.image.toCharArray();}
682 } catch (ParseException e) {
683 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
685 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
686 errorEnd = SimpleCharStream.getPosition() + 1;
687 processParseException(e);
688 superclassNameImage = SYNTAX_ERROR_CHAR;
692 if (superclassNameImage == null) {
693 classDeclaration = new ClassDeclaration(currentSegment,
698 classDeclaration = new ClassDeclaration(currentSegment,
704 currentSegment.add(classDeclaration);
705 currentSegment = classDeclaration;
707 ClassBody(classDeclaration)
708 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
709 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
710 pushOnAstNodes(classDeclaration);
711 return classDeclaration;}
714 void ClassBody(final ClassDeclaration classDeclaration) :
719 } catch (ParseException e) {
720 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected";
722 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
723 errorEnd = SimpleCharStream.getPosition() + 1;
724 processParseException(e);
726 ( ClassBodyDeclaration(classDeclaration) )*
729 } catch (ParseException e) {
730 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected";
732 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
733 errorEnd = SimpleCharStream.getPosition() + 1;
734 processParseException(e);
739 * A class can contain only methods and fields.
741 void ClassBodyDeclaration(final ClassDeclaration classDeclaration) :
743 final MethodDeclaration method;
744 final FieldDeclaration field;
747 method = MethodDeclaration() {classDeclaration.addMethod(method);}
748 | field = FieldDeclaration() {classDeclaration.addField(field);}
752 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
754 FieldDeclaration FieldDeclaration() :
756 VariableDeclaration variableDeclaration;
757 final VariableDeclaration[] list;
758 final ArrayList arrayList = new ArrayList();
759 final int pos = SimpleCharStream.getPosition();
762 <VAR> variableDeclaration = VariableDeclarator()
763 {arrayList.add(variableDeclaration);
764 outlineInfo.addVariable(new String(variableDeclaration.name));}
765 ( <COMMA> variableDeclaration = VariableDeclarator()
766 {arrayList.add(variableDeclaration);
767 outlineInfo.addVariable(new String(variableDeclaration.name));}
771 } catch (ParseException e) {
772 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
774 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
775 errorEnd = SimpleCharStream.getPosition() + 1;
776 processParseException(e);
779 {list = new VariableDeclaration[arrayList.size()];
780 arrayList.toArray(list);
781 return new FieldDeclaration(list,
783 SimpleCharStream.getPosition(),
787 VariableDeclaration VariableDeclarator() :
789 final String varName;
790 Expression initializer = null;
791 final int pos = SimpleCharStream.getPosition();
794 varName = VariableDeclaratorId()
798 initializer = VariableInitializer()
799 } catch (ParseException e) {
800 errorMessage = "Literal expression expected in variable initializer";
802 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
803 errorEnd = SimpleCharStream.getPosition() + 1;
804 processParseException(e);
808 if (initializer == null) {
809 return new VariableDeclaration(currentSegment,
810 varName.toCharArray(),
812 SimpleCharStream.getPosition());
814 return new VariableDeclaration(currentSegment,
815 varName.toCharArray(),
823 * @return the variable name (with suffix)
825 String VariableDeclaratorId() :
828 Expression expression = null;
829 final int pos = SimpleCharStream.getPosition();
830 ConstantIdentifier ex;
836 {ex = new ConstantIdentifier(expr.toCharArray(),
838 SimpleCharStream.getPosition());}
839 expression = VariableSuffix(ex)
842 if (expression == null) {
845 return expression.toStringExpression();
847 } catch (ParseException e) {
848 errorMessage = "'$' expected for variable identifier";
850 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
851 errorEnd = SimpleCharStream.getPosition() + 1;
857 * Return a variablename without the $.
858 * @return a variable name
862 final StringBuffer buff;
863 Expression expression = null;
868 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
870 if (expression == null) {
871 return token.image.substring(1);
873 buff = new StringBuffer(token.image);
875 buff.append(expression.toStringExpression());
877 return buff.toString();
880 <DOLLAR> expr = VariableName()
885 * A Variable name (without the $)
886 * @return a variable name String
888 String VariableName():
890 final StringBuffer buff;
892 Expression expression = null;
896 <LBRACE> expression = Expression() <RBRACE>
897 {buff = new StringBuffer("{");
898 buff.append(expression.toStringExpression());
900 return buff.toString();}
902 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
904 if (expression == null) {
907 buff = new StringBuffer(token.image);
909 buff.append(expression.toStringExpression());
911 return buff.toString();
914 <DOLLAR> expr = VariableName()
916 buff = new StringBuffer("$");
918 return buff.toString();
921 token = <DOLLAR_ID> {return token.image;}
924 Expression VariableInitializer() :
926 final Expression expr;
928 final int pos = SimpleCharStream.getPosition();
934 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
935 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
937 SimpleCharStream.getPosition()),
941 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
942 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
944 SimpleCharStream.getPosition()),
948 expr = ArrayDeclarator()
952 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
955 ArrayVariableDeclaration ArrayVariable() :
957 final Expression expr,expr2;
961 [<ARRAYASSIGN> expr2 = Expression()
962 {return new ArrayVariableDeclaration(expr,expr2);}
964 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
967 ArrayVariableDeclaration[] ArrayInitializer() :
969 ArrayVariableDeclaration expr;
970 final ArrayList list = new ArrayList();
973 <LPAREN> [ expr = ArrayVariable()
975 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
979 [<COMMA> {list.add(null);}]
982 final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
988 * A Method Declaration.
989 * <b>function</b> MetodDeclarator() Block()
991 MethodDeclaration MethodDeclaration() :
993 final MethodDeclaration functionDeclaration;
995 final OutlineableWithChildren seg = currentSegment;
1000 functionDeclaration = MethodDeclarator()
1001 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1002 } catch (ParseException e) {
1003 if (errorMessage != null) throw e;
1004 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1006 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1007 errorEnd = SimpleCharStream.getPosition() + 1;
1010 {currentSegment = functionDeclaration;}
1012 {functionDeclaration.statements = block.statements;
1013 currentSegment = seg;
1014 return functionDeclaration;}
1018 * A MethodDeclarator.
1019 * [&] IDENTIFIER(parameters ...).
1020 * @return a function description for the outline
1022 MethodDeclaration MethodDeclarator() :
1024 final Token identifier;
1025 Token reference = null;
1026 final Hashtable formalParameters;
1027 final int pos = SimpleCharStream.getPosition();
1028 char[] identifierChar = SYNTAX_ERROR_CHAR;
1031 [reference = <BIT_AND>]
1033 identifier = <IDENTIFIER>
1034 {identifierChar = identifier.image.toCharArray();}
1035 } catch (ParseException e) {
1036 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1038 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1039 errorEnd = SimpleCharStream.getPosition() + 1;
1040 processParseException(e);
1042 formalParameters = FormalParameters()
1043 {return new MethodDeclaration(currentSegment,
1048 SimpleCharStream.getPosition());}
1052 * FormalParameters follows method identifier.
1053 * (FormalParameter())
1055 Hashtable FormalParameters() :
1057 VariableDeclaration var;
1058 final Hashtable parameters = new Hashtable();
1063 } catch (ParseException e) {
1064 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1066 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1067 errorEnd = SimpleCharStream.getPosition() + 1;
1068 processParseException(e);
1070 [ var = FormalParameter()
1071 {parameters.put(new String(var.name),var);}
1073 <COMMA> var = FormalParameter()
1074 {parameters.put(new String(var.name),var);}
1079 } catch (ParseException e) {
1080 errorMessage = "')' expected";
1082 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1083 errorEnd = SimpleCharStream.getPosition() + 1;
1084 processParseException(e);
1086 {return parameters;}
1090 * A formal parameter.
1091 * $varname[=value] (,$varname[=value])
1093 VariableDeclaration FormalParameter() :
1095 final VariableDeclaration variableDeclaration;
1099 [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
1101 if (token != null) {
1102 variableDeclaration.setReference(true);
1104 return variableDeclaration;}
1107 ConstantIdentifier Type() :
1110 <STRING> {pos = SimpleCharStream.getPosition();
1111 return new ConstantIdentifier(Types.STRING,pos,pos-6);}
1112 | <BOOL> {pos = SimpleCharStream.getPosition();
1113 return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
1114 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1115 return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
1116 | <REAL> {pos = SimpleCharStream.getPosition();
1117 return new ConstantIdentifier(Types.REAL,pos,pos-4);}
1118 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1119 return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
1120 | <FLOAT> {pos = SimpleCharStream.getPosition();
1121 return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
1122 | <INT> {pos = SimpleCharStream.getPosition();
1123 return new ConstantIdentifier(Types.INT,pos,pos-3);}
1124 | <INTEGER> {pos = SimpleCharStream.getPosition();
1125 return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
1126 | <OBJECT> {pos = SimpleCharStream.getPosition();
1127 return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
1130 Expression Expression() :
1132 final Expression expr;
1133 Expression initializer = null;
1134 int assignOperator = -1;
1135 final int pos = SimpleCharStream.getPosition();
1139 expr = ConditionalExpression()
1140 [ assignOperator = AssignmentOperator()
1142 initializer = Expression()
1143 } catch (ParseException e) {
1144 if (errorMessage != null) {
1147 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1149 errorEnd = SimpleCharStream.getPosition();
1154 if (assignOperator == -1) return expr;
1155 return new VarAssignation(expr,
1159 SimpleCharStream.getPosition());
1161 | expr = ExpressionWBang() {return expr;}
1164 Expression ExpressionWBang() :
1166 final Expression expr;
1167 final int pos = SimpleCharStream.getPosition();
1170 <BANG> expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1171 | expr = ExpressionNoBang() {return expr;}
1174 Expression ExpressionNoBang() :
1176 final Expression expr;
1179 expr = PrintExpression() {return expr;}
1180 | expr = ListExpression() {return expr;}
1184 * Any assignement operator.
1185 * @return the assignement operator id
1187 int AssignmentOperator() :
1190 <ASSIGN> {return VarAssignation.EQUAL;}
1191 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1192 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1193 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1194 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1195 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1196 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1197 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1198 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1199 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1200 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1201 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1202 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1205 Expression ConditionalExpression() :
1207 final Expression expr;
1208 Expression expr2 = null;
1209 Expression expr3 = null;
1212 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1214 if (expr3 == null) {
1217 return new ConditionalExpression(expr,expr2,expr3);
1221 Expression ConditionalOrExpression() :
1223 Expression expr,expr2;
1227 expr = ConditionalAndExpression()
1230 <OR_OR> {operator = OperatorIds.OR_OR;}
1231 | <_ORL> {operator = OperatorIds.ORL;}
1232 ) expr2 = ConditionalAndExpression()
1234 expr = new BinaryExpression(expr,expr2,operator);
1240 Expression ConditionalAndExpression() :
1242 Expression expr,expr2;
1246 expr = ConcatExpression()
1248 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1249 | <_ANDL> {operator = OperatorIds.ANDL;})
1250 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1255 Expression ConcatExpression() :
1257 Expression expr,expr2;
1260 expr = InclusiveOrExpression()
1262 <DOT> expr2 = InclusiveOrExpression()
1263 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1268 Expression InclusiveOrExpression() :
1270 Expression expr,expr2;
1273 expr = ExclusiveOrExpression()
1274 (<BIT_OR> expr2 = ExclusiveOrExpression()
1275 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1280 Expression ExclusiveOrExpression() :
1282 Expression expr,expr2;
1285 expr = AndExpression()
1287 <XOR> expr2 = AndExpression()
1288 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1293 Expression AndExpression() :
1295 Expression expr,expr2;
1298 expr = EqualityExpression()
1300 <BIT_AND> expr2 = EqualityExpression()
1301 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1306 Expression EqualityExpression() :
1308 Expression expr,expr2;
1312 expr = RelationalExpression()
1314 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1315 | <DIF> {operator = OperatorIds.DIF;}
1316 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1317 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1318 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1321 expr2 = RelationalExpression()
1322 } catch (ParseException e) {
1323 if (errorMessage != null) {
1326 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1328 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1329 errorEnd = SimpleCharStream.getPosition() + 1;
1333 expr = new BinaryExpression(expr,expr2,operator);
1339 Expression RelationalExpression() :
1341 Expression expr,expr2;
1345 expr = ShiftExpression()
1347 ( <LT> {operator = OperatorIds.LESS;}
1348 | <GT> {operator = OperatorIds.GREATER;}
1349 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1350 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1351 expr2 = ShiftExpression()
1352 {expr = new BinaryExpression(expr,expr2,operator);}
1357 Expression ShiftExpression() :
1359 Expression expr,expr2;
1363 expr = AdditiveExpression()
1365 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1366 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1367 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1368 expr2 = AdditiveExpression()
1369 {expr = new BinaryExpression(expr,expr2,operator);}
1374 Expression AdditiveExpression() :
1376 Expression expr,expr2;
1380 expr = MultiplicativeExpression()
1382 ( <PLUS> {operator = OperatorIds.PLUS;}
1383 | <MINUS> {operator = OperatorIds.MINUS;} )
1384 expr2 = MultiplicativeExpression()
1385 {expr = new BinaryExpression(expr,expr2,operator);}
1390 Expression MultiplicativeExpression() :
1392 Expression expr,expr2;
1397 expr = UnaryExpression()
1398 } catch (ParseException e) {
1399 if (errorMessage != null) throw e;
1400 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1402 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1403 errorEnd = SimpleCharStream.getPosition() + 1;
1407 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1408 | <SLASH> {operator = OperatorIds.DIVIDE;}
1409 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1410 expr2 = UnaryExpression()
1411 {expr = new BinaryExpression(expr,expr2,operator);}
1417 * An unary expression starting with @, & or nothing
1419 Expression UnaryExpression() :
1421 final Expression expr;
1422 final int pos = SimpleCharStream.getPosition();
1425 <BIT_AND> expr = UnaryExpressionNoPrefix()
1426 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1428 expr = AtUnaryExpression() {return expr;}
1431 Expression AtUnaryExpression() :
1433 final Expression expr;
1434 final int pos = SimpleCharStream.getPosition();
1438 expr = AtUnaryExpression()
1439 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1441 expr = UnaryExpressionNoPrefix()
1446 Expression UnaryExpressionNoPrefix() :
1448 final Expression expr;
1450 final int pos = SimpleCharStream.getPosition();
1453 ( <PLUS> {operator = OperatorIds.PLUS;}
1454 | <MINUS> {operator = OperatorIds.MINUS;})
1455 expr = UnaryExpression()
1456 {return new PrefixedUnaryExpression(expr,operator,pos);}
1458 expr = PreIncDecExpression()
1461 expr = UnaryExpressionNotPlusMinus()
1466 Expression PreIncDecExpression() :
1468 final Expression expr;
1470 final int pos = SimpleCharStream.getPosition();
1473 ( <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1474 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;})
1475 expr = PrimaryExpression()
1476 {return new PrefixedUnaryExpression(expr,operator,pos);}
1479 Expression UnaryExpressionNotPlusMinus() :
1481 final Expression expr;
1482 final int pos = SimpleCharStream.getPosition();
1485 LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1486 expr = CastExpression() {return expr;}
1487 | <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1488 | expr = PostfixExpression() {return expr;}
1489 | expr = Literal() {return expr;}
1490 | <LPAREN> expr = Expression()
1493 } catch (ParseException e) {
1494 errorMessage = "')' expected";
1496 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1497 errorEnd = SimpleCharStream.getPosition() + 1;
1503 CastExpression CastExpression() :
1505 final ConstantIdentifier type;
1506 final Expression expr;
1507 final int pos = SimpleCharStream.getPosition();
1512 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1513 <RPAREN> expr = UnaryExpression()
1514 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1517 Expression PostfixExpression() :
1519 final Expression expr;
1521 final int pos = SimpleCharStream.getPosition();
1524 expr = PrimaryExpression()
1525 [ <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1526 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}]
1528 if (operator == -1) {
1531 return new PostfixedUnaryExpression(expr,operator,pos);
1535 Expression PrimaryExpression() :
1540 expr = PrimaryPrefix()
1542 LOOKAHEAD(PrimarySuffix())
1543 expr = PrimarySuffix(expr)
1547 expr = ArrayDeclarator()
1551 Expression PrimaryPrefix() :
1553 final Expression expr;
1556 final int pos = SimpleCharStream.getPosition();
1559 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1561 SimpleCharStream.getPosition());}
1562 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1565 | var = VariableDeclaratorId() {return new VariableDeclaration(currentSegment,
1568 SimpleCharStream.getPosition());}
1571 AbstractSuffixExpression PrimarySuffix(final Expression prefix) :
1573 final AbstractSuffixExpression suffix;
1574 final Expression expr;
1577 suffix = Arguments(prefix) {return suffix;}
1578 | suffix = VariableSuffix(prefix) {return suffix;}
1579 | <STATICCLASSACCESS> expr = ClassIdentifier()
1580 {suffix = new ClassAccess(prefix,
1582 ClassAccess.STATIC);
1587 * An array declarator.
1591 ArrayInitializer ArrayDeclarator() :
1593 final ArrayVariableDeclaration[] vars;
1594 final int pos = SimpleCharStream.getPosition();
1597 <ARRAY> vars = ArrayInitializer()
1598 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1601 PrefixedUnaryExpression classInstantiation() :
1604 final StringBuffer buff;
1605 final int pos = SimpleCharStream.getPosition();
1608 <NEW> expr = ClassIdentifier()
1610 {buff = new StringBuffer(expr.toStringExpression());}
1611 expr = PrimaryExpression()
1612 {buff.append(expr.toStringExpression());
1613 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1615 SimpleCharStream.getPosition());}
1617 {return new PrefixedUnaryExpression(expr,
1622 ConstantIdentifier ClassIdentifier():
1626 final int pos = SimpleCharStream.getPosition();
1627 final ConstantIdentifier type;
1630 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1632 SimpleCharStream.getPosition());}
1633 | type = Type() {return type;}
1634 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1636 SimpleCharStream.getPosition());}
1639 AbstractSuffixExpression VariableSuffix(final Expression prefix) :
1642 final int pos = SimpleCharStream.getPosition();
1643 Expression expression = null;
1648 expr = VariableName()
1649 } catch (ParseException e) {
1650 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1652 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1653 errorEnd = SimpleCharStream.getPosition() + 1;
1656 {return new ClassAccess(prefix,
1657 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1658 ClassAccess.NORMAL);}
1660 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1663 } catch (ParseException e) {
1664 errorMessage = "']' expected";
1666 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1667 errorEnd = SimpleCharStream.getPosition() + 1;
1670 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1679 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1680 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1681 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1682 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1683 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1684 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1685 | <TRUE> {pos = SimpleCharStream.getPosition();
1686 return new TrueLiteral(pos-4,pos);}
1687 | <FALSE> {pos = SimpleCharStream.getPosition();
1688 return new FalseLiteral(pos-4,pos);}
1689 | <NULL> {pos = SimpleCharStream.getPosition();
1690 return new NullLiteral(pos-4,pos);}
1693 FunctionCall Arguments(final Expression func) :
1695 Expression[] args = null;
1698 <LPAREN> [ args = ArgumentList() ]
1701 } catch (ParseException e) {
1702 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1704 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1705 errorEnd = SimpleCharStream.getPosition() + 1;
1708 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1712 * An argument list is a list of arguments separated by comma :
1713 * argumentDeclaration() (, argumentDeclaration)*
1714 * @return an array of arguments
1716 Expression[] ArgumentList() :
1719 final ArrayList list = new ArrayList();
1728 } catch (ParseException e) {
1729 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1731 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1732 errorEnd = SimpleCharStream.getPosition() + 1;
1737 final Expression[] arguments = new Expression[list.size()];
1738 list.toArray(arguments);
1743 * A Statement without break.
1745 Statement StatementNoBreak() :
1747 final Statement statement;
1752 statement = Expression()
1755 } catch (ParseException e) {
1756 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1757 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1759 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1760 errorEnd = SimpleCharStream.getPosition() + 1;
1766 statement = LabeledStatement() {return statement;}
1767 | statement = Block() {return statement;}
1768 | statement = EmptyStatement() {return statement;}
1769 | statement = StatementExpression()
1772 } catch (ParseException e) {
1773 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1775 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1776 errorEnd = SimpleCharStream.getPosition() + 1;
1780 | statement = SwitchStatement() {return statement;}
1781 | statement = IfStatement() {return statement;}
1782 | statement = WhileStatement() {return statement;}
1783 | statement = DoStatement() {return statement;}
1784 | statement = ForStatement() {return statement;}
1785 | statement = ForeachStatement() {return statement;}
1786 | statement = ContinueStatement() {return statement;}
1787 | statement = ReturnStatement() {return statement;}
1788 | statement = EchoStatement() {return statement;}
1789 | [token=<AT>] statement = IncludeStatement()
1790 {if (token != null) {
1791 ((InclusionStatement)statement).silent = true;
1794 | statement = StaticStatement() {return statement;}
1795 | statement = GlobalStatement() {return statement;}
1796 | statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
1799 Define defineStatement() :
1801 final int start = SimpleCharStream.getPosition();
1802 Expression defineName,defineValue;
1808 } catch (ParseException e) {
1809 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1811 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1812 errorEnd = SimpleCharStream.getPosition() + 1;
1813 processParseException(e);
1816 defineName = Expression()
1817 } catch (ParseException e) {
1818 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1820 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1821 errorEnd = SimpleCharStream.getPosition() + 1;
1826 } catch (ParseException e) {
1827 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1829 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1830 errorEnd = SimpleCharStream.getPosition() + 1;
1831 processParseException(e);
1834 defineValue = Expression()
1835 } catch (ParseException e) {
1836 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1838 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1839 errorEnd = SimpleCharStream.getPosition() + 1;
1844 } catch (ParseException e) {
1845 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1847 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1848 errorEnd = SimpleCharStream.getPosition() + 1;
1849 processParseException(e);
1851 {return new Define(currentSegment,
1855 SimpleCharStream.getPosition());}
1859 * A Normal statement.
1861 Statement Statement() :
1863 final Statement statement;
1866 statement = StatementNoBreak() {return statement;}
1867 | statement = BreakStatement() {return statement;}
1871 * An html block inside a php syntax.
1873 HTMLBlock htmlBlock() :
1875 final int startIndex = nodePtr;
1876 final AstNode[] blockNodes;
1880 <PHPEND> (phpEchoBlock())*
1882 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1883 } catch (ParseException e) {
1884 errorMessage = "unexpected end of file , '<?php' expected";
1886 errorStart = SimpleCharStream.getPosition();
1887 errorEnd = SimpleCharStream.getPosition();
1891 nbNodes = nodePtr - startIndex;
1892 blockNodes = new AstNode[nbNodes];
1893 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1894 nodePtr = startIndex;
1895 return new HTMLBlock(blockNodes);}
1899 * An include statement. It's "include" an expression;
1901 InclusionStatement IncludeStatement() :
1903 final Expression expr;
1905 final int pos = SimpleCharStream.getPosition();
1906 final InclusionStatement inclusionStatement;
1909 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1910 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1911 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1912 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1915 } catch (ParseException e) {
1916 if (errorMessage != null) {
1919 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1921 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1922 errorEnd = SimpleCharStream.getPosition() + 1;
1925 {inclusionStatement = new InclusionStatement(currentSegment,
1929 currentSegment.add(inclusionStatement);
1933 } catch (ParseException e) {
1934 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1936 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1937 errorEnd = SimpleCharStream.getPosition() + 1;
1940 {return inclusionStatement;}
1943 PrintExpression PrintExpression() :
1945 final Expression expr;
1946 final int pos = SimpleCharStream.getPosition();
1949 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1952 ListExpression ListExpression() :
1955 final Expression expression;
1956 final ArrayList list = new ArrayList();
1957 final int pos = SimpleCharStream.getPosition();
1963 } catch (ParseException e) {
1964 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1966 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1967 errorEnd = SimpleCharStream.getPosition() + 1;
1971 expr = VariableDeclaratorId()
1974 {if (expr == null) list.add(null);}
1978 } catch (ParseException e) {
1979 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1981 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1982 errorEnd = SimpleCharStream.getPosition() + 1;
1985 [expr = VariableDeclaratorId() {list.add(expr);}]
1989 } catch (ParseException e) {
1990 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1992 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1993 errorEnd = SimpleCharStream.getPosition() + 1;
1996 [ <ASSIGN> expression = Expression()
1998 final String[] strings = new String[list.size()];
1999 list.toArray(strings);
2000 return new ListExpression(strings,
2003 SimpleCharStream.getPosition());}
2006 final String[] strings = new String[list.size()];
2007 list.toArray(strings);
2008 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
2012 * An echo statement.
2013 * echo anyexpression (, otherexpression)*
2015 EchoStatement EchoStatement() :
2017 final ArrayList expressions = new ArrayList();
2019 final int pos = SimpleCharStream.getPosition();
2022 <ECHO> expr = Expression()
2023 {expressions.add(expr);}
2025 <COMMA> expr = Expression()
2026 {expressions.add(expr);}
2030 } catch (ParseException e) {
2031 if (e.currentToken.next.kind != 4) {
2032 errorMessage = "';' expected after 'echo' statement";
2034 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2035 errorEnd = SimpleCharStream.getPosition() + 1;
2039 {final Expression[] exprs = new Expression[expressions.size()];
2040 expressions.toArray(exprs);
2041 return new EchoStatement(exprs,pos);}
2044 GlobalStatement GlobalStatement() :
2046 final int pos = SimpleCharStream.getPosition();
2048 final ArrayList vars = new ArrayList();
2049 final GlobalStatement global;
2053 expr = VariableDeclaratorId()
2056 expr = VariableDeclaratorId()
2062 final String[] strings = new String[vars.size()];
2063 vars.toArray(strings);
2064 global = new GlobalStatement(currentSegment,
2067 SimpleCharStream.getPosition());
2068 currentSegment.add(global);
2070 } catch (ParseException e) {
2071 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2073 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2074 errorEnd = SimpleCharStream.getPosition() + 1;
2079 StaticStatement StaticStatement() :
2081 final int pos = SimpleCharStream.getPosition();
2082 final ArrayList vars = new ArrayList();
2083 VariableDeclaration expr;
2086 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2087 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2091 final String[] strings = new String[vars.size()];
2092 vars.toArray(strings);
2093 return new StaticStatement(strings,
2095 SimpleCharStream.getPosition());}
2096 } catch (ParseException e) {
2097 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2099 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2100 errorEnd = SimpleCharStream.getPosition() + 1;
2105 LabeledStatement LabeledStatement() :
2107 final int pos = SimpleCharStream.getPosition();
2109 final Statement statement;
2112 label = <IDENTIFIER> <COLON> statement = Statement()
2113 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2125 final int pos = SimpleCharStream.getPosition();
2126 final ArrayList list = new ArrayList();
2127 Statement statement;
2132 } catch (ParseException e) {
2133 errorMessage = "'{' expected";
2135 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2136 errorEnd = SimpleCharStream.getPosition() + 1;
2139 ( statement = BlockStatement() {list.add(statement);}
2140 | statement = htmlBlock() {list.add(statement);})*
2143 } catch (ParseException e) {
2144 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2146 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2147 errorEnd = SimpleCharStream.getPosition() + 1;
2151 final Statement[] statements = new Statement[list.size()];
2152 list.toArray(statements);
2153 return new Block(statements,pos,SimpleCharStream.getPosition());}
2156 Statement BlockStatement() :
2158 final Statement statement;
2161 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2163 | statement = ClassDeclaration() {return statement;}
2164 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2165 currentSegment.add((MethodDeclaration) statement);
2170 * A Block statement that will not contain any 'break'
2172 Statement BlockStatementNoBreak() :
2174 final Statement statement;
2177 statement = StatementNoBreak() {return statement;}
2178 | statement = ClassDeclaration() {return statement;}
2179 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2183 VariableDeclaration[] LocalVariableDeclaration() :
2185 final ArrayList list = new ArrayList();
2186 VariableDeclaration var;
2189 var = LocalVariableDeclarator()
2191 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2193 final VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2198 VariableDeclaration LocalVariableDeclarator() :
2200 final String varName;
2201 Expression initializer = null;
2202 final int pos = SimpleCharStream.getPosition();
2205 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2207 if (initializer == null) {
2208 return new VariableDeclaration(currentSegment,
2209 varName.toCharArray(),
2211 SimpleCharStream.getPosition());
2213 return new VariableDeclaration(currentSegment,
2214 varName.toCharArray(),
2220 EmptyStatement EmptyStatement() :
2226 {pos = SimpleCharStream.getPosition();
2227 return new EmptyStatement(pos-1,pos);}
2230 Expression StatementExpression() :
2232 final Expression expr,expr2;
2236 expr = PreIncDecExpression() {return expr;}
2238 expr = PrimaryExpression()
2239 [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
2240 OperatorIds.PLUS_PLUS,
2241 SimpleCharStream.getPosition());}
2242 | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
2243 OperatorIds.MINUS_MINUS,
2244 SimpleCharStream.getPosition());}
2245 | operator = AssignmentOperator() expr2 = Expression()
2246 {return new BinaryExpression(expr,expr2,operator);}
2251 SwitchStatement SwitchStatement() :
2253 final Expression variable;
2254 final AbstractCase[] cases;
2255 final int pos = SimpleCharStream.getPosition();
2261 } catch (ParseException e) {
2262 errorMessage = "'(' expected after 'switch'";
2264 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2265 errorEnd = SimpleCharStream.getPosition() + 1;
2269 variable = Expression()
2270 } catch (ParseException e) {
2271 if (errorMessage != null) {
2274 errorMessage = "expression expected";
2276 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2277 errorEnd = SimpleCharStream.getPosition() + 1;
2282 } catch (ParseException e) {
2283 errorMessage = "')' expected";
2285 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2286 errorEnd = SimpleCharStream.getPosition() + 1;
2289 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2290 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2293 AbstractCase[] switchStatementBrace() :
2296 final ArrayList cases = new ArrayList();
2300 ( cas = switchLabel0() {cases.add(cas);})*
2304 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2305 cases.toArray(abcase);
2307 } catch (ParseException e) {
2308 errorMessage = "'}' expected";
2310 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2311 errorEnd = SimpleCharStream.getPosition() + 1;
2316 * A Switch statement with : ... endswitch;
2317 * @param start the begin offset of the switch
2318 * @param end the end offset of the switch
2320 AbstractCase[] switchStatementColon(final int start, final int end) :
2323 final ArrayList cases = new ArrayList();
2328 setMarker(fileToParse,
2329 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2333 "Line " + token.beginLine);
2334 } catch (CoreException e) {
2335 PHPeclipsePlugin.log(e);
2337 ( cas = switchLabel0() {cases.add(cas);})*
2340 } catch (ParseException e) {
2341 errorMessage = "'endswitch' expected";
2343 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2344 errorEnd = SimpleCharStream.getPosition() + 1;
2350 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2351 cases.toArray(abcase);
2353 } catch (ParseException e) {
2354 errorMessage = "';' expected after 'endswitch' keyword";
2356 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2357 errorEnd = SimpleCharStream.getPosition() + 1;
2362 AbstractCase switchLabel0() :
2364 final Expression expr;
2365 Statement statement;
2366 final ArrayList stmts = new ArrayList();
2367 final int pos = SimpleCharStream.getPosition();
2370 expr = SwitchLabel()
2371 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2372 | statement = htmlBlock() {stmts.add(statement);})*
2373 [ statement = BreakStatement() {stmts.add(statement);}]
2375 final Statement[] stmtsArray = new Statement[stmts.size()];
2376 stmts.toArray(stmtsArray);
2377 if (expr == null) {//it's a default
2378 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2380 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2385 * case Expression() :
2387 * @return the if it was a case and null if not
2389 Expression SwitchLabel() :
2391 final Expression expr;
2397 } catch (ParseException e) {
2398 if (errorMessage != null) throw e;
2399 errorMessage = "expression expected after 'case' keyword";
2401 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2402 errorEnd = SimpleCharStream.getPosition() + 1;
2408 } catch (ParseException e) {
2409 errorMessage = "':' expected after case expression";
2411 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2412 errorEnd = SimpleCharStream.getPosition() + 1;
2420 } catch (ParseException e) {
2421 errorMessage = "':' expected after 'default' keyword";
2423 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2424 errorEnd = SimpleCharStream.getPosition() + 1;
2429 Break BreakStatement() :
2431 Expression expression = null;
2432 final int start = SimpleCharStream.getPosition();
2435 <BREAK> [ expression = Expression() ]
2438 } catch (ParseException e) {
2439 errorMessage = "';' expected after 'break' keyword";
2441 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2442 errorEnd = SimpleCharStream.getPosition() + 1;
2445 {return new Break(expression, start, SimpleCharStream.getPosition());}
2448 IfStatement IfStatement() :
2450 final int pos = SimpleCharStream.getPosition();
2451 final Expression condition;
2452 final IfStatement ifStatement;
2455 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2456 {return ifStatement;}
2460 Expression Condition(final String keyword) :
2462 final Expression condition;
2467 } catch (ParseException e) {
2468 errorMessage = "'(' expected after " + keyword + " keyword";
2470 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2471 errorEnd = errorStart +1;
2472 processParseException(e);
2474 condition = Expression()
2477 } catch (ParseException e) {
2478 errorMessage = "')' expected after " + keyword + " keyword";
2480 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2481 errorEnd = SimpleCharStream.getPosition() + 1;
2482 processParseException(e);
2487 IfStatement IfStatement0(final Expression condition, final int start,final int end) :
2489 Statement statement;
2490 final Statement stmt;
2491 final Statement[] statementsArray;
2492 ElseIf elseifStatement;
2493 Else elseStatement = null;
2494 final ArrayList stmts;
2495 final ArrayList elseIfList = new ArrayList();
2496 final ElseIf[] elseIfs;
2497 int pos = SimpleCharStream.getPosition();
2498 final int endStatements;
2502 {stmts = new ArrayList();}
2503 ( statement = Statement() {stmts.add(statement);}
2504 | statement = htmlBlock() {stmts.add(statement);})*
2505 {endStatements = SimpleCharStream.getPosition();}
2506 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2507 [elseStatement = ElseStatementColon()]
2510 setMarker(fileToParse,
2511 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2515 "Line " + token.beginLine);
2516 } catch (CoreException e) {
2517 PHPeclipsePlugin.log(e);
2521 } catch (ParseException e) {
2522 errorMessage = "'endif' expected";
2524 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2525 errorEnd = SimpleCharStream.getPosition() + 1;
2530 } catch (ParseException e) {
2531 errorMessage = "';' expected after 'endif' keyword";
2533 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2534 errorEnd = SimpleCharStream.getPosition() + 1;
2538 elseIfs = new ElseIf[elseIfList.size()];
2539 elseIfList.toArray(elseIfs);
2540 if (stmts.size() == 1) {
2541 return new IfStatement(condition,
2542 (Statement) stmts.get(0),
2546 SimpleCharStream.getPosition());
2548 statementsArray = new Statement[stmts.size()];
2549 stmts.toArray(statementsArray);
2550 return new IfStatement(condition,
2551 new Block(statementsArray,pos,endStatements),
2555 SimpleCharStream.getPosition());
2560 (stmt = Statement() | stmt = htmlBlock())
2561 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2565 {pos = SimpleCharStream.getPosition();}
2566 statement = Statement()
2567 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2568 } catch (ParseException e) {
2569 if (errorMessage != null) {
2572 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2574 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2575 errorEnd = SimpleCharStream.getPosition() + 1;
2580 elseIfs = new ElseIf[elseIfList.size()];
2581 elseIfList.toArray(elseIfs);
2582 return new IfStatement(condition,
2587 SimpleCharStream.getPosition());}
2590 ElseIf ElseIfStatementColon() :
2592 final Expression condition;
2593 Statement statement;
2594 final ArrayList list = new ArrayList();
2595 final int pos = SimpleCharStream.getPosition();
2598 <ELSEIF> condition = Condition("elseif")
2599 <COLON> ( statement = Statement() {list.add(statement);}
2600 | statement = htmlBlock() {list.add(statement);})*
2602 final Statement[] stmtsArray = new Statement[list.size()];
2603 list.toArray(stmtsArray);
2604 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2607 Else ElseStatementColon() :
2609 Statement statement;
2610 final ArrayList list = new ArrayList();
2611 final int pos = SimpleCharStream.getPosition();
2614 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2615 | statement = htmlBlock() {list.add(statement);})*
2617 final Statement[] stmtsArray = new Statement[list.size()];
2618 list.toArray(stmtsArray);
2619 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2622 ElseIf ElseIfStatement() :
2624 final Expression condition;
2625 final Statement statement;
2626 final ArrayList list = new ArrayList();
2627 final int pos = SimpleCharStream.getPosition();
2630 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2632 final Statement[] stmtsArray = new Statement[list.size()];
2633 list.toArray(stmtsArray);
2634 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2637 WhileStatement WhileStatement() :
2639 final Expression condition;
2640 final Statement action;
2641 final int pos = SimpleCharStream.getPosition();
2645 condition = Condition("while")
2646 action = WhileStatement0(pos,pos + 5)
2647 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2650 Statement WhileStatement0(final int start, final int end) :
2652 Statement statement;
2653 final ArrayList stmts = new ArrayList();
2654 final int pos = SimpleCharStream.getPosition();
2657 <COLON> (statement = Statement() {stmts.add(statement);})*
2659 setMarker(fileToParse,
2660 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2664 "Line " + token.beginLine);
2665 } catch (CoreException e) {
2666 PHPeclipsePlugin.log(e);
2670 } catch (ParseException e) {
2671 errorMessage = "'endwhile' expected";
2673 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2674 errorEnd = SimpleCharStream.getPosition() + 1;
2680 final Statement[] stmtsArray = new Statement[stmts.size()];
2681 stmts.toArray(stmtsArray);
2682 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2683 } catch (ParseException e) {
2684 errorMessage = "';' expected after 'endwhile' keyword";
2686 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2687 errorEnd = SimpleCharStream.getPosition() + 1;
2691 statement = Statement()
2695 DoStatement DoStatement() :
2697 final Statement action;
2698 final Expression condition;
2699 final int pos = SimpleCharStream.getPosition();
2702 <DO> action = Statement() <WHILE> condition = Condition("while")
2705 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2706 } catch (ParseException e) {
2707 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2709 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2710 errorEnd = SimpleCharStream.getPosition() + 1;
2715 ForeachStatement ForeachStatement() :
2717 Statement statement;
2718 Expression expression;
2719 final int pos = SimpleCharStream.getPosition();
2720 ArrayVariableDeclaration variable;
2726 } catch (ParseException e) {
2727 errorMessage = "'(' expected after 'foreach' keyword";
2729 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2730 errorEnd = SimpleCharStream.getPosition() + 1;
2734 expression = Expression()
2735 } catch (ParseException e) {
2736 errorMessage = "variable expected";
2738 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2739 errorEnd = SimpleCharStream.getPosition() + 1;
2744 } catch (ParseException e) {
2745 errorMessage = "'as' expected";
2747 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2748 errorEnd = SimpleCharStream.getPosition() + 1;
2752 variable = ArrayVariable()
2753 } catch (ParseException e) {
2754 errorMessage = "variable expected";
2756 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2757 errorEnd = SimpleCharStream.getPosition() + 1;
2762 } catch (ParseException e) {
2763 errorMessage = "')' expected after 'foreach' keyword";
2765 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2766 errorEnd = SimpleCharStream.getPosition() + 1;
2770 statement = Statement()
2771 } catch (ParseException e) {
2772 if (errorMessage != null) throw e;
2773 errorMessage = "statement expected";
2775 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2776 errorEnd = SimpleCharStream.getPosition() + 1;
2779 {return new ForeachStatement(expression,
2783 SimpleCharStream.getPosition());}
2787 ForStatement ForStatement() :
2790 final int pos = SimpleCharStream.getPosition();
2791 Expression[] initializations = null;
2792 Expression condition = null;
2793 Expression[] increments = null;
2795 final ArrayList list = new ArrayList();
2796 final int startBlock, endBlock;
2802 } catch (ParseException e) {
2803 errorMessage = "'(' expected after 'for' keyword";
2805 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2806 errorEnd = SimpleCharStream.getPosition() + 1;
2809 [ initializations = ForInit() ] <SEMICOLON>
2810 [ condition = Expression() ] <SEMICOLON>
2811 [ increments = StatementExpressionList() ] <RPAREN>
2813 action = Statement()
2814 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2817 {startBlock = SimpleCharStream.getPosition();}
2818 (action = Statement() {list.add(action);})*
2821 setMarker(fileToParse,
2822 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2824 pos+token.image.length(),
2826 "Line " + token.beginLine);
2827 } catch (CoreException e) {
2828 PHPeclipsePlugin.log(e);
2831 {endBlock = SimpleCharStream.getPosition();}
2834 } catch (ParseException e) {
2835 errorMessage = "'endfor' expected";
2837 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2838 errorEnd = SimpleCharStream.getPosition() + 1;
2844 final Statement[] stmtsArray = new Statement[list.size()];
2845 list.toArray(stmtsArray);
2846 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2847 } catch (ParseException e) {
2848 errorMessage = "';' expected after 'endfor' keyword";
2850 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2851 errorEnd = SimpleCharStream.getPosition() + 1;
2857 Expression[] ForInit() :
2859 final Expression[] exprs;
2862 LOOKAHEAD(LocalVariableDeclaration())
2863 exprs = LocalVariableDeclaration()
2866 exprs = StatementExpressionList()
2870 Expression[] StatementExpressionList() :
2872 final ArrayList list = new ArrayList();
2873 final Expression expr;
2876 expr = StatementExpression() {list.add(expr);}
2877 (<COMMA> StatementExpression() {list.add(expr);})*
2879 final Expression[] exprsArray = new Expression[list.size()];
2880 list.toArray(exprsArray);
2884 Continue ContinueStatement() :
2886 Expression expr = null;
2887 final int pos = SimpleCharStream.getPosition();
2890 <CONTINUE> [ expr = Expression() ]
2893 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2894 } catch (ParseException e) {
2895 errorMessage = "';' expected after 'continue' statement";
2897 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2898 errorEnd = SimpleCharStream.getPosition() + 1;
2903 ReturnStatement ReturnStatement() :
2905 Expression expr = null;
2906 final int pos = SimpleCharStream.getPosition();
2909 <RETURN> [ expr = Expression() ]
2912 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2913 } catch (ParseException e) {
2914 errorMessage = "';' expected after 'return' statement";
2916 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2917 errorEnd = SimpleCharStream.getPosition() + 1;