[Biophp-dev] Abstracting the parser backend

biophp-dev@bioinformatics.org biophp-dev@bioinformatics.org
Tue, 29 Apr 2003 20:54:00 PST

> The fact that I can treat an ftp or http url or socket like a filehandle
> is one of the feature I abuse the heck out of in PHP...the only relevant
> difference here is that there's no way to feasibly read back to the
> previous record (without reading the whole stream into memory first), 

Well, you could use the 'file' comment (which in effect, would read the
whole thing into memory).  

A thought about streams versus arrays.  The Parse class now holds
pointers to its relevant lines in the array $index.  Why not simply hold
pointers to the appropriate position in a stream whenever you deal with a 
stream?  All that would be needed would be some wrapper functions for the 
functions next, key, each, current (all used now to navigate through
arrays).  If we work with an array, we'll use the normal array functions, 
if we have a stream, we'll do an fgets and ftell and fseek (through the
wrapper).  That would make streams and arrays the same thing from the
viewpoint of the parser classes.  

This doesn't fit your idea to have parser functions that can be
completely independent, but it will make it pretty darn easy to write
parsers that can take any data source.