3 CHOICE_AMBIGUITY_CHECK = 2;
4 OTHER_AMBIGUITY_CHECK = 1;
7 DEBUG_LOOKAHEAD = false;
8 DEBUG_TOKEN_MANAGER = false;
9 OPTIMIZE_TOKEN_MANAGER = false;
10 ERROR_REPORTING = true;
11 JAVA_UNICODE_ESCAPE = false;
12 UNICODE_INPUT = false;
14 USER_TOKEN_MANAGER = false;
15 USER_CHAR_STREAM = false;
17 BUILD_TOKEN_MANAGER = true;
19 FORCE_LA_CHECK = false;
22 PARSER_BEGIN(PHPParser)
25 import org.eclipse.core.resources.IFile;
26 import org.eclipse.core.resources.IMarker;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.ui.texteditor.MarkerUtilities;
29 import org.eclipse.jface.preference.IPreferenceStore;
31 import java.util.Hashtable;
32 import java.util.ArrayList;
33 import java.io.StringReader;
35 import java.text.MessageFormat;
37 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
38 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
39 import net.sourceforge.phpdt.internal.compiler.ast.*;
40 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
41 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
46 * This php parser is inspired by the Java 1.2 grammar example
47 * given with JavaCC. You can get JavaCC at http://www.webgain.com
48 * You can test the parser with the PHPParserTestCase2.java
49 * @author Matthieu Casanova
51 public final class PHPParser extends PHPParserSuperclass {
53 /** The current segment. */
54 private static OutlineableWithChildren currentSegment;
56 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
57 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
58 static PHPOutlineInfo outlineInfo;
60 /** The error level of the current ParseException. */
61 private static int errorLevel = ERROR;
62 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
63 private static String errorMessage;
65 private static int errorStart = -1;
66 private static int errorEnd = -1;
67 private static PHPDocument phpDocument;
69 private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
71 * The point where html starts.
72 * It will be used by the token manager to create HTMLCode objects
74 public static int htmlStart;
77 private final static int AstStackIncrement = 100;
78 /** The stack of node. */
79 private static AstNode[] nodes;
80 /** The cursor in expression stack. */
81 private static int nodePtr;
83 private static final boolean PARSER_DEBUG = false;
85 public final void setFileToParse(final IFile fileToParse) {
86 PHPParser.fileToParse = fileToParse;
92 public PHPParser(final IFile fileToParse) {
93 this(new StringReader(""));
94 PHPParser.fileToParse = fileToParse;
98 * Reinitialize the parser.
100 private static final void init() {
101 nodes = new AstNode[AstStackIncrement];
107 * Add an php node on the stack.
108 * @param node the node that will be added to the stack
110 private static final void pushOnAstNodes(final AstNode node) {
112 nodes[++nodePtr] = node;
113 } catch (IndexOutOfBoundsException e) {
114 final int oldStackLength = nodes.length;
115 final AstNode[] oldStack = nodes;
116 nodes = new AstNode[oldStackLength + AstStackIncrement];
117 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
118 nodePtr = oldStackLength;
119 nodes[nodePtr] = node;
123 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
124 phpDocument = new PHPDocument(parent,"_root".toCharArray());
125 currentSegment = phpDocument;
126 outlineInfo = new PHPOutlineInfo(parent, currentSegment);
127 final StringReader stream = new StringReader(s);
128 if (jj_input_stream == null) {
129 jj_input_stream = new SimpleCharStream(stream, 1, 1);
135 phpDocument.nodes = new AstNode[nodes.length];
136 System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
137 if (PHPeclipsePlugin.DEBUG) {
138 PHPeclipsePlugin.log(1,phpDocument.toString());
140 } catch (ParseException e) {
141 processParseException(e);
147 * This method will process the parse exception.
148 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
149 * @param e the ParseException
151 private static void processParseException(final ParseException e) {
156 if (errorMessage == null) {
157 PHPeclipsePlugin.log(e);
158 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
159 errorStart = SimpleCharStream.getPosition();
160 errorEnd = errorStart + 1;
164 // if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e);
168 * Create marker for the parse error.
169 * @param e the ParseException
171 private static void setMarker(final ParseException e) {
173 if (errorStart == -1) {
174 setMarker(fileToParse,
176 SimpleCharStream.tokenBegin,
177 SimpleCharStream.tokenBegin + e.currentToken.image.length(),
179 "Line " + e.currentToken.beginLine);
181 setMarker(fileToParse,
186 "Line " + e.currentToken.beginLine);
190 } catch (CoreException e2) {
191 PHPeclipsePlugin.log(e2);
195 private static void scanLine(final String output,
198 final int brIndx) throws CoreException {
200 final StringBuffer lineNumberBuffer = new StringBuffer(10);
202 current = output.substring(indx, brIndx);
204 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
205 final int onLine = current.indexOf("on line <b>");
207 lineNumberBuffer.delete(0, lineNumberBuffer.length());
208 for (int i = onLine; i < current.length(); i++) {
209 ch = current.charAt(i);
210 if ('0' <= ch && '9' >= ch) {
211 lineNumberBuffer.append(ch);
215 final int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
217 final Hashtable attributes = new Hashtable();
219 current = current.replaceAll("\n", "");
220 current = current.replaceAll("<b>", "");
221 current = current.replaceAll("</b>", "");
222 MarkerUtilities.setMessage(attributes, current);
224 if (current.indexOf(PARSE_ERROR_STRING) != -1)
225 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
226 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
227 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
229 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
230 MarkerUtilities.setLineNumber(attributes, lineNumber);
231 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
236 public final void parse(final String s) throws CoreException {
237 final StringReader stream = new StringReader(s);
238 if (jj_input_stream == null) {
239 jj_input_stream = new SimpleCharStream(stream, 1, 1);
245 } catch (ParseException e) {
246 processParseException(e);
251 * Call the php parse command ( php -l -f <filename> )
252 * and create markers according to the external parser output
254 public static void phpExternalParse(final IFile file) {
255 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
256 final String filename = file.getLocation().toString();
258 final String[] arguments = { filename };
259 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
260 final String command = form.format(arguments);
262 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
265 // parse the buffer to find the errors and warnings
266 createMarkers(parserResult, file);
267 } catch (CoreException e) {
268 PHPeclipsePlugin.log(e);
273 * Put a new html block in the stack.
275 public static final void createNewHTMLCode() {
276 final int currentPosition = SimpleCharStream.getPosition();
277 if (currentPosition == htmlStart || currentPosition > SimpleCharStream.currentBuffer.length()) {
280 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
281 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
284 /** Create a new task. */
285 public static final void createNewTask() {
286 final int currentPosition = SimpleCharStream.getPosition();
287 final String todo = SimpleCharStream.currentBuffer.substring(currentPosition-3,
288 SimpleCharStream.currentBuffer.indexOf("\n",
290 PHPeclipsePlugin.log(1,SimpleCharStream.currentBuffer.toString());
292 setMarker(fileToParse,
294 SimpleCharStream.getBeginLine(),
296 "Line "+SimpleCharStream.getBeginLine());
297 } catch (CoreException e) {
298 PHPeclipsePlugin.log(e);
302 private static final void parse() throws ParseException {
307 PARSER_END(PHPParser)
311 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
312 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
313 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
318 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
321 /* Skip any character if we are not in php mode */
339 <PHPPARSING> SPECIAL_TOKEN :
341 "//" : IN_SINGLE_LINE_COMMENT
342 | "#" : IN_SINGLE_LINE_COMMENT
343 | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
344 | "/*" : IN_MULTI_LINE_COMMENT
347 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
349 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
353 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
355 "todo" {PHPParser.createNewTask();}
358 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
363 <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
368 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
378 | <FUNCTION : "function">
381 | <ELSEIF : "elseif">
388 /* LANGUAGE CONSTRUCT */
393 | <INCLUDE : "include">
394 | <REQUIRE : "require">
395 | <INCLUDE_ONCE : "include_once">
396 | <REQUIRE_ONCE : "require_once">
397 | <GLOBAL : "global">
398 | <DEFINE : "define">
399 | <STATIC : "static">
400 | <CLASSACCESS : "->">
401 | <STATICCLASSACCESS : "::">
402 | <ARRAYASSIGN : "=>">
405 /* RESERVED WORDS AND LITERALS */
411 | <CONTINUE : "continue">
412 | <_DEFAULT : "default">
414 | <EXTENDS : "extends">
419 | <RETURN : "return">
421 | <SWITCH : "switch">
426 | <ENDWHILE : "endwhile">
427 | <ENDSWITCH: "endswitch">
429 | <ENDFOR : "endfor">
430 | <FOREACH : "foreach">
438 | <OBJECT : "object">
440 | <BOOLEAN : "boolean">
442 | <DOUBLE : "double">
445 | <INTEGER : "integer">
465 | <MINUS_MINUS : "--">
475 | <RSIGNEDSHIFT : ">>">
476 | <RUNSIGNEDSHIFT : ">>>">
485 <DECIMAL_LITERAL> (["l","L"])?
486 | <HEX_LITERAL> (["l","L"])?
487 | <OCTAL_LITERAL> (["l","L"])?
490 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
492 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
494 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
496 <FLOATING_POINT_LITERAL:
497 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
498 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
499 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
500 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
503 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
505 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
506 | <STRING_1: "\"" ( ~["\"","\\"] | "\\" ~[] )* "\"">
507 | <STRING_2: "'" ( ~["'","\\"] | "\\" ~[] )* "'">
508 | <STRING_3: "`" ( ~["`","\\"] | "\\" ~[] )* "`">
515 <IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
518 ["a"-"z"] | ["A"-"Z"]
526 "_" | ["\u007f"-"\u00ff"]
551 | <EQUAL_EQUAL : "==">
556 | <BANGDOUBLEEQUAL : "!==">
557 | <TRIPLEEQUAL : "===">
564 | <PLUSASSIGN : "+=">
565 | <MINUSASSIGN : "-=">
566 | <STARASSIGN : "*=">
567 | <SLASHASSIGN : "/=">
573 | <TILDEEQUAL : "~=">
574 | <LSHIFTASSIGN : "<<=">
575 | <RSIGNEDSHIFTASSIGN : ">>=">
580 <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
588 {PHPParser.createNewHTMLCode();}
589 } catch (TokenMgrError e) {
590 PHPeclipsePlugin.log(e);
591 errorStart = SimpleCharStream.getPosition();
592 errorEnd = errorStart + 1;
593 errorMessage = e.getMessage();
595 throw generateParseException();
600 * A php block is a <?= expression [;]?>
601 * or <?php somephpcode ?>
602 * or <? somephpcode ?>
606 final int start = SimpleCharStream.getPosition();
607 final PHPEchoBlock phpEchoBlock;
610 phpEchoBlock = phpEchoBlock()
611 {pushOnAstNodes(phpEchoBlock);}
616 setMarker(fileToParse,
617 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
619 SimpleCharStream.getPosition(),
621 "Line " + token.beginLine);
622 } catch (CoreException e) {
623 PHPeclipsePlugin.log(e);
629 } catch (ParseException e) {
630 errorMessage = "'?>' expected";
632 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
633 errorEnd = SimpleCharStream.getPosition() + 1;
634 processParseException(e);
638 PHPEchoBlock phpEchoBlock() :
640 final Expression expr;
641 final int pos = SimpleCharStream.getPosition();
642 final PHPEchoBlock echoBlock;
645 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
647 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
648 pushOnAstNodes(echoBlock);
658 ClassDeclaration ClassDeclaration() :
660 final ClassDeclaration classDeclaration;
661 final Token className,superclassName;
663 char[] classNameImage = SYNTAX_ERROR_CHAR;
664 char[] superclassNameImage = null;
668 {pos = SimpleCharStream.getPosition();}
670 className = <IDENTIFIER>
671 {classNameImage = className.image.toCharArray();}
672 } catch (ParseException e) {
673 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
675 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
676 errorEnd = SimpleCharStream.getPosition() + 1;
677 processParseException(e);
682 superclassName = <IDENTIFIER>
683 {superclassNameImage = superclassName.image.toCharArray();}
684 } catch (ParseException e) {
685 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
687 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
688 errorEnd = SimpleCharStream.getPosition() + 1;
689 processParseException(e);
690 superclassNameImage = SYNTAX_ERROR_CHAR;
694 if (superclassNameImage == null) {
695 classDeclaration = new ClassDeclaration(currentSegment,
700 classDeclaration = new ClassDeclaration(currentSegment,
706 currentSegment.add(classDeclaration);
707 currentSegment = classDeclaration;
709 ClassBody(classDeclaration)
710 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
711 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
712 pushOnAstNodes(classDeclaration);
713 return classDeclaration;}
716 void ClassBody(final ClassDeclaration classDeclaration) :
721 } catch (ParseException e) {
722 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected";
724 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
725 errorEnd = SimpleCharStream.getPosition() + 1;
726 processParseException(e);
728 ( ClassBodyDeclaration(classDeclaration) )*
731 } catch (ParseException e) {
732 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected";
734 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
735 errorEnd = SimpleCharStream.getPosition() + 1;
736 processParseException(e);
741 * A class can contain only methods and fields.
743 void ClassBodyDeclaration(final ClassDeclaration classDeclaration) :
745 final MethodDeclaration method;
746 final FieldDeclaration field;
749 method = MethodDeclaration() {method.analyzeCode();
750 classDeclaration.addMethod(method);}
751 | field = FieldDeclaration() {classDeclaration.addField(field);}
755 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
756 * it is only used by ClassBodyDeclaration()
758 FieldDeclaration FieldDeclaration() :
760 VariableDeclaration variableDeclaration;
761 final VariableDeclaration[] list;
762 final ArrayList arrayList = new ArrayList();
763 final int pos = SimpleCharStream.getPosition();
766 <VAR> variableDeclaration = VariableDeclaratorNoSuffix()
767 {arrayList.add(variableDeclaration);
768 outlineInfo.addVariable(new String(variableDeclaration.name));}
770 <COMMA> variableDeclaration = VariableDeclaratorNoSuffix()
771 {arrayList.add(variableDeclaration);
772 outlineInfo.addVariable(new String(variableDeclaration.name));}
776 } catch (ParseException e) {
777 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
779 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
780 errorEnd = SimpleCharStream.getPosition() + 1;
781 processParseException(e);
784 {list = new VariableDeclaration[arrayList.size()];
785 arrayList.toArray(list);
786 return new FieldDeclaration(list,
788 SimpleCharStream.getPosition(),
793 * a strict variable declarator : there cannot be a suffix here.
795 VariableDeclaration VariableDeclaratorNoSuffix() :
798 Expression initializer = null;
799 final int pos = SimpleCharStream.getPosition();
802 varName = <DOLLAR_ID>
806 initializer = VariableInitializer()
807 } catch (ParseException e) {
808 errorMessage = "Literal expression expected in variable initializer";
810 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
811 errorEnd = SimpleCharStream.getPosition() + 1;
812 processParseException(e);
816 if (initializer == null) {
817 return new VariableDeclaration(currentSegment,
818 varName.image.substring(1).toCharArray(),
820 SimpleCharStream.getPosition());
822 return new VariableDeclaration(currentSegment,
823 varName.image.substring(1).toCharArray(),
825 VariableDeclaration.EQUAL,
830 VariableDeclaration VariableDeclarator() :
832 final String varName;
833 Expression initializer = null;
834 final int pos = SimpleCharStream.getPosition();
837 varName = VariableDeclaratorId()
841 initializer = VariableInitializer()
842 } catch (ParseException e) {
843 errorMessage = "Literal expression expected in variable initializer";
845 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
846 errorEnd = SimpleCharStream.getPosition() + 1;
847 processParseException(e);
851 if (initializer == null) {
852 return new VariableDeclaration(currentSegment,
853 varName.toCharArray(),
855 SimpleCharStream.getPosition());
857 return new VariableDeclaration(currentSegment,
858 varName.toCharArray(),
860 VariableDeclaration.EQUAL,
867 * @return the variable name (with suffix)
869 String VariableDeclaratorId() :
872 Expression expression = null;
873 final int pos = SimpleCharStream.getPosition();
874 ConstantIdentifier ex;
881 {ex = new ConstantIdentifier(var.toCharArray(),
883 SimpleCharStream.getPosition());}
884 expression = VariableSuffix(ex)
887 if (expression == null) {
890 return expression.toStringExpression();
892 } catch (ParseException e) {
893 errorMessage = "'$' expected for variable identifier";
895 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
896 errorEnd = SimpleCharStream.getPosition() + 1;
902 * Return a variablename without the $.
903 * @return a variable name
907 final StringBuffer buff;
908 Expression expression = null;
913 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
915 if (expression == null) {
916 return token.image.substring(1);
918 buff = new StringBuffer(token.image);
920 buff.append(expression.toStringExpression());
922 return buff.toString();
925 <DOLLAR> expr = VariableName()
930 * A Variable name (without the $)
931 * @return a variable name String
933 String VariableName():
935 final StringBuffer buff;
937 Expression expression = null;
941 <LBRACE> expression = Expression() <RBRACE>
942 {buff = new StringBuffer("{");
943 buff.append(expression.toStringExpression());
945 return buff.toString();}
947 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
949 if (expression == null) {
952 buff = new StringBuffer(token.image);
954 buff.append(expression.toStringExpression());
956 return buff.toString();
959 <DOLLAR> expr = VariableName()
961 buff = new StringBuffer("$");
963 return buff.toString();
966 token = <DOLLAR_ID> {return token.image;}
969 Expression VariableInitializer() :
971 final Expression expr;
973 final int pos = SimpleCharStream.getPosition();
979 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
980 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
982 SimpleCharStream.getPosition()),
986 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
987 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
989 SimpleCharStream.getPosition()),
993 expr = ArrayDeclarator()
997 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
1000 ArrayVariableDeclaration ArrayVariable() :
1002 final Expression expr,expr2;
1007 <ARRAYASSIGN> expr2 = Expression()
1008 {return new ArrayVariableDeclaration(expr,expr2);}
1010 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
1013 ArrayVariableDeclaration[] ArrayInitializer() :
1015 ArrayVariableDeclaration expr;
1016 final ArrayList list = new ArrayList();
1021 expr = ArrayVariable()
1023 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
1028 <COMMA> {list.add(null);}
1032 final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
1038 * A Method Declaration.
1039 * <b>function</b> MetodDeclarator() Block()
1041 MethodDeclaration MethodDeclaration() :
1043 final MethodDeclaration functionDeclaration;
1045 final OutlineableWithChildren seg = currentSegment;
1050 functionDeclaration = MethodDeclarator()
1051 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1052 } catch (ParseException e) {
1053 if (errorMessage != null) throw e;
1054 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1056 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1057 errorEnd = SimpleCharStream.getPosition() + 1;
1060 {currentSegment = functionDeclaration;}
1062 {functionDeclaration.statements = block.statements;
1063 currentSegment = seg;
1064 return functionDeclaration;}
1068 * A MethodDeclarator.
1069 * [&] IDENTIFIER(parameters ...).
1070 * @return a function description for the outline
1072 MethodDeclaration MethodDeclarator() :
1074 final Token identifier;
1075 Token reference = null;
1076 final Hashtable formalParameters;
1077 final int pos = SimpleCharStream.getPosition();
1078 char[] identifierChar = SYNTAX_ERROR_CHAR;
1081 [reference = <BIT_AND>]
1083 identifier = <IDENTIFIER>
1084 {identifierChar = identifier.image.toCharArray();}
1085 } catch (ParseException e) {
1086 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1088 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1089 errorEnd = SimpleCharStream.getPosition() + 1;
1090 processParseException(e);
1092 formalParameters = FormalParameters()
1093 {MethodDeclaration method = new MethodDeclaration(currentSegment,
1098 SimpleCharStream.getPosition());
1103 * FormalParameters follows method identifier.
1104 * (FormalParameter())
1106 Hashtable FormalParameters() :
1108 VariableDeclaration var;
1109 final Hashtable parameters = new Hashtable();
1114 } catch (ParseException e) {
1115 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1117 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1118 errorEnd = SimpleCharStream.getPosition() + 1;
1119 processParseException(e);
1122 var = FormalParameter()
1123 {parameters.put(new String(var.name),var);}
1125 <COMMA> var = FormalParameter()
1126 {parameters.put(new String(var.name),var);}
1131 } catch (ParseException e) {
1132 errorMessage = "')' expected";
1134 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1135 errorEnd = SimpleCharStream.getPosition() + 1;
1136 processParseException(e);
1138 {return parameters;}
1142 * A formal parameter.
1143 * $varname[=value] (,$varname[=value])
1145 VariableDeclaration FormalParameter() :
1147 final VariableDeclaration variableDeclaration;
1151 [token = <BIT_AND>] variableDeclaration = VariableDeclaratorNoSuffix()
1153 if (token != null) {
1154 variableDeclaration.setReference(true);
1156 return variableDeclaration;}
1159 ConstantIdentifier Type() :
1162 <STRING> {pos = SimpleCharStream.getPosition();
1163 return new ConstantIdentifier(Types.STRING,pos,pos-6);}
1164 | <BOOL> {pos = SimpleCharStream.getPosition();
1165 return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
1166 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1167 return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
1168 | <REAL> {pos = SimpleCharStream.getPosition();
1169 return new ConstantIdentifier(Types.REAL,pos,pos-4);}
1170 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1171 return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
1172 | <FLOAT> {pos = SimpleCharStream.getPosition();
1173 return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
1174 | <INT> {pos = SimpleCharStream.getPosition();
1175 return new ConstantIdentifier(Types.INT,pos,pos-3);}
1176 | <INTEGER> {pos = SimpleCharStream.getPosition();
1177 return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
1178 | <OBJECT> {pos = SimpleCharStream.getPosition();
1179 return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
1182 Expression Expression() :
1184 final Expression expr;
1185 Expression initializer = null;
1186 final int pos = SimpleCharStream.getPosition();
1189 expr = ConditionalExpression() {return expr;}
1190 | expr = ExpressionWBang() {return expr;}
1193 Expression ExpressionWBang() :
1195 final Expression expr;
1196 final int pos = SimpleCharStream.getPosition();
1199 <BANG> expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1200 | expr = ExpressionNoBang() {return expr;}
1203 Expression ExpressionNoBang() :
1205 Expression expr = null;
1206 int assignOperator = -1;
1208 final int pos = SimpleCharStream.getPosition();
1211 expr = PrintExpression() {return expr;}
1212 | expr = ListExpression() {return expr;}
1214 var = VariableDeclaratorId()
1216 assignOperator = AssignmentOperator()
1219 } catch (ParseException e) {
1220 if (errorMessage != null) {
1223 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1225 errorEnd = SimpleCharStream.getPosition();
1230 if (assignOperator == -1) {
1231 return new VariableDeclaration(currentSegment,
1234 SimpleCharStream.getPosition());
1236 return new VariableDeclaration(currentSegment,
1246 * Any assignement operator.
1247 * @return the assignement operator id
1249 int AssignmentOperator() :
1252 <ASSIGN> {return VariableDeclaration.EQUAL;}
1253 | <STARASSIGN> {return VariableDeclaration.STAR_EQUAL;}
1254 | <SLASHASSIGN> {return VariableDeclaration.SLASH_EQUAL;}
1255 | <REMASSIGN> {return VariableDeclaration.REM_EQUAL;}
1256 | <PLUSASSIGN> {return VariableDeclaration.PLUS_EQUAL;}
1257 | <MINUSASSIGN> {return VariableDeclaration.MINUS_EQUAL;}
1258 | <LSHIFTASSIGN> {return VariableDeclaration.LSHIFT_EQUAL;}
1259 | <RSIGNEDSHIFTASSIGN> {return VariableDeclaration.RSIGNEDSHIFT_EQUAL;}
1260 | <ANDASSIGN> {return VariableDeclaration.AND_EQUAL;}
1261 | <XORASSIGN> {return VariableDeclaration.XOR_EQUAL;}
1262 | <ORASSIGN> {return VariableDeclaration.OR_EQUAL;}
1263 | <DOTASSIGN> {return VariableDeclaration.DOT_EQUAL;}
1264 | <TILDEEQUAL> {return VariableDeclaration.TILDE_EQUAL;}
1267 Expression ConditionalExpression() :
1269 final Expression expr;
1270 Expression expr2 = null;
1271 Expression expr3 = null;
1274 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1276 if (expr3 == null) {
1279 return new ConditionalExpression(expr,expr2,expr3);
1283 Expression ConditionalOrExpression() :
1285 Expression expr,expr2;
1289 expr = ConditionalAndExpression()
1292 <OR_OR> {operator = OperatorIds.OR_OR;}
1293 | <_ORL> {operator = OperatorIds.ORL;}
1295 expr2 = ConditionalAndExpression()
1297 expr = new BinaryExpression(expr,expr2,operator);
1303 Expression ConditionalAndExpression() :
1305 Expression expr,expr2;
1309 expr = ConcatExpression()
1311 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1312 | <_ANDL> {operator = OperatorIds.ANDL;})
1313 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1318 Expression ConcatExpression() :
1320 Expression expr,expr2;
1323 expr = InclusiveOrExpression()
1325 <DOT> expr2 = InclusiveOrExpression()
1326 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1331 Expression InclusiveOrExpression() :
1333 Expression expr,expr2;
1336 expr = ExclusiveOrExpression()
1337 (<BIT_OR> expr2 = ExclusiveOrExpression()
1338 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1343 Expression ExclusiveOrExpression() :
1345 Expression expr,expr2;
1348 expr = AndExpression()
1350 <XOR> expr2 = AndExpression()
1351 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1356 Expression AndExpression() :
1358 Expression expr,expr2;
1361 expr = EqualityExpression()
1364 <BIT_AND> expr2 = EqualityExpression()
1365 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1370 Expression EqualityExpression() :
1372 Expression expr,expr2;
1376 expr = RelationalExpression()
1378 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1379 | <DIF> {operator = OperatorIds.DIF;}
1380 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1381 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1382 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1385 expr2 = RelationalExpression()
1386 } catch (ParseException e) {
1387 if (errorMessage != null) {
1390 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1392 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1393 errorEnd = SimpleCharStream.getPosition() + 1;
1397 expr = new BinaryExpression(expr,expr2,operator);
1403 Expression RelationalExpression() :
1405 Expression expr,expr2;
1409 expr = ShiftExpression()
1411 ( <LT> {operator = OperatorIds.LESS;}
1412 | <GT> {operator = OperatorIds.GREATER;}
1413 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1414 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1415 expr2 = ShiftExpression()
1416 {expr = new BinaryExpression(expr,expr2,operator);}
1421 Expression ShiftExpression() :
1423 Expression expr,expr2;
1427 expr = AdditiveExpression()
1429 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1430 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1431 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1432 expr2 = AdditiveExpression()
1433 {expr = new BinaryExpression(expr,expr2,operator);}
1438 Expression AdditiveExpression() :
1440 Expression expr,expr2;
1444 expr = MultiplicativeExpression()
1447 ( <PLUS> {operator = OperatorIds.PLUS;}
1448 | <MINUS> {operator = OperatorIds.MINUS;} )
1449 expr2 = MultiplicativeExpression()
1450 {expr = new BinaryExpression(expr,expr2,operator);}
1455 Expression MultiplicativeExpression() :
1457 Expression expr,expr2;
1462 expr = UnaryExpression()
1463 } catch (ParseException e) {
1464 if (errorMessage != null) throw e;
1465 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1467 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1468 errorEnd = SimpleCharStream.getPosition() + 1;
1472 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1473 | <SLASH> {operator = OperatorIds.DIVIDE;}
1474 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1475 expr2 = UnaryExpression()
1476 {expr = new BinaryExpression(expr,expr2,operator);}
1482 * An unary expression starting with @, & or nothing
1484 Expression UnaryExpression() :
1486 final Expression expr;
1487 final int pos = SimpleCharStream.getPosition();
1490 <BIT_AND> expr = UnaryExpressionNoPrefix()
1491 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1493 expr = AtUnaryExpression() {return expr;}
1496 Expression AtUnaryExpression() :
1498 final Expression expr;
1499 final int pos = SimpleCharStream.getPosition();
1503 expr = AtUnaryExpression()
1504 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1506 expr = UnaryExpressionNoPrefix()
1511 Expression UnaryExpressionNoPrefix() :
1513 final Expression expr;
1515 final int pos = SimpleCharStream.getPosition();
1519 <PLUS> {operator = OperatorIds.PLUS;}
1521 <MINUS> {operator = OperatorIds.MINUS;}
1523 expr = UnaryExpression()
1524 {return new PrefixedUnaryExpression(expr,operator,pos);}
1526 expr = PreIncDecExpression()
1529 expr = UnaryExpressionNotPlusMinus()
1534 Expression PreIncDecExpression() :
1536 final Expression expr;
1538 final int pos = SimpleCharStream.getPosition();
1542 <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1544 <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}
1546 expr = PrimaryExpression()
1547 {return new PrefixedUnaryExpression(expr,operator,pos);}
1550 Expression UnaryExpressionNotPlusMinus() :
1552 final Expression expr;
1553 final int pos = SimpleCharStream.getPosition();
1556 LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1557 expr = CastExpression() {return expr;}
1558 | expr = PostfixExpression() {return expr;}
1559 | expr = Literal() {return expr;}
1560 | <LPAREN> expr = Expression()
1563 } catch (ParseException e) {
1564 errorMessage = "')' expected";
1566 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1567 errorEnd = SimpleCharStream.getPosition() + 1;
1573 CastExpression CastExpression() :
1575 final ConstantIdentifier type;
1576 final Expression expr;
1577 final int pos = SimpleCharStream.getPosition();
1584 <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());}
1586 <RPAREN> expr = UnaryExpression()
1587 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1590 Expression PostfixExpression() :
1592 final Expression expr;
1594 final int pos = SimpleCharStream.getPosition();
1597 expr = PrimaryExpression()
1599 <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1601 <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}
1604 if (operator == -1) {
1607 return new PostfixedUnaryExpression(expr,operator,pos);
1611 Expression PrimaryExpression() :
1614 int assignOperator = -1;
1615 final Token identifier;
1617 final int pos = SimpleCharStream.getPosition();
1620 identifier = <IDENTIFIER>
1621 {expr = new ConstantIdentifier(token.image.toCharArray(),
1623 SimpleCharStream.getPosition());}
1624 (expr = PrimarySuffix(expr))*
1627 expr = ArrayDeclarator()
1630 <NEW> expr = ClassIdentifier()
1631 {expr = new PrefixedUnaryExpression(expr,OperatorIds.NEW,pos);}
1632 [expr = Arguments(expr)]
1636 AbstractSuffixExpression PrimarySuffix(final Expression prefix) :
1638 final AbstractSuffixExpression suffix;
1639 final Expression expr;
1642 suffix = Arguments(prefix) {return suffix;}
1643 | suffix = VariableSuffix(prefix) {return suffix;}
1644 | <STATICCLASSACCESS> expr = ClassIdentifier()
1645 {suffix = new ClassAccess(prefix,
1647 ClassAccess.STATIC);
1652 * An array declarator.
1656 ArrayInitializer ArrayDeclarator() :
1658 final ArrayVariableDeclaration[] vars;
1659 final int pos = SimpleCharStream.getPosition();
1662 <ARRAY> vars = ArrayInitializer()
1663 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1666 PrefixedUnaryExpression classInstantiation() :
1669 final StringBuffer buff;
1670 final int pos = SimpleCharStream.getPosition();
1673 <NEW> expr = ClassIdentifier()
1675 {buff = new StringBuffer(expr.toStringExpression());}
1676 expr = PrimaryExpression()
1677 {buff.append(expr.toStringExpression());
1678 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1680 SimpleCharStream.getPosition());}
1682 {return new PrefixedUnaryExpression(expr,
1687 ConstantIdentifier ClassIdentifier():
1691 final int pos = SimpleCharStream.getPosition();
1692 final ConstantIdentifier type;
1695 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1697 SimpleCharStream.getPosition());}
1698 | type = Type() {return type;}
1699 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1701 SimpleCharStream.getPosition());}
1704 AbstractSuffixExpression VariableSuffix(final Expression prefix) :
1707 final int pos = SimpleCharStream.getPosition();
1708 Expression expression = null;
1713 expr = VariableName()
1714 } catch (ParseException e) {
1715 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1717 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1718 errorEnd = SimpleCharStream.getPosition() + 1;
1721 {return new ClassAccess(prefix,
1722 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1723 ClassAccess.NORMAL);}
1725 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1728 } catch (ParseException e) {
1729 errorMessage = "']' expected";
1731 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1732 errorEnd = SimpleCharStream.getPosition() + 1;
1735 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1744 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1745 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1746 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1747 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1748 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1749 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1750 | <TRUE> {pos = SimpleCharStream.getPosition();
1751 return new TrueLiteral(pos-4,pos);}
1752 | <FALSE> {pos = SimpleCharStream.getPosition();
1753 return new FalseLiteral(pos-4,pos);}
1754 | <NULL> {pos = SimpleCharStream.getPosition();
1755 return new NullLiteral(pos-4,pos);}
1758 FunctionCall Arguments(final Expression func) :
1760 Expression[] args = null;
1763 <LPAREN> [ args = ArgumentList() ]
1766 } catch (ParseException e) {
1767 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1769 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1770 errorEnd = SimpleCharStream.getPosition() + 1;
1773 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1777 * An argument list is a list of arguments separated by comma :
1778 * argumentDeclaration() (, argumentDeclaration)*
1779 * @return an array of arguments
1781 Expression[] ArgumentList() :
1784 final ArrayList list = new ArrayList();
1793 } catch (ParseException e) {
1794 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1796 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1797 errorEnd = SimpleCharStream.getPosition() + 1;
1802 final Expression[] arguments = new Expression[list.size()];
1803 list.toArray(arguments);
1808 * A Statement without break.
1810 Statement StatementNoBreak() :
1812 final Statement statement;
1817 statement = Expression()
1820 } catch (ParseException e) {
1821 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1822 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1824 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1825 errorEnd = SimpleCharStream.getPosition() + 1;
1831 statement = LabeledStatement() {return statement;}
1832 | statement = Block() {return statement;}
1833 | statement = EmptyStatement() {return statement;}
1834 /*| statement = StatementExpression()
1837 } catch (ParseException e) {
1838 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1840 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1841 errorEnd = SimpleCharStream.getPosition() + 1;
1844 {return statement;} */
1845 | statement = SwitchStatement() {return statement;}
1846 | statement = IfStatement() {return statement;}
1847 | statement = WhileStatement() {return statement;}
1848 | statement = DoStatement() {return statement;}
1849 | statement = ForStatement() {return statement;}
1850 | statement = ForeachStatement() {return statement;}
1851 | statement = ContinueStatement() {return statement;}
1852 | statement = ReturnStatement() {return statement;}
1853 | statement = EchoStatement() {return statement;}
1854 | [token=<AT>] statement = IncludeStatement()
1855 {if (token != null) {
1856 ((InclusionStatement)statement).silent = true;
1859 | statement = StaticStatement() {return statement;}
1860 | statement = GlobalStatement() {return statement;}
1861 | statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
1864 Define defineStatement() :
1866 final int start = SimpleCharStream.getPosition();
1867 Expression defineName,defineValue;
1873 } catch (ParseException e) {
1874 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1876 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1877 errorEnd = SimpleCharStream.getPosition() + 1;
1878 processParseException(e);
1881 defineName = Expression()
1882 } catch (ParseException e) {
1883 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1885 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1886 errorEnd = SimpleCharStream.getPosition() + 1;
1891 } catch (ParseException e) {
1892 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1894 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1895 errorEnd = SimpleCharStream.getPosition() + 1;
1896 processParseException(e);
1899 defineValue = Expression()
1900 } catch (ParseException e) {
1901 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1903 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1904 errorEnd = SimpleCharStream.getPosition() + 1;
1909 } catch (ParseException e) {
1910 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1912 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1913 errorEnd = SimpleCharStream.getPosition() + 1;
1914 processParseException(e);
1916 {return new Define(currentSegment,
1920 SimpleCharStream.getPosition());}
1924 * A Normal statement.
1926 Statement Statement() :
1928 final Statement statement;
1931 statement = StatementNoBreak() {return statement;}
1932 | statement = BreakStatement() {return statement;}
1936 * An html block inside a php syntax.
1938 HTMLBlock htmlBlock() :
1940 final int startIndex = nodePtr;
1941 final AstNode[] blockNodes;
1945 <PHPEND> (phpEchoBlock())*
1947 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1948 } catch (ParseException e) {
1949 errorMessage = "unexpected end of file , '<?php' expected";
1951 errorStart = SimpleCharStream.getPosition();
1952 errorEnd = SimpleCharStream.getPosition();
1956 nbNodes = nodePtr - startIndex;
1957 blockNodes = new AstNode[nbNodes];
1958 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1959 nodePtr = startIndex;
1960 return new HTMLBlock(blockNodes);}
1964 * An include statement. It's "include" an expression;
1966 InclusionStatement IncludeStatement() :
1968 final Expression expr;
1970 final int pos = SimpleCharStream.getPosition();
1971 final InclusionStatement inclusionStatement;
1974 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1975 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1976 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1977 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1980 } catch (ParseException e) {
1981 if (errorMessage != null) {
1984 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1986 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1987 errorEnd = SimpleCharStream.getPosition() + 1;
1990 {inclusionStatement = new InclusionStatement(currentSegment,
1994 currentSegment.add(inclusionStatement);
1998 } catch (ParseException e) {
1999 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2001 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2002 errorEnd = SimpleCharStream.getPosition() + 1;
2005 {return inclusionStatement;}
2008 PrintExpression PrintExpression() :
2010 final Expression expr;
2011 final int pos = SimpleCharStream.getPosition();
2014 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
2017 ListExpression ListExpression() :
2020 final Expression expression;
2021 final ArrayList list = new ArrayList();
2022 final int pos = SimpleCharStream.getPosition();
2028 } catch (ParseException e) {
2029 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
2031 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2032 errorEnd = SimpleCharStream.getPosition() + 1;
2036 expr = VariableDeclaratorId()
2039 {if (expr == null) list.add(null);}
2043 } catch (ParseException e) {
2044 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
2046 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2047 errorEnd = SimpleCharStream.getPosition() + 1;
2050 [expr = VariableDeclaratorId() {list.add(expr);}]
2054 } catch (ParseException e) {
2055 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
2057 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2058 errorEnd = SimpleCharStream.getPosition() + 1;
2061 [ <ASSIGN> expression = Expression()
2063 final String[] strings = new String[list.size()];
2064 list.toArray(strings);
2065 return new ListExpression(strings,
2068 SimpleCharStream.getPosition());}
2071 final String[] strings = new String[list.size()];
2072 list.toArray(strings);
2073 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
2077 * An echo statement.
2078 * echo anyexpression (, otherexpression)*
2080 EchoStatement EchoStatement() :
2082 final ArrayList expressions = new ArrayList();
2084 final int pos = SimpleCharStream.getPosition();
2087 <ECHO> expr = Expression()
2088 {expressions.add(expr);}
2090 <COMMA> expr = Expression()
2091 {expressions.add(expr);}
2095 } catch (ParseException e) {
2096 if (e.currentToken.next.kind != 4) {
2097 errorMessage = "';' expected after 'echo' statement";
2099 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2100 errorEnd = SimpleCharStream.getPosition() + 1;
2104 {final Expression[] exprs = new Expression[expressions.size()];
2105 expressions.toArray(exprs);
2106 return new EchoStatement(exprs,pos);}
2109 GlobalStatement GlobalStatement() :
2111 final int pos = SimpleCharStream.getPosition();
2113 final ArrayList vars = new ArrayList();
2114 final GlobalStatement global;
2118 expr = VariableDeclaratorId()
2121 expr = VariableDeclaratorId()
2127 final String[] strings = new String[vars.size()];
2128 vars.toArray(strings);
2129 global = new GlobalStatement(currentSegment,
2132 SimpleCharStream.getPosition());
2133 currentSegment.add(global);
2135 } catch (ParseException e) {
2136 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2138 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2139 errorEnd = SimpleCharStream.getPosition() + 1;
2144 StaticStatement StaticStatement() :
2146 final int pos = SimpleCharStream.getPosition();
2147 final ArrayList vars = new ArrayList();
2148 VariableDeclaration expr;
2151 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2152 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2156 final String[] strings = new String[vars.size()];
2157 vars.toArray(strings);
2158 return new StaticStatement(strings,
2160 SimpleCharStream.getPosition());}
2161 } catch (ParseException e) {
2162 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2164 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2165 errorEnd = SimpleCharStream.getPosition() + 1;
2170 LabeledStatement LabeledStatement() :
2172 final int pos = SimpleCharStream.getPosition();
2174 final Statement statement;
2177 label = <IDENTIFIER> <COLON> statement = Statement()
2178 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2190 final int pos = SimpleCharStream.getPosition();
2191 final ArrayList list = new ArrayList();
2192 Statement statement;
2197 } catch (ParseException e) {
2198 errorMessage = "'{' expected";
2200 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2201 errorEnd = SimpleCharStream.getPosition() + 1;
2204 ( statement = BlockStatement() {list.add(statement);}
2205 | statement = htmlBlock() {list.add(statement);})*
2208 } catch (ParseException e) {
2209 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2211 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2212 errorEnd = SimpleCharStream.getPosition() + 1;
2216 final Statement[] statements = new Statement[list.size()];
2217 list.toArray(statements);
2218 return new Block(statements,pos,SimpleCharStream.getPosition());}
2221 Statement BlockStatement() :
2223 final Statement statement;
2226 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2228 | statement = ClassDeclaration() {return statement;}
2229 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2230 currentSegment.add((MethodDeclaration) statement);
2231 ((MethodDeclaration) statement).analyzeCode();
2236 * A Block statement that will not contain any 'break'
2238 Statement BlockStatementNoBreak() :
2240 final Statement statement;
2243 statement = StatementNoBreak() {return statement;}
2244 | statement = ClassDeclaration() {return statement;}
2245 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2246 ((MethodDeclaration) statement).analyzeCode();
2250 VariableDeclaration[] LocalVariableDeclaration() :
2252 final ArrayList list = new ArrayList();
2253 VariableDeclaration var;
2256 var = LocalVariableDeclarator()
2258 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2260 final VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2265 VariableDeclaration LocalVariableDeclarator() :
2267 final String varName;
2268 Expression initializer = null;
2269 final int pos = SimpleCharStream.getPosition();
2272 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2274 if (initializer == null) {
2275 return new VariableDeclaration(currentSegment,
2276 varName.toCharArray(),
2278 SimpleCharStream.getPosition());
2280 return new VariableDeclaration(currentSegment,
2281 varName.toCharArray(),
2283 VariableDeclaration.EQUAL,
2288 EmptyStatement EmptyStatement() :
2294 {pos = SimpleCharStream.getPosition();
2295 return new EmptyStatement(pos-1,pos);}
2298 Expression StatementExpression() :
2300 final Expression expr,expr2;
2304 expr = PreIncDecExpression() {return expr;}
2306 expr = PrimaryExpression()
2307 [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
2308 OperatorIds.PLUS_PLUS,
2309 SimpleCharStream.getPosition());}
2310 | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
2311 OperatorIds.MINUS_MINUS,
2312 SimpleCharStream.getPosition());}
2317 SwitchStatement SwitchStatement() :
2319 final Expression variable;
2320 final AbstractCase[] cases;
2321 final int pos = SimpleCharStream.getPosition();
2327 } catch (ParseException e) {
2328 errorMessage = "'(' expected after 'switch'";
2330 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2331 errorEnd = SimpleCharStream.getPosition() + 1;
2335 variable = Expression()
2336 } catch (ParseException e) {
2337 if (errorMessage != null) {
2340 errorMessage = "expression expected";
2342 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2343 errorEnd = SimpleCharStream.getPosition() + 1;
2348 } catch (ParseException e) {
2349 errorMessage = "')' expected";
2351 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2352 errorEnd = SimpleCharStream.getPosition() + 1;
2355 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2356 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2359 AbstractCase[] switchStatementBrace() :
2362 final ArrayList cases = new ArrayList();
2366 ( cas = switchLabel0() {cases.add(cas);})*
2370 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2371 cases.toArray(abcase);
2373 } catch (ParseException e) {
2374 errorMessage = "'}' expected";
2376 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2377 errorEnd = SimpleCharStream.getPosition() + 1;
2382 * A Switch statement with : ... endswitch;
2383 * @param start the begin offset of the switch
2384 * @param end the end offset of the switch
2386 AbstractCase[] switchStatementColon(final int start, final int end) :
2389 final ArrayList cases = new ArrayList();
2394 setMarker(fileToParse,
2395 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2399 "Line " + token.beginLine);
2400 } catch (CoreException e) {
2401 PHPeclipsePlugin.log(e);
2403 ( cas = switchLabel0() {cases.add(cas);})*
2406 } catch (ParseException e) {
2407 errorMessage = "'endswitch' expected";
2409 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2410 errorEnd = SimpleCharStream.getPosition() + 1;
2416 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2417 cases.toArray(abcase);
2419 } catch (ParseException e) {
2420 errorMessage = "';' expected after 'endswitch' keyword";
2422 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2423 errorEnd = SimpleCharStream.getPosition() + 1;
2428 AbstractCase switchLabel0() :
2430 final Expression expr;
2431 Statement statement;
2432 final ArrayList stmts = new ArrayList();
2433 final int pos = SimpleCharStream.getPosition();
2436 expr = SwitchLabel()
2437 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2438 | statement = htmlBlock() {stmts.add(statement);})*
2439 [ statement = BreakStatement() {stmts.add(statement);}]
2441 final Statement[] stmtsArray = new Statement[stmts.size()];
2442 stmts.toArray(stmtsArray);
2443 if (expr == null) {//it's a default
2444 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2446 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2451 * case Expression() :
2453 * @return the if it was a case and null if not
2455 Expression SwitchLabel() :
2457 final Expression expr;
2463 } catch (ParseException e) {
2464 if (errorMessage != null) throw e;
2465 errorMessage = "expression expected after 'case' keyword";
2467 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2468 errorEnd = SimpleCharStream.getPosition() + 1;
2474 } catch (ParseException e) {
2475 errorMessage = "':' expected after case expression";
2477 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2478 errorEnd = SimpleCharStream.getPosition() + 1;
2486 } catch (ParseException e) {
2487 errorMessage = "':' expected after 'default' keyword";
2489 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2490 errorEnd = SimpleCharStream.getPosition() + 1;
2495 Break BreakStatement() :
2497 Expression expression = null;
2498 final int start = SimpleCharStream.getPosition();
2501 <BREAK> [ expression = Expression() ]
2504 } catch (ParseException e) {
2505 errorMessage = "';' expected after 'break' keyword";
2507 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2508 errorEnd = SimpleCharStream.getPosition() + 1;
2511 {return new Break(expression, start, SimpleCharStream.getPosition());}
2514 IfStatement IfStatement() :
2516 final int pos = SimpleCharStream.getPosition();
2517 final Expression condition;
2518 final IfStatement ifStatement;
2521 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2522 {return ifStatement;}
2526 Expression Condition(final String keyword) :
2528 final Expression condition;
2533 } catch (ParseException e) {
2534 errorMessage = "'(' expected after " + keyword + " keyword";
2536 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2537 errorEnd = errorStart +1;
2538 processParseException(e);
2540 condition = Expression()
2543 } catch (ParseException e) {
2544 errorMessage = "')' expected after " + keyword + " keyword";
2546 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2547 errorEnd = SimpleCharStream.getPosition() + 1;
2548 processParseException(e);
2553 IfStatement IfStatement0(final Expression condition, final int start,final int end) :
2555 Statement statement;
2556 final Statement stmt;
2557 final Statement[] statementsArray;
2558 ElseIf elseifStatement;
2559 Else elseStatement = null;
2560 final ArrayList stmts;
2561 final ArrayList elseIfList = new ArrayList();
2562 final ElseIf[] elseIfs;
2563 int pos = SimpleCharStream.getPosition();
2564 final int endStatements;
2568 {stmts = new ArrayList();}
2569 ( statement = Statement() {stmts.add(statement);}
2570 | statement = htmlBlock() {stmts.add(statement);})*
2571 {endStatements = SimpleCharStream.getPosition();}
2572 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2573 [elseStatement = ElseStatementColon()]
2576 setMarker(fileToParse,
2577 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2581 "Line " + token.beginLine);
2582 } catch (CoreException e) {
2583 PHPeclipsePlugin.log(e);
2587 } catch (ParseException e) {
2588 errorMessage = "'endif' expected";
2590 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2591 errorEnd = SimpleCharStream.getPosition() + 1;
2596 } catch (ParseException e) {
2597 errorMessage = "';' expected after 'endif' keyword";
2599 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2600 errorEnd = SimpleCharStream.getPosition() + 1;
2604 elseIfs = new ElseIf[elseIfList.size()];
2605 elseIfList.toArray(elseIfs);
2606 if (stmts.size() == 1) {
2607 return new IfStatement(condition,
2608 (Statement) stmts.get(0),
2612 SimpleCharStream.getPosition());
2614 statementsArray = new Statement[stmts.size()];
2615 stmts.toArray(statementsArray);
2616 return new IfStatement(condition,
2617 new Block(statementsArray,pos,endStatements),
2621 SimpleCharStream.getPosition());
2626 (stmt = Statement() | stmt = htmlBlock())
2627 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2631 {pos = SimpleCharStream.getPosition();}
2632 statement = Statement()
2633 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2634 } catch (ParseException e) {
2635 if (errorMessage != null) {
2638 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2640 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2641 errorEnd = SimpleCharStream.getPosition() + 1;
2646 elseIfs = new ElseIf[elseIfList.size()];
2647 elseIfList.toArray(elseIfs);
2648 return new IfStatement(condition,
2653 SimpleCharStream.getPosition());}
2656 ElseIf ElseIfStatementColon() :
2658 final Expression condition;
2659 Statement statement;
2660 final ArrayList list = new ArrayList();
2661 final int pos = SimpleCharStream.getPosition();
2664 <ELSEIF> condition = Condition("elseif")
2665 <COLON> ( statement = Statement() {list.add(statement);}
2666 | statement = htmlBlock() {list.add(statement);})*
2668 final Statement[] stmtsArray = new Statement[list.size()];
2669 list.toArray(stmtsArray);
2670 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2673 Else ElseStatementColon() :
2675 Statement statement;
2676 final ArrayList list = new ArrayList();
2677 final int pos = SimpleCharStream.getPosition();
2680 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2681 | statement = htmlBlock() {list.add(statement);})*
2683 final Statement[] stmtsArray = new Statement[list.size()];
2684 list.toArray(stmtsArray);
2685 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2688 ElseIf ElseIfStatement() :
2690 final Expression condition;
2691 final Statement statement;
2692 final ArrayList list = new ArrayList();
2693 final int pos = SimpleCharStream.getPosition();
2696 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2698 final Statement[] stmtsArray = new Statement[list.size()];
2699 list.toArray(stmtsArray);
2700 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2703 WhileStatement WhileStatement() :
2705 final Expression condition;
2706 final Statement action;
2707 final int pos = SimpleCharStream.getPosition();
2711 condition = Condition("while")
2712 action = WhileStatement0(pos,pos + 5)
2713 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2716 Statement WhileStatement0(final int start, final int end) :
2718 Statement statement;
2719 final ArrayList stmts = new ArrayList();
2720 final int pos = SimpleCharStream.getPosition();
2723 <COLON> (statement = Statement() {stmts.add(statement);})*
2725 setMarker(fileToParse,
2726 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2730 "Line " + token.beginLine);
2731 } catch (CoreException e) {
2732 PHPeclipsePlugin.log(e);
2736 } catch (ParseException e) {
2737 errorMessage = "'endwhile' expected";
2739 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2740 errorEnd = SimpleCharStream.getPosition() + 1;
2746 final Statement[] stmtsArray = new Statement[stmts.size()];
2747 stmts.toArray(stmtsArray);
2748 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2749 } catch (ParseException e) {
2750 errorMessage = "';' expected after 'endwhile' keyword";
2752 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2753 errorEnd = SimpleCharStream.getPosition() + 1;
2757 statement = Statement()
2761 DoStatement DoStatement() :
2763 final Statement action;
2764 final Expression condition;
2765 final int pos = SimpleCharStream.getPosition();
2768 <DO> action = Statement() <WHILE> condition = Condition("while")
2771 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2772 } catch (ParseException e) {
2773 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2775 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2776 errorEnd = SimpleCharStream.getPosition() + 1;
2781 ForeachStatement ForeachStatement() :
2783 Statement statement;
2784 Expression expression;
2785 final int pos = SimpleCharStream.getPosition();
2786 ArrayVariableDeclaration variable;
2792 } catch (ParseException e) {
2793 errorMessage = "'(' expected after 'foreach' keyword";
2795 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2796 errorEnd = SimpleCharStream.getPosition() + 1;
2800 expression = Expression()
2801 } catch (ParseException e) {
2802 errorMessage = "variable expected";
2804 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2805 errorEnd = SimpleCharStream.getPosition() + 1;
2810 } catch (ParseException e) {
2811 errorMessage = "'as' expected";
2813 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2814 errorEnd = SimpleCharStream.getPosition() + 1;
2818 variable = ArrayVariable()
2819 } catch (ParseException e) {
2820 errorMessage = "variable expected";
2822 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2823 errorEnd = SimpleCharStream.getPosition() + 1;
2828 } catch (ParseException e) {
2829 errorMessage = "')' expected after 'foreach' keyword";
2831 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2832 errorEnd = SimpleCharStream.getPosition() + 1;
2836 statement = Statement()
2837 } catch (ParseException e) {
2838 if (errorMessage != null) throw e;
2839 errorMessage = "statement expected";
2841 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2842 errorEnd = SimpleCharStream.getPosition() + 1;
2845 {return new ForeachStatement(expression,
2849 SimpleCharStream.getPosition());}
2853 ForStatement ForStatement() :
2856 final int pos = SimpleCharStream.getPosition();
2857 Expression[] initializations = null;
2858 Expression condition = null;
2859 Expression[] increments = null;
2861 final ArrayList list = new ArrayList();
2862 final int startBlock, endBlock;
2868 } catch (ParseException e) {
2869 errorMessage = "'(' expected after 'for' keyword";
2871 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2872 errorEnd = SimpleCharStream.getPosition() + 1;
2875 [ initializations = ForInit() ] <SEMICOLON>
2876 [ condition = Expression() ] <SEMICOLON>
2877 [ increments = StatementExpressionList() ] <RPAREN>
2879 action = Statement()
2880 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2883 {startBlock = SimpleCharStream.getPosition();}
2884 (action = Statement() {list.add(action);})*
2887 setMarker(fileToParse,
2888 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2890 pos+token.image.length(),
2892 "Line " + token.beginLine);
2893 } catch (CoreException e) {
2894 PHPeclipsePlugin.log(e);
2897 {endBlock = SimpleCharStream.getPosition();}
2900 } catch (ParseException e) {
2901 errorMessage = "'endfor' expected";
2903 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2904 errorEnd = SimpleCharStream.getPosition() + 1;
2910 final Statement[] stmtsArray = new Statement[list.size()];
2911 list.toArray(stmtsArray);
2912 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2913 } catch (ParseException e) {
2914 errorMessage = "';' expected after 'endfor' keyword";
2916 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2917 errorEnd = SimpleCharStream.getPosition() + 1;
2923 Expression[] ForInit() :
2925 final Expression[] exprs;
2928 LOOKAHEAD(LocalVariableDeclaration())
2929 exprs = LocalVariableDeclaration()
2932 exprs = StatementExpressionList()
2936 Expression[] StatementExpressionList() :
2938 final ArrayList list = new ArrayList();
2939 final Expression expr;
2942 expr = StatementExpression() {list.add(expr);}
2943 (<COMMA> StatementExpression() {list.add(expr);})*
2945 final Expression[] exprsArray = new Expression[list.size()];
2946 list.toArray(exprsArray);
2950 Continue ContinueStatement() :
2952 Expression expr = null;
2953 final int pos = SimpleCharStream.getPosition();
2956 <CONTINUE> [ expr = Expression() ]
2959 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2960 } catch (ParseException e) {
2961 errorMessage = "';' expected after 'continue' statement";
2963 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2964 errorEnd = SimpleCharStream.getPosition() + 1;
2969 ReturnStatement ReturnStatement() :
2971 Expression expr = null;
2972 final int pos = SimpleCharStream.getPosition();
2975 <RETURN> [ expr = Expression() ]
2978 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2979 } catch (ParseException e) {
2980 errorMessage = "';' expected after 'return' statement";
2982 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2983 errorEnd = SimpleCharStream.getPosition() + 1;