aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-06-29 14:00:26 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-06-29 14:00:26 +0200
commit6ad74815f66cb36ec4039c597b38473db853eb6c (patch)
tree85301653113fc2d6b546091a702b8140d1a08a17 /src/Text
parentc505de59c022e2c02b6b220da0849a4e67394d6a (diff)
downloadpandoc-6ad74815f66cb36ec4039c597b38473db853eb6c.tar.gz
Text.Pandoc.Lua: use generics to reduce boilerplate.
I tested this with the str.lua filter on MANUAL.txt, and I could see no significant performance degradation. Doing things this way will ease maintenance, as we won't have to manually modify this module when types change. @tarleb, do we really need special cases for things like DoubleQuoted and InlineMath?
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Lua.hs35
1 files changed, 3 insertions, 32 deletions
diff --git a/src/Text/Pandoc/Lua.hs b/src/Text/Pandoc/Lua.hs
index 2ee8d0847..85a080277 100644
--- a/src/Text/Pandoc/Lua.hs
+++ b/src/Text/Pandoc/Lua.hs
@@ -36,6 +36,7 @@ module Text.Pandoc.Lua ( LuaException(..),
import Control.Exception
import Control.Monad (unless, when, (>=>))
import Control.Monad.Trans (MonadIO (..))
+import Data.Data (toConstr)
import Data.Map (Map)
import Data.Typeable (Typeable)
import Scripting.Lua (LuaState, StackValue (..))
@@ -129,21 +130,7 @@ execBlockLuaFilter lua fnMap x = do
case Map.lookup filterFnName fnMap of
Nothing -> return x
Just fn -> runFilterFunction lua fn x
- case x of
- BlockQuote{} -> tryFilter "BlockQuote"
- BulletList{} -> tryFilter "BulletList"
- CodeBlock{} -> tryFilter "CodeBlock"
- DefinitionList{} -> tryFilter "DefinitionList"
- Div{} -> tryFilter "Div"
- Header{} -> tryFilter "Header"
- HorizontalRule -> tryFilter "HorizontalRule"
- LineBlock{} -> tryFilter "LineBlock"
- Null -> tryFilter "Null"
- Para{} -> tryFilter "Para"
- Plain{} -> tryFilter "Plain"
- RawBlock{} -> tryFilter "RawBlock"
- OrderedList{} -> tryFilter "OrderedList"
- Table{} -> tryFilter "Table"
+ tryFilter (show (toConstr x))
execInlineLuaFilter :: LuaState
-> FunctionMap
@@ -161,27 +148,11 @@ execInlineLuaFilter lua fnMap x = do
Nothing -> tryFilterAlternatives alternatives
Just fn -> runFilterFunction lua fn x
case x of
- Cite{} -> tryFilter "Cite"
- Code{} -> tryFilter "Code"
- Emph{} -> tryFilter "Emph"
- Image{} -> tryFilter "Image"
- LineBreak -> tryFilter "LineBreak"
- Link{} -> tryFilter "Link"
Math DisplayMath _ -> tryFilterAlternatives ["DisplayMath", "Math"]
Math InlineMath _ -> tryFilterAlternatives ["InlineMath", "Math"]
- Note{} -> tryFilter "Note"
Quoted DoubleQuote _ -> tryFilterAlternatives ["DoubleQuoted", "Quoted"]
Quoted SingleQuote _ -> tryFilterAlternatives ["SingleQuoted", "Quoted"]
- RawInline{} -> tryFilter "RawInline"
- SmallCaps{} -> tryFilter "SmallCaps"
- SoftBreak -> tryFilter "SoftBreak"
- Space -> tryFilter "Space"
- Span{} -> tryFilter "Span"
- Str{} -> tryFilter "Str"
- Strikeout{} -> tryFilter "Strikeout"
- Strong{} -> tryFilter "Strong"
- Subscript{} -> tryFilter "Subscript"
- Superscript{} -> tryFilter "Superscript"
+ _ -> tryFilter (show (toConstr x))
instance StackValue LuaFilter where
valuetype _ = Lua.TTABLE