4 patches for repository http://code.haskell.org/parsec3: Sun Feb 20 18:24:22 EET 2011 Roman Cheplyaka * Choose the longest match when merging error messages Sun Feb 20 18:24:49 EET 2011 Roman Cheplyaka * try: do not reset the error position Sun Feb 20 18:29:20 EET 2011 Roman Cheplyaka * lookAhead: do not consume input on success; update documentation Sun Feb 20 19:30:26 EET 2011 Roman Cheplyaka * Improve New patches: [Choose the longest match when merging error messages Roman Cheplyaka **20110220162422 Ignore-this: 54e2733159a1574abb229e09ff6935c1 ] hunk ./Text/Parsec/Error.hs 137 = ParseError pos (msg : filter (msg /=) msgs) mergeError :: ParseError -> ParseError -> ParseError -mergeError (ParseError pos msgs1) (ParseError _ msgs2) - = ParseError pos (msgs1 ++ msgs2) +mergeError (ParseError pos1 msgs1) (ParseError pos2 msgs2) + = case pos1 `compare` pos2 of + -- select the longest match + EQ -> ParseError pos1 (msgs1 ++ msgs2) + GT -> ParseError pos1 msgs1 + LT -> ParseError pos2 msgs2 instance Show ParseError where show err [try: do not reset the error position Roman Cheplyaka **20110220162449 Ignore-this: 8508bc41fc6dcd9b7c06aac762f12c71 ] hunk ./Text/Parsec/Prim.hs 435 try :: ParsecT s u m a -> ParsecT s u m a try p = - ParsecT $ \s@(State _ pos _) cok _ eok eerr -> - let pcerr parseError = eerr $ setErrorPos pos parseError - in unParser p s cok pcerr eok eerr + ParsecT $ \s cok _ eok eerr -> + unParser p s cok eerr eok eerr -- | The parser @tokenPrim showTok posFromTok testTok@ accepts a token @t@ -- with result @x@ when the function @testTok t@ returns @'Just' x@. The [lookAhead: do not consume input on success; update documentation Roman Cheplyaka **20110220162920 Ignore-this: e884771490209b93e9fec044543a18ef ] { hunk ./Text/Parsec/Combinator.hs 279 <|> do{ x <- p; xs <- scan; return (x:xs) } --- | @lookAhead p@ parses @p@ without consuming any input. - -lookAhead :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m a -lookAhead p = do{ state <- getParserState - ; x <- p - ; setParserState state - ; return x - } - hunk ./Text/Parsec/Prim.hs 40 , (<|>) , label , labels + , lookAhead , Stream(..) , tokens , try hunk ./Text/Parsec/Prim.hs 439 ParsecT $ \s cok _ eok eerr -> unParser p s cok eerr eok eerr +-- | @lookAhead p@ parses @p@ without consuming any input. +-- +-- If @p@ fails and consumes some input, so does @lookAhead@. Combine with 'try' +-- if this is undesirable. + +lookAhead :: (Stream s m t) => ParsecT s u m a -> ParsecT s u m a +lookAhead p = do{ state <- getParserState + ; x <- p' + ; setParserState state + ; return x + } + where + p' = ParsecT $ \s cok cerr eok eerr -> + unParser p s eok cerr eok eerr + -- | The parser @tokenPrim 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 } [Improve Roman Cheplyaka **20110220173026 Ignore-this: b147dad8729f0a8f22b7149559d6b243 ] hunk ./Text/Parsec/Prim.hs 315 -- letter', which is less friendly. () :: (ParsecT s u m a) -> String -> (ParsecT s u m a) -p msg = label p msg +p msg = ParsecT $ \s cok cerr eok eerr -> + let parseError = newErrorMessage (Expect msg) (statePos s) + eok' x s' _ = eok x s' parseError + eerr' _ = eerr parseError + in unParser p s cok cerr eok' eerr' -- | This combinator implements choice. The parser @p \<|> q@ first -- applies @p@. If it succeeds, the value of @p@ is returned. If @p@ Context: [TAG 3.1.1 Antoine Latter **20110129160030 Ignore-this: 42ddc9e7316d68945c2c1260c2acd403 ] Patch bundle hash: 52077d12002c2820c33c39701e01ead8de62c61e