From e4b00259ec4c1338f766561aba3b7a3a3159d216 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 Jul 2017 19:36:28 +0200 Subject: Move `Plugin` and `PluginAction` to a new module Move our base plugin types to a new module to enable us to use them in both the plugin matching code (which we'll leave in "Plugin.hs") and in specialised plugin modules. This enables us to import and provide a list of plugins in `plugins` in "Plugin.hs" and use these types in that file and in the plugin files without any circular/recursive module dependencies. --- src/Plugin.hs | 13 ++----------- src/Plugin/Base.hs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 src/Plugin/Base.hs (limited to 'src') diff --git a/src/Plugin.hs b/src/Plugin.hs index 6522e0b..41b0296 100644 --- a/src/Plugin.hs +++ b/src/Plugin.hs @@ -1,21 +1,12 @@ module Plugin - ( Plugin - , matchPlugin + ( matchPlugin , performPlugin , plugins ) where import Text.Regex.TDFA -type PluginAction = String -> String - -data Plugin = Plugin - { matchRegex :: String - , perform :: PluginAction - } - -instance Show Plugin where - show (Plugin r p) = "matchRegex = " ++ r +import Plugin.Base matchPlugin :: String -> Maybe Plugin matchPlugin message = firstPlugin $ matchPlugins message plugins diff --git a/src/Plugin/Base.hs b/src/Plugin/Base.hs new file mode 100644 index 0000000..c73ef6a --- /dev/null +++ b/src/Plugin/Base.hs @@ -0,0 +1,17 @@ +module Plugin.Base + ( PluginAction + + , Plugin(..) + , matchRegex + , perform + ) where + +type PluginAction = String -> String + +data Plugin = Plugin + { matchRegex :: String + , perform :: PluginAction + } + +instance Show Plugin where + show (Plugin r p) = "matchRegex = " ++ r -- cgit v1.2.3