import net.sourceforge.phpeclipse.actions.PHPStartApacheAction;
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
+import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren;
+import net.sourceforge.phpdt.internal.compiler.parser.PHPFunctionDeclaration;
+import net.sourceforge.phpdt.internal.compiler.parser.PHPClassDeclaration;
/**
* A new php parser.
*/
public class PHPParser extends PHPParserSuperclass {
- private static PHPParser me;
-
private static IFile fileToParse;
+ /** The current segment */
+ private static PHPSegmentWithChildren currentSegment;
+
private static final String PARSE_ERROR_STRING = "Parse error"; //$NON-NLS-1$
private static final String PARSE_WARNING_STRING = "Warning"; //$NON-NLS-1$
public static final int ERROR = 2;
public PHPParser() {
}
- public static PHPParser getInstance(IFile fileToParse) {
- if (me == null) {
- me = new PHPParser(fileToParse);
- } else {
- me.setFileToParse(fileToParse);
- }
- return me;
- }
-
public void setFileToParse(IFile fileToParse) {
this.fileToParse = fileToParse;
}
- public static PHPParser getInstance(java.io.Reader stream) {
- if (me == null) {
- me = new PHPParser(stream);
- } else {
- me.ReInit(stream);
- }
- return me;
- }
-
public PHPParser(IFile fileToParse) {
this(new StringReader(""));
this.fileToParse = fileToParse;
public PHPOutlineInfo parseInfo(Object parent, String s) {
outlineInfo = new PHPOutlineInfo(parent);
+ currentSegment = outlineInfo.getDeclarations();
StringReader stream = new StringReader(s);
if (jj_input_stream == null) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
try {
parse();
} catch (ParseException e) {
- PHPeclipsePlugin.log(e);
+ if (errorMessage == null) {
+ PHPeclipsePlugin.log(e);
+ } else {
+ setMarker(errorMessage, e.currentToken.beginLine, errorLevel);
+ errorMessage = null;
+ }
}
}
}
void ClassDeclaration() :
-{}
{
- <CLASS> <IDENTIFIER> [ <EXTENDS> <IDENTIFIER> ]
+ PHPClassDeclaration classDeclaration;
+ Token className;
+ int pos = jj_input_stream.bufpos;
+}
+{
+ <CLASS> className = <IDENTIFIER> [ <EXTENDS> <IDENTIFIER> ]
+ {
+ classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos);
+ currentSegment.add(classDeclaration);
+ currentSegment = classDeclaration;
+ }
ClassBody()
+ {
+ currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
+ }
}
void ClassBody() :
}
void MethodDeclaration() :
-{}
{
- <FUNCTION> MethodDeclarator()
+ PHPFunctionDeclaration functionDeclaration;
+}
+{
+ <FUNCTION> functionDeclaration = MethodDeclarator()
+ {
+ currentSegment.add(functionDeclaration);
+ currentSegment = functionDeclaration;
+ }
( Block() | <SEMICOLON> )
+ {
+ currentSegment = (PHPSegmentWithChildren) currentSegment.getParent();
+ }
}
-void MethodDeclarator() :
-{}
+PHPFunctionDeclaration MethodDeclarator() :
+{
+ Token bit_and = null;
+ Token identifier;
+ StringBuffer methodDeclaration = new StringBuffer();
+ String formalParameters;
+ int pos = jj_input_stream.bufpos;
+}
{
- [<BIT_AND>] <IDENTIFIER> FormalParameters()
+ [ bit_and = <BIT_AND>]
+ identifier = <IDENTIFIER> FormalParameters()
+ {
+ if (bit_and != null) {
+ methodDeclaration.append("&");
+ }
+ methodDeclaration.append(identifier);
+ return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos);
+ }
}
void FormalParameters() :
void Arguments() :
{}
{
- <LPAREN> [ ArgumentList() ] <RPAREN>
+ <LPAREN> [ ArgumentList() ]
+ try {
+ <RPAREN>
+ } catch (ParseException e) {
+ errorMessage = "')' expected to close the argument list";
+ errorLevel = ERROR;
+ throw e;
+ }
}
void ArgumentList() :
{}
{
- Expression() ( <COMMA> Expression() )*
+ Expression()
+ ( <COMMA>
+ try {
+ Expression()
+ } catch (ParseException e) {
+ errorMessage = "expression expected after a comma in argument list";
+ errorLevel = ERROR;
+ throw e;
+ }
+ )*
}
/*