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.PHPOutlineInfo;
45 * This php parser is inspired by the Java 1.2 grammar example
46 * given with JavaCC. You can get JavaCC at http://www.webgain.com
47 * You can test the parser with the PHPParserTestCase2.java
48 * @author Matthieu Casanova
50 public final class PHPParser extends PHPParserSuperclass {
52 /** The file that is parsed. */
53 private static IFile fileToParse;
55 /** The current segment. */
56 private static OutlineableWithChildren currentSegment;
58 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
59 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
60 static PHPOutlineInfo outlineInfo;
62 /** The error level of the current ParseException. */
63 private static int errorLevel = ERROR;
64 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
65 private static String errorMessage;
67 private static int errorStart = -1;
68 private static int errorEnd = -1;
69 private static PHPDocument phpDocument;
71 private static final char[] SYNTAX_ERROR_CHAR = {'s','y','n','t','a','x',' ','e','r','r','o','r'};
73 * The point where html starts.
74 * It will be used by the token manager to create HTMLCode objects
76 public static int htmlStart;
79 private final static int AstStackIncrement = 100;
80 /** The stack of node. */
81 private static AstNode[] nodes;
82 /** The cursor in expression stack. */
83 private static int nodePtr;
85 public final void setFileToParse(final IFile fileToParse) {
86 this.fileToParse = fileToParse;
92 public PHPParser(final IFile fileToParse) {
93 this(new StringReader(""));
94 this.fileToParse = fileToParse;
98 * Reinitialize the parser.
100 private static final void init() {
101 nodes = new AstNode[AstStackIncrement];
107 * Add an php node on the stack.
108 * @param node the node that will be added to the stack
110 private static final void pushOnAstNodes(AstNode node) {
112 nodes[++nodePtr] = node;
113 } catch (IndexOutOfBoundsException e) {
114 int oldStackLength = nodes.length;
115 AstNode[] oldStack = nodes;
116 nodes = new AstNode[oldStackLength + AstStackIncrement];
117 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
118 nodePtr = oldStackLength;
119 nodes[nodePtr] = node;
123 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
124 phpDocument = new PHPDocument(parent,"_root".toCharArray());
125 currentSegment = phpDocument;
126 outlineInfo = new PHPOutlineInfo(parent, currentSegment);
127 final StringReader stream = new StringReader(s);
128 if (jj_input_stream == null) {
129 jj_input_stream = new SimpleCharStream(stream, 1, 1);
135 phpDocument.nodes = new AstNode[nodes.length];
136 System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
137 if (PHPeclipsePlugin.DEBUG) {
138 PHPeclipsePlugin.log(1,phpDocument.toString());
140 } catch (ParseException e) {
141 processParseException(e);
147 * This method will process the parse exception.
148 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
149 * @param e the ParseException
151 private static void processParseException(final ParseException e) {
152 if (errorMessage == null) {
153 PHPeclipsePlugin.log(e);
154 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
155 errorStart = SimpleCharStream.getPosition();
156 errorEnd = errorStart + 1;
163 * Create marker for the parse error
164 * @param e the ParseException
166 private static void setMarker(final ParseException e) {
168 if (errorStart == -1) {
169 setMarker(fileToParse,
171 SimpleCharStream.tokenBegin,
172 SimpleCharStream.tokenBegin + e.currentToken.image.length(),
174 "Line " + e.currentToken.beginLine);
176 setMarker(fileToParse,
181 "Line " + e.currentToken.beginLine);
185 } catch (CoreException e2) {
186 PHPeclipsePlugin.log(e2);
190 private static void scanLine(final String output,
193 final int brIndx) throws CoreException {
195 StringBuffer lineNumberBuffer = new StringBuffer(10);
197 current = output.substring(indx, brIndx);
199 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
200 int onLine = current.indexOf("on line <b>");
202 lineNumberBuffer.delete(0, lineNumberBuffer.length());
203 for (int i = onLine; i < current.length(); i++) {
204 ch = current.charAt(i);
205 if ('0' <= ch && '9' >= ch) {
206 lineNumberBuffer.append(ch);
210 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
212 Hashtable attributes = new Hashtable();
214 current = current.replaceAll("\n", "");
215 current = current.replaceAll("<b>", "");
216 current = current.replaceAll("</b>", "");
217 MarkerUtilities.setMessage(attributes, current);
219 if (current.indexOf(PARSE_ERROR_STRING) != -1)
220 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
221 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
222 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
224 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
225 MarkerUtilities.setLineNumber(attributes, lineNumber);
226 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
231 public final void parse(final String s) throws CoreException {
232 final StringReader stream = new StringReader(s);
233 if (jj_input_stream == null) {
234 jj_input_stream = new SimpleCharStream(stream, 1, 1);
240 } catch (ParseException e) {
241 processParseException(e);
246 * Call the php parse command ( php -l -f <filename> )
247 * and create markers according to the external parser output
249 public static void phpExternalParse(final IFile file) {
250 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
251 final String filename = file.getLocation().toString();
253 final String[] arguments = { filename };
254 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
255 final String command = form.format(arguments);
257 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
260 // parse the buffer to find the errors and warnings
261 createMarkers(parserResult, file);
262 } catch (CoreException e) {
263 PHPeclipsePlugin.log(e);
268 * Put a new html block in the stack.
270 public static final void createNewHTMLCode() {
271 final int currentPosition = SimpleCharStream.getPosition();
272 if (currentPosition == htmlStart) {
275 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition+1).toCharArray();
276 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
282 public static final void createNewTask() {
283 final int currentPosition = SimpleCharStream.getPosition();
284 final String todo = SimpleCharStream.currentBuffer.substring(currentPosition+1,
285 SimpleCharStream.currentBuffer.indexOf("\n",
288 setMarker(fileToParse,
290 SimpleCharStream.getBeginLine(),
292 "Line "+SimpleCharStream.getBeginLine());
293 } catch (CoreException e) {
294 PHPeclipsePlugin.log(e);
298 private static final void parse() throws ParseException {
303 PARSER_END(PHPParser)
307 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
308 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
309 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
314 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
317 /* Skip any character if we are not in php mode */
335 <PHPPARSING> SPECIAL_TOKEN :
337 "//" : IN_SINGLE_LINE_COMMENT
338 | "#" : IN_SINGLE_LINE_COMMENT
339 | <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
340 | "/*" : IN_MULTI_LINE_COMMENT
343 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
345 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
349 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
351 "todo" {PHPParser.createNewTask();}
354 <IN_FORMAL_COMMENT> SPECIAL_TOKEN :
359 <IN_MULTI_LINE_COMMENT> SPECIAL_TOKEN :
364 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
374 | <FUNCTION : "function">
377 | <ELSEIF : "elseif">
384 /* LANGUAGE CONSTRUCT */
389 | <INCLUDE : "include">
390 | <REQUIRE : "require">
391 | <INCLUDE_ONCE : "include_once">
392 | <REQUIRE_ONCE : "require_once">
393 | <GLOBAL : "global">
394 | <STATIC : "static">
395 | <CLASSACCESS : "->">
396 | <STATICCLASSACCESS : "::">
397 | <ARRAYASSIGN : "=>">
400 /* RESERVED WORDS AND LITERALS */
406 | <CONTINUE : "continue">
407 | <_DEFAULT : "default">
409 | <EXTENDS : "extends">
414 | <RETURN : "return">
416 | <SWITCH : "switch">
421 | <ENDWHILE : "endwhile">
422 | <ENDSWITCH: "endswitch">
424 | <ENDFOR : "endfor">
425 | <FOREACH : "foreach">
433 | <OBJECT : "object">
435 | <BOOLEAN : "boolean">
437 | <DOUBLE : "double">
440 | <INTEGER : "integer">
460 | <MINUS_MINUS : "--">
470 | <RSIGNEDSHIFT : ">>">
471 | <RUNSIGNEDSHIFT : ">>>">
480 <DECIMAL_LITERAL> (["l","L"])?
481 | <HEX_LITERAL> (["l","L"])?
482 | <OCTAL_LITERAL> (["l","L"])?
485 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
487 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
489 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
491 <FLOATING_POINT_LITERAL:
492 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
493 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
494 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
495 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
498 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
500 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
533 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
536 ["a"-"z"] | ["A"-"Z"]
544 "_" | ["\u007f"-"\u00ff"]
569 | <EQUAL_EQUAL : "==">
574 | <BANGDOUBLEEQUAL : "!==">
575 | <TRIPLEEQUAL : "===">
582 | <PLUSASSIGN : "+=">
583 | <MINUSASSIGN : "-=">
584 | <STARASSIGN : "*=">
585 | <SLASHASSIGN : "/=">
591 | <TILDEEQUAL : "~=">
592 | <LSHIFTASSIGN : "<<=">
593 | <RSIGNEDSHIFTASSIGN : ">>=">
598 <DOLLAR_ID: <DOLLAR> <IDENTIFIER>>
606 {PHPParser.createNewHTMLCode();}
607 } catch (TokenMgrError e) {
608 PHPeclipsePlugin.log(e);
609 errorStart = SimpleCharStream.getPosition();
610 errorEnd = errorStart + 1;
611 errorMessage = e.getMessage();
613 throw generateParseException();
618 * A php block is a <?= expression [;]?>
619 * or <?php somephpcode ?>
620 * or <? somephpcode ?>
624 final int start = SimpleCharStream.getPosition();
625 final PHPEchoBlock phpEchoBlock;
628 phpEchoBlock = phpEchoBlock()
629 {pushOnAstNodes(phpEchoBlock);}
634 setMarker(fileToParse,
635 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
637 SimpleCharStream.getPosition(),
639 "Line " + token.beginLine);
640 } catch (CoreException e) {
641 PHPeclipsePlugin.log(e);
647 } catch (ParseException e) {
648 errorMessage = "'?>' expected";
650 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
651 errorEnd = SimpleCharStream.getPosition() + 1;
652 processParseException(e);
656 PHPEchoBlock phpEchoBlock() :
658 final Expression expr;
659 final int pos = SimpleCharStream.getPosition();
660 PHPEchoBlock echoBlock;
663 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
665 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
666 pushOnAstNodes(echoBlock);
676 ClassDeclaration ClassDeclaration() :
678 final ClassDeclaration classDeclaration;
679 final Token className;
680 Token superclassName = null;
682 char[] classNameImage = SYNTAX_ERROR_CHAR;
683 char[] superclassNameImage = null;
687 {pos = SimpleCharStream.getPosition();}
689 className = <IDENTIFIER>
690 {classNameImage = className.image.toCharArray();}
691 } catch (ParseException e) {
692 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
694 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
695 errorEnd = SimpleCharStream.getPosition() + 1;
696 processParseException(e);
701 superclassName = <IDENTIFIER>
702 {superclassNameImage = superclassName.image.toCharArray();}
703 } catch (ParseException e) {
704 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
706 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
707 errorEnd = SimpleCharStream.getPosition() + 1;
708 processParseException(e);
709 superclassNameImage = SYNTAX_ERROR_CHAR;
713 if (superclassNameImage == null) {
714 classDeclaration = new ClassDeclaration(currentSegment,
719 classDeclaration = new ClassDeclaration(currentSegment,
725 currentSegment.add(classDeclaration);
726 currentSegment = classDeclaration;
728 ClassBody(classDeclaration)
729 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
730 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
731 pushOnAstNodes(classDeclaration);
732 return classDeclaration;}
735 void ClassBody(ClassDeclaration classDeclaration) :
740 } catch (ParseException e) {
741 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
743 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
744 errorEnd = SimpleCharStream.getPosition() + 1;
747 ( ClassBodyDeclaration(classDeclaration) )*
750 } catch (ParseException e) {
751 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
753 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
754 errorEnd = SimpleCharStream.getPosition() + 1;
760 * A class can contain only methods and fields.
762 void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
764 MethodDeclaration method;
765 FieldDeclaration field;
768 method = MethodDeclaration() {classDeclaration.addMethod(method);}
769 | field = FieldDeclaration() {classDeclaration.addField(field);}
773 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
775 FieldDeclaration FieldDeclaration() :
777 VariableDeclaration variableDeclaration;
778 VariableDeclaration[] list;
779 final ArrayList arrayList = new ArrayList();
780 final int pos = SimpleCharStream.getPosition();
783 <VAR> variableDeclaration = VariableDeclarator()
784 {arrayList.add(variableDeclaration);
785 outlineInfo.addVariable(new String(variableDeclaration.name));}
786 ( <COMMA> variableDeclaration = VariableDeclarator()
787 {arrayList.add(variableDeclaration);
788 outlineInfo.addVariable(new String(variableDeclaration.name));}
792 } catch (ParseException e) {
793 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
795 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
796 errorEnd = SimpleCharStream.getPosition() + 1;
797 processParseException(e);
800 {list = new VariableDeclaration[arrayList.size()];
801 arrayList.toArray(list);
802 return new FieldDeclaration(list,
804 SimpleCharStream.getPosition(),
808 VariableDeclaration VariableDeclarator() :
810 final String varName;
811 Expression initializer = null;
812 final int pos = SimpleCharStream.getPosition();
815 varName = VariableDeclaratorId()
819 initializer = VariableInitializer()
820 } catch (ParseException e) {
821 errorMessage = "Literal expression expected in variable initializer";
823 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
824 errorEnd = SimpleCharStream.getPosition() + 1;
829 if (initializer == null) {
830 return new VariableDeclaration(currentSegment,
831 varName.toCharArray(),
833 SimpleCharStream.getPosition());
835 return new VariableDeclaration(currentSegment,
836 varName.toCharArray(),
844 * @return the variable name (with suffix)
846 String VariableDeclaratorId() :
849 Expression expression = null;
850 final StringBuffer buff = new StringBuffer();
851 final int pos = SimpleCharStream.getPosition();
852 ConstantIdentifier ex;
858 {ex = new ConstantIdentifier(expr.toCharArray(),
860 SimpleCharStream.getPosition());}
861 expression = VariableSuffix(ex)
864 if (expression == null) {
867 return expression.toStringExpression();
869 } catch (ParseException e) {
870 errorMessage = "'$' expected for variable identifier";
872 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
873 errorEnd = SimpleCharStream.getPosition() + 1;
879 * Return a variablename without the $.
880 * @return a variable name
884 final StringBuffer buff;
885 Expression expression = null;
890 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
892 if (expression == null) {
893 return token.image.substring(1);
895 buff = new StringBuffer(token.image);
897 buff.append(expression.toStringExpression());
899 return buff.toString();
902 <DOLLAR> expr = VariableName()
907 * A Variable name (without the $)
908 * @return a variable name String
910 String VariableName():
912 final StringBuffer buff;
914 Expression expression = null;
918 <LBRACE> expression = Expression() <RBRACE>
919 {buff = new StringBuffer("{");
920 buff.append(expression.toStringExpression());
922 return buff.toString();}
924 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
926 if (expression == null) {
929 buff = new StringBuffer(token.image);
931 buff.append(expression.toStringExpression());
933 return buff.toString();
936 <DOLLAR> expr = VariableName()
938 buff = new StringBuffer("$");
940 return buff.toString();
943 token = <DOLLAR_ID> {return token.image;}
946 Expression VariableInitializer() :
948 final Expression expr;
950 final int pos = SimpleCharStream.getPosition();
956 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
957 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
959 SimpleCharStream.getPosition()),
963 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
964 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
966 SimpleCharStream.getPosition()),
970 expr = ArrayDeclarator()
974 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
977 ArrayVariableDeclaration ArrayVariable() :
979 Expression expr,expr2;
983 [<ARRAYASSIGN> expr2 = Expression()
984 {return new ArrayVariableDeclaration(expr,expr2);}
986 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
989 ArrayVariableDeclaration[] ArrayInitializer() :
991 ArrayVariableDeclaration expr;
992 final ArrayList list = new ArrayList();
995 <LPAREN> [ expr = ArrayVariable()
997 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
1001 [<COMMA> {list.add(null);}]
1004 ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
1010 * A Method Declaration.
1011 * <b>function</b> MetodDeclarator() Block()
1013 MethodDeclaration MethodDeclaration() :
1015 final MethodDeclaration functionDeclaration;
1017 final OutlineableWithChildren seg = currentSegment;
1022 functionDeclaration = MethodDeclarator()
1023 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1024 } catch (ParseException e) {
1025 if (errorMessage != null) throw e;
1026 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1028 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1029 errorEnd = SimpleCharStream.getPosition() + 1;
1032 {currentSegment = functionDeclaration;}
1034 {functionDeclaration.statements = block.statements;
1035 currentSegment = seg;
1036 return functionDeclaration;}
1040 * A MethodDeclarator.
1041 * [&] IDENTIFIER(parameters ...).
1042 * @return a function description for the outline
1044 MethodDeclaration MethodDeclarator() :
1046 final Token identifier;
1047 Token reference = null;
1048 final Hashtable formalParameters;
1049 final int pos = SimpleCharStream.getPosition();
1050 char[] identifierChar = SYNTAX_ERROR_CHAR;
1053 [reference = <BIT_AND>]
1055 identifier = <IDENTIFIER>
1056 {identifierChar = identifier.image.toCharArray();}
1057 } catch (ParseException e) {
1058 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1060 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1061 errorEnd = SimpleCharStream.getPosition() + 1;
1062 processParseException(e);
1064 formalParameters = FormalParameters()
1065 {return new MethodDeclaration(currentSegment,
1070 SimpleCharStream.getPosition());}
1074 * FormalParameters follows method identifier.
1075 * (FormalParameter())
1077 Hashtable FormalParameters() :
1079 VariableDeclaration var;
1080 final Hashtable parameters = new Hashtable();
1085 } catch (ParseException e) {
1086 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1088 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1089 errorEnd = SimpleCharStream.getPosition() + 1;
1090 processParseException(e);
1092 [ var = FormalParameter()
1093 {parameters.put(new String(var.name),var);}
1095 <COMMA> var = FormalParameter()
1096 {parameters.put(new String(var.name),var);}
1101 } catch (ParseException e) {
1102 errorMessage = "')' expected";
1104 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1105 errorEnd = SimpleCharStream.getPosition() + 1;
1106 processParseException(e);
1108 {return parameters;}
1112 * A formal parameter.
1113 * $varname[=value] (,$varname[=value])
1115 VariableDeclaration FormalParameter() :
1117 final VariableDeclaration variableDeclaration;
1121 [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
1123 if (token != null) {
1124 variableDeclaration.setReference(true);
1126 return variableDeclaration;}
1129 ConstantIdentifier Type() :
1132 <STRING> {pos = SimpleCharStream.getPosition();
1133 return new ConstantIdentifier(Types.STRING,pos,pos-6);}
1134 | <BOOL> {pos = SimpleCharStream.getPosition();
1135 return new ConstantIdentifier(Types.BOOL,pos,pos-4);}
1136 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1137 return new ConstantIdentifier(Types.BOOLEAN,pos,pos-7);}
1138 | <REAL> {pos = SimpleCharStream.getPosition();
1139 return new ConstantIdentifier(Types.REAL,pos,pos-4);}
1140 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1141 return new ConstantIdentifier(Types.DOUBLE,pos,pos-5);}
1142 | <FLOAT> {pos = SimpleCharStream.getPosition();
1143 return new ConstantIdentifier(Types.FLOAT,pos,pos-5);}
1144 | <INT> {pos = SimpleCharStream.getPosition();
1145 return new ConstantIdentifier(Types.INT,pos,pos-3);}
1146 | <INTEGER> {pos = SimpleCharStream.getPosition();
1147 return new ConstantIdentifier(Types.INTEGER,pos,pos-7);}
1148 | <OBJECT> {pos = SimpleCharStream.getPosition();
1149 return new ConstantIdentifier(Types.OBJECT,pos,pos-6);}
1152 Expression Expression() :
1154 final Expression expr;
1157 expr = PrintExpression() {return expr;}
1158 | expr = ListExpression() {return expr;}
1159 | LOOKAHEAD(varAssignation())
1160 expr = varAssignation() {return expr;}
1161 | expr = ConditionalExpression() {return expr;}
1165 * A Variable assignation.
1166 * varName (an assign operator) any expression
1168 VarAssignation varAssignation() :
1171 final Expression initializer;
1172 final int assignOperator;
1173 final int pos = SimpleCharStream.getPosition();
1176 varName = VariableDeclaratorId()
1177 assignOperator = AssignmentOperator()
1179 initializer = Expression()
1180 } catch (ParseException e) {
1181 if (errorMessage != null) {
1184 errorMessage = "expression expected";
1186 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1187 errorEnd = SimpleCharStream.getPosition() + 1;
1190 {return new VarAssignation(varName.toCharArray(),
1194 SimpleCharStream.getPosition());}
1197 int AssignmentOperator() :
1200 <ASSIGN> {return VarAssignation.EQUAL;}
1201 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1202 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1203 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1204 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1205 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1206 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1207 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1208 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1209 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1210 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1211 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1212 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1215 Expression ConditionalExpression() :
1217 final Expression expr;
1218 Expression expr2 = null;
1219 Expression expr3 = null;
1222 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1224 if (expr3 == null) {
1227 return new ConditionalExpression(expr,expr2,expr3);
1231 Expression ConditionalOrExpression() :
1233 Expression expr,expr2;
1237 expr = ConditionalAndExpression()
1240 <OR_OR> {operator = OperatorIds.OR_OR;}
1241 | <_ORL> {operator = OperatorIds.ORL;}
1242 ) expr2 = ConditionalAndExpression()
1244 expr = new BinaryExpression(expr,expr2,operator);
1250 Expression ConditionalAndExpression() :
1252 Expression expr,expr2;
1256 expr = ConcatExpression()
1258 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1259 | <_ANDL> {operator = OperatorIds.ANDL;})
1260 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1265 Expression ConcatExpression() :
1267 Expression expr,expr2;
1270 expr = InclusiveOrExpression()
1272 <DOT> expr2 = InclusiveOrExpression()
1273 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1278 Expression InclusiveOrExpression() :
1280 Expression expr,expr2;
1283 expr = ExclusiveOrExpression()
1284 (<BIT_OR> expr2 = ExclusiveOrExpression()
1285 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1290 Expression ExclusiveOrExpression() :
1292 Expression expr,expr2;
1295 expr = AndExpression()
1297 <XOR> expr2 = AndExpression()
1298 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1303 Expression AndExpression() :
1305 Expression expr,expr2;
1308 expr = EqualityExpression()
1310 <BIT_AND> expr2 = EqualityExpression()
1311 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1316 Expression EqualityExpression() :
1318 Expression expr,expr2;
1322 expr = RelationalExpression()
1324 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1325 | <DIF> {operator = OperatorIds.DIF;}
1326 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1327 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1328 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1331 expr2 = RelationalExpression()
1332 } catch (ParseException e) {
1333 if (errorMessage != null) {
1336 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1338 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1339 errorEnd = SimpleCharStream.getPosition() + 1;
1343 expr = new BinaryExpression(expr,expr2,operator);
1349 Expression RelationalExpression() :
1351 Expression expr,expr2;
1355 expr = ShiftExpression()
1357 ( <LT> {operator = OperatorIds.LESS;}
1358 | <GT> {operator = OperatorIds.GREATER;}
1359 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1360 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1361 expr2 = ShiftExpression()
1362 {expr = new BinaryExpression(expr,expr2,operator);}
1367 Expression ShiftExpression() :
1369 Expression expr,expr2;
1373 expr = AdditiveExpression()
1375 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1376 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1377 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1378 expr2 = AdditiveExpression()
1379 {expr = new BinaryExpression(expr,expr2,operator);}
1384 Expression AdditiveExpression() :
1386 Expression expr,expr2;
1390 expr = MultiplicativeExpression()
1392 ( <PLUS> {operator = OperatorIds.PLUS;}
1393 | <MINUS> {operator = OperatorIds.MINUS;} )
1394 expr2 = MultiplicativeExpression()
1395 {expr = new BinaryExpression(expr,expr2,operator);}
1400 Expression MultiplicativeExpression() :
1402 Expression expr,expr2;
1407 expr = UnaryExpression()
1408 } catch (ParseException e) {
1409 if (errorMessage != null) throw e;
1410 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1412 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1413 errorEnd = SimpleCharStream.getPosition() + 1;
1417 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1418 | <SLASH> {operator = OperatorIds.DIVIDE;}
1419 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1420 expr2 = UnaryExpression()
1421 {expr = new BinaryExpression(expr,expr2,operator);}
1427 * An unary expression starting with @, & or nothing
1429 Expression UnaryExpression() :
1432 final int pos = SimpleCharStream.getPosition();
1435 <BIT_AND> expr = UnaryExpressionNoPrefix()
1436 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1438 expr = AtUnaryExpression() {return expr;}
1441 Expression AtUnaryExpression() :
1444 final int pos = SimpleCharStream.getPosition();
1448 expr = AtUnaryExpression()
1449 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1451 expr = UnaryExpressionNoPrefix()
1456 Expression UnaryExpressionNoPrefix() :
1460 final int pos = SimpleCharStream.getPosition();
1463 ( <PLUS> {operator = OperatorIds.PLUS;}
1464 | <MINUS> {operator = OperatorIds.MINUS;})
1465 expr = UnaryExpression()
1466 {return new PrefixedUnaryExpression(expr,operator,pos);}
1468 expr = PreIncDecExpression()
1471 expr = UnaryExpressionNotPlusMinus()
1476 Expression PreIncDecExpression() :
1478 final Expression expr;
1480 final int pos = SimpleCharStream.getPosition();
1483 ( <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1484 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;})
1485 expr = PrimaryExpression()
1486 {return new PrefixedUnaryExpression(expr,operator,pos);}
1489 Expression UnaryExpressionNotPlusMinus() :
1492 final int pos = SimpleCharStream.getPosition();
1495 <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1496 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1497 expr = CastExpression() {return expr;}
1498 | expr = PostfixExpression() {return expr;}
1499 | expr = Literal() {return expr;}
1500 | <LPAREN> expr = Expression()
1503 } catch (ParseException e) {
1504 errorMessage = "')' expected";
1506 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1507 errorEnd = SimpleCharStream.getPosition() + 1;
1513 CastExpression CastExpression() :
1515 final ConstantIdentifier type;
1516 final Expression expr;
1517 final int pos = SimpleCharStream.getPosition();
1522 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1523 <RPAREN> expr = UnaryExpression()
1524 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1527 Expression PostfixExpression() :
1531 final int pos = SimpleCharStream.getPosition();
1534 expr = PrimaryExpression()
1535 [ <PLUS_PLUS> {operator = OperatorIds.PLUS_PLUS;}
1536 | <MINUS_MINUS> {operator = OperatorIds.MINUS_MINUS;}]
1538 if (operator == -1) {
1541 return new PostfixedUnaryExpression(expr,operator,pos);
1545 Expression PrimaryExpression() :
1547 final Token identifier;
1549 final int pos = SimpleCharStream.getPosition();
1553 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1554 {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
1556 SimpleCharStream.getPosition()),
1558 ClassAccess.STATIC);}
1559 (expr = PrimarySuffix(expr))*
1562 expr = PrimaryPrefix()
1563 (expr = PrimarySuffix(expr))*
1566 expr = ArrayDeclarator()
1571 * An array declarator.
1575 ArrayInitializer ArrayDeclarator() :
1577 final ArrayVariableDeclaration[] vars;
1578 final int pos = SimpleCharStream.getPosition();
1581 <ARRAY> vars = ArrayInitializer()
1582 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1585 Expression PrimaryPrefix() :
1587 final Expression expr;
1590 final int pos = SimpleCharStream.getPosition();
1593 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1595 SimpleCharStream.getPosition());}
1596 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1599 | var = VariableDeclaratorId() {return new VariableDeclaration(currentSegment,
1602 SimpleCharStream.getPosition());}
1605 PrefixedUnaryExpression classInstantiation() :
1608 final StringBuffer buff;
1609 final int pos = SimpleCharStream.getPosition();
1612 <NEW> expr = ClassIdentifier()
1614 {buff = new StringBuffer(expr.toStringExpression());}
1615 expr = PrimaryExpression()
1616 {buff.append(expr.toStringExpression());
1617 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1619 SimpleCharStream.getPosition());}
1621 {return new PrefixedUnaryExpression(expr,
1626 ConstantIdentifier ClassIdentifier():
1630 final int pos = SimpleCharStream.getPosition();
1633 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1635 SimpleCharStream.getPosition());}
1636 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1638 SimpleCharStream.getPosition());}
1641 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
1643 final AbstractSuffixExpression expr;
1646 expr = Arguments(prefix) {return expr;}
1647 | expr = VariableSuffix(prefix) {return expr;}
1650 AbstractSuffixExpression VariableSuffix(Expression prefix) :
1653 final int pos = SimpleCharStream.getPosition();
1654 Expression expression = null;
1659 expr = VariableName()
1660 } catch (ParseException e) {
1661 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1663 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1664 errorEnd = SimpleCharStream.getPosition() + 1;
1667 {return new ClassAccess(prefix,
1668 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1669 ClassAccess.NORMAL);}
1671 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1674 } catch (ParseException e) {
1675 errorMessage = "']' expected";
1677 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1678 errorEnd = SimpleCharStream.getPosition() + 1;
1681 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1690 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1691 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1692 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1693 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1694 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1695 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1696 | <TRUE> {pos = SimpleCharStream.getPosition();
1697 return new TrueLiteral(pos-4,pos);}
1698 | <FALSE> {pos = SimpleCharStream.getPosition();
1699 return new FalseLiteral(pos-4,pos);}
1700 | <NULL> {pos = SimpleCharStream.getPosition();
1701 return new NullLiteral(pos-4,pos);}
1704 FunctionCall Arguments(Expression func) :
1706 Expression[] args = null;
1709 <LPAREN> [ args = ArgumentList() ]
1712 } catch (ParseException e) {
1713 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1715 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1716 errorEnd = SimpleCharStream.getPosition() + 1;
1719 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1723 * An argument list is a list of arguments separated by comma :
1724 * argumentDeclaration() (, argumentDeclaration)*
1725 * @return an array of arguments
1727 Expression[] ArgumentList() :
1730 final ArrayList list = new ArrayList();
1739 } catch (ParseException e) {
1740 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1742 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1743 errorEnd = SimpleCharStream.getPosition() + 1;
1748 Expression[] arguments = new Expression[list.size()];
1749 list.toArray(arguments);
1754 * A Statement without break.
1756 Statement StatementNoBreak() :
1758 final Statement statement;
1763 statement = Expression()
1766 } catch (ParseException e) {
1767 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1768 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1770 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1771 errorEnd = SimpleCharStream.getPosition() + 1;
1777 statement = LabeledStatement() {return statement;}
1778 | statement = Block() {return statement;}
1779 | statement = EmptyStatement() {return statement;}
1780 | statement = StatementExpression()
1783 } catch (ParseException e) {
1784 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1786 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1787 errorEnd = SimpleCharStream.getPosition() + 1;
1791 | statement = SwitchStatement() {return statement;}
1792 | statement = IfStatement() {return statement;}
1793 | statement = WhileStatement() {return statement;}
1794 | statement = DoStatement() {return statement;}
1795 | statement = ForStatement() {return statement;}
1796 | statement = ForeachStatement() {return statement;}
1797 | statement = ContinueStatement() {return statement;}
1798 | statement = ReturnStatement() {return statement;}
1799 | statement = EchoStatement() {return statement;}
1800 | [token=<AT>] statement = IncludeStatement()
1801 {if (token != null) {
1802 ((InclusionStatement)statement).silent = true;
1805 | statement = StaticStatement() {return statement;}
1806 | statement = GlobalStatement() {return statement;}
1810 * A Normal statement.
1812 Statement Statement() :
1814 final Statement statement;
1817 statement = StatementNoBreak() {return statement;}
1818 | statement = BreakStatement() {return statement;}
1822 * An html block inside a php syntax.
1824 HTMLBlock htmlBlock() :
1826 final int startIndex = nodePtr;
1827 AstNode[] blockNodes;
1831 <PHPEND> (phpEchoBlock())*
1833 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1834 } catch (ParseException e) {
1835 errorMessage = "unexpected end of file , '<?php' expected";
1837 errorStart = SimpleCharStream.getPosition();
1838 errorEnd = SimpleCharStream.getPosition();
1842 nbNodes = nodePtr - startIndex;
1843 blockNodes = new AstNode[nbNodes];
1844 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1845 nodePtr = startIndex;
1846 return new HTMLBlock(blockNodes);}
1850 * An include statement. It's "include" an expression;
1852 InclusionStatement IncludeStatement() :
1854 final Expression expr;
1856 final int pos = SimpleCharStream.getPosition();
1857 final InclusionStatement inclusionStatement;
1860 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1861 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1862 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1863 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1866 } catch (ParseException e) {
1867 if (errorMessage != null) {
1870 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1872 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1873 errorEnd = SimpleCharStream.getPosition() + 1;
1876 {inclusionStatement = new InclusionStatement(currentSegment,
1880 currentSegment.add(inclusionStatement);
1884 } catch (ParseException e) {
1885 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1887 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1888 errorEnd = SimpleCharStream.getPosition() + 1;
1891 {return inclusionStatement;}
1894 PrintExpression PrintExpression() :
1896 final Expression expr;
1897 final int pos = SimpleCharStream.getPosition();
1900 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1903 ListExpression ListExpression() :
1906 Expression expression = null;
1907 ArrayList list = new ArrayList();
1908 final int pos = SimpleCharStream.getPosition();
1914 } catch (ParseException e) {
1915 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1917 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1918 errorEnd = SimpleCharStream.getPosition() + 1;
1922 expr = VariableDeclaratorId()
1925 {if (expr == null) list.add(null);}
1929 } catch (ParseException e) {
1930 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1932 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1933 errorEnd = SimpleCharStream.getPosition() + 1;
1936 expr = VariableDeclaratorId()
1941 } catch (ParseException e) {
1942 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1944 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1945 errorEnd = SimpleCharStream.getPosition() + 1;
1948 [ <ASSIGN> expression = Expression()
1950 String[] strings = new String[list.size()];
1951 list.toArray(strings);
1952 return new ListExpression(strings,
1955 SimpleCharStream.getPosition());}
1958 String[] strings = new String[list.size()];
1959 list.toArray(strings);
1960 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
1964 * An echo statement.
1965 * echo anyexpression (, otherexpression)*
1967 EchoStatement EchoStatement() :
1969 final ArrayList expressions = new ArrayList();
1971 final int pos = SimpleCharStream.getPosition();
1974 <ECHO> expr = Expression()
1975 {expressions.add(expr);}
1977 <COMMA> expr = Expression()
1978 {expressions.add(expr);}
1982 } catch (ParseException e) {
1983 if (e.currentToken.next.kind != 4) {
1984 errorMessage = "';' expected after 'echo' statement";
1986 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1987 errorEnd = SimpleCharStream.getPosition() + 1;
1991 {Expression[] exprs = new Expression[expressions.size()];
1992 expressions.toArray(exprs);
1993 return new EchoStatement(exprs,pos);}
1996 GlobalStatement GlobalStatement() :
1998 final int pos = SimpleCharStream.getPosition();
2000 ArrayList vars = new ArrayList();
2001 GlobalStatement global;
2005 expr = VariableDeclaratorId()
2008 expr = VariableDeclaratorId()
2014 String[] strings = new String[vars.size()];
2015 vars.toArray(strings);
2016 global = new GlobalStatement(currentSegment,
2019 SimpleCharStream.getPosition());
2020 currentSegment.add(global);
2022 } catch (ParseException e) {
2023 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2025 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2026 errorEnd = SimpleCharStream.getPosition() + 1;
2031 StaticStatement StaticStatement() :
2033 final int pos = SimpleCharStream.getPosition();
2034 final ArrayList vars = new ArrayList();
2035 VariableDeclaration expr;
2038 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2039 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2043 String[] strings = new String[vars.size()];
2044 vars.toArray(strings);
2045 return new StaticStatement(strings,
2047 SimpleCharStream.getPosition());}
2048 } catch (ParseException e) {
2049 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2051 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2052 errorEnd = SimpleCharStream.getPosition() + 1;
2057 LabeledStatement LabeledStatement() :
2059 final int pos = SimpleCharStream.getPosition();
2061 final Statement statement;
2064 label = <IDENTIFIER> <COLON> statement = Statement()
2065 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2077 final int pos = SimpleCharStream.getPosition();
2078 final ArrayList list = new ArrayList();
2079 Statement statement;
2084 } catch (ParseException e) {
2085 errorMessage = "'{' expected";
2087 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2088 errorEnd = SimpleCharStream.getPosition() + 1;
2091 ( statement = BlockStatement() {list.add(statement);}
2092 | statement = htmlBlock() {list.add(statement);})*
2095 } catch (ParseException e) {
2096 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2098 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2099 errorEnd = SimpleCharStream.getPosition() + 1;
2103 Statement[] statements = new Statement[list.size()];
2104 list.toArray(statements);
2105 return new Block(statements,pos,SimpleCharStream.getPosition());}
2108 Statement BlockStatement() :
2110 final Statement statement;
2114 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2116 } catch (ParseException e) {
2117 if (errorMessage != null) throw e;
2118 errorMessage = "statement expected";
2120 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2121 errorEnd = SimpleCharStream.getPosition() + 1;
2124 | statement = ClassDeclaration() {return statement;}
2125 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2126 currentSegment.add((MethodDeclaration) statement);
2131 * A Block statement that will not contain any 'break'
2133 Statement BlockStatementNoBreak() :
2135 final Statement statement;
2138 statement = StatementNoBreak() {return statement;}
2139 | statement = ClassDeclaration() {return statement;}
2140 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2144 VariableDeclaration[] LocalVariableDeclaration() :
2146 final ArrayList list = new ArrayList();
2147 VariableDeclaration var;
2150 var = LocalVariableDeclarator()
2152 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2154 VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2159 VariableDeclaration LocalVariableDeclarator() :
2161 final String varName;
2162 Expression initializer = null;
2163 final int pos = SimpleCharStream.getPosition();
2166 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2168 if (initializer == null) {
2169 return new VariableDeclaration(currentSegment,
2170 varName.toCharArray(),
2172 SimpleCharStream.getPosition());
2174 return new VariableDeclaration(currentSegment,
2175 varName.toCharArray(),
2181 EmptyStatement EmptyStatement() :
2187 {pos = SimpleCharStream.getPosition();
2188 return new EmptyStatement(pos-1,pos);}
2191 Expression StatementExpression() :
2193 Expression expr,expr2;
2197 expr = PreIncDecExpression() {return expr;}
2199 expr = PrimaryExpression()
2200 [ <PLUS_PLUS> {return new PostfixedUnaryExpression(expr,
2201 OperatorIds.PLUS_PLUS,
2202 SimpleCharStream.getPosition());}
2203 | <MINUS_MINUS> {return new PostfixedUnaryExpression(expr,
2204 OperatorIds.MINUS_MINUS,
2205 SimpleCharStream.getPosition());}
2206 | operator = AssignmentOperator() expr2 = Expression()
2207 {return new BinaryExpression(expr,expr2,operator);}
2212 SwitchStatement SwitchStatement() :
2214 final Expression variable;
2215 final AbstractCase[] cases;
2216 final int pos = SimpleCharStream.getPosition();
2222 } catch (ParseException e) {
2223 errorMessage = "'(' expected after 'switch'";
2225 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2226 errorEnd = SimpleCharStream.getPosition() + 1;
2230 variable = Expression()
2231 } catch (ParseException e) {
2232 if (errorMessage != null) {
2235 errorMessage = "expression expected";
2237 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2238 errorEnd = SimpleCharStream.getPosition() + 1;
2243 } catch (ParseException e) {
2244 errorMessage = "')' expected";
2246 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2247 errorEnd = SimpleCharStream.getPosition() + 1;
2250 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2251 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2254 AbstractCase[] switchStatementBrace() :
2257 final ArrayList cases = new ArrayList();
2261 ( cas = switchLabel0() {cases.add(cas);})*
2265 AbstractCase[] abcase = new AbstractCase[cases.size()];
2266 cases.toArray(abcase);
2268 } catch (ParseException e) {
2269 errorMessage = "'}' expected";
2271 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2272 errorEnd = SimpleCharStream.getPosition() + 1;
2277 * A Switch statement with : ... endswitch;
2278 * @param start the begin offset of the switch
2279 * @param end the end offset of the switch
2281 AbstractCase[] switchStatementColon(final int start, final int end) :
2284 final ArrayList cases = new ArrayList();
2289 setMarker(fileToParse,
2290 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2294 "Line " + token.beginLine);
2295 } catch (CoreException e) {
2296 PHPeclipsePlugin.log(e);
2298 ( cas = switchLabel0() {cases.add(cas);})*
2301 } catch (ParseException e) {
2302 errorMessage = "'endswitch' expected";
2304 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2305 errorEnd = SimpleCharStream.getPosition() + 1;
2311 AbstractCase[] abcase = new AbstractCase[cases.size()];
2312 cases.toArray(abcase);
2314 } catch (ParseException e) {
2315 errorMessage = "';' expected after 'endswitch' keyword";
2317 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2318 errorEnd = SimpleCharStream.getPosition() + 1;
2323 AbstractCase switchLabel0() :
2325 final Expression expr;
2326 Statement statement;
2327 final ArrayList stmts = new ArrayList();
2328 final int pos = SimpleCharStream.getPosition();
2331 expr = SwitchLabel()
2332 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2333 | statement = htmlBlock() {stmts.add(statement);})*
2334 [ statement = BreakStatement() {stmts.add(statement);}]
2336 Statement[] stmtsArray = new Statement[stmts.size()];
2337 stmts.toArray(stmtsArray);
2338 if (expr == null) {//it's a default
2339 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2341 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2346 * case Expression() :
2348 * @return the if it was a case and null if not
2350 Expression SwitchLabel() :
2352 final Expression expr;
2358 } catch (ParseException e) {
2359 if (errorMessage != null) throw e;
2360 errorMessage = "expression expected after 'case' keyword";
2362 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2363 errorEnd = SimpleCharStream.getPosition() + 1;
2369 } catch (ParseException e) {
2370 errorMessage = "':' expected after case expression";
2372 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2373 errorEnd = SimpleCharStream.getPosition() + 1;
2381 } catch (ParseException e) {
2382 errorMessage = "':' expected after 'default' keyword";
2384 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2385 errorEnd = SimpleCharStream.getPosition() + 1;
2390 Break BreakStatement() :
2392 Expression expression = null;
2393 final int start = SimpleCharStream.getPosition();
2396 <BREAK> [ expression = Expression() ]
2399 } catch (ParseException e) {
2400 errorMessage = "';' expected after 'break' keyword";
2402 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2403 errorEnd = SimpleCharStream.getPosition() + 1;
2406 {return new Break(expression, start, SimpleCharStream.getPosition());}
2409 IfStatement IfStatement() :
2411 final int pos = SimpleCharStream.getPosition();
2412 Expression condition;
2413 IfStatement ifStatement;
2416 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2417 {return ifStatement;}
2421 Expression Condition(final String keyword) :
2423 final Expression condition;
2428 } catch (ParseException e) {
2429 errorMessage = "'(' expected after " + keyword + " keyword";
2431 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2432 errorEnd = errorStart +1;
2433 processParseException(e);
2435 condition = Expression()
2438 } catch (ParseException e) {
2439 errorMessage = "')' expected after " + keyword + " keyword";
2441 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2442 errorEnd = SimpleCharStream.getPosition() + 1;
2443 processParseException(e);
2448 IfStatement IfStatement0(Expression condition, final int start,final int end) :
2450 Statement statement;
2452 final Statement[] statementsArray;
2453 ElseIf elseifStatement;
2454 Else elseStatement = null;
2456 final ArrayList elseIfList = new ArrayList();
2458 int pos = SimpleCharStream.getPosition();
2463 {stmts = new ArrayList();}
2464 ( statement = Statement() {stmts.add(statement);}
2465 | statement = htmlBlock() {stmts.add(statement);})*
2466 {endStatements = SimpleCharStream.getPosition();}
2467 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2468 [elseStatement = ElseStatementColon()]
2471 setMarker(fileToParse,
2472 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2476 "Line " + token.beginLine);
2477 } catch (CoreException e) {
2478 PHPeclipsePlugin.log(e);
2482 } catch (ParseException e) {
2483 errorMessage = "'endif' expected";
2485 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2486 errorEnd = SimpleCharStream.getPosition() + 1;
2491 } catch (ParseException e) {
2492 errorMessage = "';' expected after 'endif' keyword";
2494 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2495 errorEnd = SimpleCharStream.getPosition() + 1;
2499 elseIfs = new ElseIf[elseIfList.size()];
2500 elseIfList.toArray(elseIfs);
2501 if (stmts.size() == 1) {
2502 return new IfStatement(condition,
2503 (Statement) stmts.get(0),
2507 SimpleCharStream.getPosition());
2509 statementsArray = new Statement[stmts.size()];
2510 stmts.toArray(statementsArray);
2511 return new IfStatement(condition,
2512 new Block(statementsArray,pos,endStatements),
2516 SimpleCharStream.getPosition());
2521 (stmt = Statement() | stmt = htmlBlock())
2522 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2526 {pos = SimpleCharStream.getPosition();}
2527 statement = Statement()
2528 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2529 } catch (ParseException e) {
2530 if (errorMessage != null) {
2533 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2535 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2536 errorEnd = SimpleCharStream.getPosition() + 1;
2541 elseIfs = new ElseIf[elseIfList.size()];
2542 elseIfList.toArray(elseIfs);
2543 return new IfStatement(condition,
2548 SimpleCharStream.getPosition());}
2551 ElseIf ElseIfStatementColon() :
2553 Expression condition;
2554 Statement statement;
2555 final ArrayList list = new ArrayList();
2556 final int pos = SimpleCharStream.getPosition();
2559 <ELSEIF> condition = Condition("elseif")
2560 <COLON> ( statement = Statement() {list.add(statement);}
2561 | statement = htmlBlock() {list.add(statement);})*
2563 Statement[] stmtsArray = new Statement[list.size()];
2564 list.toArray(stmtsArray);
2565 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2568 Else ElseStatementColon() :
2570 Statement statement;
2571 final ArrayList list = new ArrayList();
2572 final int pos = SimpleCharStream.getPosition();
2575 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2576 | statement = htmlBlock() {list.add(statement);})*
2578 Statement[] stmtsArray = new Statement[list.size()];
2579 list.toArray(stmtsArray);
2580 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2583 ElseIf ElseIfStatement() :
2585 Expression condition;
2586 Statement statement;
2587 final ArrayList list = new ArrayList();
2588 final int pos = SimpleCharStream.getPosition();
2591 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2593 Statement[] stmtsArray = new Statement[list.size()];
2594 list.toArray(stmtsArray);
2595 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2598 WhileStatement WhileStatement() :
2600 final Expression condition;
2601 final Statement action;
2602 final int pos = SimpleCharStream.getPosition();
2606 condition = Condition("while")
2607 action = WhileStatement0(pos,pos + 5)
2608 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2611 Statement WhileStatement0(final int start, final int end) :
2613 Statement statement;
2614 final ArrayList stmts = new ArrayList();
2615 final int pos = SimpleCharStream.getPosition();
2618 <COLON> (statement = Statement() {stmts.add(statement);})*
2620 setMarker(fileToParse,
2621 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2625 "Line " + token.beginLine);
2626 } catch (CoreException e) {
2627 PHPeclipsePlugin.log(e);
2631 } catch (ParseException e) {
2632 errorMessage = "'endwhile' expected";
2634 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2635 errorEnd = SimpleCharStream.getPosition() + 1;
2641 Statement[] stmtsArray = new Statement[stmts.size()];
2642 stmts.toArray(stmtsArray);
2643 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2644 } catch (ParseException e) {
2645 errorMessage = "';' expected after 'endwhile' keyword";
2647 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2648 errorEnd = SimpleCharStream.getPosition() + 1;
2652 statement = Statement()
2656 DoStatement DoStatement() :
2658 final Statement action;
2659 final Expression condition;
2660 final int pos = SimpleCharStream.getPosition();
2663 <DO> action = Statement() <WHILE> condition = Condition("while")
2666 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2667 } catch (ParseException e) {
2668 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2670 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2671 errorEnd = SimpleCharStream.getPosition() + 1;
2676 ForeachStatement ForeachStatement() :
2678 Statement statement;
2679 Expression expression;
2680 final int pos = SimpleCharStream.getPosition();
2681 ArrayVariableDeclaration variable;
2687 } catch (ParseException e) {
2688 errorMessage = "'(' expected after 'foreach' keyword";
2690 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2691 errorEnd = SimpleCharStream.getPosition() + 1;
2695 expression = Expression()
2696 } catch (ParseException e) {
2697 errorMessage = "variable expected";
2699 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2700 errorEnd = SimpleCharStream.getPosition() + 1;
2705 } catch (ParseException e) {
2706 errorMessage = "'as' expected";
2708 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2709 errorEnd = SimpleCharStream.getPosition() + 1;
2713 variable = ArrayVariable()
2714 } catch (ParseException e) {
2715 errorMessage = "variable expected";
2717 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2718 errorEnd = SimpleCharStream.getPosition() + 1;
2723 } catch (ParseException e) {
2724 errorMessage = "')' expected after 'foreach' keyword";
2726 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2727 errorEnd = SimpleCharStream.getPosition() + 1;
2731 statement = Statement()
2732 } catch (ParseException e) {
2733 if (errorMessage != null) throw e;
2734 errorMessage = "statement expected";
2736 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2737 errorEnd = SimpleCharStream.getPosition() + 1;
2740 {return new ForeachStatement(expression,
2744 SimpleCharStream.getPosition());}
2748 ForStatement ForStatement() :
2751 final int pos = SimpleCharStream.getPosition();
2752 Expression[] initializations = null;
2753 Expression condition = null;
2754 Expression[] increments = null;
2756 final ArrayList list = new ArrayList();
2757 final int startBlock, endBlock;
2763 } catch (ParseException e) {
2764 errorMessage = "'(' expected after 'for' keyword";
2766 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2767 errorEnd = SimpleCharStream.getPosition() + 1;
2770 [ initializations = ForInit() ] <SEMICOLON>
2771 [ condition = Expression() ] <SEMICOLON>
2772 [ increments = StatementExpressionList() ] <RPAREN>
2774 action = Statement()
2775 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2778 {startBlock = SimpleCharStream.getPosition();}
2779 (action = Statement() {list.add(action);})*
2782 setMarker(fileToParse,
2783 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2785 pos+token.image.length(),
2787 "Line " + token.beginLine);
2788 } catch (CoreException e) {
2789 PHPeclipsePlugin.log(e);
2792 {endBlock = SimpleCharStream.getPosition();}
2795 } catch (ParseException e) {
2796 errorMessage = "'endfor' expected";
2798 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2799 errorEnd = SimpleCharStream.getPosition() + 1;
2805 Statement[] stmtsArray = new Statement[list.size()];
2806 list.toArray(stmtsArray);
2807 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2808 } catch (ParseException e) {
2809 errorMessage = "';' expected after 'endfor' keyword";
2811 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2812 errorEnd = SimpleCharStream.getPosition() + 1;
2818 Expression[] ForInit() :
2823 LOOKAHEAD(LocalVariableDeclaration())
2824 exprs = LocalVariableDeclaration()
2827 exprs = StatementExpressionList()
2831 Expression[] StatementExpressionList() :
2833 final ArrayList list = new ArrayList();
2837 expr = StatementExpression() {list.add(expr);}
2838 (<COMMA> StatementExpression() {list.add(expr);})*
2840 Expression[] exprsArray = new Expression[list.size()];
2841 list.toArray(exprsArray);
2845 Continue ContinueStatement() :
2847 Expression expr = null;
2848 final int pos = SimpleCharStream.getPosition();
2851 <CONTINUE> [ expr = Expression() ]
2854 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2855 } catch (ParseException e) {
2856 errorMessage = "';' expected after 'continue' statement";
2858 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2859 errorEnd = SimpleCharStream.getPosition() + 1;
2864 ReturnStatement ReturnStatement() :
2866 Expression expr = null;
2867 final int pos = SimpleCharStream.getPosition();
2870 <RETURN> [ expr = Expression() ]
2873 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2874 } catch (ParseException e) {
2875 errorMessage = "';' expected after 'return' statement";
2877 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2878 errorEnd = SimpleCharStream.getPosition() + 1;