1 patch for repository http://code.haskell.org/parsec3: Thu Sep 5 11:12:47 CEST 2013 Petr Pudlak * Add 'emptyIf' which allows a parser to optinally fail without consuming any input. New patches: [Add 'emptyIf' which allows a parser to optinally fail without consuming any input. Petr Pudlak **20130905091247 Ignore-this: 59b93c660fe860acd9a5fff887f7678f ] { hunk ./Text/Parsec/Prim.hs 38 , parserPlus , () , (<|>) + , emptyIf , label , labels , lookAhead hunk ./Text/Parsec/Prim.hs 455 p' = ParsecT $ \s cok cerr eok eerr -> unParser p s eok cerr eok eerr +-- | @emptyIf p@ parses @p@ and if its return value is @Nothing@, pretends +-- that an error has occured with no input consumed. +-- +-- If @p@ fails and consumes some input, so does @emptyIf p@. Combine with +-- 'try' if this is undesirable. + +emptyIf :: (Stream s m t) => ParsecT s u m (Maybe a) -> ParsecT s u m a +emptyIf p = ParsecT $ \s cok cerr eok eerr -> + let cok' (Just x) s e = cok x s e + cok' Nothing _ e = eerr e + eok' (Just x) s e = eok x s e + eok' Nothing _ e = eerr e + in unParser p s cok' cerr eok' eerr + + -- | The parser @token showTok posFromTok testTok@ accepts a token @t@ -- with result @x@ when the function @testTok t@ returns @'Just' x@. The -- source position of the @t@ should be returned by @posFromTok t@ and } Context: [Fix haddock module links. Bjorn Buckwalter **20130821095713 Ignore-this: 304217ec8b73f59edcd96dd13aca67af ] [TAG 3.1.3 Antoine Latter **20120612020909 Ignore-this: 7100375a3e4853c09f1ea993ae32eed7 ] Patch bundle hash: 173111b8bbc5a6eb69d41926053184c35ae9b3cc