{-# LANGUAGE CPP #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Text.Pandoc.Lua.Marshal.ReaderOptions
( peekReaderOptions
, pushReaderOptions
, pushReaderOptionsReadonly
) where
import Data.Default (def)
import HsLua as Lua
#if !MIN_VERSION_hslua(2,2,0)
import HsLua.Aeson (peekViaJSON, pushViaJSON)
#endif
import Text.Pandoc.Lua.Marshal.List (pushPandocList)
import Text.Pandoc.Options (ReaderOptions (..))
peekReaderOptions :: LuaError e => Peeker e ReaderOptions
peekReaderOptions :: forall e. LuaError e => Peeker e ReaderOptions
peekReaderOptions = forall e a. Name -> Peek e a -> Peek e a
retrieving Name
"ReaderOptions" forall b c a. (b -> c) -> (a -> b) -> a -> c
. \StackIndex
idx ->
forall e a. LuaE e a -> Peek e a
liftLua (forall e. StackIndex -> LuaE e Type
ltype StackIndex
idx) forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Type
TypeUserdata -> forall e a. LuaError e => [Peeker e a] -> Peeker e a
choice [ forall e fn a itemtype.
LuaError e =>
UDTypeWithList e fn a itemtype -> Peeker e a
peekUD forall e. LuaError e => DocumentedType e ReaderOptions
typeReaderOptions
, forall e fn a itemtype.
LuaError e =>
UDTypeWithList e fn a itemtype -> Peeker e a
peekUD forall e. LuaError e => DocumentedType e ReaderOptions
typeReaderOptionsReadonly
]
StackIndex
idx
Type
TypeTable -> forall e. LuaError e => Peeker e ReaderOptions
peekReaderOptionsTable StackIndex
idx
Type
_ -> forall a e. ByteString -> Peek e a
failPeek forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<<
forall e. Name -> StackIndex -> Peek e ByteString
typeMismatchMessage Name
"ReaderOptions userdata or table" StackIndex
idx
pushReaderOptions :: LuaError e => Pusher e ReaderOptions
pushReaderOptions :: forall e. LuaError e => Pusher e ReaderOptions
pushReaderOptions = forall e fn a itemtype.
LuaError e =>
UDTypeWithList e fn a itemtype -> a -> LuaE e ()
pushUD forall e. LuaError e => DocumentedType e ReaderOptions
typeReaderOptions
pushReaderOptionsReadonly :: LuaError e => Pusher e ReaderOptions
pushReaderOptionsReadonly :: forall e. LuaError e => Pusher e ReaderOptions
pushReaderOptionsReadonly = forall e fn a itemtype.
LuaError e =>
UDTypeWithList e fn a itemtype -> a -> LuaE e ()
pushUD forall e. LuaError e => DocumentedType e ReaderOptions
typeReaderOptionsReadonly
typeReaderOptionsReadonly :: LuaError e => DocumentedType e ReaderOptions
typeReaderOptionsReadonly :: forall e. LuaError e => DocumentedType e ReaderOptions
typeReaderOptionsReadonly = forall e a.
LuaError e =>
Name
-> [(Operation, DocumentedFunction e)]
-> [Member e (DocumentedFunction e) a]
-> DocumentedType e a
deftype Name
"ReaderOptions (read-only)"
[ forall e.
Operation
-> DocumentedFunction e -> (Operation, DocumentedFunction e)
operation Operation
Tostring forall a b. (a -> b) -> a -> b
$ forall a e. a -> HsFnPrecursor e a
lambda
### liftPure show
forall e a b.
HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
<#> forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype
-> Text -> Text -> Parameter e a
udparam forall e. LuaError e => DocumentedType e ReaderOptions
typeReaderOptions Text
"opts" Text
"options to print in native format"
forall e a.
HsFnPrecursor e (LuaE e a)
-> FunctionResults e a -> DocumentedFunction e
=#> forall e a. Pusher e a -> Text -> Text -> FunctionResults e a
functionResult forall e. String -> LuaE e ()
pushString Text
"string" Text
"Haskell representation"
, forall e.
Operation
-> DocumentedFunction e -> (Operation, DocumentedFunction e)
operation Operation
Newindex forall a b. (a -> b) -> a -> b
$ forall a e. a -> HsFnPrecursor e a
lambda
### (failLua "This ReaderOptions value is read-only.")
forall e.
HsFnPrecursor e (LuaE e NumResults) -> Text -> DocumentedFunction e
=?> Text
"Throws an error when called, i.e., an assignment is made."
]
forall e.
LuaError e =>
[Member e (DocumentedFunction e) ReaderOptions]
readerOptionsMembers
typeReaderOptions :: LuaError e => DocumentedType e ReaderOptions
typeReaderOptions :: forall e. LuaError e => DocumentedType e ReaderOptions
typeReaderOptions = forall e a.
LuaError e =>
Name
-> [(Operation, DocumentedFunction e)]
-> [Member e (DocumentedFunction e) a]
-> DocumentedType e a
deftype Name
"ReaderOptions"
[ forall e.
Operation
-> DocumentedFunction e -> (Operation, DocumentedFunction e)
operation Operation
Tostring forall a b. (a -> b) -> a -> b
$ forall a e. a -> HsFnPrecursor e a
lambda
### liftPure show
forall e a b.
HsFnPrecursor e (a -> b) -> Parameter e a -> HsFnPrecursor e b
<#> forall e a itemtype.
LuaError e =>
DocumentedTypeWithList e a itemtype
-> Text -> Text -> Parameter e a
udparam forall e. LuaError e => DocumentedType e ReaderOptions
typeReaderOptions Text
"opts" Text
"options to print in native format"
forall e a.
HsFnPrecursor e (LuaE e a)
-> FunctionResults e a -> DocumentedFunction e
=#> forall e a. Pusher e a -> Text -> Text -> FunctionResults e a
functionResult forall e. String -> LuaE e ()
pushString Text
"string" Text
"Haskell representation"
]
forall e.
LuaError e =>
[Member e (DocumentedFunction e) ReaderOptions]
readerOptionsMembers
readerOptionsMembers :: LuaError e
=> [Member e (DocumentedFunction e) ReaderOptions]
readerOptionsMembers :: forall e.
LuaError e =>
[Member e (DocumentedFunction e) ReaderOptions]
readerOptionsMembers =
[ forall e b a fn.
LuaError e =>
Name
-> Text
-> (Pusher e b, a -> b)
-> (Peeker e b, a -> b -> a)
-> Member e fn a
property Name
"abbreviations" Text
""
(forall e a. LuaError e => Pusher e a -> Pusher e (Set a)
pushSet forall e. Pusher e Text
pushText, ReaderOptions -> Set Text
readerAbbreviations)
(forall e a. (LuaError e, Ord a) => Peeker e a -> Peeker e (Set a)
peekSet forall e. Peeker e Text
peekText, \ReaderOptions
opts Set Text
x -> ReaderOptions
opts{ readerAbbreviations :: Set Text
readerAbbreviations = Set Text
x })
, forall e b a fn.
LuaError e =>
Name
-> Text
-> (Pusher e b, a -> b)
-> (Peeker e b, a -> b -> a)
-> Member e fn a
property Name
"columns" Text
""
(forall a e. (Integral a, Show a) => a -> LuaE e ()
pushIntegral, ReaderOptions -> Int
readerColumns)
(forall a e. (Integral a, Read a) => Peeker e a
peekIntegral, \ReaderOptions
opts Int
x -> ReaderOptions
opts{ readerColumns :: Int
readerColumns = Int
x })
, forall e b a fn.
LuaError e =>
Name
-> Text
-> (Pusher e b, a -> b)
-> (Peeker e b, a -> b -> a)
-> Member e fn a
property Name
"default_image_extension" Text
""
(forall e. Pusher e Text
pushText, ReaderOptions -> Text
readerDefaultImageExtension)
(forall e. Peeker e Text
peekText, \ReaderOptions
opts Text
x -> ReaderOptions
opts{ readerDefaultImageExtension :: Text
readerDefaultImageExtension = Text
x })
, forall e b a fn.
LuaError e =>
Name
-> Text
-> (Pusher e b, a -> b)
-> (Peeker e b, a -> b -> a)
-> Member e fn a
property Name
"extensions" Text
""
(forall a e. (ToJSON a, LuaError e) => Pusher e a
pushViaJSON, ReaderOptions -> Extensions
readerExtensions)
(forall a e. (FromJSON a, LuaError e) => Peeker e a
peekViaJSON, \ReaderOptions
opts Extensions
x -> ReaderOptions
opts{ readerExtensions :: Extensions
readerExtensions = Extensions
x })
, forall e b a fn.
LuaError e =>
Name
-> Text
-> (Pusher e b, a -> b)
-> (Peeker e b, a -> b -> a)
-> Member e fn a
property Name
"indented_code_classes" Text
""
(forall e a. LuaError e => Pusher e a -> Pusher e [a]
pushPandocList forall e. Pusher e Text
pushText, ReaderOptions -> [Text]
readerIndentedCodeClasses)
(forall a e. LuaError e => Peeker e a -> Peeker e [a]
peekList forall e. Peeker e Text
peekText, \ReaderOptions
opts [Text]
x -> ReaderOptions
opts{ readerIndentedCodeClasses :: [Text]
readerIndentedCodeClasses = [Text]
x })
, forall e b a fn.
LuaError e =>
Name
-> Text
-> (Pusher e b, a -> b)
-> (Peeker e b, a -> b -> a)
-> Member e fn a
property Name
"standalone" Text
""
(forall e. Pusher e Bool
pushBool, ReaderOptions -> Bool
readerStandalone)
(forall e. Peeker e Bool
peekBool, \ReaderOptions
opts Bool
x -> ReaderOptions
opts{ readerStandalone :: Bool
readerStandalone = Bool
x })
, forall e b a fn.
LuaError e =>
Name
-> Text
-> (Pusher e b, a -> b)
-> (Peeker e b, a -> b -> a)
-> Member e fn a
property Name
"strip_comments" Text
""
(forall e. Pusher e Bool
pushBool, ReaderOptions -> Bool
readerStripComments)
(forall e. Peeker e Bool
peekBool, \ReaderOptions
opts Bool
x -> ReaderOptions
opts{ readerStripComments :: Bool
readerStripComments = Bool
x })
, forall e b a fn.
LuaError e =>
Name
-> Text
-> (Pusher e b, a -> b)
-> (Peeker e b, a -> b -> a)
-> Member e fn a
property Name
"tab_stop" Text
""
(forall a e. (Integral a, Show a) => a -> LuaE e ()
pushIntegral, ReaderOptions -> Int
readerTabStop)
(forall a e. (Integral a, Read a) => Peeker e a
peekIntegral, \ReaderOptions
opts Int
x -> ReaderOptions
opts{ readerTabStop :: Int
readerTabStop = Int
x })
, forall e b a fn.
LuaError e =>
Name
-> Text
-> (Pusher e b, a -> b)
-> (Peeker e b, a -> b -> a)
-> Member e fn a
property Name
"track_changes" Text
""
(forall a e. (ToJSON a, LuaError e) => Pusher e a
pushViaJSON, ReaderOptions -> TrackChanges
readerTrackChanges)
(forall e a. LuaError e => [Peeker e a] -> Peeker e a
choice [forall a e. Read a => Peeker e a
peekRead, forall a e. (FromJSON a, LuaError e) => Peeker e a
peekViaJSON], \ReaderOptions
opts TrackChanges
x -> ReaderOptions
opts{ readerTrackChanges :: TrackChanges
readerTrackChanges = TrackChanges
x })
]
peekReaderOptionsTable :: LuaError e => Peeker e ReaderOptions
peekReaderOptionsTable :: forall e. LuaError e => Peeker e ReaderOptions
peekReaderOptionsTable StackIndex
idx = forall e a. Name -> Peek e a -> Peek e a
retrieving Name
"ReaderOptions (table)" forall a b. (a -> b) -> a -> b
$ do
forall e a. LuaE e a -> Peek e a
liftLua forall a b. (a -> b) -> a -> b
$ do
StackIndex
absidx <- forall e. StackIndex -> LuaE e StackIndex
absindex StackIndex
idx
forall e fn a itemtype.
LuaError e =>
UDTypeWithList e fn a itemtype -> a -> LuaE e ()
pushUD forall e. LuaError e => DocumentedType e ReaderOptions
typeReaderOptions forall a. Default a => a
def
let setFields :: LuaE e ()
setFields = do
forall e. LuaError e => StackIndex -> LuaE e Bool
next StackIndex
absidx forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Bool
False -> forall (m :: * -> *) a. Monad m => a -> m a
return ()
Bool
True -> do
forall e. StackIndex -> LuaE e ()
pushvalue (CInt -> StackIndex
nth CInt
2) forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> forall e. StackIndex -> LuaE e ()
insert (CInt -> StackIndex
nth CInt
2)
forall e. LuaError e => StackIndex -> LuaE e ()
settable (CInt -> StackIndex
nth CInt
4)
LuaE e ()
setFields
forall e. LuaE e ()
pushnil
LuaE e ()
setFields
forall e fn a itemtype.
LuaError e =>
UDTypeWithList e fn a itemtype -> Peeker e a
peekUD forall e. LuaError e => DocumentedType e ReaderOptions
typeReaderOptions StackIndex
top forall e a b. Peek e a -> LuaE e b -> Peek e a
`lastly` forall e. Int -> LuaE e ()
pop Int
1
instance Pushable ReaderOptions where
push :: forall e. LuaError e => Pusher e ReaderOptions
push = forall e. LuaError e => Pusher e ReaderOptions
pushReaderOptions