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 junit.framework.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 = false;
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;
99 * Reinitialize the parser.
101 private static final void init() {
102 nodes = new AstNode[AstStackIncrement];
108 * Add an php node on the stack.
109 * @param node the node that will be added to the stack
111 private static final void pushOnAstNodes(final AstNode node) {
113 nodes[++nodePtr] = node;
114 } catch (IndexOutOfBoundsException e) {
115 final int oldStackLength = nodes.length;
116 final AstNode[] oldStack = nodes;
117 nodes = new AstNode[oldStackLength + AstStackIncrement];
118 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
119 nodePtr = oldStackLength;
120 nodes[nodePtr] = node;
124 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
125 phpDocument = new PHPDocument(parent,"_root".toCharArray());
126 currentSegment = phpDocument;
127 outlineInfo = new PHPOutlineInfo(parent, currentSegment);
128 final StringReader stream = new StringReader(s);
129 if (jj_input_stream == null) {
130 jj_input_stream = new SimpleCharStream(stream, 1, 1);
136 phpDocument.nodes = new AstNode[nodes.length];
137 System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
138 if (PHPeclipsePlugin.DEBUG) {
139 PHPeclipsePlugin.log(1,phpDocument.toString());
141 } catch (ParseException e) {
142 processParseException(e);
148 * This method will process the parse exception.
149 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
150 * @param e the ParseException
152 private static void processParseException(final ParseException e) {
155 Assert.assertTrue(false);
157 if (errorMessage == null) {
158 PHPeclipsePlugin.log(e);
159 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
160 errorStart = SimpleCharStream.getPosition();
161 errorEnd = errorStart + 1;
165 // if (PHPeclipsePlugin.DEBUG) PHPeclipsePlugin.log(e);
169 * Create marker for the parse error.
170 * @param e the ParseException
172 private static void setMarker(final ParseException e) {
174 if (errorStart == -1) {
175 setMarker(fileToParse,
177 SimpleCharStream.tokenBegin,
178 SimpleCharStream.tokenBegin + e.currentToken.image.length(),
180 "Line " + e.currentToken.beginLine);
182 setMarker(fileToParse,
187 "Line " + e.currentToken.beginLine);
191 } catch (CoreException e2) {
192 PHPeclipsePlugin.log(e2);
196 private static void scanLine(final String output,
199 final int brIndx) throws CoreException {
201 final StringBuffer lineNumberBuffer = new StringBuffer(10);
203 current = output.substring(indx, brIndx);
205 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
206 final int onLine = current.indexOf("on line <b>");
208 lineNumberBuffer.delete(0, lineNumberBuffer.length());
209 for (int i = onLine; i < current.length(); i++) {
210 ch = current.charAt(i);
211 if ('0' <= ch && '9' >= ch) {
212 lineNumberBuffer.append(ch);
216 final int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
218 final Hashtable attributes = new Hashtable();
220 current = current.replaceAll("\n", "");
221 current = current.replaceAll("<b>", "");
222 current = current.replaceAll("</b>", "");
223 MarkerUtilities.setMessage(attributes, current);
225 if (current.indexOf(PARSE_ERROR_STRING) != -1)
226 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
227 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
228 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
230 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
231 MarkerUtilities.setLineNumber(attributes, lineNumber);
232 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
237 public final void parse(final String s) {
238 final StringReader stream = new StringReader(s);
239 if (jj_input_stream == null) {
240 jj_input_stream = new SimpleCharStream(stream, 1, 1);
246 } catch (ParseException e) {
247 processParseException(e);
252 * Call the php parse command ( php -l -f <filename> )
253 * and create markers according to the external parser output
255 public static void phpExternalParse(final IFile file) {
256 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
257 final String filename = file.getLocation().toString();
259 final String[] arguments = { filename };
260 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
261 final String command = form.format(arguments);
263 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
266 // parse the buffer to find the errors and warnings
267 createMarkers(parserResult, file);
268 } catch (CoreException e) {
269 PHPeclipsePlugin.log(e);
274 * Put a new html block in the stack.
276 public static final void createNewHTMLCode() {
277 final int currentPosition = SimpleCharStream.getPosition();
278 if (currentPosition == htmlStart || currentPosition > SimpleCharStream.currentBuffer.length()) {
281 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
282 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
285 /** Create a new task. */
286 public static final void createNewTask() {
287 final int currentPosition = SimpleCharStream.getPosition();
288 final String todo = SimpleCharStream.currentBuffer.substring(currentPosition-3,
289 SimpleCharStream.currentBuffer.indexOf("\n",
291 PHPeclipsePlugin.log(1,SimpleCharStream.currentBuffer.toString());
293 setMarker(fileToParse,
295 SimpleCharStream.getBeginLine(),
297 "Line "+SimpleCharStream.getBeginLine());
298 } catch (CoreException e) {
299 PHPeclipsePlugin.log(e);
303 private static final void parse() throws ParseException {
308 PARSER_END(PHPParser)
312 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
313 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
314 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
319 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
322 /* Skip any character if we are not in php mode */
340 <PHPPARSING> SPECIAL_TOKEN :
342 "//" : IN_SINGLE_LINE_COMMENT
343 | "#" : IN_SINGLE_LINE_COMMENT
344 | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
345 | "/*" : IN_MULTI_LINE_COMMENT
348 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
350 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
354 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
356 "todo" {PHPParser.createNewTask();}
359 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
364 <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
369 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
379 | <FUNCTION : "function">
382 | <ELSEIF : "elseif">
389 /* LANGUAGE CONSTRUCT */
394 | <INCLUDE : "include">
395 | <REQUIRE : "require">
396 | <INCLUDE_ONCE : "include_once">
397 | <REQUIRE_ONCE : "require_once">
398 | <GLOBAL : "global">
399 | <DEFINE : "define">
400 | <STATIC : "static">
401 | <CLASSACCESS : "->">
402 | <STATICCLASSACCESS : "::">
403 | <ARRAYASSIGN : "=>">
406 /* RESERVED WORDS AND LITERALS */
412 | <CONTINUE : "continue">
413 | <_DEFAULT : "default">
415 | <EXTENDS : "extends">
420 | <RETURN : "return">
422 | <SWITCH : "switch">
427 | <ENDWHILE : "endwhile">
428 | <ENDSWITCH: "endswitch">
430 | <ENDFOR : "endfor">
431 | <FOREACH : "foreach">
439 | <OBJECT : "object">
441 | <BOOLEAN : "boolean">
443 | <DOUBLE : "double">
446 | <INTEGER : "integer">
466 | <MINUS_MINUS : "--">
476 | <RSIGNEDSHIFT : ">>">
477 | <RUNSIGNEDSHIFT : ">>>">
486 <DECIMAL_LITERAL> (["l","L"])?
487 | <HEX_LITERAL> (["l","L"])?
488 | <OCTAL_LITERAL> (["l","L"])?
491 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
493 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
495 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
497 <FLOATING_POINT_LITERAL:
498 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
499 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
500 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
501 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
504 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
506 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
507 | <STRING_1: "\"" ( ~["\"","\\"] | "\\" ~[] )* "\"">
508 | <STRING_2: "'" ( ~["'","\\"] | "\\" ~[] )* "'">
509 | <STRING_3: "`" ( ~["`","\\"] | "\\" ~[] )* "`">
516 <IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
519 ["a"-"z"] | ["A"-"Z"]
527 "_" | ["\u007f"-"\u00ff"]
552 | <EQUAL_EQUAL : "==">
557 | <BANGDOUBLEEQUAL : "!==">
558 | <TRIPLEEQUAL : "===">
565 | <PLUSASSIGN : "+=">
566 | <MINUSASSIGN : "-=">
567 | <STARASSIGN : "*=">
568 | <SLASHASSIGN : "/=">
574 | <TILDEEQUAL : "~=">
575 | <LSHIFTASSIGN : "<<=">
576 | <RSIGNEDSHIFTASSIGN : ">>=">
581 <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
589 {PHPParser.createNewHTMLCode();}
590 } catch (TokenMgrError e) {
591 PHPeclipsePlugin.log(e);
592 errorStart = SimpleCharStream.getPosition();
593 errorEnd = errorStart + 1;
594 errorMessage = e.getMessage();
596 throw generateParseException();
601 * A php block is a <?= expression [;]?>
602 * or <?php somephpcode ?>
603 * or <? somephpcode ?>
607 final int start = SimpleCharStream.getPosition();
608 final PHPEchoBlock phpEchoBlock;
611 phpEchoBlock = phpEchoBlock()
612 {pushOnAstNodes(phpEchoBlock);}
617 setMarker(fileToParse,
618 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
620 SimpleCharStream.getPosition(),
622 "Line " + token.beginLine);
623 } catch (CoreException e) {
624 PHPeclipsePlugin.log(e);
630 } catch (ParseException e) {
631 errorMessage = "'?>' expected";
633 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
634 errorEnd = SimpleCharStream.getPosition() + 1;
635 processParseException(e);
639 PHPEchoBlock phpEchoBlock() :
641 final Expression expr;
642 final int pos = SimpleCharStream.getPosition();
643 final PHPEchoBlock echoBlock;
646 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
648 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
649 pushOnAstNodes(echoBlock);
659 ClassDeclaration ClassDeclaration() :
661 final ClassDeclaration classDeclaration;
662 final Token className,superclassName;
664 char[] classNameImage = SYNTAX_ERROR_CHAR;
665 char[] superclassNameImage = null;
669 {pos = SimpleCharStream.getPosition();}
671 className = <IDENTIFIER>
672 {classNameImage = className.image.toCharArray();}
673 } catch (ParseException e) {
674 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
676 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
677 errorEnd = SimpleCharStream.getPosition() + 1;
678 processParseException(e);
683 superclassName = <IDENTIFIER>
684 {superclassNameImage = superclassName.image.toCharArray();}
685 } catch (ParseException e) {
686 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
688 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
689 errorEnd = SimpleCharStream.getPosition() + 1;
690 processParseException(e);
691 superclassNameImage = SYNTAX_ERROR_CHAR;
695 if (superclassNameImage == null) {
696 classDeclaration = new ClassDeclaration(currentSegment,
701 classDeclaration = new ClassDeclaration(currentSegment,
707 currentSegment.add(classDeclaration);
708 currentSegment = classDeclaration;
710 ClassBody(classDeclaration)
711 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
712 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
713 pushOnAstNodes(classDeclaration);
714 return classDeclaration;}
717 void ClassBody(final ClassDeclaration classDeclaration) :
722 } catch (ParseException e) {
723 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "'. '{' expected";
725 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
726 errorEnd = SimpleCharStream.getPosition() + 1;
727 processParseException(e);
729 ( ClassBodyDeclaration(classDeclaration) )*
732 } catch (ParseException e) {
733 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. 'var', 'function' or '}' expected";
735 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
736 errorEnd = SimpleCharStream.getPosition() + 1;
737 processParseException(e);
742 * A class can contain only methods and fields.
744 void ClassBodyDeclaration(final ClassDeclaration classDeclaration) :
746 final MethodDeclaration method;
747 final FieldDeclaration field;
750 method = MethodDeclaration() {method.analyzeCode();
751 classDeclaration.addMethod(method);}
752 | field = FieldDeclaration() {classDeclaration.addField(field);}
756 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
757 * it is only used by ClassBodyDeclaration()
759 FieldDeclaration FieldDeclaration() :
761 VariableDeclaration variableDeclaration;
762 final VariableDeclaration[] list;
763 final ArrayList arrayList = new ArrayList();
764 final int pos = SimpleCharStream.getPosition();
767 <VAR> variableDeclaration = VariableDeclaratorNoSuffix()
768 {arrayList.add(variableDeclaration);
769 outlineInfo.addVariable(new String(variableDeclaration.name()));}
771 <COMMA> variableDeclaration = VariableDeclaratorNoSuffix()
772 {arrayList.add(variableDeclaration);
773 outlineInfo.addVariable(new String(variableDeclaration.name()));}
777 } catch (ParseException e) {
778 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
780 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
781 errorEnd = SimpleCharStream.getPosition() + 1;
782 processParseException(e);
785 {list = new VariableDeclaration[arrayList.size()];
786 arrayList.toArray(list);
787 return new FieldDeclaration(list,
789 SimpleCharStream.getPosition(),
794 * a strict variable declarator : there cannot be a suffix here.
795 * It will be used by fields and formal parameters
797 VariableDeclaration VariableDeclaratorNoSuffix() :
800 Expression initializer = null;
801 final int pos = SimpleCharStream.getPosition();
804 varName = <DOLLAR_ID>
808 initializer = VariableInitializer()
809 } catch (ParseException e) {
810 errorMessage = "Literal expression expected in variable initializer";
812 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
813 errorEnd = SimpleCharStream.getPosition() + 1;
814 processParseException(e);
818 if (initializer == null) {
819 return new VariableDeclaration(currentSegment,
820 new Variable(varName.image.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
822 SimpleCharStream.getPosition());
824 return new VariableDeclaration(currentSegment,
825 new Variable(varName.image.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.image.length()-1,SimpleCharStream.getPosition()),
827 VariableDeclaration.EQUAL,
833 * this will be used by static statement
835 VariableDeclaration VariableDeclarator() :
837 final String varName;
838 Expression initializer = null;
839 final int pos = SimpleCharStream.getPosition();
842 varName = VariableDeclaratorId()
846 initializer = VariableInitializer()
847 } catch (ParseException e) {
848 errorMessage = "Literal expression expected in variable initializer";
850 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
851 errorEnd = SimpleCharStream.getPosition() + 1;
852 processParseException(e);
856 if (initializer == null) {
857 return new VariableDeclaration(currentSegment,
858 new Variable(varName.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.length()-1,SimpleCharStream.getPosition()),
860 SimpleCharStream.getPosition());
862 return new VariableDeclaration(currentSegment,
863 new Variable(varName.substring(1).toCharArray(),SimpleCharStream.getPosition()-varName.length()-1,SimpleCharStream.getPosition()),
865 VariableDeclaration.EQUAL,
872 * @return the variable name (with suffix)
874 String VariableDeclaratorId() :
877 Expression expression = null;
878 final int pos = SimpleCharStream.getPosition();
879 ConstantIdentifier ex;
886 {ex = new ConstantIdentifier(var.toCharArray(),
888 SimpleCharStream.getPosition());}
889 expression = VariableSuffix(ex)
892 if (expression == null) {
895 return expression.toStringExpression();
897 } catch (ParseException e) {
898 errorMessage = "'$' expected for variable identifier";
900 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
901 errorEnd = SimpleCharStream.getPosition() + 1;
907 * Return a variablename without the $.
908 * @return a variable name
912 final StringBuffer buff;
913 Expression expression = null;
918 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
920 if (expression == null) {
921 return token.image.substring(1);
923 buff = new StringBuffer(token.image);
925 buff.append(expression.toStringExpression());
927 return buff.toString();
930 <DOLLAR> expr = VariableName()
935 * A Variable name (without the $)
936 * @return a variable name String
938 String VariableName():
940 final StringBuffer buff;
942 Expression expression = null;
946 <LBRACE> expression = Expression() <RBRACE>
947 {buff = new StringBuffer("{");
948 buff.append(expression.toStringExpression());
950 return buff.toString();}
952 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
954 if (expression == null) {
957 buff = new StringBuffer(token.image);
959 buff.append(expression.toStringExpression());
961 return buff.toString();
964 <DOLLAR> expr = VariableName()
966 buff = new StringBuffer("$");
968 return buff.toString();
971 token = <DOLLAR_ID> {return token.image;}
974 Expression VariableInitializer() :
976 final Expression expr;
978 final int pos = SimpleCharStream.getPosition();
984 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
985 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
987 SimpleCharStream.getPosition()),
991 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
992 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
994 SimpleCharStream.getPosition()),
998 expr = ArrayDeclarator()
1001 token = <IDENTIFIER>
1002 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
1005 ArrayVariableDeclaration ArrayVariable() :
1007 final Expression expr,expr2;
1012 <ARRAYASSIGN> expr2 = Expression()
1013 {return new ArrayVariableDeclaration(expr,expr2);}
1015 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
1018 ArrayVariableDeclaration[] ArrayInitializer() :
1020 ArrayVariableDeclaration expr;
1021 final ArrayList list = new ArrayList();
1026 expr = ArrayVariable()
1028 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
1033 <COMMA> {list.add(null);}
1037 final ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
1043 * A Method Declaration.
1044 * <b>function</b> MetodDeclarator() Block()
1046 MethodDeclaration MethodDeclaration() :
1048 final MethodDeclaration functionDeclaration;
1050 final OutlineableWithChildren seg = currentSegment;
1055 functionDeclaration = MethodDeclarator()
1056 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1057 } catch (ParseException e) {
1058 if (errorMessage != null) throw e;
1059 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1061 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1062 errorEnd = SimpleCharStream.getPosition() + 1;
1065 {currentSegment = functionDeclaration;}
1067 {functionDeclaration.statements = block.statements;
1068 currentSegment = seg;
1069 return functionDeclaration;}
1073 * A MethodDeclarator.
1074 * [&] IDENTIFIER(parameters ...).
1075 * @return a function description for the outline
1077 MethodDeclaration MethodDeclarator() :
1079 final Token identifier;
1080 Token reference = null;
1081 final Hashtable formalParameters;
1082 final int pos = SimpleCharStream.getPosition();
1083 char[] identifierChar = SYNTAX_ERROR_CHAR;
1086 [reference = <BIT_AND>]
1088 identifier = <IDENTIFIER>
1089 {identifierChar = identifier.image.toCharArray();}
1090 } catch (ParseException e) {
1091 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1093 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1094 errorEnd = SimpleCharStream.getPosition() + 1;
1095 processParseException(e);
1097 formalParameters = FormalParameters()
1098 {MethodDeclaration method = new MethodDeclaration(currentSegment,
1103 SimpleCharStream.getPosition());
1108 * FormalParameters follows method identifier.
1109 * (FormalParameter())
1111 Hashtable FormalParameters() :
1113 VariableDeclaration var;
1114 final Hashtable parameters = new Hashtable();
1119 } catch (ParseException e) {
1120 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1122 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1123 errorEnd = SimpleCharStream.getPosition() + 1;
1124 processParseException(e);
1127 var = FormalParameter()
1128 {parameters.put(new String(var.name()),var);}
1130 <COMMA> var = FormalParameter()
1131 {parameters.put(new String(var.name()),var);}
1136 } catch (ParseException e) {
1137 errorMessage = "')' expected";
1139 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1140 errorEnd = SimpleCharStream.getPosition() + 1;
1141 processParseException(e);
1143 {return parameters;}
1147 * A formal parameter.
1148 * $varname[=value] (,$varname[=value])
1150 VariableDeclaration FormalParameter() :
1152 final VariableDeclaration variableDeclaration;
1156 [token = <BIT_AND>] variableDeclaration = VariableDeclaratorNoSuffix()
1158 if (token != null) {
1159 variableDeclaration.setReference(true);
1161 return variableDeclaration;}
1164 ConstantIdentifier Type() :
1167 <STRING> {pos = SimpleCharStream.getPosition();
1168 return new ConstantIdentifier(Types.STRING,pos,pos-6);}
1169 | <BOOL> {pos = SimpleCharStream.getPosition();
1170 return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
1171 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1172 return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
1173 | <REAL> {pos = SimpleCharStream.getPosition();
1174 return new ConstantIdentifier(Types.REAL,pos,pos-4);}
1175 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1176 return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
1177 | <FLOAT> {pos = SimpleCharStream.getPosition();
1178 return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
1179 | <INT> {pos = SimpleCharStream.getPosition();
1180 return new ConstantIdentifier(Types.INT,pos,pos-3);}
1181 | <INTEGER> {pos = SimpleCharStream.getPosition();
1182 return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
1183 | <OBJECT> {pos = SimpleCharStream.getPosition();
1184 return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
1187 Expression Expression() :
1189 final Expression expr;
1190 Expression initializer = null;
1191 final int pos = SimpleCharStream.getPosition();
1192 int assignOperator = -1;
1196 expr = ConditionalExpression()
1198 assignOperator = AssignmentOperator()
1200 initializer = Expression()
1201 } catch (ParseException e) {
1202 if (errorMessage != null) {
1205 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1207 errorEnd = SimpleCharStream.getPosition();
1212 char[] varName = expr.toStringExpression().substring(1).toCharArray();
1213 if (assignOperator == -1) {
1214 return new VariableDeclaration(currentSegment,
1215 new Variable(varName,SimpleCharStream.getPosition()-varName.length-1,SimpleCharStream.getPosition()),
1217 SimpleCharStream.getPosition());
1220 return new VariableDeclaration(currentSegment,
1221 new Variable(varName,SimpleCharStream.getPosition()-varName.length-1,SimpleCharStream.getPosition()),
1227 | expr = ExpressionWBang() {return expr;}
1230 Expression ExpressionWBang() :
1232 final Expression expr;
1233 final int pos = SimpleCharStream.getPosition();
1236 <BANG> expr = ExpressionWBang() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1237 | expr = ExpressionNoBang() {return expr;}
1240 Expression ExpressionNoBang() :
1245 expr = PrintExpression() {return expr;}
1246 | expr = ListExpression() {return expr;}
1250 * Any assignement operator.
1251 * @return the assignement operator id
1253 int AssignmentOperator() :
1256 <ASSIGN> {return VariableDeclaration.EQUAL;}
1257 | <STARASSIGN> {return VariableDeclaration.STAR_EQUAL;}
1258 | <SLASHASSIGN> {return VariableDeclaration.SLASH_EQUAL;}
1259 | <REMASSIGN> {return VariableDeclaration.REM_EQUAL;}
1260 | <PLUSASSIGN> {return VariableDeclaration.PLUS_EQUAL;}
1261 | <MINUSASSIGN> {return VariableDeclaration.MINUS_EQUAL;}
1262 | <LSHIFTASSIGN> {return VariableDeclaration.LSHIFT_EQUAL;}
1263 | <RSIGNEDSHIFTASSIGN> {return VariableDeclaration.RSIGNEDSHIFT_EQUAL;}
1264 | <ANDASSIGN> {return VariableDeclaration.AND_EQUAL;}
1265 | <XORASSIGN> {return VariableDeclaration.XOR_EQUAL;}
1266 | <ORASSIGN> {return VariableDeclaration.OR_EQUAL;}
1267 | <DOTASSIGN> {return VariableDeclaration.DOT_EQUAL;}
1268 | <TILDEEQUAL> {return VariableDeclaration.TILDE_EQUAL;}
1271 Expression ConditionalExpression() :
1273 final Expression expr;
1274 Expression expr2 = null;
1275 Expression expr3 = null;
1278 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1280 if (expr3 == null) {
1283 return new ConditionalExpression(expr,expr2,expr3);
1287 Expression ConditionalOrExpression() :
1289 Expression expr,expr2;
1293 expr = ConditionalAndExpression()
1296 <OR_OR> {operator = OperatorIds.OR_OR;}
1297 | <_ORL> {operator = OperatorIds.ORL;}
1299 expr2 = ConditionalAndExpression()
1301 expr = new BinaryExpression(expr,expr2,operator);
1307 Expression ConditionalAndExpression() :
1309 Expression expr,expr2;
1313 expr = ConcatExpression()
1315 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1316 | <_ANDL> {operator = OperatorIds.ANDL;})
1317 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1322 Expression ConcatExpression() :
1324 Expression expr,expr2;
1327 expr = InclusiveOrExpression()
1329 <DOT> expr2 = InclusiveOrExpression()
1330 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1335 Expression InclusiveOrExpression() :
1337 Expression expr,expr2;
1340 expr = ExclusiveOrExpression()
1341 (<BIT_OR> expr2 = ExclusiveOrExpression()
1342 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1347 Expression ExclusiveOrExpression() :
1349 Expression expr,expr2;
1352 expr = AndExpression()
1354 <XOR> expr2 = AndExpression()
1355 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1360 Expression AndExpression() :
1362 Expression expr,expr2;
1365 expr = EqualityExpression()
1368 <BIT_AND> expr2 = EqualityExpression()
1369 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1374 Expression EqualityExpression() :
1376 Expression expr,expr2;
1380 expr = RelationalExpression()
1382 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1383 | <DIF> {operator = OperatorIds.DIF;}
1384 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1385 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1386 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1389 expr2 = RelationalExpression()
1390 } catch (ParseException e) {
1391 if (errorMessage != null) {
1394 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1396 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1397 errorEnd = SimpleCharStream.getPosition() + 1;
1401 expr = new BinaryExpression(expr,expr2,operator);
1407 Expression RelationalExpression() :
1409 Expression expr,expr2;
1413 expr = ShiftExpression()
1415 ( <LT> {operator = OperatorIds.LESS;}
1416 | <GT> {operator = OperatorIds.GREATER;}
1417 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1418 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1419 expr2 = ShiftExpression()
1420 {expr = new BinaryExpression(expr,expr2,operator);}
1425 Expression ShiftExpression() :
1427 Expression expr,expr2;
1431 expr = AdditiveExpression()
1433 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1434 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1435 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1436 expr2 = AdditiveExpression()
1437 {expr = new BinaryExpression(expr,expr2,operator);}
1442 Expression AdditiveExpression() :
1444 Expression expr,expr2;
1448 expr = MultiplicativeExpression()
1451 ( <PLUS> {operator = OperatorIds.PLUS;}
1452 | <MINUS> {operator = OperatorIds.MINUS;} )
1453 expr2 = MultiplicativeExpression()
1454 {expr = new BinaryExpression(expr,expr2,operator);}
1459 Expression MultiplicativeExpression() :
1461 Expression expr,expr2;
1466 expr = UnaryExpression()
1467 } catch (ParseException e) {
1468 if (errorMessage != null) throw e;
1469 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1471 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1472 errorEnd = SimpleCharStream.getPosition() + 1;
1476 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1477 | <SLASH> {operator = OperatorIds.DIVIDE;}
1478 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1479 expr2 = UnaryExpression()
1480 {expr = new BinaryExpression(expr,expr2,operator);}
1486 * An unary expression starting with @, & or nothing
1488 Expression UnaryExpression() :
1490 final Expression expr;
1491 final int pos = SimpleCharStream.getPosition();
1494 <BIT_AND> expr = UnaryExpressionNoPrefix()
1495 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1497 expr = AtNotUnaryExpression() {return expr;}
1501 * An expression prefixed (or not) by one or more @ and !.
1502 * @return the expression
1504 Expression AtNotUnaryExpression() :
1506 final Expression expr;
1507 final int pos = SimpleCharStream.getPosition();
1511 expr = AtNotUnaryExpression()
1512 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1515 expr = AtNotUnaryExpression()
1516 {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1518 expr = UnaryExpressionNoPrefix()
1523 Expression UnaryExpressionNoPrefix() :
1525 final Expression expr;
1527 final int pos = SimpleCharStream.getPosition();
1531 <PLUS> {operator = OperatorIds.PLUS;}
1533 <MINUS> {operator = OperatorIds.MINUS;}
1535 expr = UnaryExpression()
1536 {return new PrefixedUnaryExpression(expr,operator,pos);}
1538 expr = PreIncDecExpression()
1541 expr = UnaryExpressionNotPlusMinus()
1545 expr = PrintExpression() {return expr;}*/
1549 Expression PreIncDecExpression() :
1551 final Expression expr;
1553 final int pos = SimpleCharStream.getPosition();
1557 <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1559 <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}
1561 expr = PrimaryExpression()
1562 {return new PrefixedUnaryExpression(expr,operator,pos);}
1565 Expression UnaryExpressionNotPlusMinus() :
1567 final Expression expr;
1568 final int pos = SimpleCharStream.getPosition();
1571 LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1572 expr = CastExpression() {return expr;}
1573 | expr = PostfixExpression() {return expr;}
1574 | expr = Literal() {return expr;}
1575 | <LPAREN> expr = Expression()
1578 } catch (ParseException e) {
1579 errorMessage = "')' expected";
1581 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1582 errorEnd = SimpleCharStream.getPosition() + 1;
1588 CastExpression CastExpression() :
1590 final ConstantIdentifier type;
1591 final Expression expr;
1592 final int pos = SimpleCharStream.getPosition();
1599 <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());}
1601 <RPAREN> expr = UnaryExpression()
1602 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1605 Expression PostfixExpression() :
1607 final Expression expr;
1609 final int pos = SimpleCharStream.getPosition();
1612 expr = PrimaryExpression()
1614 <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1616 <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}
1619 if (operator == -1) {
1622 return new PostfixedUnaryExpression(expr,operator,pos);
1626 Expression PrimaryExpression() :
1629 int assignOperator = -1;
1630 final Token identifier;
1632 final int pos = SimpleCharStream.getPosition();
1635 expr = PrimaryPrefix()
1636 (expr = PrimarySuffix(expr))*
1637 [ expr = Arguments(expr) ]
1640 <NEW> expr = ClassIdentifier()
1641 {expr = new PrefixedUnaryExpression(expr,
1645 [ expr = Arguments(expr) ]
1648 expr = ArrayDeclarator()
1652 Expression PrimaryPrefix() :
1654 final Expression expr;
1657 final int pos = SimpleCharStream.getPosition();
1660 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1662 SimpleCharStream.getPosition());}
1664 var = VariableDeclaratorId() {return new Variable(var.toCharArray(),
1666 SimpleCharStream.getPosition());}
1669 AbstractSuffixExpression PrimarySuffix(final Expression prefix) :
1671 final AbstractSuffixExpression suffix;
1672 final Expression expr;
1675 suffix = VariableSuffix(prefix) {return suffix;}
1676 | <STATICCLASSACCESS> expr = ClassIdentifier()
1677 {suffix = new ClassAccess(prefix,
1679 ClassAccess.STATIC);
1684 * An array declarator.
1688 ArrayInitializer ArrayDeclarator() :
1690 final ArrayVariableDeclaration[] vars;
1691 final int pos = SimpleCharStream.getPosition();
1694 <ARRAY> vars = ArrayInitializer()
1695 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1698 PrefixedUnaryExpression classInstantiation() :
1701 final StringBuffer buff;
1702 final int pos = SimpleCharStream.getPosition();
1705 <NEW> expr = ClassIdentifier()
1707 {buff = new StringBuffer(expr.toStringExpression());}
1708 expr = PrimaryExpression()
1709 {buff.append(expr.toStringExpression());
1710 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1712 SimpleCharStream.getPosition());}
1714 {return new PrefixedUnaryExpression(expr,
1719 ConstantIdentifier ClassIdentifier():
1723 final int pos = SimpleCharStream.getPosition();
1724 final ConstantIdentifier type;
1727 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1729 SimpleCharStream.getPosition());}
1730 | type = Type() {return type;}
1731 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1733 SimpleCharStream.getPosition());}
1736 AbstractSuffixExpression VariableSuffix(final Expression prefix) :
1739 final int pos = SimpleCharStream.getPosition();
1740 Expression expression = null;
1745 expr = VariableName()
1746 } catch (ParseException e) {
1747 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1749 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1750 errorEnd = SimpleCharStream.getPosition() + 1;
1753 {return new ClassAccess(prefix,
1754 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1755 ClassAccess.NORMAL);}
1757 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1760 } catch (ParseException e) {
1761 errorMessage = "']' expected";
1763 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1764 errorEnd = SimpleCharStream.getPosition() + 1;
1767 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1776 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1777 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1778 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1779 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1780 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1781 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1782 | <TRUE> {pos = SimpleCharStream.getPosition();
1783 return new TrueLiteral(pos-4,pos);}
1784 | <FALSE> {pos = SimpleCharStream.getPosition();
1785 return new FalseLiteral(pos-4,pos);}
1786 | <NULL> {pos = SimpleCharStream.getPosition();
1787 return new NullLiteral(pos-4,pos);}
1790 FunctionCall Arguments(final Expression func) :
1792 Expression[] args = null;
1795 <LPAREN> [ args = ArgumentList() ]
1798 } catch (ParseException e) {
1799 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1801 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1802 errorEnd = SimpleCharStream.getPosition() + 1;
1805 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1809 * An argument list is a list of arguments separated by comma :
1810 * argumentDeclaration() (, argumentDeclaration)*
1811 * @return an array of arguments
1813 Expression[] ArgumentList() :
1816 final ArrayList list = new ArrayList();
1825 } catch (ParseException e) {
1826 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1828 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1829 errorEnd = SimpleCharStream.getPosition() + 1;
1834 final Expression[] arguments = new Expression[list.size()];
1835 list.toArray(arguments);
1840 * A Statement without break.
1841 * @return a statement
1843 Statement StatementNoBreak() :
1845 final Statement statement;
1850 statement = expressionStatement() {return statement;}
1852 statement = LabeledStatement() {return statement;}
1853 | statement = Block() {return statement;}
1854 | statement = EmptyStatement() {return statement;}
1855 | statement = SwitchStatement() {return statement;}
1856 | statement = IfStatement() {return statement;}
1857 | statement = WhileStatement() {return statement;}
1858 | statement = DoStatement() {return statement;}
1859 | statement = ForStatement() {return statement;}
1860 | statement = ForeachStatement() {return statement;}
1861 | statement = ContinueStatement() {return statement;}
1862 | statement = ReturnStatement() {return statement;}
1863 | statement = EchoStatement() {return statement;}
1864 | [token=<AT>] statement = IncludeStatement()
1865 {if (token != null) {
1866 ((InclusionStatement)statement).silent = true;
1869 | statement = StaticStatement() {return statement;}
1870 | statement = GlobalStatement() {return statement;}
1871 | statement = defineStatement() {currentSegment.add((Outlineable)statement);return statement;}
1875 * A statement expression.
1877 * @return an expression
1879 Statement expressionStatement() :
1881 final Statement statement;
1884 statement = Expression()
1887 } catch (ParseException e) {
1888 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1889 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1891 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1892 errorEnd = SimpleCharStream.getPosition() + 1;
1899 Define defineStatement() :
1901 final int start = SimpleCharStream.getPosition();
1902 Expression defineName,defineValue;
1908 } catch (ParseException e) {
1909 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1911 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1912 errorEnd = SimpleCharStream.getPosition() + 1;
1913 processParseException(e);
1916 defineName = Expression()
1917 } catch (ParseException e) {
1918 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1920 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1921 errorEnd = SimpleCharStream.getPosition() + 1;
1926 } catch (ParseException e) {
1927 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1929 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1930 errorEnd = SimpleCharStream.getPosition() + 1;
1931 processParseException(e);
1934 defineValue = Expression()
1935 } catch (ParseException e) {
1936 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1938 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1939 errorEnd = SimpleCharStream.getPosition() + 1;
1944 } catch (ParseException e) {
1945 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1947 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1948 errorEnd = SimpleCharStream.getPosition() + 1;
1949 processParseException(e);
1951 {return new Define(currentSegment,
1955 SimpleCharStream.getPosition());}
1959 * A Normal statement.
1961 Statement Statement() :
1963 final Statement statement;
1966 statement = StatementNoBreak() {return statement;}
1967 | statement = BreakStatement() {return statement;}
1971 * An html block inside a php syntax.
1973 HTMLBlock htmlBlock() :
1975 final int startIndex = nodePtr;
1976 final AstNode[] blockNodes;
1980 <PHPEND> (phpEchoBlock())*
1982 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1983 } catch (ParseException e) {
1984 errorMessage = "unexpected end of file , '<?php' expected";
1986 errorStart = SimpleCharStream.getPosition();
1987 errorEnd = SimpleCharStream.getPosition();
1991 nbNodes = nodePtr - startIndex;
1992 blockNodes = new AstNode[nbNodes];
1993 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1994 nodePtr = startIndex;
1995 return new HTMLBlock(blockNodes);}
1999 * An include statement. It's "include" an expression;
2001 InclusionStatement IncludeStatement() :
2003 final Expression expr;
2005 final int pos = SimpleCharStream.getPosition();
2006 final InclusionStatement inclusionStatement;
2009 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
2010 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
2011 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
2012 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
2015 } catch (ParseException e) {
2016 if (errorMessage != null) {
2019 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
2021 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2022 errorEnd = SimpleCharStream.getPosition() + 1;
2025 {inclusionStatement = new InclusionStatement(currentSegment,
2029 currentSegment.add(inclusionStatement);
2033 } catch (ParseException e) {
2034 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2036 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2037 errorEnd = SimpleCharStream.getPosition() + 1;
2040 {return inclusionStatement;}
2043 PrintExpression PrintExpression() :
2045 final Expression expr;
2046 final int pos = SimpleCharStream.getPosition();
2049 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
2052 ListExpression ListExpression() :
2055 final Expression expression;
2056 final ArrayList list = new ArrayList();
2057 final int pos = SimpleCharStream.getPosition();
2063 } catch (ParseException e) {
2064 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
2066 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2067 errorEnd = SimpleCharStream.getPosition() + 1;
2071 expr = VariableDeclaratorId()
2074 {if (expr == null) list.add(null);}
2078 } catch (ParseException e) {
2079 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
2081 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2082 errorEnd = SimpleCharStream.getPosition() + 1;
2085 [expr = VariableDeclaratorId() {list.add(expr);}]
2089 } catch (ParseException e) {
2090 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
2092 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2093 errorEnd = SimpleCharStream.getPosition() + 1;
2096 [ <ASSIGN> expression = Expression()
2098 final String[] strings = new String[list.size()];
2099 list.toArray(strings);
2100 return new ListExpression(strings,
2103 SimpleCharStream.getPosition());}
2106 final String[] strings = new String[list.size()];
2107 list.toArray(strings);
2108 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
2112 * An echo statement.
2113 * echo anyexpression (, otherexpression)*
2115 EchoStatement EchoStatement() :
2117 final ArrayList expressions = new ArrayList();
2119 final int pos = SimpleCharStream.getPosition();
2122 <ECHO> expr = Expression()
2123 {expressions.add(expr);}
2125 <COMMA> expr = Expression()
2126 {expressions.add(expr);}
2130 } catch (ParseException e) {
2131 if (e.currentToken.next.kind != 4) {
2132 errorMessage = "';' expected after 'echo' statement";
2134 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2135 errorEnd = SimpleCharStream.getPosition() + 1;
2139 {final Expression[] exprs = new Expression[expressions.size()];
2140 expressions.toArray(exprs);
2141 return new EchoStatement(exprs,pos);}
2144 GlobalStatement GlobalStatement() :
2146 final int pos = SimpleCharStream.getPosition();
2148 final ArrayList vars = new ArrayList();
2149 final GlobalStatement global;
2153 expr = VariableDeclaratorId()
2156 expr = VariableDeclaratorId()
2162 final String[] strings = new String[vars.size()];
2163 vars.toArray(strings);
2164 global = new GlobalStatement(currentSegment,
2167 SimpleCharStream.getPosition());
2168 currentSegment.add(global);
2170 } catch (ParseException e) {
2171 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2173 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2174 errorEnd = SimpleCharStream.getPosition() + 1;
2179 StaticStatement StaticStatement() :
2181 final int pos = SimpleCharStream.getPosition();
2182 final ArrayList vars = new ArrayList();
2183 VariableDeclaration expr;
2186 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name()));}
2187 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name()));})*
2191 final String[] strings = new String[vars.size()];
2192 vars.toArray(strings);
2193 return new StaticStatement(strings,
2195 SimpleCharStream.getPosition());}
2196 } catch (ParseException e) {
2197 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2199 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2200 errorEnd = SimpleCharStream.getPosition() + 1;
2205 LabeledStatement LabeledStatement() :
2207 final int pos = SimpleCharStream.getPosition();
2209 final Statement statement;
2212 label = <IDENTIFIER> <COLON> statement = Statement()
2213 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2225 final int pos = SimpleCharStream.getPosition();
2226 final ArrayList list = new ArrayList();
2227 Statement statement;
2232 } catch (ParseException e) {
2233 errorMessage = "'{' expected";
2235 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2236 errorEnd = SimpleCharStream.getPosition() + 1;
2239 ( statement = BlockStatement() {list.add(statement);}
2240 | statement = htmlBlock() {list.add(statement);})*
2243 } catch (ParseException e) {
2244 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2246 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2247 errorEnd = SimpleCharStream.getPosition() + 1;
2251 final Statement[] statements = new Statement[list.size()];
2252 list.toArray(statements);
2253 return new Block(statements,pos,SimpleCharStream.getPosition());}
2256 Statement BlockStatement() :
2258 final Statement statement;
2261 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2263 | statement = ClassDeclaration() {return statement;}
2264 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2265 currentSegment.add((MethodDeclaration) statement);
2266 ((MethodDeclaration) statement).analyzeCode();
2271 * A Block statement that will not contain any 'break'
2273 Statement BlockStatementNoBreak() :
2275 final Statement statement;
2278 statement = StatementNoBreak() {return statement;}
2279 | statement = ClassDeclaration() {return statement;}
2280 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2281 ((MethodDeclaration) statement).analyzeCode();
2286 * used only by ForInit()
2288 VariableDeclaration[] LocalVariableDeclaration() :
2290 final ArrayList list = new ArrayList();
2291 VariableDeclaration var;
2294 var = LocalVariableDeclarator()
2296 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2298 final VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2304 * used only by LocalVariableDeclaration().
2306 VariableDeclaration LocalVariableDeclarator() :
2308 final String varName;
2309 Expression initializer = null;
2310 final int pos = SimpleCharStream.getPosition();
2313 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2315 if (initializer == null) {
2316 return new VariableDeclaration(currentSegment,
2317 new Variable(varName.toCharArray(),SimpleCharStream.getPosition()-varName.length(),SimpleCharStream.getPosition()),
2319 SimpleCharStream.getPosition());
2321 return new VariableDeclaration(currentSegment,
2322 new Variable(varName.toCharArray(),SimpleCharStream.getPosition()-varName.length(),SimpleCharStream.getPosition()),
2324 VariableDeclaration.EQUAL,
2329 EmptyStatement EmptyStatement() :
2335 {pos = SimpleCharStream.getPosition();
2336 return new EmptyStatement(pos-1,pos);}
2340 * used only by StatementExpressionList() which is used only by ForInit() and ForStatement()
2342 Expression StatementExpression() :
2344 final Expression expr,expr2;
2348 expr = PreIncDecExpression() {return expr;}
2350 expr = PrimaryExpression()
2351 [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
2352 OperatorIds.PLUS_PLUS,
2353 SimpleCharStream.getPosition());}
2354 | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
2355 OperatorIds.MINUS_MINUS,
2356 SimpleCharStream.getPosition());}
2361 SwitchStatement SwitchStatement() :
2363 final Expression variable;
2364 final AbstractCase[] cases;
2365 final int pos = SimpleCharStream.getPosition();
2371 } catch (ParseException e) {
2372 errorMessage = "'(' expected after 'switch'";
2374 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2375 errorEnd = SimpleCharStream.getPosition() + 1;
2379 variable = Expression()
2380 } catch (ParseException e) {
2381 if (errorMessage != null) {
2384 errorMessage = "expression expected";
2386 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2387 errorEnd = SimpleCharStream.getPosition() + 1;
2392 } catch (ParseException e) {
2393 errorMessage = "')' expected";
2395 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2396 errorEnd = SimpleCharStream.getPosition() + 1;
2399 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2400 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2403 AbstractCase[] switchStatementBrace() :
2406 final ArrayList cases = new ArrayList();
2410 ( cas = switchLabel0() {cases.add(cas);})*
2414 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2415 cases.toArray(abcase);
2417 } catch (ParseException e) {
2418 errorMessage = "'}' expected";
2420 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2421 errorEnd = SimpleCharStream.getPosition() + 1;
2426 * A Switch statement with : ... endswitch;
2427 * @param start the begin offset of the switch
2428 * @param end the end offset of the switch
2430 AbstractCase[] switchStatementColon(final int start, final int end) :
2433 final ArrayList cases = new ArrayList();
2438 setMarker(fileToParse,
2439 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2443 "Line " + token.beginLine);
2444 } catch (CoreException e) {
2445 PHPeclipsePlugin.log(e);
2447 ( cas = switchLabel0() {cases.add(cas);})*
2450 } catch (ParseException e) {
2451 errorMessage = "'endswitch' expected";
2453 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2454 errorEnd = SimpleCharStream.getPosition() + 1;
2460 final AbstractCase[] abcase = new AbstractCase[cases.size()];
2461 cases.toArray(abcase);
2463 } catch (ParseException e) {
2464 errorMessage = "';' expected after 'endswitch' keyword";
2466 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2467 errorEnd = SimpleCharStream.getPosition() + 1;
2472 AbstractCase switchLabel0() :
2474 final Expression expr;
2475 Statement statement;
2476 final ArrayList stmts = new ArrayList();
2477 final int pos = SimpleCharStream.getPosition();
2480 expr = SwitchLabel()
2481 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2482 | statement = htmlBlock() {stmts.add(statement);})*
2483 [ statement = BreakStatement() {stmts.add(statement);}]
2485 final Statement[] stmtsArray = new Statement[stmts.size()];
2486 stmts.toArray(stmtsArray);
2487 if (expr == null) {//it's a default
2488 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2490 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2495 * case Expression() :
2497 * @return the if it was a case and null if not
2499 Expression SwitchLabel() :
2501 final Expression expr;
2507 } catch (ParseException e) {
2508 if (errorMessage != null) throw e;
2509 errorMessage = "expression expected after 'case' keyword";
2511 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2512 errorEnd = SimpleCharStream.getPosition() + 1;
2518 } catch (ParseException e) {
2519 errorMessage = "':' expected after case expression";
2521 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2522 errorEnd = SimpleCharStream.getPosition() + 1;
2530 } catch (ParseException e) {
2531 errorMessage = "':' expected after 'default' keyword";
2533 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2534 errorEnd = SimpleCharStream.getPosition() + 1;
2539 Break BreakStatement() :
2541 Expression expression = null;
2542 final int start = SimpleCharStream.getPosition();
2545 <BREAK> [ expression = Expression() ]
2548 } catch (ParseException e) {
2549 errorMessage = "';' expected after 'break' keyword";
2551 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2552 errorEnd = SimpleCharStream.getPosition() + 1;
2555 {return new Break(expression, start, SimpleCharStream.getPosition());}
2558 IfStatement IfStatement() :
2560 final int pos = SimpleCharStream.getPosition();
2561 final Expression condition;
2562 final IfStatement ifStatement;
2565 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2566 {return ifStatement;}
2570 Expression Condition(final String keyword) :
2572 final Expression condition;
2577 } catch (ParseException e) {
2578 errorMessage = "'(' expected after " + keyword + " keyword";
2580 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2581 errorEnd = errorStart +1;
2582 processParseException(e);
2584 condition = Expression()
2587 } catch (ParseException e) {
2588 errorMessage = "')' expected after " + keyword + " keyword";
2590 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2591 errorEnd = SimpleCharStream.getPosition() + 1;
2592 processParseException(e);
2597 IfStatement IfStatement0(final Expression condition, final int start,final int end) :
2599 Statement statement;
2600 final Statement stmt;
2601 final Statement[] statementsArray;
2602 ElseIf elseifStatement;
2603 Else elseStatement = null;
2604 final ArrayList stmts;
2605 final ArrayList elseIfList = new ArrayList();
2606 final ElseIf[] elseIfs;
2607 int pos = SimpleCharStream.getPosition();
2608 final int endStatements;
2612 {stmts = new ArrayList();}
2613 ( statement = Statement() {stmts.add(statement);}
2614 | statement = htmlBlock() {stmts.add(statement);})*
2615 {endStatements = SimpleCharStream.getPosition();}
2616 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2617 [elseStatement = ElseStatementColon()]
2620 setMarker(fileToParse,
2621 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2625 "Line " + token.beginLine);
2626 } catch (CoreException e) {
2627 PHPeclipsePlugin.log(e);
2631 } catch (ParseException e) {
2632 errorMessage = "'endif' expected";
2634 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2635 errorEnd = SimpleCharStream.getPosition() + 1;
2640 } catch (ParseException e) {
2641 errorMessage = "';' expected after 'endif' keyword";
2643 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2644 errorEnd = SimpleCharStream.getPosition() + 1;
2648 elseIfs = new ElseIf[elseIfList.size()];
2649 elseIfList.toArray(elseIfs);
2650 if (stmts.size() == 1) {
2651 return new IfStatement(condition,
2652 (Statement) stmts.get(0),
2656 SimpleCharStream.getPosition());
2658 statementsArray = new Statement[stmts.size()];
2659 stmts.toArray(statementsArray);
2660 return new IfStatement(condition,
2661 new Block(statementsArray,pos,endStatements),
2665 SimpleCharStream.getPosition());
2670 (stmt = Statement() | stmt = htmlBlock())
2671 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2675 {pos = SimpleCharStream.getPosition();}
2676 statement = Statement()
2677 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2678 } catch (ParseException e) {
2679 if (errorMessage != null) {
2682 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2684 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2685 errorEnd = SimpleCharStream.getPosition() + 1;
2690 elseIfs = new ElseIf[elseIfList.size()];
2691 elseIfList.toArray(elseIfs);
2692 return new IfStatement(condition,
2697 SimpleCharStream.getPosition());}
2700 ElseIf ElseIfStatementColon() :
2702 final Expression condition;
2703 Statement statement;
2704 final ArrayList list = new ArrayList();
2705 final int pos = SimpleCharStream.getPosition();
2708 <ELSEIF> condition = Condition("elseif")
2709 <COLON> ( statement = Statement() {list.add(statement);}
2710 | statement = htmlBlock() {list.add(statement);})*
2712 final Statement[] stmtsArray = new Statement[list.size()];
2713 list.toArray(stmtsArray);
2714 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2717 Else ElseStatementColon() :
2719 Statement statement;
2720 final ArrayList list = new ArrayList();
2721 final int pos = SimpleCharStream.getPosition();
2724 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2725 | statement = htmlBlock() {list.add(statement);})*
2727 final Statement[] stmtsArray = new Statement[list.size()];
2728 list.toArray(stmtsArray);
2729 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2732 ElseIf ElseIfStatement() :
2734 final Expression condition;
2735 final Statement statement;
2736 final ArrayList list = new ArrayList();
2737 final int pos = SimpleCharStream.getPosition();
2740 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2742 final Statement[] stmtsArray = new Statement[list.size()];
2743 list.toArray(stmtsArray);
2744 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2747 WhileStatement WhileStatement() :
2749 final Expression condition;
2750 final Statement action;
2751 final int pos = SimpleCharStream.getPosition();
2755 condition = Condition("while")
2756 action = WhileStatement0(pos,pos + 5)
2757 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2760 Statement WhileStatement0(final int start, final int end) :
2762 Statement statement;
2763 final ArrayList stmts = new ArrayList();
2764 final int pos = SimpleCharStream.getPosition();
2767 <COLON> (statement = Statement() {stmts.add(statement);})*
2769 setMarker(fileToParse,
2770 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2774 "Line " + token.beginLine);
2775 } catch (CoreException e) {
2776 PHPeclipsePlugin.log(e);
2780 } catch (ParseException e) {
2781 errorMessage = "'endwhile' expected";
2783 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2784 errorEnd = SimpleCharStream.getPosition() + 1;
2790 final Statement[] stmtsArray = new Statement[stmts.size()];
2791 stmts.toArray(stmtsArray);
2792 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2793 } catch (ParseException e) {
2794 errorMessage = "';' expected after 'endwhile' keyword";
2796 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2797 errorEnd = SimpleCharStream.getPosition() + 1;
2801 statement = Statement()
2805 DoStatement DoStatement() :
2807 final Statement action;
2808 final Expression condition;
2809 final int pos = SimpleCharStream.getPosition();
2812 <DO> action = Statement() <WHILE> condition = Condition("while")
2815 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2816 } catch (ParseException e) {
2817 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2819 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2820 errorEnd = SimpleCharStream.getPosition() + 1;
2825 ForeachStatement ForeachStatement() :
2827 Statement statement;
2828 Expression expression;
2829 final int pos = SimpleCharStream.getPosition();
2830 ArrayVariableDeclaration variable;
2836 } catch (ParseException e) {
2837 errorMessage = "'(' expected after 'foreach' keyword";
2839 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2840 errorEnd = SimpleCharStream.getPosition() + 1;
2844 expression = Expression()
2845 } catch (ParseException e) {
2846 errorMessage = "variable expected";
2848 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2849 errorEnd = SimpleCharStream.getPosition() + 1;
2854 } catch (ParseException e) {
2855 errorMessage = "'as' expected";
2857 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2858 errorEnd = SimpleCharStream.getPosition() + 1;
2862 variable = ArrayVariable()
2863 } catch (ParseException e) {
2864 errorMessage = "variable expected";
2866 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2867 errorEnd = SimpleCharStream.getPosition() + 1;
2872 } catch (ParseException e) {
2873 errorMessage = "')' expected after 'foreach' keyword";
2875 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2876 errorEnd = SimpleCharStream.getPosition() + 1;
2880 statement = Statement()
2881 } catch (ParseException e) {
2882 if (errorMessage != null) throw e;
2883 errorMessage = "statement expected";
2885 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2886 errorEnd = SimpleCharStream.getPosition() + 1;
2889 {return new ForeachStatement(expression,
2893 SimpleCharStream.getPosition());}
2897 ForStatement ForStatement() :
2900 final int pos = SimpleCharStream.getPosition();
2901 Expression[] initializations = null;
2902 Expression condition = null;
2903 Expression[] increments = null;
2905 final ArrayList list = new ArrayList();
2906 final int startBlock, endBlock;
2912 } catch (ParseException e) {
2913 errorMessage = "'(' expected after 'for' keyword";
2915 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2916 errorEnd = SimpleCharStream.getPosition() + 1;
2919 [ initializations = ForInit() ] <SEMICOLON>
2920 [ condition = Expression() ] <SEMICOLON>
2921 [ increments = StatementExpressionList() ] <RPAREN>
2923 action = Statement()
2924 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2927 {startBlock = SimpleCharStream.getPosition();}
2928 (action = Statement() {list.add(action);})*
2931 setMarker(fileToParse,
2932 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2934 pos+token.image.length(),
2936 "Line " + token.beginLine);
2937 } catch (CoreException e) {
2938 PHPeclipsePlugin.log(e);
2941 {endBlock = SimpleCharStream.getPosition();}
2944 } catch (ParseException e) {
2945 errorMessage = "'endfor' expected";
2947 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2948 errorEnd = SimpleCharStream.getPosition() + 1;
2954 final Statement[] stmtsArray = new Statement[list.size()];
2955 list.toArray(stmtsArray);
2956 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2957 } catch (ParseException e) {
2958 errorMessage = "';' expected after 'endfor' keyword";
2960 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2961 errorEnd = SimpleCharStream.getPosition() + 1;
2967 Expression[] ForInit() :
2969 final Expression[] exprs;
2972 LOOKAHEAD(LocalVariableDeclaration())
2973 exprs = LocalVariableDeclaration()
2976 exprs = StatementExpressionList()
2980 Expression[] StatementExpressionList() :
2982 final ArrayList list = new ArrayList();
2983 final Expression expr;
2986 expr = StatementExpression() {list.add(expr);}
2987 (<COMMA> StatementExpression() {list.add(expr);})*
2989 final Expression[] exprsArray = new Expression[list.size()];
2990 list.toArray(exprsArray);
2994 Continue ContinueStatement() :
2996 Expression expr = null;
2997 final int pos = SimpleCharStream.getPosition();
3000 <CONTINUE> [ expr = Expression() ]
3003 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
3004 } catch (ParseException e) {
3005 errorMessage = "';' expected after 'continue' statement";
3007 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
3008 errorEnd = SimpleCharStream.getPosition() + 1;
3013 ReturnStatement ReturnStatement() :
3015 Expression expr = null;
3016 final int pos = SimpleCharStream.getPosition();
3019 <RETURN> [ expr = Expression() ]
3022 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
3023 } catch (ParseException e) {
3024 errorMessage = "';' expected after 'return' statement";
3026 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
3027 errorEnd = SimpleCharStream.getPosition() + 1;