template 0.2.0.1 → 0.2.0.2
raw patch · 2 files changed
+17/−12 lines, 2 filesdep ~basedep ~mtl
Dependency ranges changed: base, mtl
Files
- Data/Text/Template.hs +14/−9
- template.cabal +3/−3
Data/Text/Template.hs view
@@ -46,7 +46,7 @@ import Control.Applicative (Applicative(pure), (<$>)) import Control.Monad (liftM, liftM2)-import Control.Monad.State (State, evalState, get, put)+import Control.Monad.State.Strict (State, evalState, get, put) import Data.Char (isAlphaNum) import Data.Function (on) import Data.Traversable (traverse)@@ -215,17 +215,22 @@ -- ----------------------------------------------------------------------------- -- Text parser -type Parser = State (T.Text, Int, Int)+-- | The parser state.+data S = S {-# UNPACK #-} !T.Text -- ^ Remaining input+ {-# UNPACK #-} !Int -- ^ Row+ {-# UNPACK #-} !Int -- ^ Col +type Parser = State S+ char :: Parser (Maybe Char) char = do- (s, row, col) <- get+ S s row col <- get if T.null s then return Nothing else do c <- return $! T.head s case c of- '\n' -> put (T.tail s, row + 1 :: Int, 1 :: Int)- _ -> put (T.tail s, row, col + 1 :: Int)+ '\n' -> put $! S (T.tail s) (row + 1) 1+ _ -> put $! S (T.tail s) row (col + 1) return $ Just c peek :: Parser (Maybe Char)@@ -245,7 +250,7 @@ takeWhile :: (Char -> Bool) -> Parser T.Text takeWhile p = do- (s, row, col) <- get+ S s row col <- get case T.spanBy p s of (x, s') -> do let xlines = T.lines x@@ -257,16 +262,16 @@ _ -> T.length (last xlines) -- Selection extends -- to next line at least- put (s', row', col')+ put $! S s' row' col' return x pos :: Parser (Int, Int) pos = do- (_, row, col) <- get+ S _ row col <- get return (row, col) runParser :: Parser a -> T.Text -> a-runParser p s = evalState p (s, 1 :: Int, 1 :: Int)+runParser p s = evalState p $ S s 1 1 -- ----------------------------------------------------------------------------- -- Example
template.cabal view
@@ -1,5 +1,5 @@ name: template-version: 0.2.0.1+version: 0.2.0.2 description: Simple string substitution library that supports \"$\"-based substitution. Meant to be used when Text.Printf or string@@ -19,8 +19,8 @@ exposed-modules: Data.Text.Template build-depends:- base < 5,- mtl < 1.2,+ base >= 3.0 && < 4.4,+ mtl >= 1.1 && < 2.0.2, text >= 0.7.2 && < 0.11 ghc-options: -funbox-strict-fields -Wall