3 CHOICE_AMBIGUITY_CHECK = 2;
4 OTHER_AMBIGUITY_CHECK = 1;
7 DEBUG_LOOKAHEAD = false;
8 DEBUG_TOKEN_MANAGER = false;
9 OPTIMIZE_TOKEN_MANAGER = false;
10 ERROR_REPORTING = true;
11 JAVA_UNICODE_ESCAPE = false;
12 UNICODE_INPUT = false;
14 USER_TOKEN_MANAGER = false;
15 USER_CHAR_STREAM = false;
17 BUILD_TOKEN_MANAGER = true;
19 FORCE_LA_CHECK = false;
22 PARSER_BEGIN(PHPParser)
25 import org.eclipse.core.resources.IFile;
26 import org.eclipse.core.resources.IMarker;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.ui.texteditor.MarkerUtilities;
29 import org.eclipse.jface.preference.IPreferenceStore;
31 import java.util.Hashtable;
32 import java.util.ArrayList;
33 import java.io.StringReader;
35 import java.text.MessageFormat;
37 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
38 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
39 import net.sourceforge.phpdt.internal.compiler.ast.*;
40 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
41 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
46 * This php parser is inspired by the Java 1.2 grammar example
47 * given with JavaCC. You can get JavaCC at http://www.webgain.com
48 * You can test the parser with the PHPParserTestCase2.java
49 * @author Matthieu Casanova
50 * @version $Reference: 1.0$
52 public final class PHPParser extends PHPParserSuperclass {
54 /** The file that is parsed. */
55 private static IFile fileToParse;
57 /** The current segment. */
58 private static OutlineableWithChildren currentSegment;
60 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
61 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
62 static PHPOutlineInfo outlineInfo;
64 /** The error level of the current ParseException. */
65 private static int errorLevel = ERROR;
66 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
67 private static String errorMessage;
69 private static int errorStart = -1;
70 private static int errorEnd = -1;
71 private static PHPDocument phpDocument;
73 private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
75 * The point where html starts.
76 * It will be used by the token manager to create HTMLCode objects
78 public static int htmlStart;
81 private final static int AstStackIncrement = 100;
82 /** The stack of node. */
83 private static AstNode[] nodes;
84 /** The cursor in expression stack. */
85 private static int nodePtr;
87 public final void setFileToParse(final IFile fileToParse) {
88 this.fileToParse = fileToParse;
94 public PHPParser(final IFile fileToParse) {
95 this(new StringReader(""));
96 this.fileToParse = fileToParse;
100 * Reinitialize the parser.
102 private static final void init() {
103 nodes = new AstNode[AstStackIncrement];
109 * Add an php node on the stack.
110 * @param node the node that will be added to the stack
112 private static final void pushOnAstNodes(final AstNode node) {
114 nodes[++nodePtr] = node;
115 } catch (IndexOutOfBoundsException e) {
116 final int oldStackLength = nodes.length;
117 final AstNode[] oldStack = nodes;
118 nodes = new AstNode[oldStackLength + AstStackIncrement];
119 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
120 nodePtr = oldStackLength;
121 nodes[nodePtr] = node;
125 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
126 phpDocument = new PHPDocument(parent,"_root".toCharArray());
127 currentSegment = phpDocument;
128 outlineInfo = new PHPOutlineInfo(parent, currentSegment);
129 final StringReader stream = new StringReader(s);
130 if (jj_input_stream == null) {
131 jj_input_stream = new SimpleCharStream(stream, 1, 1);
137 phpDocument.nodes = new AstNode[nodes.length];
138 System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
139 if (PHPeclipsePlugin.DEBUG) {
140 PHPeclipsePlugin.log(1,phpDocument.toString());
142 } catch (ParseException e) {
143 processParseException(e);
149 * This method will process the parse exception.
150 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
151 * @param e the ParseException
153 private static void processParseException(final ParseException e) {
154 if (errorMessage == null) {
155 PHPeclipsePlugin.log(e);
156 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
157 errorStart = SimpleCharStream.getPosition();
158 errorEnd = errorStart + 1;
162 if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e);
166 * Create marker for the parse error
167 * @param e the ParseException
169 private static void setMarker(final ParseException e) {
171 if (errorStart == -1) {
172 setMarker(fileToParse,
174 SimpleCharStream.tokenBegin,
175 SimpleCharStream.tokenBegin + e.currentToken.image.length(),
177 "Line " + e.currentToken.beginLine);
179 setMarker(fileToParse,
184 "Line " + e.currentToken.beginLine);
188 } catch (CoreException e2) {
189 PHPeclipsePlugin.log(e2);
193 private static void scanLine(final String output,
196 final int brIndx) throws CoreException {
198 StringBuffer lineNumberBuffer = new StringBuffer(10);
200 current = output.substring(indx, brIndx);
202 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
203 int onLine = current.indexOf("on line <b>");
205 lineNumberBuffer.delete(0, lineNumberBuffer.length());
206 for (int i = onLine; i < current.length(); i++) {
207 ch = current.charAt(i);
208 if ('0' <= ch && '9' >= ch) {
209 lineNumberBuffer.append(ch);
213 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
215 Hashtable attributes = new Hashtable();
217 current = current.replaceAll("\n", "");
218 current = current.replaceAll("<b>", "");
219 current = current.replaceAll("</b>", "");
220 MarkerUtilities.setMessage(attributes, current);
222 if (current.indexOf(PARSE_ERROR_STRING) != -1)
223 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
224 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
225 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
227 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
228 MarkerUtilities.setLineNumber(attributes, lineNumber);
229 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
234 public final void parse(final String s) throws CoreException {
235 final StringReader stream = new StringReader(s);
236 if (jj_input_stream == null) {
237 jj_input_stream = new SimpleCharStream(stream, 1, 1);
243 } catch (ParseException e) {
244 processParseException(e);
249 * Call the php parse command ( php -l -f <filename> )
250 * and create markers according to the external parser output
252 public static void phpExternalParse(final IFile file) {
253 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
254 final String filename = file.getLocation().toString();
256 final String[] arguments = { filename };
257 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
258 final String command = form.format(arguments);
260 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
263 // parse the buffer to find the errors and warnings
264 createMarkers(parserResult, file);
265 } catch (CoreException e) {
266 PHPeclipsePlugin.log(e);
271 * Put a new html block in the stack.
273 public static final void createNewHTMLCode() {
274 final int currentPosition = SimpleCharStream.getPosition();
275 if (currentPosition == htmlStart || currentPosition > SimpleCharStream.currentBuffer.length()) {
278 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
279 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
285 public static final void createNewTask() {
286 final int currentPosition = SimpleCharStream.getPosition();
287 final String todo = SimpleCharStream.currentBuffer.substring(currentPosition+1,
288 SimpleCharStream.currentBuffer.indexOf("\n",
291 setMarker(fileToParse,
293 SimpleCharStream.getBeginLine(),
295 "Line "+SimpleCharStream.getBeginLine());
296 } catch (CoreException e) {
297 PHPeclipsePlugin.log(e);
301 private static final void parse() throws ParseException {
306 PARSER_END(PHPParser)
310 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
311 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
312 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
317 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
320 /* Skip any character if we are not in php mode */
338 <PHPPARSING> SPECIAL_TOKEN :
340 "//" : IN_SINGLE_LINE_COMMENT
341 | "#" : IN_SINGLE_LINE_COMMENT
342 | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
343 | "/*" : IN_MULTI_LINE_COMMENT
346 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
348 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
352 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
354 "todo" {PHPParser.createNewTask();}
357 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
362 <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
367 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
377 | <FUNCTION : "function">
380 | <ELSEIF : "elseif">
387 /* LANGUAGE CONSTRUCT */
392 | <INCLUDE : "include">
393 | <REQUIRE : "require">
394 | <INCLUDE_ONCE : "include_once">
395 | <REQUIRE_ONCE : "require_once">
396 | <GLOBAL : "global">
397 | <DEFINE : "define">
398 | <STATIC : "static">
399 | <CLASSACCESS : "->">
400 | <STATICCLASSACCESS : "::">
401 | <ARRAYASSIGN : "=>">
404 /* RESERVED WORDS AND LITERALS */
410 | <CONTINUE : "continue">
411 | <_DEFAULT : "default">
413 | <EXTENDS : "extends">
418 | <RETURN : "return">
420 | <SWITCH : "switch">
425 | <ENDWHILE : "endwhile">
426 | <ENDSWITCH: "endswitch">
428 | <ENDFOR : "endfor">
429 | <FOREACH : "foreach">
437 | <OBJECT : "object">
439 | <BOOLEAN : "boolean">
441 | <DOUBLE : "double">
444 | <INTEGER : "integer">
464 | <MINUS_MINUS : "--">
474 | <RSIGNEDSHIFT : ">>">
475 | <RUNSIGNEDSHIFT : ">>>">
484 <DECIMAL_LITERAL> (["l","L"])?
485 | <HEX_LITERAL> (["l","L"])?
486 | <OCTAL_LITERAL> (["l","L"])?
489 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
491 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
493 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
495 <FLOATING_POINT_LITERAL:
496 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
497 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
498 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
499 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
502 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
504 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
505 | <STRING_1: "\"" ( ~["\"","\\"] | "\\" ~[] )* "\"">
506 | <STRING_2: "'" ( ~["'","\\"] | "\\" ~[] )* "'">
507 | <STRING_3: "`" ( ~["`","\\"] | "\\" ~[] )* "`">
514 <IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
517 ["a"-"z"] | ["A"-"Z"]
525 "_" | ["\u007f"-"\u00ff"]
550 | <EQUAL_EQUAL : "==">
555 | <BANGDOUBLEEQUAL : "!==">
556 | <TRIPLEEQUAL : "===">
563 | <PLUSASSIGN : "+=">
564 | <MINUSASSIGN : "-=">
565 | <STARASSIGN : "*=">
566 | <SLASHASSIGN : "/=">
572 | <TILDEEQUAL : "~=">
573 | <LSHIFTASSIGN : "<<=">
574 | <RSIGNEDSHIFTASSIGN : ">>=">
579 <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
587 {PHPParser.createNewHTMLCode();}
588 } catch (TokenMgrError e) {
589 PHPeclipsePlugin.log(e);
590 errorStart = SimpleCharStream.getPosition();
591 errorEnd = errorStart + 1;
592 errorMessage = e.getMessage();
594 throw generateParseException();
599 * A php block is a <?= expression [;]?>
600 * or <?php somephpcode ?>
601 * or <? somephpcode ?>
605 final int start = SimpleCharStream.getPosition();
606 final PHPEchoBlock phpEchoBlock;
609 phpEchoBlock = phpEchoBlock()
610 {pushOnAstNodes(phpEchoBlock);}
615 setMarker(fileToParse,
616 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
618 SimpleCharStream.getPosition(),
620 "Line " + token.beginLine);
621 } catch (CoreException e) {
622 PHPeclipsePlugin.log(e);
628 } catch (ParseException e) {
629 errorMessage = "'?>' expected";
631 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
632 errorEnd = SimpleCharStream.getPosition() + 1;
633 processParseException(e);
637 PHPEchoBlock phpEchoBlock() :
639 final Expression expr;
640 final int pos = SimpleCharStream.getPosition();
641 final PHPEchoBlock echoBlock;
644 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
646 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
647 pushOnAstNodes(echoBlock);
657 ClassDeclaration ClassDeclaration() :
659 final ClassDeclaration classDeclaration;
660 final Token className,superclassName;
662 char[] classNameImage = SYNTAX_ERROR_CHAR;
663 char[] superclassNameImage = null;
667 {pos = SimpleCharStream.getPosition();}
669 className = <IDENTIFIER>
670 {classNameImage = className.image.toCharArray();}
671 } catch (ParseException e) {
672 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
674 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
675 errorEnd = SimpleCharStream.getPosition() + 1;
676 processParseException(e);
681 superclassName = <IDENTIFIER>
682 {superclassNameImage = superclassName.image.toCharArray();}
683 } catch (ParseException e) {
684 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
686 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
687 errorEnd = SimpleCharStream.getPosition() + 1;
688 processParseException(e);
689 superclassNameImage = SYNTAX_ERROR_CHAR;
693 if (superclassNameImage == null) {
694 classDeclaration = new ClassDeclaration(currentSegment,
699 classDeclaration = new ClassDeclaration(currentSegment,
705 currentSegment.add(classDeclaration);
706 currentSegment = classDeclaration;
708 ClassBody(classDeclaration)
709 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
710 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
711 pushOnAstNodes(classDeclaration);
712 return classDeclaration;}
715 void ClassBody(final ClassDeclaration classDeclaration) :
720 } catch (ParseException e) {
721 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
723 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
724 errorEnd = SimpleCharStream.getPosition() + 1;
727 ( ClassBodyDeclaration(classDeclaration) )*
730 } catch (ParseException e) {
731 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
733 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
734 errorEnd = SimpleCharStream.getPosition() + 1;
740 * A class can contain only methods and fields.
742 void ClassBodyDeclaration(final ClassDeclaration classDeclaration) :
744 final MethodDeclaration method;
745 final FieldDeclaration field;
748 method = MethodDeclaration() {classDeclaration.addMethod(method);}
749 | field = FieldDeclaration() {classDeclaration.addField(field);}
753 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
755 FieldDeclaration FieldDeclaration() :
757 VariableDeclaration variableDeclaration;
758 final VariableDeclaration[] list;
759 final ArrayList arrayList = new ArrayList();
760 final int pos = SimpleCharStream.getPosition();
763 <VAR> variableDeclaration = VariableDeclarator()
764 {arrayList.add(variableDeclaration);
765 outlineInfo.addVariable(new String(variableDeclaration.name));}
766 ( <COMMA> variableDeclaration = VariableDeclarator()
767 {arrayList.add(variableDeclaration);
768 outlineInfo.addVariable(new String(variableDeclaration.name));}
772 } catch (ParseException e) {
773 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
775 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
776 errorEnd = SimpleCharStream.getPosition() + 1;
777 processParseException(e);
780 {list = new VariableDeclaration[arrayList.size()];
781 arrayList.toArray(list);
782 return new FieldDeclaration(list,
784 SimpleCharStream.getPosition(),
788 VariableDeclaration VariableDeclarator() :
790 final String varName;
791 Expression initializer = null;
792 final int pos = SimpleCharStream.getPosition();
795 varName = VariableDeclaratorId()
799 initializer = VariableInitializer()
800 } catch (ParseException e) {
801 errorMessage = "Literal expression expected in variable initializer";
803 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
804 errorEnd = SimpleCharStream.getPosition() + 1;
809 if (initializer == null) {
810 return new VariableDeclaration(currentSegment,
811 varName.toCharArray(),
813 SimpleCharStream.getPosition());
815 return new VariableDeclaration(currentSegment,
816 varName.toCharArray(),
824 * @return the variable name (with suffix)
826 String VariableDeclaratorId() :
829 Expression expression = null;
830 final int pos = SimpleCharStream.getPosition();
831 ConstantIdentifier ex;
837 {ex = new ConstantIdentifier(expr.toCharArray(),
839 SimpleCharStream.getPosition());}
840 expression = VariableSuffix(ex)
843 if (expression == null) {
846 return expression.toStringExpression();
848 } catch (ParseException e) {
849 errorMessage = "'$' expected for variable identifier";
851 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
852 errorEnd = SimpleCharStream.getPosition() + 1;
858 * Return a variablename without the $.
859 * @return a variable name
863 final StringBuffer buff;
864 Expression expression = null;
869 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
871 if (expression == null) {
872 return token.image.substring(1);
874 buff = new StringBuffer(token.image);
876 buff.append(expression.toStringExpression());
878 return buff.toString();
881 <DOLLAR> expr = VariableName()
886 * A Variable name (without the $)
887 * @return a variable name String
889 String VariableName():
891 final StringBuffer buff;
893 Expression expression = null;
897 <LBRACE> expression = Expression() <RBRACE>
898 {buff = new StringBuffer("{");
899 buff.append(expression.toStringExpression());
901 return buff.toString();}
903 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
905 if (expression == null) {
908 buff = new StringBuffer(token.image);
910 buff.append(expression.toStringExpression());
912 return buff.toString();
915 <DOLLAR> expr = VariableName()
917 buff = new StringBuffer("$");
919 return buff.toString();
922 token = <DOLLAR_ID> {return token.image;}
925 Expression VariableInitializer() :
927 final Expression expr;
929 final int pos = SimpleCharStream.getPosition();
935 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
936 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
938 SimpleCharStream.getPosition()),
942 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
943 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
945 SimpleCharStream.getPosition()),
949 expr = ArrayDeclarator()
953 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
956 ArrayVariableDeclaration ArrayVariable() :
958 final Expression expr,expr2;
962 [<ARRAYASSIGN> expr2 = Expression()
963 {return new ArrayVariableDeclaration(expr,expr2);}
965 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
968 ArrayVariableDeclaration[] ArrayInitializer() :
970 ArrayVariableDeclaration expr;
971 final ArrayList list = new ArrayList();
974 <LPAREN> [ expr = ArrayVariable()
976 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
980 [<COMMA> {list.add(null);}]
983 final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
989 * A Method Declaration.
990 * <b>function</b> MetodDeclarator() Block()
992 MethodDeclaration MethodDeclaration() :
994 final MethodDeclaration functionDeclaration;
996 final OutlineableWithChildren seg = currentSegment;
1001 functionDeclaration = MethodDeclarator()
1002 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1003 } catch (ParseException e) {
1004 if (errorMessage != null) throw e;
1005 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1007 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1008 errorEnd = SimpleCharStream.getPosition() + 1;
1011 {currentSegment = functionDeclaration;}
1013 {functionDeclaration.statements = block.statements;
1014 currentSegment = seg;
1015 return functionDeclaration;}
1019 * A MethodDeclarator.
1020 * [&] IDENTIFIER(parameters ...).
1021 * @return a function description for the outline
1023 MethodDeclaration MethodDeclarator() :
1025 final Token identifier;
1026 Token reference = null;
1027 final Hashtable formalParameters;
1028 final int pos = SimpleCharStream.getPosition();
1029 char[] identifierChar = SYNTAX_ERROR_CHAR;
1032 [reference = <BIT_AND>]
1034 identifier = <IDENTIFIER>
1035 {identifierChar = identifier.image.toCharArray();}
1036 } catch (ParseException e) {
1037 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1039 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1040 errorEnd = SimpleCharStream.getPosition() + 1;
1041 processParseException(e);
1043 formalParameters = FormalParameters()
1044 {return new MethodDeclaration(currentSegment,
1049 SimpleCharStream.getPosition());}
1053 * FormalParameters follows method identifier.
1054 * (FormalParameter())
1056 Hashtable FormalParameters() :
1058 VariableDeclaration var;
1059 final Hashtable parameters = new Hashtable();
1064 } catch (ParseException e) {
1065 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1067 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1068 errorEnd = SimpleCharStream.getPosition() + 1;
1069 processParseException(e);
1071 [ var = FormalParameter()
1072 {parameters.put(new String(var.name),var);}
1074 <COMMA> var = FormalParameter()
1075 {parameters.put(new String(var.name),var);}
1080 } catch (ParseException e) {
1081 errorMessage = "')' expected";
1083 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1084 errorEnd = SimpleCharStream.getPosition() + 1;
1085 processParseException(e);
1087 {return parameters;}
1091 * A formal parameter.
1092 * $varname[=value] (,$varname[=value])
1094 VariableDeclaration FormalParameter() :
1096 final VariableDeclaration variableDeclaration;
1100 [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
1102 if (token != null) {
1103 variableDeclaration.setReference(true);
1105 return variableDeclaration;}
1108 ConstantIdentifier Type() :
1111 <STRING> {pos = SimpleCharStream.getPosition();
1112 return new ConstantIdentifier(Types.STRING,pos,pos-6);}
1113 | <BOOL> {pos = SimpleCharStream.getPosition();
1114 return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
1115 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1116 return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
1117 | <REAL> {pos = SimpleCharStream.getPosition();
1118 return new ConstantIdentifier(Types.REAL,pos,pos-4);}
1119 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1120 return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
1121 | <FLOAT> {pos = SimpleCharStream.getPosition();
1122 return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
1123 | <INT> {pos = SimpleCharStream.getPosition();
1124 return new ConstantIdentifier(Types.INT,pos,pos-3);}
1125 | <INTEGER> {pos = SimpleCharStream.getPosition();
1126 return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
1127 | <OBJECT> {pos = SimpleCharStream.getPosition();
1128 return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
1131 Expression Expression() :
1133 final Expression expr;
1134 Expression initializer = null;
1135 int assignOperator = -1;
1136 final int pos = SimpleCharStream.getPosition();
1140 expr = ConditionalExpression() [ assignOperator = AssignmentOperator() initializer = Expression() ]
1142 if (assignOperator == -1) return expr;
1143 return new VarAssignation(expr,
1147 SimpleCharStream.getPosition());
1149 | expr = ExpressionWBang() {return expr;}
1152 Expression ExpressionWBang() :
1154 final Expression expr;
1155 final int pos = SimpleCharStream.getPosition();
1158 <BANG> expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1159 | expr = ExpressionNoBang() {return expr;}
1162 Expression ExpressionNoBang() :
1164 final Expression expr;
1167 expr = PrintExpression() {return expr;}
1168 | expr = ListExpression() {return expr;}
1172 * Any assignement operator.
1173 * @return the assignement operator id
1175 int AssignmentOperator() :
1178 <ASSIGN> {return VarAssignation.EQUAL;}
1179 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1180 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1181 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1182 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1183 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1184 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1185 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1186 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1187 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1188 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1189 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1190 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1193 Expression ConditionalExpression() :
1195 final Expression expr;
1196 Expression expr2 = null;
1197 Expression expr3 = null;
1200 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1202 if (expr3 == null) {
1205 return new ConditionalExpression(expr,expr2,expr3);
1209 Expression ConditionalOrExpression() :
1211 Expression expr,expr2;
1215 expr = ConditionalAndExpression()
1218 <OR_OR> {operator = OperatorIds.OR_OR;}
1219 | <_ORL> {operator = OperatorIds.ORL;}
1220 ) expr2 = ConditionalAndExpression()
1222 expr = new BinaryExpression(expr,expr2,operator);
1228 Expression ConditionalAndExpression() :
1230 Expression expr,expr2;
1234 expr = ConcatExpression()
1236 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1237 | <_ANDL> {operator = OperatorIds.ANDL;})
1238 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1243 Expression ConcatExpression() :
1245 Expression expr,expr2;
1248 expr = InclusiveOrExpression()
1250 <DOT> expr2 = InclusiveOrExpression()
1251 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1256 Expression InclusiveOrExpression() :
1258 Expression expr,expr2;
1261 expr = ExclusiveOrExpression()
1262 (<BIT_OR> expr2 = ExclusiveOrExpression()
1263 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1268 Expression ExclusiveOrExpression() :
1270 Expression expr,expr2;
1273 expr = AndExpression()
1275 <XOR> expr2 = AndExpression()
1276 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1281 Expression AndExpression() :
1283 Expression expr,expr2;
1286 expr = EqualityExpression()
1288 <BIT_AND> expr2 = EqualityExpression()
1289 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1294 Expression EqualityExpression() :
1296 Expression expr,expr2;
1300 expr = RelationalExpression()
1302 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1303 | <DIF> {operator = OperatorIds.DIF;}
1304 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1305 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1306 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1309 expr2 = RelationalExpression()
1310 } catch (ParseException e) {
1311 if (errorMessage != null) {
1314 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1316 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1317 errorEnd = SimpleCharStream.getPosition() + 1;
1321 expr = new BinaryExpression(expr,expr2,operator);
1327 Expression RelationalExpression() :
1329 Expression expr,expr2;
1333 expr = ShiftExpression()
1335 ( <LT> {operator = OperatorIds.LESS;}
1336 | <GT> {operator = OperatorIds.GREATER;}
1337 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1338 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1339 expr2 = ShiftExpression()
1340 {expr = new BinaryExpression(expr,expr2,operator);}
1345 Expression ShiftExpression() :
1347 Expression expr,expr2;
1351 expr = AdditiveExpression()
1353 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1354 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1355 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1356 expr2 = AdditiveExpression()
1357 {expr = new BinaryExpression(expr,expr2,operator);}
1362 Expression AdditiveExpression() :
1364 Expression expr,expr2;
1368 expr = MultiplicativeExpression()
1370 ( <PLUS> {operator = OperatorIds.PLUS;}
1371 | <MINUS> {operator = OperatorIds.MINUS;} )
1372 expr2 = MultiplicativeExpression()
1373 {expr = new BinaryExpression(expr,expr2,operator);}
1378 Expression MultiplicativeExpression() :
1380 Expression expr,expr2;
1385 expr = UnaryExpression()
1386 } catch (ParseException e) {
1387 if (errorMessage != null) throw e;
1388 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1390 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1391 errorEnd = SimpleCharStream.getPosition() + 1;
1395 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1396 | <SLASH> {operator = OperatorIds.DIVIDE;}
1397 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1398 expr2 = UnaryExpression()
1399 {expr = new BinaryExpression(expr,expr2,operator);}
1405 * An unary expression starting with @, & or nothing
1407 Expression UnaryExpression() :
1409 final Expression expr;
1410 final int pos = SimpleCharStream.getPosition();
1413 <BIT_AND> expr = UnaryExpressionNoPrefix()
1414 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1416 expr = AtUnaryExpression() {return expr;}
1419 Expression AtUnaryExpression() :
1421 final Expression expr;
1422 final int pos = SimpleCharStream.getPosition();
1426 expr = AtUnaryExpression()
1427 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1429 expr = UnaryExpressionNoPrefix()
1434 Expression UnaryExpressionNoPrefix() :
1436 final Expression expr;
1438 final int pos = SimpleCharStream.getPosition();
1441 ( <PLUS> {operator = OperatorIds.PLUS;}
1442 | <MINUS> {operator = OperatorIds.MINUS;})
1443 expr = UnaryExpression()
1444 {return new PrefixedUnaryExpression(expr,operator,pos);}
1446 expr = PreIncDecExpression()
1449 expr = UnaryExpressionNotPlusMinus()
1454 Expression PreIncDecExpression() :
1456 final Expression expr;
1458 final int pos = SimpleCharStream.getPosition();
1461 ( <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1462 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;})
1463 expr = PrimaryExpression()
1464 {return new PrefixedUnaryExpression(expr,operator,pos);}
1467 Expression UnaryExpressionNotPlusMinus() :
1469 final Expression expr;
1470 final int pos = SimpleCharStream.getPosition();
1473 LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1474 expr = CastExpression() {return expr;}
1475 | <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1476 | expr = PostfixExpression() {return expr;}
1477 | expr = Literal() {return expr;}
1478 | <LPAREN> expr = Expression()
1481 } catch (ParseException e) {
1482 errorMessage = "')' expected";
1484 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1485 errorEnd = SimpleCharStream.getPosition() + 1;
1491 CastExpression CastExpression() :
1493 final ConstantIdentifier type;
1494 final Expression expr;
1495 final int pos = SimpleCharStream.getPosition();
1500 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1501 <RPAREN> expr = UnaryExpression()
1502 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1505 Expression PostfixExpression() :
1507 final Expression expr;
1509 final int pos = SimpleCharStream.getPosition();
1512 expr = PrimaryExpression()
1513 [ <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1514 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}]
1516 if (operator == -1) {
1519 return new PostfixedUnaryExpression(expr,operator,pos);
1523 Expression PrimaryExpression() :
1525 final Token identifier;
1527 final int pos = SimpleCharStream.getPosition();
1530 expr = PrimaryPrefix()
1532 LOOKAHEAD(PrimarySuffix())
1533 expr = PrimarySuffix(expr))*
1536 expr = ArrayDeclarator()
1540 Expression PrimaryPrefix() :
1542 final Expression expr;
1545 final int pos = SimpleCharStream.getPosition();
1548 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1550 SimpleCharStream.getPosition());}
1551 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1554 | var = VariableDeclaratorId() {return new VariableDeclaration(currentSegment,
1557 SimpleCharStream.getPosition());}
1560 AbstractSuffixExpression PrimarySuffix(final Expression prefix) :
1562 final AbstractSuffixExpression suffix;
1563 final Expression expr;
1566 suffix = Arguments(prefix) {return suffix;}
1567 | suffix = VariableSuffix(prefix) {return suffix;}
1568 | <STATICCLASSACCESS> expr = ClassIdentifier()
1569 {suffix = new ClassAccess(prefix,
1571 ClassAccess.STATIC);
1576 * An array declarator.
1580 ArrayInitializer ArrayDeclarator() :
1582 final ArrayVariableDeclaration[] vars;
1583 final int pos = SimpleCharStream.getPosition();
1586 <ARRAY> vars = ArrayInitializer()
1587 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1590 PrefixedUnaryExpression classInstantiation() :
1593 final StringBuffer buff;
1594 final int pos = SimpleCharStream.getPosition();
1597 <NEW> expr = ClassIdentifier()
1599 {buff = new StringBuffer(expr.toStringExpression());}
1600 expr = PrimaryExpression()
1601 {buff.append(expr.toStringExpression());
1602 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1604 SimpleCharStream.getPosition());}
1606 {return new PrefixedUnaryExpression(expr,
1611 ConstantIdentifier ClassIdentifier():
1615 final int pos = SimpleCharStream.getPosition();
1616 final ConstantIdentifier type;
1619 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1621 SimpleCharStream.getPosition());}
1622 | type = Type() {return type;}
1623 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1625 SimpleCharStream.getPosition());}
1628 AbstractSuffixExpression VariableSuffix(final Expression prefix) :
1631 final int pos = SimpleCharStream.getPosition();
1632 Expression expression = null;
1637 expr = VariableName()
1638 } catch (ParseException e) {
1639 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1641 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1642 errorEnd = SimpleCharStream.getPosition() + 1;
1645 {return new ClassAccess(prefix,
1646 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1647 ClassAccess.NORMAL);}
1649 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1652 } catch (ParseException e) {
1653 errorMessage = "']' expected";
1655 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1656 errorEnd = SimpleCharStream.getPosition() + 1;
1659 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1668 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1669 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1670 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1671 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1672 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1673 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1674 | <TRUE> {pos = SimpleCharStream.getPosition();
1675 return new TrueLiteral(pos-4,pos);}
1676 | <FALSE> {pos = SimpleCharStream.getPosition();
1677 return new FalseLiteral(pos-4,pos);}
1678 | <NULL> {pos = SimpleCharStream.getPosition();
1679 return new NullLiteral(pos-4,pos);}
1682 FunctionCall Arguments(final Expression func) :
1684 Expression[] args = null;
1687 <LPAREN> [ args = ArgumentList() ]
1690 } catch (ParseException e) {
1691 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1693 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1694 errorEnd = SimpleCharStream.getPosition() + 1;
1697 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1701 * An argument list is a list of arguments separated by comma :
1702 * argumentDeclaration() (, argumentDeclaration)*
1703 * @return an array of arguments
1705 Expression[] ArgumentList() :
1708 final ArrayList list = new ArrayList();
1717 } catch (ParseException e) {
1718 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1720 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1721 errorEnd = SimpleCharStream.getPosition() + 1;
1726 final Expression[] arguments = new Expression[list.size()];
1727 list.toArray(arguments);
1732 * A Statement without break.
1734 Statement StatementNoBreak() :
1736 final Statement statement;
1741 statement = Expression()
1744 } catch (ParseException e) {
1745 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1746 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1748 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1749 errorEnd = SimpleCharStream.getPosition() + 1;
1755 statement = LabeledStatement() {return statement;}
1756 | statement = Block() {return statement;}
1757 | statement = EmptyStatement() {return statement;}
1758 | statement = StatementExpression()
1761 } catch (ParseException e) {
1762 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1764 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1765 errorEnd = SimpleCharStream.getPosition() + 1;
1769 | statement = SwitchStatement() {return statement;}
1770 | statement = IfStatement() {return statement;}
1771 | statement = WhileStatement() {return statement;}
1772 | statement = DoStatement() {return statement;}
1773 | statement = ForStatement() {return statement;}
1774 | statement = ForeachStatement() {return statement;}
1775 | statement = ContinueStatement() {return statement;}
1776 | statement = ReturnStatement() {return statement;}
1777 | statement = EchoStatement() {return statement;}
1778 | [token=<AT>] statement = IncludeStatement()
1779 {if (token != null) {
1780 ((InclusionStatement)statement).silent = true;
1783 | statement = StaticStatement() {return statement;}
1784 | statement = GlobalStatement() {return statement;}
1785 | statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
1788 Define defineStatement() :
1790 final int start = SimpleCharStream.getPosition();
1791 Expression defineName,defineValue;
1797 } catch (ParseException e) {
1798 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1800 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1801 errorEnd = SimpleCharStream.getPosition() + 1;
1802 processParseException(e);
1805 defineName = Expression()
1806 } catch (ParseException e) {
1807 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1809 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1810 errorEnd = SimpleCharStream.getPosition() + 1;
1815 } catch (ParseException e) {
1816 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1818 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1819 errorEnd = SimpleCharStream.getPosition() + 1;
1820 processParseException(e);
1823 defineValue = Expression()
1824 } catch (ParseException e) {
1825 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1827 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1828 errorEnd = SimpleCharStream.getPosition() + 1;
1833 } catch (ParseException e) {
1834 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1836 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1837 errorEnd = SimpleCharStream.getPosition() + 1;
1838 processParseException(e);
1840 {return new Define(currentSegment,
1844 SimpleCharStream.getPosition());}
1848 * A Normal statement.
1850 Statement Statement() :
1852 final Statement statement;
1855 statement = StatementNoBreak() {return statement;}
1856 | statement = BreakStatement() {return statement;}
1860 * An html block inside a php syntax.
1862 HTMLBlock htmlBlock() :
1864 final int startIndex = nodePtr;
1865 final AstNode[] blockNodes;
1869 <PHPEND> (phpEchoBlock())*
1871 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1872 } catch (ParseException e) {
1873 errorMessage = "unexpected end of file , '<?php' expected";
1875 errorStart = SimpleCharStream.getPosition();
1876 errorEnd = SimpleCharStream.getPosition();
1880 nbNodes = nodePtr - startIndex;
1881 blockNodes = new AstNode[nbNodes];
1882 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1883 nodePtr = startIndex;
1884 return new HTMLBlock(blockNodes);}
1888 * An include statement. It's "include" an expression;
1890 InclusionStatement IncludeStatement() :
1892 final Expression expr;
1894 final int pos = SimpleCharStream.getPosition();
1895 final InclusionStatement inclusionStatement;
1898 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1899 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1900 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1901 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1904 } catch (ParseException e) {
1905 if (errorMessage != null) {
1908 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1910 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1911 errorEnd = SimpleCharStream.getPosition() + 1;
1914 {inclusionStatement = new InclusionStatement(currentSegment,
1918 currentSegment.add(inclusionStatement);
1922 } catch (ParseException e) {
1923 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1925 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1926 errorEnd = SimpleCharStream.getPosition() + 1;
1929 {return inclusionStatement;}
1932 PrintExpression PrintExpression() :
1934 final Expression expr;
1935 final int pos = SimpleCharStream.getPosition();
1938 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1941 ListExpression ListExpression() :
1944 final Expression expression;
1945 final ArrayList list = new ArrayList();
1946 final int pos = SimpleCharStream.getPosition();
1952 } catch (ParseException e) {
1953 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1955 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1956 errorEnd = SimpleCharStream.getPosition() + 1;
1960 expr = VariableDeclaratorId()
1963 {if (expr == null) list.add(null);}
1967 } catch (ParseException e) {
1968 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1970 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1971 errorEnd = SimpleCharStream.getPosition() + 1;
1974 [expr = VariableDeclaratorId() {list.add(expr);}]
1978 } catch (ParseException e) {
1979 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1981 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1982 errorEnd = SimpleCharStream.getPosition() + 1;
1985 [ <ASSIGN> expression = Expression()
1987 final String[] strings = new String[list.size()];
1988 list.toArray(strings);
1989 return new ListExpression(strings,
1992 SimpleCharStream.getPosition());}
1995 final String[] strings = new String[list.size()];
1996 list.toArray(strings);
1997 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
2001 * An echo statement.
2002 * echo anyexpression (, otherexpression)*
2004 EchoStatement EchoStatement() :
2006 final ArrayList expressions = new ArrayList();
2008 final int pos = SimpleCharStream.getPosition();
2011 <ECHO> expr = Expression()
2012 {expressions.add(expr);}
2014 <COMMA> expr = Expression()
2015 {expressions.add(expr);}
2019 } catch (ParseException e) {
2020 if (e.currentToken.next.kind != 4) {
2021 errorMessage = "';' expected after 'echo' statement";
2023 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2024 errorEnd = SimpleCharStream.getPosition() + 1;
2028 {final Expression[] exprs = new Expression[expressions.size()];
2029 expressions.toArray(exprs);
2030 return new EchoStatement(exprs,pos);}
2033 GlobalStatement GlobalStatement() :
2035 final int pos = SimpleCharStream.getPosition();
2037 final ArrayList vars = new ArrayList();
2038 final GlobalStatement global;
2042 expr = VariableDeclaratorId()
2045 expr = VariableDeclaratorId()
2051 final String[] strings = new String[vars.size()];
2052 vars.toArray(strings);
2053 global = new GlobalStatement(currentSegment,
2056 SimpleCharStream.getPosition());
2057 currentSegment.add(global);
2059 } catch (ParseException e) {
2060 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2062 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2063 errorEnd = SimpleCharStream.getPosition() + 1;
2068 StaticStatement StaticStatement() :
2070 final int pos = SimpleCharStream.getPosition();
2071 final ArrayList vars = new ArrayList();
2072 VariableDeclaration expr;
2075 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2076 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2080 final String[] strings = new String[vars.size()];
2081 vars.toArray(strings);
2082 return new StaticStatement(strings,
2084 SimpleCharStream.getPosition());}
2085 } catch (ParseException e) {
2086 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2088 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2089 errorEnd = SimpleCharStream.getPosition() + 1;
2094 LabeledStatement LabeledStatement() :
2096 final int pos = SimpleCharStream.getPosition();
2098 final Statement statement;
2101 label = <IDENTIFIER> <COLON> statement = Statement()
2102 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2114 final int pos = SimpleCharStream.getPosition();
2115 final ArrayList list = new ArrayList();
2116 Statement statement;
2121 } catch (ParseException e) {
2122 errorMessage = "'{' expected";
2124 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2125 errorEnd = SimpleCharStream.getPosition() + 1;
2128 ( statement = BlockStatement() {list.add(statement);}
2129 | statement = htmlBlock() {list.add(statement);})*
2132 } catch (ParseException e) {
2133 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2135 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2136 errorEnd = SimpleCharStream.getPosition() + 1;
2140 final Statement[] statements = new Statement[list.size()];
2141 list.toArray(statements);
2142 return new Block(statements,pos,SimpleCharStream.getPosition());}
2145 Statement BlockStatement() :
2147 final Statement statement;
2150 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2152 | statement = ClassDeclaration() {return statement;}
2153 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2154 currentSegment.add((MethodDeclaration) statement);
2159 * A Block statement that will not contain any 'break'
2161 Statement BlockStatementNoBreak() :
2163 final Statement statement;
2166 statement = StatementNoBreak() {return statement;}
2167 | statement = ClassDeclaration() {return statement;}
2168 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2172 VariableDeclaration[] LocalVariableDeclaration() :
2174 final ArrayList list = new ArrayList();
2175 VariableDeclaration var;
2178 var = LocalVariableDeclarator()
2180 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2182 final VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2187 VariableDeclaration LocalVariableDeclarator() :
2189 final String varName;
2190 Expression initializer = null;
2191 final int pos = SimpleCharStream.getPosition();
2194 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2196 if (initializer == null) {
2197 return new VariableDeclaration(currentSegment,
2198 varName.toCharArray(),
2200 SimpleCharStream.getPosition());
2202 return new VariableDeclaration(currentSegment,
2203 varName.toCharArray(),
2209 EmptyStatement EmptyStatement() :
2215 {pos = SimpleCharStream.getPosition();
2216 return new EmptyStatement(pos-1,pos);}
2219 Expression StatementExpression() :
2221 final Expression expr,expr2;
2225 expr = PreIncDecExpression() {return expr;}
2227 expr = PrimaryExpression()
2228 [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
2229 OperatorIds.PLUS_PLUS,
2230 SimpleCharStream.getPosition());}
2231 | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
2232 OperatorIds.MINUS_MINUS,
2233 SimpleCharStream.getPosition());}
2234 | operator = AssignmentOperator() expr2 = Expression()
2235 {return new BinaryExpression(expr,expr2,operator);}
2240 SwitchStatement SwitchStatement() :
2242 final Expression variable;
2243 final AbstractCase[] cases;
2244 final int pos = SimpleCharStream.getPosition();
2250 } catch (ParseException e) {
2251 errorMessage = "'(' expected after 'switch'";
2253 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2254 errorEnd = SimpleCharStream.getPosition() + 1;
2258 variable = Expression()
2259 } catch (ParseException e) {
2260 if (errorMessage != null) {
2263 errorMessage = "expression expected";
2265 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2266 errorEnd = SimpleCharStream.getPosition() + 1;
2271 } catch (ParseException e) {
2272 errorMessage = "')' expected";
2274 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2275 errorEnd = SimpleCharStream.getPosition() + 1;
2278 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2279 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2282 AbstractCase[] switchStatementBrace() :
2285 final ArrayList cases = new ArrayList();
2289 ( cas = switchLabel0() {cases.add(cas);})*
2293 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2294 cases.toArray(abcase);
2296 } catch (ParseException e) {
2297 errorMessage = "'}' expected";
2299 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2300 errorEnd = SimpleCharStream.getPosition() + 1;
2305 * A Switch statement with : ... endswitch;
2306 * @param start the begin offset of the switch
2307 * @param end the end offset of the switch
2309 AbstractCase[] switchStatementColon(final int start, final int end) :
2312 final ArrayList cases = new ArrayList();
2317 setMarker(fileToParse,
2318 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2322 "Line " + token.beginLine);
2323 } catch (CoreException e) {
2324 PHPeclipsePlugin.log(e);
2326 ( cas = switchLabel0() {cases.add(cas);})*
2329 } catch (ParseException e) {
2330 errorMessage = "'endswitch' expected";
2332 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2333 errorEnd = SimpleCharStream.getPosition() + 1;
2339 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2340 cases.toArray(abcase);
2342 } catch (ParseException e) {
2343 errorMessage = "';' expected after 'endswitch' keyword";
2345 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2346 errorEnd = SimpleCharStream.getPosition() + 1;
2351 AbstractCase switchLabel0() :
2353 final Expression expr;
2354 Statement statement;
2355 final ArrayList stmts = new ArrayList();
2356 final int pos = SimpleCharStream.getPosition();
2359 expr = SwitchLabel()
2360 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2361 | statement = htmlBlock() {stmts.add(statement);})*
2362 [ statement = BreakStatement() {stmts.add(statement);}]
2364 final Statement[] stmtsArray = new Statement[stmts.size()];
2365 stmts.toArray(stmtsArray);
2366 if (expr == null) {//it's a default
2367 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2369 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2374 * case Expression() :
2376 * @return the if it was a case and null if not
2378 Expression SwitchLabel() :
2380 final Expression expr;
2386 } catch (ParseException e) {
2387 if (errorMessage != null) throw e;
2388 errorMessage = "expression expected after 'case' keyword";
2390 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2391 errorEnd = SimpleCharStream.getPosition() + 1;
2397 } catch (ParseException e) {
2398 errorMessage = "':' expected after case expression";
2400 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2401 errorEnd = SimpleCharStream.getPosition() + 1;
2409 } catch (ParseException e) {
2410 errorMessage = "':' expected after 'default' keyword";
2412 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2413 errorEnd = SimpleCharStream.getPosition() + 1;
2418 Break BreakStatement() :
2420 Expression expression = null;
2421 final int start = SimpleCharStream.getPosition();
2424 <BREAK> [ expression = Expression() ]
2427 } catch (ParseException e) {
2428 errorMessage = "';' expected after 'break' keyword";
2430 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2431 errorEnd = SimpleCharStream.getPosition() + 1;
2434 {return new Break(expression, start, SimpleCharStream.getPosition());}
2437 IfStatement IfStatement() :
2439 final int pos = SimpleCharStream.getPosition();
2440 final Expression condition;
2441 final IfStatement ifStatement;
2444 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2445 {return ifStatement;}
2449 Expression Condition(final String keyword) :
2451 final Expression condition;
2456 } catch (ParseException e) {
2457 errorMessage = "'(' expected after " + keyword + " keyword";
2459 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2460 errorEnd = errorStart +1;
2461 processParseException(e);
2463 condition = Expression()
2466 } catch (ParseException e) {
2467 errorMessage = "')' expected after " + keyword + " keyword";
2469 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2470 errorEnd = SimpleCharStream.getPosition() + 1;
2471 processParseException(e);
2476 IfStatement IfStatement0(final Expression condition, final int start,final int end) :
2478 Statement statement;
2479 final Statement stmt;
2480 final Statement[] statementsArray;
2481 ElseIf elseifStatement;
2482 Else elseStatement = null;
2483 final ArrayList stmts;
2484 final ArrayList elseIfList = new ArrayList();
2485 final ElseIf[] elseIfs;
2486 int pos = SimpleCharStream.getPosition();
2487 final int endStatements;
2491 {stmts = new ArrayList();}
2492 ( statement = Statement() {stmts.add(statement);}
2493 | statement = htmlBlock() {stmts.add(statement);})*
2494 {endStatements = SimpleCharStream.getPosition();}
2495 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2496 [elseStatement = ElseStatementColon()]
2499 setMarker(fileToParse,
2500 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2504 "Line " + token.beginLine);
2505 } catch (CoreException e) {
2506 PHPeclipsePlugin.log(e);
2510 } catch (ParseException e) {
2511 errorMessage = "'endif' expected";
2513 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2514 errorEnd = SimpleCharStream.getPosition() + 1;
2519 } catch (ParseException e) {
2520 errorMessage = "';' expected after 'endif' keyword";
2522 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2523 errorEnd = SimpleCharStream.getPosition() + 1;
2527 elseIfs = new ElseIf[elseIfList.size()];
2528 elseIfList.toArray(elseIfs);
2529 if (stmts.size() == 1) {
2530 return new IfStatement(condition,
2531 (Statement) stmts.get(0),
2535 SimpleCharStream.getPosition());
2537 statementsArray = new Statement[stmts.size()];
2538 stmts.toArray(statementsArray);
2539 return new IfStatement(condition,
2540 new Block(statementsArray,pos,endStatements),
2544 SimpleCharStream.getPosition());
2549 (stmt = Statement() | stmt = htmlBlock())
2550 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2554 {pos = SimpleCharStream.getPosition();}
2555 statement = Statement()
2556 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2557 } catch (ParseException e) {
2558 if (errorMessage != null) {
2561 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2563 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2564 errorEnd = SimpleCharStream.getPosition() + 1;
2569 elseIfs = new ElseIf[elseIfList.size()];
2570 elseIfList.toArray(elseIfs);
2571 return new IfStatement(condition,
2576 SimpleCharStream.getPosition());}
2579 ElseIf ElseIfStatementColon() :
2581 final Expression condition;
2582 Statement statement;
2583 final ArrayList list = new ArrayList();
2584 final int pos = SimpleCharStream.getPosition();
2587 <ELSEIF> condition = Condition("elseif")
2588 <COLON> ( statement = Statement() {list.add(statement);}
2589 | statement = htmlBlock() {list.add(statement);})*
2591 final Statement[] stmtsArray = new Statement[list.size()];
2592 list.toArray(stmtsArray);
2593 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2596 Else ElseStatementColon() :
2598 Statement statement;
2599 final ArrayList list = new ArrayList();
2600 final int pos = SimpleCharStream.getPosition();
2603 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2604 | statement = htmlBlock() {list.add(statement);})*
2606 final Statement[] stmtsArray = new Statement[list.size()];
2607 list.toArray(stmtsArray);
2608 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2611 ElseIf ElseIfStatement() :
2613 final Expression condition;
2614 final Statement statement;
2615 final ArrayList list = new ArrayList();
2616 final int pos = SimpleCharStream.getPosition();
2619 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2621 final Statement[] stmtsArray = new Statement[list.size()];
2622 list.toArray(stmtsArray);
2623 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2626 WhileStatement WhileStatement() :
2628 final Expression condition;
2629 final Statement action;
2630 final int pos = SimpleCharStream.getPosition();
2634 condition = Condition("while")
2635 action = WhileStatement0(pos,pos + 5)
2636 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2639 Statement WhileStatement0(final int start, final int end) :
2641 Statement statement;
2642 final ArrayList stmts = new ArrayList();
2643 final int pos = SimpleCharStream.getPosition();
2646 <COLON> (statement = Statement() {stmts.add(statement);})*
2648 setMarker(fileToParse,
2649 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2653 "Line " + token.beginLine);
2654 } catch (CoreException e) {
2655 PHPeclipsePlugin.log(e);
2659 } catch (ParseException e) {
2660 errorMessage = "'endwhile' expected";
2662 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2663 errorEnd = SimpleCharStream.getPosition() + 1;
2669 final Statement[] stmtsArray = new Statement[stmts.size()];
2670 stmts.toArray(stmtsArray);
2671 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2672 } catch (ParseException e) {
2673 errorMessage = "';' expected after 'endwhile' keyword";
2675 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2676 errorEnd = SimpleCharStream.getPosition() + 1;
2680 statement = Statement()
2684 DoStatement DoStatement() :
2686 final Statement action;
2687 final Expression condition;
2688 final int pos = SimpleCharStream.getPosition();
2691 <DO> action = Statement() <WHILE> condition = Condition("while")
2694 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2695 } catch (ParseException e) {
2696 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2698 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2699 errorEnd = SimpleCharStream.getPosition() + 1;
2704 ForeachStatement ForeachStatement() :
2706 Statement statement;
2707 Expression expression;
2708 final int pos = SimpleCharStream.getPosition();
2709 ArrayVariableDeclaration variable;
2715 } catch (ParseException e) {
2716 errorMessage = "'(' expected after 'foreach' keyword";
2718 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2719 errorEnd = SimpleCharStream.getPosition() + 1;
2723 expression = Expression()
2724 } catch (ParseException e) {
2725 errorMessage = "variable expected";
2727 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2728 errorEnd = SimpleCharStream.getPosition() + 1;
2733 } catch (ParseException e) {
2734 errorMessage = "'as' expected";
2736 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2737 errorEnd = SimpleCharStream.getPosition() + 1;
2741 variable = ArrayVariable()
2742 } catch (ParseException e) {
2743 errorMessage = "variable expected";
2745 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2746 errorEnd = SimpleCharStream.getPosition() + 1;
2751 } catch (ParseException e) {
2752 errorMessage = "')' expected after 'foreach' keyword";
2754 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2755 errorEnd = SimpleCharStream.getPosition() + 1;
2759 statement = Statement()
2760 } catch (ParseException e) {
2761 if (errorMessage != null) throw e;
2762 errorMessage = "statement expected";
2764 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2765 errorEnd = SimpleCharStream.getPosition() + 1;
2768 {return new ForeachStatement(expression,
2772 SimpleCharStream.getPosition());}
2776 ForStatement ForStatement() :
2779 final int pos = SimpleCharStream.getPosition();
2780 Expression[] initializations = null;
2781 Expression condition = null;
2782 Expression[] increments = null;
2784 final ArrayList list = new ArrayList();
2785 final int startBlock, endBlock;
2791 } catch (ParseException e) {
2792 errorMessage = "'(' expected after 'for' keyword";
2794 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2795 errorEnd = SimpleCharStream.getPosition() + 1;
2798 [ initializations = ForInit() ] <SEMICOLON>
2799 [ condition = Expression() ] <SEMICOLON>
2800 [ increments = StatementExpressionList() ] <RPAREN>
2802 action = Statement()
2803 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2806 {startBlock = SimpleCharStream.getPosition();}
2807 (action = Statement() {list.add(action);})*
2810 setMarker(fileToParse,
2811 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2813 pos+token.image.length(),
2815 "Line " + token.beginLine);
2816 } catch (CoreException e) {
2817 PHPeclipsePlugin.log(e);
2820 {endBlock = SimpleCharStream.getPosition();}
2823 } catch (ParseException e) {
2824 errorMessage = "'endfor' expected";
2826 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2827 errorEnd = SimpleCharStream.getPosition() + 1;
2833 final Statement[] stmtsArray = new Statement[list.size()];
2834 list.toArray(stmtsArray);
2835 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2836 } catch (ParseException e) {
2837 errorMessage = "';' expected after 'endfor' keyword";
2839 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2840 errorEnd = SimpleCharStream.getPosition() + 1;
2846 Expression[] ForInit() :
2848 final Expression[] exprs;
2851 LOOKAHEAD(LocalVariableDeclaration())
2852 exprs = LocalVariableDeclaration()
2855 exprs = StatementExpressionList()
2859 Expression[] StatementExpressionList() :
2861 final ArrayList list = new ArrayList();
2862 final Expression expr;
2865 expr = StatementExpression() {list.add(expr);}
2866 (<COMMA> StatementExpression() {list.add(expr);})*
2868 final Expression[] exprsArray = new Expression[list.size()];
2869 list.toArray(exprsArray);
2873 Continue ContinueStatement() :
2875 Expression expr = null;
2876 final int pos = SimpleCharStream.getPosition();
2879 <CONTINUE> [ expr = Expression() ]
2882 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2883 } catch (ParseException e) {
2884 errorMessage = "';' expected after 'continue' statement";
2886 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2887 errorEnd = SimpleCharStream.getPosition() + 1;
2892 ReturnStatement ReturnStatement() :
2894 Expression expr = null;
2895 final int pos = SimpleCharStream.getPosition();
2898 <RETURN> [ expr = Expression() ]
2901 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2902 } catch (ParseException e) {
2903 errorMessage = "';' expected after 'return' statement";
2905 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2906 errorEnd = SimpleCharStream.getPosition() + 1;