packages feed

lima 0.2.1.1 → 0.2.1.2

raw patch · 11 files changed

+136/−119 lines, 11 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

README.hs view
@@ -5,13 +5,19 @@  ## Related works -- [LiterateMarkdown](https://github.com/haskie-lambda/LiterateMarkdown) - `lima` is a fork of this (abandoned?) project.+- [LiterateMarkdown](https://hackage.haskell.org/package/LiterateMarkdown) - `lima` is a fork of this (abandoned?) project. -- [pandoc](https://www.uv.es/wikibase/doc/cas/pandoc_manual_instalado.wiki?60) - [supports](https://www.uv.es/wikibase/doc/cas/pandoc_manual_instalado.wiki?60) `Literate Haskell` and a ton of other formats.+- [pandoc](https://hackage.haskell.org/package/pandoc) - [supports](https://www.uv.es/wikibase/doc/cas/pandoc_manual_instalado.wiki?60) `Literate Haskell` and a ton of other formats. -- [IHaskell](https://github.com/IHaskell/IHaskell) - create `Jupyter` notebooks with `Haskell` code cells and `GitHub Flavored Markdown` text cells and do much more.+- [IHaskell](https://hackage.haskell.org/package/ihaskell) - create `Jupyter` notebooks with `Haskell` code cells and `GitHub Flavored Markdown` text cells.  - [lhs2tex](https://hackage.haskell.org/package/lhs2tex) - convert `Literate Haskell` to `TeX`.++- [agda2lagda](https://hackage.haskell.org/package/agda2lagda) - Generate a literate Agda/Haskell script from an Agda/Haskell script. Produces LaTeX or Markdown literate scripts.++- [markdown-unlit](https://hackage.haskell.org/package/markdown-unlit) - `markdown-unlit` is a custom unlit program. It can be used to extract Haskell code from Markdown files..++- [unlit](https://hackage.haskell.org/package/unlit) - Tool to convert literate code between styles or to code.  ## Supported formats 
README.md view
@@ -4,13 +4,17 @@  ## Related works -- [LiterateMarkdown](https://github.com/haskie-lambda/LiterateMarkdown) - `lima` is a fork of this (abandoned?) project.+- [LiterateMarkdown](https://hackage.haskell.org/package/LiterateMarkdown) - `lima` is a fork of this (abandoned?) project. -- [pandoc](https://www.uv.es/wikibase/doc/cas/pandoc_manual_instalado.wiki?60) - [supports](https://www.uv.es/wikibase/doc/cas/pandoc_manual_instalado.wiki?60) `Literate Haskell` and a ton of other formats.+- [pandoc](https://hackage.haskell.org/package/pandoc) - [supports](https://www.uv.es/wikibase/doc/cas/pandoc_manual_instalado.wiki?60) `Literate Haskell` and a ton of other formats. -- [IHaskell](https://github.com/IHaskell/IHaskell) - create `Jupyter` notebooks with `Haskell` code cells and `GitHub Flavored Markdown` text cells and do much more.+- [IHaskell](https://hackage.haskell.org/package/ihaskell) - create `Jupyter` notebooks with `Haskell` code cells and `GitHub Flavored Markdown` text cells.  - [lhs2tex](https://hackage.haskell.org/package/lhs2tex) - convert `Literate Haskell` to `TeX`.++- [agda2lagda](https://hackage.haskell.org/package/agda2lagda) - Generate a literate Agda/Haskell script from an Agda/Haskell script. Produces LaTeX or Markdown literate scripts.++- [markdown-unlit](https://hackage.haskell.org/package/markdown-unlit) - `markdown-unlit` is a custom unlit program. It can be used to extract Haskell code from Markdown files..  ## Supported formats 
lima.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           lima-version:        0.2.1.1+version:        0.2.1.2 synopsis:       Convert between Haskell, Markdown, Literate Haskell, TeX description:    See the [README.md](https://github.com/deemp/lima#readme) category:       Productivity@@ -19,7 +19,6 @@     CHANGELOG.md     README.md     testdata/md/test.hs-    testdata/md/test.lhs     testdata/md/test.md     testdata/md/tokens.hs     testdata/tex/test.hs
src/Converter.hs view
@@ -49,6 +49,47 @@ --             @ -- --      - There are no leading or trailing empty lines inside of 'Tokens'.+-- +-- There are several forms of @Haskell@ code blocks in @Literate Haskell@ recognized by @GHC@.+--+-- 1. Code between @\begin{code}@ and @\end{code}@ tags.+--+--     @+--     \begin{code}+--        a = 42+--     \end{code}+--     \begin{code}+--        b = a+--     \end{code}+--     @+-- +--     - The line starting with @\begin{code}@ cannot have other non-space characters after @\begin{code}@.+--     - The indentation of all expressions in code blocks must be the same.+--+-- 1. Code lines starting with @'> '@.+--+--     @+--     \begin{mycode}+--+--     >    a = 42+--+--     \end{mycode}+--     \begin{mycode}+--+--     >    b = a+--+--     \end{mycode}+--     @+--     +--     - There must be at least a single empty line before and after each @Haskell@ code block.+--     - Any text may surround @Haskell@ code blocks.+--     - The indentation of all expressions in code blocks must be the same.+--+-- This library supports only the second form as this form is more versatile.+-- +-- Moreover, this form does not require writing @Markdown@ tags like @\'```haskell\'@.+-- +-- Such tags will automatically be printed when converting @Literate Haskell@ to @Markdown@. module Converter (   -- * Config   Mode,@@ -164,8 +205,8 @@ --   _dedent = "LIMA_DEDENT", --   _mdHaskellCodeStart = "```haskell", --   _mdHaskellCodeEnd = "```",---   _texHaskellCodeStart = "\\begin{code}",---   _texHaskellCodeEnd = "\\end{code}",+--   _texHaskellCodeStart = "\\begin{mycode}",+--   _texHaskellCodeEnd = "\\end{mycode}", --   _texSingleLineCommentStart = "SINGLE_LINE ", --   _lhsSingleLineCommentStart = "SINGLE_LINE " -- }@@ -180,8 +221,8 @@ --   _dedent = "dedent", --   _mdHaskellCodeStart = "```haskell", --   _mdHaskellCodeEnd = "```",---   _texHaskellCodeStart = "\\begin{code}",---   _texHaskellCodeEnd = "\\end{code}",+--   _texHaskellCodeStart = "\\begin{mycode}",+--   _texHaskellCodeEnd = "\\end{mycode}", --   _texSingleLineCommentStart = "SINGLE_LINE ", --   _lhsSingleLineCommentStart = "SINGLE_LINE " -- }@@ -206,9 +247,9 @@   , _texHaskellCodeEnd :: Mode a   -- ^ Mark the end of a @Haskell@ code block in @TeX@.   , _texSingleLineCommentStart :: Mode a-  -- ^ Mark start of a comment that must be single-line.+  -- ^ Mark start of a comment that must be single-line in @TeX@.   , _lhsSingleLineCommentStart :: Mode a-  -- ^ Mark start of a comment that must be single-line+  -- ^ Mark start of a comment that must be single-line in @Literate Haskell@.   }   deriving (Generic) @@ -243,8 +284,8 @@     _dedent = "LIMA_DEDENT"     _mdHaskellCodeStart = "```haskell"     _mdHaskellCodeEnd = "```"-    _texHaskellCodeStart = "\\begin{code}"-    _texHaskellCodeEnd = "\\end{code}"+    _texHaskellCodeStart = "\\begin{mycode}"+    _texHaskellCodeEnd = "\\end{mycode}"     _texSingleLineCommentStart = "SINGLE_LINE"     _lhsSingleLineCommentStart = "SINGLE_LINE" @@ -565,36 +606,40 @@ --   Indent {n = 3}, --   Disabled {manyLines = ["-- What's the answer?"]}, --   Indent {n = 1},---   Indent {n = 2},---   Text {someLines = "\\begin{code}" :| ["","Intermediate results"]},+--   Indent {n = 0},+--   Text {someLines = "\\begin{mycode}" :| ["","Intermediate results"]}, --   HaskellCode {manyLines = ["b = a 4","a = const 3"]},---   Text {someLines = "\\end{code}" :| []},+--   Text {someLines = "\\end{mycode}" :| []}, --   Dedent,---   Text {someLines = "\\begin{code}" :| []},+--   Text {someLines = "\\begin{mycode}" :| []}, --   HaskellCode {manyLines = ["answer = b * 14"]},---   Text {someLines = "\\end{code}" :| []},+--   Text {someLines = "\\end{mycode}" :| []}, --   Comment {someLines = "world!" :| ["","Hello from comments,"]}, --   CommentSingleLine {someLine = "Comment on a single line."} -- ]+ exampleTexTokens :: Tokens exampleTexTokens =   normalizeTokens $     [ Indent 3     , Disabled{manyLines = ["-- What's the answer?"]}     , Indent 1-    , Indent 2+    , Indent 0     , Text{someLines = "Intermediate results" :| []}-    , Text{someLines = "\\begin{code}" :| []}+    , codeStart     , HaskellCode ["   b = a 4", "   a = const 3"]-    , Text{someLines = "\\end{code}" :| []}+    , codeEnd     , Dedent-    , Text{someLines = "\\begin{code}" :| []}+    , codeStart     , HaskellCode ["answer = b * 14"]-    , Text{someLines = "\\end{code}" :| []}+    , codeEnd     , Comment ("Hello from comments," :| [])     , Comment ("world!" :| [])     , CommentSingleLine ("Comment on a single line.")     ]+  where +    codeStart = Text{someLines = def @(Config Internal) ^. texHaskellCodeStart :| []}+    codeEnd = Text{someLines = def @(Config Internal) ^. texHaskellCodeEnd :| []}  -- | Compose a function that converts a document in one 'Format' to a document in another 'Format'. convertTo :: Format -> Format -> Config User -> T.Text -> T.Text@@ -712,20 +757,20 @@ -- <BLANKLINE> -- % LIMA_INDENT 1 -- <BLANKLINE>--- % LIMA_INDENT 2+-- % LIMA_INDENT 0 -- <BLANKLINE> -- Intermediate results -- <BLANKLINE>--- \begin{code}---   a = const 3---   b = a 4--- \end{code}+-- \begin{mycode}+-- a = const 3+-- b = a 4+-- \end{mycode} -- <BLANKLINE> -- % LIMA_DEDENT -- <BLANKLINE>--- \begin{code}+-- \begin{mycode} -- answer = b * 14--- \end{code}+-- \end{mycode} -- <BLANKLINE> -- % Hello from comments, -- <BLANKLINE>@@ -898,6 +943,7 @@ -- % LIMA_INDENT 2 -- <BLANKLINE> -- - Intermediate results+-- <BLANKLINE> -- >   a = const 3 -- >   b = a 4 -- <BLANKLINE>@@ -924,32 +970,19 @@ -- These 'T.Text's are concatenated in 'lhsFromTokens'. lhsFromTokens' :: Config User -> Tokens -> [T.Text] lhsFromTokens' (toConfigInternal -> Config{..}) blocks =-  dropEmpties $ reverse (T.intercalate "\n" . reverse <$> (fromTokens (Dedent : blocks) (0, [])))+  dropEmpties $ reverse (T.intercalate "\n" . reverse <$> (fromTokens (blocks) (0, [])))  where   fromTokens :: Tokens -> (Int, [[T.Text]]) -> [[T.Text]]-  fromTokens bs'@(_ : cur : bs) (curIndent, rs) =-    fromTokens (cur : bs) (translate curIndent bs' rs)-  fromTokens [_] (_, rs) = rs-  fromTokens _ _ = errorNotEnoughTokens Lhs-  translate curIndent (prev : cur : _) rs =+  fromTokens (cur : bs) (curIndent, rs) =+    fromTokens bs (translate curIndent (cur : bs) rs)+  fromTokens [] (_, rs) = rs+  translate curIndent (cur : _) rs =     case cur of-      Indent{..} -> (n,) $ [lhsCommentSpace <> _indent <> " " <> T.pack (show n)] : [] : rs-      Dedent -> (0,) $ [lhsCommentSpace <> _dedent] : [] : rs-      Disabled{..} -> (0,) $ [lhsCommentSpace <> _enable] : [] : (prependLhsComment <$> manyLines) : [] : [lhsCommentSpace <> _disable] : [] : rs-      HaskellCode{..} ->-        (curIndent,) $-          ((lhsHsCodeSpace <>) . indentN curIndent <$> manyLines)-            : ( case prev of-                  Text{} -> rs-                  _ -> [] : rs-              )-      Text{..} ->-        (curIndent,) $-          toList (lhsEscapeHash <$> someLines)-            : ( case prev of-                  HaskellCode{} -> rs-                  _ -> [] : rs-              )+      Indent{..} -> (n, [lhsCommentSpace <> _indent <> " " <> T.pack (show n)] : [] : rs)+      Dedent -> (0, [lhsCommentSpace <> _dedent] : [] : rs)+      Disabled{..} -> (0, [lhsCommentSpace <> _enable] : [] : (prependLhsComment <$> manyLines) : [] : [lhsCommentSpace <> _disable] : [] : rs)+      HaskellCode{..} -> (curIndent, ((lhsHsCodeSpace <>) . indentN curIndent <$> manyLines) : [] : rs)+      Text{..} -> (curIndent, toList (lhsEscapeHash <$> someLines) : [] : rs)       Comment{someLines = t :| ts} -> (curIndent, (prependLhsComment <$> t : ts) : [] : rs)       CommentSingleLine{someLine} -> (curIndent, [prependLhsComment $ _lhsSingleLineCommentStart <> someLine] : [] : rs)   translate _ _ _ = errorNotEnoughTokens Lhs
test/Conversions/Main.hs view
@@ -81,7 +81,7 @@ selectFormats :: Format -> [Format] selectFormats = \case   TeX -> [Hs, Md, Lhs, TeX]-  _ -> [Hs, Md, Lhs]+  _ -> [Hs, Lhs, Md]  testWrite :: Format -> TestTree testWrite format =
− testdata/md/test.lhs
@@ -1,29 +0,0 @@-% LIMA_INDENT 3--% LIMA_DISABLE--% -- What's the answer?--% LIMA_ENABLE--% LIMA_INDENT 1--% LIMA_INDENT 2--- Intermediate results->   a = const 3->   b = a 4--% LIMA_DEDENT--> answer = b * 14--% Hello from comments,--% world!--% SINGLE_LINE Comment on a single line.--Hello from text,--world!
testdata/tex/test.hs view
@@ -8,31 +8,31 @@  {- LIMA_INDENT 1 -} -{- LIMA_INDENT 2 -}+{- LIMA_INDENT 0 -}  {- Intermediate results -\begin{code}+\begin{mycode} -}  a = const 3 b = a 4  {--\end{code}+\end{mycode} -}  {- LIMA_DEDENT -}  {--\begin{code}+\begin{mycode} -}  answer = b * 14  {--\end{code}+\end{mycode} -}  {- Hello from comments,
testdata/tex/test.lhs view
@@ -8,20 +8,24 @@  % LIMA_INDENT 1 -% LIMA_INDENT 2+% LIMA_INDENT 0  Intermediate results -\begin{code}->   a = const 3->   b = a 4-\end{code}+\begin{mycode} +> a = const 3+> b = a 4++\end{mycode}+ % LIMA_DEDENT -\begin{code}+\begin{mycode}+ > answer = b * 14-\end{code}++\end{mycode}  % Hello from comments, 
testdata/tex/test.md view
@@ -8,28 +8,28 @@   <!-- LIMA_INDENT 1 --> -  <!-- LIMA_INDENT 2 -->+<!-- LIMA_INDENT 0 -->  Intermediate results -\begin{code}+\begin{mycode} -  ```haskell-  a = const 3-  b = a 4-  ```+```haskell+a = const 3+b = a 4+``` -\end{code}+\end{mycode}  <!-- LIMA_DEDENT --> -\begin{code}+\begin{mycode}  ```haskell answer = b * 14 ``` -\end{code}+\end{mycode}  <!-- Hello from comments, 
testdata/tex/test.tex view
@@ -8,20 +8,20 @@  % LIMA_INDENT 1 -% LIMA_INDENT 2+% LIMA_INDENT 0  Intermediate results -\begin{code}-  a = const 3-  b = a 4-\end{code}+\begin{mycode}+a = const 3+b = a 4+\end{mycode}  % LIMA_DEDENT -\begin{code}+\begin{mycode} answer = b * 14-\end{code}+\end{mycode}  % Hello from comments, 
testdata/tex/tokens.hs view
@@ -5,9 +5,9 @@ , Indent     { n = 1 } , Indent-    { n = 2 }+    { n = 0 } , Text-    { someLines = "\\begin{code}" :|+    { someLines = "\\begin{mycode}" :|         [ ""         , "Intermediate results"         ]@@ -19,14 +19,14 @@         ]     } , Text-    { someLines = "\\end{code}" :| [] }+    { someLines = "\\end{mycode}" :| [] } , Dedent , Text-    { someLines = "\\begin{code}" :| [] }+    { someLines = "\\begin{mycode}" :| [] } , HaskellCode     { manyLines = [ "answer = b * 14" ] } , Text-    { someLines = "\\end{code}" :| [] }+    { someLines = "\\end{mycode}" :| [] } , Comment     { someLines = "world!" :|         [ ""