Daniel Fischer wrote: > On Wednesday 29 September 2010 19:10:22, Ben Franksen wrote: >> > >> > Note the last line mentions only '}'. I would rather like to see >> > >> > expecting "}" or digit >> > >> > since the parser could very well accept another digit here. > > parsec2 did that, I don't know whether that change is intentional or > accidental.
This looks more like a bug than a feature to me. I checked parsec-3.0.1 and it behaves like parsec-2, i.e. behaves as I expected. >> > (1) What is the reason for this behaviour? >> > (2) Is there another combinator that behaves as I would like? >> > (3) Otherwise, how do I write one myself? >> >> I just saw that Christian Maeder answered a similar question recently. I >> >> tried his suggestion of using manyTill and bingo: >> > {-# LANGUAGE NoMonomorphismRestriction #-} >> > import Control.Applicative ((*>),(<*)) >> > import Text.Parsec >> > block p = char '{' *> p <* char '}' >> > parser = block (manyTill digit (char '}')) >> > main = parseTest parser "{123a}" > You would need > > block (manyTill digit (lookAhead (char '}')) > > to replicate the behaviour of block (many digit). Right, so it gets even more complicated. >> Is there a non-greedy variant of 'many' so >> that modularity gets restored and efficiency is not lost? So many questions... Cheers Ben _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe