embeddock 0.1.0.1 → 0.2
raw patch · 3 files changed
+47/−6 lines, 3 filesdep ~base
Dependency ranges changed: base
Files
- embeddock.cabal +7/−2
- src/Embeddock/Example.hs +29/−0
- src/main.hs +11/−4
embeddock.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: embeddock-version: 0.1.0.1+version: 0.2 synopsis: Embed the values in scope in the haddock documentation of the module description: embeddock is a Haskell source-code preprocessor. It allows you to embed computer-generated @@ -21,11 +21,16 @@ build-type: Simple cabal-version: >=1.8 +library+ hs-source-dirs: src/+ exposed-modules: Embeddock.Example+ build-depends: base >=4.5 && <5+ executable embeddock main-is: main.hs hs-source-dirs: src/ -- other-modules: - build-depends: base ==4.6.*+ build-depends: base >=4.5 && <5 , filepath >= 1.3 , her-lexer >= 0.1.1 , MissingH >= 1.2
+ src/Embeddock/Example.hs view
@@ -0,0 +1,29 @@+{-# OPTIONS_GHC -F -pgmF embeddock -optF $EMBED$ #-}++{- | To use embeddock, place the following preprocessor pragma at the+ beginning of your source code.++ > {-# OPTIONS_GHC -F -pgmF embeddock -optF $EMBED$ #-}++ You can specify the embed string by @-optF@. The default embed+ string is "$" . Expressions in parenthesis that immediately follow+ the embed strings are treated as embed expression. Embed+ expressions are evaluated in the context of the module. The result+ should be of type string.++ Please look at the source code of this module for an usecase of+ @embeddock@.++ At the moment, embeddock is not compatible with one-liner comment "--"+ due to the backend lexer.+-}++module Embeddock.Example where+++{- | An answer to the life, the universe and everything.+ the answer is $EMBED$(show answer) .+-}++answer :: Integer+answer = 6*7
src/main.hs view
@@ -13,7 +13,10 @@ main :: IO () main = do- (srcPath:_:destPath:ppOpts) <- getArgs+ argv <- getArgs+ let (srcPath:_:destPath:ppOpts) + | length argv >= 3 = argv+ | otherwise = take 3 $ argv ++ repeat "" src <- readFile srcPath let embedKey :: String@@ -52,8 +55,9 @@ runnerFn = srcDir </> ("." ++ srcFnBody ++ "_embeddock") <.> srcExt - destContent = tokssOut parsedSrc + destContent = tokssOut parsedSrc+ quineMain = unlines $ "main = do" :map mkPrinter parsedSrc mkPrinter :: [Tok] -> String@@ -104,6 +108,9 @@ when (not isEmbedLoop) $ do writeFile runnerFn $ destContent ++ "\n" ++ quineMain- (_, hOut, _, _) <- runInteractiveCommand $+ (_, hOut, hErr, _) <- runInteractiveCommand $ printf "runhaskell %s %s" (unwords runhaskellArgs) runnerFn- hGetContents hOut >>= writeFile destPath+ hGetContents hErr >>= hPutStr stderr+ hGetContents hOut >>= + (if destPath /= "" then writeFile destPath+ else putStrLn )