packages feed

nowdoc 0.1.0.3 → 0.1.0.4

raw patch · 3 files changed

+63/−18 lines, 3 files

Files

README.md view
@@ -6,6 +6,8 @@ * remove head newline if exist * remove one space from '|', space, space, ..., ']' +## short examples+ ```hs hello = [nowdoc| abc@@ -46,4 +48,51 @@  ```hs hello = "hello |]\nworld| ]\n! |  ]"+```++## run perl++```hs+{-# LANGUAGE QuasiQuotes #-}++import System.Process+import Text.Nowdoc++main :: IO ()+main = () <$ rawSystem "perl" ["-e", [nowdoc|+use strict;+use warnings;++my $hello = "Hello, world!\n";+print $hello;+|]]+```++## ASCII art++```hs+{-# LANGUAGE QuasiQuotes #-}++import Text.Nowdoc++main :: IO ()+main = putStr [nowdoc|+            ______             +       .d$$$******$$$$c.       +    .d$P"            "$$c      +   $$$$$.           .$$$*$.    + .$$ 4$L*$$.     .$$Pd$  '$b   + $F   *$. "$$e.e$$" 4$F   ^$b  +d$     $$   z$$$e   $$     '$. +$P     `$L$$P` `"$$d$"      $$ +$$     e$$F       4$$b.     $$ +$b  .$$" $$      .$$ "4$b.  $$ +$$e$P"    $b     d$`    "$$c$F +'$P$$$$$$$$$$$$$$$$$$$$$$$$$$  + "$c.      4$.  $$       .$$   +  ^$$.      $$ d$"      d$P    +    "$$c.   `$b$F    .d$P"     +      `4$$$c.$$$..e$$P"        +          `^^^^^^^`+|] ```
nowdoc.cabal view
@@ -2,12 +2,12 @@ -- -- see: https://github.com/sol/hpack ----- hash: 5c79bb879133786755fd90f6d2d66bc8d423fc9d44335dafa3cdaa458f0fc7e2+-- hash: 210f2844c035c43c8f37a0625f4be9e91610d28eaba8a46bec9f0880222815ae  name:           nowdoc-version:        0.1.0.3+version:        0.1.0.4 synopsis:       Here document without variable expansion like PHP Nowdoc-description:    Please see the README on GitHub+description:    Please see the README on GitHub at <https://github.com/YoshikuniJujo/nowdoc#readme> category:       Text homepage:       https://github.com/YoshikuniJujo/nowdoc#readme bug-reports:    https://github.com/YoshikuniJujo/nowdoc/issues
src/Text/Nowdoc.hs view
@@ -1,26 +1,17 @@+{-# LANGUAGE LambdaCase #-} {-# OPTIONS_GHC -Wall -fno-warn-tabs #-}  module Text.Nowdoc (nowdoc) where -import Language.Haskell.TH (litE, stringL)+import Language.Haskell.TH (stringE) import Language.Haskell.TH.Quote (QuasiQuoter(..))  nowdoc :: QuasiQuoter nowdoc = QuasiQuoter {-	quoteExp = litE . stringL . unescape . dropHeadNewline,-	quotePat = const . error $ errorString "a pattern",-	quoteType = const . error $ errorString "a type",-	quoteDec = const . error $ errorString "a declaration"-	}--errorString :: String -> String-errorString ctx =-	"You have used the `nowdoc' QuasiQoter in " ++ ctx ++-	" context; you must only use it in an expression context"--dropHeadNewline :: String -> String-dropHeadNewline ('\n' : cs) = cs-dropHeadNewline cs = cs+	quoteExp = stringE . unescape . \case '\n' : cs -> cs; cs -> cs,+	quotePat = const $ err "pattern",+	quoteType = const $ err "type",+	quoteDec = const $ err "declaration" }  unescape :: String -> String unescape ('|' : cs) = case span (== ' ') cs of@@ -28,3 +19,8 @@ 	(ss, cs') -> '|' : ss ++ unescape cs' unescape (c : cs) = c : unescape cs unescape "" = ""++err :: String -> a+err ctx = error $+	"You have used the `nowdoc' QuasiQoter in a " ++ ctx +++	" context; you must only use it in an expression context"