aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Lua/Marshaling/ReaderOptions.hs
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2021-11-28 02:08:01 +0100
committerGitHub <noreply@github.com>2021-11-27 17:08:01 -0800
commit3692a1d1e83703fbf235214f2838cd92683c625c (patch)
tree2eb377285e1ca485c03ea60eef1d92ff58827666 /src/Text/Pandoc/Lua/Marshaling/ReaderOptions.hs
parent0d25232bbf2998cccf6ca4b1dc6e8d6f36eb9c60 (diff)
downloadpandoc-3692a1d1e83703fbf235214f2838cd92683c625c.tar.gz
Lua: use package pandoc-lua-marshal (#7719)
The marshaling functions for pandoc's AST are extracted into a separate package. The package comes with a number of changes: - Pandoc's List module was rewritten in C, thereby improving error messages. - Lists of `Block` and `Inline` elements are marshaled using the new list types `Blocks` and `Inlines`, respectively. These types currently behave identical to the generic List type, but give better error messages. This also opens up the possibility of adding element-specific methods to these lists in the future. - Elements of type `MetaValue` are no longer pushed as values which have `.t` and `.tag` properties. This was already true for `MetaString` and `MetaBool` values, which are still marshaled as Lua strings and booleans, respectively. Affected values: + `MetaBlocks` values are marshaled as a `Blocks` list; + `MetaInlines` values are marshaled as a `Inlines` list; + `MetaList` values are marshaled as a generic pandoc `List`s. + `MetaMap` values are marshaled as plain tables and no longer given any metatable. - The test suite for marshaled objects and their constructors has been extended and improved. - A bug in Citation objects, where setting a citation's suffix modified it's prefix, has been fixed.
Diffstat (limited to 'src/Text/Pandoc/Lua/Marshaling/ReaderOptions.hs')
-rw-r--r--src/Text/Pandoc/Lua/Marshaling/ReaderOptions.hs133
1 files changed, 0 insertions, 133 deletions
diff --git a/src/Text/Pandoc/Lua/Marshaling/ReaderOptions.hs b/src/Text/Pandoc/Lua/Marshaling/ReaderOptions.hs
deleted file mode 100644
index 91eb22ae9..000000000
--- a/src/Text/Pandoc/Lua/Marshaling/ReaderOptions.hs
+++ /dev/null
@@ -1,133 +0,0 @@
-{-# LANGUAGE LambdaCase #-}
-{-# LANGUAGE OverloadedStrings #-}
-{-# LANGUAGE ScopedTypeVariables #-}
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-{- |
- Module : Text.Pandoc.Lua.Marshaling.ReaderOptions
- Copyright : © 2012-2021 John MacFarlane
- © 2017-2021 Albert Krewinkel
- License : GNU GPL, version 2 or above
-
- Maintainer : Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
- Stability : alpha
-
-Marshaling instance for ReaderOptions and its components.
--}
-module Text.Pandoc.Lua.Marshaling.ReaderOptions
- ( peekReaderOptions
- , pushReaderOptions
- , pushReaderOptionsReadonly
- ) where
-
-import Data.Default (def)
-import HsLua as Lua
-import Text.Pandoc.Lua.Marshaling.List (pushPandocList)
-import Text.Pandoc.Options (ReaderOptions (..))
-
---
--- Reader Options
---
-
--- | Retrieve a ReaderOptions value, either from a normal ReaderOptions
--- value, from a read-only object, or from a table with the same
--- keys as a ReaderOptions object.
-peekReaderOptions :: LuaError e => Peeker e ReaderOptions
-peekReaderOptions = retrieving "ReaderOptions" . \idx ->
- liftLua (ltype idx) >>= \case
- TypeUserdata -> choice [ peekUD typeReaderOptions
- , peekUD typeReaderOptionsReadonly
- ]
- idx
- TypeTable -> peekReaderOptionsTable idx
- _ -> failPeek =<<
- typeMismatchMessage "ReaderOptions userdata or table" idx
-
--- | Pushes a ReaderOptions value as userdata object.
-pushReaderOptions :: LuaError e => Pusher e ReaderOptions
-pushReaderOptions = pushUD typeReaderOptions
-
--- | Pushes a ReaderOptions object, but makes it read-only.
-pushReaderOptionsReadonly :: LuaError e => Pusher e ReaderOptions
-pushReaderOptionsReadonly = pushUD typeReaderOptionsReadonly
-
--- | ReaderOptions object type for read-only values.
-typeReaderOptionsReadonly :: LuaError e => DocumentedType e ReaderOptions
-typeReaderOptionsReadonly = deftype "ReaderOptions (read-only)"
- [ operation Tostring $ lambda
- ### liftPure show
- <#> udparam typeReaderOptions "opts" "options to print in native format"
- =#> functionResult pushString "string" "Haskell representation"
- , operation Newindex $ lambda
- ### (failLua "This ReaderOptions value is read-only.")
- =?> "Throws an error when called, i.e., an assignment is made."
- ]
- readerOptionsMembers
-
--- | 'ReaderOptions' object type.
-typeReaderOptions :: LuaError e => DocumentedType e ReaderOptions
-typeReaderOptions = deftype "ReaderOptions"
- [ operation Tostring $ lambda
- ### liftPure show
- <#> udparam typeReaderOptions "opts" "options to print in native format"
- =#> functionResult pushString "string" "Haskell representation"
- ]
- readerOptionsMembers
-
--- | Member properties of 'ReaderOptions' Lua values.
-readerOptionsMembers :: LuaError e
- => [Member e (DocumentedFunction e) ReaderOptions]
-readerOptionsMembers =
- [ property "abbreviations" ""
- (pushSet pushText, readerAbbreviations)
- (peekSet peekText, \opts x -> opts{ readerAbbreviations = x })
- , property "columns" ""
- (pushIntegral, readerColumns)
- (peekIntegral, \opts x -> opts{ readerColumns = x })
- , property "default_image_extension" ""
- (pushText, readerDefaultImageExtension)
- (peekText, \opts x -> opts{ readerDefaultImageExtension = x })
- , property "extensions" ""
- (pushString . show, readerExtensions)
- (peekRead, \opts x -> opts{ readerExtensions = x })
- , property "indented_code_classes" ""
- (pushPandocList pushText, readerIndentedCodeClasses)
- (peekList peekText, \opts x -> opts{ readerIndentedCodeClasses = x })
- , property "strip_comments" ""
- (pushBool, readerStripComments)
- (peekBool, \opts x -> opts{ readerStripComments = x })
- , property "standalone" ""
- (pushBool, readerStandalone)
- (peekBool, \opts x -> opts{ readerStandalone = x })
- , property "tab_stop" ""
- (pushIntegral, readerTabStop)
- (peekIntegral, \opts x -> opts{ readerTabStop = x })
- , property "track_changes" ""
- (pushString . show, readerTrackChanges)
- (peekRead, \opts x -> opts{ readerTrackChanges = x })
- ]
-
--- | Retrieves a 'ReaderOptions' object from a table on the stack, using
--- the default values for all missing fields.
---
--- Internally, this pushes the default reader options, sets each
--- key/value pair of the table in the userdata value, then retrieves the
--- object again. This will update all fields and complain about unknown
--- keys.
-peekReaderOptionsTable :: LuaError e => Peeker e ReaderOptions
-peekReaderOptionsTable idx = retrieving "ReaderOptions (table)" $ do
- liftLua $ do
- absidx <- absindex idx
- pushUD typeReaderOptions def
- let setFields = do
- next absidx >>= \case
- False -> return () -- all fields were copied
- True -> do
- pushvalue (nth 2) *> insert (nth 2)
- settable (nth 4) -- set in userdata object
- setFields
- pushnil -- first key
- setFields
- peekUD typeReaderOptions top
-
-instance Pushable ReaderOptions where
- push = pushReaderOptions