trifecta 1.5.2 → 1.6
raw patch · 15 files changed
+71/−60 lines, 15 filesdep ~basedep ~comonaddep ~transformersnew-uploader
Dependency ranges changed: base, comonad, transformers
Files
- LICENSE +1/−1
- src/Text/Trifecta.hs +1/−2
- src/Text/Trifecta/Combinators.hs +1/−1
- src/Text/Trifecta/Delta.hs +0/−1
- src/Text/Trifecta/Highlight.hs +1/−2
- src/Text/Trifecta/Instances.hs +1/−2
- src/Text/Trifecta/Parser.hs +19/−12
- src/Text/Trifecta/Rendering.hs +1/−2
- src/Text/Trifecta/Result.hs +36/−24
- src/Text/Trifecta/Rope.hs +2/−3
- src/Text/Trifecta/Util/Array.hs +0/−1
- src/Text/Trifecta/Util/Combinators.hs +1/−2
- src/Text/Trifecta/Util/IntervalMap.hs +1/−1
- src/Text/Trifecta/Util/It.hs +1/−1
- trifecta.cabal +5/−5
LICENSE view
@@ -1,4 +1,4 @@-Copyright 2010-2014 Edward Kmett+Copyright 2010-2015 Edward Kmett Copyright 2008 Ross Patterson Copyright 2007 Paolo Martini Copyright 1999-2000 Daan Leijen
src/Text/Trifecta.hs view
@@ -1,7 +1,6 @@ ----------------------------------------------------------------------------- -- |--- Module : Text.Trifecta--- Copyright : (C) 2011-2014 Edward Kmett,+-- Copyright : (C) 2011-2015 Edward Kmett -- License : BSD-style (see the file LICENSE) -- -- Maintainer : Edward Kmett <ekmett@gmail.com>
src/Text/Trifecta/Combinators.hs view
@@ -6,7 +6,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Text.Trifecta.Combinators--- Copyright : (c) Edward Kmett 2011-2014+-- Copyright : (c) Edward Kmett 2011-2015 -- License : BSD3 -- -- Maintainer : ekmett@gmail.com
src/Text/Trifecta/Delta.hs view
@@ -3,7 +3,6 @@ {-# LANGUAGE DeriveGeneric #-} ----------------------------------------------------------------------------- -- |--- Module : Text.Trifecta.Delta -- Copyright : (C) 2011-2015 Edward Kmett -- License : BSD-style (see the file LICENSE) --
src/Text/Trifecta/Highlight.hs view
@@ -7,8 +7,7 @@ #endif ----------------------------------------------------------------------------- -- |--- Module : Text.Trifecta.Highlight--- Copyright : (C) 2011-2014 Edward Kmett+-- Copyright : (C) 2011-2015 Edward Kmett -- License : BSD-style (see the file LICENSE) -- -- Maintainer : Edward Kmett <ekmett@gmail.com>
src/Text/Trifecta/Instances.hs view
@@ -1,8 +1,7 @@ {-# OPTIONS_GHC -fno-warn-orphans #-} ----------------------------------------------------------------------------- -- |--- Module : Text.Trifecta.Instances--- Copyright : (c) Edward Kmett 2013-2014+-- Copyright : (c) Edward Kmett 2013-2015 -- License : BSD3 -- -- Maintainer : ekmett@gmail.com
src/Text/Trifecta/Parser.hs view
@@ -10,8 +10,7 @@ {-# LANGUAGE TemplateHaskell #-} ----------------------------------------------------------------------------- -- |--- Module : Text.Trifecta.Parser--- Copyright : (c) Edward Kmett 2011-2014+-- Copyright : (c) Edward Kmett 2011-2015 -- License : BSD3 -- -- Maintainer : ekmett@gmail.com@@ -66,7 +65,7 @@ (a -> Err -> It Rope r) -> (Err -> It Rope r) -> (a -> Set String -> Delta -> ByteString -> It Rope r) -> -- committed success- (Doc -> It Rope r) -> -- committed err+ (ErrInfo -> It Rope r) -> -- committed err Delta -> ByteString -> It Rope r } @@ -109,7 +108,11 @@ m (\a e -> unparser (k a) (\b e' -> eo b (e <> e')) (\e' -> ee (e <> e')) co ce d bs) ee (\a es d' bs' -> unparser (k a) (\b e' -> co b (es <> _expected e') d' bs')- (\e -> ce (explain (renderingCaret d' bs') e { _expected = _expected e <> es }))+ (\e ->+ let errDoc = explain (renderingCaret d' bs') e { _expected = _expected e <> es }+ errDelta = _finalDeltas e+ in ce $ ErrInfo errDoc (d' : errDelta)+ ) co ce d' bs') ce d bs {-# INLINE (>>=) #-} (>>) = (*>)@@ -126,7 +129,8 @@ manyAccum :: (a -> [a] -> [a]) -> Parser a -> Parser [a] manyAccum f (Parser p) = Parser $ \eo _ co ce d bs -> let walk xs x es d' bs' = p (manyErr d' bs') (\e -> co (f x xs) (_expected e <> es) d' bs') (walk (f x xs)) ce d' bs'- manyErr d' bs' _ e = ce $ explain (renderingCaret d' bs') (e <> failed "'many' applied to a parser that accepted an empty string")+ manyErr d' bs' _ e = ce (ErrInfo errDoc [d'])+ where errDoc = explain (renderingCaret d' bs') (e <> failed "'many' applied to a parser that accepted an empty string") in p (manyErr d bs) (eo []) (walk []) ce d bs liftIt :: It Rope a -> Parser a@@ -203,7 +207,7 @@ data Step a = StepDone !Rope a- | StepFail !Rope Doc+ | StepFail !Rope ErrInfo | StepCont !Rope (Result a) (Rope -> Step a) instance Show a => Show (Step a) where@@ -246,21 +250,24 @@ = EO a Err | EE Err | CO a (Set String) Delta ByteString- | CE Doc+ | CE ErrInfo stepParser :: Parser a -> Delta -> ByteString -> Step a stepParser (Parser p) d0 bs0 = go mempty $ p eo ee co ce d0 bs0 where eo a e = Pure (EO a e) ee e = Pure (EE e) co a es d bs = Pure (CO a es d bs)- ce doc = Pure (CE doc)+ ce errInf = Pure (CE errInf) go r (Pure (EO a _)) = StepDone r a- go r (Pure (EE e)) = StepFail r $ explain (renderingCaret d0 bs0) e+ go r (Pure (EE e)) = StepFail r $+ let errDoc = explain (renderingCaret d0 bs0) e+ in ErrInfo errDoc (_finalDeltas e) go r (Pure (CO a _ _ _)) = StepDone r a go r (Pure (CE d)) = StepFail r d go r (It ma k) = StepCont r (case ma of EO a _ -> Success a- EE e -> Failure $ explain (renderingCaret d0 bs0) e+ EE e -> Failure $+ ErrInfo (explain (renderingCaret d0 bs0) e) (d0 : _finalDeltas e) CO a _ _ _ -> Success a CE d -> Failure d ) (go <*> k)@@ -281,7 +288,7 @@ case result of Success a -> return (Just a) Failure xs -> do- liftIO $ displayIO stdout $ renderPretty 0.8 80 $ xs <> linebreak+ liftIO $ displayIO stdout $ renderPretty 0.8 80 $ (_errDoc xs) <> linebreak return Nothing -- | @parseFromFileEx p filePath@ runs a parser @p@ on the@@ -310,5 +317,5 @@ parseTest :: (MonadIO m, Show a) => Parser a -> String -> m () parseTest p s = case parseByteString p mempty (UTF8.fromString s) of- Failure xs -> liftIO $ displayIO stdout $ renderPretty 0.8 80 $ xs <> linebreak -- TODO: retrieve columns+ Failure xs -> liftIO $ displayIO stdout $ renderPretty 0.8 80 $ (_errDoc xs) <> linebreak -- TODO: retrieve columns Success a -> liftIO (print a)
src/Text/Trifecta/Rendering.hs view
@@ -6,8 +6,7 @@ {-# LANGUAGE DeriveGeneric #-} ----------------------------------------------------------------------------- -- |--- Module : Text.Trifecta.Rendering--- Copyright : (C) 2011-2014 Edward Kmett+-- Copyright : (C) 2011-2015 Edward Kmett -- License : BSD-style (see the file LICENSE) -- -- Maintainer : Edward Kmett <ekmett@gmail.com>
src/Text/Trifecta/Result.hs view
@@ -11,8 +11,7 @@ {-# LANGUAGE UndecidableInstances #-} ----------------------------------------------------------------------------- -- |--- Module : Text.Trifecta.Result--- Copyright : (c) Edward Kmett 2011-2014+-- Copyright : (c) Edward Kmett 2011-2015 -- License : BSD3 -- -- Maintainer : ekmett@gmail.com@@ -30,6 +29,7 @@ , _Failure -- * Parsing Errors , Err(..), HasErr(..), Errable(..)+ , ErrInfo(..) , explain , failed ) where@@ -47,35 +47,41 @@ import Text.Trifecta.Rendering import Text.Trifecta.Delta as Delta +data ErrInfo = ErrInfo+ { _errDoc :: Doc+ , _errDeltas :: [Delta]+ } deriving(Show)+ -- | This is used to report an error. What went wrong, some supplemental docs and a set of things expected -- at the current location. This does not, however, include the actual location. data Err = Err- { _reason :: Maybe Doc- , _footnotes :: [Doc]- , _expected :: Set String+ { _reason :: Maybe Doc+ , _footnotes :: [Doc]+ , _expected :: Set String+ , _finalDeltas :: [Delta] } makeClassy ''Err instance Semigroup Err where- Err md mds mes <> Err nd nds nes- = Err (nd <|> md) (if isJust nd then nds else if isJust md then mds else nds ++ mds) (mes <> nes)+ Err md mds mes delta1 <> Err nd nds nes delta2+ = Err (nd <|> md) (if isJust nd then nds else if isJust md then mds else nds ++ mds) (mes <> nes) (delta1 <> delta2) {-# INLINE (<>) #-} instance Monoid Err where- mempty = Err Nothing [] mempty+ mempty = Err Nothing [] mempty mempty {-# INLINE mempty #-} mappend = (<>) {-# INLINE mappend #-} -- | Generate a simple 'Err' word-wrapping the supplied message. failed :: String -> Err-failed m = Err (Just (fillSep (pretty <$> words m))) [] mempty+failed m = Err (Just (fillSep (pretty <$> words m))) [] mempty mempty {-# INLINE failed #-} -- | Convert a location and an 'Err' into a 'Doc' explain :: Rendering -> Err -> Doc-explain r (Err mm as es)+explain r (Err mm as es _) | Set.null es = report (withEx mempty) | isJust mm = report $ withEx $ Pretty.char ',' <+> expecting | otherwise = report expecting@@ -92,10 +98,14 @@ class Errable m where raiseErr :: Err -> m a +instance Monoid ErrInfo where+ mempty = ErrInfo mempty mempty+ mappend (ErrInfo xs d1) (ErrInfo ys d2) = ErrInfo (vsep [xs, ys]) (max d1 d2)+ -- | The result of parsing. Either we succeeded or something went wrong. data Result a = Success a- | Failure Doc+ | Failure ErrInfo deriving (Show,Functor,Foldable,Traversable) -- | A 'Prism' that lets you embed or retrieve a 'Result' in a potentially larger type.@@ -110,34 +120,36 @@ _Success :: AsResult s t a b => Prism s t a b _Success = _Result . dimap seta (either id id) . right' . rmap (fmap Success) where seta (Success a) = Right a- seta (Failure d) = Left (pure (Failure d))+ seta (Failure e) = Left (pure (Failure e)) {-# INLINE _Success #-} -- | The 'Prism' for the 'Failure' constructor of 'Result'-_Failure :: AsResult s s a a => Prism' s Doc+_Failure :: AsResult s s a a => Prism' s ErrInfo _Failure = _Result . dimap seta (either id id) . right' . rmap (fmap Failure) where- seta (Failure d) = Right d+ seta (Failure e) = Right e seta (Success a) = Left (pure (Success a)) {-# INLINE _Failure #-} instance Show a => Pretty (Result a) where- pretty (Success a) = pretty (show a)- pretty (Failure xs) = pretty xs+ pretty (Success a) = pretty (show a)+ pretty (Failure xs) = pretty . _errDoc $ xs instance Applicative Result where pure = Success {-# INLINE pure #-}- Success f <*> Success a = Success (f a)- Success _ <*> Failure ys = Failure ys- Failure xs <*> Success _ = Failure xs- Failure xs <*> Failure ys = Failure $ vsep [xs, ys]+ Success f <*> Success a = Success (f a)+ Success _ <*> Failure y = Failure y+ Failure x <*> Success _ = Failure x+ Failure x <*> Failure y =+ Failure $ ErrInfo (vsep [_errDoc x, _errDoc y]) (_errDeltas x <> _errDeltas y) {-# INLINE (<*>) #-} instance Alternative Result where- Failure xs <|> Failure ys = Failure $ vsep [xs, ys]- Success a <|> Success _ = Success a- Success a <|> Failure _ = Success a- Failure _ <|> Success a = Success a+ Failure x <|> Failure y =+ Failure $ ErrInfo (vsep [_errDoc x, _errDoc y]) (_errDeltas x <> _errDeltas y)+ Success a <|> Success _ = Success a+ Success a <|> Failure _ = Success a+ Failure _ <|> Success a = Success a {-# INLINE (<|>) #-} empty = Failure mempty {-# INLINE empty #-}
src/Text/Trifecta/Rope.hs view
@@ -1,8 +1,7 @@-{-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances, BangPatterns, PatternGuards, DeriveDataTypeable, DeriveGeneric #-}+{-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances, BangPatterns, DeriveDataTypeable, DeriveGeneric #-} ----------------------------------------------------------------------------- -- |--- Module : Text.Trifecta.Rope--- Copyright : (C) 2011-2014 Edward Kmett+-- Copyright : (C) 2011-2015 Edward Kmett -- License : BSD-style (see the file LICENSE) -- -- Maintainer : Edward Kmett <ekmett@gmail.com>
src/Text/Trifecta/Util/Array.hs view
@@ -1,7 +1,6 @@ {-# LANGUAGE BangPatterns, CPP, MagicHash, Rank2Types, UnboxedTuples #-} ----------------------------------------------------------------------------- -- |--- Module : Text.Trifecta.Util.Array -- Copyright : Edward Kmett 2011-2015 -- Johan Tibell 2011 -- License : BSD3
src/Text/Trifecta/Util/Combinators.hs view
@@ -1,7 +1,6 @@ ----------------------------------------------------------------------------- -- |--- Module : Text.Trifecta.Util.Combinators--- Copyright : (C) 2011-2014 Edward Kmett+-- Copyright : (C) 2011-2015 Edward Kmett -- License : BSD-style (see the file LICENSE) -- -- Maintainer : Edward Kmett <ekmett@gmail.com>
src/Text/Trifecta/Util/IntervalMap.hs view
@@ -9,7 +9,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Text.Trifecta.Util.IntervalMap--- Copyright : (c) Edward Kmett 2011-2014+-- Copyright : (c) Edward Kmett 2011-2015 -- (c) Ross Paterson 2008 -- License : BSD-style -- Maintainer : ekmett@gmail.com
src/Text/Trifecta/Util/It.hs view
@@ -7,7 +7,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Text.Trifecta.Util.It--- Copyright : (C) 2011-2014 Edward Kmett+-- Copyright : (C) 2011-2015 Edward Kmett -- License : BSD-style (see the file LICENSE) -- -- Maintainer : Edward Kmett <ekmett@gmail.com>
trifecta.cabal view
@@ -1,6 +1,6 @@ name: trifecta category: Text, Parsing, Diagnostics, Pretty Printer, Logging-version: 1.5.2+version: 1.6 license: BSD3 cabal-version: >= 1.10 license-file: LICENSE@@ -9,7 +9,7 @@ stability: experimental homepage: http://github.com/ekmett/trifecta/ bug-reports: http://github.com/ekmett/trifecta/issues-copyright: Copyright (C) 2010-2014 Edward A. Kmett+copyright: Copyright (C) 2010-2015 Edward A. Kmett synopsis: A modern parser combinator library with convenient diagnostics description: A modern parser combinator library with slicing and Clang-style colored diagnostics@@ -50,7 +50,7 @@ blaze-markup >= 0.5 && < 0.8, bytestring >= 0.9.1 && < 0.11, charset >= 0.3.5.1 && < 1,- comonad >= 4 && < 5,+ comonad >= 4 && < 6, containers >= 0.3 && < 0.6, deepseq >= 1.2.0.1 && < 1.5, fingertree >= 0.1 && < 0.2,@@ -62,13 +62,13 @@ profunctors >= 4.0 && < 6, reducers >= 3.10 && < 4, semigroups >= 0.8.3.1 && < 1,- transformers >= 0.2 && < 0.5,+ transformers >= 0.2 && < 0.6, unordered-containers >= 0.2.1 && < 0.3, utf8-string >= 0.3.6 && < 1.1 default-language: Haskell2010 hs-source-dirs: src- ghc-options: -O2 -Wall+ ghc-options: -O2 -Wall -fobject-code test-suite doctests