3 CHOICE_AMBIGUITY_CHECK = 2;
4 OTHER_AMBIGUITY_CHECK = 1;
7 DEBUG_LOOKAHEAD = false;
8 DEBUG_TOKEN_MANAGER = false;
9 OPTIMIZE_TOKEN_MANAGER = false;
10 ERROR_REPORTING = true;
11 JAVA_UNICODE_ESCAPE = false;
12 UNICODE_INPUT = false;
14 USER_TOKEN_MANAGER = false;
15 USER_CHAR_STREAM = false;
17 BUILD_TOKEN_MANAGER = true;
19 FORCE_LA_CHECK = false;
22 PARSER_BEGIN(PHPParser)
25 import org.eclipse.core.resources.IFile;
26 import org.eclipse.core.resources.IMarker;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.ui.texteditor.MarkerUtilities;
29 import org.eclipse.jface.preference.IPreferenceStore;
31 import java.util.Hashtable;
32 import java.util.ArrayList;
33 import java.io.StringReader;
35 import java.text.MessageFormat;
37 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
38 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
39 import net.sourceforge.phpdt.internal.compiler.ast.*;
40 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
41 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
46 * This php parser is inspired by the Java 1.2 grammar example
47 * given with JavaCC. You can get JavaCC at http://www.webgain.com
48 * You can test the parser with the PHPParserTestCase2.java
49 * @author Matthieu Casanova
51 public final class PHPParser extends PHPParserSuperclass {
53 /** The file that is parsed. */
54 private static IFile fileToParse;
56 /** The current segment. */
57 private static OutlineableWithChildren currentSegment;
59 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
60 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
61 static PHPOutlineInfo outlineInfo;
63 /** The error level of the current ParseException. */
64 private static int errorLevel = ERROR;
65 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
66 private static String errorMessage;
68 private static int errorStart = -1;
69 private static int errorEnd = -1;
70 private static PHPDocument phpDocument;
72 private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
74 * The point where html starts.
75 * It will be used by the token manager to create HTMLCode objects
77 public static int htmlStart;
80 private final static int AstStackIncrement = 100;
81 /** The stack of node. */
82 private static AstNode[] nodes;
83 /** The cursor in expression stack. */
84 private static int nodePtr;
86 public final void setFileToParse(final IFile fileToParse) {
87 this.fileToParse = fileToParse;
93 public PHPParser(final IFile fileToParse) {
94 this(new StringReader(""));
95 this.fileToParse = fileToParse;
99 * Reinitialize the parser.
101 private static final void init() {
102 nodes = new AstNode[AstStackIncrement];
108 * Add an php node on the stack.
109 * @param node the node that will be added to the stack
111 private static final void pushOnAstNodes(AstNode node) {
113 nodes[++nodePtr] = node;
114 } catch (IndexOutOfBoundsException e) {
115 int oldStackLength = nodes.length;
116 AstNode[] oldStack = nodes;
117 nodes = new AstNode[oldStackLength + AstStackIncrement];
118 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
119 nodePtr = oldStackLength;
120 nodes[nodePtr] = node;
124 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
125 phpDocument = new PHPDocument(parent,"_root".toCharArray());
126 currentSegment = phpDocument;
127 outlineInfo = new PHPOutlineInfo(parent, currentSegment);
128 final StringReader stream = new StringReader(s);
129 if (jj_input_stream == null) {
130 jj_input_stream = new SimpleCharStream(stream, 1, 1);
136 phpDocument.nodes = new AstNode[nodes.length];
137 System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
138 if (PHPeclipsePlugin.DEBUG) {
139 PHPeclipsePlugin.log(1,phpDocument.toString());
141 } catch (ParseException e) {
142 processParseException(e);
148 * This method will process the parse exception.
149 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
150 * @param e the ParseException
152 private static void processParseException(final ParseException e) {
153 if (errorMessage == null) {
154 PHPeclipsePlugin.log(e);
155 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
156 errorStart = SimpleCharStream.getPosition();
157 errorEnd = errorStart + 1;
164 * Create marker for the parse error
165 * @param e the ParseException
167 private static void setMarker(final ParseException e) {
169 if (errorStart == -1) {
170 setMarker(fileToParse,
172 SimpleCharStream.tokenBegin,
173 SimpleCharStream.tokenBegin + e.currentToken.image.length(),
175 "Line " + e.currentToken.beginLine);
177 setMarker(fileToParse,
182 "Line " + e.currentToken.beginLine);
186 } catch (CoreException e2) {
187 PHPeclipsePlugin.log(e2);
191 private static void scanLine(final String output,
194 final int brIndx) throws CoreException {
196 StringBuffer lineNumberBuffer = new StringBuffer(10);
198 current = output.substring(indx, brIndx);
200 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
201 int onLine = current.indexOf("on line <b>");
203 lineNumberBuffer.delete(0, lineNumberBuffer.length());
204 for (int i = onLine; i < current.length(); i++) {
205 ch = current.charAt(i);
206 if ('0' <= ch && '9' >= ch) {
207 lineNumberBuffer.append(ch);
211 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
213 Hashtable attributes = new Hashtable();
215 current = current.replaceAll("\n", "");
216 current = current.replaceAll("<b>", "");
217 current = current.replaceAll("</b>", "");
218 MarkerUtilities.setMessage(attributes, current);
220 if (current.indexOf(PARSE_ERROR_STRING) != -1)
221 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
222 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
223 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
225 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
226 MarkerUtilities.setLineNumber(attributes, lineNumber);
227 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
232 public final void parse(final String s) throws CoreException {
233 final StringReader stream = new StringReader(s);
234 if (jj_input_stream == null) {
235 jj_input_stream = new SimpleCharStream(stream, 1, 1);
241 } catch (ParseException e) {
242 processParseException(e);
247 * Call the php parse command ( php -l -f <filename> )
248 * and create markers according to the external parser output
250 public static void phpExternalParse(final IFile file) {
251 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
252 final String filename = file.getLocation().toString();
254 final String[] arguments = { filename };
255 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
256 final String command = form.format(arguments);
258 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
261 // parse the buffer to find the errors and warnings
262 createMarkers(parserResult, file);
263 } catch (CoreException e) {
264 PHPeclipsePlugin.log(e);
269 * Put a new html block in the stack.
271 public static final void createNewHTMLCode() {
272 final int currentPosition = SimpleCharStream.getPosition();
273 if (currentPosition == htmlStart) {
276 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
277 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
283 public static final void createNewTask() {
284 final int currentPosition = SimpleCharStream.getPosition();
285 final String todo = SimpleCharStream.currentBuffer.substring(currentPosition+1,
286 SimpleCharStream.currentBuffer.indexOf("\n",
289 setMarker(fileToParse,
291 SimpleCharStream.getBeginLine(),
293 "Line "+SimpleCharStream.getBeginLine());
294 } catch (CoreException e) {
295 PHPeclipsePlugin.log(e);
299 private static final void parse() throws ParseException {
304 PARSER_END(PHPParser)
308 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
309 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
310 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
315 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
318 /* Skip any character if we are not in php mode */
336 <PHPPARSING> SPECIAL_TOKEN :
338 "//" : IN_SINGLE_LINE_COMMENT
339 | "#" : IN_SINGLE_LINE_COMMENT
340 | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
341 | "/*" : IN_MULTI_LINE_COMMENT
344 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
346 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
350 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
352 "todo" {PHPParser.createNewTask();}
355 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
360 <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
365 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
375 | <FUNCTION : "function">
378 | <ELSEIF : "elseif">
385 /* LANGUAGE CONSTRUCT */
390 | <INCLUDE : "include">
391 | <REQUIRE : "require">
392 | <INCLUDE_ONCE : "include_once">
393 | <REQUIRE_ONCE : "require_once">
394 | <GLOBAL : "global">
395 | <DEFINE : "define">
396 | <STATIC : "static">
397 | <CLASSACCESS : "->">
398 | <STATICCLASSACCESS : "::">
399 | <ARRAYASSIGN : "=>">
402 /* RESERVED WORDS AND LITERALS */
408 | <CONTINUE : "continue">
409 | <_DEFAULT : "default">
411 | <EXTENDS : "extends">
416 | <RETURN : "return">
418 | <SWITCH : "switch">
423 | <ENDWHILE : "endwhile">
424 | <ENDSWITCH: "endswitch">
426 | <ENDFOR : "endfor">
427 | <FOREACH : "foreach">
435 | <OBJECT : "object">
437 | <BOOLEAN : "boolean">
439 | <DOUBLE : "double">
442 | <INTEGER : "integer">
462 | <MINUS_MINUS : "--">
472 | <RSIGNEDSHIFT : ">>">
473 | <RUNSIGNEDSHIFT : ">>>">
482 <DECIMAL_LITERAL> (["l","L"])?
483 | <HEX_LITERAL> (["l","L"])?
484 | <OCTAL_LITERAL> (["l","L"])?
487 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
489 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
491 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
493 <FLOATING_POINT_LITERAL:
494 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
495 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
496 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
497 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
500 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
502 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
503 | <STRING_1: "\"" ( ~["\""] | "\\\"" | "\\" )* "\"">
504 | <STRING_2: "'" ( ~["'"] | "\\'" )* "'">
505 | <STRING_3: "`" ( ~["`"] | "\\`" )* "`">
512 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
515 ["a"-"z"] | ["A"-"Z"]
523 "_" | ["\u007f"-"\u00ff"]
548 | <EQUAL_EQUAL : "==">
553 | <BANGDOUBLEEQUAL : "!==">
554 | <TRIPLEEQUAL : "===">
561 | <PLUSASSIGN : "+=">
562 | <MINUSASSIGN : "-=">
563 | <STARASSIGN : "*=">
564 | <SLASHASSIGN : "/=">
570 | <TILDEEQUAL : "~=">
571 | <LSHIFTASSIGN : "<<=">
572 | <RSIGNEDSHIFTASSIGN : ">>=">
577 <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
585 {PHPParser.createNewHTMLCode();}
586 } catch (TokenMgrError e) {
587 PHPeclipsePlugin.log(e);
588 errorStart = SimpleCharStream.getPosition();
589 errorEnd = errorStart + 1;
590 errorMessage = e.getMessage();
592 throw generateParseException();
597 * A php block is a <?= expression [;]?>
598 * or <?php somephpcode ?>
599 * or <? somephpcode ?>
603 final int start = SimpleCharStream.getPosition();
604 final PHPEchoBlock phpEchoBlock;
607 phpEchoBlock = phpEchoBlock()
608 {pushOnAstNodes(phpEchoBlock);}
613 setMarker(fileToParse,
614 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
616 SimpleCharStream.getPosition(),
618 "Line " + token.beginLine);
619 } catch (CoreException e) {
620 PHPeclipsePlugin.log(e);
626 } catch (ParseException e) {
627 errorMessage = "'?>' expected";
629 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
630 errorEnd = SimpleCharStream.getPosition() + 1;
631 processParseException(e);
635 PHPEchoBlock phpEchoBlock() :
637 final Expression expr;
638 final int pos = SimpleCharStream.getPosition();
639 PHPEchoBlock echoBlock;
642 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
644 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
645 pushOnAstNodes(echoBlock);
655 ClassDeclaration ClassDeclaration() :
657 final ClassDeclaration classDeclaration;
658 final Token className;
659 Token superclassName = null;
661 char[] classNameImage = SYNTAX_ERROR_CHAR;
662 char[] superclassNameImage = null;
666 {pos = SimpleCharStream.getPosition();}
668 className = <IDENTIFIER>
669 {classNameImage = className.image.toCharArray();}
670 } catch (ParseException e) {
671 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
673 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
674 errorEnd = SimpleCharStream.getPosition() + 1;
675 processParseException(e);
680 superclassName = <IDENTIFIER>
681 {superclassNameImage = superclassName.image.toCharArray();}
682 } catch (ParseException e) {
683 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
685 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
686 errorEnd = SimpleCharStream.getPosition() + 1;
687 processParseException(e);
688 superclassNameImage = SYNTAX_ERROR_CHAR;
692 if (superclassNameImage == null) {
693 classDeclaration = new ClassDeclaration(currentSegment,
698 classDeclaration = new ClassDeclaration(currentSegment,
704 currentSegment.add(classDeclaration);
705 currentSegment = classDeclaration;
707 ClassBody(classDeclaration)
708 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
709 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
710 pushOnAstNodes(classDeclaration);
711 return classDeclaration;}
714 void ClassBody(ClassDeclaration classDeclaration) :
719 } catch (ParseException e) {
720 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
722 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
723 errorEnd = SimpleCharStream.getPosition() + 1;
726 ( ClassBodyDeclaration(classDeclaration) )*
729 } catch (ParseException e) {
730 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
732 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
733 errorEnd = SimpleCharStream.getPosition() + 1;
739 * A class can contain only methods and fields.
741 void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
743 MethodDeclaration method;
744 FieldDeclaration field;
747 method = MethodDeclaration() {classDeclaration.addMethod(method);}
748 | field = FieldDeclaration() {classDeclaration.addField(field);}
752 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
754 FieldDeclaration FieldDeclaration() :
756 VariableDeclaration variableDeclaration;
757 VariableDeclaration[] list;
758 final ArrayList arrayList = new ArrayList();
759 final int pos = SimpleCharStream.getPosition();
762 <VAR> variableDeclaration = VariableDeclarator()
763 {arrayList.add(variableDeclaration);
764 outlineInfo.addVariable(new String(variableDeclaration.name));}
765 ( <COMMA> variableDeclaration = VariableDeclarator()
766 {arrayList.add(variableDeclaration);
767 outlineInfo.addVariable(new String(variableDeclaration.name));}
771 } catch (ParseException e) {
772 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
774 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
775 errorEnd = SimpleCharStream.getPosition() + 1;
776 processParseException(e);
779 {list = new VariableDeclaration[arrayList.size()];
780 arrayList.toArray(list);
781 return new FieldDeclaration(list,
783 SimpleCharStream.getPosition(),
787 VariableDeclaration VariableDeclarator() :
789 final String varName;
790 Expression initializer = null;
791 final int pos = SimpleCharStream.getPosition();
794 varName = VariableDeclaratorId()
798 initializer = VariableInitializer()
799 } catch (ParseException e) {
800 errorMessage = "Literal expression expected in variable initializer";
802 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
803 errorEnd = SimpleCharStream.getPosition() + 1;
808 if (initializer == null) {
809 return new VariableDeclaration(currentSegment,
810 varName.toCharArray(),
812 SimpleCharStream.getPosition());
814 return new VariableDeclaration(currentSegment,
815 varName.toCharArray(),
823 * @return the variable name (with suffix)
825 String VariableDeclaratorId() :
828 Expression expression = null;
829 final StringBuffer buff = new StringBuffer();
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 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 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;
1136 expr = PrintExpression() {return expr;}
1137 | expr = ListExpression() {return expr;}
1138 | LOOKAHEAD(varAssignation())
1139 expr = varAssignation() {return expr;}
1140 | expr = ConditionalExpression() {return expr;}
1144 * A Variable assignation.
1145 * varName (an assign operator) any expression
1147 VarAssignation varAssignation() :
1150 final Expression initializer;
1151 final int assignOperator;
1152 final int pos = SimpleCharStream.getPosition();
1155 varName = VariableDeclaratorId()
1156 assignOperator = AssignmentOperator()
1158 initializer = Expression()
1159 } catch (ParseException e) {
1160 if (errorMessage != null) {
1163 errorMessage = "expression expected";
1165 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1166 errorEnd = SimpleCharStream.getPosition() + 1;
1169 {return new VarAssignation(varName.toCharArray(),
1173 SimpleCharStream.getPosition());}
1176 int AssignmentOperator() :
1179 <ASSIGN> {return VarAssignation.EQUAL;}
1180 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1181 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1182 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1183 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1184 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1185 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1186 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1187 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1188 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1189 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1190 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1191 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1194 Expression ConditionalExpression() :
1196 final Expression expr;
1197 Expression expr2 = null;
1198 Expression expr3 = null;
1201 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1203 if (expr3 == null) {
1206 return new ConditionalExpression(expr,expr2,expr3);
1210 Expression ConditionalOrExpression() :
1212 Expression expr,expr2;
1216 expr = ConditionalAndExpression()
1219 <OR_OR> {operator = OperatorIds.OR_OR;}
1220 | <_ORL> {operator = OperatorIds.ORL;}
1221 ) expr2 = ConditionalAndExpression()
1223 expr = new BinaryExpression(expr,expr2,operator);
1229 Expression ConditionalAndExpression() :
1231 Expression expr,expr2;
1235 expr = ConcatExpression()
1237 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1238 | <_ANDL> {operator = OperatorIds.ANDL;})
1239 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1244 Expression ConcatExpression() :
1246 Expression expr,expr2;
1249 expr = InclusiveOrExpression()
1251 <DOT> expr2 = InclusiveOrExpression()
1252 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1257 Expression InclusiveOrExpression() :
1259 Expression expr,expr2;
1262 expr = ExclusiveOrExpression()
1263 (<BIT_OR> expr2 = ExclusiveOrExpression()
1264 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1269 Expression ExclusiveOrExpression() :
1271 Expression expr,expr2;
1274 expr = AndExpression()
1276 <XOR> expr2 = AndExpression()
1277 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1282 Expression AndExpression() :
1284 Expression expr,expr2;
1287 expr = EqualityExpression()
1289 <BIT_AND> expr2 = EqualityExpression()
1290 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1295 Expression EqualityExpression() :
1297 Expression expr,expr2;
1301 expr = RelationalExpression()
1303 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1304 | <DIF> {operator = OperatorIds.DIF;}
1305 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1306 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1307 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1310 expr2 = RelationalExpression()
1311 } catch (ParseException e) {
1312 if (errorMessage != null) {
1315 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1317 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1318 errorEnd = SimpleCharStream.getPosition() + 1;
1322 expr = new BinaryExpression(expr,expr2,operator);
1328 Expression RelationalExpression() :
1330 Expression expr,expr2;
1334 expr = ShiftExpression()
1336 ( <LT> {operator = OperatorIds.LESS;}
1337 | <GT> {operator = OperatorIds.GREATER;}
1338 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1339 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1340 expr2 = ShiftExpression()
1341 {expr = new BinaryExpression(expr,expr2,operator);}
1346 Expression ShiftExpression() :
1348 Expression expr,expr2;
1352 expr = AdditiveExpression()
1354 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1355 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1356 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1357 expr2 = AdditiveExpression()
1358 {expr = new BinaryExpression(expr,expr2,operator);}
1363 Expression AdditiveExpression() :
1365 Expression expr,expr2;
1369 expr = MultiplicativeExpression()
1371 ( <PLUS> {operator = OperatorIds.PLUS;}
1372 | <MINUS> {operator = OperatorIds.MINUS;} )
1373 expr2 = MultiplicativeExpression()
1374 {expr = new BinaryExpression(expr,expr2,operator);}
1379 Expression MultiplicativeExpression() :
1381 Expression expr,expr2;
1386 expr = UnaryExpression()
1387 } catch (ParseException e) {
1388 if (errorMessage != null) throw e;
1389 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1391 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1392 errorEnd = SimpleCharStream.getPosition() + 1;
1396 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1397 | <SLASH> {operator = OperatorIds.DIVIDE;}
1398 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1399 expr2 = UnaryExpression()
1400 {expr = new BinaryExpression(expr,expr2,operator);}
1406 * An unary expression starting with @, & or nothing
1408 Expression UnaryExpression() :
1411 final int pos = SimpleCharStream.getPosition();
1414 <BIT_AND> expr = UnaryExpressionNoPrefix()
1415 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1417 expr = AtUnaryExpression() {return expr;}
1420 Expression AtUnaryExpression() :
1423 final int pos = SimpleCharStream.getPosition();
1427 expr = AtUnaryExpression()
1428 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1430 expr = UnaryExpressionNoPrefix()
1435 Expression UnaryExpressionNoPrefix() :
1439 final int pos = SimpleCharStream.getPosition();
1442 ( <PLUS> {operator = OperatorIds.PLUS;}
1443 | <MINUS> {operator = OperatorIds.MINUS;})
1444 expr = UnaryExpression()
1445 {return new PrefixedUnaryExpression(expr,operator,pos);}
1447 expr = PreIncDecExpression()
1450 expr = UnaryExpressionNotPlusMinus()
1455 Expression PreIncDecExpression() :
1457 final Expression expr;
1459 final int pos = SimpleCharStream.getPosition();
1462 ( <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1463 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;})
1464 expr = PrimaryExpression()
1465 {return new PrefixedUnaryExpression(expr,operator,pos);}
1468 Expression UnaryExpressionNotPlusMinus() :
1471 final int pos = SimpleCharStream.getPosition();
1474 <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1475 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1476 expr = CastExpression() {return expr;}
1477 | expr = PostfixExpression() {return expr;}
1478 | expr = Literal() {return expr;}
1479 | <LPAREN> expr = Expression()
1482 } catch (ParseException e) {
1483 errorMessage = "')' expected";
1485 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1486 errorEnd = SimpleCharStream.getPosition() + 1;
1492 CastExpression CastExpression() :
1494 final ConstantIdentifier type;
1495 final Expression expr;
1496 final int pos = SimpleCharStream.getPosition();
1501 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1502 <RPAREN> expr = UnaryExpression()
1503 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1506 Expression PostfixExpression() :
1510 final int pos = SimpleCharStream.getPosition();
1513 expr = PrimaryExpression()
1514 [ <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1515 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}]
1517 if (operator == -1) {
1520 return new PostfixedUnaryExpression(expr,operator,pos);
1524 Expression PrimaryExpression() :
1526 final Token identifier;
1528 final int pos = SimpleCharStream.getPosition();
1532 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1533 {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
1535 SimpleCharStream.getPosition()),
1537 ClassAccess.STATIC);}
1539 LOOKAHEAD(PrimarySuffix())
1540 expr = PrimarySuffix(expr))*
1543 expr = PrimaryPrefix()
1545 LOOKAHEAD(PrimarySuffix())
1546 expr = PrimarySuffix(expr))*
1549 expr = ArrayDeclarator()
1554 * An array declarator.
1558 ArrayInitializer ArrayDeclarator() :
1560 final ArrayVariableDeclaration[] vars;
1561 final int pos = SimpleCharStream.getPosition();
1564 <ARRAY> vars = ArrayInitializer()
1565 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1568 Expression PrimaryPrefix() :
1570 final Expression expr;
1573 final int pos = SimpleCharStream.getPosition();
1576 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1578 SimpleCharStream.getPosition());}
1579 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1582 | var = VariableDeclaratorId() {return new VariableDeclaration(currentSegment,
1585 SimpleCharStream.getPosition());}
1588 PrefixedUnaryExpression classInstantiation() :
1591 final StringBuffer buff;
1592 final int pos = SimpleCharStream.getPosition();
1595 <NEW> expr = ClassIdentifier()
1597 {buff = new StringBuffer(expr.toStringExpression());}
1598 expr = PrimaryExpression()
1599 {buff.append(expr.toStringExpression());
1600 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1602 SimpleCharStream.getPosition());}
1604 {return new PrefixedUnaryExpression(expr,
1609 ConstantIdentifier ClassIdentifier():
1613 final int pos = SimpleCharStream.getPosition();
1616 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1618 SimpleCharStream.getPosition());}
1619 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1621 SimpleCharStream.getPosition());}
1624 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
1626 final AbstractSuffixExpression expr;
1629 expr = Arguments(prefix) {return expr;}
1630 | expr = VariableSuffix(prefix) {return expr;}
1633 AbstractSuffixExpression VariableSuffix(Expression prefix) :
1636 final int pos = SimpleCharStream.getPosition();
1637 Expression expression = null;
1642 expr = VariableName()
1643 } catch (ParseException e) {
1644 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1646 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1647 errorEnd = SimpleCharStream.getPosition() + 1;
1650 {return new ClassAccess(prefix,
1651 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1652 ClassAccess.NORMAL);}
1654 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1657 } catch (ParseException e) {
1658 errorMessage = "']' expected";
1660 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1661 errorEnd = SimpleCharStream.getPosition() + 1;
1664 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1673 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1674 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1675 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1676 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1677 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1678 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1679 | <TRUE> {pos = SimpleCharStream.getPosition();
1680 return new TrueLiteral(pos-4,pos);}
1681 | <FALSE> {pos = SimpleCharStream.getPosition();
1682 return new FalseLiteral(pos-4,pos);}
1683 | <NULL> {pos = SimpleCharStream.getPosition();
1684 return new NullLiteral(pos-4,pos);}
1687 FunctionCall Arguments(Expression func) :
1689 Expression[] args = null;
1692 <LPAREN> [ args = ArgumentList() ]
1695 } catch (ParseException e) {
1696 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1698 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1699 errorEnd = SimpleCharStream.getPosition() + 1;
1702 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1706 * An argument list is a list of arguments separated by comma :
1707 * argumentDeclaration() (, argumentDeclaration)*
1708 * @return an array of arguments
1710 Expression[] ArgumentList() :
1713 final ArrayList list = new ArrayList();
1722 } catch (ParseException e) {
1723 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1725 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1726 errorEnd = SimpleCharStream.getPosition() + 1;
1731 Expression[] arguments = new Expression[list.size()];
1732 list.toArray(arguments);
1737 * A Statement without break.
1739 Statement StatementNoBreak() :
1741 final Statement statement;
1746 statement = Expression()
1749 } catch (ParseException e) {
1750 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1751 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1753 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1754 errorEnd = SimpleCharStream.getPosition() + 1;
1760 statement = LabeledStatement() {return statement;}
1761 | statement = Block() {return statement;}
1762 | statement = EmptyStatement() {return statement;}
1763 | statement = StatementExpression()
1766 } catch (ParseException e) {
1767 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1769 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1770 errorEnd = SimpleCharStream.getPosition() + 1;
1774 | statement = SwitchStatement() {return statement;}
1775 | statement = IfStatement() {return statement;}
1776 | statement = WhileStatement() {return statement;}
1777 | statement = DoStatement() {return statement;}
1778 | statement = ForStatement() {return statement;}
1779 | statement = ForeachStatement() {return statement;}
1780 | statement = ContinueStatement() {return statement;}
1781 | statement = ReturnStatement() {return statement;}
1782 | statement = EchoStatement() {return statement;}
1783 | [token=<AT>] statement = IncludeStatement()
1784 {if (token != null) {
1785 ((InclusionStatement)statement).silent = true;
1788 | statement = StaticStatement() {return statement;}
1789 | statement = GlobalStatement() {return statement;}
1790 | statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
1793 Define defineStatement() :
1795 final int start = SimpleCharStream.getPosition();
1796 Expression defineName,defineValue;
1802 } catch (ParseException e) {
1803 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1805 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1806 errorEnd = SimpleCharStream.getPosition() + 1;
1807 processParseException(e);
1810 defineName = Expression()
1811 } catch (ParseException e) {
1812 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1814 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1815 errorEnd = SimpleCharStream.getPosition() + 1;
1820 } catch (ParseException e) {
1821 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1823 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1824 errorEnd = SimpleCharStream.getPosition() + 1;
1825 processParseException(e);
1828 ( defineValue = PrintExpression()
1829 | LOOKAHEAD(varAssignation())
1830 defineValue = varAssignation()
1831 | defineValue = ConditionalExpression())
1832 } catch (ParseException e) {
1833 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1835 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1836 errorEnd = SimpleCharStream.getPosition() + 1;
1841 } catch (ParseException e) {
1842 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1844 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1845 errorEnd = SimpleCharStream.getPosition() + 1;
1846 processParseException(e);
1848 {return new Define(currentSegment,
1852 SimpleCharStream.getPosition());}
1856 * A Normal statement.
1858 Statement Statement() :
1860 final Statement statement;
1863 statement = StatementNoBreak() {return statement;}
1864 | statement = BreakStatement() {return statement;}
1868 * An html block inside a php syntax.
1870 HTMLBlock htmlBlock() :
1872 final int startIndex = nodePtr;
1873 AstNode[] blockNodes;
1877 <PHPEND> (phpEchoBlock())*
1879 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1880 } catch (ParseException e) {
1881 errorMessage = "unexpected end of file , '<?php' expected";
1883 errorStart = SimpleCharStream.getPosition();
1884 errorEnd = SimpleCharStream.getPosition();
1888 nbNodes = nodePtr - startIndex;
1889 blockNodes = new AstNode[nbNodes];
1890 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1891 nodePtr = startIndex;
1892 return new HTMLBlock(blockNodes);}
1896 * An include statement. It's "include" an expression;
1898 InclusionStatement IncludeStatement() :
1900 final Expression expr;
1902 final int pos = SimpleCharStream.getPosition();
1903 final InclusionStatement inclusionStatement;
1906 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1907 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1908 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1909 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1912 } catch (ParseException e) {
1913 if (errorMessage != null) {
1916 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1918 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1919 errorEnd = SimpleCharStream.getPosition() + 1;
1922 {inclusionStatement = new InclusionStatement(currentSegment,
1926 currentSegment.add(inclusionStatement);
1930 } catch (ParseException e) {
1931 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1933 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1934 errorEnd = SimpleCharStream.getPosition() + 1;
1937 {return inclusionStatement;}
1940 PrintExpression PrintExpression() :
1942 final Expression expr;
1943 final int pos = SimpleCharStream.getPosition();
1946 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1949 ListExpression ListExpression() :
1952 Expression expression = null;
1953 ArrayList list = new ArrayList();
1954 final int pos = SimpleCharStream.getPosition();
1960 } catch (ParseException e) {
1961 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1963 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1964 errorEnd = SimpleCharStream.getPosition() + 1;
1968 expr = VariableDeclaratorId()
1971 {if (expr == null) list.add(null);}
1975 } catch (ParseException e) {
1976 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1978 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1979 errorEnd = SimpleCharStream.getPosition() + 1;
1982 expr = VariableDeclaratorId()
1987 } catch (ParseException e) {
1988 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1990 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1991 errorEnd = SimpleCharStream.getPosition() + 1;
1994 [ <ASSIGN> expression = Expression()
1996 String[] strings = new String[list.size()];
1997 list.toArray(strings);
1998 return new ListExpression(strings,
2001 SimpleCharStream.getPosition());}
2004 String[] strings = new String[list.size()];
2005 list.toArray(strings);
2006 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
2010 * An echo statement.
2011 * echo anyexpression (, otherexpression)*
2013 EchoStatement EchoStatement() :
2015 final ArrayList expressions = new ArrayList();
2017 final int pos = SimpleCharStream.getPosition();
2020 <ECHO> expr = Expression()
2021 {expressions.add(expr);}
2023 <COMMA> expr = Expression()
2024 {expressions.add(expr);}
2028 } catch (ParseException e) {
2029 if (e.currentToken.next.kind != 4) {
2030 errorMessage = "';' expected after 'echo' statement";
2032 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2033 errorEnd = SimpleCharStream.getPosition() + 1;
2037 {Expression[] exprs = new Expression[expressions.size()];
2038 expressions.toArray(exprs);
2039 return new EchoStatement(exprs,pos);}
2042 GlobalStatement GlobalStatement() :
2044 final int pos = SimpleCharStream.getPosition();
2046 ArrayList vars = new ArrayList();
2047 GlobalStatement global;
2051 expr = VariableDeclaratorId()
2054 expr = VariableDeclaratorId()
2060 String[] strings = new String[vars.size()];
2061 vars.toArray(strings);
2062 global = new GlobalStatement(currentSegment,
2065 SimpleCharStream.getPosition());
2066 currentSegment.add(global);
2068 } catch (ParseException e) {
2069 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2071 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2072 errorEnd = SimpleCharStream.getPosition() + 1;
2077 StaticStatement StaticStatement() :
2079 final int pos = SimpleCharStream.getPosition();
2080 final ArrayList vars = new ArrayList();
2081 VariableDeclaration expr;
2084 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2085 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2089 String[] strings = new String[vars.size()];
2090 vars.toArray(strings);
2091 return new StaticStatement(strings,
2093 SimpleCharStream.getPosition());}
2094 } catch (ParseException e) {
2095 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2097 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2098 errorEnd = SimpleCharStream.getPosition() + 1;
2103 LabeledStatement LabeledStatement() :
2105 final int pos = SimpleCharStream.getPosition();
2107 final Statement statement;
2110 label = <IDENTIFIER> <COLON> statement = Statement()
2111 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2123 final int pos = SimpleCharStream.getPosition();
2124 final ArrayList list = new ArrayList();
2125 Statement statement;
2130 } catch (ParseException e) {
2131 errorMessage = "'{' expected";
2133 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2134 errorEnd = SimpleCharStream.getPosition() + 1;
2137 ( statement = BlockStatement() {list.add(statement);}
2138 | statement = htmlBlock() {list.add(statement);})*
2141 } catch (ParseException e) {
2142 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2144 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2145 errorEnd = SimpleCharStream.getPosition() + 1;
2149 Statement[] statements = new Statement[list.size()];
2150 list.toArray(statements);
2151 return new Block(statements,pos,SimpleCharStream.getPosition());}
2154 Statement BlockStatement() :
2156 final Statement statement;
2160 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2162 } catch (ParseException e) {
2163 if (errorMessage != null) throw e;
2164 errorMessage = "statement expected";
2166 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2167 errorEnd = SimpleCharStream.getPosition() + 1;
2170 | statement = ClassDeclaration() {return statement;}
2171 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2172 currentSegment.add((MethodDeclaration) statement);
2177 * A Block statement that will not contain any 'break'
2179 Statement BlockStatementNoBreak() :
2181 final Statement statement;
2184 statement = StatementNoBreak() {return statement;}
2185 | statement = ClassDeclaration() {return statement;}
2186 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2190 VariableDeclaration[] LocalVariableDeclaration() :
2192 final ArrayList list = new ArrayList();
2193 VariableDeclaration var;
2196 var = LocalVariableDeclarator()
2198 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2200 VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2205 VariableDeclaration LocalVariableDeclarator() :
2207 final String varName;
2208 Expression initializer = null;
2209 final int pos = SimpleCharStream.getPosition();
2212 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2214 if (initializer == null) {
2215 return new VariableDeclaration(currentSegment,
2216 varName.toCharArray(),
2218 SimpleCharStream.getPosition());
2220 return new VariableDeclaration(currentSegment,
2221 varName.toCharArray(),
2227 EmptyStatement EmptyStatement() :
2233 {pos = SimpleCharStream.getPosition();
2234 return new EmptyStatement(pos-1,pos);}
2237 Expression StatementExpression() :
2239 Expression expr,expr2;
2243 expr = PreIncDecExpression() {return expr;}
2245 expr = PrimaryExpression()
2246 [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
2247 OperatorIds.PLUS_PLUS,
2248 SimpleCharStream.getPosition());}
2249 | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
2250 OperatorIds.MINUS_MINUS,
2251 SimpleCharStream.getPosition());}
2252 | operator = AssignmentOperator() expr2 = Expression()
2253 {return new BinaryExpression(expr,expr2,operator);}
2258 SwitchStatement SwitchStatement() :
2260 final Expression variable;
2261 final AbstractCase[] cases;
2262 final int pos = SimpleCharStream.getPosition();
2268 } catch (ParseException e) {
2269 errorMessage = "'(' expected after 'switch'";
2271 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2272 errorEnd = SimpleCharStream.getPosition() + 1;
2276 variable = Expression()
2277 } catch (ParseException e) {
2278 if (errorMessage != null) {
2281 errorMessage = "expression expected";
2283 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2284 errorEnd = SimpleCharStream.getPosition() + 1;
2289 } catch (ParseException e) {
2290 errorMessage = "')' expected";
2292 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2293 errorEnd = SimpleCharStream.getPosition() + 1;
2296 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2297 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2300 AbstractCase[] switchStatementBrace() :
2303 final ArrayList cases = new ArrayList();
2307 ( cas = switchLabel0() {cases.add(cas);})*
2311 AbstractCase[] abcase = new AbstractCase[cases.size()];
2312 cases.toArray(abcase);
2314 } catch (ParseException e) {
2315 errorMessage = "'}' expected";
2317 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2318 errorEnd = SimpleCharStream.getPosition() + 1;
2323 * A Switch statement with : ... endswitch;
2324 * @param start the begin offset of the switch
2325 * @param end the end offset of the switch
2327 AbstractCase[] switchStatementColon(final int start, final int end) :
2330 final ArrayList cases = new ArrayList();
2335 setMarker(fileToParse,
2336 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2340 "Line " + token.beginLine);
2341 } catch (CoreException e) {
2342 PHPeclipsePlugin.log(e);
2344 ( cas = switchLabel0() {cases.add(cas);})*
2347 } catch (ParseException e) {
2348 errorMessage = "'endswitch' expected";
2350 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2351 errorEnd = SimpleCharStream.getPosition() + 1;
2357 AbstractCase[] abcase = new AbstractCase[cases.size()];
2358 cases.toArray(abcase);
2360 } catch (ParseException e) {
2361 errorMessage = "';' expected after 'endswitch' keyword";
2363 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2364 errorEnd = SimpleCharStream.getPosition() + 1;
2369 AbstractCase switchLabel0() :
2371 final Expression expr;
2372 Statement statement;
2373 final ArrayList stmts = new ArrayList();
2374 final int pos = SimpleCharStream.getPosition();
2377 expr = SwitchLabel()
2378 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2379 | statement = htmlBlock() {stmts.add(statement);})*
2380 [ statement = BreakStatement() {stmts.add(statement);}]
2382 Statement[] stmtsArray = new Statement[stmts.size()];
2383 stmts.toArray(stmtsArray);
2384 if (expr == null) {//it's a default
2385 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2387 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2392 * case Expression() :
2394 * @return the if it was a case and null if not
2396 Expression SwitchLabel() :
2398 final Expression expr;
2404 } catch (ParseException e) {
2405 if (errorMessage != null) throw e;
2406 errorMessage = "expression expected after 'case' keyword";
2408 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2409 errorEnd = SimpleCharStream.getPosition() + 1;
2415 } catch (ParseException e) {
2416 errorMessage = "':' expected after case expression";
2418 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2419 errorEnd = SimpleCharStream.getPosition() + 1;
2427 } catch (ParseException e) {
2428 errorMessage = "':' expected after 'default' keyword";
2430 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2431 errorEnd = SimpleCharStream.getPosition() + 1;
2436 Break BreakStatement() :
2438 Expression expression = null;
2439 final int start = SimpleCharStream.getPosition();
2442 <BREAK> [ expression = Expression() ]
2445 } catch (ParseException e) {
2446 errorMessage = "';' expected after 'break' keyword";
2448 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2449 errorEnd = SimpleCharStream.getPosition() + 1;
2452 {return new Break(expression, start, SimpleCharStream.getPosition());}
2455 IfStatement IfStatement() :
2457 final int pos = SimpleCharStream.getPosition();
2458 Expression condition;
2459 IfStatement ifStatement;
2462 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2463 {return ifStatement;}
2467 Expression Condition(final String keyword) :
2469 final Expression condition;
2474 } catch (ParseException e) {
2475 errorMessage = "'(' expected after " + keyword + " keyword";
2477 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2478 errorEnd = errorStart +1;
2479 processParseException(e);
2481 condition = Expression()
2484 } catch (ParseException e) {
2485 errorMessage = "')' expected after " + keyword + " keyword";
2487 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2488 errorEnd = SimpleCharStream.getPosition() + 1;
2489 processParseException(e);
2494 IfStatement IfStatement0(Expression condition, final int start,final int end) :
2496 Statement statement;
2498 final Statement[] statementsArray;
2499 ElseIf elseifStatement;
2500 Else elseStatement = null;
2502 final ArrayList elseIfList = new ArrayList();
2504 int pos = SimpleCharStream.getPosition();
2509 {stmts = new ArrayList();}
2510 ( statement = Statement() {stmts.add(statement);}
2511 | statement = htmlBlock() {stmts.add(statement);})*
2512 {endStatements = SimpleCharStream.getPosition();}
2513 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2514 [elseStatement = ElseStatementColon()]
2517 setMarker(fileToParse,
2518 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2522 "Line " + token.beginLine);
2523 } catch (CoreException e) {
2524 PHPeclipsePlugin.log(e);
2528 } catch (ParseException e) {
2529 errorMessage = "'endif' expected";
2531 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2532 errorEnd = SimpleCharStream.getPosition() + 1;
2537 } catch (ParseException e) {
2538 errorMessage = "';' expected after 'endif' keyword";
2540 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2541 errorEnd = SimpleCharStream.getPosition() + 1;
2545 elseIfs = new ElseIf[elseIfList.size()];
2546 elseIfList.toArray(elseIfs);
2547 if (stmts.size() == 1) {
2548 return new IfStatement(condition,
2549 (Statement) stmts.get(0),
2553 SimpleCharStream.getPosition());
2555 statementsArray = new Statement[stmts.size()];
2556 stmts.toArray(statementsArray);
2557 return new IfStatement(condition,
2558 new Block(statementsArray,pos,endStatements),
2562 SimpleCharStream.getPosition());
2567 (stmt = Statement() | stmt = htmlBlock())
2568 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2572 {pos = SimpleCharStream.getPosition();}
2573 statement = Statement()
2574 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2575 } catch (ParseException e) {
2576 if (errorMessage != null) {
2579 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2581 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2582 errorEnd = SimpleCharStream.getPosition() + 1;
2587 elseIfs = new ElseIf[elseIfList.size()];
2588 elseIfList.toArray(elseIfs);
2589 return new IfStatement(condition,
2594 SimpleCharStream.getPosition());}
2597 ElseIf ElseIfStatementColon() :
2599 Expression condition;
2600 Statement statement;
2601 final ArrayList list = new ArrayList();
2602 final int pos = SimpleCharStream.getPosition();
2605 <ELSEIF> condition = Condition("elseif")
2606 <COLON> ( statement = Statement() {list.add(statement);}
2607 | statement = htmlBlock() {list.add(statement);})*
2609 Statement[] stmtsArray = new Statement[list.size()];
2610 list.toArray(stmtsArray);
2611 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2614 Else ElseStatementColon() :
2616 Statement statement;
2617 final ArrayList list = new ArrayList();
2618 final int pos = SimpleCharStream.getPosition();
2621 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2622 | statement = htmlBlock() {list.add(statement);})*
2624 Statement[] stmtsArray = new Statement[list.size()];
2625 list.toArray(stmtsArray);
2626 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2629 ElseIf ElseIfStatement() :
2631 Expression condition;
2632 Statement statement;
2633 final ArrayList list = new ArrayList();
2634 final int pos = SimpleCharStream.getPosition();
2637 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2639 Statement[] stmtsArray = new Statement[list.size()];
2640 list.toArray(stmtsArray);
2641 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2644 WhileStatement WhileStatement() :
2646 final Expression condition;
2647 final Statement action;
2648 final int pos = SimpleCharStream.getPosition();
2652 condition = Condition("while")
2653 action = WhileStatement0(pos,pos + 5)
2654 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2657 Statement WhileStatement0(final int start, final int end) :
2659 Statement statement;
2660 final ArrayList stmts = new ArrayList();
2661 final int pos = SimpleCharStream.getPosition();
2664 <COLON> (statement = Statement() {stmts.add(statement);})*
2666 setMarker(fileToParse,
2667 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2671 "Line " + token.beginLine);
2672 } catch (CoreException e) {
2673 PHPeclipsePlugin.log(e);
2677 } catch (ParseException e) {
2678 errorMessage = "'endwhile' expected";
2680 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2681 errorEnd = SimpleCharStream.getPosition() + 1;
2687 Statement[] stmtsArray = new Statement[stmts.size()];
2688 stmts.toArray(stmtsArray);
2689 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2690 } catch (ParseException e) {
2691 errorMessage = "';' expected after 'endwhile' keyword";
2693 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2694 errorEnd = SimpleCharStream.getPosition() + 1;
2698 statement = Statement()
2702 DoStatement DoStatement() :
2704 final Statement action;
2705 final Expression condition;
2706 final int pos = SimpleCharStream.getPosition();
2709 <DO> action = Statement() <WHILE> condition = Condition("while")
2712 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2713 } catch (ParseException e) {
2714 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2716 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2717 errorEnd = SimpleCharStream.getPosition() + 1;
2722 ForeachStatement ForeachStatement() :
2724 Statement statement;
2725 Expression expression;
2726 final int pos = SimpleCharStream.getPosition();
2727 ArrayVariableDeclaration variable;
2733 } catch (ParseException e) {
2734 errorMessage = "'(' expected after 'foreach' keyword";
2736 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2737 errorEnd = SimpleCharStream.getPosition() + 1;
2741 expression = Expression()
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 = "'as' expected";
2754 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2755 errorEnd = SimpleCharStream.getPosition() + 1;
2759 variable = ArrayVariable()
2760 } catch (ParseException e) {
2761 errorMessage = "variable expected";
2763 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2764 errorEnd = SimpleCharStream.getPosition() + 1;
2769 } catch (ParseException e) {
2770 errorMessage = "')' expected after 'foreach' keyword";
2772 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2773 errorEnd = SimpleCharStream.getPosition() + 1;
2777 statement = Statement()
2778 } catch (ParseException e) {
2779 if (errorMessage != null) throw e;
2780 errorMessage = "statement expected";
2782 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2783 errorEnd = SimpleCharStream.getPosition() + 1;
2786 {return new ForeachStatement(expression,
2790 SimpleCharStream.getPosition());}
2794 ForStatement ForStatement() :
2797 final int pos = SimpleCharStream.getPosition();
2798 Expression[] initializations = null;
2799 Expression condition = null;
2800 Expression[] increments = null;
2802 final ArrayList list = new ArrayList();
2803 final int startBlock, endBlock;
2809 } catch (ParseException e) {
2810 errorMessage = "'(' expected after 'for' keyword";
2812 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2813 errorEnd = SimpleCharStream.getPosition() + 1;
2816 [ initializations = ForInit() ] <SEMICOLON>
2817 [ condition = Expression() ] <SEMICOLON>
2818 [ increments = StatementExpressionList() ] <RPAREN>
2820 action = Statement()
2821 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2824 {startBlock = SimpleCharStream.getPosition();}
2825 (action = Statement() {list.add(action);})*
2828 setMarker(fileToParse,
2829 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2831 pos+token.image.length(),
2833 "Line " + token.beginLine);
2834 } catch (CoreException e) {
2835 PHPeclipsePlugin.log(e);
2838 {endBlock = SimpleCharStream.getPosition();}
2841 } catch (ParseException e) {
2842 errorMessage = "'endfor' expected";
2844 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2845 errorEnd = SimpleCharStream.getPosition() + 1;
2851 Statement[] stmtsArray = new Statement[list.size()];
2852 list.toArray(stmtsArray);
2853 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2854 } catch (ParseException e) {
2855 errorMessage = "';' expected after 'endfor' keyword";
2857 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2858 errorEnd = SimpleCharStream.getPosition() + 1;
2864 Expression[] ForInit() :
2869 LOOKAHEAD(LocalVariableDeclaration())
2870 exprs = LocalVariableDeclaration()
2873 exprs = StatementExpressionList()
2877 Expression[] StatementExpressionList() :
2879 final ArrayList list = new ArrayList();
2883 expr = StatementExpression() {list.add(expr);}
2884 (<COMMA> StatementExpression() {list.add(expr);})*
2886 Expression[] exprsArray = new Expression[list.size()];
2887 list.toArray(exprsArray);
2891 Continue ContinueStatement() :
2893 Expression expr = null;
2894 final int pos = SimpleCharStream.getPosition();
2897 <CONTINUE> [ expr = Expression() ]
2900 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2901 } catch (ParseException e) {
2902 errorMessage = "';' expected after 'continue' statement";
2904 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2905 errorEnd = SimpleCharStream.getPosition() + 1;
2910 ReturnStatement ReturnStatement() :
2912 Expression expr = null;
2913 final int pos = SimpleCharStream.getPosition();
2916 <RETURN> [ expr = Expression() ]
2919 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2920 } catch (ParseException e) {
2921 errorMessage = "';' expected after 'return' statement";
2923 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2924 errorEnd = SimpleCharStream.getPosition() + 1;