Finalizing D2

Daniel Keep daniel.keep.lists at gmail.com
Sun May 24 00:22:47 PDT 2009



Michel Fortin wrote:
> On 2009-05-23 01:25:49 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> said:
> 
>> * std.xml: replace with something that moves faster than molasses.
> 
> I started to write an XML parser using D1 and a pseudo-range
> implementation a little while ago, but never finished it. (I was
> undecided about the API, and that somewhat killed my interest.)
> 
> Perhaps I should finish it and contribute to Phobos.
> 
> The irking thing about the API was that if I expose a range for parsing
> and returning tokens, I then need a switch statement to do the right
> thing about each kind of these tokens (like instantiating the proper
> node type) whereas with a callback API you don't need to bother saving
> and then switching on a flag value telling you which kind of node you've
> read (and callbacks can be aliases in templates). They are two different
> compromises between speed and flexibility and I guess both should be
> supported.

Callbacks are "easier" to set up, but are incredibly complicated for any
sort of structured parsing.  The problem is that you can't easily change
the behaviour of the parser once it's started.

I had to write a SAX parser for a structured data format a few years
ago.  I swear that 90% of the code (and it's a monstrously huge module)
was just boilerplate to work around the bloody callback system.  I've
come to the conclusion that the SAX api is about the worse POSSIBLE way
of parsing anything more complex than a flat file that shouldn't have
been XML in the first place.

Something like Tango's PullParser is the superior API because although
it's more verbose up-front, that's as bad as it gets.  Plus, you can
actually do stuff like call subroutines.



More information about the Digitalmars-d mailing list