packages feed

trifecta 0.1 → 0.2

raw patch · 6 files changed

+78/−8 lines, 6 filesdep +transformersdep ~intern

Dependencies added: transformers

Dependency ranges changed: intern

Files

+ Text/Trifecta.hs view
@@ -0,0 +1,17 @@+module Text.Trifecta +  ( module Text.Trifecta.Cursor+  , module Text.Trifecta.Delta+  , module Text.Trifecta.Hunk+  , module Text.Trifecta.It+  , module Text.Trifecta.Path+  , module Text.Trifecta.Rope+  , module Text.Trifecta.Supply+  ) where++import Text.Trifecta.Cursor+import Text.Trifecta.Delta+import Text.Trifecta.Hunk+import Text.Trifecta.It+import Text.Trifecta.Path+import Text.Trifecta.Rope+import Text.Trifecta.Supply
Text/Trifecta/Hunk.hs view
@@ -13,6 +13,7 @@ import GHC.IO import Text.Trifecta.Delta import Text.PrettyPrint.Leijen.Extras+--import Control.Exception  data Hunk = Hunk {-# UNPACK #-} !Id !Delta {-# UNPACK #-} !ByteString @@ -45,6 +46,7 @@   describe = Describe   identify i bs = Hunk i (delta bs) bs   identity (Hunk i _ _) = i+-- modifyAdvice = bracket_ (Prelude.putStrLn "entering hunk") (Prelude.putStrLn "exiting hunk")   cache = hunkCache  instance Uninternable Hunk where
Text/Trifecta/It.hs view
@@ -1,20 +1,30 @@-{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE MultiParamTypeClasses, BangPatterns #-} module Text.Trifecta.It    ( It(..)   , getRope   , getMeasure   , getEof+  , getWord8+  , sliceIt+  , slice+  , sliced   ) where  import Control.Applicative import Control.Monad+import Control.Monad.Trans.Class import Data.Semigroup import Data.Monoid import Data.Word+import Data.Interned+import Data.Foldable (toList) import Data.FingerTree as FingerTree+import Data.ByteString as Strict+import Data.ByteString.Lazy as Lazy import Data.Functor.Bind import Data.Functor.Plus import Text.Trifecta.Cursor+import Text.Trifecta.Hunk import Text.Trifecta.Rope as Rope import Text.Trifecta.Delta import Text.Parsec.Prim hiding ((<|>))@@ -29,7 +39,7 @@     showString "Done " . showsPrec 11 r . showChar ' ' . showsPrec 11 b . showChar ' ' . showsPrec 11 a   showsPrec d (Fail r b s) = showParen (d > 10) $     showString "Fail " . showsPrec 11 r . showChar ' ' . showsPrec 11 b . showChar ' ' . showsPrec 11 s-  showsPrec d (Cont k) = showParen (d > 10) $ showString "Cont ..."+  showsPrec d (Cont _) = showParen (d > 10) $ showString "Cont ..."  instance Functor It where   fmap f (Done r b a) = Done r b (f a)@@ -84,7 +94,7 @@   uncons (Cursor b d _ _) = (getWord8 b >>= go) <|> return Nothing where     go c | c <= 0x7f = do         Cursor _ _ i t <- getMeasure-        return $ Just (toEnum (fromEnum c), Cursor (b + 1) (d <> delta c) i t)+        return $ Just (toEnum (fromEnum c), Cursor (b + 1) (d <> delta c) i t) -- TODO: add in PathHunks          | otherwise = error "TODO"     -- TODO: finish these @@ -93,4 +103,39 @@   go h eof      | n < Rope.lastNewline h eof = Done h eof $ indexByte n h     | eof                        = Fail h True "Unexpected EOF"-    | otherwise                  = Cont $ \h' -> go (h <> h')+    | otherwise                  = Cont $ \h' -> go (h <> h') -- h' <> h++sliceIt :: Int -> Int -> It Strict.ByteString+sliceIt !i !j = Cont go where+  go :: Rope -> Bool -> It Strict.ByteString+  go t@(Rope _ h) eof+    | j <= cursorBytes (measure h) || eof = Done t eof (sliceStrands h)+    | otherwise = Cont $ \t' eof' -> go (t <> t') eof'+  sliceStrands :: FingerTree Cursor Strand -> Strict.ByteString+  sliceStrands !t+    | req <= rmn = Strict.take req first -- yay! sharing+    | otherwise = Strict.concat +                $ Lazy.toChunks +                $ Lazy.take (fromIntegral req) +                $ Lazy.fromChunks +                $ first : Prelude.foldr iter [] (toList r')+    where iter (HunkStrand h) b = unintern h : b+          iter (PathStrand _) b = b+          (l,r) = FingerTree.split (\m -> cursorBytes m > i) t+          HunkStrand (Hunk _ _ a) :< r' = FingerTree.viewl r+          first = Strict.drop (i - cursorBytes (measure l)) a+          req = j - i+          rmn = Strict.length first++slice :: Cursor -> Cursor -> ParsecT Cursor u It Strict.ByteString+slice mark release = lift $ sliceIt (cursorBytes mark) (cursorBytes release)++sliced :: ParsecT Cursor u It a -> ParsecT Cursor u It Strict.ByteString+sliced p = do+  mark <- getInput+  _ <- p+  release <- getInput+  slice mark release++-- sliceDelta :: Int -> Int -> It Delta+
Text/Trifecta/Path.hs view
@@ -12,6 +12,7 @@ import Data.Hashable import Data.Interned import Data.Interned.String+--import Control.Exception import Data.Semigroup import Text.PrettyPrint.Leijen.Extras @@ -78,6 +79,7 @@         JustFileName f -> Just (identity f)         NothingFileName -> Nothing                      +--  modifyAdvice = bracket_ (putStrLn "entering path") (putStrLn "exiting path")   identify i (UPath h mf l flags) = Path i h mf l flags   identity (Path i _ _ _ _) = i   cache = pathCache
Text/Trifecta/Rope.hs view
@@ -20,6 +20,7 @@ import Text.Trifecta.Path import Text.Trifecta.Cursor import Text.Trifecta.Delta+-- import Control.Exception  data Strand   = HunkStrand !Hunk@@ -32,7 +33,7 @@ -- measure twice, cut once instance Measured Cursor Strand where   measure (HunkStrand s) = Cursor (Strict.length (unintern s)) (delta s) i (Seq.singleton i) where i = 42 + (identity s * 2)-  measure (PathStrand p) = Cursor 0 (Directed p 0 0 0) i (Seq.singleton i)   where i = 42 + (identity p * 2 + 1)+  measure (PathStrand p) = Cursor 0 (Directed p 0 0 0) i (Seq.singleton i)   where i = 230 + (identity p * 2 + 1)  data Rope = Rope    { _ropeId  :: {-# UNPACK #-} !Id@@ -75,6 +76,7 @@   describe t = DR h i where Cursor _ _ h i = measure t   identify = Rope   identity (Rope i _) = i+-- modifyAdvice = bracket_ (Prelude.putStrLn "entering rope") (Prelude.putStrLn "exiting rope")   cache = ropeCache  instance Hashable (Description Rope) where
trifecta.cabal view
@@ -1,6 +1,6 @@ name:          trifecta category:      Text, Parsing-version:       0.1+version:       0.2 license:       BSD3 cabal-version: >= 1.6 license-file:  LICENSE@@ -21,7 +21,7 @@   build-depends:      base             >= 4        && < 5,      containers       >= 0.3      && < 0.5,-    intern           >= 0.5      && < 0.6,+    intern           >= 0.5.1.1  && < 0.6,     hashable         >= 1.1.2.1  && < 1.2,     bytestring       >= 0.9.1    && < 0.10,     text             >= 0.11.1.5 && < 0.12,@@ -33,11 +33,13 @@     parsec           >= 3.1.1    && < 3.2,     utf8-string      >= 0.3.6    && < 0.4,     semigroupoids    >= 1.2.4    && < 1.3,-    parallel         >= 3.1.0.1  && < 3.2+    parallel         >= 3.1.0.1  && < 3.2,+    transformers     >= 0.2.2    && < 0.3    ghc-options: -Wall    exposed-modules:+    Text.Trifecta     Text.Trifecta.Path     Text.Trifecta.Delta     Text.Trifecta.Cursor