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.Enumeration;
33 import java.util.ArrayList;
34 import java.io.StringReader;
36 import java.text.MessageFormat;
38 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
39 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
40 import net.sourceforge.phpdt.internal.compiler.ast.*;
41 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
46 * This php parser is inspired by the Java 1.2 grammar example
47 * given with JavaCC. You can get JavaCC at http://www.webgain.com
48 * You can test the parser with the PHPParserTestCase2.java
49 * @author Matthieu Casanova
51 public final class PHPParser extends PHPParserSuperclass {
53 /** The file that is parsed. */
54 private static IFile fileToParse;
56 /** The current segment. */
57 private static OutlineableWithChildren currentSegment;
59 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
60 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
61 static PHPOutlineInfo outlineInfo;
63 /** The error level of the current ParseException. */
64 private static int errorLevel = ERROR;
65 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
66 private static String errorMessage;
68 private static int errorStart = -1;
69 private static int errorEnd = -1;
70 private static PHPDocument phpDocument;
72 private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
74 * The point where html starts.
75 * It will be used by the token manager to create HTMLCode objects
77 public static int htmlStart;
80 private final static int AstStackIncrement = 100;
81 /** The stack of node. */
82 private static AstNode[] nodes;
83 /** The cursor in expression stack. */
84 private static int nodePtr;
86 public final void setFileToParse(final IFile fileToParse) {
87 this.fileToParse = fileToParse;
93 public PHPParser(final IFile fileToParse) {
94 this(new StringReader(""));
95 this.fileToParse = fileToParse;
99 * Reinitialize the parser.
101 private static final void init() {
102 nodes = new AstNode[AstStackIncrement];
108 * Add an php node on the stack.
109 * @param node the node that will be added to the stack
111 private static final void pushOnAstNodes(AstNode node) {
113 nodes[++nodePtr] = node;
114 } catch (IndexOutOfBoundsException e) {
115 int oldStackLength = nodes.length;
116 AstNode[] oldStack = nodes;
117 nodes = new AstNode[oldStackLength + AstStackIncrement];
118 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
119 nodePtr = oldStackLength;
120 nodes[nodePtr] = node;
124 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
125 phpDocument = new PHPDocument(parent,"_root".toCharArray());
126 currentSegment = phpDocument;
127 outlineInfo = new PHPOutlineInfo(parent, currentSegment);
128 final StringReader stream = new StringReader(s);
129 if (jj_input_stream == null) {
130 jj_input_stream = new SimpleCharStream(stream, 1, 1);
136 phpDocument.nodes = new AstNode[nodes.length];
137 System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
138 if (PHPeclipsePlugin.DEBUG) {
139 PHPeclipsePlugin.log(1,phpDocument.toString());
141 } catch (ParseException e) {
142 processParseException(e);
148 * This method will process the parse exception.
149 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
150 * @param e the ParseException
152 private static void processParseException(final ParseException e) {
153 if (errorMessage == null) {
154 PHPeclipsePlugin.log(e);
155 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
156 errorStart = SimpleCharStream.getPosition();
157 errorEnd = errorStart + 1;
164 * Create marker for the parse error
165 * @param e the ParseException
167 private static void setMarker(final ParseException e) {
169 if (errorStart == -1) {
170 setMarker(fileToParse,
172 SimpleCharStream.tokenBegin,
173 SimpleCharStream.tokenBegin + e.currentToken.image.length(),
175 "Line " + e.currentToken.beginLine);
177 setMarker(fileToParse,
182 "Line " + e.currentToken.beginLine);
186 } catch (CoreException e2) {
187 PHPeclipsePlugin.log(e2);
192 * Create markers according to the external parser output
194 private static void createMarkers(final String output, final IFile file) throws CoreException {
195 // delete all markers
196 file.deleteMarkers(IMarker.PROBLEM, false, 0);
201 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
202 // newer php error output (tested with 4.2.3)
203 scanLine(output, file, indx, brIndx);
208 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
209 // older php error output (tested with 4.2.3)
210 scanLine(output, file, indx, brIndx);
216 private static void scanLine(final String output,
219 final int brIndx) throws CoreException {
221 StringBuffer lineNumberBuffer = new StringBuffer(10);
223 current = output.substring(indx, brIndx);
225 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
226 int onLine = current.indexOf("on line <b>");
228 lineNumberBuffer.delete(0, lineNumberBuffer.length());
229 for (int i = onLine; i < current.length(); i++) {
230 ch = current.charAt(i);
231 if ('0' <= ch && '9' >= ch) {
232 lineNumberBuffer.append(ch);
236 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
238 Hashtable attributes = new Hashtable();
240 current = current.replaceAll("\n", "");
241 current = current.replaceAll("<b>", "");
242 current = current.replaceAll("</b>", "");
243 MarkerUtilities.setMessage(attributes, current);
245 if (current.indexOf(PARSE_ERROR_STRING) != -1)
246 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
247 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
248 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
250 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
251 MarkerUtilities.setLineNumber(attributes, lineNumber);
252 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
257 public final void parse(final String s) throws CoreException {
258 final StringReader stream = new StringReader(s);
259 if (jj_input_stream == null) {
260 jj_input_stream = new SimpleCharStream(stream, 1, 1);
266 } catch (ParseException e) {
267 processParseException(e);
272 * Call the php parse command ( php -l -f <filename> )
273 * and create markers according to the external parser output
275 public static void phpExternalParse(final IFile file) {
276 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
277 final String filename = file.getLocation().toString();
279 final String[] arguments = { filename };
280 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
281 final String command = form.format(arguments);
283 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
286 // parse the buffer to find the errors and warnings
287 createMarkers(parserResult, file);
288 } catch (CoreException e) {
289 PHPeclipsePlugin.log(e);
294 * Put a new html block in the stack.
296 public static final void createNewHTMLCode() {
297 final int currentPosition = SimpleCharStream.getPosition();
298 if (currentPosition == htmlStart) {
301 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
302 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
305 private static final void parse() throws ParseException {
310 PARSER_END(PHPParser)
314 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
315 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
316 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
321 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
324 /* Skip any character if we are not in php mode */
342 <PHPPARSING> SPECIAL_TOKEN :
344 "//" : IN_SINGLE_LINE_COMMENT
346 "#" : IN_SINGLE_LINE_COMMENT
348 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
350 "/*" : IN_MULTI_LINE_COMMENT
353 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
355 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
358 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
360 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
366 <FORMAL_COMMENT: "*/" > : PHPPARSING
369 <IN_MULTI_LINE_COMMENT>
372 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
375 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
385 | <FUNCTION : "function">
388 | <ELSEIF : "elseif">
395 /* LANGUAGE CONSTRUCT */
400 | <INCLUDE : "include">
401 | <REQUIRE : "require">
402 | <INCLUDE_ONCE : "include_once">
403 | <REQUIRE_ONCE : "require_once">
404 | <GLOBAL : "global">
405 | <STATIC : "static">
406 | <CLASSACCESS : "->">
407 | <STATICCLASSACCESS : "::">
408 | <ARRAYASSIGN : "=>">
411 /* RESERVED WORDS AND LITERALS */
417 | <CONTINUE : "continue">
418 | <_DEFAULT : "default">
420 | <EXTENDS : "extends">
425 | <RETURN : "return">
427 | <SWITCH : "switch">
432 | <ENDWHILE : "endwhile">
433 | <ENDSWITCH: "endswitch">
435 | <ENDFOR : "endfor">
436 | <FOREACH : "foreach">
444 | <OBJECT : "object">
446 | <BOOLEAN : "boolean">
448 | <DOUBLE : "double">
451 | <INTEGER : "integer">
481 | <RSIGNEDSHIFT : ">>">
482 | <RUNSIGNEDSHIFT : ">>>">
491 <DECIMAL_LITERAL> (["l","L"])?
492 | <HEX_LITERAL> (["l","L"])?
493 | <OCTAL_LITERAL> (["l","L"])?
496 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
498 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
500 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
502 <FLOATING_POINT_LITERAL:
503 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
504 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
505 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
506 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
509 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
511 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
544 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
547 ["a"-"z"] | ["A"-"Z"]
555 "_" | ["\u007f"-"\u00ff"]
580 | <EQUAL_EQUAL : "==">
585 | <BANGDOUBLEEQUAL : "!==">
586 | <TRIPLEEQUAL : "===">
593 | <PLUSASSIGN : "+=">
594 | <MINUSASSIGN : "-=">
595 | <STARASSIGN : "*=">
596 | <SLASHASSIGN : "/=">
602 | <TILDEEQUAL : "~=">
603 | <LSHIFTASSIGN : "<<=">
604 | <RSIGNEDSHIFTASSIGN : ">>=">
609 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
618 } catch (TokenMgrError e) {
619 PHPeclipsePlugin.log(e);
620 errorStart = SimpleCharStream.getPosition();
621 errorEnd = errorStart + 1;
622 errorMessage = e.getMessage();
624 throw generateParseException();
629 * A php block is a <?= expression [;]?>
630 * or <?php somephpcode ?>
631 * or <? somephpcode ?>
635 final int start = SimpleCharStream.getPosition();
636 final PHPEchoBlock phpEchoBlock;
639 phpEchoBlock = phpEchoBlock()
640 {pushOnAstNodes(phpEchoBlock);}
645 setMarker(fileToParse,
646 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
648 SimpleCharStream.getPosition(),
650 "Line " + token.beginLine);
651 } catch (CoreException e) {
652 PHPeclipsePlugin.log(e);
658 } catch (ParseException e) {
659 errorMessage = "'?>' expected";
661 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
662 errorEnd = SimpleCharStream.getPosition() + 1;
663 processParseException(e);
667 PHPEchoBlock phpEchoBlock() :
669 final Expression expr;
670 final int pos = SimpleCharStream.getPosition();
671 PHPEchoBlock echoBlock;
674 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
676 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
677 pushOnAstNodes(echoBlock);
687 ClassDeclaration ClassDeclaration() :
689 final ClassDeclaration classDeclaration;
690 final Token className;
691 Token superclassName = null;
693 char[] classNameImage = SYNTAX_ERROR_CHAR;
694 char[] superclassNameImage = null;
698 {pos = SimpleCharStream.getPosition();}
700 className = <IDENTIFIER>
701 {classNameImage = className.image.toCharArray();}
702 } catch (ParseException e) {
703 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
705 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
706 errorEnd = SimpleCharStream.getPosition() + 1;
707 processParseException(e);
712 superclassName = <IDENTIFIER>
713 {superclassNameImage = superclassName.image.toCharArray();}
714 } catch (ParseException e) {
715 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
717 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
718 errorEnd = SimpleCharStream.getPosition() + 1;
719 processParseException(e);
720 superclassNameImage = SYNTAX_ERROR_CHAR;
724 if (superclassNameImage == null) {
725 classDeclaration = new ClassDeclaration(currentSegment,
730 classDeclaration = new ClassDeclaration(currentSegment,
736 currentSegment.add(classDeclaration);
737 currentSegment = classDeclaration;
739 ClassBody(classDeclaration)
740 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
741 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
742 pushOnAstNodes(classDeclaration);
743 return classDeclaration;}
746 void ClassBody(ClassDeclaration classDeclaration) :
751 } catch (ParseException e) {
752 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
754 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
755 errorEnd = SimpleCharStream.getPosition() + 1;
758 ( ClassBodyDeclaration(classDeclaration) )*
761 } catch (ParseException e) {
762 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
764 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
765 errorEnd = SimpleCharStream.getPosition() + 1;
771 * A class can contain only methods and fields.
773 void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
775 MethodDeclaration method;
776 FieldDeclaration field;
779 method = MethodDeclaration() {method.setParent(classDeclaration);}
780 | field = FieldDeclaration()
784 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
786 FieldDeclaration FieldDeclaration() :
788 VariableDeclaration variableDeclaration;
789 VariableDeclaration[] list;
790 final ArrayList arrayList = new ArrayList();
791 final int pos = SimpleCharStream.getPosition();
794 <VAR> variableDeclaration = VariableDeclarator()
795 {arrayList.add(variableDeclaration);
796 outlineInfo.addVariable(new String(variableDeclaration.name));
797 currentSegment.add(variableDeclaration);}
798 ( <COMMA> variableDeclaration = VariableDeclarator()
799 {arrayList.add(variableDeclaration);
800 outlineInfo.addVariable(new String(variableDeclaration.name));
801 currentSegment.add(variableDeclaration);}
805 } catch (ParseException e) {
806 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
808 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
809 errorEnd = SimpleCharStream.getPosition() + 1;
810 processParseException(e);
813 {list = new VariableDeclaration[arrayList.size()];
814 arrayList.toArray(list);
815 return new FieldDeclaration(list,
817 SimpleCharStream.getPosition(),
821 VariableDeclaration VariableDeclarator() :
823 final String varName;
824 Expression initializer = null;
825 final int pos = SimpleCharStream.getPosition();
828 varName = VariableDeclaratorId()
832 initializer = VariableInitializer()
833 } catch (ParseException e) {
834 errorMessage = "Literal expression expected in variable initializer";
836 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
837 errorEnd = SimpleCharStream.getPosition() + 1;
842 if (initializer == null) {
843 return new VariableDeclaration(currentSegment,
844 varName.toCharArray(),
846 SimpleCharStream.getPosition());
848 return new VariableDeclaration(currentSegment,
849 varName.toCharArray(),
857 * @return the variable name (with suffix)
859 String VariableDeclaratorId() :
862 Expression expression;
863 final StringBuffer buff = new StringBuffer();
864 final int pos = SimpleCharStream.getPosition();
865 ConstantIdentifier ex;
869 expr = Variable() {buff.append(expr);}
871 {ex = new ConstantIdentifier(expr.toCharArray(),
873 SimpleCharStream.getPosition());}
874 expression = VariableSuffix(ex)
875 {buff.append(expression.toStringExpression());}
877 {return buff.toString();}
878 } catch (ParseException e) {
879 errorMessage = "'$' expected for variable identifier";
881 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
882 errorEnd = SimpleCharStream.getPosition() + 1;
889 final StringBuffer buff;
890 Expression expression = null;
895 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
897 if (expression == null) {
898 return token.image.substring(1);
900 buff = new StringBuffer(token.image);
902 buff.append(expression.toStringExpression());
904 return buff.toString();
907 <DOLLAR> expr = VariableName()
912 * A Variable name (without the $)
913 * @return a variable name String
915 String VariableName():
917 final StringBuffer buff;
919 Expression expression = null;
923 <LBRACE> expression = Expression() <RBRACE>
924 {buff = new StringBuffer("{");
925 buff.append(expression.toStringExpression());
927 return buff.toString();}
929 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
931 if (expression == null) {
934 buff = new StringBuffer(token.image);
936 buff.append(expression.toStringExpression());
938 return buff.toString();
941 <DOLLAR> expr = VariableName()
943 buff = new StringBuffer("$");
945 return buff.toString();
948 token = <DOLLAR_ID> {return token.image;}
951 Expression VariableInitializer() :
953 final Expression expr;
955 final int pos = SimpleCharStream.getPosition();
961 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
962 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
964 SimpleCharStream.getPosition()),
968 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
969 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
971 SimpleCharStream.getPosition()),
975 expr = ArrayDeclarator()
979 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
982 ArrayVariableDeclaration ArrayVariable() :
984 Expression expr,expr2;
988 [<ARRAYASSIGN> expr2 = Expression()
989 {return new ArrayVariableDeclaration(expr,expr2);}
991 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
994 ArrayVariableDeclaration[] ArrayInitializer() :
996 ArrayVariableDeclaration expr;
997 final ArrayList list = new ArrayList();
1000 <LPAREN> [ expr = ArrayVariable()
1002 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
1006 [<COMMA> {list.add(null);}]
1009 ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
1015 * A Method Declaration.
1016 * <b>function</b> MetodDeclarator() Block()
1018 MethodDeclaration MethodDeclaration() :
1020 final MethodDeclaration functionDeclaration;
1026 functionDeclaration = MethodDeclarator()
1027 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1028 } catch (ParseException e) {
1029 if (errorMessage != null) throw e;
1030 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1032 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1033 errorEnd = SimpleCharStream.getPosition() + 1;
1037 if (currentSegment != null) {
1038 currentSegment.add(functionDeclaration);
1039 currentSegment = functionDeclaration;
1044 functionDeclaration.statements = block.statements;
1045 if (currentSegment != null) {
1046 currentSegment = (OutlineableWithChildren) currentSegment.getParent();
1048 return functionDeclaration;
1053 * A MethodDeclarator.
1054 * [&] IDENTIFIER(parameters ...).
1055 * @return a function description for the outline
1057 MethodDeclaration MethodDeclarator() :
1059 final Token identifier;
1060 Token reference = null;
1061 final Hashtable formalParameters;
1062 final int pos = SimpleCharStream.getPosition();
1063 char[] identifierChar = SYNTAX_ERROR_CHAR;
1066 [reference = <BIT_AND>]
1068 identifier = <IDENTIFIER>
1069 {identifierChar = identifier.image.toCharArray();}
1070 } catch (ParseException e) {
1071 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1073 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1074 errorEnd = SimpleCharStream.getPosition() + 1;
1075 processParseException(e);
1077 formalParameters = FormalParameters()
1078 {return new MethodDeclaration(currentSegment,
1083 SimpleCharStream.getPosition());}
1087 * FormalParameters follows method identifier.
1088 * (FormalParameter())
1090 Hashtable FormalParameters() :
1092 VariableDeclaration var;
1093 final Hashtable parameters = new Hashtable();
1098 } catch (ParseException e) {
1099 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1101 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1102 errorEnd = SimpleCharStream.getPosition() + 1;
1105 [ var = FormalParameter()
1106 {parameters.put(new String(var.name),var);}
1108 <COMMA> var = FormalParameter()
1109 {parameters.put(new String(var.name),var);}
1114 } catch (ParseException e) {
1115 errorMessage = "')' expected";
1117 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1118 errorEnd = SimpleCharStream.getPosition() + 1;
1121 {return parameters;}
1125 * A formal parameter.
1126 * $varname[=value] (,$varname[=value])
1128 VariableDeclaration FormalParameter() :
1130 final VariableDeclaration variableDeclaration;
1134 [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
1136 if (token != null) {
1137 variableDeclaration.setReference(true);
1139 return variableDeclaration;}
1142 ConstantIdentifier Type() :
1145 <STRING> {pos = SimpleCharStream.getPosition();
1146 return new ConstantIdentifier(Types.STRING,pos,pos-6);}
1147 | <BOOL> {pos = SimpleCharStream.getPosition();
1148 return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
1149 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1150 return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
1151 | <REAL> {pos = SimpleCharStream.getPosition();
1152 return new ConstantIdentifier(Types.REAL,pos,pos-4);}
1153 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1154 return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
1155 | <FLOAT> {pos = SimpleCharStream.getPosition();
1156 return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
1157 | <INT> {pos = SimpleCharStream.getPosition();
1158 return new ConstantIdentifier(Types.INT,pos,pos-3);}
1159 | <INTEGER> {pos = SimpleCharStream.getPosition();
1160 return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
1161 | <OBJECT> {pos = SimpleCharStream.getPosition();
1162 return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
1165 Expression Expression() :
1167 final Expression expr;
1170 expr = PrintExpression() {return expr;}
1171 | expr = ListExpression() {return expr;}
1172 | LOOKAHEAD(varAssignation())
1173 expr = varAssignation() {return expr;}
1174 | expr = ConditionalExpression() {return expr;}
1178 * A Variable assignation.
1179 * varName (an assign operator) any expression
1181 VarAssignation varAssignation() :
1184 final Expression expression;
1185 final int assignOperator;
1186 final int pos = SimpleCharStream.getPosition();
1189 varName = VariableDeclaratorId()
1190 assignOperator = AssignmentOperator()
1192 expression = Expression()
1193 } catch (ParseException e) {
1194 if (errorMessage != null) {
1197 errorMessage = "expression expected";
1199 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1200 errorEnd = SimpleCharStream.getPosition() + 1;
1203 {return new VarAssignation(varName.toCharArray(),
1207 SimpleCharStream.getPosition());}
1210 int AssignmentOperator() :
1213 <ASSIGN> {return VarAssignation.EQUAL;}
1214 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1215 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1216 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1217 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1218 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1219 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1220 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1221 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1222 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1223 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1224 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1225 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1228 Expression ConditionalExpression() :
1230 final Expression expr;
1231 Expression expr2 = null;
1232 Expression expr3 = null;
1235 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1237 if (expr3 == null) {
1240 return new ConditionalExpression(expr,expr2,expr3);
1244 Expression ConditionalOrExpression() :
1246 Expression expr,expr2;
1250 expr = ConditionalAndExpression()
1253 <OR_OR> {operator = OperatorIds.OR_OR;}
1254 | <_ORL> {operator = OperatorIds.ORL;}
1255 ) expr2 = ConditionalAndExpression()
1257 expr = new BinaryExpression(expr,expr2,operator);
1263 Expression ConditionalAndExpression() :
1265 Expression expr,expr2;
1269 expr = ConcatExpression()
1271 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1272 | <_ANDL> {operator = OperatorIds.ANDL;})
1273 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1278 Expression ConcatExpression() :
1280 Expression expr,expr2;
1283 expr = InclusiveOrExpression()
1285 <DOT> expr2 = InclusiveOrExpression()
1286 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1291 Expression InclusiveOrExpression() :
1293 Expression expr,expr2;
1296 expr = ExclusiveOrExpression()
1297 (<BIT_OR> expr2 = ExclusiveOrExpression()
1298 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1303 Expression ExclusiveOrExpression() :
1305 Expression expr,expr2;
1308 expr = AndExpression()
1310 <XOR> expr2 = AndExpression()
1311 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1316 Expression AndExpression() :
1318 Expression expr,expr2;
1321 expr = EqualityExpression()
1323 <BIT_AND> expr2 = EqualityExpression()
1324 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1329 Expression EqualityExpression() :
1331 Expression expr,expr2;
1335 expr = RelationalExpression()
1337 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1338 | <DIF> {operator = OperatorIds.DIF;}
1339 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1340 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1341 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1344 expr2 = RelationalExpression()
1345 } catch (ParseException e) {
1346 if (errorMessage != null) {
1349 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1351 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1352 errorEnd = SimpleCharStream.getPosition() + 1;
1356 expr = new BinaryExpression(expr,expr2,operator);
1362 Expression RelationalExpression() :
1364 Expression expr,expr2;
1368 expr = ShiftExpression()
1370 ( <LT> {operator = OperatorIds.LESS;}
1371 | <GT> {operator = OperatorIds.GREATER;}
1372 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1373 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1374 expr2 = ShiftExpression()
1375 {expr = new BinaryExpression(expr,expr2,operator);}
1380 Expression ShiftExpression() :
1382 Expression expr,expr2;
1386 expr = AdditiveExpression()
1388 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1389 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1390 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1391 expr2 = AdditiveExpression()
1392 {expr = new BinaryExpression(expr,expr2,operator);}
1397 Expression AdditiveExpression() :
1399 Expression expr,expr2;
1403 expr = MultiplicativeExpression()
1405 ( <PLUS> {operator = OperatorIds.PLUS;}
1406 | <MINUS> {operator = OperatorIds.MINUS;} )
1407 expr2 = MultiplicativeExpression()
1408 {expr = new BinaryExpression(expr,expr2,operator);}
1413 Expression MultiplicativeExpression() :
1415 Expression expr,expr2;
1420 expr = UnaryExpression()
1421 } catch (ParseException e) {
1422 if (errorMessage != null) throw e;
1423 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1425 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1426 errorEnd = SimpleCharStream.getPosition() + 1;
1430 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1431 | <SLASH> {operator = OperatorIds.DIVIDE;}
1432 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1433 expr2 = UnaryExpression()
1434 {expr = new BinaryExpression(expr,expr2,operator);}
1440 * An unary expression starting with @, & or nothing
1442 Expression UnaryExpression() :
1445 final int pos = SimpleCharStream.getPosition();
1448 <BIT_AND> expr = UnaryExpressionNoPrefix()
1449 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1451 expr = AtUnaryExpression() {return expr;}
1454 Expression AtUnaryExpression() :
1457 final int pos = SimpleCharStream.getPosition();
1461 expr = AtUnaryExpression()
1462 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1464 expr = UnaryExpressionNoPrefix()
1469 Expression UnaryExpressionNoPrefix() :
1473 final int pos = SimpleCharStream.getPosition();
1476 ( <PLUS> {operator = OperatorIds.PLUS;}
1477 | <MINUS> {operator = OperatorIds.MINUS;})
1478 expr = UnaryExpression()
1479 {return new PrefixedUnaryExpression(expr,operator,pos);}
1481 expr = PreIncDecExpression()
1484 expr = UnaryExpressionNotPlusMinus()
1489 Expression PreIncDecExpression() :
1491 final Expression expr;
1493 final int pos = SimpleCharStream.getPosition();
1496 ( <INCR> {operator = OperatorIds.PLUS_PLUS;}
1497 | <DECR> {operator = OperatorIds.MINUS_MINUS;})
1498 expr = PrimaryExpression()
1499 {return new PrefixedUnaryExpression(expr,operator,pos);}
1502 Expression UnaryExpressionNotPlusMinus() :
1505 final int pos = SimpleCharStream.getPosition();
1508 <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1509 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1510 expr = CastExpression() {return expr;}
1511 | expr = PostfixExpression() {return expr;}
1512 | expr = Literal() {return expr;}
1513 | <LPAREN> expr = Expression()
1516 } catch (ParseException e) {
1517 errorMessage = "')' expected";
1519 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1520 errorEnd = SimpleCharStream.getPosition() + 1;
1526 CastExpression CastExpression() :
1528 final ConstantIdentifier type;
1529 final Expression expr;
1530 final int pos = SimpleCharStream.getPosition();
1535 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1536 <RPAREN> expr = UnaryExpression()
1537 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1540 Expression PostfixExpression() :
1544 final int pos = SimpleCharStream.getPosition();
1547 expr = PrimaryExpression()
1548 [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
1549 | <DECR> {operator = OperatorIds.MINUS_MINUS;}]
1551 if (operator == -1) {
1554 return new PostfixedUnaryExpression(expr,operator,pos);
1558 Expression PrimaryExpression() :
1560 final Token identifier;
1562 final int pos = SimpleCharStream.getPosition();
1566 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1567 {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
1569 SimpleCharStream.getPosition()),
1571 ClassAccess.STATIC);}
1572 (expr = PrimarySuffix(expr))*
1575 expr = PrimaryPrefix()
1576 (expr = PrimarySuffix(expr))*
1579 expr = ArrayDeclarator()
1583 ArrayInitializer ArrayDeclarator() :
1585 final ArrayVariableDeclaration[] vars;
1586 final int pos = SimpleCharStream.getPosition();
1589 <ARRAY> vars = ArrayInitializer()
1590 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1593 Expression PrimaryPrefix() :
1595 final Expression expr;
1598 final int pos = SimpleCharStream.getPosition();
1601 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1603 SimpleCharStream.getPosition());}
1604 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1607 | var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(),
1609 SimpleCharStream.getPosition());}
1612 PrefixedUnaryExpression classInstantiation() :
1615 final StringBuffer buff;
1616 final int pos = SimpleCharStream.getPosition();
1619 <NEW> expr = ClassIdentifier()
1621 {buff = new StringBuffer(expr.toStringExpression());}
1622 expr = PrimaryExpression()
1623 {buff.append(expr.toStringExpression());
1624 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1626 SimpleCharStream.getPosition());}
1628 {return new PrefixedUnaryExpression(expr,
1633 ConstantIdentifier ClassIdentifier():
1637 final int pos = SimpleCharStream.getPosition();
1640 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1642 SimpleCharStream.getPosition());}
1643 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1645 SimpleCharStream.getPosition());}
1648 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
1650 final AbstractSuffixExpression expr;
1653 expr = Arguments(prefix) {return expr;}
1654 | expr = VariableSuffix(prefix) {return expr;}
1657 AbstractSuffixExpression VariableSuffix(Expression prefix) :
1660 final int pos = SimpleCharStream.getPosition();
1661 Expression expression = null;
1666 expr = VariableName()
1667 } catch (ParseException e) {
1668 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1670 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1671 errorEnd = SimpleCharStream.getPosition() + 1;
1674 {return new ClassAccess(prefix,
1675 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1676 ClassAccess.NORMAL);}
1678 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1681 } catch (ParseException e) {
1682 errorMessage = "']' expected";
1684 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1685 errorEnd = SimpleCharStream.getPosition() + 1;
1688 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1697 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1698 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1699 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1700 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1701 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1702 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1703 | <TRUE> {pos = SimpleCharStream.getPosition();
1704 return new TrueLiteral(pos-4,pos);}
1705 | <FALSE> {pos = SimpleCharStream.getPosition();
1706 return new FalseLiteral(pos-4,pos);}
1707 | <NULL> {pos = SimpleCharStream.getPosition();
1708 return new NullLiteral(pos-4,pos);}
1711 FunctionCall Arguments(Expression func) :
1713 Expression[] args = null;
1716 <LPAREN> [ args = ArgumentList() ]
1719 } catch (ParseException e) {
1720 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1722 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1723 errorEnd = SimpleCharStream.getPosition() + 1;
1726 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1730 * An argument list is a list of arguments separated by comma :
1731 * argumentDeclaration() (, argumentDeclaration)*
1732 * @return an array of arguments
1734 Expression[] ArgumentList() :
1737 final ArrayList list = new ArrayList();
1746 } catch (ParseException e) {
1747 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1749 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1750 errorEnd = SimpleCharStream.getPosition() + 1;
1755 Expression[] arguments = new Expression[list.size()];
1756 list.toArray(arguments);
1761 * A Statement without break.
1763 Statement StatementNoBreak() :
1765 final Statement statement;
1770 statement = Expression()
1773 } catch (ParseException e) {
1774 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1775 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1777 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1778 errorEnd = SimpleCharStream.getPosition() + 1;
1784 statement = LabeledStatement() {return statement;}
1785 | statement = Block() {return statement;}
1786 | statement = EmptyStatement() {return statement;}
1787 | statement = StatementExpression()
1790 } catch (ParseException e) {
1791 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1793 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1794 errorEnd = SimpleCharStream.getPosition() + 1;
1798 | statement = SwitchStatement() {return statement;}
1799 | statement = IfStatement() {return statement;}
1800 | statement = WhileStatement() {return statement;}
1801 | statement = DoStatement() {return statement;}
1802 | statement = ForStatement() {return statement;}
1803 | statement = ForeachStatement() {return statement;}
1804 | statement = ContinueStatement() {return statement;}
1805 | statement = ReturnStatement() {return statement;}
1806 | statement = EchoStatement() {return statement;}
1807 | [token=<AT>] statement = IncludeStatement()
1808 {if (token != null) {
1809 ((InclusionStatement)statement).silent = true;
1812 | statement = StaticStatement() {return statement;}
1813 | statement = GlobalStatement() {return statement;}
1817 * A Normal statement.
1819 Statement Statement() :
1821 final Statement statement;
1824 statement = StatementNoBreak() {return statement;}
1825 | statement = BreakStatement() {return statement;}
1829 * An html block inside a php syntax.
1831 HTMLBlock htmlBlock() :
1833 final int startIndex = nodePtr;
1834 AstNode[] blockNodes;
1838 <PHPEND> (phpEchoBlock())*
1840 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1841 } catch (ParseException e) {
1842 errorMessage = "End of file unexpected, '<?php' expected";
1844 errorStart = SimpleCharStream.getPosition();
1845 errorEnd = SimpleCharStream.getPosition();
1849 nbNodes = nodePtr - startIndex;
1850 blockNodes = new AstNode[nbNodes];
1851 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1852 nodePtr = startIndex;
1853 return new HTMLBlock(blockNodes);}
1857 * An include statement. It's "include" an expression;
1859 InclusionStatement IncludeStatement() :
1861 final Expression expr;
1863 final int pos = SimpleCharStream.getPosition();
1864 final InclusionStatement inclusionStatement;
1867 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1868 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1869 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1870 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1873 } catch (ParseException e) {
1874 if (errorMessage != null) {
1877 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1879 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1880 errorEnd = SimpleCharStream.getPosition() + 1;
1883 {inclusionStatement = new InclusionStatement(currentSegment,
1887 currentSegment.add(inclusionStatement);
1891 } catch (ParseException e) {
1892 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1894 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1895 errorEnd = SimpleCharStream.getPosition() + 1;
1898 {return inclusionStatement;}
1901 PrintExpression PrintExpression() :
1903 final Expression expr;
1904 final int pos = SimpleCharStream.getPosition();
1907 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1910 ListExpression ListExpression() :
1913 Expression expression = null;
1914 ArrayList list = new ArrayList();
1915 final int pos = SimpleCharStream.getPosition();
1921 } catch (ParseException e) {
1922 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1924 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1925 errorEnd = SimpleCharStream.getPosition() + 1;
1929 expr = VariableDeclaratorId()
1932 {if (expr == null) list.add(null);}
1936 } catch (ParseException e) {
1937 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1939 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1940 errorEnd = SimpleCharStream.getPosition() + 1;
1943 expr = VariableDeclaratorId()
1948 } catch (ParseException e) {
1949 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1951 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1952 errorEnd = SimpleCharStream.getPosition() + 1;
1955 [ <ASSIGN> expression = Expression()
1957 String[] strings = new String[list.size()];
1958 list.toArray(strings);
1959 return new ListExpression(strings,
1962 SimpleCharStream.getPosition());}
1965 String[] strings = new String[list.size()];
1966 list.toArray(strings);
1967 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
1971 * An echo statement.
1972 * echo anyexpression (, otherexpression)*
1974 EchoStatement EchoStatement() :
1976 final ArrayList expressions = new ArrayList();
1978 final int pos = SimpleCharStream.getPosition();
1981 <ECHO> expr = Expression()
1982 {expressions.add(expr);}
1984 <COMMA> expr = Expression()
1985 {expressions.add(expr);}
1989 } catch (ParseException e) {
1990 if (e.currentToken.next.kind != 4) {
1991 errorMessage = "';' expected after 'echo' statement";
1993 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1994 errorEnd = SimpleCharStream.getPosition() + 1;
1998 {Expression[] exprs = new Expression[expressions.size()];
1999 expressions.toArray(exprs);
2000 return new EchoStatement(exprs,pos);}
2003 GlobalStatement GlobalStatement() :
2005 final int pos = SimpleCharStream.getPosition();
2007 ArrayList vars = new ArrayList();
2008 GlobalStatement global;
2012 expr = VariableDeclaratorId()
2015 expr = VariableDeclaratorId()
2021 String[] strings = new String[vars.size()];
2022 vars.toArray(strings);
2023 global = new GlobalStatement(currentSegment,
2026 SimpleCharStream.getPosition());
2027 currentSegment.add(global);
2029 } catch (ParseException e) {
2030 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2032 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2033 errorEnd = SimpleCharStream.getPosition() + 1;
2038 StaticStatement StaticStatement() :
2040 final int pos = SimpleCharStream.getPosition();
2041 final ArrayList vars = new ArrayList();
2042 VariableDeclaration expr;
2045 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2046 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2050 String[] strings = new String[vars.size()];
2051 vars.toArray(strings);
2052 return new StaticStatement(strings,
2054 SimpleCharStream.getPosition());}
2055 } catch (ParseException e) {
2056 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2058 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2059 errorEnd = SimpleCharStream.getPosition() + 1;
2064 LabeledStatement LabeledStatement() :
2066 final int pos = SimpleCharStream.getPosition();
2068 final Statement statement;
2071 label = <IDENTIFIER> <COLON> statement = Statement()
2072 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2084 final int pos = SimpleCharStream.getPosition();
2085 final ArrayList list = new ArrayList();
2086 Statement statement;
2091 } catch (ParseException e) {
2092 errorMessage = "'{' expected";
2094 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2095 errorEnd = SimpleCharStream.getPosition() + 1;
2098 ( statement = BlockStatement() {list.add(statement);}
2099 | statement = htmlBlock() {list.add(statement);})*
2102 } catch (ParseException e) {
2103 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2105 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2106 errorEnd = SimpleCharStream.getPosition() + 1;
2110 Statement[] statements = new Statement[list.size()];
2111 list.toArray(statements);
2112 return new Block(statements,pos,SimpleCharStream.getPosition());}
2115 Statement BlockStatement() :
2117 final Statement statement;
2121 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2123 } catch (ParseException e) {
2124 errorMessage = "statement expected";
2126 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2127 errorEnd = SimpleCharStream.getPosition() + 1;
2130 | statement = ClassDeclaration() {return statement;}
2131 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2136 * A Block statement that will not contain any 'break'
2138 Statement BlockStatementNoBreak() :
2140 final Statement statement;
2143 statement = StatementNoBreak() {return statement;}
2144 | statement = ClassDeclaration() {return statement;}
2145 | statement = MethodDeclaration() {return statement;}
2148 VariableDeclaration[] LocalVariableDeclaration() :
2150 final ArrayList list = new ArrayList();
2151 VariableDeclaration var;
2154 var = LocalVariableDeclarator()
2156 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2158 VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2163 VariableDeclaration LocalVariableDeclarator() :
2165 final String varName;
2166 Expression initializer = null;
2167 final int pos = SimpleCharStream.getPosition();
2170 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2172 if (initializer == null) {
2173 return new VariableDeclaration(currentSegment,
2174 varName.toCharArray(),
2176 SimpleCharStream.getPosition());
2178 return new VariableDeclaration(currentSegment,
2179 varName.toCharArray(),
2185 EmptyStatement EmptyStatement() :
2191 {pos = SimpleCharStream.getPosition();
2192 return new EmptyStatement(pos-1,pos);}
2195 Statement StatementExpression() :
2197 Expression expr,expr2;
2201 expr = PreIncDecExpression() {return expr;}
2203 expr = PrimaryExpression()
2204 [ <INCR> {return new PostfixedUnaryExpression(expr,
2205 OperatorIds.PLUS_PLUS,
2206 SimpleCharStream.getPosition());}
2207 | <DECR> {return new PostfixedUnaryExpression(expr,
2208 OperatorIds.MINUS_MINUS,
2209 SimpleCharStream.getPosition());}
2210 | operator = AssignmentOperator() expr2 = Expression()
2211 {return new BinaryExpression(expr,expr2,operator);}
2216 SwitchStatement SwitchStatement() :
2218 final Expression variable;
2219 final AbstractCase[] cases;
2220 final int pos = SimpleCharStream.getPosition();
2226 } catch (ParseException e) {
2227 errorMessage = "'(' expected after 'switch'";
2229 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2230 errorEnd = SimpleCharStream.getPosition() + 1;
2234 variable = Expression()
2235 } catch (ParseException e) {
2236 if (errorMessage != null) {
2239 errorMessage = "expression expected";
2241 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2242 errorEnd = SimpleCharStream.getPosition() + 1;
2247 } catch (ParseException e) {
2248 errorMessage = "')' expected";
2250 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2251 errorEnd = SimpleCharStream.getPosition() + 1;
2254 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2255 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2258 AbstractCase[] switchStatementBrace() :
2261 final ArrayList cases = new ArrayList();
2265 ( cas = switchLabel0() {cases.add(cas);})*
2269 AbstractCase[] abcase = new AbstractCase[cases.size()];
2270 cases.toArray(abcase);
2272 } catch (ParseException e) {
2273 errorMessage = "'}' expected";
2275 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2276 errorEnd = SimpleCharStream.getPosition() + 1;
2281 * A Switch statement with : ... endswitch;
2282 * @param start the begin offset of the switch
2283 * @param end the end offset of the switch
2285 AbstractCase[] switchStatementColon(final int start, final int end) :
2288 final ArrayList cases = new ArrayList();
2293 setMarker(fileToParse,
2294 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2298 "Line " + token.beginLine);
2299 } catch (CoreException e) {
2300 PHPeclipsePlugin.log(e);
2302 ( cas = switchLabel0() {cases.add(cas);})*
2305 } catch (ParseException e) {
2306 errorMessage = "'endswitch' expected";
2308 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2309 errorEnd = SimpleCharStream.getPosition() + 1;
2315 AbstractCase[] abcase = new AbstractCase[cases.size()];
2316 cases.toArray(abcase);
2318 } catch (ParseException e) {
2319 errorMessage = "';' expected after 'endswitch' keyword";
2321 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2322 errorEnd = SimpleCharStream.getPosition() + 1;
2327 AbstractCase switchLabel0() :
2329 final Expression expr;
2330 Statement statement;
2331 final ArrayList stmts = new ArrayList();
2332 final int pos = SimpleCharStream.getPosition();
2335 expr = SwitchLabel()
2336 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2337 | statement = htmlBlock() {stmts.add(statement);})*
2338 [ statement = BreakStatement() {stmts.add(statement);}]
2340 Statement[] stmtsArray = new Statement[stmts.size()];
2341 stmts.toArray(stmtsArray);
2342 if (expr == null) {//it's a default
2343 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2345 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2350 * case Expression() :
2352 * @return the if it was a case and null if not
2354 Expression SwitchLabel() :
2356 final Expression expr;
2362 } catch (ParseException e) {
2363 if (errorMessage != null) throw e;
2364 errorMessage = "expression expected after 'case' keyword";
2366 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2367 errorEnd = SimpleCharStream.getPosition() + 1;
2373 } catch (ParseException e) {
2374 errorMessage = "':' expected after case expression";
2376 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2377 errorEnd = SimpleCharStream.getPosition() + 1;
2385 } catch (ParseException e) {
2386 errorMessage = "':' expected after 'default' keyword";
2388 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2389 errorEnd = SimpleCharStream.getPosition() + 1;
2394 Break BreakStatement() :
2396 Expression expression = null;
2397 final int start = SimpleCharStream.getPosition();
2400 <BREAK> [ expression = Expression() ]
2403 } catch (ParseException e) {
2404 errorMessage = "';' expected after 'break' keyword";
2406 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2407 errorEnd = SimpleCharStream.getPosition() + 1;
2410 {return new Break(expression, start, SimpleCharStream.getPosition());}
2413 IfStatement IfStatement() :
2415 final int pos = SimpleCharStream.getPosition();
2416 Expression condition;
2417 IfStatement ifStatement;
2420 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2421 {return ifStatement;}
2425 Expression Condition(final String keyword) :
2427 final Expression condition;
2432 } catch (ParseException e) {
2433 errorMessage = "'(' expected after " + keyword + " keyword";
2435 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2436 errorEnd = errorStart +1;
2437 processParseException(e);
2439 condition = Expression()
2442 } catch (ParseException e) {
2443 errorMessage = "')' expected after " + keyword + " keyword";
2445 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2446 errorEnd = SimpleCharStream.getPosition() + 1;
2447 processParseException(e);
2452 IfStatement IfStatement0(Expression condition, final int start,final int end) :
2454 Statement statement;
2456 final Statement[] statementsArray;
2457 ElseIf elseifStatement;
2458 Else elseStatement = null;
2460 final ArrayList elseIfList = new ArrayList();
2462 int pos = SimpleCharStream.getPosition();
2467 {stmts = new ArrayList();}
2468 ( statement = Statement() {stmts.add(statement);}
2469 | statement = htmlBlock() {stmts.add(statement);})*
2470 {endStatements = SimpleCharStream.getPosition();}
2471 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2472 [elseStatement = ElseStatementColon()]
2475 setMarker(fileToParse,
2476 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2480 "Line " + token.beginLine);
2481 } catch (CoreException e) {
2482 PHPeclipsePlugin.log(e);
2486 } catch (ParseException e) {
2487 errorMessage = "'endif' expected";
2489 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2490 errorEnd = SimpleCharStream.getPosition() + 1;
2495 } catch (ParseException e) {
2496 errorMessage = "';' expected after 'endif' keyword";
2498 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2499 errorEnd = SimpleCharStream.getPosition() + 1;
2503 elseIfs = new ElseIf[elseIfList.size()];
2504 elseIfList.toArray(elseIfs);
2505 if (stmts.size() == 1) {
2506 return new IfStatement(condition,
2507 (Statement) stmts.get(0),
2511 SimpleCharStream.getPosition());
2513 statementsArray = new Statement[stmts.size()];
2514 stmts.toArray(statementsArray);
2515 return new IfStatement(condition,
2516 new Block(statementsArray,pos,endStatements),
2520 SimpleCharStream.getPosition());
2525 (stmt = Statement() | stmt = htmlBlock())
2526 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2530 {pos = SimpleCharStream.getPosition();}
2531 statement = Statement()
2532 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2533 } catch (ParseException e) {
2534 if (errorMessage != null) {
2537 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2539 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2540 errorEnd = SimpleCharStream.getPosition() + 1;
2545 elseIfs = new ElseIf[elseIfList.size()];
2546 elseIfList.toArray(elseIfs);
2547 return new IfStatement(condition,
2552 SimpleCharStream.getPosition());}
2555 ElseIf ElseIfStatementColon() :
2557 Expression condition;
2558 Statement statement;
2559 final ArrayList list = new ArrayList();
2560 final int pos = SimpleCharStream.getPosition();
2563 <ELSEIF> condition = Condition("elseif")
2564 <COLON> ( statement = Statement() {list.add(statement);}
2565 | statement = htmlBlock() {list.add(statement);})*
2567 Statement[] stmtsArray = new Statement[list.size()];
2568 list.toArray(stmtsArray);
2569 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2572 Else ElseStatementColon() :
2574 Statement statement;
2575 final ArrayList list = new ArrayList();
2576 final int pos = SimpleCharStream.getPosition();
2579 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2580 | statement = htmlBlock() {list.add(statement);})*
2582 Statement[] stmtsArray = new Statement[list.size()];
2583 list.toArray(stmtsArray);
2584 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2587 ElseIf ElseIfStatement() :
2589 Expression condition;
2590 Statement statement;
2591 final ArrayList list = new ArrayList();
2592 final int pos = SimpleCharStream.getPosition();
2595 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2597 Statement[] stmtsArray = new Statement[list.size()];
2598 list.toArray(stmtsArray);
2599 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2602 WhileStatement WhileStatement() :
2604 final Expression condition;
2605 final Statement action;
2606 final int pos = SimpleCharStream.getPosition();
2610 condition = Condition("while")
2611 action = WhileStatement0(pos,pos + 5)
2612 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2615 Statement WhileStatement0(final int start, final int end) :
2617 Statement statement;
2618 final ArrayList stmts = new ArrayList();
2619 final int pos = SimpleCharStream.getPosition();
2622 <COLON> (statement = Statement() {stmts.add(statement);})*
2624 setMarker(fileToParse,
2625 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2629 "Line " + token.beginLine);
2630 } catch (CoreException e) {
2631 PHPeclipsePlugin.log(e);
2635 } catch (ParseException e) {
2636 errorMessage = "'endwhile' expected";
2638 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2639 errorEnd = SimpleCharStream.getPosition() + 1;
2645 Statement[] stmtsArray = new Statement[stmts.size()];
2646 stmts.toArray(stmtsArray);
2647 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2648 } catch (ParseException e) {
2649 errorMessage = "';' expected after 'endwhile' keyword";
2651 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2652 errorEnd = SimpleCharStream.getPosition() + 1;
2656 statement = Statement()
2660 DoStatement DoStatement() :
2662 final Statement action;
2663 final Expression condition;
2664 final int pos = SimpleCharStream.getPosition();
2667 <DO> action = Statement() <WHILE> condition = Condition("while")
2670 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2671 } catch (ParseException e) {
2672 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2674 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2675 errorEnd = SimpleCharStream.getPosition() + 1;
2680 ForeachStatement ForeachStatement() :
2682 Statement statement;
2683 Expression expression;
2684 final int pos = SimpleCharStream.getPosition();
2685 ArrayVariableDeclaration variable;
2691 } catch (ParseException e) {
2692 errorMessage = "'(' expected after 'foreach' keyword";
2694 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2695 errorEnd = SimpleCharStream.getPosition() + 1;
2699 expression = Expression()
2700 } catch (ParseException e) {
2701 errorMessage = "variable expected";
2703 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2704 errorEnd = SimpleCharStream.getPosition() + 1;
2709 } catch (ParseException e) {
2710 errorMessage = "'as' expected";
2712 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2713 errorEnd = SimpleCharStream.getPosition() + 1;
2717 variable = ArrayVariable()
2718 } catch (ParseException e) {
2719 errorMessage = "variable expected";
2721 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2722 errorEnd = SimpleCharStream.getPosition() + 1;
2727 } catch (ParseException e) {
2728 errorMessage = "')' expected after 'foreach' keyword";
2730 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2731 errorEnd = SimpleCharStream.getPosition() + 1;
2735 statement = Statement()
2736 } catch (ParseException e) {
2737 if (errorMessage != null) throw e;
2738 errorMessage = "statement expected";
2740 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2741 errorEnd = SimpleCharStream.getPosition() + 1;
2744 {return new ForeachStatement(expression,
2748 SimpleCharStream.getPosition());}
2752 ForStatement ForStatement() :
2755 final int pos = SimpleCharStream.getPosition();
2756 Statement[] initializations = null;
2757 Expression condition = null;
2758 Statement[] increments = null;
2760 final ArrayList list = new ArrayList();
2761 final int startBlock, endBlock;
2767 } catch (ParseException e) {
2768 errorMessage = "'(' expected after 'for' keyword";
2770 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2771 errorEnd = SimpleCharStream.getPosition() + 1;
2774 [ initializations = ForInit() ] <SEMICOLON>
2775 [ condition = Expression() ] <SEMICOLON>
2776 [ increments = StatementExpressionList() ] <RPAREN>
2778 action = Statement()
2779 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2782 {startBlock = SimpleCharStream.getPosition();}
2783 (action = Statement() {list.add(action);})*
2786 setMarker(fileToParse,
2787 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2789 pos+token.image.length(),
2791 "Line " + token.beginLine);
2792 } catch (CoreException e) {
2793 PHPeclipsePlugin.log(e);
2796 {endBlock = SimpleCharStream.getPosition();}
2799 } catch (ParseException e) {
2800 errorMessage = "'endfor' expected";
2802 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2803 errorEnd = SimpleCharStream.getPosition() + 1;
2809 Statement[] stmtsArray = new Statement[list.size()];
2810 list.toArray(stmtsArray);
2811 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2812 } catch (ParseException e) {
2813 errorMessage = "';' expected after 'endfor' keyword";
2815 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2816 errorEnd = SimpleCharStream.getPosition() + 1;
2822 Statement[] ForInit() :
2824 Statement[] statements;
2827 LOOKAHEAD(LocalVariableDeclaration())
2828 statements = LocalVariableDeclaration()
2829 {return statements;}
2831 statements = StatementExpressionList()
2832 {return statements;}
2835 Statement[] StatementExpressionList() :
2837 final ArrayList list = new ArrayList();
2841 expr = StatementExpression() {list.add(expr);}
2842 (<COMMA> StatementExpression() {list.add(expr);})*
2844 Statement[] stmtsArray = new Statement[list.size()];
2845 list.toArray(stmtsArray);
2849 Continue ContinueStatement() :
2851 Expression expr = null;
2852 final int pos = SimpleCharStream.getPosition();
2855 <CONTINUE> [ expr = Expression() ]
2858 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2859 } catch (ParseException e) {
2860 errorMessage = "';' expected after 'continue' statement";
2862 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2863 errorEnd = SimpleCharStream.getPosition() + 1;
2868 ReturnStatement ReturnStatement() :
2870 Expression expr = null;
2871 final int pos = SimpleCharStream.getPosition();
2874 <RETURN> [ expr = Expression() ]
2877 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2878 } catch (ParseException e) {
2879 errorMessage = "';' expected after 'return' statement";
2881 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2882 errorEnd = SimpleCharStream.getPosition() + 1;