about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlukasepple <git@lukasepple.de>2016-03-19 18:57:51 +0100
committerlukasepple <git@lukasepple.de>2016-03-19 18:57:51 +0100
commitcae0c890d2a80c6d9730f50cba16a2b456ee5b48 (patch)
treea5525e39657760794badbe397b2095219365dd31
parent6e609884d03a4907ab10a0770f3d081141517fa8 (diff)
Introduce Text.Emoji.Emojis
This module contains emojiData which is a list
of all Emojis. At compile time the file emoji-data.txt
is embedded into the file but parsed at runtime. I still
need to figure out a way to parse at compile time that
does not result into virtually infinite pain.
-rw-r--r--emoji.cabal2
-rw-r--r--shell.nix6
-rw-r--r--src/Text/Emoji/Emojis.hs16
3 files changed, 21 insertions, 3 deletions
diff --git a/emoji.cabal b/emoji.cabal
index 011af52..f1045a8 100644
--- a/emoji.cabal
+++ b/emoji.cabal
@@ -20,6 +20,7 @@ library
                      , Text.Emoji.Data
                      , Text.Emoji.String
                      , Text.Emoji.Text
+                     , Text.Emoji.Emojis
   -- other-modules:       
   -- other-extensions:    
   build-depends:       base
@@ -28,5 +29,6 @@ library
                      , parsec
                      , split
                      , utf8-light
+                     , file-embed
   hs-source-dirs:      src
   default-language:    Haskell2010
diff --git a/shell.nix b/shell.nix
index 160b524..80d3198 100644
--- a/shell.nix
+++ b/shell.nix
@@ -4,15 +4,15 @@ let
 
   inherit (nixpkgs) pkgs;
 
-  f = { mkDerivation, base, bytestring, parsec, split, stdenv, text
-      , utf8-light
+  f = { mkDerivation, base, bytestring, file-embed, parsec, split
+      , stdenv, text, utf8-light
       }:
       mkDerivation {
         pname = "emoji";
         version = "0.1.0.0";
         src = ./.;
         libraryHaskellDepends = [
-          base bytestring parsec split text utf8-light
+          base bytestring file-embed parsec split text utf8-light
         ];
         description = "Emoji name expander for different string types";
         license = stdenv.lib.licenses.gpl3;
diff --git a/src/Text/Emoji/Emojis.hs b/src/Text/Emoji/Emojis.hs
new file mode 100644
index 0000000..de37ac5
--- /dev/null
+++ b/src/Text/Emoji/Emojis.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE TemplateHaskell #-}
+module Text.Emoji.Emojis
+  ( emojiData
+  ) where
+
+import Text.Emoji.Types
+import Text.Emoji.Data
+import Data.Either
+import Data.FileEmbed
+import Text.Parsec
+
+emojiData :: [Emoji]
+emojiData = toRights . (\(Right x) -> x) $ parse emojiDataFile "" $(embedStringFile "./emoji-data.txt")
+
+toRights :: [Either a b] -> [b]
+toRights = map (\(Right x) -> x) . filter isRight