packages feed

trifecta 0.26 → 0.27

raw patch · 12 files changed

+68/−267 lines, 12 filesdep −interndep ~wl-pprint-terminfo

Dependencies removed: intern

Dependency ranges changed: wl-pprint-terminfo

Files

Text/Trifecta/Diagnostic/Level.hs view
@@ -43,8 +43,9 @@   pretty p = prettyTerm p *> empty  instance PrettyTerm DiagnosticLevel where-  prettyTerm (Verbose n) = blue $ text "verbose (" <> int n <> char ')'-  prettyTerm Note        = black $ text "note"+  prettyTerm (Verbose n) = blue    $ text "verbose (" <> int n <> char ')'+  prettyTerm Note        = black   $ text "note"   prettyTerm Warning     = magenta $ text "warning"-  prettyTerm Error       = red $ text "error"+  prettyTerm Error       = red            $ text "error"   prettyTerm Fatal       = standout $ red $ text "fatal"+  prettyTerm Panic       = standout $ red $ text "panic"
Text/Trifecta/Diagnostic/Rendering/Prim.hs view
@@ -135,7 +135,7 @@ instance PrettyTerm Rendering where   prettyTerm (Rendering d ll l f) = nesting $ \k -> columns $ \n -> go (n - k) where     go cols = align (vsep (P.map ln [t..b])) where -      (lo, hi) = window (column d) ll (cols - 2)+      (lo, hi) = window (column d) ll (min (max (cols - 2) 30) 200)       a = f d $ l $ array ((0,lo),(-1,hi)) []       ((t,_),(b,_)) = bounds a       ln y = hcat 
Text/Trifecta/Parser.hs view
@@ -5,15 +5,15 @@   , module Text.Trifecta.Parser.Combinators   , module Text.Trifecta.Parser.Token   , module Text.Trifecta.Parser.Result-  -- * traditional numeric literals that would be in Token-  , decimal-  , hexadecimal-  , octal-  -- * expressive diagnostics+  , module Text.Trifecta.Parser.Literals+  -- * Expressive Diagnostics+  -- ** Text.Trifecta.Diagnostic.Rendering.Caret   , caret   , careted+  -- ** Text.Trifecta.Diagnostic.Rendering.Span   , span   , spanned+  -- ** Text.Trifecta.Diagnostic.Rendering.Fixit   , fixit   ) where 
Text/Trifecta/Parser/Class.hs view
@@ -15,6 +15,7 @@   ( MonadParser(..)   , restOfLine   , (<?>)+  , skipping   , slicedWith   , sliced   , rend@@ -55,8 +56,6 @@   skipMany   :: m a -> m ()   skipMany p = () <$ many p  -  -- useful when we've just recognized something out of band using access to the current line -  skipping :: Delta -> m ()    -- actions that definitely commit   release    :: Delta -> m ()@@ -156,6 +155,11 @@ -- instance (MonadParser m, Monoid w) => MonadParser (MaybeT m) where -- instance (Error e, MonadParser m, Monoid w) => MonadParser (ErrorT e m) where +  -- useful when we've just recognized something out of band using access to the current line +skipping :: MonadParser m => Delta -> m ()+skipping d = do+  m <- mark+  release (m <> d)  -- | grab the remainder of the current line restOfLine :: MonadParser m => m ByteString
Text/Trifecta/Parser/Prim.hs view
@@ -191,15 +191,6 @@         | bytes d' == bytes (rewind d) + Strict.length bs -> co () mempty l d' $                                                               if near d d' then bs else mempty         | otherwise -> ee mempty l d bs-  skipping d' = Parser $ \_ ee co _ l d bs -> do-    let d'' = d <> d'-    mbs <- rewindIt d''-    case mbs of-      Just bs' -> co () mempty l d'' bs'-      Nothing -        | bytes d'' == bytes (rewind d) + Strict.length bs -> co () mempty l d'' $-                                                              if near d d'' then bs else mempty-        | otherwise -> ee mempty l d bs   {-# INLINE release #-}   line = Parser $ \eo _ _ _ l d bs -> eo bs mempty l d bs   {-# INLINE line #-}
Text/Trifecta/Rope.hs view
@@ -1,15 +1,7 @@ module Text.Trifecta.Rope    ( Rope, rope, strands   -- * Strands of a rope-  , Strand(..)-  -- ** Hunk strands-  , Hunk(..)-  , hunk-  -- ** Path strands (import directly for more)-  , Path-  , file-  , appendPath-  , comparablePath+  , Strand(..), strand   -- * Properties   , Delta(..)   , HasDelta(..)@@ -17,8 +9,5 @@   ) where  import Text.Trifecta.Rope.Prim-import Text.Trifecta.Rope.Strand-import Text.Trifecta.Rope.Hunk-import Text.Trifecta.Rope.Path import Text.Trifecta.Rope.Delta import Text.Trifecta.Rope.Bytes
Text/Trifecta/Rope/Delta.hs view
@@ -13,11 +13,10 @@ import Data.Semigroup import Data.Hashable import Data.Word-import Data.Interned import Data.Foldable import Data.FingerTree hiding (empty) import Data.ByteString hiding (empty)-import Text.Trifecta.Rope.Path+import qualified Data.ByteString.UTF8 as UTF8 import Text.Trifecta.Rope.Bytes import Text.PrettyPrint.Free hiding (column) import System.Console.Terminfo.PrettyPrint@@ -32,7 +31,7 @@               {-# UNPACK #-} !Int  -- the number of characters since the last newline               {-# UNPACK #-} !Int  -- number of bytes               {-# UNPACK #-} !Int  -- the number of bytes since the last newline-  | Directed                 !Path -- the sequence of #line directives since the start of the file+  | Directed  !ByteString          -- current file name               {-# UNPACK #-} !Int  -- the number of lines since the last line directive               {-# UNPACK #-} !Int  -- the number of characters since the last newline               {-# UNPACK #-} !Int  -- number of bytes@@ -56,7 +55,7 @@     Columns c _ -> k f 0 c     Tab x y _ -> k f 0 (nextTab x + y)     Lines l c _ _ -> k f l c-    Directed (Path _ _ _ fn _ _) l c _ _ -> k (maybeFileName f unintern fn) l c  -- TODO: add include path+    Directed fn l c _ _ -> k (UTF8.toString fn) l c     where        k fn ln cn = bold (string fn)                            <> char ':' @@ -104,7 +103,7 @@   Directed p l c t a <> Columns d b            = Directed p l (c + d) (t + b) (a + b)   Directed p l c t a <> Tab x y b              = Directed p l (nextTab (c + x) + y) (t + b) (a + b)   Directed p l _ t a <> Lines m d t' b         = Directed p (l + m) d (t + t') (a + b)-  Directed p l _ t _ <> Directed p' l' c' t' b = Directed (appendPath p l p') l' c' (t + t') b+  Directed _ _ _ t _ <> Directed p' l' c' t' b = Directed {- p + l + -} p' l' c' (t + t') b    nextTab :: Int -> Int nextTab x = x + (8 - mod x 8)@@ -148,9 +147,6 @@  instance HasDelta ByteString where   delta = foldMap delta . unpack--instance HasDelta Path where-  delta p = Directed p 0 0 0 0  instance (Measured v a, HasDelta v) => HasDelta (FingerTree v a) where   delta = delta . measure
− Text/Trifecta/Rope/Hunk.hs
@@ -1,58 +0,0 @@-{-# LANGUAGE MultiParamTypeClasses, TypeFamilies, FlexibleInstances #-}-module Text.Trifecta.Rope.Hunk -  ( Hunk(..)-  , hunk-  ) where--import Data.ByteString-import qualified Data.ByteString.UTF8 as UTF8-import Data.FingerTree as FingerTree-import Data.Function (on)-import Data.Hashable-import Data.Interned-import Data.String-import Text.Trifecta.Rope.Delta--data Hunk = Hunk {-# UNPACK #-} !Id !Delta {-# UNPACK #-} !ByteString-  deriving Show--hunk :: ByteString -> Hunk-hunk = intern ---- instance Show Hunk where showsPrec d (Hunk _ _ b) = showsPrec d b--instance IsString Hunk where-  fromString = hunk . UTF8.fromString--instance Eq Hunk where-  (==) = (==) `on` identity--instance Hashable Hunk where-  hash = hash . identity--instance Ord Hunk where-  compare = compare `on` identity--instance HasDelta Hunk where-  delta (Hunk _ d _) = d--instance Interned Hunk where-  type Uninterned Hunk = ByteString-  data Description Hunk = Describe {-# UNPACK #-} !ByteString deriving (Eq)-  describe = Describe-  identify i bs = Hunk i (delta bs) bs-  identity (Hunk i _ _) = i-  cache = hunkCache--instance Uninternable Hunk where-  unintern (Hunk _ _ bs) = bs--instance Hashable (Description Hunk) where-  hash (Describe bs) = hash bs--hunkCache :: Cache Hunk-hunkCache = mkCache -{-# NOINLINE hunkCache #-}--instance Measured Delta Hunk where-  measure = delta
− Text/Trifecta/Rope/Path.hs
@@ -1,103 +0,0 @@-{-# LANGUAGE TypeFamilies, FlexibleInstances, BangPatterns #-}-module Text.Trifecta.Rope.Path-  ( FileName-  , Path(..), History(..)-  , file-  , snocPath-  , path-  , appendPath-  , comparablePath-  -- * Internals-  , MaybeFileName(..)-  , maybeFileName-  ) where--import Data.Hashable-import Data.Interned-import Data.Interned.String-import Data.Function (on)-import Data.Semigroup-import Data.IntSet as IntSet--type FileName = InternedString--data Path = Path {-# UNPACK #-} !Id !IntSet !History !MaybeFileName {-# UNPACK #-} !Int [Int]-  deriving Show--pathIds :: Path -> IntSet-pathIds (Path _ is _ _ _ _) = is--comparablePath :: Path -> Path -> Bool-comparablePath x y = identity x `IntSet.member` pathIds y-                  || identity y `IntSet.member` pathIds x--instance Eq Path where-  (==) = (==) `on` identity--instance Ord Path where-  compare = compare `on` identity--data History = Continue !Path {-# UNPACK #-} !Int | Complete deriving (Eq, Show)--data MaybeFileName = JustFileName !FileName | NothingFileName deriving (Eq, Show)--maybeFileName :: r -> (FileName -> r) -> MaybeFileName -> r-maybeFileName n _ NothingFileName  = n-maybeFileName _ f (JustFileName a) = f a--file :: String -> Path -file !n = path Complete (JustFileName (intern n)) 0 []--snocPath :: Path -> Int -> MaybeFileName -> Int -> [Int] -> Path-snocPath d l jf l' flags = path (Continue d l) jf l' flags--path :: History -> MaybeFileName -> Int -> [Int] -> Path-path !h !mf l flags = intern (UPath h mf l flags)--appendPath :: Path -> Int -> Path -> Path-appendPath p dl (Path _ _ Complete          mf l flags) = snocPath p dl mf l flags-appendPath p dl (Path _ _ (Continue p' dl') mf l flags) = snocPath (appendPath p dl p') dl' mf l flags--instance Semigroup Path where-  p <> p' = appendPath p 0 p'--data UninternedPath = UPath !History !MaybeFileName {-# UNPACK #-} !Int [Int]-data DHistory = DContinue {-# UNPACK #-} !Id {-# UNPACK #-} !Int | DComplete deriving Eq--instance Hashable DHistory where-  hash (DContinue x y) = y `hashWithSalt` x-  hash DComplete       = 0--instance Hashable Path where-  hash = hash . identity--instance Interned Path where-  type Uninterned Path = UninternedPath-  data Description Path = DPath !(Maybe Id) {-# UNPACK #-} !Int [Int] !DHistory deriving Eq-  describe (UPath h mf l flags) = DPath mi l flags $ case h of-    Continue p dl -> DContinue (identity p) dl-    Complete      -> DComplete -    where -      mi = case mf of -        JustFileName f -> Just (identity f)-        NothingFileName -> Nothing-                     -  identify i (UPath h mf l flags) = Path i m h mf l flags -    where -      m = case h of -        Complete -> IntSet.singleton i-        Continue (Path _ m' _ _ _ _) _ -> IntSet.insert i m'-                 -  identity (Path i _ _ _ _ _) = i-  cache = pathCache--instance Uninternable Path where-  unintern (Path _ _ h mf l flags) = UPath h mf l flags--instance Hashable (Description Path) where-  hash (DPath mi l flags dh) = l `hashWithSalt` mi `hashWithSalt` flags `hashWithSalt` dh--pathCache :: Cache Path-pathCache = mkCache-{-# NOINLINE pathCache #-}-
Text/Trifecta/Rope/Prim.hs view
@@ -2,6 +2,8 @@ module Text.Trifecta.Rope.Prim   ( Rope(..)   , rope+  , Strand(..)+  , strand   , strands   , grabRest   , grabLine@@ -10,17 +12,40 @@ import Data.Monoid import Data.Semigroup import Data.Semigroup.Reducer+import Data.ByteString (ByteString) import qualified Data.ByteString as Strict import qualified Data.ByteString.Lazy as Lazy+import qualified Data.ByteString.UTF8 as UTF8 import Data.FingerTree as FingerTree import Data.Foldable (toList)-import Text.Trifecta.Rope.Hunk-import Text.Trifecta.Rope.Path-import Text.Trifecta.Rope.Delta-import Text.Trifecta.Rope.Bytes-import Text.Trifecta.Rope.Strand+import Data.Hashable import Text.Trifecta.Util as Util+import Text.Trifecta.Rope.Bytes+import Text.Trifecta.Rope.Delta +data Strand+  = Strand        {-# UNPACK #-} !ByteString !Delta+  | LineDirective {-# UNPACK #-} !ByteString {-# UNPACK #-} !Int+  deriving Show++strand :: ByteString -> Strand+strand bs = Strand bs (delta bs)++instance Measured Delta Strand where+  measure (Strand _ s) = delta s+  measure (LineDirective p l) = delta (Directed p l 0 0 0)++instance Hashable Strand where+  hash (Strand h _) = hashWithSalt 0 h+  hash (LineDirective p l)   = l `hashWithSalt` p++instance HasDelta Strand where+  delta = measure++instance HasBytes Strand where+  bytes (Strand _ d) = bytes d+  bytes _            = 0+ data Rope = Rope !Delta !(FingerTree Delta Strand) deriving Show  rope :: FingerTree Delta Strand -> Rope@@ -32,11 +57,11 @@ -- | grab a the contents of a rope from a given location up to a newline grabRest :: Delta -> Rope -> r -> (Delta -> Lazy.ByteString -> r) -> r grabRest i t kf ks = trim (toList r) (delta l) (bytes i - bytes l) where-  trim (PathStrand p            : xs) j k = trim xs (j <> delta p) k-  trim (HunkStrand (Hunk _ _ h) : xs) j 0 = go j h xs-  trim (HunkStrand (Hunk _ _ h) : xs) _ k = go i (Strict.drop k h) xs+  trim (p@LineDirective{} : xs) j k = trim xs (j <> delta p) k+  trim (Strand h _ : xs) j 0 = go j h xs+  trim (Strand h _ : xs) _ k = go i (Strict.drop k h) xs   trim [] _ _ = kf-  go j h s = ks j $ Lazy.fromChunks $ h : [ a | HunkStrand (Hunk _ _ a) <- s ]+  go j h s = ks j $ Lazy.fromChunks $ h : [ a | Strand a _ <- s ]   (l, r) = FingerTree.split (\b -> bytes b > bytes i) $ strands t  -- | grab a the contents of a rope from a given location up to a newline@@ -63,21 +88,18 @@   unit = id  instance Reducer Strand Rope where-  unit s = rope (singleton s)+  unit s = rope (FingerTree.singleton s)   cons s (Rope mt t) = Rope (delta s `mappend` mt) (s <| t)   snoc (Rope mt t) !s = Rope (mt `mappend` delta s) (t |> s) -instance Reducer Hunk Rope where-  unit s = Rope (delta s) (singleton (HunkStrand s))-  cons s (Rope mt t) = Rope (delta s `mappend` mt) (HunkStrand s <| t)-  snoc (Rope mt t) s = Rope (mt `mappend` delta s) (t |> HunkStrand s)-  -instance Reducer Path Rope where-  unit s = Rope (delta s) (singleton (PathStrand s))-  cons s (Rope mt t) = Rope (delta s `mappend` mt) (PathStrand s <| t)-  snoc (Rope mt t) s = Rope (mt `mappend` delta s) (t |> PathStrand s)- instance Reducer Strict.ByteString Rope where-  unit = unit . hunk-  cons = cons . hunk -  snoc r = snoc r . hunk+  unit = unit . strand+  cons = cons . strand+  snoc r = snoc r . strand++instance Reducer [Char] Rope where+  unit = unit . strand . UTF8.fromString+  cons = cons . strand . UTF8.fromString+  snoc r = snoc r . strand . UTF8.fromString++
− Text/Trifecta/Rope/Strand.hs
@@ -1,37 +0,0 @@-{-# LANGUAGE TypeFamilies, MultiParamTypeClasses, FlexibleInstances #-}-module Text.Trifecta.Rope.Strand-  ( Strand(..)-  ) where--import Data.Interned-import Data.Hashable-import Data.ByteString as Strict-import Data.FingerTree as FingerTree-import Text.Trifecta.Rope.Hunk-import Text.Trifecta.Rope.Path-import Text.Trifecta.Rope.Bytes-import Text.Trifecta.Rope.Delta--data Strand-  = HunkStrand !Hunk-  | PathStrand !Path-  deriving Show----instance Show Strand where---  showsPrec d (HunkStrand h) = showsPrec d h---  showsPrec d (PathStrand p) = showsPrec d p--instance Measured Delta Strand where-  measure (HunkStrand s) = delta s-  measure (PathStrand p) = delta p--instance Hashable Strand where-  hash (HunkStrand h) = hashWithSalt 0 h-  hash (PathStrand p) = hashWithSalt 0 p--instance HasDelta Strand where-  delta = measure--instance HasBytes Strand where-  bytes (HunkStrand h) = Strict.length (unintern h)-  bytes _ = 0
trifecta.cabal view
@@ -1,6 +1,6 @@ name:          trifecta category:      Text, Parsing, Diagnostics, Pretty Printer, Logging-version:       0.26+version:       0.27 license:       BSD3 cabal-version: >= 1.6 license-file:  LICENSE@@ -31,10 +31,7 @@     Text.Trifecta.Rope     Text.Trifecta.Rope.Bytes     Text.Trifecta.Rope.Delta-    Text.Trifecta.Rope.Hunk-    Text.Trifecta.Rope.Path     Text.Trifecta.Rope.Prim-    Text.Trifecta.Rope.Strand     Text.Trifecta.Diagnostic     Text.Trifecta.Diagnostic.Prim     Text.Trifecta.Diagnostic.Class@@ -76,7 +73,6 @@     containers           >= 0.3     && < 0.5,     unordered-containers >= 0.1.4   && < 0.2,     bifunctors           >= 0.1.1.3 && < 0.2,-    intern               >= 0.5.1.1 && < 0.6,     hashable             >= 1.1.2.1 && < 1.2,     bytestring           >= 0.9.1   && < 0.10,     mtl                  >= 2.0.1   && < 2.1,@@ -92,4 +88,4 @@     terminfo             >= 0.3.2   && < 0.4,     keys                 >= 2.1     && < 2.2,     wl-pprint-extras     >= 1.4     && < 1.5,-    wl-pprint-terminfo   >= 0.4     && < 0.5+    wl-pprint-terminfo   >= 0.5     && < 0.6