package test; import net.sourceforge.phpdt.internal.compiler.ast.PHPDocument; import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.CoreException; import java.io.StringReader; /** * This class will handle the true php parser. * * @author Matthieu Casanova */ public class Parser extends PHPParserSuperclass implements PHPParserListener { public final PHPOutlineInfo parseInfo(final Object parent, final String s) { try { final StringReader stream = new StringReader(s); PHPParser phpParser = new PHPParser(stream); phpParser.addParserListener(this); return phpParser.parseInfo(parent, s); } catch (ParseException e) { PHPeclipsePlugin.log(e); } final PHPDocument phpDocument = new PHPDocument(parent, "_root"); return new PHPOutlineInfo(parent, phpDocument); } public void parseError(PHPParseErrorEvent e) { try { setMarker(fileToParse, e.getMessage(), e.getSourceStart(), e.getSourceEnd(), e.getLevel(), "Line " + e.getBeginLine() + ", " + e.getBeginColumn() + ':' + e.getEndColumn()); } catch (CoreException ex) { PHPeclipsePlugin.log(ex); } } public void parseMessage(PHPParseMessageEvent e) { try { setMarker(fileToParse, e.getMessage(), e.getSourceStart(), e.getSourceEnd(), e.getLevel(), "Line " + e.getBeginLine() + ", " + e.getBeginColumn() + ':' + e.getEndColumn()); } catch (CoreException ex) { PHPeclipsePlugin.log(ex); } } /* private final void init() { nodes = new AstNode[AstStackIncrement]; nodePtr = -1; htmlStart = 0; } */ public final void setFileToParse(final IFile fileToParse) { PHPParserSuperclass.fileToParse = fileToParse; } public final void parse(final String s) { final StringReader stream = new StringReader(s); PHPParser phpParser = new PHPParser(stream); phpParser.addParserListener(this); try { phpParser.parse(); } catch (ParseException e) { PHPeclipsePlugin.log(e); } } }