git.iko.soy/typeable/pandoc
on master help sign in
Delete Text.Pandoc.Lua.SharedInstances

Stack instances for common data types are now provides by hslua. The instance for Either was useful only for a very specific case; the function that was using the `ToLuaStack Either` instance was rewritten to work without it. Closes: #3805

commit3d87e2080a27618e70edd1ff2d4160ff959732a6 authorAlbert Krewinkel <albert@zeitkraut.de> dateSun 13 Aug 2017, 17:48 (9 years ago) parent6e6cee4
6 files changed+11−59
pandoc.cabal−1 src/Text/Pandoc/Lua.hs−1 src/Text/Pandoc/Lua/PandocModule.hs+11−11 src/Text/Pandoc/Lua/SharedInstances.hs−44 src/Text/Pandoc/Lua/StackInstances.hs−1 src/Text/Pandoc/Writers/Custom.hs−1
pandoc.cabal−1
@@ -465,7 +465,6 @@ Library
465465 Text.Pandoc.Readers.Org.Parsing,
466466 Text.Pandoc.Readers.Org.Shared,
467467 Text.Pandoc.Lua.PandocModule,
468− Text.Pandoc.Lua.SharedInstances,
469468 Text.Pandoc.Lua.StackInstances,
470469 Text.Pandoc.Lua.Util,
471470 Text.Pandoc.CSS,
src/Text/Pandoc/Lua.hs−1
@@ -44,7 +44,6 @@ import Foreign.Lua (Lua, FromLuaStack (peek), LuaException (..), StackIndex,
4444 registryindex, runLua, setglobal, throwLuaError)
4545import Text.Pandoc.Definition
4646import Text.Pandoc.Lua.PandocModule (pushPandocModule)
47−import Text.Pandoc.Lua.StackInstances ()
4847import Text.Pandoc.Walk (Walkable (walkM))
4948
5049import qualified Data.Map as Map
src/Text/Pandoc/Lua/PandocModule.hs+11−11
@@ -31,10 +31,9 @@ import Control.Monad (unless)
3131import Data.ByteString.Char8 (unpack)
3232import Data.Default (Default (..))
3333import Data.Text (pack)
34−import Foreign.Lua (Lua, Status (OK), liftIO, push, pushHaskellFunction)
35−import Foreign.Lua.Api (call, loadstring, rawset)
36−import Text.Pandoc.Class
37−import Text.Pandoc.Definition (Pandoc)
34+import Foreign.Lua (Lua, Status (OK), NumResults, call, loadstring, liftIO,
35+ push, pushHaskellFunction, rawset)
36+import Text.Pandoc.Class (readDataFile, runIO, runIOorExplode, setUserDataDir)
3837import Text.Pandoc.Options (ReaderOptions(readerExtensions))
3938import Text.Pandoc.Lua.StackInstances ()
4039import Text.Pandoc.Readers (Reader (..), getReader)
@@ -54,16 +53,17 @@ pandocModuleScript :: Maybe FilePath -> IO String
5453pandocModuleScript datadir = unpack <$>
5554 runIOorExplode (setUserDataDir datadir >> readDataFile "pandoc.lua")
5655
57−readDoc :: String -> String -> Lua (Either String Pandoc)
58−readDoc formatSpec content = liftIO $ do
56+readDoc :: String -> String -> Lua NumResults
57+readDoc formatSpec content = do
5958 case getReader formatSpec of
60− Left s -> return $ Left s
59+ Left s -> push s -- Unknown reader
6160 Right (reader, es) ->
6261 case reader of
6362 TextReader r -> do
64− res <- runIO $ r def{ readerExtensions = es } (pack content)
63+ res <- liftIO $ runIO $ r def{ readerExtensions = es } (pack content)
6564 case res of
66− Left s -> return . Left $ show s
67− Right pd -> return $ Right pd
68− _ -> return $ Left "Only string formats are supported at the moment."
65+ Left s -> push $ show s -- error while reading
66+ Right pd -> push pd -- success, push Pandoc
67+ _ -> push "Only string formats are supported at the moment."
68+ return 1
6969
src/Text/Pandoc/Lua/SharedInstances.hsdeleted−44
@@ -1,44 +0,0 @@
1−{-
2−Copyright © 2012-2017 John MacFarlane <jgm@berkeley.edu>
3− 2017 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
4−
5−This program is free software; you can redistribute it and/or modify
6−it under the terms of the GNU General Public License as published by
7−the Free Software Foundation; either version 2 of the License, or
8−(at your option) any later version.
9−
10−This program is distributed in the hope that it will be useful,
11−but WITHOUT ANY WARRANTY; without even the implied warranty of
12−MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13−GNU General Public License for more details.
14−
15−You should have received a copy of the GNU General Public License
16−along with this program; if not, write to the Free Software
17−Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18−-}
19−{-# LANGUAGE CPP #-}
20−{-# LANGUAGE FlexibleInstances #-}
21−{-# LANGUAGE LambdaCase #-}
22−#if !MIN_VERSION_base(4,8,0)
23−{-# LANGUAGE OverlappingInstances #-}
24−#endif
25−{-# OPTIONS_GHC -fno-warn-orphans #-}
26−{- |
27− Module : Text.Pandoc.Lua.SharedInstances
28− Copyright : © 2012–2016 John MacFarlane,
29− © 2017 Albert Krewinkel
30− License : GNU GPL, version 2 or above
31−
32− Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
33− Stability : alpha
34−
35−Shared StackValue instances for pandoc and generic types.
36−-}
37−module Text.Pandoc.Lua.SharedInstances () where
38−
39−import Foreign.Lua (ToLuaStack (push))
40−
41−instance (ToLuaStack a, ToLuaStack b) => ToLuaStack (Either a b) where
42− push = \case
43− Left x -> push x
44− Right x -> push x
src/Text/Pandoc/Lua/StackInstances.hs−1
@@ -37,7 +37,6 @@ import Foreign.Lua (Lua, Type (..), FromLuaStack (peek), ToLuaStack (push),
3737 StackIndex, throwLuaError, tryLua)
3838import Foreign.Lua.Api (getmetatable, ltype, newtable, pop, rawget, rawlen)
3939import Text.Pandoc.Definition
40−import Text.Pandoc.Lua.SharedInstances ()
4140import Text.Pandoc.Lua.Util (addValue, adjustIndexBy, getTable, pushViaConstructor)
4241import Text.Pandoc.Shared (safeRead)
4342
src/Text/Pandoc/Writers/Custom.hs−1
@@ -48,7 +48,6 @@ import Foreign.Lua (Lua, ToLuaStack (..), callFunc, runLua)
4848import Foreign.Lua.Api
4949import Text.Pandoc.Error
5050import Text.Pandoc.Lua.Util ( addValue )
51−import Text.Pandoc.Lua.SharedInstances ()
5251import Text.Pandoc.Definition
5352import Text.Pandoc.Options
5453import Text.Pandoc.Templates