From: kpouer Date: Sun, 2 Mar 2003 17:06:24 +0000 (+0000) Subject: Far better but not finished, it will now get function and class declaration in outline X-Git-Url: http://secure.phpeclipse.com Far better but not finished, it will now get function and class declaration in outline --- diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj index e62d7e8..306f21d 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -35,6 +35,9 @@ import java.text.MessageFormat; 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. @@ -45,10 +48,11 @@ import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; */ 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; @@ -61,28 +65,10 @@ public class PHPParser extends PHPParserSuperclass { 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; @@ -109,6 +95,7 @@ public class PHPParser extends PHPParserSuperclass { 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); @@ -227,7 +214,12 @@ public class PHPParser extends PHPParserSuperclass { try { parse(); } catch (ParseException e) { - PHPeclipsePlugin.log(e); + if (errorMessage == null) { + PHPeclipsePlugin.log(e); + } else { + setMarker(errorMessage, e.currentToken.beginLine, errorLevel); + errorMessage = null; + } } } @@ -555,10 +547,22 @@ void Php() : } void ClassDeclaration() : -{} { - [ ] + PHPClassDeclaration classDeclaration; + Token className; + int pos = jj_input_stream.bufpos; +} +{ + className = [ ] + { + classDeclaration = new PHPClassDeclaration(currentSegment,className.image,pos); + currentSegment.add(classDeclaration); + currentSegment = classDeclaration; + } ClassBody() + { + currentSegment = (PHPSegmentWithChildren) currentSegment.getParent(); + } } void ClassBody() : @@ -630,16 +634,39 @@ void ArrayInitializer() : } void MethodDeclaration() : -{} { - MethodDeclarator() + PHPFunctionDeclaration functionDeclaration; +} +{ + functionDeclaration = MethodDeclarator() + { + currentSegment.add(functionDeclaration); + currentSegment = functionDeclaration; + } ( Block() | ) + { + 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; +} { - [] FormalParameters() + [ bit_and = ] + identifier = FormalParameters() + { + if (bit_and != null) { + methodDeclaration.append("&"); + } + methodDeclaration.append(identifier); + return new PHPFunctionDeclaration(currentSegment,methodDeclaration.toString(),pos); + } } void FormalParameters() : @@ -905,13 +932,29 @@ void NullLiteral() : void Arguments() : {} { - [ ArgumentList() ] + [ ArgumentList() ] + try { + + } catch (ParseException e) { + errorMessage = "')' expected to close the argument list"; + errorLevel = ERROR; + throw e; + } } void ArgumentList() : {} { - Expression() ( Expression() )* + Expression() + ( + try { + Expression() + } catch (ParseException e) { + errorMessage = "expression expected after a comma in argument list"; + errorLevel = ERROR; + throw e; + } + )* } /*