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;
43 import net.sourceforge.phpdt.internal.corext.Assert;
47 * This php parser is inspired by the Java 1.2 grammar example
48 * given with JavaCC. You can get JavaCC at http://www.webgain.com
49 * You can test the parser with the PHPParserTestCase2.java
50 * @author Matthieu Casanova
52 public final class PHPParser extends PHPParserSuperclass {
54 /** The current segment. */
55 private static OutlineableWithChildren currentSegment;
57 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
58 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
59 static PHPOutlineInfo outlineInfo;
61 /** The error level of the current ParseException. */
62 private static int errorLevel = ERROR;
63 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
64 private static String errorMessage;
66 private static int errorStart = -1;
67 private static int errorEnd = -1;
68 private static PHPDocument phpDocument;
70 private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
72 * The point where html starts.
73 * It will be used by the token manager to create HTMLCode objects
75 public static int htmlStart;
78 private final static int AstStackIncrement = 100;
79 /** The stack of node. */
80 private static AstNode[] nodes;
81 /** The cursor in expression stack. */
82 private static int nodePtr;
84 private static final boolean PARSER_DEBUG = true;
86 public final void setFileToParse(final IFile fileToParse) {
87 PHPParser.fileToParse = fileToParse;
93 public PHPParser(final IFile fileToParse) {
94 this(new StringReader(""));
95 PHPParser.fileToParse = fileToParse;
98 public static final void phpParserTester(final String strEval) throws ParseException {
99 final StringReader stream = new StringReader(strEval);
100 if (jj_input_stream == null) {
101 jj_input_stream = new SimpleCharStream(stream, 1, 1);
103 ReInit(new StringReader(strEval));
105 phpDocument = new PHPDocument(null,"_root".toCharArray());
106 currentSegment = phpDocument;
107 outlineInfo = new PHPOutlineInfo(null, currentSegment);
108 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
112 public static final void htmlParserTester(final File fileName) throws FileNotFoundException, ParseException {
113 final Reader stream = new FileReader(fileName);
114 if (jj_input_stream == null) {
115 jj_input_stream = new SimpleCharStream(stream, 1, 1);
119 phpDocument = new PHPDocument(null,"_root".toCharArray());
120 currentSegment = phpDocument;
121 outlineInfo = new PHPOutlineInfo(null, currentSegment);
125 public static final void htmlParserTester(final String strEval) throws ParseException {
126 final StringReader stream = new StringReader(strEval);
127 if (jj_input_stream == null) {
128 jj_input_stream = new SimpleCharStream(stream, 1, 1);
132 phpDocument = new PHPDocument(null,"_root".toCharArray());
133 currentSegment = phpDocument;
134 outlineInfo = new PHPOutlineInfo(null, currentSegment);
139 * Reinitialize the parser.
141 private static final void init() {
142 nodes = new AstNode[AstStackIncrement];
148 * Add an php node on the stack.
149 * @param node the node that will be added to the stack
151 private static final void pushOnAstNodes(final AstNode node) {
153 nodes[++nodePtr] = node;
154 } catch (IndexOutOfBoundsException e) {
155 final int oldStackLength = nodes.length;
156 final AstNode[] oldStack = nodes;
157 nodes = new AstNode[oldStackLength + AstStackIncrement];
158 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
159 nodePtr = oldStackLength;
160 nodes[nodePtr] = node;
164 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
165 phpDocument = new PHPDocument(parent,"_root".toCharArray());
166 currentSegment = phpDocument;
167 outlineInfo = new PHPOutlineInfo(parent, currentSegment);
168 final StringReader stream = new StringReader(s);
169 if (jj_input_stream == null) {
170 jj_input_stream = new SimpleCharStream(stream, 1, 1);
176 phpDocument.nodes = new AstNode[nodes.length];
177 System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
178 if (PHPeclipsePlugin.DEBUG) {
179 PHPeclipsePlugin.log(1,phpDocument.toString());
181 } catch (ParseException e) {
182 processParseException(e);
187 private static void processParseExceptionDebug(final ParseException e) throws ParseException {
191 processParseException(e);
194 * This method will process the parse exception.
195 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
196 * @param e the ParseException
198 private static void processParseException(final ParseException e) {
199 if (errorMessage == null) {
200 PHPeclipsePlugin.log(e);
201 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
202 errorStart = SimpleCharStream.getPosition();
203 errorEnd = errorStart + 1;
207 // if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e);
211 * Create marker for the parse error.
212 * @param e the ParseException
214 private static void setMarker(final ParseException e) {
216 if (errorStart == -1) {
217 setMarker(fileToParse,
219 SimpleCharStream.tokenBegin,
220 SimpleCharStream.tokenBegin + e.currentToken.image.length(),
222 "Line " + e.currentToken.beginLine);
224 setMarker(fileToParse,
229 "Line " + e.currentToken.beginLine);
233 } catch (CoreException e2) {
234 PHPeclipsePlugin.log(e2);
238 private static void scanLine(final String output,
241 final int brIndx) throws CoreException {
243 final StringBuffer lineNumberBuffer = new StringBuffer(10);
245 current = output.substring(indx, brIndx);
247 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
248 final int onLine = current.indexOf("on line <b>");
250 lineNumberBuffer.delete(0, lineNumberBuffer.length());
251 for (int i = onLine; i < current.length(); i++) {
252 ch = current.charAt(i);
253 if ('0' <= ch && '9' >= ch) {
254 lineNumberBuffer.append(ch);
258 final int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
260 final Hashtable attributes = new Hashtable();
262 current = current.replaceAll("\n", "");
263 current = current.replaceAll("<b>", "");
264 current = current.replaceAll("</b>", "");
265 MarkerUtilities.setMessage(attributes, current);
267 if (current.indexOf(PARSE_ERROR_STRING) != -1)
268 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
269 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
270 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
272 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
273 MarkerUtilities.setLineNumber(attributes, lineNumber);
274 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
279 public final void parse(final String s) {
280 final StringReader stream = new StringReader(s);
281 if (jj_input_stream == null) {
282 jj_input_stream = new SimpleCharStream(stream, 1, 1);
288 } catch (ParseException e) {
289 processParseException(e);
294 * Call the php parse command ( php -l -f <filename> )
295 * and create markers according to the external parser output
297 public static void phpExternalParse(final IFile file) {
298 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
299 final String filename = file.getLocation().toString();
301 final String[] arguments = { filename };
302 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
303 final String command = form.format(arguments);
305 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
308 // parse the buffer to find the errors and warnings
309 createMarkers(parserResult, file);
310 } catch (CoreException e) {
311 PHPeclipsePlugin.log(e);
316 * Put a new html block in the stack.
318 public static final void createNewHTMLCode() {
319 final int currentPosition = SimpleCharStream.getPosition();
320 if (currentPosition == htmlStart || currentPosition > SimpleCharStream.currentBuffer.length()) {
323 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
324 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
327 /** Create a new task. */
328 public static final void createNewTask() {
329 final int currentPosition = SimpleCharStream.getPosition();
330 final String todo = SimpleCharStream.currentBuffer.substring(currentPosition-3,
331 SimpleCharStream.currentBuffer.indexOf("\n",
333 PHPeclipsePlugin.log(1,SimpleCharStream.currentBuffer.toString());
335 setMarker(fileToParse,
337 SimpleCharStream.getBeginLine(),
339 "Line "+SimpleCharStream.getBeginLine());
340 } catch (CoreException e) {
341 PHPeclipsePlugin.log(e);
345 private static final void parse() throws ParseException {
350 PARSER_END(PHPParser)
354 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
355 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
356 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
361 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
364 /* Skip any character if we are not in php mode */
382 <PHPPARSING> SPECIAL_TOKEN :
384 "//" : IN_SINGLE_LINE_COMMENT
385 | "#" : IN_SINGLE_LINE_COMMENT
386 | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
387 | "/*" : IN_MULTI_LINE_COMMENT
390 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
392 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
396 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
398 "todo" {PHPParser.createNewTask();}
401 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
406 <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
411 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
421 | <FUNCTION : "function">
424 | <ELSEIF : "elseif">
431 /* LANGUAGE CONSTRUCT */
436 | <INCLUDE : "include">
437 | <REQUIRE : "require">
438 | <INCLUDE_ONCE : "include_once">
439 | <REQUIRE_ONCE : "require_once">
440 | <GLOBAL : "global">
441 | <DEFINE : "define">
442 | <STATIC : "static">
443 | <CLASSACCESS : "->">
444 | <STATICCLASSACCESS : "::">
445 | <ARRAYASSIGN : "=>">
448 /* RESERVED WORDS AND LITERALS */
454 | <CONTINUE : "continue">
455 | <_DEFAULT : "default">
457 | <EXTENDS : "extends">
462 | <RETURN : "return">
464 | <SWITCH : "switch">
469 | <ENDWHILE : "endwhile">
470 | <ENDSWITCH: "endswitch">
472 | <ENDFOR : "endfor">
473 | <FOREACH : "foreach">
481 | <OBJECT : "object">
483 | <BOOLEAN : "boolean">
485 | <DOUBLE : "double">
488 | <INTEGER : "integer">
508 | <MINUS_MINUS : "--">
518 | <RSIGNEDSHIFT : ">>">
519 | <RUNSIGNEDSHIFT : ">>>">
528 <DECIMAL_LITERAL> (["l","L"])?
529 | <HEX_LITERAL> (["l","L"])?
530 | <OCTAL_LITERAL> (["l","L"])?
533 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
535 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
537 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
539 <FLOATING_POINT_LITERAL:
540 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
541 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
542 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
543 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
546 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
548 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
549 | <STRING_1: "\"" ( ~["\"","\\"] | "\\" ~[] )* "\"">
550 | <STRING_2: "'" ( ~["'","\\"] | "\\" ~[] )* "'">
551 | <STRING_3: "`" ( ~["`","\\"] | "\\" ~[] )* "`">
558 <IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
561 ["a"-"z"] | ["A"-"Z"]
569 "_" | ["\u007f"-"\u00ff"]
594 | <EQUAL_EQUAL : "==">
599 | <BANGDOUBLEEQUAL : "!==">
600 | <TRIPLEEQUAL : "===">
607 | <PLUSASSIGN : "+=">
608 | <MINUSASSIGN : "-=">
609 | <STARASSIGN : "*=">
610 | <SLASHASSIGN : "/=">
616 | <TILDEEQUAL : "~=">
617 | <LSHIFTASSIGN : "<<=">
618 | <RSIGNEDSHIFTASSIGN : ">>=">
623 <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
638 {PHPParser.createNewHTMLCode();}
639 } catch (TokenMgrError e) {
640 PHPeclipsePlugin.log(e);
641 errorStart = SimpleCharStream.getPosition();
642 errorEnd = errorStart + 1;
643 errorMessage = e.getMessage();
645 throw generateParseException();
650 * A php block is a <?= expression [;]?>
651 * or <?php somephpcode ?>
652 * or <? somephpcode ?>
656 final int start = SimpleCharStream.getPosition();
657 final PHPEchoBlock phpEchoBlock;
660 phpEchoBlock = phpEchoBlock()
661 {pushOnAstNodes(phpEchoBlock);}
666 setMarker(fileToParse,
667 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
669 SimpleCharStream.getPosition(),
671 "Line " + token.beginLine);
672 } catch (CoreException e) {
673 PHPeclipsePlugin.log(e);
679 } catch (ParseException e) {
680 errorMessage = "'?>' expected";
682 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
683 errorEnd = SimpleCharStream.getPosition() + 1;
684 processParseExceptionDebug(e);
688 PHPEchoBlock phpEchoBlock() :
690 final Expression expr;
691 final int pos = SimpleCharStream.getPosition();
692 final PHPEchoBlock echoBlock;
695 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
697 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
698 pushOnAstNodes(echoBlock);
708 ClassDeclaration ClassDeclaration() :
710 final ClassDeclaration classDeclaration;
711 final Token className,superclassName;
713 char[] classNameImage = SYNTAX_ERROR_CHAR;
714 char[] superclassNameImage = null;
718 {pos = SimpleCharStream.getPosition();}
720 className = <IDENTIFIER>
721 {classNameImage = className.image.toCharArray();}
722 } catch (ParseException e) {
723 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
725 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
726 errorEnd = SimpleCharStream.getPosition() + 1;
727 processParseExceptionDebug(e);
732 superclassName = <IDENTIFIER>
733 {superclassNameImage = superclassName.image.toCharArray();}
734 } catch (ParseException e) {
735 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
737 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
738 errorEnd = SimpleCharStream.getPosition() + 1;
739 processParseExceptionDebug(e);
740 superclassNameImage = SYNTAX_ERROR_CHAR;
744 if (superclassNameImage == null) {
745 classDeclaration = new ClassDeclaration(currentSegment,
750 classDeclaration = new ClassDeclaration(currentSegment,
756 currentSegment.add(classDeclaration);
757 currentSegment = classDeclaration;
759 ClassBody(classDeclaration)
760 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
761 classDeclaration.setSourceEnd(SimpleCharStream.getPosition());
762 pushOnAstNodes(classDeclaration);
763 return classDeclaration;}
766 void ClassBody(final ClassDeclaration classDeclaration) :
771 } catch (ParseException e) {
772 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected";
774 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
775 errorEnd = SimpleCharStream.getPosition() + 1;
776 processParseExceptionDebug(e);
778 ( ClassBodyDeclaration(classDeclaration) )*
781 } catch (ParseException e) {
782 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected";
784 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
785 errorEnd = SimpleCharStream.getPosition() + 1;
786 processParseExceptionDebug(e);
791 * A class can contain only methods and fields.
793 void ClassBodyDeclaration(final ClassDeclaration classDeclaration) :
795 final MethodDeclaration method;
796 final FieldDeclaration field;
799 method = MethodDeclaration() {method.analyzeCode();
800 classDeclaration.addMethod(method);}
801 | field = FieldDeclaration() {classDeclaration.addField(field);}
805 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
806 * it is only used by ClassBodyDeclaration()
808 FieldDeclaration FieldDeclaration() :
810 VariableDeclaration variableDeclaration;
811 final VariableDeclaration[] list;
812 final ArrayList arrayList = new ArrayList();
813 final int pos = SimpleCharStream.getPosition();
816 <VAR> variableDeclaration = VariableDeclaratorNoSuffix()
817 {arrayList.add(variableDeclaration);
818 outlineInfo.addVariable(new String(variableDeclaration.name()));}
820 <COMMA> variableDeclaration = VariableDeclaratorNoSuffix()
821 {arrayList.add(variableDeclaration);
822 outlineInfo.addVariable(new String(variableDeclaration.name()));}
826 } catch (ParseException e) {
827 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
829 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
830 errorEnd = SimpleCharStream.getPosition() + 1;
831 processParseExceptionDebug(e);
834 {list = new VariableDeclaration[arrayList.size()];
835 arrayList.toArray(list);
836 return new FieldDeclaration(list,
838 SimpleCharStream.getPosition(),
843 * a strict variable declarator : there cannot be a suffix here.
844 * It will be used by fields and formal parameters
846 VariableDeclaration VariableDeclaratorNoSuffix() :
849 Expression initializer = null;
852 varName = <DOLLAR_ID>
853 {final int pos = SimpleCharStream.getPosition()-varName.image.length();}
857 initializer = VariableInitializer()
858 } catch (ParseException e) {
859 errorMessage = "Literal expression expected in variable initializer";
861 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
862 errorEnd = SimpleCharStream.getPosition() + 1;
863 processParseExceptionDebug(e);
867 if (initializer == null) {
868 return new VariableDeclaration(currentSegment,
869 new Variable(varName.image.substring(1),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
871 SimpleCharStream.getPosition());
873 return new VariableDeclaration(currentSegment,
874 new Variable(varName.image.substring(1),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
876 VariableDeclaration.EQUAL,
882 * this will be used by static statement
884 VariableDeclaration VariableDeclarator() :
886 final AbstractVariable variable;
887 Expression initializer = null;
888 final int pos = SimpleCharStream.getPosition();
891 variable = VariableDeclaratorId()
895 initializer = VariableInitializer()
896 } catch (ParseException e) {
897 errorMessage = "Literal expression expected in variable initializer";
899 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
900 errorEnd = SimpleCharStream.getPosition() + 1;
901 processParseExceptionDebug(e);
905 if (initializer == null) {
906 return new VariableDeclaration(currentSegment,
909 SimpleCharStream.getPosition());
911 return new VariableDeclaration(currentSegment,
914 VariableDeclaration.EQUAL,
921 * @return the variable name (with suffix)
923 AbstractVariable VariableDeclaratorId() :
926 AbstractVariable expression = null;
927 final int pos = SimpleCharStream.getPosition();
934 expression = VariableSuffix(var)
937 if (expression == null) {
942 } catch (ParseException e) {
943 errorMessage = "'$' expected for variable identifier";
945 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
946 errorEnd = SimpleCharStream.getPosition() + 1;
952 * Return a variablename without the $.
953 * @return a variable name
957 final StringBuffer buff;
958 Expression expression = null;
964 token = <DOLLAR_ID> {pos = SimpleCharStream.getPosition()-token.image.length();}
965 [<LBRACE> expression = Expression() <RBRACE>]
967 if (expression == null) {
968 return new Variable(token.image.substring(1),pos,SimpleCharStream.getPosition());
970 String s = expression.toStringExpression();
971 buff = new StringBuffer(token.image.length()+s.length()+2);
972 buff.append(token.image);
977 return new Variable(s,pos,SimpleCharStream.getPosition());
980 <DOLLAR> {pos = SimpleCharStream.getPosition()-1;}
981 expr = VariableName()
982 {return new Variable(expr,pos,SimpleCharStream.getPosition());}
986 * A Variable name (without the $)
987 * @return a variable name String
989 Variable VariableName():
991 final StringBuffer buff;
994 Expression expression = null;
1000 {pos = SimpleCharStream.getPosition()-1;}
1001 expression = Expression() <RBRACE>
1002 {expr = expression.toStringExpression();
1003 buff = new StringBuffer(expr.length()+2);
1007 pos = SimpleCharStream.getPosition();
1008 expr = buff.toString();
1009 return new Variable(expr,
1011 SimpleCharStream.getPosition());
1015 token = <IDENTIFIER>
1016 {pos = SimpleCharStream.getPosition() - token.image.length();}
1017 [<LBRACE> expression = Expression() <RBRACE>]
1019 if (expression == null) {
1020 return new Variable(token.image,
1022 SimpleCharStream.getPosition());
1024 expr = expression.toStringExpression();
1025 buff = new StringBuffer(token.image.length()+expr.length()+2);
1026 buff.append(token.image);
1030 expr = buff.toString();
1031 return new Variable(expr,
1033 SimpleCharStream.getPosition());
1036 <DOLLAR> {pos = SimpleCharStream.getPosition() - 1;}
1037 var = VariableName()
1039 return new Variable(var,
1041 SimpleCharStream.getPosition());
1046 pos = SimpleCharStream.getPosition();
1047 return new Variable(token.image,
1048 pos-token.image.length(),
1053 Expression VariableInitializer() :
1055 final Expression expr;
1057 final int pos = SimpleCharStream.getPosition();
1063 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
1064 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
1066 SimpleCharStream.getPosition()),
1070 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
1071 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
1073 SimpleCharStream.getPosition()),
1077 expr = ArrayDeclarator()
1080 token = <IDENTIFIER>
1081 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
1084 ArrayVariableDeclaration ArrayVariable() :
1086 final Expression expr,expr2;
1091 <ARRAYASSIGN> expr2 = Expression()
1092 {return new ArrayVariableDeclaration(expr,expr2);}
1094 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
1097 ArrayVariableDeclaration[] ArrayInitializer() :
1099 ArrayVariableDeclaration expr;
1100 final ArrayList list = new ArrayList();
1105 expr = ArrayVariable()
1107 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
1112 <COMMA> {list.add(null);}
1116 final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
1122 * A Method Declaration.
1123 * <b>function</b> MetodDeclarator() Block()
1125 MethodDeclaration MethodDeclaration() :
1127 final MethodDeclaration functionDeclaration;
1129 final OutlineableWithChildren seg = currentSegment;
1134 functionDeclaration = MethodDeclarator()
1135 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1136 } catch (ParseException e) {
1137 if (errorMessage != null) throw e;
1138 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1140 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1141 errorEnd = SimpleCharStream.getPosition() + 1;
1144 {currentSegment = functionDeclaration;}
1146 {functionDeclaration.statements = block.statements;
1147 currentSegment = seg;
1148 return functionDeclaration;}
1152 * A MethodDeclarator.
1153 * [&] IDENTIFIER(parameters ...).
1154 * @return a function description for the outline
1156 MethodDeclaration MethodDeclarator() :
1158 final Token identifier;
1159 Token reference = null;
1160 final Hashtable formalParameters;
1161 final int pos = SimpleCharStream.getPosition();
1162 char[] identifierChar = SYNTAX_ERROR_CHAR;
1165 [reference = <BIT_AND>]
1167 identifier = <IDENTIFIER>
1168 {identifierChar = identifier.image.toCharArray();}
1169 } catch (ParseException e) {
1170 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1172 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1173 errorEnd = SimpleCharStream.getPosition() + 1;
1174 processParseExceptionDebug(e);
1176 formalParameters = FormalParameters()
1177 {MethodDeclaration method = new MethodDeclaration(currentSegment,
1182 SimpleCharStream.getPosition());
1187 * FormalParameters follows method identifier.
1188 * (FormalParameter())
1190 Hashtable FormalParameters() :
1192 VariableDeclaration var;
1193 final Hashtable parameters = new Hashtable();
1198 } catch (ParseException e) {
1199 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1201 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1202 errorEnd = SimpleCharStream.getPosition() + 1;
1203 processParseExceptionDebug(e);
1206 var = FormalParameter()
1207 {parameters.put(new String(var.name()),var);}
1209 <COMMA> var = FormalParameter()
1210 {parameters.put(new String(var.name()),var);}
1215 } catch (ParseException e) {
1216 errorMessage = "')' expected";
1218 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1219 errorEnd = SimpleCharStream.getPosition() + 1;
1220 processParseExceptionDebug(e);
1222 {return parameters;}
1226 * A formal parameter.
1227 * $varname[=value] (,$varname[=value])
1229 VariableDeclaration FormalParameter() :
1231 final VariableDeclaration variableDeclaration;
1235 [token = <BIT_AND>] variableDeclaration = VariableDeclaratorNoSuffix()
1237 if (token != null) {
1238 variableDeclaration.setReference(true);
1240 return variableDeclaration;}
1243 ConstantIdentifier Type() :
1246 <STRING> {pos = SimpleCharStream.getPosition();
1247 return new ConstantIdentifier(Types.STRING,pos,pos-6);}
1248 | <BOOL> {pos = SimpleCharStream.getPosition();
1249 return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
1250 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1251 return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
1252 | <REAL> {pos = SimpleCharStream.getPosition();
1253 return new ConstantIdentifier(Types.REAL,pos,pos-4);}
1254 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1255 return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
1256 | <FLOAT> {pos = SimpleCharStream.getPosition();
1257 return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
1258 | <INT> {pos = SimpleCharStream.getPosition();
1259 return new ConstantIdentifier(Types.INT,pos,pos-3);}
1260 | <INTEGER> {pos = SimpleCharStream.getPosition();
1261 return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
1262 | <OBJECT> {pos = SimpleCharStream.getPosition();
1263 return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
1266 Expression Expression() :
1268 final Expression expr;
1269 Expression initializer = null;
1270 final int pos = SimpleCharStream.getPosition();
1271 int assignOperator = -1;
1275 expr = ConditionalExpression()
1277 assignOperator = AssignmentOperator()
1279 initializer = Expression()
1280 } catch (ParseException e) {
1281 if (errorMessage != null) {
1284 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1286 errorEnd = SimpleCharStream.getPosition();
1291 if (assignOperator != -1) {// todo : change this, very very bad :(
1292 if (expr instanceof AbstractVariable) {
1293 return new VariableDeclaration(currentSegment,
1294 (AbstractVariable) expr,
1296 SimpleCharStream.getPosition());
1298 String varName = expr.toStringExpression().substring(1);
1299 return new VariableDeclaration(currentSegment,
1300 new Variable(varName,SimpleCharStream.getPosition()-varName.length()-1,SimpleCharStream.getPosition()),
1302 SimpleCharStream.getPosition());
1306 | expr = ExpressionWBang() {return expr;}
1309 Expression ExpressionWBang() :
1311 final Expression expr;
1312 final int pos = SimpleCharStream.getPosition();
1315 <BANG> expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1316 | expr = ExpressionNoBang() {return expr;}
1319 Expression ExpressionNoBang() :
1324 expr = ListExpression() {return expr;}
1326 expr = PrintExpression() {return expr;}
1330 * Any assignement operator.
1331 * @return the assignement operator id
1333 int AssignmentOperator() :
1336 <ASSIGN> {return VariableDeclaration.EQUAL;}
1337 | <STARASSIGN> {return VariableDeclaration.STAR_EQUAL;}
1338 | <SLASHASSIGN> {return VariableDeclaration.SLASH_EQUAL;}
1339 | <REMASSIGN> {return VariableDeclaration.REM_EQUAL;}
1340 | <PLUSASSIGN> {return VariableDeclaration.PLUS_EQUAL;}
1341 | <MINUSASSIGN> {return VariableDeclaration.MINUS_EQUAL;}
1342 | <LSHIFTASSIGN> {return VariableDeclaration.LSHIFT_EQUAL;}
1343 | <RSIGNEDSHIFTASSIGN> {return VariableDeclaration.RSIGNEDSHIFT_EQUAL;}
1344 | <ANDASSIGN> {return VariableDeclaration.AND_EQUAL;}
1345 | <XORASSIGN> {return VariableDeclaration.XOR_EQUAL;}
1346 | <ORASSIGN> {return VariableDeclaration.OR_EQUAL;}
1347 | <DOTASSIGN> {return VariableDeclaration.DOT_EQUAL;}
1348 | <TILDEEQUAL> {return VariableDeclaration.TILDE_EQUAL;}
1351 Expression ConditionalExpression() :
1353 final Expression expr;
1354 Expression expr2 = null;
1355 Expression expr3 = null;
1358 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1360 if (expr3 == null) {
1363 return new ConditionalExpression(expr,expr2,expr3);
1367 Expression ConditionalOrExpression() :
1369 Expression expr,expr2;
1373 expr = ConditionalAndExpression()
1376 <OR_OR> {operator = OperatorIds.OR_OR;}
1377 | <_ORL> {operator = OperatorIds.ORL;}
1379 expr2 = ConditionalAndExpression()
1381 expr = new BinaryExpression(expr,expr2,operator);
1387 Expression ConditionalAndExpression() :
1389 Expression expr,expr2;
1393 expr = ConcatExpression()
1395 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1396 | <_ANDL> {operator = OperatorIds.ANDL;})
1397 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1402 Expression ConcatExpression() :
1404 Expression expr,expr2;
1407 expr = InclusiveOrExpression()
1409 <DOT> expr2 = InclusiveOrExpression()
1410 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1415 Expression InclusiveOrExpression() :
1417 Expression expr,expr2;
1420 expr = ExclusiveOrExpression()
1421 (<BIT_OR> expr2 = ExclusiveOrExpression()
1422 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1427 Expression ExclusiveOrExpression() :
1429 Expression expr,expr2;
1432 expr = AndExpression()
1434 <XOR> expr2 = AndExpression()
1435 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1440 Expression AndExpression() :
1442 Expression expr,expr2;
1445 expr = EqualityExpression()
1448 <BIT_AND> expr2 = EqualityExpression()
1449 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1454 Expression EqualityExpression() :
1456 Expression expr,expr2;
1460 expr = RelationalExpression()
1462 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1463 | <DIF> {operator = OperatorIds.DIF;}
1464 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1465 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1466 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1469 expr2 = RelationalExpression()
1470 } catch (ParseException e) {
1471 if (errorMessage != null) {
1474 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1476 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1477 errorEnd = SimpleCharStream.getPosition() + 1;
1481 expr = new BinaryExpression(expr,expr2,operator);
1487 Expression RelationalExpression() :
1489 Expression expr,expr2;
1493 expr = ShiftExpression()
1495 ( <LT> {operator = OperatorIds.LESS;}
1496 | <GT> {operator = OperatorIds.GREATER;}
1497 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1498 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1499 expr2 = ShiftExpression()
1500 {expr = new BinaryExpression(expr,expr2,operator);}
1505 Expression ShiftExpression() :
1507 Expression expr,expr2;
1511 expr = AdditiveExpression()
1513 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1514 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1515 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1516 expr2 = AdditiveExpression()
1517 {expr = new BinaryExpression(expr,expr2,operator);}
1522 Expression AdditiveExpression() :
1524 Expression expr,expr2;
1528 expr = MultiplicativeExpression()
1531 ( <PLUS> {operator = OperatorIds.PLUS;}
1532 | <MINUS> {operator = OperatorIds.MINUS;}
1534 expr2 = MultiplicativeExpression()
1535 {expr = new BinaryExpression(expr,expr2,operator);}
1540 Expression MultiplicativeExpression() :
1542 Expression expr,expr2;
1547 expr = UnaryExpression()
1548 } catch (ParseException e) {
1549 if (errorMessage != null) throw e;
1550 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1552 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1553 errorEnd = SimpleCharStream.getPosition() + 1;
1557 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1558 | <SLASH> {operator = OperatorIds.DIVIDE;}
1559 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1560 expr2 = UnaryExpression()
1561 {expr = new BinaryExpression(expr,expr2,operator);}
1567 * An unary expression starting with @, & or nothing
1569 Expression UnaryExpression() :
1571 final Expression expr;
1572 final int pos = SimpleCharStream.getPosition();
1575 /* <BIT_AND> expr = UnaryExpressionNoPrefix() //why did I had that ?
1576 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1578 expr = AtNotUnaryExpression() {return expr;}
1582 * An expression prefixed (or not) by one or more @ and !.
1583 * @return the expression
1585 Expression AtNotUnaryExpression() :
1587 final Expression expr;
1588 final int pos = SimpleCharStream.getPosition();
1592 expr = AtNotUnaryExpression()
1593 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1596 expr = AtNotUnaryExpression()
1597 {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1599 expr = UnaryExpressionNoPrefix()
1604 Expression UnaryExpressionNoPrefix() :
1606 final Expression expr;
1607 final int pos = SimpleCharStream.getPosition();
1610 <PLUS> expr = AtNotUnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.PLUS,pos);}
1612 <MINUS> expr = AtNotUnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.MINUS,pos);}
1614 expr = PreIncDecExpression()
1617 expr = UnaryExpressionNotPlusMinus()
1622 Expression PreIncDecExpression() :
1624 final Expression expr;
1626 final int pos = SimpleCharStream.getPosition();
1630 <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1632 <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}
1634 expr = PrimaryExpression()
1635 {return new PrefixedUnaryExpression(expr,operator,pos);}
1638 Expression UnaryExpressionNotPlusMinus() :
1640 final Expression expr;
1641 final int pos = SimpleCharStream.getPosition();
1644 LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1645 expr = CastExpression() {return expr;}
1646 | expr = PostfixExpression() {return expr;}
1647 | expr = Literal() {return expr;}
1648 | <LPAREN> expr = Expression()
1651 } catch (ParseException e) {
1652 errorMessage = "')' expected";
1654 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1655 errorEnd = SimpleCharStream.getPosition() + 1;
1661 CastExpression CastExpression() :
1663 final ConstantIdentifier type;
1664 final Expression expr;
1665 final int pos = SimpleCharStream.getPosition();
1672 <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());}
1674 <RPAREN> expr = UnaryExpression()
1675 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1678 Expression PostfixExpression() :
1680 final Expression expr;
1682 final int pos = SimpleCharStream.getPosition();
1685 expr = PrimaryExpression()
1687 <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1689 <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}
1692 if (operator == -1) {
1695 return new PostfixedUnaryExpression(expr,operator,pos);
1699 Expression PrimaryExpression() :
1701 Expression expr = null;
1703 int assignOperator = -1;
1704 final Token identifier;
1709 token = <IDENTIFIER>
1711 pos = SimpleCharStream.getPosition();
1712 expr = new ConstantIdentifier(token.image.toCharArray(),
1713 pos-token.image.length(),
1717 <STATICCLASSACCESS> expr2 = ClassIdentifier()
1718 {expr = new ClassAccess(expr,
1720 ClassAccess.STATIC);}
1722 [ expr = Arguments(expr) ]
1725 expr = VariableDeclaratorId()
1726 [ expr = Arguments(expr) ]
1730 {pos = SimpleCharStream.getPosition();}
1731 expr = ClassIdentifier()
1732 {expr = new PrefixedUnaryExpression(expr,
1736 [ expr = Arguments(expr) ]
1739 expr = ArrayDeclarator()
1744 * An array declarator.
1748 ArrayInitializer ArrayDeclarator() :
1750 final ArrayVariableDeclaration[] vars;
1751 final int pos = SimpleCharStream.getPosition();
1754 <ARRAY> vars = ArrayInitializer()
1755 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1758 PrefixedUnaryExpression classInstantiation() :
1761 final StringBuffer buff;
1762 final int pos = SimpleCharStream.getPosition();
1765 <NEW> expr = ClassIdentifier()
1767 {buff = new StringBuffer(expr.toStringExpression());}
1768 expr = PrimaryExpression()
1769 {buff.append(expr.toStringExpression());
1770 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1772 SimpleCharStream.getPosition());}
1774 {return new PrefixedUnaryExpression(expr,
1779 Expression ClassIdentifier():
1781 final Expression expr;
1783 final ConstantIdentifier type;
1786 token = <IDENTIFIER>
1787 {final int pos = SimpleCharStream.getPosition();
1788 return new ConstantIdentifier(token.image.toCharArray(),
1789 pos-token.image.length(),
1791 | expr = Type() {return expr;}
1792 | expr = VariableDeclaratorId() {return expr;}
1796 * Used by Variabledeclaratorid and primarysuffix
1798 AbstractVariable VariableSuffix(final AbstractVariable prefix) :
1800 Variable expr = null;
1801 final int pos = SimpleCharStream.getPosition();
1802 Expression expression = null;
1807 expr = VariableName()
1808 } catch (ParseException e) {
1809 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1811 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1812 errorEnd = SimpleCharStream.getPosition() + 1;
1815 {return new ClassAccess(prefix,
1817 ClassAccess.NORMAL);}
1819 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1822 } catch (ParseException e) {
1823 errorMessage = "']' expected";
1825 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1826 errorEnd = SimpleCharStream.getPosition() + 1;
1829 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1838 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1839 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1840 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1841 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1842 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1843 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1844 | <TRUE> {pos = SimpleCharStream.getPosition();
1845 return new TrueLiteral(pos-4,pos);}
1846 | <FALSE> {pos = SimpleCharStream.getPosition();
1847 return new FalseLiteral(pos-4,pos);}
1848 | <NULL> {pos = SimpleCharStream.getPosition();
1849 return new NullLiteral(pos-4,pos);}
1852 FunctionCall Arguments(final Expression func) :
1854 Expression[] args = null;
1857 <LPAREN> [ args = ArgumentList() ]
1860 } catch (ParseException e) {
1861 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1863 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1864 errorEnd = SimpleCharStream.getPosition() + 1;
1867 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1871 * An argument list is a list of arguments separated by comma :
1872 * argumentDeclaration() (, argumentDeclaration)*
1873 * @return an array of arguments
1875 Expression[] ArgumentList() :
1878 final ArrayList list = new ArrayList();
1887 } catch (ParseException e) {
1888 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1890 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1891 errorEnd = SimpleCharStream.getPosition() + 1;
1896 final Expression[] arguments = new Expression[list.size()];
1897 list.toArray(arguments);
1902 * A Statement without break.
1903 * @return a statement
1905 Statement StatementNoBreak() :
1907 final Statement statement;
1912 statement = expressionStatement() {return statement;}
1914 statement = LabeledStatement() {return statement;}
1915 | statement = Block() {return statement;}
1916 | statement = EmptyStatement() {return statement;}
1917 | statement = SwitchStatement() {return statement;}
1918 | statement = IfStatement() {return statement;}
1919 | statement = WhileStatement() {return statement;}
1920 | statement = DoStatement() {return statement;}
1921 | statement = ForStatement() {return statement;}
1922 | statement = ForeachStatement() {return statement;}
1923 | statement = ContinueStatement() {return statement;}
1924 | statement = ReturnStatement() {return statement;}
1925 | statement = EchoStatement() {return statement;}
1926 | [token=<AT>] statement = IncludeStatement()
1927 {if (token != null) {
1928 ((InclusionStatement)statement).silent = true;
1931 | statement = StaticStatement() {return statement;}
1932 | statement = GlobalStatement() {return statement;}
1933 | statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
1937 * A statement expression.
1939 * @return an expression
1941 Statement expressionStatement() :
1943 final Statement statement;
1946 statement = Expression()
1949 } catch (ParseException e) {
1950 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1951 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1953 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1954 errorEnd = SimpleCharStream.getPosition() + 1;
1961 Define defineStatement() :
1963 final int start = SimpleCharStream.getPosition();
1964 Expression defineName,defineValue;
1970 } catch (ParseException e) {
1971 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1973 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1974 errorEnd = SimpleCharStream.getPosition() + 1;
1975 processParseExceptionDebug(e);
1978 defineName = Expression()
1979 } catch (ParseException e) {
1980 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1982 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1983 errorEnd = SimpleCharStream.getPosition() + 1;
1988 } catch (ParseException e) {
1989 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1991 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1992 errorEnd = SimpleCharStream.getPosition() + 1;
1993 processParseExceptionDebug(e);
1996 defineValue = Expression()
1997 } catch (ParseException e) {
1998 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
2000 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2001 errorEnd = SimpleCharStream.getPosition() + 1;
2006 } catch (ParseException e) {
2007 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
2009 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2010 errorEnd = SimpleCharStream.getPosition() + 1;
2011 processParseExceptionDebug(e);
2013 {return new Define(currentSegment,
2017 SimpleCharStream.getPosition());}
2021 * A Normal statement.
2023 Statement Statement() :
2025 final Statement statement;
2028 statement = StatementNoBreak() {return statement;}
2029 | statement = BreakStatement() {return statement;}
2033 * An html block inside a php syntax.
2035 HTMLBlock htmlBlock() :
2037 final int startIndex = nodePtr;
2038 final AstNode[] blockNodes;
2042 <PHPEND> (phpEchoBlock())*
2044 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
2045 } catch (ParseException e) {
2046 errorMessage = "unexpected end of file , '<?php' expected";
2048 errorStart = SimpleCharStream.getPosition();
2049 errorEnd = SimpleCharStream.getPosition();
2053 nbNodes = nodePtr - startIndex;
2054 blockNodes = new AstNode[nbNodes];
2055 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
2056 nodePtr = startIndex;
2057 return new HTMLBlock(blockNodes);}
2061 * An include statement. It's "include" an expression;
2063 InclusionStatement IncludeStatement() :
2065 final Expression expr;
2067 final int pos = SimpleCharStream.getPosition();
2068 final InclusionStatement inclusionStatement;
2071 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
2072 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
2073 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
2074 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
2077 } catch (ParseException e) {
2078 if (errorMessage != null) {
2081 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
2083 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2084 errorEnd = SimpleCharStream.getPosition() + 1;
2087 {inclusionStatement = new InclusionStatement(currentSegment,
2091 currentSegment.add(inclusionStatement);
2095 } catch (ParseException e) {
2096 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2098 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2099 errorEnd = SimpleCharStream.getPosition() + 1;
2102 {return inclusionStatement;}
2105 PrintExpression PrintExpression() :
2107 final Expression expr;
2108 final int pos = SimpleCharStream.getPosition();
2111 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
2114 ListExpression ListExpression() :
2116 Expression expr = null;
2117 final Expression expression;
2118 final ArrayList list = new ArrayList();
2119 final int pos = SimpleCharStream.getPosition();
2125 } catch (ParseException e) {
2126 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
2128 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2129 errorEnd = SimpleCharStream.getPosition() + 1;
2133 expr = VariableDeclaratorId()
2136 {if (expr == null) list.add(null);}
2140 } catch (ParseException e) {
2141 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
2143 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2144 errorEnd = SimpleCharStream.getPosition() + 1;
2147 [expr = VariableDeclaratorId() {list.add(expr);}]
2151 } catch (ParseException e) {
2152 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
2154 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2155 errorEnd = SimpleCharStream.getPosition() + 1;
2158 [ <ASSIGN> expression = Expression()
2160 final Variable[] vars = new Variable[list.size()];
2162 return new ListExpression(vars,
2165 SimpleCharStream.getPosition());}
2168 final Variable[] vars = new Variable[list.size()];
2170 return new ListExpression(vars,pos,SimpleCharStream.getPosition());}
2174 * An echo statement.
2175 * echo anyexpression (, otherexpression)*
2177 EchoStatement EchoStatement() :
2179 final ArrayList expressions = new ArrayList();
2181 final int pos = SimpleCharStream.getPosition();
2184 <ECHO> expr = Expression()
2185 {expressions.add(expr);}
2187 <COMMA> expr = Expression()
2188 {expressions.add(expr);}
2192 } catch (ParseException e) {
2193 if (e.currentToken.next.kind != 4) {
2194 errorMessage = "';' expected after 'echo' statement";
2196 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2197 errorEnd = SimpleCharStream.getPosition() + 1;
2201 {final Expression[] exprs = new Expression[expressions.size()];
2202 expressions.toArray(exprs);
2203 return new EchoStatement(exprs,pos);}
2206 GlobalStatement GlobalStatement() :
2208 final int pos = SimpleCharStream.getPosition();
2210 final ArrayList vars = new ArrayList();
2211 final GlobalStatement global;
2224 final Variable[] variables = new Variable[vars.size()];
2225 vars.toArray(variables);
2226 global = new GlobalStatement(currentSegment,
2229 SimpleCharStream.getPosition());
2230 currentSegment.add(global);
2232 } catch (ParseException e) {
2233 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2235 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2236 errorEnd = SimpleCharStream.getPosition() + 1;
2241 StaticStatement StaticStatement() :
2243 final int pos = SimpleCharStream.getPosition();
2244 final ArrayList vars = new ArrayList();
2245 VariableDeclaration expr;
2248 <STATIC> expr = VariableDeclarator() {vars.add(expr);}
2250 <COMMA> expr = VariableDeclarator() {vars.add(expr);}
2255 final VariableDeclaration[] variables = new VariableDeclaration[vars.size()];
2256 vars.toArray(variables);
2257 return new StaticStatement(variables,
2259 SimpleCharStream.getPosition());}
2260 } catch (ParseException e) {
2261 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2263 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2264 errorEnd = SimpleCharStream.getPosition() + 1;
2269 LabeledStatement LabeledStatement() :
2271 final int pos = SimpleCharStream.getPosition();
2273 final Statement statement;
2276 label = <IDENTIFIER> <COLON> statement = Statement()
2277 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2289 final int pos = SimpleCharStream.getPosition();
2290 final ArrayList list = new ArrayList();
2291 Statement statement;
2296 } catch (ParseException e) {
2297 errorMessage = "'{' expected";
2299 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2300 errorEnd = SimpleCharStream.getPosition() + 1;
2303 ( statement = BlockStatement() {list.add(statement);}
2304 | statement = htmlBlock() {list.add(statement);})*
2307 } catch (ParseException e) {
2308 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2310 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2311 errorEnd = SimpleCharStream.getPosition() + 1;
2315 final Statement[] statements = new Statement[list.size()];
2316 list.toArray(statements);
2317 return new Block(statements,pos,SimpleCharStream.getPosition());}
2320 Statement BlockStatement() :
2322 final Statement statement;
2325 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2327 | statement = ClassDeclaration() {return statement;}
2328 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2329 currentSegment.add((MethodDeclaration) statement);
2330 ((MethodDeclaration) statement).analyzeCode();
2335 * A Block statement that will not contain any 'break'
2337 Statement BlockStatementNoBreak() :
2339 final Statement statement;
2342 statement = StatementNoBreak() {return statement;}
2343 | statement = ClassDeclaration() {return statement;}
2344 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2345 ((MethodDeclaration) statement).analyzeCode();
2350 * used only by ForInit()
2352 VariableDeclaration[] LocalVariableDeclaration() :
2354 final ArrayList list = new ArrayList();
2355 VariableDeclaration var;
2358 var = LocalVariableDeclarator()
2360 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2362 final VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2368 * used only by LocalVariableDeclaration().
2370 VariableDeclaration LocalVariableDeclarator() :
2372 final Variable varName;
2373 Expression initializer = null;
2374 final int pos = SimpleCharStream.getPosition();
2377 varName = Variable() [ <ASSIGN> initializer = Expression() ]
2379 if (initializer == null) {
2380 return new VariableDeclaration(currentSegment,
2383 SimpleCharStream.getPosition());
2385 return new VariableDeclaration(currentSegment,
2388 VariableDeclaration.EQUAL,
2393 EmptyStatement EmptyStatement() :
2399 {pos = SimpleCharStream.getPosition();
2400 return new EmptyStatement(pos-1,pos);}
2404 * used only by StatementExpressionList() which is used only by ForInit() and ForStatement()
2406 Expression StatementExpression() :
2408 final Expression expr,expr2;
2412 expr = PreIncDecExpression() {return expr;}
2414 expr = PrimaryExpression()
2415 [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
2416 OperatorIds.PLUS_PLUS,
2417 SimpleCharStream.getPosition());}
2418 | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
2419 OperatorIds.MINUS_MINUS,
2420 SimpleCharStream.getPosition());}
2425 SwitchStatement SwitchStatement() :
2427 final Expression variable;
2428 final AbstractCase[] cases;
2429 final int pos = SimpleCharStream.getPosition();
2435 } catch (ParseException e) {
2436 errorMessage = "'(' expected after 'switch'";
2438 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2439 errorEnd = SimpleCharStream.getPosition() + 1;
2443 variable = Expression()
2444 } catch (ParseException e) {
2445 if (errorMessage != null) {
2448 errorMessage = "expression expected";
2450 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2451 errorEnd = SimpleCharStream.getPosition() + 1;
2456 } catch (ParseException e) {
2457 errorMessage = "')' expected";
2459 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2460 errorEnd = SimpleCharStream.getPosition() + 1;
2463 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2464 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2467 AbstractCase[] switchStatementBrace() :
2470 final ArrayList cases = new ArrayList();
2474 ( cas = switchLabel0() {cases.add(cas);})*
2478 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2479 cases.toArray(abcase);
2481 } catch (ParseException e) {
2482 errorMessage = "'}' expected";
2484 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2485 errorEnd = SimpleCharStream.getPosition() + 1;
2490 * A Switch statement with : ... endswitch;
2491 * @param start the begin offset of the switch
2492 * @param end the end offset of the switch
2494 AbstractCase[] switchStatementColon(final int start, final int end) :
2497 final ArrayList cases = new ArrayList();
2502 setMarker(fileToParse,
2503 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2507 "Line " + token.beginLine);
2508 } catch (CoreException e) {
2509 PHPeclipsePlugin.log(e);
2511 ( cas = switchLabel0() {cases.add(cas);})*
2514 } catch (ParseException e) {
2515 errorMessage = "'endswitch' expected";
2517 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2518 errorEnd = SimpleCharStream.getPosition() + 1;
2524 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2525 cases.toArray(abcase);
2527 } catch (ParseException e) {
2528 errorMessage = "';' expected after 'endswitch' keyword";
2530 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2531 errorEnd = SimpleCharStream.getPosition() + 1;
2536 AbstractCase switchLabel0() :
2538 final Expression expr;
2539 Statement statement;
2540 final ArrayList stmts = new ArrayList();
2541 final int pos = SimpleCharStream.getPosition();
2544 expr = SwitchLabel()
2545 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2546 | statement = htmlBlock() {stmts.add(statement);})*
2547 [ statement = BreakStatement() {stmts.add(statement);}]
2549 final Statement[] stmtsArray = new Statement[stmts.size()];
2550 stmts.toArray(stmtsArray);
2551 if (expr == null) {//it's a default
2552 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2554 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2559 * case Expression() :
2561 * @return the if it was a case and null if not
2563 Expression SwitchLabel() :
2565 final Expression expr;
2571 } catch (ParseException e) {
2572 if (errorMessage != null) throw e;
2573 errorMessage = "expression expected after 'case' keyword";
2575 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2576 errorEnd = SimpleCharStream.getPosition() + 1;
2582 } catch (ParseException e) {
2583 errorMessage = "':' expected after case expression";
2585 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2586 errorEnd = SimpleCharStream.getPosition() + 1;
2594 } catch (ParseException e) {
2595 errorMessage = "':' expected after 'default' keyword";
2597 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2598 errorEnd = SimpleCharStream.getPosition() + 1;
2603 Break BreakStatement() :
2605 Expression expression = null;
2606 final int start = SimpleCharStream.getPosition();
2609 <BREAK> [ expression = Expression() ]
2612 } catch (ParseException e) {
2613 errorMessage = "';' expected after 'break' keyword";
2615 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2616 errorEnd = SimpleCharStream.getPosition() + 1;
2619 {return new Break(expression, start, SimpleCharStream.getPosition());}
2622 IfStatement IfStatement() :
2624 final int pos = SimpleCharStream.getPosition();
2625 final Expression condition;
2626 final IfStatement ifStatement;
2629 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2630 {return ifStatement;}
2634 Expression Condition(final String keyword) :
2636 final Expression condition;
2641 } catch (ParseException e) {
2642 errorMessage = "'(' expected after " + keyword + " keyword";
2644 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2645 errorEnd = errorStart +1;
2646 processParseExceptionDebug(e);
2648 condition = Expression()
2651 } catch (ParseException e) {
2652 errorMessage = "')' expected after " + keyword + " keyword";
2654 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2655 errorEnd = SimpleCharStream.getPosition() + 1;
2656 processParseExceptionDebug(e);
2661 IfStatement IfStatement0(final Expression condition, final int start,final int end) :
2663 Statement statement;
2664 final Statement stmt;
2665 final Statement[] statementsArray;
2666 ElseIf elseifStatement;
2667 Else elseStatement = null;
2668 final ArrayList stmts;
2669 final ArrayList elseIfList = new ArrayList();
2670 final ElseIf[] elseIfs;
2671 int pos = SimpleCharStream.getPosition();
2672 final int endStatements;
2676 {stmts = new ArrayList();}
2677 ( statement = Statement() {stmts.add(statement);}
2678 | statement = htmlBlock() {stmts.add(statement);})*
2679 {endStatements = SimpleCharStream.getPosition();}
2680 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2681 [elseStatement = ElseStatementColon()]
2684 setMarker(fileToParse,
2685 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2689 "Line " + token.beginLine);
2690 } catch (CoreException e) {
2691 PHPeclipsePlugin.log(e);
2695 } catch (ParseException e) {
2696 errorMessage = "'endif' expected";
2698 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2699 errorEnd = SimpleCharStream.getPosition() + 1;
2704 } catch (ParseException e) {
2705 errorMessage = "';' expected after 'endif' keyword";
2707 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2708 errorEnd = SimpleCharStream.getPosition() + 1;
2712 elseIfs = new ElseIf[elseIfList.size()];
2713 elseIfList.toArray(elseIfs);
2714 if (stmts.size() == 1) {
2715 return new IfStatement(condition,
2716 (Statement) stmts.get(0),
2720 SimpleCharStream.getPosition());
2722 statementsArray = new Statement[stmts.size()];
2723 stmts.toArray(statementsArray);
2724 return new IfStatement(condition,
2725 new Block(statementsArray,pos,endStatements),
2729 SimpleCharStream.getPosition());
2734 (stmt = Statement() | stmt = htmlBlock())
2735 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2739 {pos = SimpleCharStream.getPosition();}
2740 statement = Statement()
2741 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2742 } catch (ParseException e) {
2743 if (errorMessage != null) {
2746 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2748 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2749 errorEnd = SimpleCharStream.getPosition() + 1;
2754 elseIfs = new ElseIf[elseIfList.size()];
2755 elseIfList.toArray(elseIfs);
2756 return new IfStatement(condition,
2761 SimpleCharStream.getPosition());}
2764 ElseIf ElseIfStatementColon() :
2766 final Expression condition;
2767 Statement statement;
2768 final ArrayList list = new ArrayList();
2769 final int pos = SimpleCharStream.getPosition();
2772 <ELSEIF> condition = Condition("elseif")
2773 <COLON> ( statement = Statement() {list.add(statement);}
2774 | statement = htmlBlock() {list.add(statement);})*
2776 final Statement[] stmtsArray = new Statement[list.size()];
2777 list.toArray(stmtsArray);
2778 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2781 Else ElseStatementColon() :
2783 Statement statement;
2784 final ArrayList list = new ArrayList();
2785 final int pos = SimpleCharStream.getPosition();
2788 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2789 | statement = htmlBlock() {list.add(statement);})*
2791 final Statement[] stmtsArray = new Statement[list.size()];
2792 list.toArray(stmtsArray);
2793 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2796 ElseIf ElseIfStatement() :
2798 final Expression condition;
2799 final Statement statement;
2800 final ArrayList list = new ArrayList();
2801 final int pos = SimpleCharStream.getPosition();
2804 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2806 final Statement[] stmtsArray = new Statement[list.size()];
2807 list.toArray(stmtsArray);
2808 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2811 WhileStatement WhileStatement() :
2813 final Expression condition;
2814 final Statement action;
2815 final int pos = SimpleCharStream.getPosition();
2819 condition = Condition("while")
2820 action = WhileStatement0(pos,pos + 5)
2821 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2824 Statement WhileStatement0(final int start, final int end) :
2826 Statement statement;
2827 final ArrayList stmts = new ArrayList();
2828 final int pos = SimpleCharStream.getPosition();
2831 <COLON> (statement = Statement() {stmts.add(statement);})*
2833 setMarker(fileToParse,
2834 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2838 "Line " + token.beginLine);
2839 } catch (CoreException e) {
2840 PHPeclipsePlugin.log(e);
2844 } catch (ParseException e) {
2845 errorMessage = "'endwhile' expected";
2847 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2848 errorEnd = SimpleCharStream.getPosition() + 1;
2854 final Statement[] stmtsArray = new Statement[stmts.size()];
2855 stmts.toArray(stmtsArray);
2856 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2857 } catch (ParseException e) {
2858 errorMessage = "';' expected after 'endwhile' keyword";
2860 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2861 errorEnd = SimpleCharStream.getPosition() + 1;
2865 statement = Statement()
2869 DoStatement DoStatement() :
2871 final Statement action;
2872 final Expression condition;
2873 final int pos = SimpleCharStream.getPosition();
2876 <DO> action = Statement() <WHILE> condition = Condition("while")
2879 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2880 } catch (ParseException e) {
2881 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2883 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2884 errorEnd = SimpleCharStream.getPosition() + 1;
2889 ForeachStatement ForeachStatement() :
2891 Statement statement;
2892 Expression expression;
2893 final int pos = SimpleCharStream.getPosition();
2894 ArrayVariableDeclaration variable;
2900 } catch (ParseException e) {
2901 errorMessage = "'(' expected after 'foreach' keyword";
2903 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2904 errorEnd = SimpleCharStream.getPosition() + 1;
2908 expression = Expression()
2909 } catch (ParseException e) {
2910 errorMessage = "variable expected";
2912 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2913 errorEnd = SimpleCharStream.getPosition() + 1;
2918 } catch (ParseException e) {
2919 errorMessage = "'as' expected";
2921 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2922 errorEnd = SimpleCharStream.getPosition() + 1;
2926 variable = ArrayVariable()
2927 } catch (ParseException e) {
2928 errorMessage = "variable expected";
2930 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2931 errorEnd = SimpleCharStream.getPosition() + 1;
2936 } catch (ParseException e) {
2937 errorMessage = "')' expected after 'foreach' keyword";
2939 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2940 errorEnd = SimpleCharStream.getPosition() + 1;
2944 statement = Statement()
2945 } catch (ParseException e) {
2946 if (errorMessage != null) throw e;
2947 errorMessage = "statement expected";
2949 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2950 errorEnd = SimpleCharStream.getPosition() + 1;
2953 {return new ForeachStatement(expression,
2957 SimpleCharStream.getPosition());}
2961 ForStatement ForStatement() :
2964 final int pos = SimpleCharStream.getPosition();
2965 Expression[] initializations = null;
2966 Expression condition = null;
2967 Expression[] increments = null;
2969 final ArrayList list = new ArrayList();
2970 final int startBlock, endBlock;
2976 } catch (ParseException e) {
2977 errorMessage = "'(' expected after 'for' keyword";
2979 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2980 errorEnd = SimpleCharStream.getPosition() + 1;
2983 [ initializations = ForInit() ] <SEMICOLON>
2984 [ condition = Expression() ] <SEMICOLON>
2985 [ increments = StatementExpressionList() ] <RPAREN>
2987 action = Statement()
2988 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2991 {startBlock = SimpleCharStream.getPosition();}
2992 (action = Statement() {list.add(action);})*
2995 setMarker(fileToParse,
2996 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2998 pos+token.image.length(),
3000 "Line " + token.beginLine);
3001 } catch (CoreException e) {
3002 PHPeclipsePlugin.log(e);
3005 {endBlock = SimpleCharStream.getPosition();}
3008 } catch (ParseException e) {
3009 errorMessage = "'endfor' expected";
3011 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
3012 errorEnd = SimpleCharStream.getPosition() + 1;
3018 final Statement[] stmtsArray = new Statement[list.size()];
3019 list.toArray(stmtsArray);
3020 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
3021 } catch (ParseException e) {
3022 errorMessage = "';' expected after 'endfor' keyword";
3024 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
3025 errorEnd = SimpleCharStream.getPosition() + 1;
3031 Expression[] ForInit() :
3033 final Expression[] exprs;
3036 LOOKAHEAD(LocalVariableDeclaration())
3037 exprs = LocalVariableDeclaration()
3040 exprs = StatementExpressionList()
3044 Expression[] StatementExpressionList() :
3046 final ArrayList list = new ArrayList();
3047 final Expression expr;
3050 expr = StatementExpression() {list.add(expr);}
3051 (<COMMA> StatementExpression() {list.add(expr);})*
3053 final Expression[] exprsArray = new Expression[list.size()];
3054 list.toArray(exprsArray);
3058 Continue ContinueStatement() :
3060 Expression expr = null;
3061 final int pos = SimpleCharStream.getPosition();
3064 <CONTINUE> [ expr = Expression() ]
3067 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
3068 } catch (ParseException e) {
3069 errorMessage = "';' expected after 'continue' statement";
3071 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
3072 errorEnd = SimpleCharStream.getPosition() + 1;
3077 ReturnStatement ReturnStatement() :
3079 Expression expr = null;
3080 final int pos = SimpleCharStream.getPosition();
3083 <RETURN> [ expr = Expression() ]
3086 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
3087 } catch (ParseException e) {
3088 errorMessage = "';' expected after 'return' statement";
3090 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
3091 errorEnd = SimpleCharStream.getPosition() + 1;