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
51 public final class PHPParser extends PHPParserSuperclass {
53 /** The current segment. */
54 private static OutlineableWithChildren currentSegment;
56 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
57 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
58 static PHPOutlineInfo outlineInfo;
60 /** The error level of the current ParseException. */
61 private static int errorLevel = ERROR;
62 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
63 private static String errorMessage;
65 private static int errorStart = -1;
66 private static int errorEnd = -1;
67 private static PHPDocument phpDocument;
69 private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
71 * The point where html starts.
72 * It will be used by the token manager to create HTMLCode objects
74 public static int htmlStart;
77 private final static int AstStackIncrement = 100;
78 /** The stack of node. */
79 private static AstNode[] nodes;
80 /** The cursor in expression stack. */
81 private static int nodePtr;
83 private static final boolean PARSER_DEBUG = false;
85 public final void setFileToParse(final IFile fileToParse) {
86 PHPParser.fileToParse = fileToParse;
92 public PHPParser(final IFile fileToParse) {
93 this(new StringReader(""));
94 PHPParser.fileToParse = fileToParse;
98 * Reinitialize the parser.
100 private static final void init() {
101 nodes = new AstNode[AstStackIncrement];
107 * Add an php node on the stack.
108 * @param node the node that will be added to the stack
110 private static final void pushOnAstNodes(final AstNode node) {
112 nodes[++nodePtr] = node;
113 } catch (IndexOutOfBoundsException e) {
114 final int oldStackLength = nodes.length;
115 final AstNode[] oldStack = nodes;
116 nodes = new AstNode[oldStackLength + AstStackIncrement];
117 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
118 nodePtr = oldStackLength;
119 nodes[nodePtr] = node;
123 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
124 phpDocument = new PHPDocument(parent,"_root".toCharArray());
125 currentSegment = phpDocument;
126 outlineInfo = new PHPOutlineInfo(parent, currentSegment);
127 final StringReader stream = new StringReader(s);
128 if (jj_input_stream == null) {
129 jj_input_stream = new SimpleCharStream(stream, 1, 1);
135 phpDocument.nodes = new AstNode[nodes.length];
136 System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
137 if (PHPeclipsePlugin.DEBUG) {
138 PHPeclipsePlugin.log(1,phpDocument.toString());
140 } catch (ParseException e) {
141 processParseException(e);
147 * This method will process the parse exception.
148 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
149 * @param e the ParseException
151 private static void processParseException(final ParseException e) {
156 if (errorMessage == null) {
157 PHPeclipsePlugin.log(e);
158 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
159 errorStart = SimpleCharStream.getPosition();
160 errorEnd = errorStart + 1;
164 // if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e);
168 * Create marker for the parse error.
169 * @param e the ParseException
171 private static void setMarker(final ParseException e) {
173 if (errorStart == -1) {
174 setMarker(fileToParse,
176 SimpleCharStream.tokenBegin,
177 SimpleCharStream.tokenBegin + e.currentToken.image.length(),
179 "Line " + e.currentToken.beginLine);
181 setMarker(fileToParse,
186 "Line " + e.currentToken.beginLine);
190 } catch (CoreException e2) {
191 PHPeclipsePlugin.log(e2);
195 private static void scanLine(final String output,
198 final int brIndx) throws CoreException {
200 final StringBuffer lineNumberBuffer = new StringBuffer(10);
202 current = output.substring(indx, brIndx);
204 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
205 final int onLine = current.indexOf("on line <b>");
207 lineNumberBuffer.delete(0, lineNumberBuffer.length());
208 for (int i = onLine; i < current.length(); i++) {
209 ch = current.charAt(i);
210 if ('0' <= ch && '9' >= ch) {
211 lineNumberBuffer.append(ch);
215 final int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
217 final Hashtable attributes = new Hashtable();
219 current = current.replaceAll("\n", "");
220 current = current.replaceAll("<b>", "");
221 current = current.replaceAll("</b>", "");
222 MarkerUtilities.setMessage(attributes, current);
224 if (current.indexOf(PARSE_ERROR_STRING) != -1)
225 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
226 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
227 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
229 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
230 MarkerUtilities.setLineNumber(attributes, lineNumber);
231 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
236 public final void parse(final String s) throws CoreException {
237 final StringReader stream = new StringReader(s);
238 if (jj_input_stream == null) {
239 jj_input_stream = new SimpleCharStream(stream, 1, 1);
245 } catch (ParseException e) {
246 processParseException(e);
251 * Call the php parse command ( php -l -f <filename> )
252 * and create markers according to the external parser output
254 public static void phpExternalParse(final IFile file) {
255 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
256 final String filename = file.getLocation().toString();
258 final String[] arguments = { filename };
259 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
260 final String command = form.format(arguments);
262 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
265 // parse the buffer to find the errors and warnings
266 createMarkers(parserResult, file);
267 } catch (CoreException e) {
268 PHPeclipsePlugin.log(e);
273 * Put a new html block in the stack.
275 public static final void createNewHTMLCode() {
276 final int currentPosition = SimpleCharStream.getPosition();
277 if (currentPosition == htmlStart || currentPosition > SimpleCharStream.currentBuffer.length()) {
280 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
281 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
284 /** Create a new task. */
285 public static final void createNewTask() {
286 final int currentPosition = SimpleCharStream.getPosition();
287 final String todo = SimpleCharStream.currentBuffer.substring(currentPosition-3,
288 SimpleCharStream.currentBuffer.indexOf("\n",
290 PHPeclipsePlugin.log(1,SimpleCharStream.currentBuffer.toString());
292 setMarker(fileToParse,
294 SimpleCharStream.getBeginLine(),
296 "Line "+SimpleCharStream.getBeginLine());
297 } catch (CoreException e) {
298 PHPeclipsePlugin.log(e);
302 private static final void parse() throws ParseException {
307 PARSER_END(PHPParser)
311 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
312 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
313 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
318 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
321 /* Skip any character if we are not in php mode */
339 <PHPPARSING> SPECIAL_TOKEN :
341 "//" : IN_SINGLE_LINE_COMMENT
342 | "#" : IN_SINGLE_LINE_COMMENT
343 | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
344 | "/*" : IN_MULTI_LINE_COMMENT
347 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
349 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
353 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
355 "todo" {PHPParser.createNewTask();}
358 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
363 <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
368 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
378 | <FUNCTION : "function">
381 | <ELSEIF : "elseif">
388 /* LANGUAGE CONSTRUCT */
393 | <INCLUDE : "include">
394 | <REQUIRE : "require">
395 | <INCLUDE_ONCE : "include_once">
396 | <REQUIRE_ONCE : "require_once">
397 | <GLOBAL : "global">
398 | <DEFINE : "define">
399 | <STATIC : "static">
400 | <CLASSACCESS : "->">
401 | <STATICCLASSACCESS : "::">
402 | <ARRAYASSIGN : "=>">
405 /* RESERVED WORDS AND LITERALS */
411 | <CONTINUE : "continue">
412 | <_DEFAULT : "default">
414 | <EXTENDS : "extends">
419 | <RETURN : "return">
421 | <SWITCH : "switch">
426 | <ENDWHILE : "endwhile">
427 | <ENDSWITCH: "endswitch">
429 | <ENDFOR : "endfor">
430 | <FOREACH : "foreach">
438 | <OBJECT : "object">
440 | <BOOLEAN : "boolean">
442 | <DOUBLE : "double">
445 | <INTEGER : "integer">
465 | <MINUS_MINUS : "--">
475 | <RSIGNEDSHIFT : ">>">
476 | <RUNSIGNEDSHIFT : ">>>">
485 <DECIMAL_LITERAL> (["l","L"])?
486 | <HEX_LITERAL> (["l","L"])?
487 | <OCTAL_LITERAL> (["l","L"])?
490 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
492 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
494 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
496 <FLOATING_POINT_LITERAL:
497 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
498 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
499 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
500 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
503 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
505 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
506 | <STRING_1: "\"" ( ~["\"","\\"] | "\\" ~[] )* "\"">
507 | <STRING_2: "'" ( ~["'","\\"] | "\\" ~[] )* "'">
508 | <STRING_3: "`" ( ~["`","\\"] | "\\" ~[] )* "`">
515 <IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
518 ["a"-"z"] | ["A"-"Z"]
526 "_" | ["\u007f"-"\u00ff"]
551 | <EQUAL_EQUAL : "==">
556 | <BANGDOUBLEEQUAL : "!==">
557 | <TRIPLEEQUAL : "===">
564 | <PLUSASSIGN : "+=">
565 | <MINUSASSIGN : "-=">
566 | <STARASSIGN : "*=">
567 | <SLASHASSIGN : "/=">
573 | <TILDEEQUAL : "~=">
574 | <LSHIFTASSIGN : "<<=">
575 | <RSIGNEDSHIFTASSIGN : ">>=">
580 <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
588 {PHPParser.createNewHTMLCode();}
589 } catch (TokenMgrError e) {
590 PHPeclipsePlugin.log(e);
591 errorStart = SimpleCharStream.getPosition();
592 errorEnd = errorStart + 1;
593 errorMessage = e.getMessage();
595 throw generateParseException();
600 * A php block is a <?= expression [;]?>
601 * or <?php somephpcode ?>
602 * or <? somephpcode ?>
606 final int start = SimpleCharStream.getPosition();
607 final PHPEchoBlock phpEchoBlock;
610 phpEchoBlock = phpEchoBlock()
611 {pushOnAstNodes(phpEchoBlock);}
616 setMarker(fileToParse,
617 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
619 SimpleCharStream.getPosition(),
621 "Line " + token.beginLine);
622 } catch (CoreException e) {
623 PHPeclipsePlugin.log(e);
629 } catch (ParseException e) {
630 errorMessage = "'?>' expected";
632 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
633 errorEnd = SimpleCharStream.getPosition() + 1;
634 processParseException(e);
638 PHPEchoBlock phpEchoBlock() :
640 final Expression expr;
641 final int pos = SimpleCharStream.getPosition();
642 final PHPEchoBlock echoBlock;
645 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
647 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
648 pushOnAstNodes(echoBlock);
658 ClassDeclaration ClassDeclaration() :
660 final ClassDeclaration classDeclaration;
661 final Token className,superclassName;
663 char[] classNameImage = SYNTAX_ERROR_CHAR;
664 char[] superclassNameImage = null;
668 {pos = SimpleCharStream.getPosition();}
670 className = <IDENTIFIER>
671 {classNameImage = className.image.toCharArray();}
672 } catch (ParseException e) {
673 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
675 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
676 errorEnd = SimpleCharStream.getPosition() + 1;
677 processParseException(e);
682 superclassName = <IDENTIFIER>
683 {superclassNameImage = superclassName.image.toCharArray();}
684 } catch (ParseException e) {
685 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
687 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
688 errorEnd = SimpleCharStream.getPosition() + 1;
689 processParseException(e);
690 superclassNameImage = SYNTAX_ERROR_CHAR;
694 if (superclassNameImage == null) {
695 classDeclaration = new ClassDeclaration(currentSegment,
700 classDeclaration = new ClassDeclaration(currentSegment,
706 currentSegment.add(classDeclaration);
707 currentSegment = classDeclaration;
709 ClassBody(classDeclaration)
710 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
711 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
712 pushOnAstNodes(classDeclaration);
713 return classDeclaration;}
716 void ClassBody(final ClassDeclaration classDeclaration) :
721 } catch (ParseException e) {
722 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected";
724 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
725 errorEnd = SimpleCharStream.getPosition() + 1;
726 processParseException(e);
728 ( ClassBodyDeclaration(classDeclaration) )*
731 } catch (ParseException e) {
732 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected";
734 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
735 errorEnd = SimpleCharStream.getPosition() + 1;
736 processParseException(e);
741 * A class can contain only methods and fields.
743 void ClassBodyDeclaration(final ClassDeclaration classDeclaration) :
745 final MethodDeclaration method;
746 final FieldDeclaration field;
749 method = MethodDeclaration() {method.analyzeCode();
750 classDeclaration.addMethod(method);}
751 | field = FieldDeclaration() {classDeclaration.addField(field);}
755 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
756 * it is only used by ClassBodyDeclaration()
758 FieldDeclaration FieldDeclaration() :
760 VariableDeclaration variableDeclaration;
761 final VariableDeclaration[] list;
762 final ArrayList arrayList = new ArrayList();
763 final int pos = SimpleCharStream.getPosition();
766 <VAR> variableDeclaration = VariableDeclaratorNoSuffix()
767 {arrayList.add(variableDeclaration);
768 outlineInfo.addVariable(new String(variableDeclaration.name()));}
770 <COMMA> variableDeclaration = VariableDeclaratorNoSuffix()
771 {arrayList.add(variableDeclaration);
772 outlineInfo.addVariable(new String(variableDeclaration.name()));}
776 } catch (ParseException e) {
777 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
779 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
780 errorEnd = SimpleCharStream.getPosition() + 1;
781 processParseException(e);
784 {list = new VariableDeclaration[arrayList.size()];
785 arrayList.toArray(list);
786 return new FieldDeclaration(list,
788 SimpleCharStream.getPosition(),
793 * a strict variable declarator : there cannot be a suffix here.
795 VariableDeclaration VariableDeclaratorNoSuffix() :
798 Expression initializer = null;
799 final int pos = SimpleCharStream.getPosition();
802 varName = <DOLLAR_ID>
806 initializer = VariableInitializer()
807 } catch (ParseException e) {
808 errorMessage = "Literal expression expected in variable initializer";
810 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
811 errorEnd = SimpleCharStream.getPosition() + 1;
812 processParseException(e);
816 if (initializer == null) {
817 return new VariableDeclaration(currentSegment,
818 new Variable(varName.image.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
820 SimpleCharStream.getPosition());
822 return new VariableDeclaration(currentSegment,
823 new Variable(varName.image.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
825 VariableDeclaration.EQUAL,
830 VariableDeclaration VariableDeclarator() :
832 final String varName;
833 Expression initializer = null;
834 final int pos = SimpleCharStream.getPosition();
837 varName = VariableDeclaratorId()
841 initializer = VariableInitializer()
842 } catch (ParseException e) {
843 errorMessage = "Literal expression expected in variable initializer";
845 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
846 errorEnd = SimpleCharStream.getPosition() + 1;
847 processParseException(e);
851 if (initializer == null) {
852 return new VariableDeclaration(currentSegment,
853 new Variable(varName.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.length()-1,SimpleCharStream.getPosition()),
855 SimpleCharStream.getPosition());
857 return new VariableDeclaration(currentSegment,
858 new Variable(varName.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.length()-1,SimpleCharStream.getPosition()),
860 VariableDeclaration.EQUAL,
867 * @return the variable name (with suffix)
869 String VariableDeclaratorId() :
872 Expression expression = null;
873 final int pos = SimpleCharStream.getPosition();
874 ConstantIdentifier ex;
881 {ex = new ConstantIdentifier(var.toCharArray(),
883 SimpleCharStream.getPosition());}
884 expression = VariableSuffix(ex)
887 if (expression == null) {
890 return expression.toStringExpression();
892 } catch (ParseException e) {
893 errorMessage = "'$' expected for variable identifier";
895 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
896 errorEnd = SimpleCharStream.getPosition() + 1;
902 * Return a variablename without the $.
903 * @return a variable name
907 final StringBuffer buff;
908 Expression expression = null;
913 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
915 if (expression == null) {
916 return token.image.substring(1);
918 buff = new StringBuffer(token.image);
920 buff.append(expression.toStringExpression());
922 return buff.toString();
925 <DOLLAR> expr = VariableName()
930 * A Variable name (without the $)
931 * @return a variable name String
933 String VariableName():
935 final StringBuffer buff;
937 Expression expression = null;
941 <LBRACE> expression = Expression() <RBRACE>
942 {buff = new StringBuffer("{");
943 buff.append(expression.toStringExpression());
945 return buff.toString();}
947 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
949 if (expression == null) {
952 buff = new StringBuffer(token.image);
954 buff.append(expression.toStringExpression());
956 return buff.toString();
959 <DOLLAR> expr = VariableName()
961 buff = new StringBuffer("$");
963 return buff.toString();
966 token = <DOLLAR_ID> {return token.image;}
969 Expression VariableInitializer() :
971 final Expression expr;
973 final int pos = SimpleCharStream.getPosition();
979 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
980 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
982 SimpleCharStream.getPosition()),
986 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
987 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
989 SimpleCharStream.getPosition()),
993 expr = ArrayDeclarator()
997 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
1000 ArrayVariableDeclaration ArrayVariable() :
1002 final Expression expr,expr2;
1007 <ARRAYASSIGN> expr2 = Expression()
1008 {return new ArrayVariableDeclaration(expr,expr2);}
1010 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
1013 ArrayVariableDeclaration[] ArrayInitializer() :
1015 ArrayVariableDeclaration expr;
1016 final ArrayList list = new ArrayList();
1021 expr = ArrayVariable()
1023 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
1028 <COMMA> {list.add(null);}
1032 final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
1038 * A Method Declaration.
1039 * <b>function</b> MetodDeclarator() Block()
1041 MethodDeclaration MethodDeclaration() :
1043 final MethodDeclaration functionDeclaration;
1045 final OutlineableWithChildren seg = currentSegment;
1050 functionDeclaration = MethodDeclarator()
1051 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1052 } catch (ParseException e) {
1053 if (errorMessage != null) throw e;
1054 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1056 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1057 errorEnd = SimpleCharStream.getPosition() + 1;
1060 {currentSegment = functionDeclaration;}
1062 {functionDeclaration.statements = block.statements;
1063 currentSegment = seg;
1064 return functionDeclaration;}
1068 * A MethodDeclarator.
1069 * [&] IDENTIFIER(parameters ...).
1070 * @return a function description for the outline
1072 MethodDeclaration MethodDeclarator() :
1074 final Token identifier;
1075 Token reference = null;
1076 final Hashtable formalParameters;
1077 final int pos = SimpleCharStream.getPosition();
1078 char[] identifierChar = SYNTAX_ERROR_CHAR;
1081 [reference = <BIT_AND>]
1083 identifier = <IDENTIFIER>
1084 {identifierChar = identifier.image.toCharArray();}
1085 } catch (ParseException e) {
1086 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1088 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1089 errorEnd = SimpleCharStream.getPosition() + 1;
1090 processParseException(e);
1092 formalParameters = FormalParameters()
1093 {MethodDeclaration method = new MethodDeclaration(currentSegment,
1098 SimpleCharStream.getPosition());
1103 * FormalParameters follows method identifier.
1104 * (FormalParameter())
1106 Hashtable FormalParameters() :
1108 VariableDeclaration var;
1109 final Hashtable parameters = new Hashtable();
1114 } catch (ParseException e) {
1115 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1117 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1118 errorEnd = SimpleCharStream.getPosition() + 1;
1119 processParseException(e);
1122 var = FormalParameter()
1123 {parameters.put(new String(var.name()),var);}
1125 <COMMA> var = FormalParameter()
1126 {parameters.put(new String(var.name()),var);}
1131 } catch (ParseException e) {
1132 errorMessage = "')' expected";
1134 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1135 errorEnd = SimpleCharStream.getPosition() + 1;
1136 processParseException(e);
1138 {return parameters;}
1142 * A formal parameter.
1143 * $varname[=value] (,$varname[=value])
1145 VariableDeclaration FormalParameter() :
1147 final VariableDeclaration variableDeclaration;
1151 [token = <BIT_AND>] variableDeclaration = VariableDeclaratorNoSuffix()
1153 if (token != null) {
1154 variableDeclaration.setReference(true);
1156 return variableDeclaration;}
1159 ConstantIdentifier Type() :
1162 <STRING> {pos = SimpleCharStream.getPosition();
1163 return new ConstantIdentifier(Types.STRING,pos,pos-6);}
1164 | <BOOL> {pos = SimpleCharStream.getPosition();
1165 return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
1166 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1167 return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
1168 | <REAL> {pos = SimpleCharStream.getPosition();
1169 return new ConstantIdentifier(Types.REAL,pos,pos-4);}
1170 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1171 return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
1172 | <FLOAT> {pos = SimpleCharStream.getPosition();
1173 return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
1174 | <INT> {pos = SimpleCharStream.getPosition();
1175 return new ConstantIdentifier(Types.INT,pos,pos-3);}
1176 | <INTEGER> {pos = SimpleCharStream.getPosition();
1177 return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
1178 | <OBJECT> {pos = SimpleCharStream.getPosition();
1179 return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
1182 Expression Expression() :
1184 final Expression expr;
1185 Expression initializer = null;
1186 final int pos = SimpleCharStream.getPosition();
1187 int assignOperator = -1;
1191 expr = ConditionalExpression()
1193 assignOperator = AssignmentOperator()
1195 initializer = ConditionalExpression()
1196 } catch (ParseException e) {
1197 if (errorMessage != null) {
1200 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1202 errorEnd = SimpleCharStream.getPosition();
1207 char[] varName = expr.toStringExpression().substring(1).toCharArray();
1208 if (assignOperator == -1) {
1209 return new VariableDeclaration(currentSegment,
1210 new Variable(varName,SimpleCharStream.getPosition()-varName.length-1,SimpleCharStream.getPosition()),
1212 SimpleCharStream.getPosition());
1215 return new VariableDeclaration(currentSegment,
1216 new Variable(varName,SimpleCharStream.getPosition()-varName.length-1,SimpleCharStream.getPosition()),
1222 | expr = ExpressionWBang() {return expr;}
1225 Expression ExpressionWBang() :
1227 final Expression expr;
1228 final int pos = SimpleCharStream.getPosition();
1231 <BANG> expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1232 | expr = ExpressionNoBang() {return expr;}
1235 Expression ExpressionNoBang() :
1237 Expression expr = null;
1238 int assignOperator = -1;
1240 final int pos = SimpleCharStream.getPosition();
1243 expr = PrintExpression() {return expr;}
1244 | expr = ListExpression() {return expr;}
1248 * Any assignement operator.
1249 * @return the assignement operator id
1251 int AssignmentOperator() :
1254 <ASSIGN> {return VariableDeclaration.EQUAL;}
1255 | <STARASSIGN> {return VariableDeclaration.STAR_EQUAL;}
1256 | <SLASHASSIGN> {return VariableDeclaration.SLASH_EQUAL;}
1257 | <REMASSIGN> {return VariableDeclaration.REM_EQUAL;}
1258 | <PLUSASSIGN> {return VariableDeclaration.PLUS_EQUAL;}
1259 | <MINUSASSIGN> {return VariableDeclaration.MINUS_EQUAL;}
1260 | <LSHIFTASSIGN> {return VariableDeclaration.LSHIFT_EQUAL;}
1261 | <RSIGNEDSHIFTASSIGN> {return VariableDeclaration.RSIGNEDSHIFT_EQUAL;}
1262 | <ANDASSIGN> {return VariableDeclaration.AND_EQUAL;}
1263 | <XORASSIGN> {return VariableDeclaration.XOR_EQUAL;}
1264 | <ORASSIGN> {return VariableDeclaration.OR_EQUAL;}
1265 | <DOTASSIGN> {return VariableDeclaration.DOT_EQUAL;}
1266 | <TILDEEQUAL> {return VariableDeclaration.TILDE_EQUAL;}
1269 Expression ConditionalExpression() :
1271 final Expression expr;
1272 Expression expr2 = null;
1273 Expression expr3 = null;
1276 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1278 if (expr3 == null) {
1281 return new ConditionalExpression(expr,expr2,expr3);
1285 Expression ConditionalOrExpression() :
1287 Expression expr,expr2;
1291 expr = ConditionalAndExpression()
1294 <OR_OR> {operator = OperatorIds.OR_OR;}
1295 | <_ORL> {operator = OperatorIds.ORL;}
1297 expr2 = ConditionalAndExpression()
1299 expr = new BinaryExpression(expr,expr2,operator);
1305 Expression ConditionalAndExpression() :
1307 Expression expr,expr2;
1311 expr = ConcatExpression()
1313 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1314 | <_ANDL> {operator = OperatorIds.ANDL;})
1315 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1320 Expression ConcatExpression() :
1322 Expression expr,expr2;
1325 expr = InclusiveOrExpression()
1327 <DOT> expr2 = InclusiveOrExpression()
1328 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1333 Expression InclusiveOrExpression() :
1335 Expression expr,expr2;
1338 expr = ExclusiveOrExpression()
1339 (<BIT_OR> expr2 = ExclusiveOrExpression()
1340 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1345 Expression ExclusiveOrExpression() :
1347 Expression expr,expr2;
1350 expr = AndExpression()
1352 <XOR> expr2 = AndExpression()
1353 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1358 Expression AndExpression() :
1360 Expression expr,expr2;
1363 expr = EqualityExpression()
1366 <BIT_AND> expr2 = EqualityExpression()
1367 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1372 Expression EqualityExpression() :
1374 Expression expr,expr2;
1378 expr = RelationalExpression()
1380 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1381 | <DIF> {operator = OperatorIds.DIF;}
1382 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1383 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1384 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1387 expr2 = RelationalExpression()
1388 } catch (ParseException e) {
1389 if (errorMessage != null) {
1392 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1394 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1395 errorEnd = SimpleCharStream.getPosition() + 1;
1399 expr = new BinaryExpression(expr,expr2,operator);
1405 Expression RelationalExpression() :
1407 Expression expr,expr2;
1411 expr = ShiftExpression()
1413 ( <LT> {operator = OperatorIds.LESS;}
1414 | <GT> {operator = OperatorIds.GREATER;}
1415 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1416 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1417 expr2 = ShiftExpression()
1418 {expr = new BinaryExpression(expr,expr2,operator);}
1423 Expression ShiftExpression() :
1425 Expression expr,expr2;
1429 expr = AdditiveExpression()
1431 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1432 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1433 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1434 expr2 = AdditiveExpression()
1435 {expr = new BinaryExpression(expr,expr2,operator);}
1440 Expression AdditiveExpression() :
1442 Expression expr,expr2;
1446 expr = MultiplicativeExpression()
1449 ( <PLUS> {operator = OperatorIds.PLUS;}
1450 | <MINUS> {operator = OperatorIds.MINUS;} )
1451 expr2 = MultiplicativeExpression()
1452 {expr = new BinaryExpression(expr,expr2,operator);}
1457 Expression MultiplicativeExpression() :
1459 Expression expr,expr2;
1464 expr = UnaryExpression()
1465 } catch (ParseException e) {
1466 if (errorMessage != null) throw e;
1467 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1469 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1470 errorEnd = SimpleCharStream.getPosition() + 1;
1474 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1475 | <SLASH> {operator = OperatorIds.DIVIDE;}
1476 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1477 expr2 = UnaryExpression()
1478 {expr = new BinaryExpression(expr,expr2,operator);}
1484 * An unary expression starting with @, & or nothing
1486 Expression UnaryExpression() :
1488 final Expression expr;
1489 final int pos = SimpleCharStream.getPosition();
1492 <BIT_AND> expr = UnaryExpressionNoPrefix()
1493 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1495 expr = AtUnaryExpression() {return expr;}
1498 Expression AtUnaryExpression() :
1500 final Expression expr;
1501 final int pos = SimpleCharStream.getPosition();
1505 expr = AtUnaryExpression()
1506 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1508 expr = UnaryExpressionNoPrefix()
1513 Expression UnaryExpressionNoPrefix() :
1515 final Expression expr;
1517 final int pos = SimpleCharStream.getPosition();
1521 <PLUS> {operator = OperatorIds.PLUS;}
1523 <MINUS> {operator = OperatorIds.MINUS;}
1525 expr = UnaryExpression()
1526 {return new PrefixedUnaryExpression(expr,operator,pos);}
1528 expr = PreIncDecExpression()
1531 expr = UnaryExpressionNotPlusMinus()
1536 Expression PreIncDecExpression() :
1538 final Expression expr;
1540 final int pos = SimpleCharStream.getPosition();
1544 <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1546 <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}
1548 expr = PrimaryExpression()
1549 {return new PrefixedUnaryExpression(expr,operator,pos);}
1552 Expression UnaryExpressionNotPlusMinus() :
1554 final Expression expr;
1555 final int pos = SimpleCharStream.getPosition();
1558 LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1559 expr = CastExpression() {return expr;}
1560 | expr = PostfixExpression() {return expr;}
1561 | expr = Literal() {return expr;}
1562 | <LPAREN> expr = Expression()
1565 } catch (ParseException e) {
1566 errorMessage = "')' expected";
1568 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1569 errorEnd = SimpleCharStream.getPosition() + 1;
1575 CastExpression CastExpression() :
1577 final ConstantIdentifier type;
1578 final Expression expr;
1579 final int pos = SimpleCharStream.getPosition();
1586 <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());}
1588 <RPAREN> expr = UnaryExpression()
1589 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1592 Expression PostfixExpression() :
1594 final Expression expr;
1596 final int pos = SimpleCharStream.getPosition();
1599 expr = PrimaryExpression()
1601 <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1603 <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}
1606 if (operator == -1) {
1609 return new PostfixedUnaryExpression(expr,operator,pos);
1613 Expression PrimaryExpression() :
1616 int assignOperator = -1;
1617 final Token identifier;
1619 final int pos = SimpleCharStream.getPosition();
1622 expr = PrimaryPrefix()
1623 (expr = PrimarySuffix(expr))*
1624 [ expr = Arguments(expr) ]
1627 <NEW> expr = ClassIdentifier()
1628 {expr = new PrefixedUnaryExpression(expr,
1632 [ expr = Arguments(expr) ]
1635 expr = ArrayDeclarator()
1639 Expression PrimaryPrefix() :
1641 final Expression expr;
1644 final int pos = SimpleCharStream.getPosition();
1647 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1649 SimpleCharStream.getPosition());}
1651 var = VariableDeclaratorId() {return new Variable(var.toCharArray(),
1653 SimpleCharStream.getPosition());}
1656 AbstractSuffixExpression PrimarySuffix(final Expression prefix) :
1658 final AbstractSuffixExpression suffix;
1659 final Expression expr;
1662 suffix = VariableSuffix(prefix) {return suffix;}
1663 | <STATICCLASSACCESS> expr = ClassIdentifier()
1664 {suffix = new ClassAccess(prefix,
1666 ClassAccess.STATIC);
1671 * An array declarator.
1675 ArrayInitializer ArrayDeclarator() :
1677 final ArrayVariableDeclaration[] vars;
1678 final int pos = SimpleCharStream.getPosition();
1681 <ARRAY> vars = ArrayInitializer()
1682 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1685 PrefixedUnaryExpression classInstantiation() :
1688 final StringBuffer buff;
1689 final int pos = SimpleCharStream.getPosition();
1692 <NEW> expr = ClassIdentifier()
1694 {buff = new StringBuffer(expr.toStringExpression());}
1695 expr = PrimaryExpression()
1696 {buff.append(expr.toStringExpression());
1697 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1699 SimpleCharStream.getPosition());}
1701 {return new PrefixedUnaryExpression(expr,
1706 ConstantIdentifier ClassIdentifier():
1710 final int pos = SimpleCharStream.getPosition();
1711 final ConstantIdentifier type;
1714 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1716 SimpleCharStream.getPosition());}
1717 | type = Type() {return type;}
1718 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1720 SimpleCharStream.getPosition());}
1723 AbstractSuffixExpression VariableSuffix(final Expression prefix) :
1726 final int pos = SimpleCharStream.getPosition();
1727 Expression expression = null;
1732 expr = VariableName()
1733 } catch (ParseException e) {
1734 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1736 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1737 errorEnd = SimpleCharStream.getPosition() + 1;
1740 {return new ClassAccess(prefix,
1741 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1742 ClassAccess.NORMAL);}
1744 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1747 } catch (ParseException e) {
1748 errorMessage = "']' expected";
1750 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1751 errorEnd = SimpleCharStream.getPosition() + 1;
1754 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1763 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1764 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1765 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1766 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1767 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1768 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1769 | <TRUE> {pos = SimpleCharStream.getPosition();
1770 return new TrueLiteral(pos-4,pos);}
1771 | <FALSE> {pos = SimpleCharStream.getPosition();
1772 return new FalseLiteral(pos-4,pos);}
1773 | <NULL> {pos = SimpleCharStream.getPosition();
1774 return new NullLiteral(pos-4,pos);}
1777 FunctionCall Arguments(final Expression func) :
1779 Expression[] args = null;
1782 <LPAREN> [ args = ArgumentList() ]
1785 } catch (ParseException e) {
1786 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1788 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1789 errorEnd = SimpleCharStream.getPosition() + 1;
1792 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1796 * An argument list is a list of arguments separated by comma :
1797 * argumentDeclaration() (, argumentDeclaration)*
1798 * @return an array of arguments
1800 Expression[] ArgumentList() :
1803 final ArrayList list = new ArrayList();
1812 } catch (ParseException e) {
1813 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1815 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1816 errorEnd = SimpleCharStream.getPosition() + 1;
1821 final Expression[] arguments = new Expression[list.size()];
1822 list.toArray(arguments);
1827 * A Statement without break.
1828 * @return a statement
1830 Statement StatementNoBreak() :
1832 final Statement statement;
1837 statement = expressionStatement() {return statement;}
1839 statement = LabeledStatement() {return statement;}
1840 | statement = Block() {return statement;}
1841 | statement = EmptyStatement() {return statement;}
1842 | statement = SwitchStatement() {return statement;}
1843 | statement = IfStatement() {return statement;}
1844 | statement = WhileStatement() {return statement;}
1845 | statement = DoStatement() {return statement;}
1846 | statement = ForStatement() {return statement;}
1847 | statement = ForeachStatement() {return statement;}
1848 | statement = ContinueStatement() {return statement;}
1849 | statement = ReturnStatement() {return statement;}
1850 | statement = EchoStatement() {return statement;}
1851 | [token=<AT>] statement = IncludeStatement()
1852 {if (token != null) {
1853 ((InclusionStatement)statement).silent = true;
1856 | statement = StaticStatement() {return statement;}
1857 | statement = GlobalStatement() {return statement;}
1858 | statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
1862 * A statement expression.
1864 * @return an expression
1866 Statement expressionStatement() :
1868 final Statement statement;
1871 statement = Expression()
1874 } catch (ParseException e) {
1875 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1876 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1878 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1879 errorEnd = SimpleCharStream.getPosition() + 1;
1886 Define defineStatement() :
1888 final int start = SimpleCharStream.getPosition();
1889 Expression defineName,defineValue;
1895 } catch (ParseException e) {
1896 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1898 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1899 errorEnd = SimpleCharStream.getPosition() + 1;
1900 processParseException(e);
1903 defineName = Expression()
1904 } catch (ParseException e) {
1905 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1907 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1908 errorEnd = SimpleCharStream.getPosition() + 1;
1913 } catch (ParseException e) {
1914 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1916 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1917 errorEnd = SimpleCharStream.getPosition() + 1;
1918 processParseException(e);
1921 defineValue = Expression()
1922 } catch (ParseException e) {
1923 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1925 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1926 errorEnd = SimpleCharStream.getPosition() + 1;
1931 } catch (ParseException e) {
1932 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1934 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1935 errorEnd = SimpleCharStream.getPosition() + 1;
1936 processParseException(e);
1938 {return new Define(currentSegment,
1942 SimpleCharStream.getPosition());}
1946 * A Normal statement.
1948 Statement Statement() :
1950 final Statement statement;
1953 statement = StatementNoBreak() {return statement;}
1954 | statement = BreakStatement() {return statement;}
1958 * An html block inside a php syntax.
1960 HTMLBlock htmlBlock() :
1962 final int startIndex = nodePtr;
1963 final AstNode[] blockNodes;
1967 <PHPEND> (phpEchoBlock())*
1969 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1970 } catch (ParseException e) {
1971 errorMessage = "unexpected end of file , '<?php' expected";
1973 errorStart = SimpleCharStream.getPosition();
1974 errorEnd = SimpleCharStream.getPosition();
1978 nbNodes = nodePtr - startIndex;
1979 blockNodes = new AstNode[nbNodes];
1980 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1981 nodePtr = startIndex;
1982 return new HTMLBlock(blockNodes);}
1986 * An include statement. It's "include" an expression;
1988 InclusionStatement IncludeStatement() :
1990 final Expression expr;
1992 final int pos = SimpleCharStream.getPosition();
1993 final InclusionStatement inclusionStatement;
1996 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1997 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1998 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1999 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
2002 } catch (ParseException e) {
2003 if (errorMessage != null) {
2006 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
2008 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2009 errorEnd = SimpleCharStream.getPosition() + 1;
2012 {inclusionStatement = new InclusionStatement(currentSegment,
2016 currentSegment.add(inclusionStatement);
2020 } catch (ParseException e) {
2021 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2023 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2024 errorEnd = SimpleCharStream.getPosition() + 1;
2027 {return inclusionStatement;}
2030 PrintExpression PrintExpression() :
2032 final Expression expr;
2033 final int pos = SimpleCharStream.getPosition();
2036 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
2039 ListExpression ListExpression() :
2042 final Expression expression;
2043 final ArrayList list = new ArrayList();
2044 final int pos = SimpleCharStream.getPosition();
2050 } catch (ParseException e) {
2051 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
2053 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2054 errorEnd = SimpleCharStream.getPosition() + 1;
2058 expr = VariableDeclaratorId()
2061 {if (expr == null) list.add(null);}
2065 } catch (ParseException e) {
2066 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
2068 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2069 errorEnd = SimpleCharStream.getPosition() + 1;
2072 [expr = VariableDeclaratorId() {list.add(expr);}]
2076 } catch (ParseException e) {
2077 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
2079 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2080 errorEnd = SimpleCharStream.getPosition() + 1;
2083 [ <ASSIGN> expression = Expression()
2085 final String[] strings = new String[list.size()];
2086 list.toArray(strings);
2087 return new ListExpression(strings,
2090 SimpleCharStream.getPosition());}
2093 final String[] strings = new String[list.size()];
2094 list.toArray(strings);
2095 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
2099 * An echo statement.
2100 * echo anyexpression (, otherexpression)*
2102 EchoStatement EchoStatement() :
2104 final ArrayList expressions = new ArrayList();
2106 final int pos = SimpleCharStream.getPosition();
2109 <ECHO> expr = Expression()
2110 {expressions.add(expr);}
2112 <COMMA> expr = Expression()
2113 {expressions.add(expr);}
2117 } catch (ParseException e) {
2118 if (e.currentToken.next.kind != 4) {
2119 errorMessage = "';' expected after 'echo' statement";
2121 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2122 errorEnd = SimpleCharStream.getPosition() + 1;
2126 {final Expression[] exprs = new Expression[expressions.size()];
2127 expressions.toArray(exprs);
2128 return new EchoStatement(exprs,pos);}
2131 GlobalStatement GlobalStatement() :
2133 final int pos = SimpleCharStream.getPosition();
2135 final ArrayList vars = new ArrayList();
2136 final GlobalStatement global;
2140 expr = VariableDeclaratorId()
2143 expr = VariableDeclaratorId()
2149 final String[] strings = new String[vars.size()];
2150 vars.toArray(strings);
2151 global = new GlobalStatement(currentSegment,
2154 SimpleCharStream.getPosition());
2155 currentSegment.add(global);
2157 } catch (ParseException e) {
2158 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2160 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2161 errorEnd = SimpleCharStream.getPosition() + 1;
2166 StaticStatement StaticStatement() :
2168 final int pos = SimpleCharStream.getPosition();
2169 final ArrayList vars = new ArrayList();
2170 VariableDeclaration expr;
2173 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name()));}
2174 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name()));})*
2178 final String[] strings = new String[vars.size()];
2179 vars.toArray(strings);
2180 return new StaticStatement(strings,
2182 SimpleCharStream.getPosition());}
2183 } catch (ParseException e) {
2184 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2186 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2187 errorEnd = SimpleCharStream.getPosition() + 1;
2192 LabeledStatement LabeledStatement() :
2194 final int pos = SimpleCharStream.getPosition();
2196 final Statement statement;
2199 label = <IDENTIFIER> <COLON> statement = Statement()
2200 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2212 final int pos = SimpleCharStream.getPosition();
2213 final ArrayList list = new ArrayList();
2214 Statement statement;
2219 } catch (ParseException e) {
2220 errorMessage = "'{' expected";
2222 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2223 errorEnd = SimpleCharStream.getPosition() + 1;
2226 ( statement = BlockStatement() {list.add(statement);}
2227 | statement = htmlBlock() {list.add(statement);})*
2230 } catch (ParseException e) {
2231 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2233 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2234 errorEnd = SimpleCharStream.getPosition() + 1;
2238 final Statement[] statements = new Statement[list.size()];
2239 list.toArray(statements);
2240 return new Block(statements,pos,SimpleCharStream.getPosition());}
2243 Statement BlockStatement() :
2245 final Statement statement;
2248 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2250 | statement = ClassDeclaration() {return statement;}
2251 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2252 currentSegment.add((MethodDeclaration) statement);
2253 ((MethodDeclaration) statement).analyzeCode();
2258 * A Block statement that will not contain any 'break'
2260 Statement BlockStatementNoBreak() :
2262 final Statement statement;
2265 statement = StatementNoBreak() {return statement;}
2266 | statement = ClassDeclaration() {return statement;}
2267 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2268 ((MethodDeclaration) statement).analyzeCode();
2272 VariableDeclaration[] LocalVariableDeclaration() :
2274 final ArrayList list = new ArrayList();
2275 VariableDeclaration var;
2278 var = LocalVariableDeclarator()
2280 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2282 final VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2287 VariableDeclaration LocalVariableDeclarator() :
2289 final String varName;
2290 Expression initializer = null;
2291 final int pos = SimpleCharStream.getPosition();
2294 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2296 if (initializer == null) {
2297 return new VariableDeclaration(currentSegment,
2298 new Variable(varName.toCharArray(),SimpleCharStream.getPosition()-varName.length(),SimpleCharStream.getPosition()),
2300 SimpleCharStream.getPosition());
2302 return new VariableDeclaration(currentSegment,
2303 new Variable(varName.toCharArray(),SimpleCharStream.getPosition()-varName.length(),SimpleCharStream.getPosition()),
2305 VariableDeclaration.EQUAL,
2310 EmptyStatement EmptyStatement() :
2316 {pos = SimpleCharStream.getPosition();
2317 return new EmptyStatement(pos-1,pos);}
2320 Expression StatementExpression() :
2322 final Expression expr,expr2;
2326 expr = PreIncDecExpression() {return expr;}
2328 expr = PrimaryExpression()
2329 [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
2330 OperatorIds.PLUS_PLUS,
2331 SimpleCharStream.getPosition());}
2332 | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
2333 OperatorIds.MINUS_MINUS,
2334 SimpleCharStream.getPosition());}
2339 SwitchStatement SwitchStatement() :
2341 final Expression variable;
2342 final AbstractCase[] cases;
2343 final int pos = SimpleCharStream.getPosition();
2349 } catch (ParseException e) {
2350 errorMessage = "'(' expected after 'switch'";
2352 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2353 errorEnd = SimpleCharStream.getPosition() + 1;
2357 variable = Expression()
2358 } catch (ParseException e) {
2359 if (errorMessage != null) {
2362 errorMessage = "expression expected";
2364 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2365 errorEnd = SimpleCharStream.getPosition() + 1;
2370 } catch (ParseException e) {
2371 errorMessage = "')' expected";
2373 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2374 errorEnd = SimpleCharStream.getPosition() + 1;
2377 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2378 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2381 AbstractCase[] switchStatementBrace() :
2384 final ArrayList cases = new ArrayList();
2388 ( cas = switchLabel0() {cases.add(cas);})*
2392 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2393 cases.toArray(abcase);
2395 } catch (ParseException e) {
2396 errorMessage = "'}' expected";
2398 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2399 errorEnd = SimpleCharStream.getPosition() + 1;
2404 * A Switch statement with : ... endswitch;
2405 * @param start the begin offset of the switch
2406 * @param end the end offset of the switch
2408 AbstractCase[] switchStatementColon(final int start, final int end) :
2411 final ArrayList cases = new ArrayList();
2416 setMarker(fileToParse,
2417 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2421 "Line " + token.beginLine);
2422 } catch (CoreException e) {
2423 PHPeclipsePlugin.log(e);
2425 ( cas = switchLabel0() {cases.add(cas);})*
2428 } catch (ParseException e) {
2429 errorMessage = "'endswitch' expected";
2431 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2432 errorEnd = SimpleCharStream.getPosition() + 1;
2438 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2439 cases.toArray(abcase);
2441 } catch (ParseException e) {
2442 errorMessage = "';' expected after 'endswitch' keyword";
2444 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2445 errorEnd = SimpleCharStream.getPosition() + 1;
2450 AbstractCase switchLabel0() :
2452 final Expression expr;
2453 Statement statement;
2454 final ArrayList stmts = new ArrayList();
2455 final int pos = SimpleCharStream.getPosition();
2458 expr = SwitchLabel()
2459 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2460 | statement = htmlBlock() {stmts.add(statement);})*
2461 [ statement = BreakStatement() {stmts.add(statement);}]
2463 final Statement[] stmtsArray = new Statement[stmts.size()];
2464 stmts.toArray(stmtsArray);
2465 if (expr == null) {//it's a default
2466 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2468 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2473 * case Expression() :
2475 * @return the if it was a case and null if not
2477 Expression SwitchLabel() :
2479 final Expression expr;
2485 } catch (ParseException e) {
2486 if (errorMessage != null) throw e;
2487 errorMessage = "expression expected after 'case' keyword";
2489 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2490 errorEnd = SimpleCharStream.getPosition() + 1;
2496 } catch (ParseException e) {
2497 errorMessage = "':' expected after case expression";
2499 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2500 errorEnd = SimpleCharStream.getPosition() + 1;
2508 } catch (ParseException e) {
2509 errorMessage = "':' expected after 'default' keyword";
2511 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2512 errorEnd = SimpleCharStream.getPosition() + 1;
2517 Break BreakStatement() :
2519 Expression expression = null;
2520 final int start = SimpleCharStream.getPosition();
2523 <BREAK> [ expression = Expression() ]
2526 } catch (ParseException e) {
2527 errorMessage = "';' expected after 'break' keyword";
2529 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2530 errorEnd = SimpleCharStream.getPosition() + 1;
2533 {return new Break(expression, start, SimpleCharStream.getPosition());}
2536 IfStatement IfStatement() :
2538 final int pos = SimpleCharStream.getPosition();
2539 final Expression condition;
2540 final IfStatement ifStatement;
2543 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2544 {return ifStatement;}
2548 Expression Condition(final String keyword) :
2550 final Expression condition;
2555 } catch (ParseException e) {
2556 errorMessage = "'(' expected after " + keyword + " keyword";
2558 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2559 errorEnd = errorStart +1;
2560 processParseException(e);
2562 condition = Expression()
2565 } catch (ParseException e) {
2566 errorMessage = "')' expected after " + keyword + " keyword";
2568 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2569 errorEnd = SimpleCharStream.getPosition() + 1;
2570 processParseException(e);
2575 IfStatement IfStatement0(final Expression condition, final int start,final int end) :
2577 Statement statement;
2578 final Statement stmt;
2579 final Statement[] statementsArray;
2580 ElseIf elseifStatement;
2581 Else elseStatement = null;
2582 final ArrayList stmts;
2583 final ArrayList elseIfList = new ArrayList();
2584 final ElseIf[] elseIfs;
2585 int pos = SimpleCharStream.getPosition();
2586 final int endStatements;
2590 {stmts = new ArrayList();}
2591 ( statement = Statement() {stmts.add(statement);}
2592 | statement = htmlBlock() {stmts.add(statement);})*
2593 {endStatements = SimpleCharStream.getPosition();}
2594 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2595 [elseStatement = ElseStatementColon()]
2598 setMarker(fileToParse,
2599 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2603 "Line " + token.beginLine);
2604 } catch (CoreException e) {
2605 PHPeclipsePlugin.log(e);
2609 } catch (ParseException e) {
2610 errorMessage = "'endif' expected";
2612 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2613 errorEnd = SimpleCharStream.getPosition() + 1;
2618 } catch (ParseException e) {
2619 errorMessage = "';' expected after 'endif' keyword";
2621 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2622 errorEnd = SimpleCharStream.getPosition() + 1;
2626 elseIfs = new ElseIf[elseIfList.size()];
2627 elseIfList.toArray(elseIfs);
2628 if (stmts.size() == 1) {
2629 return new IfStatement(condition,
2630 (Statement) stmts.get(0),
2634 SimpleCharStream.getPosition());
2636 statementsArray = new Statement[stmts.size()];
2637 stmts.toArray(statementsArray);
2638 return new IfStatement(condition,
2639 new Block(statementsArray,pos,endStatements),
2643 SimpleCharStream.getPosition());
2648 (stmt = Statement() | stmt = htmlBlock())
2649 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2653 {pos = SimpleCharStream.getPosition();}
2654 statement = Statement()
2655 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2656 } catch (ParseException e) {
2657 if (errorMessage != null) {
2660 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2662 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2663 errorEnd = SimpleCharStream.getPosition() + 1;
2668 elseIfs = new ElseIf[elseIfList.size()];
2669 elseIfList.toArray(elseIfs);
2670 return new IfStatement(condition,
2675 SimpleCharStream.getPosition());}
2678 ElseIf ElseIfStatementColon() :
2680 final Expression condition;
2681 Statement statement;
2682 final ArrayList list = new ArrayList();
2683 final int pos = SimpleCharStream.getPosition();
2686 <ELSEIF> condition = Condition("elseif")
2687 <COLON> ( statement = Statement() {list.add(statement);}
2688 | statement = htmlBlock() {list.add(statement);})*
2690 final Statement[] stmtsArray = new Statement[list.size()];
2691 list.toArray(stmtsArray);
2692 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2695 Else ElseStatementColon() :
2697 Statement statement;
2698 final ArrayList list = new ArrayList();
2699 final int pos = SimpleCharStream.getPosition();
2702 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2703 | statement = htmlBlock() {list.add(statement);})*
2705 final Statement[] stmtsArray = new Statement[list.size()];
2706 list.toArray(stmtsArray);
2707 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2710 ElseIf ElseIfStatement() :
2712 final Expression condition;
2713 final Statement statement;
2714 final ArrayList list = new ArrayList();
2715 final int pos = SimpleCharStream.getPosition();
2718 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2720 final Statement[] stmtsArray = new Statement[list.size()];
2721 list.toArray(stmtsArray);
2722 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2725 WhileStatement WhileStatement() :
2727 final Expression condition;
2728 final Statement action;
2729 final int pos = SimpleCharStream.getPosition();
2733 condition = Condition("while")
2734 action = WhileStatement0(pos,pos + 5)
2735 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2738 Statement WhileStatement0(final int start, final int end) :
2740 Statement statement;
2741 final ArrayList stmts = new ArrayList();
2742 final int pos = SimpleCharStream.getPosition();
2745 <COLON> (statement = Statement() {stmts.add(statement);})*
2747 setMarker(fileToParse,
2748 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2752 "Line " + token.beginLine);
2753 } catch (CoreException e) {
2754 PHPeclipsePlugin.log(e);
2758 } catch (ParseException e) {
2759 errorMessage = "'endwhile' expected";
2761 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2762 errorEnd = SimpleCharStream.getPosition() + 1;
2768 final Statement[] stmtsArray = new Statement[stmts.size()];
2769 stmts.toArray(stmtsArray);
2770 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2771 } catch (ParseException e) {
2772 errorMessage = "';' expected after 'endwhile' keyword";
2774 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2775 errorEnd = SimpleCharStream.getPosition() + 1;
2779 statement = Statement()
2783 DoStatement DoStatement() :
2785 final Statement action;
2786 final Expression condition;
2787 final int pos = SimpleCharStream.getPosition();
2790 <DO> action = Statement() <WHILE> condition = Condition("while")
2793 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2794 } catch (ParseException e) {
2795 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2797 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2798 errorEnd = SimpleCharStream.getPosition() + 1;
2803 ForeachStatement ForeachStatement() :
2805 Statement statement;
2806 Expression expression;
2807 final int pos = SimpleCharStream.getPosition();
2808 ArrayVariableDeclaration variable;
2814 } catch (ParseException e) {
2815 errorMessage = "'(' expected after 'foreach' keyword";
2817 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2818 errorEnd = SimpleCharStream.getPosition() + 1;
2822 expression = Expression()
2823 } catch (ParseException e) {
2824 errorMessage = "variable expected";
2826 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2827 errorEnd = SimpleCharStream.getPosition() + 1;
2832 } catch (ParseException e) {
2833 errorMessage = "'as' expected";
2835 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2836 errorEnd = SimpleCharStream.getPosition() + 1;
2840 variable = ArrayVariable()
2841 } catch (ParseException e) {
2842 errorMessage = "variable expected";
2844 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2845 errorEnd = SimpleCharStream.getPosition() + 1;
2850 } catch (ParseException e) {
2851 errorMessage = "')' expected after 'foreach' keyword";
2853 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2854 errorEnd = SimpleCharStream.getPosition() + 1;
2858 statement = Statement()
2859 } catch (ParseException e) {
2860 if (errorMessage != null) throw e;
2861 errorMessage = "statement expected";
2863 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2864 errorEnd = SimpleCharStream.getPosition() + 1;
2867 {return new ForeachStatement(expression,
2871 SimpleCharStream.getPosition());}
2875 ForStatement ForStatement() :
2878 final int pos = SimpleCharStream.getPosition();
2879 Expression[] initializations = null;
2880 Expression condition = null;
2881 Expression[] increments = null;
2883 final ArrayList list = new ArrayList();
2884 final int startBlock, endBlock;
2890 } catch (ParseException e) {
2891 errorMessage = "'(' expected after 'for' keyword";
2893 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2894 errorEnd = SimpleCharStream.getPosition() + 1;
2897 [ initializations = ForInit() ] <SEMICOLON>
2898 [ condition = Expression() ] <SEMICOLON>
2899 [ increments = StatementExpressionList() ] <RPAREN>
2901 action = Statement()
2902 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2905 {startBlock = SimpleCharStream.getPosition();}
2906 (action = Statement() {list.add(action);})*
2909 setMarker(fileToParse,
2910 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2912 pos+token.image.length(),
2914 "Line " + token.beginLine);
2915 } catch (CoreException e) {
2916 PHPeclipsePlugin.log(e);
2919 {endBlock = SimpleCharStream.getPosition();}
2922 } catch (ParseException e) {
2923 errorMessage = "'endfor' expected";
2925 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2926 errorEnd = SimpleCharStream.getPosition() + 1;
2932 final Statement[] stmtsArray = new Statement[list.size()];
2933 list.toArray(stmtsArray);
2934 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2935 } catch (ParseException e) {
2936 errorMessage = "';' expected after 'endfor' keyword";
2938 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2939 errorEnd = SimpleCharStream.getPosition() + 1;
2945 Expression[] ForInit() :
2947 final Expression[] exprs;
2950 LOOKAHEAD(LocalVariableDeclaration())
2951 exprs = LocalVariableDeclaration()
2954 exprs = StatementExpressionList()
2958 Expression[] StatementExpressionList() :
2960 final ArrayList list = new ArrayList();
2961 final Expression expr;
2964 expr = StatementExpression() {list.add(expr);}
2965 (<COMMA> StatementExpression() {list.add(expr);})*
2967 final Expression[] exprsArray = new Expression[list.size()];
2968 list.toArray(exprsArray);
2972 Continue ContinueStatement() :
2974 Expression expr = null;
2975 final int pos = SimpleCharStream.getPosition();
2978 <CONTINUE> [ expr = Expression() ]
2981 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2982 } catch (ParseException e) {
2983 errorMessage = "';' expected after 'continue' statement";
2985 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2986 errorEnd = SimpleCharStream.getPosition() + 1;
2991 ReturnStatement ReturnStatement() :
2993 Expression expr = null;
2994 final int pos = SimpleCharStream.getPosition();
2997 <RETURN> [ expr = Expression() ]
3000 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
3001 } catch (ParseException e) {
3002 errorMessage = "';' expected after 'return' statement";
3004 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
3005 errorEnd = SimpleCharStream.getPosition() + 1;