[Haskell-cafe] Parsec problem

Derek Gladding derek at solidmath.com
Wed Jun 6 12:52:37 EDT 2007

Neil Mitchell wrote:
 > Hi,
 > I'm using parsec to parse something which is either a "name" or a
 > "type". The particular test string I'm using is a type, but isn't a
 > name. I want things to default to "name" before "type".

I just finished a parsec grammar for C99, and found this very useful 
while bringing it up:

  mtrace_enabled = False

  mtrace n p = if mtrace_enabled then
                   trace ("-> trying to match: " ++ n)
                         $ choice [do {a <- p; return (trace ("<- 
matched: " ++ n ++ "(" ++ show a ++ ")") a)},
                                    fail ("<- failed to match " ++ n)]


  expression = mtrace "expression"
               (do {a <- chainl1 assignment_expression comma_op; return a})

Oh, and hello-and-delurk :)

- Derek

More information about the Haskell-Cafe mailing list