aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/Marshaling/AST.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Lua/Marshaling/AST.hs')
-rw-r--r--src/Text/Pandoc/Lua/Marshaling/AST.hs33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/Text/Pandoc/Lua/Marshaling/AST.hs b/src/Text/Pandoc/Lua/Marshaling/AST.hs
index eedf00a94..6f97bdd36 100644
--- a/src/Text/Pandoc/Lua/Marshaling/AST.hs
+++ b/src/Text/Pandoc/Lua/Marshaling/AST.hs
@@ -40,7 +40,7 @@ import Control.Monad ((<$!>), (>=>))
import HsLua hiding (Operation (Div))
import Text.Pandoc.Definition
import Text.Pandoc.Lua.Util (pushViaConstr', pushViaConstructor)
-import Text.Pandoc.Lua.Marshaling.CommonState ()
+import Text.Pandoc.Lua.Marshaling.List (pushPandocList)
import qualified HsLua as Lua
import qualified Text.Pandoc.Lua.Util as LuaUtil
@@ -49,19 +49,32 @@ instance Pushable Pandoc where
push = pushPandoc
pushPandoc :: LuaError e => Pusher e Pandoc
-pushPandoc (Pandoc meta blocks) =
- pushViaConstr' "Pandoc" [pushList pushBlock blocks, push meta]
+pushPandoc = pushUD typePandoc
peekPandoc :: LuaError e => Peeker e Pandoc
-peekPandoc = fmap (retrieving "Pandoc value")
- . typeChecked "table" Lua.istable $ \idx -> do
- meta <- peekFieldRaw peekMeta "meta" idx
- blks <- peekFieldRaw peekBlocks "blocks" idx
- return $ Pandoc meta blks
+peekPandoc = retrieving "Pandoc value" . peekUD typePandoc
+
+typePandoc :: LuaError e => DocumentedType e Pandoc
+typePandoc = deftype "Pandoc"
+ [ operation Eq $ defun "__eq"
+ ### liftPure2 (==)
+ <#> parameter (optional . peekPandoc) "doc1" "pandoc" ""
+ <#> parameter (optional . peekPandoc) "doc2" "pandoc" ""
+ =#> functionResult pushBool "boolean" "true iff the two values are equal"
+ ]
+ [ property "blocks" "list of blocks"
+ (pushPandocList pushBlock, \(Pandoc _ blks) -> blks)
+ (peekList peekBlock, \(Pandoc m _) blks -> Pandoc m blks)
+ , property "meta" "document metadata"
+ (pushMeta, \(Pandoc meta _) -> meta)
+ (peekMeta, \(Pandoc _ blks) meta -> Pandoc meta blks)
+ ]
instance Pushable Meta where
- push (Meta mmap) =
- pushViaConstr' "Meta" [push mmap]
+ push = pushMeta
+
+pushMeta :: LuaError e => Pusher e Meta
+pushMeta (Meta mmap) = pushViaConstr' "Meta" [push mmap]
peekMeta :: LuaError e => Peeker e Meta
peekMeta idx = retrieving "Meta" $