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;
165 * Create marker for the parse error
166 * @param e the ParseException
168 private static void setMarker(final ParseException e) {
170 if (errorStart == -1) {
171 setMarker(fileToParse,
173 SimpleCharStream.tokenBegin,
174 SimpleCharStream.tokenBegin + e.currentToken.image.length(),
176 "Line " + e.currentToken.beginLine);
178 setMarker(fileToParse,
183 "Line " + e.currentToken.beginLine);
187 } catch (CoreException e2) {
188 PHPeclipsePlugin.log(e2);
192 private static void scanLine(final String output,
195 final int brIndx) throws CoreException {
197 StringBuffer lineNumberBuffer = new StringBuffer(10);
199 current = output.substring(indx, brIndx);
201 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
202 int onLine = current.indexOf("on line <b>");
204 lineNumberBuffer.delete(0, lineNumberBuffer.length());
205 for (int i = onLine; i < current.length(); i++) {
206 ch = current.charAt(i);
207 if ('0' <= ch && '9' >= ch) {
208 lineNumberBuffer.append(ch);
212 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
214 Hashtable attributes = new Hashtable();
216 current = current.replaceAll("\n", "");
217 current = current.replaceAll("<b>", "");
218 current = current.replaceAll("</b>", "");
219 MarkerUtilities.setMessage(attributes, current);
221 if (current.indexOf(PARSE_ERROR_STRING) != -1)
222 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
223 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
224 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
226 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
227 MarkerUtilities.setLineNumber(attributes, lineNumber);
228 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
233 public final void parse(final String s) throws CoreException {
234 final StringReader stream = new StringReader(s);
235 if (jj_input_stream == null) {
236 jj_input_stream = new SimpleCharStream(stream, 1, 1);
242 } catch (ParseException e) {
243 processParseException(e);
248 * Call the php parse command ( php -l -f <filename> )
249 * and create markers according to the external parser output
251 public static void phpExternalParse(final IFile file) {
252 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
253 final String filename = file.getLocation().toString();
255 final String[] arguments = { filename };
256 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
257 final String command = form.format(arguments);
259 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
262 // parse the buffer to find the errors and warnings
263 createMarkers(parserResult, file);
264 } catch (CoreException e) {
265 PHPeclipsePlugin.log(e);
270 * Put a new html block in the stack.
272 public static final void createNewHTMLCode() {
273 final int currentPosition = SimpleCharStream.getPosition();
274 if (currentPosition == htmlStart || currentPosition > SimpleCharStream.currentBuffer.length()) {
277 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
278 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
284 public static final void createNewTask() {
285 final int currentPosition = SimpleCharStream.getPosition();
286 final String todo = SimpleCharStream.currentBuffer.substring(currentPosition+1,
287 SimpleCharStream.currentBuffer.indexOf("\n",
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;
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;
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;
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 final int pos = SimpleCharStream.getPosition();
1136 <BANG> expr = Expression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1137 | expr = ExpressionNoBang() {return expr;}
1140 Expression ExpressionNoBang() :
1142 final Expression expr;
1145 expr = PrintExpression() {return expr;}
1146 | expr = ListExpression() {return expr;}
1147 | LOOKAHEAD(varAssignation())
1148 expr = varAssignation() {return expr;}
1149 | expr = ConditionalExpression() {return expr;}
1153 * A Variable assignation.
1154 * varName (an assign operator) any expression
1156 VarAssignation varAssignation() :
1158 final String varName;
1159 final Expression initializer;
1160 final int assignOperator;
1161 final int pos = SimpleCharStream.getPosition();
1164 varName = VariableDeclaratorId()
1165 assignOperator = AssignmentOperator()
1167 initializer = Expression()
1168 } catch (ParseException e) {
1169 if (errorMessage != null) {
1172 errorMessage = "expression expected";
1174 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1175 errorEnd = SimpleCharStream.getPosition() + 1;
1178 {return new VarAssignation(varName.toCharArray(),
1182 SimpleCharStream.getPosition());}
1185 int AssignmentOperator() :
1188 <ASSIGN> {return VarAssignation.EQUAL;}
1189 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1190 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1191 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1192 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1193 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1194 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1195 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1196 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1197 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1198 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1199 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1200 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1203 Expression ConditionalExpression() :
1205 final Expression expr;
1206 Expression expr2 = null;
1207 Expression expr3 = null;
1210 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1212 if (expr3 == null) {
1215 return new ConditionalExpression(expr,expr2,expr3);
1219 Expression ConditionalOrExpression() :
1221 Expression expr,expr2;
1225 expr = ConditionalAndExpression()
1228 <OR_OR> {operator = OperatorIds.OR_OR;}
1229 | <_ORL> {operator = OperatorIds.ORL;}
1230 ) expr2 = ConditionalAndExpression()
1232 expr = new BinaryExpression(expr,expr2,operator);
1238 Expression ConditionalAndExpression() :
1240 Expression expr,expr2;
1244 expr = ConcatExpression()
1246 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1247 | <_ANDL> {operator = OperatorIds.ANDL;})
1248 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1253 Expression ConcatExpression() :
1255 Expression expr,expr2;
1258 expr = InclusiveOrExpression()
1260 <DOT> expr2 = InclusiveOrExpression()
1261 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1266 Expression InclusiveOrExpression() :
1268 Expression expr,expr2;
1271 expr = ExclusiveOrExpression()
1272 (<BIT_OR> expr2 = ExclusiveOrExpression()
1273 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1278 Expression ExclusiveOrExpression() :
1280 Expression expr,expr2;
1283 expr = AndExpression()
1285 <XOR> expr2 = AndExpression()
1286 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1291 Expression AndExpression() :
1293 Expression expr,expr2;
1296 expr = EqualityExpression()
1298 <BIT_AND> expr2 = EqualityExpression()
1299 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1304 Expression EqualityExpression() :
1306 Expression expr,expr2;
1310 expr = RelationalExpression()
1312 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1313 | <DIF> {operator = OperatorIds.DIF;}
1314 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1315 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1316 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1319 expr2 = RelationalExpression()
1320 } catch (ParseException e) {
1321 if (errorMessage != null) {
1324 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1326 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1327 errorEnd = SimpleCharStream.getPosition() + 1;
1331 expr = new BinaryExpression(expr,expr2,operator);
1337 Expression RelationalExpression() :
1339 Expression expr,expr2;
1343 expr = ShiftExpression()
1345 ( <LT> {operator = OperatorIds.LESS;}
1346 | <GT> {operator = OperatorIds.GREATER;}
1347 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1348 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1349 expr2 = ShiftExpression()
1350 {expr = new BinaryExpression(expr,expr2,operator);}
1355 Expression ShiftExpression() :
1357 Expression expr,expr2;
1361 expr = AdditiveExpression()
1363 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1364 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1365 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1366 expr2 = AdditiveExpression()
1367 {expr = new BinaryExpression(expr,expr2,operator);}
1372 Expression AdditiveExpression() :
1374 Expression expr,expr2;
1378 expr = MultiplicativeExpression()
1380 ( <PLUS> {operator = OperatorIds.PLUS;}
1381 | <MINUS> {operator = OperatorIds.MINUS;} )
1382 expr2 = MultiplicativeExpression()
1383 {expr = new BinaryExpression(expr,expr2,operator);}
1388 Expression MultiplicativeExpression() :
1390 Expression expr,expr2;
1395 expr = UnaryExpression()
1396 } catch (ParseException e) {
1397 if (errorMessage != null) throw e;
1398 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1400 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1401 errorEnd = SimpleCharStream.getPosition() + 1;
1405 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1406 | <SLASH> {operator = OperatorIds.DIVIDE;}
1407 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1408 expr2 = UnaryExpression()
1409 {expr = new BinaryExpression(expr,expr2,operator);}
1415 * An unary expression starting with @, & or nothing
1417 Expression UnaryExpression() :
1419 final Expression expr;
1420 final int pos = SimpleCharStream.getPosition();
1423 <BIT_AND> expr = UnaryExpressionNoPrefix()
1424 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1426 expr = AtUnaryExpression() {return expr;}
1429 Expression AtUnaryExpression() :
1431 final Expression expr;
1432 final int pos = SimpleCharStream.getPosition();
1436 expr = AtUnaryExpression()
1437 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1439 expr = UnaryExpressionNoPrefix()
1444 Expression UnaryExpressionNoPrefix() :
1446 final Expression expr;
1448 final int pos = SimpleCharStream.getPosition();
1451 ( <PLUS> {operator = OperatorIds.PLUS;}
1452 | <MINUS> {operator = OperatorIds.MINUS;})
1453 expr = UnaryExpression()
1454 {return new PrefixedUnaryExpression(expr,operator,pos);}
1456 expr = PreIncDecExpression()
1459 expr = UnaryExpressionNotPlusMinus()
1464 Expression PreIncDecExpression() :
1466 final Expression expr;
1468 final int pos = SimpleCharStream.getPosition();
1471 ( <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1472 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;})
1473 expr = PrimaryExpression()
1474 {return new PrefixedUnaryExpression(expr,operator,pos);}
1477 Expression UnaryExpressionNotPlusMinus() :
1479 final Expression expr;
1482 // <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1483 LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1484 expr = CastExpression() {return expr;}
1485 | expr = PostfixExpression() {return expr;}
1486 | expr = Literal() {return expr;}
1487 | <LPAREN> expr = Expression()
1490 } catch (ParseException e) {
1491 errorMessage = "')' expected";
1493 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1494 errorEnd = SimpleCharStream.getPosition() + 1;
1500 CastExpression CastExpression() :
1502 final ConstantIdentifier type;
1503 final Expression expr;
1504 final int pos = SimpleCharStream.getPosition();
1509 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1510 <RPAREN> expr = UnaryExpression()
1511 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1514 Expression PostfixExpression() :
1516 final Expression expr;
1518 final int pos = SimpleCharStream.getPosition();
1521 expr = PrimaryExpression()
1522 [ <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1523 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}]
1525 if (operator == -1) {
1528 return new PostfixedUnaryExpression(expr,operator,pos);
1532 Expression PrimaryExpression() :
1534 final Token identifier;
1536 final int pos = SimpleCharStream.getPosition();
1540 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1541 {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
1543 SimpleCharStream.getPosition()),
1545 ClassAccess.STATIC);}
1547 LOOKAHEAD(PrimarySuffix())
1548 expr = PrimarySuffix(expr))*
1551 expr = PrimaryPrefix()
1553 LOOKAHEAD(PrimarySuffix())
1554 expr = PrimarySuffix(expr))*
1557 expr = ArrayDeclarator()
1562 * An array declarator.
1566 ArrayInitializer ArrayDeclarator() :
1568 final ArrayVariableDeclaration[] vars;
1569 final int pos = SimpleCharStream.getPosition();
1572 <ARRAY> vars = ArrayInitializer()
1573 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1576 Expression PrimaryPrefix() :
1578 final Expression expr;
1581 final int pos = SimpleCharStream.getPosition();
1584 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1586 SimpleCharStream.getPosition());}
1587 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1590 | var = VariableDeclaratorId() {return new VariableDeclaration(currentSegment,
1593 SimpleCharStream.getPosition());}
1596 PrefixedUnaryExpression classInstantiation() :
1599 final StringBuffer buff;
1600 final int pos = SimpleCharStream.getPosition();
1603 <NEW> expr = ClassIdentifier()
1605 {buff = new StringBuffer(expr.toStringExpression());}
1606 expr = PrimaryExpression()
1607 {buff.append(expr.toStringExpression());
1608 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1610 SimpleCharStream.getPosition());}
1612 {return new PrefixedUnaryExpression(expr,
1617 ConstantIdentifier ClassIdentifier():
1621 final int pos = SimpleCharStream.getPosition();
1624 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1626 SimpleCharStream.getPosition());}
1627 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1629 SimpleCharStream.getPosition());}
1632 AbstractSuffixExpression PrimarySuffix(final Expression prefix) :
1634 final AbstractSuffixExpression expr;
1637 expr = Arguments(prefix) {return expr;}
1638 | expr = VariableSuffix(prefix) {return expr;}
1641 AbstractSuffixExpression VariableSuffix(final Expression prefix) :
1644 final int pos = SimpleCharStream.getPosition();
1645 Expression expression = null;
1650 expr = VariableName()
1651 } catch (ParseException e) {
1652 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1654 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1655 errorEnd = SimpleCharStream.getPosition() + 1;
1658 {return new ClassAccess(prefix,
1659 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1660 ClassAccess.NORMAL);}
1662 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1665 } catch (ParseException e) {
1666 errorMessage = "']' expected";
1668 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1669 errorEnd = SimpleCharStream.getPosition() + 1;
1672 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1681 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1682 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1683 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1684 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1685 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1686 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1687 | <TRUE> {pos = SimpleCharStream.getPosition();
1688 return new TrueLiteral(pos-4,pos);}
1689 | <FALSE> {pos = SimpleCharStream.getPosition();
1690 return new FalseLiteral(pos-4,pos);}
1691 | <NULL> {pos = SimpleCharStream.getPosition();
1692 return new NullLiteral(pos-4,pos);}
1695 FunctionCall Arguments(final Expression func) :
1697 Expression[] args = null;
1700 <LPAREN> [ args = ArgumentList() ]
1703 } catch (ParseException e) {
1704 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1706 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1707 errorEnd = SimpleCharStream.getPosition() + 1;
1710 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1714 * An argument list is a list of arguments separated by comma :
1715 * argumentDeclaration() (, argumentDeclaration)*
1716 * @return an array of arguments
1718 Expression[] ArgumentList() :
1721 final ArrayList list = new ArrayList();
1730 } catch (ParseException e) {
1731 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1733 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1734 errorEnd = SimpleCharStream.getPosition() + 1;
1739 final Expression[] arguments = new Expression[list.size()];
1740 list.toArray(arguments);
1745 * A Statement without break.
1747 Statement StatementNoBreak() :
1749 final Statement statement;
1754 statement = Expression()
1757 } catch (ParseException e) {
1758 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1759 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1761 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1762 errorEnd = SimpleCharStream.getPosition() + 1;
1768 statement = LabeledStatement() {return statement;}
1769 | statement = Block() {return statement;}
1770 | statement = EmptyStatement() {return statement;}
1771 | statement = StatementExpression()
1774 } catch (ParseException e) {
1775 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1777 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1778 errorEnd = SimpleCharStream.getPosition() + 1;
1782 | statement = SwitchStatement() {return statement;}
1783 | statement = IfStatement() {return statement;}
1784 | statement = WhileStatement() {return statement;}
1785 | statement = DoStatement() {return statement;}
1786 | statement = ForStatement() {return statement;}
1787 | statement = ForeachStatement() {return statement;}
1788 | statement = ContinueStatement() {return statement;}
1789 | statement = ReturnStatement() {return statement;}
1790 | statement = EchoStatement() {return statement;}
1791 | [token=<AT>] statement = IncludeStatement()
1792 {if (token != null) {
1793 ((InclusionStatement)statement).silent = true;
1796 | statement = StaticStatement() {return statement;}
1797 | statement = GlobalStatement() {return statement;}
1798 | statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
1801 Define defineStatement() :
1803 final int start = SimpleCharStream.getPosition();
1804 Expression defineName,defineValue;
1810 } catch (ParseException e) {
1811 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1813 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1814 errorEnd = SimpleCharStream.getPosition() + 1;
1815 processParseException(e);
1818 defineName = Expression()
1819 } catch (ParseException e) {
1820 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1822 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1823 errorEnd = SimpleCharStream.getPosition() + 1;
1828 } catch (ParseException e) {
1829 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1831 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1832 errorEnd = SimpleCharStream.getPosition() + 1;
1833 processParseException(e);
1836 ( defineValue = PrintExpression()
1837 | LOOKAHEAD(varAssignation())
1838 defineValue = varAssignation()
1839 | defineValue = ConditionalExpression())
1840 } catch (ParseException e) {
1841 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1843 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1844 errorEnd = SimpleCharStream.getPosition() + 1;
1849 } catch (ParseException e) {
1850 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1852 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1853 errorEnd = SimpleCharStream.getPosition() + 1;
1854 processParseException(e);
1856 {return new Define(currentSegment,
1860 SimpleCharStream.getPosition());}
1864 * A Normal statement.
1866 Statement Statement() :
1868 final Statement statement;
1871 statement = StatementNoBreak() {return statement;}
1872 | statement = BreakStatement() {return statement;}
1876 * An html block inside a php syntax.
1878 HTMLBlock htmlBlock() :
1880 final int startIndex = nodePtr;
1881 final AstNode[] blockNodes;
1885 <PHPEND> (phpEchoBlock())*
1887 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1888 } catch (ParseException e) {
1889 errorMessage = "unexpected end of file , '<?php' expected";
1891 errorStart = SimpleCharStream.getPosition();
1892 errorEnd = SimpleCharStream.getPosition();
1896 nbNodes = nodePtr - startIndex;
1897 blockNodes = new AstNode[nbNodes];
1898 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1899 nodePtr = startIndex;
1900 return new HTMLBlock(blockNodes);}
1904 * An include statement. It's "include" an expression;
1906 InclusionStatement IncludeStatement() :
1908 final Expression expr;
1910 final int pos = SimpleCharStream.getPosition();
1911 final InclusionStatement inclusionStatement;
1914 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1915 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1916 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1917 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1920 } catch (ParseException e) {
1921 if (errorMessage != null) {
1924 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1926 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1927 errorEnd = SimpleCharStream.getPosition() + 1;
1930 {inclusionStatement = new InclusionStatement(currentSegment,
1934 currentSegment.add(inclusionStatement);
1938 } catch (ParseException e) {
1939 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1941 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1942 errorEnd = SimpleCharStream.getPosition() + 1;
1945 {return inclusionStatement;}
1948 PrintExpression PrintExpression() :
1950 final Expression expr;
1951 final int pos = SimpleCharStream.getPosition();
1954 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1957 ListExpression ListExpression() :
1960 final Expression expression;
1961 final ArrayList list = new ArrayList();
1962 final int pos = SimpleCharStream.getPosition();
1968 } catch (ParseException e) {
1969 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1971 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1972 errorEnd = SimpleCharStream.getPosition() + 1;
1976 expr = VariableDeclaratorId()
1979 {if (expr == null) list.add(null);}
1983 } catch (ParseException e) {
1984 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1986 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1987 errorEnd = SimpleCharStream.getPosition() + 1;
1990 [expr = VariableDeclaratorId() {list.add(expr);}]
1994 } catch (ParseException e) {
1995 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1997 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1998 errorEnd = SimpleCharStream.getPosition() + 1;
2001 [ <ASSIGN> expression = Expression()
2003 final String[] strings = new String[list.size()];
2004 list.toArray(strings);
2005 return new ListExpression(strings,
2008 SimpleCharStream.getPosition());}
2011 final String[] strings = new String[list.size()];
2012 list.toArray(strings);
2013 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
2017 * An echo statement.
2018 * echo anyexpression (, otherexpression)*
2020 EchoStatement EchoStatement() :
2022 final ArrayList expressions = new ArrayList();
2024 final int pos = SimpleCharStream.getPosition();
2027 <ECHO> expr = Expression()
2028 {expressions.add(expr);}
2030 <COMMA> expr = Expression()
2031 {expressions.add(expr);}
2035 } catch (ParseException e) {
2036 if (e.currentToken.next.kind != 4) {
2037 errorMessage = "';' expected after 'echo' statement";
2039 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2040 errorEnd = SimpleCharStream.getPosition() + 1;
2044 {final Expression[] exprs = new Expression[expressions.size()];
2045 expressions.toArray(exprs);
2046 return new EchoStatement(exprs,pos);}
2049 GlobalStatement GlobalStatement() :
2051 final int pos = SimpleCharStream.getPosition();
2053 final ArrayList vars = new ArrayList();
2054 final GlobalStatement global;
2058 expr = VariableDeclaratorId()
2061 expr = VariableDeclaratorId()
2067 final String[] strings = new String[vars.size()];
2068 vars.toArray(strings);
2069 global = new GlobalStatement(currentSegment,
2072 SimpleCharStream.getPosition());
2073 currentSegment.add(global);
2075 } catch (ParseException e) {
2076 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2078 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2079 errorEnd = SimpleCharStream.getPosition() + 1;
2084 StaticStatement StaticStatement() :
2086 final int pos = SimpleCharStream.getPosition();
2087 final ArrayList vars = new ArrayList();
2088 VariableDeclaration expr;
2091 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2092 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2096 final String[] strings = new String[vars.size()];
2097 vars.toArray(strings);
2098 return new StaticStatement(strings,
2100 SimpleCharStream.getPosition());}
2101 } catch (ParseException e) {
2102 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2104 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2105 errorEnd = SimpleCharStream.getPosition() + 1;
2110 LabeledStatement LabeledStatement() :
2112 final int pos = SimpleCharStream.getPosition();
2114 final Statement statement;
2117 label = <IDENTIFIER> <COLON> statement = Statement()
2118 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2130 final int pos = SimpleCharStream.getPosition();
2131 final ArrayList list = new ArrayList();
2132 Statement statement;
2137 } catch (ParseException e) {
2138 errorMessage = "'{' expected";
2140 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2141 errorEnd = SimpleCharStream.getPosition() + 1;
2144 ( statement = BlockStatement() {list.add(statement);}
2145 | statement = htmlBlock() {list.add(statement);})*
2148 } catch (ParseException e) {
2149 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2151 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2152 errorEnd = SimpleCharStream.getPosition() + 1;
2156 final Statement[] statements = new Statement[list.size()];
2157 list.toArray(statements);
2158 return new Block(statements,pos,SimpleCharStream.getPosition());}
2161 Statement BlockStatement() :
2163 final Statement statement;
2167 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2169 } catch (ParseException e) {
2170 if (errorMessage != null) throw e;
2171 errorMessage = "statement expected";
2173 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2174 errorEnd = SimpleCharStream.getPosition() + 1;
2177 | statement = ClassDeclaration() {return statement;}
2178 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2179 currentSegment.add((MethodDeclaration) statement);
2184 * A Block statement that will not contain any 'break'
2186 Statement BlockStatementNoBreak() :
2188 final Statement statement;
2191 statement = StatementNoBreak() {return statement;}
2192 | statement = ClassDeclaration() {return statement;}
2193 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2197 VariableDeclaration[] LocalVariableDeclaration() :
2199 final ArrayList list = new ArrayList();
2200 VariableDeclaration var;
2203 var = LocalVariableDeclarator()
2205 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2207 final VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2212 VariableDeclaration LocalVariableDeclarator() :
2214 final String varName;
2215 Expression initializer = null;
2216 final int pos = SimpleCharStream.getPosition();
2219 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2221 if (initializer == null) {
2222 return new VariableDeclaration(currentSegment,
2223 varName.toCharArray(),
2225 SimpleCharStream.getPosition());
2227 return new VariableDeclaration(currentSegment,
2228 varName.toCharArray(),
2234 EmptyStatement EmptyStatement() :
2240 {pos = SimpleCharStream.getPosition();
2241 return new EmptyStatement(pos-1,pos);}
2244 Expression StatementExpression() :
2246 final Expression expr,expr2;
2250 expr = PreIncDecExpression() {return expr;}
2252 expr = PrimaryExpression()
2253 [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
2254 OperatorIds.PLUS_PLUS,
2255 SimpleCharStream.getPosition());}
2256 | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
2257 OperatorIds.MINUS_MINUS,
2258 SimpleCharStream.getPosition());}
2259 | operator = AssignmentOperator() expr2 = Expression()
2260 {return new BinaryExpression(expr,expr2,operator);}
2265 SwitchStatement SwitchStatement() :
2267 final Expression variable;
2268 final AbstractCase[] cases;
2269 final int pos = SimpleCharStream.getPosition();
2275 } catch (ParseException e) {
2276 errorMessage = "'(' expected after 'switch'";
2278 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2279 errorEnd = SimpleCharStream.getPosition() + 1;
2283 variable = Expression()
2284 } catch (ParseException e) {
2285 if (errorMessage != null) {
2288 errorMessage = "expression expected";
2290 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2291 errorEnd = SimpleCharStream.getPosition() + 1;
2296 } catch (ParseException e) {
2297 errorMessage = "')' expected";
2299 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2300 errorEnd = SimpleCharStream.getPosition() + 1;
2303 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2304 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2307 AbstractCase[] switchStatementBrace() :
2310 final ArrayList cases = new ArrayList();
2314 ( cas = switchLabel0() {cases.add(cas);})*
2318 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2319 cases.toArray(abcase);
2321 } catch (ParseException e) {
2322 errorMessage = "'}' expected";
2324 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2325 errorEnd = SimpleCharStream.getPosition() + 1;
2330 * A Switch statement with : ... endswitch;
2331 * @param start the begin offset of the switch
2332 * @param end the end offset of the switch
2334 AbstractCase[] switchStatementColon(final int start, final int end) :
2337 final ArrayList cases = new ArrayList();
2342 setMarker(fileToParse,
2343 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2347 "Line " + token.beginLine);
2348 } catch (CoreException e) {
2349 PHPeclipsePlugin.log(e);
2351 ( cas = switchLabel0() {cases.add(cas);})*
2354 } catch (ParseException e) {
2355 errorMessage = "'endswitch' expected";
2357 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2358 errorEnd = SimpleCharStream.getPosition() + 1;
2364 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2365 cases.toArray(abcase);
2367 } catch (ParseException e) {
2368 errorMessage = "';' expected after 'endswitch' keyword";
2370 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2371 errorEnd = SimpleCharStream.getPosition() + 1;
2376 AbstractCase switchLabel0() :
2378 final Expression expr;
2379 Statement statement;
2380 final ArrayList stmts = new ArrayList();
2381 final int pos = SimpleCharStream.getPosition();
2384 expr = SwitchLabel()
2385 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2386 | statement = htmlBlock() {stmts.add(statement);})*
2387 [ statement = BreakStatement() {stmts.add(statement);}]
2389 final Statement[] stmtsArray = new Statement[stmts.size()];
2390 stmts.toArray(stmtsArray);
2391 if (expr == null) {//it's a default
2392 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2394 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2399 * case Expression() :
2401 * @return the if it was a case and null if not
2403 Expression SwitchLabel() :
2405 final Expression expr;
2411 } catch (ParseException e) {
2412 if (errorMessage != null) throw e;
2413 errorMessage = "expression expected after 'case' keyword";
2415 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2416 errorEnd = SimpleCharStream.getPosition() + 1;
2422 } catch (ParseException e) {
2423 errorMessage = "':' expected after case expression";
2425 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2426 errorEnd = SimpleCharStream.getPosition() + 1;
2434 } catch (ParseException e) {
2435 errorMessage = "':' expected after 'default' keyword";
2437 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2438 errorEnd = SimpleCharStream.getPosition() + 1;
2443 Break BreakStatement() :
2445 Expression expression = null;
2446 final int start = SimpleCharStream.getPosition();
2449 <BREAK> [ expression = Expression() ]
2452 } catch (ParseException e) {
2453 errorMessage = "';' expected after 'break' keyword";
2455 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2456 errorEnd = SimpleCharStream.getPosition() + 1;
2459 {return new Break(expression, start, SimpleCharStream.getPosition());}
2462 IfStatement IfStatement() :
2464 final int pos = SimpleCharStream.getPosition();
2465 final Expression condition;
2466 final IfStatement ifStatement;
2469 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2470 {return ifStatement;}
2474 Expression Condition(final String keyword) :
2476 final Expression condition;
2481 } catch (ParseException e) {
2482 errorMessage = "'(' expected after " + keyword + " keyword";
2484 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2485 errorEnd = errorStart +1;
2486 processParseException(e);
2488 condition = Expression()
2491 } catch (ParseException e) {
2492 errorMessage = "')' expected after " + keyword + " keyword";
2494 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2495 errorEnd = SimpleCharStream.getPosition() + 1;
2496 processParseException(e);
2501 IfStatement IfStatement0(final Expression condition, final int start,final int end) :
2503 Statement statement;
2504 final Statement stmt;
2505 final Statement[] statementsArray;
2506 ElseIf elseifStatement;
2507 Else elseStatement = null;
2508 final ArrayList stmts;
2509 final ArrayList elseIfList = new ArrayList();
2510 final ElseIf[] elseIfs;
2511 int pos = SimpleCharStream.getPosition();
2512 final int endStatements;
2516 {stmts = new ArrayList();}
2517 ( statement = Statement() {stmts.add(statement);}
2518 | statement = htmlBlock() {stmts.add(statement);})*
2519 {endStatements = SimpleCharStream.getPosition();}
2520 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2521 [elseStatement = ElseStatementColon()]
2524 setMarker(fileToParse,
2525 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2529 "Line " + token.beginLine);
2530 } catch (CoreException e) {
2531 PHPeclipsePlugin.log(e);
2535 } catch (ParseException e) {
2536 errorMessage = "'endif' expected";
2538 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2539 errorEnd = SimpleCharStream.getPosition() + 1;
2544 } catch (ParseException e) {
2545 errorMessage = "';' expected after 'endif' keyword";
2547 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2548 errorEnd = SimpleCharStream.getPosition() + 1;
2552 elseIfs = new ElseIf[elseIfList.size()];
2553 elseIfList.toArray(elseIfs);
2554 if (stmts.size() == 1) {
2555 return new IfStatement(condition,
2556 (Statement) stmts.get(0),
2560 SimpleCharStream.getPosition());
2562 statementsArray = new Statement[stmts.size()];
2563 stmts.toArray(statementsArray);
2564 return new IfStatement(condition,
2565 new Block(statementsArray,pos,endStatements),
2569 SimpleCharStream.getPosition());
2574 (stmt = Statement() | stmt = htmlBlock())
2575 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2579 {pos = SimpleCharStream.getPosition();}
2580 statement = Statement()
2581 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2582 } catch (ParseException e) {
2583 if (errorMessage != null) {
2586 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2588 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2589 errorEnd = SimpleCharStream.getPosition() + 1;
2594 elseIfs = new ElseIf[elseIfList.size()];
2595 elseIfList.toArray(elseIfs);
2596 return new IfStatement(condition,
2601 SimpleCharStream.getPosition());}
2604 ElseIf ElseIfStatementColon() :
2606 final Expression condition;
2607 Statement statement;
2608 final ArrayList list = new ArrayList();
2609 final int pos = SimpleCharStream.getPosition();
2612 <ELSEIF> condition = Condition("elseif")
2613 <COLON> ( statement = Statement() {list.add(statement);}
2614 | statement = htmlBlock() {list.add(statement);})*
2616 final Statement[] stmtsArray = new Statement[list.size()];
2617 list.toArray(stmtsArray);
2618 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2621 Else ElseStatementColon() :
2623 Statement statement;
2624 final ArrayList list = new ArrayList();
2625 final int pos = SimpleCharStream.getPosition();
2628 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2629 | statement = htmlBlock() {list.add(statement);})*
2631 final Statement[] stmtsArray = new Statement[list.size()];
2632 list.toArray(stmtsArray);
2633 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2636 ElseIf ElseIfStatement() :
2638 final Expression condition;
2639 final Statement statement;
2640 final ArrayList list = new ArrayList();
2641 final int pos = SimpleCharStream.getPosition();
2644 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2646 final Statement[] stmtsArray = new Statement[list.size()];
2647 list.toArray(stmtsArray);
2648 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2651 WhileStatement WhileStatement() :
2653 final Expression condition;
2654 final Statement action;
2655 final int pos = SimpleCharStream.getPosition();
2659 condition = Condition("while")
2660 action = WhileStatement0(pos,pos + 5)
2661 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2664 Statement WhileStatement0(final int start, final int end) :
2666 Statement statement;
2667 final ArrayList stmts = new ArrayList();
2668 final int pos = SimpleCharStream.getPosition();
2671 <COLON> (statement = Statement() {stmts.add(statement);})*
2673 setMarker(fileToParse,
2674 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2678 "Line " + token.beginLine);
2679 } catch (CoreException e) {
2680 PHPeclipsePlugin.log(e);
2684 } catch (ParseException e) {
2685 errorMessage = "'endwhile' expected";
2687 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2688 errorEnd = SimpleCharStream.getPosition() + 1;
2694 final Statement[] stmtsArray = new Statement[stmts.size()];
2695 stmts.toArray(stmtsArray);
2696 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2697 } catch (ParseException e) {
2698 errorMessage = "';' expected after 'endwhile' keyword";
2700 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2701 errorEnd = SimpleCharStream.getPosition() + 1;
2705 statement = Statement()
2709 DoStatement DoStatement() :
2711 final Statement action;
2712 final Expression condition;
2713 final int pos = SimpleCharStream.getPosition();
2716 <DO> action = Statement() <WHILE> condition = Condition("while")
2719 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2720 } catch (ParseException e) {
2721 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2723 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2724 errorEnd = SimpleCharStream.getPosition() + 1;
2729 ForeachStatement ForeachStatement() :
2731 Statement statement;
2732 Expression expression;
2733 final int pos = SimpleCharStream.getPosition();
2734 ArrayVariableDeclaration variable;
2740 } catch (ParseException e) {
2741 errorMessage = "'(' expected after 'foreach' keyword";
2743 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2744 errorEnd = SimpleCharStream.getPosition() + 1;
2748 expression = Expression()
2749 } catch (ParseException e) {
2750 errorMessage = "variable expected";
2752 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2753 errorEnd = SimpleCharStream.getPosition() + 1;
2758 } catch (ParseException e) {
2759 errorMessage = "'as' expected";
2761 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2762 errorEnd = SimpleCharStream.getPosition() + 1;
2766 variable = ArrayVariable()
2767 } catch (ParseException e) {
2768 errorMessage = "variable expected";
2770 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2771 errorEnd = SimpleCharStream.getPosition() + 1;
2776 } catch (ParseException e) {
2777 errorMessage = "')' expected after 'foreach' keyword";
2779 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2780 errorEnd = SimpleCharStream.getPosition() + 1;
2784 statement = Statement()
2785 } catch (ParseException e) {
2786 if (errorMessage != null) throw e;
2787 errorMessage = "statement expected";
2789 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2790 errorEnd = SimpleCharStream.getPosition() + 1;
2793 {return new ForeachStatement(expression,
2797 SimpleCharStream.getPosition());}
2801 ForStatement ForStatement() :
2804 final int pos = SimpleCharStream.getPosition();
2805 Expression[] initializations = null;
2806 Expression condition = null;
2807 Expression[] increments = null;
2809 final ArrayList list = new ArrayList();
2810 final int startBlock, endBlock;
2816 } catch (ParseException e) {
2817 errorMessage = "'(' expected after 'for' keyword";
2819 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2820 errorEnd = SimpleCharStream.getPosition() + 1;
2823 [ initializations = ForInit() ] <SEMICOLON>
2824 [ condition = Expression() ] <SEMICOLON>
2825 [ increments = StatementExpressionList() ] <RPAREN>
2827 action = Statement()
2828 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2831 {startBlock = SimpleCharStream.getPosition();}
2832 (action = Statement() {list.add(action);})*
2835 setMarker(fileToParse,
2836 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2838 pos+token.image.length(),
2840 "Line " + token.beginLine);
2841 } catch (CoreException e) {
2842 PHPeclipsePlugin.log(e);
2845 {endBlock = SimpleCharStream.getPosition();}
2848 } catch (ParseException e) {
2849 errorMessage = "'endfor' expected";
2851 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2852 errorEnd = SimpleCharStream.getPosition() + 1;
2858 final Statement[] stmtsArray = new Statement[list.size()];
2859 list.toArray(stmtsArray);
2860 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2861 } catch (ParseException e) {
2862 errorMessage = "';' expected after 'endfor' keyword";
2864 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2865 errorEnd = SimpleCharStream.getPosition() + 1;
2871 Expression[] ForInit() :
2873 final Expression[] exprs;
2876 LOOKAHEAD(LocalVariableDeclaration())
2877 exprs = LocalVariableDeclaration()
2880 exprs = StatementExpressionList()
2884 Expression[] StatementExpressionList() :
2886 final ArrayList list = new ArrayList();
2887 final Expression expr;
2890 expr = StatementExpression() {list.add(expr);}
2891 (<COMMA> StatementExpression() {list.add(expr);})*
2893 final Expression[] exprsArray = new Expression[list.size()];
2894 list.toArray(exprsArray);
2898 Continue ContinueStatement() :
2900 Expression expr = null;
2901 final int pos = SimpleCharStream.getPosition();
2904 <CONTINUE> [ expr = Expression() ]
2907 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2908 } catch (ParseException e) {
2909 errorMessage = "';' expected after 'continue' statement";
2911 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2912 errorEnd = SimpleCharStream.getPosition() + 1;
2917 ReturnStatement ReturnStatement() :
2919 Expression expr = null;
2920 final int pos = SimpleCharStream.getPosition();
2923 <RETURN> [ expr = Expression() ]
2926 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2927 } catch (ParseException e) {
2928 errorMessage = "';' expected after 'return' statement";
2930 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2931 errorEnd = SimpleCharStream.getPosition() + 1;