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()
1141 [ assignOperator = AssignmentOperator()
1143 {final int errorStart = SimpleCharStream.getPosition();}
1144 initializer = Expression()
1145 } catch (ParseException e) {
1146 if (errorMessage != null) {
1149 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1151 errorEnd = SimpleCharStream.getPosition();
1156 if (assignOperator == -1) return expr;
1157 return new VarAssignation(expr,
1161 SimpleCharStream.getPosition());
1163 | expr = ExpressionWBang() {return expr;}
1166 Expression ExpressionWBang() :
1168 final Expression expr;
1169 final int pos = SimpleCharStream.getPosition();
1172 <BANG> expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1173 | expr = ExpressionNoBang() {return expr;}
1176 Expression ExpressionNoBang() :
1178 final Expression expr;
1181 expr = PrintExpression() {return expr;}
1182 | expr = ListExpression() {return expr;}
1186 * Any assignement operator.
1187 * @return the assignement operator id
1189 int AssignmentOperator() :
1192 <ASSIGN> {return VarAssignation.EQUAL;}
1193 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1194 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1195 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1196 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1197 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1198 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1199 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1200 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1201 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1202 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1203 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1204 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1207 Expression ConditionalExpression() :
1209 final Expression expr;
1210 Expression expr2 = null;
1211 Expression expr3 = null;
1214 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1216 if (expr3 == null) {
1219 return new ConditionalExpression(expr,expr2,expr3);
1223 Expression ConditionalOrExpression() :
1225 Expression expr,expr2;
1229 expr = ConditionalAndExpression()
1232 <OR_OR> {operator = OperatorIds.OR_OR;}
1233 | <_ORL> {operator = OperatorIds.ORL;}
1234 ) expr2 = ConditionalAndExpression()
1236 expr = new BinaryExpression(expr,expr2,operator);
1242 Expression ConditionalAndExpression() :
1244 Expression expr,expr2;
1248 expr = ConcatExpression()
1250 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1251 | <_ANDL> {operator = OperatorIds.ANDL;})
1252 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1257 Expression ConcatExpression() :
1259 Expression expr,expr2;
1262 expr = InclusiveOrExpression()
1264 <DOT> expr2 = InclusiveOrExpression()
1265 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1270 Expression InclusiveOrExpression() :
1272 Expression expr,expr2;
1275 expr = ExclusiveOrExpression()
1276 (<BIT_OR> expr2 = ExclusiveOrExpression()
1277 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1282 Expression ExclusiveOrExpression() :
1284 Expression expr,expr2;
1287 expr = AndExpression()
1289 <XOR> expr2 = AndExpression()
1290 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1295 Expression AndExpression() :
1297 Expression expr,expr2;
1300 expr = EqualityExpression()
1302 <BIT_AND> expr2 = EqualityExpression()
1303 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1308 Expression EqualityExpression() :
1310 Expression expr,expr2;
1314 expr = RelationalExpression()
1316 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1317 | <DIF> {operator = OperatorIds.DIF;}
1318 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1319 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1320 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1323 expr2 = RelationalExpression()
1324 } catch (ParseException e) {
1325 if (errorMessage != null) {
1328 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1330 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1331 errorEnd = SimpleCharStream.getPosition() + 1;
1335 expr = new BinaryExpression(expr,expr2,operator);
1341 Expression RelationalExpression() :
1343 Expression expr,expr2;
1347 expr = ShiftExpression()
1349 ( <LT> {operator = OperatorIds.LESS;}
1350 | <GT> {operator = OperatorIds.GREATER;}
1351 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1352 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1353 expr2 = ShiftExpression()
1354 {expr = new BinaryExpression(expr,expr2,operator);}
1359 Expression ShiftExpression() :
1361 Expression expr,expr2;
1365 expr = AdditiveExpression()
1367 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1368 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1369 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1370 expr2 = AdditiveExpression()
1371 {expr = new BinaryExpression(expr,expr2,operator);}
1376 Expression AdditiveExpression() :
1378 Expression expr,expr2;
1382 expr = MultiplicativeExpression()
1384 ( <PLUS> {operator = OperatorIds.PLUS;}
1385 | <MINUS> {operator = OperatorIds.MINUS;} )
1386 expr2 = MultiplicativeExpression()
1387 {expr = new BinaryExpression(expr,expr2,operator);}
1392 Expression MultiplicativeExpression() :
1394 Expression expr,expr2;
1399 expr = UnaryExpression()
1400 } catch (ParseException e) {
1401 if (errorMessage != null) throw e;
1402 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1404 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1405 errorEnd = SimpleCharStream.getPosition() + 1;
1409 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1410 | <SLASH> {operator = OperatorIds.DIVIDE;}
1411 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1412 expr2 = UnaryExpression()
1413 {expr = new BinaryExpression(expr,expr2,operator);}
1419 * An unary expression starting with @, & or nothing
1421 Expression UnaryExpression() :
1423 final Expression expr;
1424 final int pos = SimpleCharStream.getPosition();
1427 <BIT_AND> expr = UnaryExpressionNoPrefix()
1428 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1430 expr = AtUnaryExpression() {return expr;}
1433 Expression AtUnaryExpression() :
1435 final Expression expr;
1436 final int pos = SimpleCharStream.getPosition();
1440 expr = AtUnaryExpression()
1441 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1443 expr = UnaryExpressionNoPrefix()
1448 Expression UnaryExpressionNoPrefix() :
1450 final Expression expr;
1452 final int pos = SimpleCharStream.getPosition();
1455 ( <PLUS> {operator = OperatorIds.PLUS;}
1456 | <MINUS> {operator = OperatorIds.MINUS;})
1457 expr = UnaryExpression()
1458 {return new PrefixedUnaryExpression(expr,operator,pos);}
1460 expr = PreIncDecExpression()
1463 expr = UnaryExpressionNotPlusMinus()
1468 Expression PreIncDecExpression() :
1470 final Expression expr;
1472 final int pos = SimpleCharStream.getPosition();
1475 ( <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1476 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;})
1477 expr = PrimaryExpression()
1478 {return new PrefixedUnaryExpression(expr,operator,pos);}
1481 Expression UnaryExpressionNotPlusMinus() :
1483 final Expression expr;
1484 final int pos = SimpleCharStream.getPosition();
1487 LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1488 expr = CastExpression() {return expr;}
1489 | <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1490 | expr = PostfixExpression() {return expr;}
1491 | expr = Literal() {return expr;}
1492 | <LPAREN> expr = Expression()
1495 } catch (ParseException e) {
1496 errorMessage = "')' expected";
1498 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1499 errorEnd = SimpleCharStream.getPosition() + 1;
1505 CastExpression CastExpression() :
1507 final ConstantIdentifier type;
1508 final Expression expr;
1509 final int pos = SimpleCharStream.getPosition();
1514 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1515 <RPAREN> expr = UnaryExpression()
1516 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1519 Expression PostfixExpression() :
1521 final Expression expr;
1523 final int pos = SimpleCharStream.getPosition();
1526 expr = PrimaryExpression()
1527 [ <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1528 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}]
1530 if (operator == -1) {
1533 return new PostfixedUnaryExpression(expr,operator,pos);
1537 Expression PrimaryExpression() :
1539 final Token identifier;
1541 final int pos = SimpleCharStream.getPosition();
1544 expr = PrimaryPrefix()
1546 LOOKAHEAD(PrimarySuffix())
1547 expr = PrimarySuffix(expr))*
1550 expr = ArrayDeclarator()
1554 Expression PrimaryPrefix() :
1556 final Expression expr;
1559 final int pos = SimpleCharStream.getPosition();
1562 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1564 SimpleCharStream.getPosition());}
1565 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1568 | var = VariableDeclaratorId() {return new VariableDeclaration(currentSegment,
1571 SimpleCharStream.getPosition());}
1574 AbstractSuffixExpression PrimarySuffix(final Expression prefix) :
1576 final AbstractSuffixExpression suffix;
1577 final Expression expr;
1580 suffix = Arguments(prefix) {return suffix;}
1581 | suffix = VariableSuffix(prefix) {return suffix;}
1582 | <STATICCLASSACCESS> expr = ClassIdentifier()
1583 {suffix = new ClassAccess(prefix,
1585 ClassAccess.STATIC);
1590 * An array declarator.
1594 ArrayInitializer ArrayDeclarator() :
1596 final ArrayVariableDeclaration[] vars;
1597 final int pos = SimpleCharStream.getPosition();
1600 <ARRAY> vars = ArrayInitializer()
1601 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1604 PrefixedUnaryExpression classInstantiation() :
1607 final StringBuffer buff;
1608 final int pos = SimpleCharStream.getPosition();
1611 <NEW> expr = ClassIdentifier()
1613 {buff = new StringBuffer(expr.toStringExpression());}
1614 expr = PrimaryExpression()
1615 {buff.append(expr.toStringExpression());
1616 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1618 SimpleCharStream.getPosition());}
1620 {return new PrefixedUnaryExpression(expr,
1625 ConstantIdentifier ClassIdentifier():
1629 final int pos = SimpleCharStream.getPosition();
1630 final ConstantIdentifier type;
1633 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1635 SimpleCharStream.getPosition());}
1636 | type = Type() {return type;}
1637 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1639 SimpleCharStream.getPosition());}
1642 AbstractSuffixExpression VariableSuffix(final Expression prefix) :
1645 final int pos = SimpleCharStream.getPosition();
1646 Expression expression = null;
1651 expr = VariableName()
1652 } catch (ParseException e) {
1653 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1655 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1656 errorEnd = SimpleCharStream.getPosition() + 1;
1659 {return new ClassAccess(prefix,
1660 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1661 ClassAccess.NORMAL);}
1663 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1666 } catch (ParseException e) {
1667 errorMessage = "']' expected";
1669 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1670 errorEnd = SimpleCharStream.getPosition() + 1;
1673 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1682 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1683 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1684 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1685 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1686 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1687 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1688 | <TRUE> {pos = SimpleCharStream.getPosition();
1689 return new TrueLiteral(pos-4,pos);}
1690 | <FALSE> {pos = SimpleCharStream.getPosition();
1691 return new FalseLiteral(pos-4,pos);}
1692 | <NULL> {pos = SimpleCharStream.getPosition();
1693 return new NullLiteral(pos-4,pos);}
1696 FunctionCall Arguments(final Expression func) :
1698 Expression[] args = null;
1701 <LPAREN> [ args = ArgumentList() ]
1704 } catch (ParseException e) {
1705 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1707 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1708 errorEnd = SimpleCharStream.getPosition() + 1;
1711 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1715 * An argument list is a list of arguments separated by comma :
1716 * argumentDeclaration() (, argumentDeclaration)*
1717 * @return an array of arguments
1719 Expression[] ArgumentList() :
1722 final ArrayList list = new ArrayList();
1731 } catch (ParseException e) {
1732 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1734 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1735 errorEnd = SimpleCharStream.getPosition() + 1;
1740 final Expression[] arguments = new Expression[list.size()];
1741 list.toArray(arguments);
1746 * A Statement without break.
1748 Statement StatementNoBreak() :
1750 final Statement statement;
1755 statement = Expression()
1758 } catch (ParseException e) {
1759 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1760 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1762 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1763 errorEnd = SimpleCharStream.getPosition() + 1;
1769 statement = LabeledStatement() {return statement;}
1770 | statement = Block() {return statement;}
1771 | statement = EmptyStatement() {return statement;}
1772 | statement = StatementExpression()
1775 } catch (ParseException e) {
1776 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1778 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1779 errorEnd = SimpleCharStream.getPosition() + 1;
1783 | statement = SwitchStatement() {return statement;}
1784 | statement = IfStatement() {return statement;}
1785 | statement = WhileStatement() {return statement;}
1786 | statement = DoStatement() {return statement;}
1787 | statement = ForStatement() {return statement;}
1788 | statement = ForeachStatement() {return statement;}
1789 | statement = ContinueStatement() {return statement;}
1790 | statement = ReturnStatement() {return statement;}
1791 | statement = EchoStatement() {return statement;}
1792 | [token=<AT>] statement = IncludeStatement()
1793 {if (token != null) {
1794 ((InclusionStatement)statement).silent = true;
1797 | statement = StaticStatement() {return statement;}
1798 | statement = GlobalStatement() {return statement;}
1799 | statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
1802 Define defineStatement() :
1804 final int start = SimpleCharStream.getPosition();
1805 Expression defineName,defineValue;
1811 } catch (ParseException e) {
1812 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1814 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1815 errorEnd = SimpleCharStream.getPosition() + 1;
1816 processParseException(e);
1819 defineName = Expression()
1820 } catch (ParseException e) {
1821 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1823 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1824 errorEnd = SimpleCharStream.getPosition() + 1;
1829 } catch (ParseException e) {
1830 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1832 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1833 errorEnd = SimpleCharStream.getPosition() + 1;
1834 processParseException(e);
1837 defineValue = Expression()
1838 } catch (ParseException e) {
1839 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1841 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1842 errorEnd = SimpleCharStream.getPosition() + 1;
1847 } catch (ParseException e) {
1848 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1850 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1851 errorEnd = SimpleCharStream.getPosition() + 1;
1852 processParseException(e);
1854 {return new Define(currentSegment,
1858 SimpleCharStream.getPosition());}
1862 * A Normal statement.
1864 Statement Statement() :
1866 final Statement statement;
1869 statement = StatementNoBreak() {return statement;}
1870 | statement = BreakStatement() {return statement;}
1874 * An html block inside a php syntax.
1876 HTMLBlock htmlBlock() :
1878 final int startIndex = nodePtr;
1879 final AstNode[] blockNodes;
1883 <PHPEND> (phpEchoBlock())*
1885 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1886 } catch (ParseException e) {
1887 errorMessage = "unexpected end of file , '<?php' expected";
1889 errorStart = SimpleCharStream.getPosition();
1890 errorEnd = SimpleCharStream.getPosition();
1894 nbNodes = nodePtr - startIndex;
1895 blockNodes = new AstNode[nbNodes];
1896 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1897 nodePtr = startIndex;
1898 return new HTMLBlock(blockNodes);}
1902 * An include statement. It's "include" an expression;
1904 InclusionStatement IncludeStatement() :
1906 final Expression expr;
1908 final int pos = SimpleCharStream.getPosition();
1909 final InclusionStatement inclusionStatement;
1912 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1913 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1914 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1915 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1918 } catch (ParseException e) {
1919 if (errorMessage != null) {
1922 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1924 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1925 errorEnd = SimpleCharStream.getPosition() + 1;
1928 {inclusionStatement = new InclusionStatement(currentSegment,
1932 currentSegment.add(inclusionStatement);
1936 } catch (ParseException e) {
1937 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1939 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1940 errorEnd = SimpleCharStream.getPosition() + 1;
1943 {return inclusionStatement;}
1946 PrintExpression PrintExpression() :
1948 final Expression expr;
1949 final int pos = SimpleCharStream.getPosition();
1952 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1955 ListExpression ListExpression() :
1958 final Expression expression;
1959 final ArrayList list = new ArrayList();
1960 final int pos = SimpleCharStream.getPosition();
1966 } catch (ParseException e) {
1967 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1969 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1970 errorEnd = SimpleCharStream.getPosition() + 1;
1974 expr = VariableDeclaratorId()
1977 {if (expr == null) list.add(null);}
1981 } catch (ParseException e) {
1982 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1984 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1985 errorEnd = SimpleCharStream.getPosition() + 1;
1988 [expr = VariableDeclaratorId() {list.add(expr);}]
1992 } catch (ParseException e) {
1993 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1995 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1996 errorEnd = SimpleCharStream.getPosition() + 1;
1999 [ <ASSIGN> expression = Expression()
2001 final String[] strings = new String[list.size()];
2002 list.toArray(strings);
2003 return new ListExpression(strings,
2006 SimpleCharStream.getPosition());}
2009 final String[] strings = new String[list.size()];
2010 list.toArray(strings);
2011 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
2015 * An echo statement.
2016 * echo anyexpression (, otherexpression)*
2018 EchoStatement EchoStatement() :
2020 final ArrayList expressions = new ArrayList();
2022 final int pos = SimpleCharStream.getPosition();
2025 <ECHO> expr = Expression()
2026 {expressions.add(expr);}
2028 <COMMA> expr = Expression()
2029 {expressions.add(expr);}
2033 } catch (ParseException e) {
2034 if (e.currentToken.next.kind != 4) {
2035 errorMessage = "';' expected after 'echo' statement";
2037 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2038 errorEnd = SimpleCharStream.getPosition() + 1;
2042 {final Expression[] exprs = new Expression[expressions.size()];
2043 expressions.toArray(exprs);
2044 return new EchoStatement(exprs,pos);}
2047 GlobalStatement GlobalStatement() :
2049 final int pos = SimpleCharStream.getPosition();
2051 final ArrayList vars = new ArrayList();
2052 final GlobalStatement global;
2056 expr = VariableDeclaratorId()
2059 expr = VariableDeclaratorId()
2065 final String[] strings = new String[vars.size()];
2066 vars.toArray(strings);
2067 global = new GlobalStatement(currentSegment,
2070 SimpleCharStream.getPosition());
2071 currentSegment.add(global);
2073 } catch (ParseException e) {
2074 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2076 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2077 errorEnd = SimpleCharStream.getPosition() + 1;
2082 StaticStatement StaticStatement() :
2084 final int pos = SimpleCharStream.getPosition();
2085 final ArrayList vars = new ArrayList();
2086 VariableDeclaration expr;
2089 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2090 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2094 final String[] strings = new String[vars.size()];
2095 vars.toArray(strings);
2096 return new StaticStatement(strings,
2098 SimpleCharStream.getPosition());}
2099 } catch (ParseException e) {
2100 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2102 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2103 errorEnd = SimpleCharStream.getPosition() + 1;
2108 LabeledStatement LabeledStatement() :
2110 final int pos = SimpleCharStream.getPosition();
2112 final Statement statement;
2115 label = <IDENTIFIER> <COLON> statement = Statement()
2116 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2128 final int pos = SimpleCharStream.getPosition();
2129 final ArrayList list = new ArrayList();
2130 Statement statement;
2135 } catch (ParseException e) {
2136 errorMessage = "'{' expected";
2138 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2139 errorEnd = SimpleCharStream.getPosition() + 1;
2142 ( statement = BlockStatement() {list.add(statement);}
2143 | statement = htmlBlock() {list.add(statement);})*
2146 } catch (ParseException e) {
2147 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2149 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2150 errorEnd = SimpleCharStream.getPosition() + 1;
2154 final Statement[] statements = new Statement[list.size()];
2155 list.toArray(statements);
2156 return new Block(statements,pos,SimpleCharStream.getPosition());}
2159 Statement BlockStatement() :
2161 final Statement statement;
2164 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2166 | statement = ClassDeclaration() {return statement;}
2167 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2168 currentSegment.add((MethodDeclaration) statement);
2173 * A Block statement that will not contain any 'break'
2175 Statement BlockStatementNoBreak() :
2177 final Statement statement;
2180 statement = StatementNoBreak() {return statement;}
2181 | statement = ClassDeclaration() {return statement;}
2182 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2186 VariableDeclaration[] LocalVariableDeclaration() :
2188 final ArrayList list = new ArrayList();
2189 VariableDeclaration var;
2192 var = LocalVariableDeclarator()
2194 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2196 final VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2201 VariableDeclaration LocalVariableDeclarator() :
2203 final String varName;
2204 Expression initializer = null;
2205 final int pos = SimpleCharStream.getPosition();
2208 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2210 if (initializer == null) {
2211 return new VariableDeclaration(currentSegment,
2212 varName.toCharArray(),
2214 SimpleCharStream.getPosition());
2216 return new VariableDeclaration(currentSegment,
2217 varName.toCharArray(),
2223 EmptyStatement EmptyStatement() :
2229 {pos = SimpleCharStream.getPosition();
2230 return new EmptyStatement(pos-1,pos);}
2233 Expression StatementExpression() :
2235 final Expression expr,expr2;
2239 expr = PreIncDecExpression() {return expr;}
2241 expr = PrimaryExpression()
2242 [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
2243 OperatorIds.PLUS_PLUS,
2244 SimpleCharStream.getPosition());}
2245 | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
2246 OperatorIds.MINUS_MINUS,
2247 SimpleCharStream.getPosition());}
2248 | operator = AssignmentOperator() expr2 = Expression()
2249 {return new BinaryExpression(expr,expr2,operator);}
2254 SwitchStatement SwitchStatement() :
2256 final Expression variable;
2257 final AbstractCase[] cases;
2258 final int pos = SimpleCharStream.getPosition();
2264 } catch (ParseException e) {
2265 errorMessage = "'(' expected after 'switch'";
2267 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2268 errorEnd = SimpleCharStream.getPosition() + 1;
2272 variable = Expression()
2273 } catch (ParseException e) {
2274 if (errorMessage != null) {
2277 errorMessage = "expression expected";
2279 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2280 errorEnd = SimpleCharStream.getPosition() + 1;
2285 } catch (ParseException e) {
2286 errorMessage = "')' expected";
2288 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2289 errorEnd = SimpleCharStream.getPosition() + 1;
2292 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2293 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2296 AbstractCase[] switchStatementBrace() :
2299 final ArrayList cases = new ArrayList();
2303 ( cas = switchLabel0() {cases.add(cas);})*
2307 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2308 cases.toArray(abcase);
2310 } catch (ParseException e) {
2311 errorMessage = "'}' expected";
2313 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2314 errorEnd = SimpleCharStream.getPosition() + 1;
2319 * A Switch statement with : ... endswitch;
2320 * @param start the begin offset of the switch
2321 * @param end the end offset of the switch
2323 AbstractCase[] switchStatementColon(final int start, final int end) :
2326 final ArrayList cases = new ArrayList();
2331 setMarker(fileToParse,
2332 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2336 "Line " + token.beginLine);
2337 } catch (CoreException e) {
2338 PHPeclipsePlugin.log(e);
2340 ( cas = switchLabel0() {cases.add(cas);})*
2343 } catch (ParseException e) {
2344 errorMessage = "'endswitch' expected";
2346 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2347 errorEnd = SimpleCharStream.getPosition() + 1;
2353 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2354 cases.toArray(abcase);
2356 } catch (ParseException e) {
2357 errorMessage = "';' expected after 'endswitch' keyword";
2359 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2360 errorEnd = SimpleCharStream.getPosition() + 1;
2365 AbstractCase switchLabel0() :
2367 final Expression expr;
2368 Statement statement;
2369 final ArrayList stmts = new ArrayList();
2370 final int pos = SimpleCharStream.getPosition();
2373 expr = SwitchLabel()
2374 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2375 | statement = htmlBlock() {stmts.add(statement);})*
2376 [ statement = BreakStatement() {stmts.add(statement);}]
2378 final Statement[] stmtsArray = new Statement[stmts.size()];
2379 stmts.toArray(stmtsArray);
2380 if (expr == null) {//it's a default
2381 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2383 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2388 * case Expression() :
2390 * @return the if it was a case and null if not
2392 Expression SwitchLabel() :
2394 final Expression expr;
2400 } catch (ParseException e) {
2401 if (errorMessage != null) throw e;
2402 errorMessage = "expression expected after 'case' keyword";
2404 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2405 errorEnd = SimpleCharStream.getPosition() + 1;
2411 } catch (ParseException e) {
2412 errorMessage = "':' expected after case expression";
2414 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2415 errorEnd = SimpleCharStream.getPosition() + 1;
2423 } catch (ParseException e) {
2424 errorMessage = "':' expected after 'default' keyword";
2426 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2427 errorEnd = SimpleCharStream.getPosition() + 1;
2432 Break BreakStatement() :
2434 Expression expression = null;
2435 final int start = SimpleCharStream.getPosition();
2438 <BREAK> [ expression = Expression() ]
2441 } catch (ParseException e) {
2442 errorMessage = "';' expected after 'break' keyword";
2444 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2445 errorEnd = SimpleCharStream.getPosition() + 1;
2448 {return new Break(expression, start, SimpleCharStream.getPosition());}
2451 IfStatement IfStatement() :
2453 final int pos = SimpleCharStream.getPosition();
2454 final Expression condition;
2455 final IfStatement ifStatement;
2458 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2459 {return ifStatement;}
2463 Expression Condition(final String keyword) :
2465 final Expression condition;
2470 } catch (ParseException e) {
2471 errorMessage = "'(' expected after " + keyword + " keyword";
2473 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2474 errorEnd = errorStart +1;
2475 processParseException(e);
2477 condition = Expression()
2480 } catch (ParseException e) {
2481 errorMessage = "')' expected after " + keyword + " keyword";
2483 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2484 errorEnd = SimpleCharStream.getPosition() + 1;
2485 processParseException(e);
2490 IfStatement IfStatement0(final Expression condition, final int start,final int end) :
2492 Statement statement;
2493 final Statement stmt;
2494 final Statement[] statementsArray;
2495 ElseIf elseifStatement;
2496 Else elseStatement = null;
2497 final ArrayList stmts;
2498 final ArrayList elseIfList = new ArrayList();
2499 final ElseIf[] elseIfs;
2500 int pos = SimpleCharStream.getPosition();
2501 final int endStatements;
2505 {stmts = new ArrayList();}
2506 ( statement = Statement() {stmts.add(statement);}
2507 | statement = htmlBlock() {stmts.add(statement);})*
2508 {endStatements = SimpleCharStream.getPosition();}
2509 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2510 [elseStatement = ElseStatementColon()]
2513 setMarker(fileToParse,
2514 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2518 "Line " + token.beginLine);
2519 } catch (CoreException e) {
2520 PHPeclipsePlugin.log(e);
2524 } catch (ParseException e) {
2525 errorMessage = "'endif' expected";
2527 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2528 errorEnd = SimpleCharStream.getPosition() + 1;
2533 } catch (ParseException e) {
2534 errorMessage = "';' expected after 'endif' keyword";
2536 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2537 errorEnd = SimpleCharStream.getPosition() + 1;
2541 elseIfs = new ElseIf[elseIfList.size()];
2542 elseIfList.toArray(elseIfs);
2543 if (stmts.size() == 1) {
2544 return new IfStatement(condition,
2545 (Statement) stmts.get(0),
2549 SimpleCharStream.getPosition());
2551 statementsArray = new Statement[stmts.size()];
2552 stmts.toArray(statementsArray);
2553 return new IfStatement(condition,
2554 new Block(statementsArray,pos,endStatements),
2558 SimpleCharStream.getPosition());
2563 (stmt = Statement() | stmt = htmlBlock())
2564 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2568 {pos = SimpleCharStream.getPosition();}
2569 statement = Statement()
2570 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2571 } catch (ParseException e) {
2572 if (errorMessage != null) {
2575 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2577 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2578 errorEnd = SimpleCharStream.getPosition() + 1;
2583 elseIfs = new ElseIf[elseIfList.size()];
2584 elseIfList.toArray(elseIfs);
2585 return new IfStatement(condition,
2590 SimpleCharStream.getPosition());}
2593 ElseIf ElseIfStatementColon() :
2595 final Expression condition;
2596 Statement statement;
2597 final ArrayList list = new ArrayList();
2598 final int pos = SimpleCharStream.getPosition();
2601 <ELSEIF> condition = Condition("elseif")
2602 <COLON> ( statement = Statement() {list.add(statement);}
2603 | statement = htmlBlock() {list.add(statement);})*
2605 final Statement[] stmtsArray = new Statement[list.size()];
2606 list.toArray(stmtsArray);
2607 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2610 Else ElseStatementColon() :
2612 Statement statement;
2613 final ArrayList list = new ArrayList();
2614 final int pos = SimpleCharStream.getPosition();
2617 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2618 | statement = htmlBlock() {list.add(statement);})*
2620 final Statement[] stmtsArray = new Statement[list.size()];
2621 list.toArray(stmtsArray);
2622 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2625 ElseIf ElseIfStatement() :
2627 final Expression condition;
2628 final Statement statement;
2629 final ArrayList list = new ArrayList();
2630 final int pos = SimpleCharStream.getPosition();
2633 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2635 final Statement[] stmtsArray = new Statement[list.size()];
2636 list.toArray(stmtsArray);
2637 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2640 WhileStatement WhileStatement() :
2642 final Expression condition;
2643 final Statement action;
2644 final int pos = SimpleCharStream.getPosition();
2648 condition = Condition("while")
2649 action = WhileStatement0(pos,pos + 5)
2650 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2653 Statement WhileStatement0(final int start, final int end) :
2655 Statement statement;
2656 final ArrayList stmts = new ArrayList();
2657 final int pos = SimpleCharStream.getPosition();
2660 <COLON> (statement = Statement() {stmts.add(statement);})*
2662 setMarker(fileToParse,
2663 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2667 "Line " + token.beginLine);
2668 } catch (CoreException e) {
2669 PHPeclipsePlugin.log(e);
2673 } catch (ParseException e) {
2674 errorMessage = "'endwhile' expected";
2676 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2677 errorEnd = SimpleCharStream.getPosition() + 1;
2683 final Statement[] stmtsArray = new Statement[stmts.size()];
2684 stmts.toArray(stmtsArray);
2685 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2686 } catch (ParseException e) {
2687 errorMessage = "';' expected after 'endwhile' keyword";
2689 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2690 errorEnd = SimpleCharStream.getPosition() + 1;
2694 statement = Statement()
2698 DoStatement DoStatement() :
2700 final Statement action;
2701 final Expression condition;
2702 final int pos = SimpleCharStream.getPosition();
2705 <DO> action = Statement() <WHILE> condition = Condition("while")
2708 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2709 } catch (ParseException e) {
2710 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2712 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2713 errorEnd = SimpleCharStream.getPosition() + 1;
2718 ForeachStatement ForeachStatement() :
2720 Statement statement;
2721 Expression expression;
2722 final int pos = SimpleCharStream.getPosition();
2723 ArrayVariableDeclaration variable;
2729 } catch (ParseException e) {
2730 errorMessage = "'(' expected after 'foreach' keyword";
2732 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2733 errorEnd = SimpleCharStream.getPosition() + 1;
2737 expression = Expression()
2738 } catch (ParseException e) {
2739 errorMessage = "variable expected";
2741 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2742 errorEnd = SimpleCharStream.getPosition() + 1;
2747 } catch (ParseException e) {
2748 errorMessage = "'as' expected";
2750 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2751 errorEnd = SimpleCharStream.getPosition() + 1;
2755 variable = ArrayVariable()
2756 } catch (ParseException e) {
2757 errorMessage = "variable expected";
2759 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2760 errorEnd = SimpleCharStream.getPosition() + 1;
2765 } catch (ParseException e) {
2766 errorMessage = "')' expected after 'foreach' keyword";
2768 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2769 errorEnd = SimpleCharStream.getPosition() + 1;
2773 statement = Statement()
2774 } catch (ParseException e) {
2775 if (errorMessage != null) throw e;
2776 errorMessage = "statement expected";
2778 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2779 errorEnd = SimpleCharStream.getPosition() + 1;
2782 {return new ForeachStatement(expression,
2786 SimpleCharStream.getPosition());}
2790 ForStatement ForStatement() :
2793 final int pos = SimpleCharStream.getPosition();
2794 Expression[] initializations = null;
2795 Expression condition = null;
2796 Expression[] increments = null;
2798 final ArrayList list = new ArrayList();
2799 final int startBlock, endBlock;
2805 } catch (ParseException e) {
2806 errorMessage = "'(' expected after 'for' keyword";
2808 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2809 errorEnd = SimpleCharStream.getPosition() + 1;
2812 [ initializations = ForInit() ] <SEMICOLON>
2813 [ condition = Expression() ] <SEMICOLON>
2814 [ increments = StatementExpressionList() ] <RPAREN>
2816 action = Statement()
2817 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2820 {startBlock = SimpleCharStream.getPosition();}
2821 (action = Statement() {list.add(action);})*
2824 setMarker(fileToParse,
2825 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2827 pos+token.image.length(),
2829 "Line " + token.beginLine);
2830 } catch (CoreException e) {
2831 PHPeclipsePlugin.log(e);
2834 {endBlock = SimpleCharStream.getPosition();}
2837 } catch (ParseException e) {
2838 errorMessage = "'endfor' expected";
2840 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2841 errorEnd = SimpleCharStream.getPosition() + 1;
2847 final Statement[] stmtsArray = new Statement[list.size()];
2848 list.toArray(stmtsArray);
2849 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2850 } catch (ParseException e) {
2851 errorMessage = "';' expected after 'endfor' keyword";
2853 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2854 errorEnd = SimpleCharStream.getPosition() + 1;
2860 Expression[] ForInit() :
2862 final Expression[] exprs;
2865 LOOKAHEAD(LocalVariableDeclaration())
2866 exprs = LocalVariableDeclaration()
2869 exprs = StatementExpressionList()
2873 Expression[] StatementExpressionList() :
2875 final ArrayList list = new ArrayList();
2876 final Expression expr;
2879 expr = StatementExpression() {list.add(expr);}
2880 (<COMMA> StatementExpression() {list.add(expr);})*
2882 final Expression[] exprsArray = new Expression[list.size()];
2883 list.toArray(exprsArray);
2887 Continue ContinueStatement() :
2889 Expression expr = null;
2890 final int pos = SimpleCharStream.getPosition();
2893 <CONTINUE> [ expr = Expression() ]
2896 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2897 } catch (ParseException e) {
2898 errorMessage = "';' expected after 'continue' statement";
2900 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2901 errorEnd = SimpleCharStream.getPosition() + 1;
2906 ReturnStatement ReturnStatement() :
2908 Expression expr = null;
2909 final int pos = SimpleCharStream.getPosition();
2912 <RETURN> [ expr = Expression() ]
2915 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2916 } catch (ParseException e) {
2917 errorMessage = "';' expected after 'return' statement";
2919 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2920 errorEnd = SimpleCharStream.getPosition() + 1;