packages feed

anansi 0.1 → 0.2

raw patch · 3 files changed

+30/−13 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Anansi: tangle :: (Monad m) => (Text -> Text -> m ()) -> [Block] -> m ()
+ Anansi: tangle :: (Monad m) => (Text -> Text -> m ()) -> Bool -> [Block] -> m ()

Files

Anansi/Tangle.hs view
@@ -15,6 +15,7 @@ --  {-# LANGUAGE OverloadedStrings #-} module Anansi.Tangle (tangle) where+import Control.Monad (when) import Control.Monad.Trans.Class (lift) import qualified Control.Monad.State as S import qualified Control.Monad.Writer as W@@ -50,26 +51,30 @@ 		files <- S.get 		S.put $ Map.insertWith accum name content files -tangle :: Monad m => (TL.Text -> TL.Text -> m ()) -> [Block] -> m ()-tangle writeFile' blocks = S.evalStateT (mapM_ putFile files) initState where+tangle :: Monad m+       => (TL.Text -> TL.Text -> m ())+       -> Bool -- ^ Enable writing #line declarations+       -> [Block]+       -> m ()+tangle writeFile' enableLine blocks = S.evalStateT (mapM_ putFile files) initState where 	initState = (TangleState (Position "" 0) "" macros) 	fileMap = buildFiles blocks 	macros = buildMacros blocks 	files = Map.toAscList fileMap 	 	putFile (path, content) = do-		text <- W.execWriterT (mapM_ putContent content)+		text <- W.execWriterT (mapM_ (putContent enableLine) content) 		lift $ writeFile' path text -putContent :: Monad m => Content -> TangleT m ()-putContent (ContentText pos t) = do+putContent :: Monad m => Bool -> Content -> TangleT m ()+putContent enableLine (ContentText pos t) = do 	TangleState _ indent _ <- S.get-	putPosition pos+	when enableLine $ putPosition pos 	W.tell indent 	W.tell t 	W.tell "\n" -putContent (ContentMacro pos indent name) = addIndent putMacro where+putContent enableLine (ContentMacro pos indent name) = addIndent putMacro where 	addIndent m = do 		TangleState lastPos old macros <- S.get 		S.put $ TangleState lastPos (TL.append old indent) macros@@ -77,8 +82,8 @@ 		TangleState newPos _ _ <- S.get 		S.put $ TangleState newPos old macros 	putMacro = do-		putPosition pos-		lookupMacro name >>= mapM_ putContent+		when enableLine $ putPosition pos+		lookupMacro name >>= mapM_ (putContent enableLine)  putPosition :: Monad m => Position -> TangleT m () putPosition pos = do
Main.hs view
@@ -40,6 +40,7 @@ 	= OptionOutput Output 	| OptionOutputPath TL.Text 	| OptionLoom TL.Text+	| OptionNoLines  optionInfo :: [OptDescr Option] optionInfo =@@ -51,6 +52,8 @@ 	  "Output path (directory for tangle, file for weave)" 	, Option ['l'] ["loom"] (ReqArg (OptionLoom . TL.pack) "NAME") 	  "Which loom should be used to weave output"+	, Option [] ["noline"] (NoArg OptionNoLines)+	  "Disable generating #line declarations in tangled code" 	]  usage :: String -> String@@ -84,6 +87,12 @@ 		Nothing -> error $ "Unknown loom: " ++ show name 	_ -> getLoom xs +getEnableLines :: [Option] -> Bool+getEnableLines [] = True+getEnableLines (x:xs) = case x of+	OptionNoLines -> False+	_ -> getEnableLines xs+ main :: IO () main = do 	args <- getArgs@@ -96,14 +105,17 @@ 	 	let path = getPath options 	let loom = getLoom options+	let enableLines = getEnableLines options 	 	parsed <- parseInputs inputs 	case parsed of-		Left err -> hPutStrLn stderr (formatError err)+		Left err -> do+			hPutStrLn stderr (formatError err)+			exitFailure 		Right blocks -> case getOutput options of 			Tangle -> case path of-				"" -> tangle debugTangle blocks-				_ -> tangle (realTangle path) blocks+				"" -> tangle debugTangle enableLines blocks+				_ -> tangle (realTangle path) enableLines blocks 			Weave -> let 				texts = execWriter $ loomWeave loom blocks 				in withFile path $ \h -> BL.hPut h $ lazyUtf8 texts
anansi.cabal view
@@ -1,5 +1,5 @@ name: anansi-version: 0.1+version: 0.2 synopsis: Simple literate programming preprocessor license: GPL-3 license-file: license.txt