Doug:

Thanks for your reply.

I think I have a similar problem to yours.  XML only provides the
skeleton of the language but there are structural aspects that the XML
tags do not express.  The language I'm parsing is essentially
a language of mathematical expressions, so you might see

        a+<fraction><denominator>c+d</denominator>
                    <numerator>e+f</numerator>
          </fraction>+g

The way I'm doing this is to use XMLLib's parser to create a tree 
(a "document object") and then using a parsing monad to "reparse" the tree
of strings into a full abstract syntax tree.  Since most combinator parser
systems and monadic parser systems expect their inputs to be strings rather
than lists of trees, I had to write my own Monad; but that wasn't so hard.  For
example, there is a combinator
        (<?>) :: String -> (Reparser a) -> (Reparser a)
which can be used thusly:

parseFraction = -- Succeeds only if the next content item is a
                -- well formed fraction element.
        "fraction" <?> (do d <- parseDenominator
                           n <- parseNumerator
                           endP -- ensure no spurious content in the element
                           return (Fraction d n) )

I'd be happy to send you the reparsing monad, if you like.  I wrote it
a while ago, so it may not be compatible with the latest version
of XMLLib (HaXml?). Unlike Daan and Manual, I'm unable to claim that it is
adequately documented or efficient.

To answer Chris's question. One could easily use this reparsing
monad to flatten the tree into a sequence of SAX tokens.  How lazy it
would be depend on the underlying XML parser.

Cheers,
Theodore Norvell

----------------------------
Dr. Theodore Norvell                                    [EMAIL PROTECTED]
Electrical and Computer Engineering         http://www.engr.mun.ca/~theo
Engineering and Applied Science                    Phone: (709) 737-8962
Memorial University of Newfoundland                  Fax: (709) 737-4042
St. John's, NF, Canada, A1B 3X5

Reply via email to