3 CHOICE_AMBIGUITY_CHECK = 2;
4 OTHER_AMBIGUITY_CHECK = 1;
7 DEBUG_LOOKAHEAD = false;
8 DEBUG_TOKEN_MANAGER = false;
9 OPTIMIZE_TOKEN_MANAGER = false;
10 ERROR_REPORTING = true;
11 JAVA_UNICODE_ESCAPE = false;
12 UNICODE_INPUT = false;
14 USER_TOKEN_MANAGER = false;
15 USER_CHAR_STREAM = false;
17 BUILD_TOKEN_MANAGER = true;
19 FORCE_LA_CHECK = false;
22 PARSER_BEGIN(PHPParser)
25 import org.eclipse.core.resources.IFile;
26 import org.eclipse.core.resources.IMarker;
27 import org.eclipse.core.runtime.CoreException;
28 import org.eclipse.ui.texteditor.MarkerUtilities;
29 import org.eclipse.jface.preference.IPreferenceStore;
31 import java.util.Hashtable;
32 import java.util.Enumeration;
33 import java.util.ArrayList;
34 import java.io.StringReader;
36 import java.text.MessageFormat;
38 import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
39 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
40 import net.sourceforge.phpdt.internal.compiler.ast.*;
41 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
42 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
46 * This php parser is inspired by the Java 1.2 grammar example
47 * given with JavaCC. You can get JavaCC at http://www.webgain.com
48 * You can test the parser with the PHPParserTestCase2.java
49 * @author Matthieu Casanova
51 public final class PHPParser extends PHPParserSuperclass {
53 /** The file that is parsed. */
54 private static IFile fileToParse;
56 /** The current segment. */
57 private static OutlineableWithChildren currentSegment;
59 private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
60 private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
61 static PHPOutlineInfo outlineInfo;
63 public static MethodDeclaration currentFunction;
64 private static boolean assigning;
66 /** The error level of the current ParseException. */
67 private static int errorLevel = ERROR;
68 /** The message of the current ParseException. If it's null it's because the parse exception wasn't handled */
69 private static String errorMessage;
71 private static int errorStart = -1;
72 private static int errorEnd = -1;
73 private static PHPDocument phpDocument;
75 * The point where html starts.
76 * It will be used by the token manager to create HTMLCode objects
78 public static int htmlStart;
81 private final static int AstStackIncrement = 100;
82 /** The stack of node. */
83 private static AstNode[] nodes;
84 /** The cursor in expression stack. */
85 private static int nodePtr;
87 public final void setFileToParse(final IFile fileToParse) {
88 this.fileToParse = fileToParse;
94 public PHPParser(final IFile fileToParse) {
95 this(new StringReader(""));
96 this.fileToParse = fileToParse;
100 * Reinitialize the parser.
102 private static final void init() {
103 nodes = new AstNode[AstStackIncrement];
109 * Add an php node on the stack.
110 * @param node the node that will be added to the stack
112 private static final void pushOnAstNodes(AstNode node) {
114 nodes[++nodePtr] = node;
115 } catch (IndexOutOfBoundsException e) {
116 int oldStackLength = nodes.length;
117 AstNode[] oldStack = nodes;
118 nodes = new AstNode[oldStackLength + AstStackIncrement];
119 System.arraycopy(oldStack, 0, nodes, 0, oldStackLength);
120 nodePtr = oldStackLength;
121 nodes[nodePtr] = node;
125 public static final void phpParserTester(final String strEval) throws CoreException, ParseException {
126 PHPParserTokenManager.SwitchTo(PHPParserTokenManager.PHPPARSING);
127 final StringReader stream = new StringReader(strEval);
128 if (jj_input_stream == null) {
129 jj_input_stream = new SimpleCharStream(stream, 1, 1);
131 ReInit(new StringReader(strEval));
136 public static final void htmlParserTester(final File fileName) throws CoreException, ParseException {
138 final Reader stream = new FileReader(fileName);
139 if (jj_input_stream == null) {
140 jj_input_stream = new SimpleCharStream(stream, 1, 1);
145 } catch (FileNotFoundException e) {
146 e.printStackTrace(); //To change body of catch statement use Options | File Templates.
150 public static final void htmlParserTester(final String strEval) throws CoreException, ParseException {
151 final StringReader stream = new StringReader(strEval);
152 if (jj_input_stream == null) {
153 jj_input_stream = new SimpleCharStream(stream, 1, 1);
160 public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
161 currentSegment = new PHPDocument(parent);
162 outlineInfo = new PHPOutlineInfo(parent);
163 final StringReader stream = new StringReader(s);
164 if (jj_input_stream == null) {
165 jj_input_stream = new SimpleCharStream(stream, 1, 1);
171 phpDocument = new PHPDocument(null);
172 phpDocument.nodes = nodes;
173 PHPeclipsePlugin.log(1,phpDocument.toString());
174 } catch (ParseException e) {
175 processParseException(e);
181 * This method will process the parse exception.
182 * If the error message is null, the parse exception wasn't catched and a trace is written in the log
183 * @param e the ParseException
185 private static void processParseException(final ParseException e) {
186 if (errorMessage == null) {
187 PHPeclipsePlugin.log(e);
188 errorMessage = "this exception wasn't handled by the parser please tell us how to reproduce it";
189 errorStart = jj_input_stream.getPosition();
190 errorEnd = errorStart + 1;
197 * Create marker for the parse error
198 * @param e the ParseException
200 private static void setMarker(final ParseException e) {
202 if (errorStart == -1) {
203 setMarker(fileToParse,
205 jj_input_stream.tokenBegin,
206 jj_input_stream.tokenBegin + e.currentToken.image.length(),
208 "Line " + e.currentToken.beginLine);
210 setMarker(fileToParse,
215 "Line " + e.currentToken.beginLine);
219 } catch (CoreException e2) {
220 PHPeclipsePlugin.log(e2);
225 * Create markers according to the external parser output
227 private static void createMarkers(final String output, final IFile file) throws CoreException {
228 // delete all markers
229 file.deleteMarkers(IMarker.PROBLEM, false, 0);
234 while ((brIndx = output.indexOf("<br />", indx)) != -1) {
235 // newer php error output (tested with 4.2.3)
236 scanLine(output, file, indx, brIndx);
241 while ((brIndx = output.indexOf("<br>", indx)) != -1) {
242 // older php error output (tested with 4.2.3)
243 scanLine(output, file, indx, brIndx);
249 private static void scanLine(final String output,
252 final int brIndx) throws CoreException {
254 StringBuffer lineNumberBuffer = new StringBuffer(10);
256 current = output.substring(indx, brIndx);
258 if (current.indexOf(PARSE_WARNING_STRING) != -1 || current.indexOf(PARSE_ERROR_STRING) != -1) {
259 int onLine = current.indexOf("on line <b>");
261 lineNumberBuffer.delete(0, lineNumberBuffer.length());
262 for (int i = onLine; i < current.length(); i++) {
263 ch = current.charAt(i);
264 if ('0' <= ch && '9' >= ch) {
265 lineNumberBuffer.append(ch);
269 int lineNumber = Integer.parseInt(lineNumberBuffer.toString());
271 Hashtable attributes = new Hashtable();
273 current = current.replaceAll("\n", "");
274 current = current.replaceAll("<b>", "");
275 current = current.replaceAll("</b>", "");
276 MarkerUtilities.setMessage(attributes, current);
278 if (current.indexOf(PARSE_ERROR_STRING) != -1)
279 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
280 else if (current.indexOf(PARSE_WARNING_STRING) != -1)
281 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
283 attributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
284 MarkerUtilities.setLineNumber(attributes, lineNumber);
285 MarkerUtilities.createMarker(file, attributes, IMarker.PROBLEM);
290 public final void parse(final String s) throws CoreException {
291 final StringReader stream = new StringReader(s);
292 if (jj_input_stream == null) {
293 jj_input_stream = new SimpleCharStream(stream, 1, 1);
299 } catch (ParseException e) {
300 processParseException(e);
305 * Call the php parse command ( php -l -f <filename> )
306 * and create markers according to the external parser output
308 public static void phpExternalParse(final IFile file) {
309 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
310 final String filename = file.getLocation().toString();
312 final String[] arguments = { filename };
313 final MessageFormat form = new MessageFormat(store.getString(PHPeclipsePlugin.EXTERNAL_PARSER_PREF));
314 final String command = form.format(arguments);
316 final String parserResult = PHPStartApacheAction.getParserOutput(command, "External parser: ");
319 // parse the buffer to find the errors and warnings
320 createMarkers(parserResult, file);
321 } catch (CoreException e) {
322 PHPeclipsePlugin.log(e);
327 * Put a new html block in the stack.
329 public static final void createNewHTMLCode() {
330 final int currentPosition = SimpleCharStream.getPosition();
331 if (currentPosition == htmlStart) {
334 final char[] chars = SimpleCharStream.currentBuffer.substring(htmlStart,currentPosition).toCharArray();
335 pushOnAstNodes(new HTMLCode(chars, htmlStart,currentPosition));
338 private static final void parse() throws ParseException {
343 PARSER_END(PHPParser)
347 <PHPSTARTSHORT : "<?"> {PHPParser.createNewHTMLCode();} : PHPPARSING
348 | <PHPSTARTLONG : "<?php"> {PHPParser.createNewHTMLCode();} : PHPPARSING
349 | <PHPECHOSTART : "<?="> {PHPParser.createNewHTMLCode();} : PHPPARSING
354 <PHPEND :"?>"> {PHPParser.htmlStart = SimpleCharStream.getPosition();} : DEFAULT
357 /* Skip any character if we are not in php mode */
375 <PHPPARSING> SPECIAL_TOKEN :
377 "//" : IN_SINGLE_LINE_COMMENT
379 "#" : IN_SINGLE_LINE_COMMENT
381 <"/**" ~["/"]> { input_stream.backup(1); } : IN_FORMAL_COMMENT
383 "/*" : IN_MULTI_LINE_COMMENT
386 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
388 <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : PHPPARSING
391 <IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
393 <SINGLE_LINE_COMMENT_PHPEND : "?>" > : DEFAULT
399 <FORMAL_COMMENT: "*/" > : PHPPARSING
402 <IN_MULTI_LINE_COMMENT>
405 <MULTI_LINE_COMMENT: "*/" > : PHPPARSING
408 <IN_SINGLE_LINE_COMMENT,IN_FORMAL_COMMENT,IN_MULTI_LINE_COMMENT>
418 | <FUNCTION : "function">
421 | <ELSEIF : "elseif">
428 /* LANGUAGE CONSTRUCT */
433 | <INCLUDE : "include">
434 | <REQUIRE : "require">
435 | <INCLUDE_ONCE : "include_once">
436 | <REQUIRE_ONCE : "require_once">
437 | <GLOBAL : "global">
438 | <STATIC : "static">
439 | <CLASSACCESS : "->">
440 | <STATICCLASSACCESS : "::">
441 | <ARRAYASSIGN : "=>">
444 /* RESERVED WORDS AND LITERALS */
450 | <CONTINUE : "continue">
451 | <_DEFAULT : "default">
453 | <EXTENDS : "extends">
458 | <RETURN : "return">
460 | <SWITCH : "switch">
465 | <ENDWHILE : "endwhile">
466 | <ENDSWITCH: "endswitch">
468 | <ENDFOR : "endfor">
469 | <FOREACH : "foreach">
477 | <OBJECT : "object">
479 | <BOOLEAN : "boolean">
481 | <DOUBLE : "double">
484 | <INTEGER : "integer">
514 | <RSIGNEDSHIFT : ">>">
515 | <RUNSIGNEDSHIFT : ">>>">
524 <DECIMAL_LITERAL> (["l","L"])?
525 | <HEX_LITERAL> (["l","L"])?
526 | <OCTAL_LITERAL> (["l","L"])?
529 <#DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* >
531 <#HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ >
533 <#OCTAL_LITERAL: "0" (["0"-"7"])* >
535 <FLOATING_POINT_LITERAL:
536 (["0"-"9"])+ "." (["0"-"9"])* (<EXPONENT>)? (["f","F","d","D"])?
537 | "." (["0"-"9"])+ (<EXPONENT>)? (["f","F","d","D"])?
538 | (["0"-"9"])+ <EXPONENT> (["f","F","d","D"])?
539 | (["0"-"9"])+ (<EXPONENT>)? ["f","F","d","D"]
542 <#EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ >
544 <STRING_LITERAL: (<STRING_1> | <STRING_2> | <STRING_3>)>
577 < IDENTIFIER: (<LETTER>|<SPECIAL>) (<LETTER>|<DIGIT>|<SPECIAL>)* >
580 ["a"-"z"] | ["A"-"Z"]
588 "_" | ["\u007f"-"\u00ff"]
613 | <EQUAL_EQUAL : "==">
618 | <BANGDOUBLEEQUAL : "!==">
619 | <TRIPLEEQUAL : "===">
626 | <PLUSASSIGN : "+=">
627 | <MINUSASSIGN : "-=">
628 | <STARASSIGN : "*=">
629 | <SLASHASSIGN : "/=">
635 | <TILDEEQUAL : "~=">
636 | <LSHIFTASSIGN : "<<=">
637 | <RSIGNEDSHIFTASSIGN : ">>=">
642 < DOLLAR_ID: <DOLLAR> <IDENTIFIER> >
650 {PHPParser.createNewHTMLCode();}
659 } catch (TokenMgrError e) {
660 PHPeclipsePlugin.log(e);
661 errorStart = SimpleCharStream.getPosition();
662 errorEnd = errorStart + 1;
663 errorMessage = e.getMessage();
665 throw generateParseException();
670 * A php block is a <?= expression [;]?>
671 * or <?php somephpcode ?>
672 * or <? somephpcode ?>
676 final int start = jj_input_stream.getPosition();
684 setMarker(fileToParse,
685 "You should use '<?php' instead of '<?' it will avoid some problems with XML",
687 jj_input_stream.getPosition(),
689 "Line " + token.beginLine);
690 } catch (CoreException e) {
691 PHPeclipsePlugin.log(e);
697 } catch (ParseException e) {
698 errorMessage = "'?>' expected";
700 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
701 errorEnd = jj_input_stream.getPosition() + 1;
706 PHPEchoBlock phpEchoBlock() :
708 final Expression expr;
709 final int pos = SimpleCharStream.getPosition();
710 PHPEchoBlock echoBlock;
713 <PHPECHOSTART> expr = Expression() [ <SEMICOLON> ] <PHPEND>
715 echoBlock = new PHPEchoBlock(expr,pos,SimpleCharStream.getPosition());
716 pushOnAstNodes(echoBlock);
726 ClassDeclaration ClassDeclaration() :
728 final ClassDeclaration classDeclaration;
729 final Token className;
730 Token superclassName = null;
736 {pos = jj_input_stream.getPosition();}
737 className = <IDENTIFIER>
738 } catch (ParseException e) {
739 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
741 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
742 errorEnd = jj_input_stream.getPosition() + 1;
748 superclassName = <IDENTIFIER>
749 } catch (ParseException e) {
750 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', identifier expected";
752 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
753 errorEnd = jj_input_stream.getPosition() + 1;
758 if (superclassName == null) {
759 classDeclaration = new ClassDeclaration(currentSegment,
760 className.image.toCharArray(),
764 classDeclaration = new ClassDeclaration(currentSegment,
765 className.image.toCharArray(),
766 superclassName.image.toCharArray(),
770 currentSegment.add(classDeclaration);
771 currentSegment = classDeclaration;
773 ClassBody(classDeclaration)
774 {currentSegment = (OutlineableWithChildren) currentSegment.getParent();
775 classDeclaration.sourceEnd = SimpleCharStream.getPosition();
776 pushOnAstNodes(classDeclaration);
777 return classDeclaration;}
780 void ClassBody(ClassDeclaration classDeclaration) :
785 } catch (ParseException e) {
786 errorMessage = "unexpected token : '"+ e.currentToken.next.image + "', '{' expected";
788 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
789 errorEnd = jj_input_stream.getPosition() + 1;
792 ( ClassBodyDeclaration(classDeclaration) )*
795 } catch (ParseException e) {
796 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', 'var', 'function' or '}' expected";
798 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
799 errorEnd = jj_input_stream.getPosition() + 1;
805 * A class can contain only methods and fields.
807 void ClassBodyDeclaration(ClassDeclaration classDeclaration) :
809 MethodDeclaration method;
810 FieldDeclaration field;
813 method = MethodDeclaration() {classDeclaration.addMethod(method);}
814 | field = FieldDeclaration() {classDeclaration.addVariable(field);}
818 * A class field declaration : it's var VariableDeclarator() (, VariableDeclarator())*;.
820 FieldDeclaration FieldDeclaration() :
822 VariableDeclaration variableDeclaration;
823 VariableDeclaration[] list;
824 final ArrayList arrayList = new ArrayList();
825 final int pos = SimpleCharStream.getPosition();
828 <VAR> variableDeclaration = VariableDeclarator()
829 {arrayList.add(variableDeclaration);
830 outlineInfo.addVariable(new String(variableDeclaration.name));
831 currentSegment.add(variableDeclaration);}
832 ( <COMMA> variableDeclaration = VariableDeclarator()
833 {arrayList.add(variableDeclaration);
834 outlineInfo.addVariable(new String(variableDeclaration.name));
835 currentSegment.add(variableDeclaration);}
839 } catch (ParseException e) {
840 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected after variable declaration";
842 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
843 errorEnd = jj_input_stream.getPosition() + 1;
847 {list = new VariableDeclaration[arrayList.size()];
848 arrayList.toArray(list);
849 return new FieldDeclaration(list,
851 SimpleCharStream.getPosition());}
854 VariableDeclaration VariableDeclarator() :
856 final String varName;
857 Expression initializer = null;
858 final int pos = jj_input_stream.getPosition();
861 varName = VariableDeclaratorId()
865 initializer = VariableInitializer()
866 } catch (ParseException e) {
867 errorMessage = "Literal expression expected in variable initializer";
869 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
870 errorEnd = jj_input_stream.getPosition() + 1;
875 if (initializer == null) {
876 return new VariableDeclaration(currentSegment,
877 varName.toCharArray(),
879 jj_input_stream.getPosition());
881 return new VariableDeclaration(currentSegment,
882 varName.toCharArray(),
890 * @return the variable name (with suffix)
892 String VariableDeclaratorId() :
895 Expression expression;
896 final StringBuffer buff = new StringBuffer();
897 final int pos = SimpleCharStream.getPosition();
898 ConstantIdentifier ex;
902 expr = Variable() {buff.append(expr);}
904 {ex = new ConstantIdentifier(expr.toCharArray(),
906 SimpleCharStream.getPosition());}
907 expression = VariableSuffix(ex)
908 {buff.append(expression.toStringExpression());}
910 {return buff.toString();}
911 } catch (ParseException e) {
912 errorMessage = "'$' expected for variable identifier";
914 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
915 errorEnd = jj_input_stream.getPosition() + 1;
922 final StringBuffer buff;
923 Expression expression = null;
928 token = <DOLLAR_ID> [<LBRACE> expression = Expression() <RBRACE>]
930 if (expression == null && !assigning) {
931 return token.image.substring(1);
933 buff = new StringBuffer(token.image);
935 buff.append(expression.toStringExpression());
937 return buff.toString();
940 <DOLLAR> expr = VariableName()
944 String VariableName():
946 final StringBuffer buff;
948 Expression expression = null;
952 <LBRACE> expression = Expression() <RBRACE>
953 {buff = new StringBuffer('{');
954 buff.append(expression.toStringExpression());
956 return buff.toString();}
958 token = <IDENTIFIER> [<LBRACE> expression = Expression() <RBRACE>]
960 if (expression == null) {
963 buff = new StringBuffer(token.image);
965 buff.append(expression.toStringExpression());
967 return buff.toString();
970 <DOLLAR> expr = VariableName()
972 buff = new StringBuffer('$');
974 return buff.toString();
977 token = <DOLLAR_ID> {return token.image;}
980 Expression VariableInitializer() :
982 final Expression expr;
984 final int pos = SimpleCharStream.getPosition();
990 <MINUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
991 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
993 SimpleCharStream.getPosition()),
997 <PLUS> (token = <INTEGER_LITERAL> | token = <FLOATING_POINT_LITERAL>)
998 {return new PrefixedUnaryExpression(new NumberLiteral(token.image.toCharArray(),
1000 SimpleCharStream.getPosition()),
1004 expr = ArrayDeclarator()
1007 token = <IDENTIFIER>
1008 {return new ConstantIdentifier(token.image.toCharArray(),pos,SimpleCharStream.getPosition());}
1011 ArrayVariableDeclaration ArrayVariable() :
1013 Expression expr,expr2;
1017 [<ARRAYASSIGN> expr2 = Expression()
1018 {return new ArrayVariableDeclaration(expr,expr2);}
1020 {return new ArrayVariableDeclaration(expr,SimpleCharStream.getPosition());}
1023 ArrayVariableDeclaration[] ArrayInitializer() :
1025 ArrayVariableDeclaration expr;
1026 final ArrayList list = new ArrayList();
1029 <LPAREN> [ expr = ArrayVariable()
1031 ( LOOKAHEAD(2) <COMMA> expr = ArrayVariable()
1035 [<COMMA> {list.add(null);}]
1038 ArrayVariableDeclaration[] vars = new ArrayVariableDeclaration[list.size()];
1044 * A Method Declaration.
1045 * <b>function</b> MetodDeclarator() Block()
1047 MethodDeclaration MethodDeclaration() :
1049 final MethodDeclaration functionDeclaration;
1055 functionDeclaration = MethodDeclarator()
1056 {outlineInfo.addVariable(new String(functionDeclaration.name));}
1057 } catch (ParseException e) {
1058 if (errorMessage != null) throw e;
1059 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function identifier expected";
1061 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1062 errorEnd = jj_input_stream.getPosition() + 1;
1066 if (currentSegment != null) {
1067 currentSegment.add(functionDeclaration);
1068 currentSegment = functionDeclaration;
1070 currentFunction = functionDeclaration;
1074 functionDeclaration.statements = block.statements;
1075 currentFunction = null;
1076 if (currentSegment != null) {
1077 currentSegment = (OutlineableWithChildren) currentSegment.getParent();
1079 return functionDeclaration;
1084 * A MethodDeclarator.
1085 * [&] IDENTIFIER(parameters ...).
1086 * @return a function description for the outline
1088 MethodDeclaration MethodDeclarator() :
1090 final Token identifier;
1091 Token reference = null;
1092 final Hashtable formalParameters;
1093 final int pos = SimpleCharStream.getPosition();
1096 [reference = <BIT_AND>] identifier = <IDENTIFIER>
1097 formalParameters = FormalParameters()
1098 {return new MethodDeclaration(currentSegment,
1099 identifier.image.toCharArray(),
1103 SimpleCharStream.getPosition());}
1107 * FormalParameters follows method identifier.
1108 * (FormalParameter())
1110 Hashtable FormalParameters() :
1112 VariableDeclaration var;
1113 final Hashtable parameters = new Hashtable();
1118 } catch (ParseException e) {
1119 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected after function identifier";
1121 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1122 errorEnd = jj_input_stream.getPosition() + 1;
1125 [ var = FormalParameter()
1126 {parameters.put(new String(var.name),var);}
1128 <COMMA> var = FormalParameter()
1129 {parameters.put(new String(var.name),var);}
1134 } catch (ParseException e) {
1135 errorMessage = "')' expected";
1137 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1138 errorEnd = jj_input_stream.getPosition() + 1;
1141 {return parameters;}
1145 * A formal parameter.
1146 * $varname[=value] (,$varname[=value])
1148 VariableDeclaration FormalParameter() :
1150 final VariableDeclaration variableDeclaration;
1154 [token = <BIT_AND>] variableDeclaration = VariableDeclarator()
1156 if (token != null) {
1157 variableDeclaration.setReference(true);
1159 return variableDeclaration;}
1162 ConstantIdentifier Type() :
1165 <STRING> {pos = SimpleCharStream.getPosition();
1166 return new ConstantIdentifier(Types.STRING,
1168 | <BOOL> {pos = SimpleCharStream.getPosition();
1169 return new ConstantIdentifier(Types.BOOL,
1171 | <BOOLEAN> {pos = SimpleCharStream.getPosition();
1172 return new ConstantIdentifier(Types.BOOLEAN,
1174 | <REAL> {pos = SimpleCharStream.getPosition();
1175 return new ConstantIdentifier(Types.REAL,
1177 | <DOUBLE> {pos = SimpleCharStream.getPosition();
1178 return new ConstantIdentifier(Types.DOUBLE,
1180 | <FLOAT> {pos = SimpleCharStream.getPosition();
1181 return new ConstantIdentifier(Types.FLOAT,
1183 | <INT> {pos = SimpleCharStream.getPosition();
1184 return new ConstantIdentifier(Types.INT,
1186 | <INTEGER> {pos = SimpleCharStream.getPosition();
1187 return new ConstantIdentifier(Types.INTEGER,
1189 | <OBJECT> {pos = SimpleCharStream.getPosition();
1190 return new ConstantIdentifier(Types.OBJECT,
1194 Expression Expression() :
1196 final Expression expr;
1199 expr = PrintExpression() {return expr;}
1200 | expr = ListExpression() {return expr;}
1201 | LOOKAHEAD(varAssignation())
1202 expr = varAssignation() {return expr;}
1203 | expr = ConditionalExpression() {return expr;}
1207 * A Variable assignation.
1208 * varName (an assign operator) any expression
1210 VarAssignation varAssignation() :
1213 final Expression expression;
1214 final int assignOperator;
1215 final int pos = SimpleCharStream.getPosition();
1218 varName = VariableDeclaratorId()
1219 assignOperator = AssignmentOperator()
1221 expression = Expression()
1222 } catch (ParseException e) {
1223 if (errorMessage != null) {
1226 errorMessage = "expression expected";
1228 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1229 errorEnd = jj_input_stream.getPosition() + 1;
1232 {return new VarAssignation(varName.toCharArray(),
1236 SimpleCharStream.getPosition());}
1239 int AssignmentOperator() :
1242 <ASSIGN> {return VarAssignation.EQUAL;}
1243 | <STARASSIGN> {return VarAssignation.STAR_EQUAL;}
1244 | <SLASHASSIGN> {return VarAssignation.SLASH_EQUAL;}
1245 | <REMASSIGN> {return VarAssignation.REM_EQUAL;}
1246 | <PLUSASSIGN> {return VarAssignation.PLUS_EQUAL;}
1247 | <MINUSASSIGN> {return VarAssignation.MINUS_EQUAL;}
1248 | <LSHIFTASSIGN> {return VarAssignation.LSHIFT_EQUAL;}
1249 | <RSIGNEDSHIFTASSIGN> {return VarAssignation.RSIGNEDSHIFT_EQUAL;}
1250 | <ANDASSIGN> {return VarAssignation.AND_EQUAL;}
1251 | <XORASSIGN> {return VarAssignation.XOR_EQUAL;}
1252 | <ORASSIGN> {return VarAssignation.OR_EQUAL;}
1253 | <DOTASSIGN> {return VarAssignation.DOT_EQUAL;}
1254 | <TILDEEQUAL> {return VarAssignation.TILDE_EQUAL;}
1257 Expression ConditionalExpression() :
1259 final Expression expr;
1260 Expression expr2 = null;
1261 Expression expr3 = null;
1264 expr = ConditionalOrExpression() [ <HOOK> expr2 = Expression() <COLON> expr3 = ConditionalExpression() ]
1266 if (expr3 == null) {
1269 return new ConditionalExpression(expr,expr2,expr3);
1273 Expression ConditionalOrExpression() :
1275 Expression expr,expr2;
1279 expr = ConditionalAndExpression()
1282 <OR_OR> {operator = OperatorIds.OR_OR;}
1283 | <_ORL> {operator = OperatorIds.ORL;}
1284 ) expr2 = ConditionalAndExpression()
1286 expr = new BinaryExpression(expr,expr2,operator);
1292 Expression ConditionalAndExpression() :
1294 Expression expr,expr2;
1298 expr = ConcatExpression()
1300 ( <AND_AND> {operator = OperatorIds.AND_AND;}
1301 | <_ANDL> {operator = OperatorIds.ANDL;})
1302 expr2 = ConcatExpression() {expr = new BinaryExpression(expr,expr2,operator);}
1307 Expression ConcatExpression() :
1309 Expression expr,expr2;
1312 expr = InclusiveOrExpression()
1314 <DOT> expr2 = InclusiveOrExpression()
1315 {expr = new BinaryExpression(expr,expr2,OperatorIds.DOT);}
1320 Expression InclusiveOrExpression() :
1322 Expression expr,expr2;
1325 expr = ExclusiveOrExpression()
1326 (<BIT_OR> expr2 = ExclusiveOrExpression()
1327 {expr = new BinaryExpression(expr,expr2,OperatorIds.OR);}
1332 Expression ExclusiveOrExpression() :
1334 Expression expr,expr2;
1337 expr = AndExpression()
1339 <XOR> expr2 = AndExpression()
1340 {expr = new BinaryExpression(expr,expr2,OperatorIds.XOR);}
1345 Expression AndExpression() :
1347 Expression expr,expr2;
1350 expr = EqualityExpression()
1352 <BIT_AND> expr2 = EqualityExpression()
1353 {expr = new BinaryExpression(expr,expr2,OperatorIds.AND);}
1358 Expression EqualityExpression() :
1360 Expression expr,expr2;
1364 expr = RelationalExpression()
1366 ( <EQUAL_EQUAL> {operator = OperatorIds.EQUAL_EQUAL;}
1367 | <DIF> {operator = OperatorIds.DIF;}
1368 | <NOT_EQUAL> {operator = OperatorIds.DIF;}
1369 | <BANGDOUBLEEQUAL> {operator = OperatorIds.BANG_EQUAL_EQUAL;}
1370 | <TRIPLEEQUAL> {operator = OperatorIds.EQUAL_EQUAL_EQUAL;}
1373 expr2 = RelationalExpression()
1374 } catch (ParseException e) {
1375 if (errorMessage != null) {
1378 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', expression expected";
1380 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1381 errorEnd = jj_input_stream.getPosition() + 1;
1385 expr = new BinaryExpression(expr,expr2,operator);
1391 Expression RelationalExpression() :
1393 Expression expr,expr2;
1397 expr = ShiftExpression()
1399 ( <LT> {operator = OperatorIds.LESS;}
1400 | <GT> {operator = OperatorIds.GREATER;}
1401 | <LE> {operator = OperatorIds.LESS_EQUAL;}
1402 | <GE> {operator = OperatorIds.GREATER_EQUAL;})
1403 expr2 = ShiftExpression()
1404 {expr = new BinaryExpression(expr,expr2,operator);}
1409 Expression ShiftExpression() :
1411 Expression expr,expr2;
1415 expr = AdditiveExpression()
1417 ( <LSHIFT> {operator = OperatorIds.LEFT_SHIFT;}
1418 | <RSIGNEDSHIFT> {operator = OperatorIds.RIGHT_SHIFT;}
1419 | <RUNSIGNEDSHIFT> {operator = OperatorIds.UNSIGNED_RIGHT_SHIFT;})
1420 expr2 = AdditiveExpression()
1421 {expr = new BinaryExpression(expr,expr2,operator);}
1426 Expression AdditiveExpression() :
1428 Expression expr,expr2;
1432 expr = MultiplicativeExpression()
1434 ( <PLUS> {operator = OperatorIds.PLUS;}
1435 | <MINUS> {operator = OperatorIds.MINUS;} )
1436 expr2 = MultiplicativeExpression()
1437 {expr = new BinaryExpression(expr,expr2,operator);}
1442 Expression MultiplicativeExpression() :
1444 Expression expr,expr2;
1449 expr = UnaryExpression()
1450 } catch (ParseException e) {
1451 if (errorMessage != null) throw e;
1452 errorMessage = "unexpected token '"+e.currentToken.next.image+"'";
1454 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1455 errorEnd = jj_input_stream.getPosition() + 1;
1459 ( <STAR> {operator = OperatorIds.MULTIPLY;}
1460 | <SLASH> {operator = OperatorIds.DIVIDE;}
1461 | <REMAINDER> {operator = OperatorIds.REMAINDER;})
1462 expr2 = UnaryExpression()
1463 {expr = new BinaryExpression(expr,expr2,operator);}
1469 * An unary expression starting with @, & or nothing
1471 Expression UnaryExpression() :
1474 final int pos = SimpleCharStream.getPosition();
1477 <BIT_AND> expr = UnaryExpressionNoPrefix()
1478 {return new PrefixedUnaryExpression(expr,OperatorIds.AND,pos);}
1480 expr = AtUnaryExpression() {return expr;}
1483 Expression AtUnaryExpression() :
1486 final int pos = SimpleCharStream.getPosition();
1490 expr = AtUnaryExpression()
1491 {return new PrefixedUnaryExpression(expr,OperatorIds.AT,pos);}
1493 expr = UnaryExpressionNoPrefix()
1498 Expression UnaryExpressionNoPrefix() :
1502 final int pos = SimpleCharStream.getPosition();
1505 ( <PLUS> {operator = OperatorIds.PLUS;}
1506 | <MINUS> {operator = OperatorIds.MINUS;})
1507 expr = UnaryExpression()
1508 {return new PrefixedUnaryExpression(expr,operator,pos);}
1510 expr = PreIncDecExpression()
1513 expr = UnaryExpressionNotPlusMinus()
1518 Expression PreIncDecExpression() :
1520 final Expression expr;
1522 final int pos = SimpleCharStream.getPosition();
1525 ( <INCR> {operator = OperatorIds.PLUS_PLUS;}
1526 | <DECR> {operator = OperatorIds.MINUS_MINUS;})
1527 expr = PrimaryExpression()
1528 {return new PrefixedUnaryExpression(expr,operator,pos);}
1531 Expression UnaryExpressionNotPlusMinus() :
1534 final int pos = SimpleCharStream.getPosition();
1537 <BANG> expr = UnaryExpression() {return new PrefixedUnaryExpression(expr,OperatorIds.NOT,pos);}
1538 | LOOKAHEAD( <LPAREN> (Type() | <ARRAY>) <RPAREN> )
1539 expr = CastExpression() {return expr;}
1540 | expr = PostfixExpression() {return expr;}
1541 | expr = Literal() {return expr;}
1542 | <LPAREN> expr = Expression()
1545 } catch (ParseException e) {
1546 errorMessage = "')' expected";
1548 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1549 errorEnd = jj_input_stream.getPosition() + 1;
1555 CastExpression CastExpression() :
1557 final ConstantIdentifier type;
1558 final Expression expr;
1559 final int pos = SimpleCharStream.getPosition();
1564 | <ARRAY> {type = new ConstantIdentifier(Types.ARRAY,pos,SimpleCharStream.getPosition());})
1565 <RPAREN> expr = UnaryExpression()
1566 {return new CastExpression(type,expr,pos,SimpleCharStream.getPosition());}
1569 Expression PostfixExpression() :
1573 final int pos = SimpleCharStream.getPosition();
1576 expr = PrimaryExpression()
1577 [ <INCR> {operator = OperatorIds.PLUS_PLUS;}
1578 | <DECR> {operator = OperatorIds.MINUS_MINUS;}]
1580 if (operator == -1) {
1583 return new PostfixedUnaryExpression(expr,operator,pos);
1587 Expression PrimaryExpression() :
1589 final Token identifier;
1591 final int pos = SimpleCharStream.getPosition();
1595 identifier = <IDENTIFIER> <STATICCLASSACCESS> expr = ClassIdentifier()
1596 {expr = new ClassAccess(new ConstantIdentifier(identifier.image.toCharArray(),
1598 SimpleCharStream.getPosition()),
1600 ClassAccess.STATIC);}
1601 (expr = PrimarySuffix(expr))*
1604 expr = PrimaryPrefix()
1605 (expr = PrimarySuffix(expr))*
1608 expr = ArrayDeclarator()
1612 ArrayInitializer ArrayDeclarator() :
1614 final ArrayVariableDeclaration[] vars;
1615 final int pos = SimpleCharStream.getPosition();
1618 <ARRAY> vars = ArrayInitializer()
1619 {return new ArrayInitializer(vars,pos,SimpleCharStream.getPosition());}
1622 Expression PrimaryPrefix() :
1624 final Expression expr;
1627 final int pos = SimpleCharStream.getPosition();
1630 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1632 SimpleCharStream.getPosition());}
1633 | <NEW> expr = ClassIdentifier() {return new PrefixedUnaryExpression(expr,
1636 | var = VariableDeclaratorId() {return new ConstantIdentifier(var.toCharArray(),
1638 SimpleCharStream.getPosition());}
1641 PrefixedUnaryExpression classInstantiation() :
1644 final StringBuffer buff;
1645 final int pos = SimpleCharStream.getPosition();
1648 <NEW> expr = ClassIdentifier()
1650 {buff = new StringBuffer(expr.toStringExpression());}
1651 expr = PrimaryExpression()
1652 {buff.append(expr.toStringExpression());
1653 expr = new ConstantIdentifier(buff.toString().toCharArray(),
1655 SimpleCharStream.getPosition());}
1657 {return new PrefixedUnaryExpression(expr,
1662 ConstantIdentifier ClassIdentifier():
1666 final int pos = SimpleCharStream.getPosition();
1669 token = <IDENTIFIER> {return new ConstantIdentifier(token.image.toCharArray(),
1671 SimpleCharStream.getPosition());}
1672 | expr = VariableDeclaratorId() {return new ConstantIdentifier(expr.toCharArray(),
1674 SimpleCharStream.getPosition());}
1677 AbstractSuffixExpression PrimarySuffix(Expression prefix) :
1679 final AbstractSuffixExpression expr;
1682 expr = Arguments(prefix) {return expr;}
1683 | expr = VariableSuffix(prefix) {return expr;}
1686 AbstractSuffixExpression VariableSuffix(Expression prefix) :
1689 final int pos = SimpleCharStream.getPosition();
1690 Expression expression = null;
1695 expr = VariableName()
1696 } catch (ParseException e) {
1697 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', function call or field access expected";
1699 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1700 errorEnd = jj_input_stream.getPosition() + 1;
1703 {return new ClassAccess(prefix,
1704 new ConstantIdentifier(expr.toCharArray(),pos,SimpleCharStream.getPosition()),
1705 ClassAccess.NORMAL);}
1707 <LBRACKET> [ expression = Expression() | expression = Type() ] //Not good
1710 } catch (ParseException e) {
1711 errorMessage = "']' expected";
1713 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1714 errorEnd = jj_input_stream.getPosition() + 1;
1717 {return new ArrayDeclarator(prefix,expression,SimpleCharStream.getPosition());}
1726 token = <INTEGER_LITERAL> {pos = SimpleCharStream.getPosition();
1727 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1728 | token = <FLOATING_POINT_LITERAL> {pos = SimpleCharStream.getPosition();
1729 return new NumberLiteral(token.image.toCharArray(),pos-token.image.length(),pos);}
1730 | token = <STRING_LITERAL> {pos = SimpleCharStream.getPosition();
1731 return new StringLiteral(token.image.toCharArray(),pos-token.image.length());}
1732 | <TRUE> {pos = SimpleCharStream.getPosition();
1733 return new TrueLiteral(pos-4,pos);}
1734 | <FALSE> {pos = SimpleCharStream.getPosition();
1735 return new FalseLiteral(pos-4,pos);}
1736 | <NULL> {pos = SimpleCharStream.getPosition();
1737 return new NullLiteral(pos-4,pos);}
1740 FunctionCall Arguments(Expression func) :
1742 Expression[] args = null;
1745 <LPAREN> [ args = ArgumentList() ]
1748 } catch (ParseException e) {
1749 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected to close the argument list";
1751 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1752 errorEnd = jj_input_stream.getPosition() + 1;
1755 {return new FunctionCall(func,args,SimpleCharStream.getPosition());}
1759 * An argument list is a list of arguments separated by comma :
1760 * argumentDeclaration() (, argumentDeclaration)*
1761 * @return an array of arguments
1763 Expression[] ArgumentList() :
1766 final ArrayList list = new ArrayList();
1775 } catch (ParseException e) {
1776 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. An expression expected after a comma in argument list";
1778 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1779 errorEnd = jj_input_stream.getPosition() + 1;
1784 Expression[] arguments = new Expression[list.size()];
1785 list.toArray(arguments);
1790 * A Statement without break.
1792 Statement StatementNoBreak() :
1794 final Statement statement;
1799 statement = Expression()
1802 } catch (ParseException e) {
1803 if (e.currentToken.next.kind != 4) {
1804 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1806 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1807 errorEnd = jj_input_stream.getPosition() + 1;
1813 statement = LabeledStatement() {return statement;}
1814 | statement = Block() {return statement;}
1815 | statement = EmptyStatement() {return statement;}
1816 | statement = StatementExpression()
1819 } catch (ParseException e) {
1820 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1822 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1823 errorEnd = jj_input_stream.getPosition() + 1;
1827 | statement = SwitchStatement() {return statement;}
1828 | statement = IfStatement() {return statement;}
1829 | statement = WhileStatement() {return statement;}
1830 | statement = DoStatement() {return statement;}
1831 | statement = ForStatement() {return statement;}
1832 | statement = ForeachStatement() {return statement;}
1833 | statement = ContinueStatement() {return statement;}
1834 | statement = ReturnStatement() {return statement;}
1835 | statement = EchoStatement() {return statement;}
1836 | [token=<AT>] statement = IncludeStatement()
1837 {if (token != null) {
1838 ((InclusionStatement)statement).silent = true;
1841 | statement = StaticStatement() {return statement;}
1842 | statement = GlobalStatement() {return statement;}
1846 * A Normal statement.
1848 Statement Statement() :
1850 final Statement statement;
1853 statement = StatementNoBreak() {return statement;}
1854 | statement = BreakStatement() {return statement;}
1858 * An html block inside a php syntax.
1860 HTMLBlock htmlBlock() :
1862 final int startIndex = nodePtr;
1863 AstNode[] blockNodes;
1867 <PHPEND> (phpEchoBlock())*
1869 (<PHPSTARTLONG> | <PHPSTARTSHORT>)
1870 } catch (ParseException e) {
1871 errorMessage = "End of file unexpected, '<?php' expected";
1873 errorStart = jj_input_stream.getPosition();
1874 errorEnd = jj_input_stream.getPosition();
1878 nbNodes = nodePtr-startIndex - 1;
1879 blockNodes = new AstNode[nbNodes];
1880 System.arraycopy(nodes,startIndex,blockNodes,0,nbNodes);
1881 return new HTMLBlock(nodes);}
1885 * An include statement. It's "include" an expression;
1887 InclusionStatement IncludeStatement() :
1889 final Expression expr;
1891 final int pos = jj_input_stream.getPosition();
1892 final InclusionStatement inclusionStatement;
1895 ( <REQUIRE> {keyword = InclusionStatement.REQUIRE;}
1896 | <REQUIRE_ONCE> {keyword = InclusionStatement.REQUIRE_ONCE;}
1897 | <INCLUDE> {keyword = InclusionStatement.INCLUDE;}
1898 | <INCLUDE_ONCE> {keyword = InclusionStatement.INCLUDE_ONCE;})
1901 } catch (ParseException e) {
1902 if (errorMessage != null) {
1905 errorMessage = "unexpected token '"+ e.currentToken.next.image+"', expression expected";
1907 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1908 errorEnd = jj_input_stream.getPosition() + 1;
1911 {inclusionStatement = new InclusionStatement(currentSegment,
1915 currentSegment.add(inclusionStatement);
1919 } catch (ParseException e) {
1920 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
1922 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1923 errorEnd = jj_input_stream.getPosition() + 1;
1926 {return inclusionStatement;}
1929 PrintExpression PrintExpression() :
1931 final Expression expr;
1932 final int pos = SimpleCharStream.getPosition();
1935 <PRINT> expr = Expression() {return new PrintExpression(expr,pos,SimpleCharStream.getPosition());}
1938 ListExpression ListExpression() :
1941 Expression expression = null;
1942 ArrayList list = new ArrayList();
1943 final int pos = SimpleCharStream.getPosition();
1949 } catch (ParseException e) {
1950 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', '(' expected";
1952 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1953 errorEnd = jj_input_stream.getPosition() + 1;
1957 expr = VariableDeclaratorId()
1960 {if (expr == null) list.add(null);}
1964 } catch (ParseException e) {
1965 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ',' expected";
1967 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1968 errorEnd = jj_input_stream.getPosition() + 1;
1971 expr = VariableDeclaratorId()
1976 } catch (ParseException e) {
1977 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"', ')' expected";
1979 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
1980 errorEnd = jj_input_stream.getPosition() + 1;
1983 [ <ASSIGN> expression = Expression()
1985 String[] strings = new String[list.size()];
1986 list.toArray(strings);
1987 return new ListExpression(strings,
1990 SimpleCharStream.getPosition());}
1993 String[] strings = new String[list.size()];
1994 list.toArray(strings);
1995 return new ListExpression(strings,pos,SimpleCharStream.getPosition());}
1999 * An echo statement.
2000 * echo anyexpression (, otherexpression)*
2002 EchoStatement EchoStatement() :
2004 final ArrayList expressions = new ArrayList();
2006 final int pos = SimpleCharStream.getPosition();
2009 <ECHO> expr = Expression()
2010 {expressions.add(expr);}
2012 <COMMA> expr = Expression()
2013 {expressions.add(expr);}
2018 Expression[] exprs = new Expression[expressions.size()];
2019 expressions.toArray(exprs);
2020 return new EchoStatement(exprs,pos);}
2021 } catch (ParseException e) {
2022 if (e.currentToken.next.kind != 4) {
2023 errorMessage = "';' expected after 'echo' statement";
2025 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2026 errorEnd = jj_input_stream.getPosition() + 1;
2032 GlobalStatement GlobalStatement() :
2034 final int pos = jj_input_stream.getPosition();
2036 ArrayList vars = new ArrayList();
2037 GlobalStatement global;
2041 expr = VariableDeclaratorId()
2044 expr = VariableDeclaratorId()
2050 String[] strings = new String[vars.size()];
2051 vars.toArray(strings);
2052 global = new GlobalStatement(currentSegment,
2055 SimpleCharStream.getPosition());
2056 currentSegment.add(global);
2058 } catch (ParseException e) {
2059 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2061 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2062 errorEnd = jj_input_stream.getPosition() + 1;
2067 StaticStatement StaticStatement() :
2069 final int pos = SimpleCharStream.getPosition();
2070 final ArrayList vars = new ArrayList();
2071 VariableDeclaration expr;
2074 <STATIC> expr = VariableDeclarator() {vars.add(new String(expr.name));}
2075 (<COMMA> expr = VariableDeclarator() {vars.add(new String(expr.name));})*
2079 String[] strings = new String[vars.size()];
2080 vars.toArray(strings);
2081 return new StaticStatement(strings,
2083 SimpleCharStream.getPosition());}
2084 } catch (ParseException e) {
2085 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. a ';' was expected";
2087 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2088 errorEnd = jj_input_stream.getPosition() + 1;
2093 LabeledStatement LabeledStatement() :
2095 final int pos = SimpleCharStream.getPosition();
2097 final Statement statement;
2100 label = <IDENTIFIER> <COLON> statement = Statement()
2101 {return new LabeledStatement(label.image.toCharArray(),statement,pos,SimpleCharStream.getPosition());}
2113 final int pos = SimpleCharStream.getPosition();
2114 final ArrayList list = new ArrayList();
2115 Statement statement;
2120 } catch (ParseException e) {
2121 errorMessage = "'{' expected";
2123 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2124 errorEnd = jj_input_stream.getPosition() + 1;
2127 ( statement = BlockStatement() {list.add(statement);}
2128 | statement = htmlBlock() {list.add(statement);})*
2131 } catch (ParseException e) {
2132 errorMessage = "unexpected token : '"+ e.currentToken.image +"', '}' expected";
2134 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2135 errorEnd = jj_input_stream.getPosition() + 1;
2139 Statement[] statements = new Statement[list.size()];
2140 list.toArray(statements);
2141 return new Block(statements,pos,SimpleCharStream.getPosition());}
2144 Statement BlockStatement() :
2146 final Statement statement;
2149 statement = Statement() {return statement;}
2150 | statement = ClassDeclaration() {return statement;}
2151 | statement = MethodDeclaration() {return statement;}
2155 * A Block statement that will not contain any 'break'
2157 Statement BlockStatementNoBreak() :
2159 final Statement statement;
2162 statement = StatementNoBreak() {return statement;}
2163 | statement = ClassDeclaration() {return statement;}
2164 | statement = MethodDeclaration() {return statement;}
2167 VariableDeclaration[] LocalVariableDeclaration() :
2169 final ArrayList list = new ArrayList();
2170 VariableDeclaration var;
2173 var = LocalVariableDeclarator()
2175 ( <COMMA> var = LocalVariableDeclarator() {list.add(var);})*
2177 VariableDeclaration[] vars = new VariableDeclaration[list.size()];
2182 VariableDeclaration LocalVariableDeclarator() :
2184 final String varName;
2185 Expression initializer = null;
2186 final int pos = SimpleCharStream.getPosition();
2189 varName = VariableDeclaratorId() [ <ASSIGN> initializer = Expression() ]
2191 if (initializer == null) {
2192 return new VariableDeclaration(currentSegment,
2193 varName.toCharArray(),
2195 jj_input_stream.getPosition());
2197 return new VariableDeclaration(currentSegment,
2198 varName.toCharArray(),
2204 EmptyStatement EmptyStatement() :
2210 {pos = SimpleCharStream.getPosition();
2211 return new EmptyStatement(pos-1,pos);}
2214 Statement StatementExpression() :
2216 Expression expr,expr2;
2220 expr = PreIncDecExpression() {return expr;}
2222 expr = PrimaryExpression()
2223 [ <INCR> {return new PostfixedUnaryExpression(expr,
2224 OperatorIds.PLUS_PLUS,
2225 SimpleCharStream.getPosition());}
2226 | <DECR> {return new PostfixedUnaryExpression(expr,
2227 OperatorIds.MINUS_MINUS,
2228 SimpleCharStream.getPosition());}
2229 | operator = AssignmentOperator() expr2 = Expression()
2230 {return new BinaryExpression(expr,expr2,operator);}
2235 SwitchStatement SwitchStatement() :
2237 final Expression variable;
2238 final AbstractCase[] cases;
2239 final int pos = SimpleCharStream.getPosition();
2245 } catch (ParseException e) {
2246 errorMessage = "'(' expected after 'switch'";
2248 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2249 errorEnd = jj_input_stream.getPosition() + 1;
2253 variable = Expression()
2254 } catch (ParseException e) {
2255 if (errorMessage != null) {
2258 errorMessage = "expression expected";
2260 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2261 errorEnd = jj_input_stream.getPosition() + 1;
2266 } catch (ParseException e) {
2267 errorMessage = "')' expected";
2269 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2270 errorEnd = jj_input_stream.getPosition() + 1;
2273 (cases = switchStatementBrace() | cases = switchStatementColon(pos, pos + 6))
2274 {return new SwitchStatement(variable,cases,pos,SimpleCharStream.getPosition());}
2277 AbstractCase[] switchStatementBrace() :
2280 final ArrayList cases = new ArrayList();
2284 ( cas = switchLabel0() {cases.add(cas);})*
2288 AbstractCase[] abcase = new AbstractCase[cases.size()];
2289 cases.toArray(abcase);
2291 } catch (ParseException e) {
2292 errorMessage = "'}' expected";
2294 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2295 errorEnd = jj_input_stream.getPosition() + 1;
2300 * A Switch statement with : ... endswitch;
2301 * @param start the begin offset of the switch
2302 * @param end the end offset of the switch
2304 AbstractCase[] switchStatementColon(final int start, final int end) :
2307 final ArrayList cases = new ArrayList();
2312 setMarker(fileToParse,
2313 "Ugly syntax detected, you should switch () {...} instead of switch (): ... enswitch;",
2317 "Line " + token.beginLine);
2318 } catch (CoreException e) {
2319 PHPeclipsePlugin.log(e);
2321 ( cas = switchLabel0() {cases.add(cas);})*
2324 } catch (ParseException e) {
2325 errorMessage = "'endswitch' expected";
2327 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2328 errorEnd = jj_input_stream.getPosition() + 1;
2334 AbstractCase[] abcase = new AbstractCase[cases.size()];
2335 cases.toArray(abcase);
2337 } catch (ParseException e) {
2338 errorMessage = "';' expected after 'endswitch' keyword";
2340 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2341 errorEnd = jj_input_stream.getPosition() + 1;
2346 AbstractCase switchLabel0() :
2348 final Expression expr;
2349 Statement statement;
2350 final ArrayList stmts = new ArrayList();
2351 final int pos = SimpleCharStream.getPosition();
2354 expr = SwitchLabel()
2355 ( statement = BlockStatementNoBreak() {stmts.add(statement);}
2356 | statement = htmlBlock() {stmts.add(statement);})*
2357 [ statement = BreakStatement() {stmts.add(statement);}]
2359 Statement[] stmtsArray = new Statement[stmts.size()];
2360 stmts.toArray(stmtsArray);
2361 if (expr == null) {//it's a default
2362 return new DefaultCase(stmtsArray,pos,SimpleCharStream.getPosition());
2364 return new Case(expr,stmtsArray,pos,SimpleCharStream.getPosition());}
2369 * case Expression() :
2371 * @return the if it was a case and null if not
2373 Expression SwitchLabel() :
2375 final Expression expr;
2381 } catch (ParseException e) {
2382 if (errorMessage != null) throw e;
2383 errorMessage = "expression expected after 'case' keyword";
2385 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2386 errorEnd = jj_input_stream.getPosition() + 1;
2392 } catch (ParseException e) {
2393 errorMessage = "':' expected after case expression";
2395 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2396 errorEnd = jj_input_stream.getPosition() + 1;
2404 } catch (ParseException e) {
2405 errorMessage = "':' expected after 'default' keyword";
2407 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2408 errorEnd = jj_input_stream.getPosition() + 1;
2413 Break BreakStatement() :
2415 Expression expression = null;
2416 final int start = SimpleCharStream.getPosition();
2419 <BREAK> [ expression = Expression() ]
2422 } catch (ParseException e) {
2423 errorMessage = "';' expected after 'break' keyword";
2425 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2426 errorEnd = jj_input_stream.getPosition() + 1;
2429 {return new Break(expression, start, SimpleCharStream.getPosition());}
2432 IfStatement IfStatement() :
2434 final int pos = jj_input_stream.getPosition();
2435 Expression condition;
2436 IfStatement ifStatement;
2439 <IF> condition = Condition("if") ifStatement = IfStatement0(condition, pos,pos+2)
2440 {return ifStatement;}
2444 Expression Condition(final String keyword) :
2446 final Expression condition;
2451 } catch (ParseException e) {
2452 errorMessage = "'(' expected after " + keyword + " keyword";
2454 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length();
2455 errorEnd = errorStart +1;
2456 processParseException(e);
2458 condition = Expression()
2462 } catch (ParseException e) {
2463 errorMessage = "')' expected after " + keyword + " keyword";
2465 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2466 errorEnd = jj_input_stream.getPosition() + 1;
2471 IfStatement IfStatement0(Expression condition, final int start,final int end) :
2473 Statement statement;
2475 final Statement[] statementsArray;
2476 ElseIf elseifStatement;
2477 Else elseStatement = null;
2479 final ArrayList elseIfList = new ArrayList();
2481 int pos = SimpleCharStream.getPosition();
2486 {stmts = new ArrayList();}
2487 ( statement = Statement() {stmts.add(statement);}
2488 | statement = htmlBlock() {stmts.add(statement);})*
2489 {endStatements = SimpleCharStream.getPosition();}
2490 (elseifStatement = ElseIfStatementColon() {elseIfList.add(elseifStatement);})*
2491 [elseStatement = ElseStatementColon()]
2494 setMarker(fileToParse,
2495 "Ugly syntax detected, you should if () {...} instead of if (): ... endif;",
2499 "Line " + token.beginLine);
2500 } catch (CoreException e) {
2501 PHPeclipsePlugin.log(e);
2505 } catch (ParseException e) {
2506 errorMessage = "'endif' expected";
2508 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2509 errorEnd = jj_input_stream.getPosition() + 1;
2514 } catch (ParseException e) {
2515 errorMessage = "';' expected after 'endif' keyword";
2517 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2518 errorEnd = jj_input_stream.getPosition() + 1;
2522 elseIfs = new ElseIf[elseIfList.size()];
2523 elseIfList.toArray(elseIfs);
2524 if (stmts.size() == 1) {
2525 return new IfStatement(condition,
2526 (Statement) stmts.get(0),
2530 SimpleCharStream.getPosition());
2532 statementsArray = new Statement[stmts.size()];
2533 stmts.toArray(statementsArray);
2534 return new IfStatement(condition,
2535 new Block(statementsArray,pos,endStatements),
2539 SimpleCharStream.getPosition());
2544 (stmt = Statement() | stmt = htmlBlock())
2545 ( LOOKAHEAD(1) elseifStatement = ElseIfStatement() {elseIfList.add(elseifStatement);})*
2549 {pos = SimpleCharStream.getPosition();}
2550 statement = Statement()
2551 {elseStatement = new Else(statement,pos,SimpleCharStream.getPosition());}
2552 } catch (ParseException e) {
2553 if (errorMessage != null) {
2556 errorMessage = "unexpected token '"+e.currentToken.next.image+"', a statement was expected";
2558 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2559 errorEnd = jj_input_stream.getPosition() + 1;
2564 elseIfs = new ElseIf[elseIfList.size()];
2565 elseIfList.toArray(elseIfs);
2566 return new IfStatement(condition,
2571 SimpleCharStream.getPosition());}
2574 ElseIf ElseIfStatementColon() :
2576 Expression condition;
2577 Statement statement;
2578 final ArrayList list = new ArrayList();
2579 final int pos = SimpleCharStream.getPosition();
2582 <ELSEIF> condition = Condition("elseif")
2583 <COLON> ( statement = Statement() {list.add(statement);}
2584 | statement = htmlBlock() {list.add(statement);})*
2586 Statement[] stmtsArray = new Statement[list.size()];
2587 list.toArray(stmtsArray);
2588 return new ElseIf(condition,stmtsArray ,pos,SimpleCharStream.getPosition());}
2591 Else ElseStatementColon() :
2593 Statement statement;
2594 final ArrayList list = new ArrayList();
2595 final int pos = SimpleCharStream.getPosition();
2598 <ELSE> <COLON> ( statement = Statement() {list.add(statement);}
2599 | statement = htmlBlock() {list.add(statement);})*
2601 Statement[] stmtsArray = new Statement[list.size()];
2602 list.toArray(stmtsArray);
2603 return new Else(stmtsArray,pos,SimpleCharStream.getPosition());}
2606 ElseIf ElseIfStatement() :
2608 Expression condition;
2609 Statement statement;
2610 final ArrayList list = new ArrayList();
2611 final int pos = SimpleCharStream.getPosition();
2614 <ELSEIF> condition = Condition("elseif") statement = Statement() {list.add(statement);/*todo:do better*/}
2616 Statement[] stmtsArray = new Statement[list.size()];
2617 list.toArray(stmtsArray);
2618 return new ElseIf(condition,stmtsArray,pos,SimpleCharStream.getPosition());}
2621 WhileStatement WhileStatement() :
2623 final Expression condition;
2624 final Statement action;
2625 final int pos = SimpleCharStream.getPosition();
2629 condition = Condition("while")
2630 action = WhileStatement0(pos,pos + 5)
2631 {return new WhileStatement(condition,action,pos,SimpleCharStream.getPosition());}
2634 Statement WhileStatement0(final int start, final int end) :
2636 Statement statement;
2637 final ArrayList stmts = new ArrayList();
2638 final int pos = SimpleCharStream.getPosition();
2641 <COLON> (statement = Statement() {stmts.add(statement);})*
2643 setMarker(fileToParse,
2644 "Ugly syntax detected, you should while () {...} instead of while (): ... endwhile;",
2648 "Line " + token.beginLine);
2649 } catch (CoreException e) {
2650 PHPeclipsePlugin.log(e);
2654 } catch (ParseException e) {
2655 errorMessage = "'endwhile' expected";
2657 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2658 errorEnd = jj_input_stream.getPosition() + 1;
2664 Statement[] stmtsArray = new Statement[stmts.size()];
2665 stmts.toArray(stmtsArray);
2666 return new Block(stmtsArray,pos,SimpleCharStream.getPosition());}
2667 } catch (ParseException e) {
2668 errorMessage = "';' expected after 'endwhile' keyword";
2670 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2671 errorEnd = jj_input_stream.getPosition() + 1;
2675 statement = Statement()
2679 DoStatement DoStatement() :
2681 final Statement action;
2682 final Expression condition;
2683 final int pos = SimpleCharStream.getPosition();
2686 <DO> action = Statement() <WHILE> condition = Condition("while")
2689 {return new DoStatement(condition,action,pos,SimpleCharStream.getPosition());}
2690 } catch (ParseException e) {
2691 errorMessage = "unexpected token : '"+ e.currentToken.next.image +"'. A ';' was expected";
2693 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2694 errorEnd = jj_input_stream.getPosition() + 1;
2699 ForeachStatement ForeachStatement() :
2701 Statement statement;
2702 Expression expression;
2703 final int pos = SimpleCharStream.getPosition();
2704 ArrayVariableDeclaration variable;
2710 } catch (ParseException e) {
2711 errorMessage = "'(' expected after 'foreach' keyword";
2713 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2714 errorEnd = jj_input_stream.getPosition() + 1;
2718 expression = Expression()
2719 } catch (ParseException e) {
2720 errorMessage = "variable expected";
2722 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2723 errorEnd = jj_input_stream.getPosition() + 1;
2728 } catch (ParseException e) {
2729 errorMessage = "'as' expected";
2731 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2732 errorEnd = jj_input_stream.getPosition() + 1;
2736 variable = ArrayVariable()
2737 } catch (ParseException e) {
2738 errorMessage = "variable expected";
2740 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2741 errorEnd = jj_input_stream.getPosition() + 1;
2746 } catch (ParseException e) {
2747 errorMessage = "')' expected after 'foreach' keyword";
2749 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2750 errorEnd = jj_input_stream.getPosition() + 1;
2754 statement = Statement()
2755 } catch (ParseException e) {
2756 if (errorMessage != null) throw e;
2757 errorMessage = "statement expected";
2759 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2760 errorEnd = jj_input_stream.getPosition() + 1;
2763 {return new ForeachStatement(expression,
2767 SimpleCharStream.getPosition());}
2771 ForStatement ForStatement() :
2774 final int pos = SimpleCharStream.getPosition();
2775 Statement[] initializations = null;
2776 Expression condition = null;
2777 Statement[] increments = null;
2779 final ArrayList list = new ArrayList();
2780 final int startBlock, endBlock;
2786 } catch (ParseException e) {
2787 errorMessage = "'(' expected after 'for' keyword";
2789 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2790 errorEnd = jj_input_stream.getPosition() + 1;
2793 [ initializations = ForInit() ] <SEMICOLON>
2794 [ condition = Expression() ] <SEMICOLON>
2795 [ increments = StatementExpressionList() ] <RPAREN>
2797 action = Statement()
2798 {return new ForStatement(initializations,condition,increments,action,pos,SimpleCharStream.getPosition());}
2801 {startBlock = SimpleCharStream.getPosition();}
2802 (action = Statement() {list.add(action);})*
2805 setMarker(fileToParse,
2806 "Ugly syntax detected, you should for () {...} instead of for (): ... endfor;",
2808 pos+token.image.length(),
2810 "Line " + token.beginLine);
2811 } catch (CoreException e) {
2812 PHPeclipsePlugin.log(e);
2815 {endBlock = SimpleCharStream.getPosition();}
2818 } catch (ParseException e) {
2819 errorMessage = "'endfor' expected";
2821 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2822 errorEnd = jj_input_stream.getPosition() + 1;
2828 Statement[] stmtsArray = new Statement[list.size()];
2829 list.toArray(stmtsArray);
2830 return new ForStatement(initializations,condition,increments,new Block(stmtsArray,startBlock,endBlock),pos,SimpleCharStream.getPosition());}
2831 } catch (ParseException e) {
2832 errorMessage = "';' expected after 'endfor' keyword";
2834 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2835 errorEnd = jj_input_stream.getPosition() + 1;
2841 Statement[] ForInit() :
2843 Statement[] statements;
2846 LOOKAHEAD(LocalVariableDeclaration())
2847 statements = LocalVariableDeclaration()
2848 {return statements;}
2850 statements = StatementExpressionList()
2851 {return statements;}
2854 Statement[] StatementExpressionList() :
2856 final ArrayList list = new ArrayList();
2860 expr = StatementExpression() {list.add(expr);}
2861 (<COMMA> StatementExpression() {list.add(expr);})*
2863 Statement[] stmtsArray = new Statement[list.size()];
2864 list.toArray(stmtsArray);
2868 Continue ContinueStatement() :
2870 Expression expr = null;
2871 final int pos = SimpleCharStream.getPosition();
2874 <CONTINUE> [ expr = Expression() ]
2877 {return new Continue(expr,pos,SimpleCharStream.getPosition());}
2878 } catch (ParseException e) {
2879 errorMessage = "';' expected after 'continue' statement";
2881 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2882 errorEnd = jj_input_stream.getPosition() + 1;
2887 ReturnStatement ReturnStatement() :
2889 Expression expr = null;
2890 final int pos = SimpleCharStream.getPosition();
2893 <RETURN> [ expr = Expression() ]
2896 {return new ReturnStatement(expr,pos,SimpleCharStream.getPosition());}
2897 } catch (ParseException e) {
2898 errorMessage = "';' expected after 'return' statement";
2900 errorStart = jj_input_stream.getPosition() - e.currentToken.next.image.length() + 1;
2901 errorEnd = jj_input_stream.getPosition() + 1;