From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: To: 9fans@cse.psu.edu Subject: Re: [9fans] OT: small xml parser found! From: rog@vitanuova.com In-Reply-To: <1077206087.1790.18.camel@pc118> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Date: Thu, 19 Feb 2004 17:15:44 +0000 Topicbox-Message-UUID: eedc128e-eacc-11e9-9e20-41e7f4b1d025 > >> Why isn't Expat suitable? > > > > callbacks are horrible. > > Reasons?. > > Callback-(handler)s are interrupt-(handler)s > [...] can i just add this reference: http://www.codepedia.com/wiki/display.aspx?WikiID=1&pagename=thunks as an example of a really nasty way (note the machine dependent bit) of getting around some of the limitations of a callback-based system. if i was going to use expat, i'd wrap it up with the plan 9 threads library, so that constructs would arrive on a channel, then at least things would be marginally more bearable. but even then, you'd probably want to put a function call interface around the channel, as otherwise it's really quite awkward skipping subtrees you don't want to know about. i wasn't too dissatisfied with the xml(2) interface in inferno, which looks something like (limbo syntax, i'm afraid): open: fn(fd: ref Sys->FD): ref Parser; Parser: adt { next: fn(p: self ref Parser): ref Item; down: fn(p: self ref Parser); up: fn(p: self ref Parser); }; next() gives you the next item at the current level (nil if we're at the end of the enclosing block); down() delves into the most recently returned element, and up() ascends a level. one advantage of doing it this way is that potentially the parser can drive how the parsing takes place; the above interface takes advantage of that by allowing random access into the XML (you can go back to a place you've previously marked).