git.iko.soy/typeable/pandoc
on master help sign in
Lua filter: use lua strings for nullary constructors
d671b69Albert Krewinkel
data/pandoc.lua+22−44
@@ -565,115 +565,93 @@ M.Superscript = M.Inline:create_constructor(
565
565
566--- Math content is to be displayed on a separate line.
566--- Math content is to be displayed on a separate line.
567-- @see Math
567-- @see Math
568−M.DisplayMath = {}
568+M.DisplayMath = "DisplayMath"
569−M.DisplayMath.t = "DisplayMath"
570--- Math content is to be displayed inline within the paragraph
569--- Math content is to be displayed inline within the paragraph
571-- @see Math
570-- @see Math
572−M.InlineMath = {}
571+M.InlineMath = "InlineMath"
573−M.InlineMath.t = "InlineMath"
574
572
575--- Double quoted content.
573--- Double quoted content.
576-- @see Quoted
574-- @see Quoted
577−M.DoubleQuote = {}
575+M.DoubleQuote = "DoubleQuote"
578−M.DoubleQuote.t = "DoubleQuote"
579
576
580--- Single quoted content.
577--- Single quoted content.
581-- @see Quoted
578-- @see Quoted
582−M.SingleQuote = {}
579+M.SingleQuote = "SingleQuote"
583−M.SingleQuote.t = "SingleQuote"
584
580
585--- Author name is mentioned in the text.
581--- Author name is mentioned in the text.
586-- @see Citation
582-- @see Citation
587-- @see Cite
583-- @see Cite
588−M.AuthorInText = {}
584+M.AuthorInText = "AuthorInText"
589−M.AuthorInText.t = "AuthorInText"
590
585
591--- Author name is suppressed.
586--- Author name is suppressed.
592-- @see Citation
587-- @see Citation
593-- @see Cite
588-- @see Cite
594−M.SuppressAuthor = {}
589+M.SuppressAuthor = "SuppressAuthor"
595−M.SuppressAuthor.t = "SuppressAuthor"
596
590
597--- Default citation style is used.
591--- Default citation style is used.
598-- @see Citation
592-- @see Citation
599-- @see Cite
593-- @see Cite
600−M.NormalCitation = {}
594+M.NormalCitation = "NormalCitation"
601−M.NormalCitation.t = "NormalCitation"
602
595
603--- Table cells aligned left.
596--- Table cells aligned left.
604-- @see Table
597-- @see Table
605−M.AlignLeft = {}
598+M.AlignLeft = "AlignLeft"
606−M.AlignLeft.t = "AlignLeft"
607
599
608--- Table cells right-aligned.
600--- Table cells right-aligned.
609-- @see Table
601-- @see Table
610−M.AlignRight = {}
602+M.AlignRight = "AlignRight"
611−M.AlignRight.t = "AlignRight"
612
603
613--- Table cell content is centered.
604--- Table cell content is centered.
614-- @see Table
605-- @see Table
615−M.AlignCenter = {}
606+M.AlignCenter = "AlignCenter"
616−M.AlignCenter.t = "AlignCenter"
617
607
618--- Table cells are alignment is unaltered.
608--- Table cells are alignment is unaltered.
619-- @see Table
609-- @see Table
620−M.AlignDefault = {}
610+M.AlignDefault = "AlignDefault"
621−M.AlignDefault.t = "AlignDefault"
622
611
623--- Default list number delimiters are used.
612--- Default list number delimiters are used.
624-- @see OrderedList
613-- @see OrderedList
625−M.DefaultDelim = {}
614+M.DefaultDelim = "DefaultDelim"
626−M.DefaultDelim.t = "DefaultDelim"
627
615
628--- List numbers are delimited by a period.
616--- List numbers are delimited by a period.
629-- @see OrderedList
617-- @see OrderedList
630−M.Period = {}
618+M.Period = "Period"
631−M.Period.t = "Period"
632
619
633--- List numbers are delimited by a single parenthesis.
620--- List numbers are delimited by a single parenthesis.
634-- @see OrderedList
621-- @see OrderedList
635−M.OneParen = {}
622+M.OneParen = "OneParen"
636−M.OneParen.t = "OneParen"
637
623
638--- List numbers are delimited by a double parentheses.
624--- List numbers are delimited by a double parentheses.
639-- @see OrderedList
625-- @see OrderedList
640−M.TwoParens = {}
626+M.TwoParens = "TwoParens"
641−M.TwoParens.t = "TwoParens"
642
627
643--- List are numbered in the default style
628--- List are numbered in the default style
644-- @see OrderedList
629-- @see OrderedList
645−M.DefaultStyle = {}
630+M.DefaultStyle = "DefaultStyle"
646−M.DefaultStyle.t = "DefaultStyle"
647
631
648--- List items are numbered as examples.
632--- List items are numbered as examples.
649-- @see OrderedList
633-- @see OrderedList
650−M.Example = {}
634+M.Example = "Example"
651−M.Example.t = "Example"
652
635
653--- List are numbered using decimal integers.
636--- List are numbered using decimal integers.
654-- @see OrderedList
637-- @see OrderedList
655−M.Decimal = {}
638+M.Decimal = "Decimal"
656−M.Decimal.t = "Decimal"
657
639
658--- List are numbered using lower-case roman numerals.
640--- List are numbered using lower-case roman numerals.
659-- @see OrderedList
641-- @see OrderedList
660−M.LowerRoman = {}
642+M.LowerRoman = "LowerRoman"
661−M.LowerRoman.t = "LowerRoman"
662
643
663--- List are numbered using upper-case roman numerals
644--- List are numbered using upper-case roman numerals
664-- @see OrderedList
645-- @see OrderedList
665−M.UpperRoman = {}
646+M.UpperRoman = "UpperRoman"
666−M.UpperRoman.t = "UpperRoman"
667
647
668--- List are numbered using lower-case alphabetic characters.
648--- List are numbered using lower-case alphabetic characters.
669-- @see OrderedList
649-- @see OrderedList
670−M.LowerAlpha = {}
650+M.LowerAlpha = "LowerAlpha"
671−M.LowerAlpha.t = "LowerAlpha"
672
651
673--- List are numbered using upper-case alphabetic characters.
652--- List are numbered using upper-case alphabetic characters.
674-- @see OrderedList
653-- @see OrderedList
675−M.UpperAlpha = {}
654+M.UpperAlpha = "UpperAlpha"
676−M.UpperAlpha.t = "UpperAlpha"
677
655
678
656
679------------------------------------------------------------------------
657------------------------------------------------------------------------
src/Text/Pandoc/Lua/StackInstances.hs+19−80
@@ -34,10 +34,11 @@ module Text.Pandoc.Lua.StackInstances () where
34
34
35import Control.Applicative ( (<|>) )
35import Control.Applicative ( (<|>) )
36import Scripting.Lua
36import Scripting.Lua
37− ( LTYPE(..), LuaState, StackValue(..), getglobal2, ltype, newtable, objlen )
37+ ( LTYPE(..), LuaState, StackValue(..), ltype, newtable, objlen )
38import Text.Pandoc.Definition
38import Text.Pandoc.Definition
39import Text.Pandoc.Lua.SharedInstances ()
39import Text.Pandoc.Lua.SharedInstances ()
40import Text.Pandoc.Lua.Util ( addValue, getTable, pushViaConstructor )
40import Text.Pandoc.Lua.Util ( addValue, getTable, pushViaConstructor )
41+import Text.Pandoc.Shared ( safeRead )
41
42
42instance StackValue Pandoc where
43instance StackValue Pandoc where
43 push lua (Pandoc meta blocks) = do
44 push lua (Pandoc meta blocks) = do
@@ -143,19 +144,8 @@ instance StackValue Inline where
143 valuetype _ = TTABLE
144 valuetype _ = TTABLE
144
145
145instance StackValue Alignment where
146instance StackValue Alignment where
146− push lua = \case
147+ push lua = push lua . show
147− AlignLeft -> getglobal2 lua "pandoc.AlignLeft"
148− AlignRight -> getglobal2 lua "pandoc.AlignRight"
149− AlignCenter -> getglobal2 lua "pandoc.AlignCenter"
150− AlignDefault -> getglobal2 lua "pandoc.AlignDefault"
151− peek lua idx = do
148+ peek lua idx = (>>= safeRead) <$> peek lua idx
152− tag <- getTable lua idx "t"
153− case tag of
154− Just "AlignLeft" -> return $ Just AlignLeft
155− Just "AlignRight" -> return $ Just AlignRight
156− Just "AlignCenter" -> return $ Just AlignCenter
157− Just "AlignDefault" -> return $ Just AlignDefault
158− _ -> return Nothing
159 valuetype _ = TSTRING
149 valuetype _ = TSTRING
160
150
161instance StackValue Citation where
151instance StackValue Citation where
@@ -172,18 +162,9 @@ instance StackValue Citation where
172 valuetype _ = TTABLE
162 valuetype _ = TTABLE
173
163
174instance StackValue CitationMode where
164instance StackValue CitationMode where
175− push lua = \case
165+ push lua = push lua . show
176− AuthorInText -> getglobal2 lua "pandoc.AuthorInText"
177− NormalCitation -> getglobal2 lua "pandoc.NormalCitation"
178− SuppressAuthor -> getglobal2 lua "pandoc.SuppressAuthor"
179− peek lua idx = do
166+ peek lua idx = (>>= safeRead) <$> peek lua idx
180− tag <- getTable lua idx "t"
181− case tag of
182− Just "AuthorInText" -> return $ Just AuthorInText
183− Just "NormalCitation" -> return $ Just NormalCitation
184− Just "SuppressAuthor" -> return $ Just SuppressAuthor
185− _ -> return Nothing
186− valuetype _ = TTABLE
167+ valuetype _ = TSTRING
187
168
188instance StackValue Format where
169instance StackValue Format where
189 push lua (Format f) = push lua f
170 push lua (Format f) = push lua f
@@ -191,66 +172,24 @@ instance StackValue Format where
191 valuetype _ = TSTRING
172 valuetype _ = TSTRING
192
173
193instance StackValue ListNumberDelim where
174instance StackValue ListNumberDelim where
194− push lua = \case
175+ push lua = push lua . show
195− DefaultDelim -> getglobal2 lua "pandoc.DefaultDelim"
196− Period -> getglobal2 lua "pandoc.Period"
197− OneParen -> getglobal2 lua "pandoc.OneParen"
198− TwoParens -> getglobal2 lua "pandoc.TwoParens"
199− peek lua idx = do
176+ peek lua idx = (>>= safeRead) <$> peek lua idx
200− tag <- getTable lua idx "t"
201− case tag of
202− Just "DefaultDelim" -> return $ Just DefaultDelim
203− Just "Period" -> return $ Just Period
204− Just "OneParen" -> return $ Just OneParen
205− Just "TwoParens" -> return $ Just TwoParens
206− _ -> return Nothing
207− valuetype _ = TTABLE
177+ valuetype _ = TSTRING
208
178
209instance StackValue ListNumberStyle where
179instance StackValue ListNumberStyle where
210− push lua = \case
180+ push lua = push lua . show
211− DefaultStyle -> getglobal2 lua "pandoc.DefaultStyle"
212− LowerRoman -> getglobal2 lua "pandoc.LowerRoman"
213− UpperRoman -> getglobal2 lua "pandoc.UpperRoman"
214− LowerAlpha -> getglobal2 lua "pandoc.LowerAlpha"
215− UpperAlpha -> getglobal2 lua "pandoc.UpperAlpha"
216− Decimal -> getglobal2 lua "pandoc.Decimal"
217− Example -> getglobal2 lua "pandoc.Example"
218− peek lua idx = do
181+ peek lua idx = (>>= safeRead) <$> peek lua idx
219− tag <- getTable lua idx "t"
220− case tag of
221− Just "DefaultStyle" -> return $ Just DefaultStyle
222− Just "LowerRoman" -> return $ Just LowerRoman
223− Just "UpperRoman" -> return $ Just UpperRoman
224− Just "LowerAlpha" -> return $ Just LowerAlpha
225− Just "UpperAlpha" -> return $ Just UpperAlpha
226− Just "Decimal" -> return $ Just Decimal
227− Just "Example" -> return $ Just Example
228− _ -> return Nothing
229− valuetype _ = TTABLE
182+ valuetype _ = TSTRING
230
183
231instance StackValue MathType where
184instance StackValue MathType where
232− push lua = \case
185+ push lua = push lua . show
233− InlineMath -> getglobal2 lua "pandoc.InlineMath"
234− DisplayMath -> getglobal2 lua "pandoc.DisplayMath"
235− peek lua idx = do
186+ peek lua idx = (>>= safeRead) <$> peek lua idx
236− res <- getTable lua idx "t"
237− case res of
238− Just "InlineMath" -> return $ Just InlineMath
239− Just "DisplayMath" -> return $ Just DisplayMath
240− _ -> return Nothing
241− valuetype _ = TTABLE
187+ valuetype _ = TSTRING
242
188
243instance StackValue QuoteType where
189instance StackValue QuoteType where
244− push lua = \case
190+ push lua = push lua . show
245− SingleQuote -> getglobal2 lua "pandoc.SingleQuote"
246− DoubleQuote -> getglobal2 lua "pandoc.DoubleQuote"
247− peek lua idx = do
191+ peek lua idx = (>>= safeRead) <$> peek lua idx
248− res <- getTable lua idx "t"
249− case res of
250− Just "SingleQuote" -> return $ Just SingleQuote
251− Just "DoubleQuote" -> return $ Just DoubleQuote
252− _ -> return Nothing
253− valuetype _ = TTABLE
192+ valuetype _ = TSTRING
254
193
255-- | Return the value at the given index as inline if possible.
194-- | Return the value at the given index as inline if possible.
256peekInline :: LuaState -> Int -> IO (Maybe Inline)
195peekInline :: LuaState -> Int -> IO (Maybe Inline)