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">
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 ( <INCR> {operator = OperatorIds.PLUS_PLUS;}
1484 | <DECR> {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 [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
1536 | <DECR> {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()
1570 ArrayInitializer ArrayDeclarator() :
1572 final ArrayVariableDeclaration[] vars;
1573 final int pos = SimpleCharStream.getPosition();
1576 <ARRAY> vars = ArrayInitializer()
1577 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1580 Expression PrimaryPrefix() :
1582 final Expression expr;
1585 final int pos = SimpleCharStream.getPosition();
1588 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1590 SimpleCharStream.getPosition());}
1591 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1594 | var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(),
1596 SimpleCharStream.getPosition());}
1599 PrefixedUnaryExpression classInstantiation() :
1602 final StringBuffer buff;
1603 final int pos = SimpleCharStream.getPosition();
1606 <NEW> expr = ClassIdentifier()
1608 {buff = new StringBuffer(expr.toStringExpression());}
1609 expr = PrimaryExpression()
1610 {buff.append(expr.toStringExpression());
1611 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1613 SimpleCharStream.getPosition());}
1615 {return new PrefixedUnaryExpression(expr,
1620 ConstantIdentifier ClassIdentifier():
1624 final int pos = SimpleCharStream.getPosition();
1627 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1629 SimpleCharStream.getPosition());}
1630 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1632 SimpleCharStream.getPosition());}
1635 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
1637 final AbstractSuffixExpression expr;
1640 expr = Arguments(prefix) {return expr;}
1641 | expr = VariableSuffix(prefix) {return expr;}
1644 AbstractSuffixExpression VariableSuffix(Expression prefix) :
1647 final int pos = SimpleCharStream.getPosition();
1648 Expression expression = null;
1653 expr = VariableName()
1654 } catch (ParseException e) {
1655 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1657 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1658 errorEnd = SimpleCharStream.getPosition() + 1;
1661 {return new ClassAccess(prefix,
1662 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1663 ClassAccess.NORMAL);}
1665 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1668 } catch (ParseException e) {
1669 errorMessage = "']' expected";
1671 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1672 errorEnd = SimpleCharStream.getPosition() + 1;
1675 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1684 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1685 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1686 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1687 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1688 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1689 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1690 | <TRUE> {pos = SimpleCharStream.getPosition();
1691 return new TrueLiteral(pos-4,pos);}
1692 | <FALSE> {pos = SimpleCharStream.getPosition();
1693 return new FalseLiteral(pos-4,pos);}
1694 | <NULL> {pos = SimpleCharStream.getPosition();
1695 return new NullLiteral(pos-4,pos);}
1698 FunctionCall Arguments(Expression func) :
1700 Expression[] args = null;
1703 <LPAREN> [ args = ArgumentList() ]
1706 } catch (ParseException e) {
1707 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1709 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1710 errorEnd = SimpleCharStream.getPosition() + 1;
1713 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1717 * An argument list is a list of arguments separated by comma :
1718 * argumentDeclaration() (, argumentDeclaration)*
1719 * @return an array of arguments
1721 Expression[] ArgumentList() :
1724 final ArrayList list = new ArrayList();
1733 } catch (ParseException e) {
1734 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1736 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1737 errorEnd = SimpleCharStream.getPosition() + 1;
1742 Expression[] arguments = new Expression[list.size()];
1743 list.toArray(arguments);
1748 * A Statement without break.
1750 Statement StatementNoBreak() :
1752 final Statement statement;
1757 statement = Expression()
1760 } catch (ParseException e) {
1761 if (e.currentToken.next.kind != PHPParserConstants.PHPEND) {
1762 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1764 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1765 errorEnd = SimpleCharStream.getPosition() + 1;
1771 statement = LabeledStatement() {return statement;}
1772 | statement = Block() {return statement;}
1773 | statement = EmptyStatement() {return statement;}
1774 | statement = StatementExpression()
1777 } catch (ParseException e) {
1778 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1780 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1781 errorEnd = SimpleCharStream.getPosition() + 1;
1785 | statement = SwitchStatement() {return statement;}
1786 | statement = IfStatement() {return statement;}
1787 | statement = WhileStatement() {return statement;}
1788 | statement = DoStatement() {return statement;}
1789 | statement = ForStatement() {return statement;}
1790 | statement = ForeachStatement() {return statement;}
1791 | statement = ContinueStatement() {return statement;}
1792 | statement = ReturnStatement() {return statement;}
1793 | statement = EchoStatement() {return statement;}
1794 | [token=<AT>] statement = IncludeStatement()
1795 {if (token != null) {
1796 ((InclusionStatement)statement).silent = true;
1799 | statement = StaticStatement() {return statement;}
1800 | statement = GlobalStatement() {return statement;}
1804 * A Normal statement.
1806 Statement Statement() :
1808 final Statement statement;
1811 statement = StatementNoBreak() {return statement;}
1812 | statement = BreakStatement() {return statement;}
1816 * An html block inside a php syntax.
1818 HTMLBlock htmlBlock() :
1820 final int startIndex = nodePtr;
1821 AstNode[] blockNodes;
1825 <PHPEND> (phpEchoBlock())*
1827 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1828 } catch (ParseException e) {
1829 errorMessage = "unexpected end of file , '<?php' expected";
1831 errorStart = SimpleCharStream.getPosition();
1832 errorEnd = SimpleCharStream.getPosition();
1836 nbNodes = nodePtr - startIndex;
1837 blockNodes = new AstNode[nbNodes];
1838 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1839 nodePtr = startIndex;
1840 return new HTMLBlock(blockNodes);}
1844 * An include statement. It's "include" an expression;
1846 InclusionStatement IncludeStatement() :
1848 final Expression expr;
1850 final int pos = SimpleCharStream.getPosition();
1851 final InclusionStatement inclusionStatement;
1854 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1855 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1856 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1857 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1860 } catch (ParseException e) {
1861 if (errorMessage != null) {
1864 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1866 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1867 errorEnd = SimpleCharStream.getPosition() + 1;
1870 {inclusionStatement = new InclusionStatement(currentSegment,
1874 currentSegment.add(inclusionStatement);
1878 } catch (ParseException e) {
1879 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1881 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1882 errorEnd = SimpleCharStream.getPosition() + 1;
1885 {return inclusionStatement;}
1888 PrintExpression PrintExpression() :
1890 final Expression expr;
1891 final int pos = SimpleCharStream.getPosition();
1894 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1897 ListExpression ListExpression() :
1900 Expression expression = null;
1901 ArrayList list = new ArrayList();
1902 final int pos = SimpleCharStream.getPosition();
1908 } catch (ParseException e) {
1909 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1911 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1912 errorEnd = SimpleCharStream.getPosition() + 1;
1916 expr = VariableDeclaratorId()
1919 {if (expr == null) list.add(null);}
1923 } catch (ParseException e) {
1924 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1926 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1927 errorEnd = SimpleCharStream.getPosition() + 1;
1930 expr = VariableDeclaratorId()
1935 } catch (ParseException e) {
1936 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1938 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1939 errorEnd = SimpleCharStream.getPosition() + 1;
1942 [ <ASSIGN> expression = Expression()
1944 String[] strings = new String[list.size()];
1945 list.toArray(strings);
1946 return new ListExpression(strings,
1949 SimpleCharStream.getPosition());}
1952 String[] strings = new String[list.size()];
1953 list.toArray(strings);
1954 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
1958 * An echo statement.
1959 * echo anyexpression (, otherexpression)*
1961 EchoStatement EchoStatement() :
1963 final ArrayList expressions = new ArrayList();
1965 final int pos = SimpleCharStream.getPosition();
1968 <ECHO> expr = Expression()
1969 {expressions.add(expr);}
1971 <COMMA> expr = Expression()
1972 {expressions.add(expr);}
1976 } catch (ParseException e) {
1977 if (e.currentToken.next.kind != 4) {
1978 errorMessage = "';' expected after 'echo' statement";
1980 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
1981 errorEnd = SimpleCharStream.getPosition() + 1;
1985 {Expression[] exprs = new Expression[expressions.size()];
1986 expressions.toArray(exprs);
1987 return new EchoStatement(exprs,pos);}
1990 GlobalStatement GlobalStatement() :
1992 final int pos = SimpleCharStream.getPosition();
1994 ArrayList vars = new ArrayList();
1995 GlobalStatement global;
1999 expr = VariableDeclaratorId()
2002 expr = VariableDeclaratorId()
2008 String[] strings = new String[vars.size()];
2009 vars.toArray(strings);
2010 global = new GlobalStatement(currentSegment,
2013 SimpleCharStream.getPosition());
2014 currentSegment.add(global);
2016 } catch (ParseException e) {
2017 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2019 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2020 errorEnd = SimpleCharStream.getPosition() + 1;
2025 StaticStatement StaticStatement() :
2027 final int pos = SimpleCharStream.getPosition();
2028 final ArrayList vars = new ArrayList();
2029 VariableDeclaration expr;
2032 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2033 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2037 String[] strings = new String[vars.size()];
2038 vars.toArray(strings);
2039 return new StaticStatement(strings,
2041 SimpleCharStream.getPosition());}
2042 } catch (ParseException e) {
2043 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2045 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2046 errorEnd = SimpleCharStream.getPosition() + 1;
2051 LabeledStatement LabeledStatement() :
2053 final int pos = SimpleCharStream.getPosition();
2055 final Statement statement;
2058 label = <IDENTIFIER> <COLON> statement = Statement()
2059 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2071 final int pos = SimpleCharStream.getPosition();
2072 final ArrayList list = new ArrayList();
2073 Statement statement;
2078 } catch (ParseException e) {
2079 errorMessage = "'{' expected";
2081 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2082 errorEnd = SimpleCharStream.getPosition() + 1;
2085 ( statement = BlockStatement() {list.add(statement);}
2086 | statement = htmlBlock() {list.add(statement);})*
2089 } catch (ParseException e) {
2090 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2092 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2093 errorEnd = SimpleCharStream.getPosition() + 1;
2097 Statement[] statements = new Statement[list.size()];
2098 list.toArray(statements);
2099 return new Block(statements,pos,SimpleCharStream.getPosition());}
2102 Statement BlockStatement() :
2104 final Statement statement;
2108 statement = Statement() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2110 } catch (ParseException e) {
2111 if (errorMessage != null) throw e;
2112 errorMessage = "statement expected";
2114 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2115 errorEnd = SimpleCharStream.getPosition() + 1;
2118 | statement = ClassDeclaration() {return statement;}
2119 | statement = MethodDeclaration() {if (phpDocument == currentSegment) pushOnAstNodes(statement);
2120 currentSegment.add((MethodDeclaration) statement);
2125 * A Block statement that will not contain any 'break'
2127 Statement BlockStatementNoBreak() :
2129 final Statement statement;
2132 statement = StatementNoBreak() {return statement;}
2133 | statement = ClassDeclaration() {return statement;}
2134 | statement = MethodDeclaration() {currentSegment.add((MethodDeclaration) statement);
2138 VariableDeclaration[] LocalVariableDeclaration() :
2140 final ArrayList list = new ArrayList();
2141 VariableDeclaration var;
2144 var = LocalVariableDeclarator()
2146 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2148 VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2153 VariableDeclaration LocalVariableDeclarator() :
2155 final String varName;
2156 Expression initializer = null;
2157 final int pos = SimpleCharStream.getPosition();
2160 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2162 if (initializer == null) {
2163 return new VariableDeclaration(currentSegment,
2164 varName.toCharArray(),
2166 SimpleCharStream.getPosition());
2168 return new VariableDeclaration(currentSegment,
2169 varName.toCharArray(),
2175 EmptyStatement EmptyStatement() :
2181 {pos = SimpleCharStream.getPosition();
2182 return new EmptyStatement(pos-1,pos);}
2185 Statement StatementExpression() :
2187 Expression expr,expr2;
2191 expr = PreIncDecExpression() {return expr;}
2193 expr = PrimaryExpression()
2194 [ <INCR> {return new PostfixedUnaryExpression(expr,
2195 OperatorIds.PLUS_PLUS,
2196 SimpleCharStream.getPosition());}
2197 | <DECR> {return new PostfixedUnaryExpression(expr,
2198 OperatorIds.MINUS_MINUS,
2199 SimpleCharStream.getPosition());}
2200 | operator = AssignmentOperator() expr2 = Expression()
2201 {return new BinaryExpression(expr,expr2,operator);}
2206 SwitchStatement SwitchStatement() :
2208 final Expression variable;
2209 final AbstractCase[] cases;
2210 final int pos = SimpleCharStream.getPosition();
2216 } catch (ParseException e) {
2217 errorMessage = "'(' expected after 'switch'";
2219 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2220 errorEnd = SimpleCharStream.getPosition() + 1;
2224 variable = Expression()
2225 } catch (ParseException e) {
2226 if (errorMessage != null) {
2229 errorMessage = "expression expected";
2231 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2232 errorEnd = SimpleCharStream.getPosition() + 1;
2237 } catch (ParseException e) {
2238 errorMessage = "')' expected";
2240 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2241 errorEnd = SimpleCharStream.getPosition() + 1;
2244 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2245 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2248 AbstractCase[] switchStatementBrace() :
2251 final ArrayList cases = new ArrayList();
2255 ( cas = switchLabel0() {cases.add(cas);})*
2259 AbstractCase[] abcase = new AbstractCase[cases.size()];
2260 cases.toArray(abcase);
2262 } catch (ParseException e) {
2263 errorMessage = "'}' expected";
2265 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2266 errorEnd = SimpleCharStream.getPosition() + 1;
2271 * A Switch statement with : ... endswitch;
2272 * @param start the begin offset of the switch
2273 * @param end the end offset of the switch
2275 AbstractCase[] switchStatementColon(final int start, final int end) :
2278 final ArrayList cases = new ArrayList();
2283 setMarker(fileToParse,
2284 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2288 "Line " + token.beginLine);
2289 } catch (CoreException e) {
2290 PHPeclipsePlugin.log(e);
2292 ( cas = switchLabel0() {cases.add(cas);})*
2295 } catch (ParseException e) {
2296 errorMessage = "'endswitch' expected";
2298 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2299 errorEnd = SimpleCharStream.getPosition() + 1;
2305 AbstractCase[] abcase = new AbstractCase[cases.size()];
2306 cases.toArray(abcase);
2308 } catch (ParseException e) {
2309 errorMessage = "';' expected after 'endswitch' keyword";
2311 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2312 errorEnd = SimpleCharStream.getPosition() + 1;
2317 AbstractCase switchLabel0() :
2319 final Expression expr;
2320 Statement statement;
2321 final ArrayList stmts = new ArrayList();
2322 final int pos = SimpleCharStream.getPosition();
2325 expr = SwitchLabel()
2326 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2327 | statement = htmlBlock() {stmts.add(statement);})*
2328 [ statement = BreakStatement() {stmts.add(statement);}]
2330 Statement[] stmtsArray = new Statement[stmts.size()];
2331 stmts.toArray(stmtsArray);
2332 if (expr == null) {//it's a default
2333 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2335 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2340 * case Expression() :
2342 * @return the if it was a case and null if not
2344 Expression SwitchLabel() :
2346 final Expression expr;
2352 } catch (ParseException e) {
2353 if (errorMessage != null) throw e;
2354 errorMessage = "expression expected after 'case' keyword";
2356 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2357 errorEnd = SimpleCharStream.getPosition() + 1;
2363 } catch (ParseException e) {
2364 errorMessage = "':' expected after case expression";
2366 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2367 errorEnd = SimpleCharStream.getPosition() + 1;
2375 } catch (ParseException e) {
2376 errorMessage = "':' expected after 'default' keyword";
2378 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2379 errorEnd = SimpleCharStream.getPosition() + 1;
2384 Break BreakStatement() :
2386 Expression expression = null;
2387 final int start = SimpleCharStream.getPosition();
2390 <BREAK> [ expression = Expression() ]
2393 } catch (ParseException e) {
2394 errorMessage = "';' expected after 'break' keyword";
2396 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2397 errorEnd = SimpleCharStream.getPosition() + 1;
2400 {return new Break(expression, start, SimpleCharStream.getPosition());}
2403 IfStatement IfStatement() :
2405 final int pos = SimpleCharStream.getPosition();
2406 Expression condition;
2407 IfStatement ifStatement;
2410 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2411 {return ifStatement;}
2415 Expression Condition(final String keyword) :
2417 final Expression condition;
2422 } catch (ParseException e) {
2423 errorMessage = "'(' expected after " + keyword + " keyword";
2425 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length();
2426 errorEnd = errorStart +1;
2427 processParseException(e);
2429 condition = Expression()
2432 } catch (ParseException e) {
2433 errorMessage = "')' expected after " + keyword + " keyword";
2435 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2436 errorEnd = SimpleCharStream.getPosition() + 1;
2437 processParseException(e);
2442 IfStatement IfStatement0(Expression condition, final int start,final int end) :
2444 Statement statement;
2446 final Statement[] statementsArray;
2447 ElseIf elseifStatement;
2448 Else elseStatement = null;
2450 final ArrayList elseIfList = new ArrayList();
2452 int pos = SimpleCharStream.getPosition();
2457 {stmts = new ArrayList();}
2458 ( statement = Statement() {stmts.add(statement);}
2459 | statement = htmlBlock() {stmts.add(statement);})*
2460 {endStatements = SimpleCharStream.getPosition();}
2461 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2462 [elseStatement = ElseStatementColon()]
2465 setMarker(fileToParse,
2466 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2470 "Line " + token.beginLine);
2471 } catch (CoreException e) {
2472 PHPeclipsePlugin.log(e);
2476 } catch (ParseException e) {
2477 errorMessage = "'endif' expected";
2479 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2480 errorEnd = SimpleCharStream.getPosition() + 1;
2485 } catch (ParseException e) {
2486 errorMessage = "';' expected after 'endif' keyword";
2488 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2489 errorEnd = SimpleCharStream.getPosition() + 1;
2493 elseIfs = new ElseIf[elseIfList.size()];
2494 elseIfList.toArray(elseIfs);
2495 if (stmts.size() == 1) {
2496 return new IfStatement(condition,
2497 (Statement) stmts.get(0),
2501 SimpleCharStream.getPosition());
2503 statementsArray = new Statement[stmts.size()];
2504 stmts.toArray(statementsArray);
2505 return new IfStatement(condition,
2506 new Block(statementsArray,pos,endStatements),
2510 SimpleCharStream.getPosition());
2515 (stmt = Statement() | stmt = htmlBlock())
2516 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2520 {pos = SimpleCharStream.getPosition();}
2521 statement = Statement()
2522 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2523 } catch (ParseException e) {
2524 if (errorMessage != null) {
2527 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2529 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2530 errorEnd = SimpleCharStream.getPosition() + 1;
2535 elseIfs = new ElseIf[elseIfList.size()];
2536 elseIfList.toArray(elseIfs);
2537 return new IfStatement(condition,
2542 SimpleCharStream.getPosition());}
2545 ElseIf ElseIfStatementColon() :
2547 Expression condition;
2548 Statement statement;
2549 final ArrayList list = new ArrayList();
2550 final int pos = SimpleCharStream.getPosition();
2553 <ELSEIF> condition = Condition("elseif")
2554 <COLON> ( statement = Statement() {list.add(statement);}
2555 | statement = htmlBlock() {list.add(statement);})*
2557 Statement[] stmtsArray = new Statement[list.size()];
2558 list.toArray(stmtsArray);
2559 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2562 Else ElseStatementColon() :
2564 Statement statement;
2565 final ArrayList list = new ArrayList();
2566 final int pos = SimpleCharStream.getPosition();
2569 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2570 | statement = htmlBlock() {list.add(statement);})*
2572 Statement[] stmtsArray = new Statement[list.size()];
2573 list.toArray(stmtsArray);
2574 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2577 ElseIf ElseIfStatement() :
2579 Expression condition;
2580 Statement statement;
2581 final ArrayList list = new ArrayList();
2582 final int pos = SimpleCharStream.getPosition();
2585 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2587 Statement[] stmtsArray = new Statement[list.size()];
2588 list.toArray(stmtsArray);
2589 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2592 WhileStatement WhileStatement() :
2594 final Expression condition;
2595 final Statement action;
2596 final int pos = SimpleCharStream.getPosition();
2600 condition = Condition("while")
2601 action = WhileStatement0(pos,pos + 5)
2602 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2605 Statement WhileStatement0(final int start, final int end) :
2607 Statement statement;
2608 final ArrayList stmts = new ArrayList();
2609 final int pos = SimpleCharStream.getPosition();
2612 <COLON> (statement = Statement() {stmts.add(statement);})*
2614 setMarker(fileToParse,
2615 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2619 "Line " + token.beginLine);
2620 } catch (CoreException e) {
2621 PHPeclipsePlugin.log(e);
2625 } catch (ParseException e) {
2626 errorMessage = "'endwhile' expected";
2628 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2629 errorEnd = SimpleCharStream.getPosition() + 1;
2635 Statement[] stmtsArray = new Statement[stmts.size()];
2636 stmts.toArray(stmtsArray);
2637 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2638 } catch (ParseException e) {
2639 errorMessage = "';' expected after 'endwhile' keyword";
2641 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2642 errorEnd = SimpleCharStream.getPosition() + 1;
2646 statement = Statement()
2650 DoStatement DoStatement() :
2652 final Statement action;
2653 final Expression condition;
2654 final int pos = SimpleCharStream.getPosition();
2657 <DO> action = Statement() <WHILE> condition = Condition("while")
2660 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2661 } catch (ParseException e) {
2662 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2664 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2665 errorEnd = SimpleCharStream.getPosition() + 1;
2670 ForeachStatement ForeachStatement() :
2672 Statement statement;
2673 Expression expression;
2674 final int pos = SimpleCharStream.getPosition();
2675 ArrayVariableDeclaration variable;
2681 } catch (ParseException e) {
2682 errorMessage = "'(' expected after 'foreach' keyword";
2684 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2685 errorEnd = SimpleCharStream.getPosition() + 1;
2689 expression = Expression()
2690 } catch (ParseException e) {
2691 errorMessage = "variable expected";
2693 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2694 errorEnd = SimpleCharStream.getPosition() + 1;
2699 } catch (ParseException e) {
2700 errorMessage = "'as' expected";
2702 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2703 errorEnd = SimpleCharStream.getPosition() + 1;
2707 variable = ArrayVariable()
2708 } catch (ParseException e) {
2709 errorMessage = "variable expected";
2711 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2712 errorEnd = SimpleCharStream.getPosition() + 1;
2717 } catch (ParseException e) {
2718 errorMessage = "')' expected after 'foreach' keyword";
2720 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2721 errorEnd = SimpleCharStream.getPosition() + 1;
2725 statement = Statement()
2726 } catch (ParseException e) {
2727 if (errorMessage != null) throw e;
2728 errorMessage = "statement expected";
2730 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2731 errorEnd = SimpleCharStream.getPosition() + 1;
2734 {return new ForeachStatement(expression,
2738 SimpleCharStream.getPosition());}
2742 ForStatement ForStatement() :
2745 final int pos = SimpleCharStream.getPosition();
2746 Statement[] initializations = null;
2747 Expression condition = null;
2748 Statement[] increments = null;
2750 final ArrayList list = new ArrayList();
2751 final int startBlock, endBlock;
2757 } catch (ParseException e) {
2758 errorMessage = "'(' expected after 'for' keyword";
2760 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2761 errorEnd = SimpleCharStream.getPosition() + 1;
2764 [ initializations = ForInit() ] <SEMICOLON>
2765 [ condition = Expression() ] <SEMICOLON>
2766 [ increments = StatementExpressionList() ] <RPAREN>
2768 action = Statement()
2769 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2772 {startBlock = SimpleCharStream.getPosition();}
2773 (action = Statement() {list.add(action);})*
2776 setMarker(fileToParse,
2777 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2779 pos+token.image.length(),
2781 "Line " + token.beginLine);
2782 } catch (CoreException e) {
2783 PHPeclipsePlugin.log(e);
2786 {endBlock = SimpleCharStream.getPosition();}
2789 } catch (ParseException e) {
2790 errorMessage = "'endfor' expected";
2792 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2793 errorEnd = SimpleCharStream.getPosition() + 1;
2799 Statement[] stmtsArray = new Statement[list.size()];
2800 list.toArray(stmtsArray);
2801 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2802 } catch (ParseException e) {
2803 errorMessage = "';' expected after 'endfor' keyword";
2805 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2806 errorEnd = SimpleCharStream.getPosition() + 1;
2812 Statement[] ForInit() :
2814 Statement[] statements;
2817 LOOKAHEAD(LocalVariableDeclaration())
2818 statements = LocalVariableDeclaration()
2819 {return statements;}
2821 statements = StatementExpressionList()
2822 {return statements;}
2825 Statement[] StatementExpressionList() :
2827 final ArrayList list = new ArrayList();
2831 expr = StatementExpression() {list.add(expr);}
2832 (<COMMA> StatementExpression() {list.add(expr);})*
2834 Statement[] stmtsArray = new Statement[list.size()];
2835 list.toArray(stmtsArray);
2839 Continue ContinueStatement() :
2841 Expression expr = null;
2842 final int pos = SimpleCharStream.getPosition();
2845 <CONTINUE> [ expr = Expression() ]
2848 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2849 } catch (ParseException e) {
2850 errorMessage = "';' expected after 'continue' statement";
2852 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2853 errorEnd = SimpleCharStream.getPosition() + 1;
2858 ReturnStatement ReturnStatement() :
2860 Expression expr = null;
2861 final int pos = SimpleCharStream.getPosition();
2864 <RETURN> [ expr = Expression() ]
2867 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2868 } catch (ParseException e) {
2869 errorMessage = "';' expected after 'return' statement";
2871 errorStart = SimpleCharStream.getPosition() - e.currentToken.next.image.length() + 1;
2872 errorEnd = SimpleCharStream.getPosition() + 1;