new version of parser combinators

S. Doaitse Swierstra doaitse@cs.uu.nl
Sat, 23 Jun 2001 10:31:57 +0200


We have been working hard on new versions of the Parser Combinators 
and AG system, with the following improvements:

      even better error repairs
      much faster and simpler basic parsing machine
      permutation (of different types) and list combinators
      extensive reporting about repairs made and what was expected
      the possibility to manipulate your own state during parsing
       and result construction, using classed based (like monads) interfaces

As an example of the permutation combinators we parse a permutation 
of three elements:

   1) a list of 'a's
   2) a 'b'
   3) an optional 'c'

which is described by:

permtest :: Parser Char (String, Char, Char)
permtest = permute $ (,,) ~$~ pList (pSym 'a') ~*~ pSym 'b' ~*~ pOptSym 'c'

pOptSym :: Char -> Parser Char Char
pOptSym x = pSym x <|> pSucceed '_'


which we try on several inputs resulting in:

t permtest "acb"
Result:
("a",'b','c')

t permtest "cdaa"
Errors:
Symbol 'd' before 'a' was deleted, because 'b' or ('a')* was expected.
Symbol 'b' was inserted  at end of file, because 'a' or 'b' was expected.
Result:
("aa",'b','c')

t permtest "abd"
Errors:
Symbol 'd' at end of file was deleted, because 'c' or eof was expected.
Result:
("a",'b','_')

t permtest ""
Errors:
Symbol 'b' was inserted  at end of file, because 'c' or 'b' or ('a')* 
was expected.
Result:
("",'b','_')

The manual is still of an earlier version and will be adapted soon. 
As an example of the combinators we provide a parser for bibtex 
files, that returns the repairs made to the erroneous  entries (as 
far as we understand the bibtex format).


   I hope this is useful to you,
    Doaitse Swierstra