on master help sign in
Fix issue with CPP and /*
commit5412b90d06ed435b933a65f8f796157a54a997f4 authorJasper Van der Jeugt <m@jaspervdj.be> dateTue 13 Mar 2018, 10:40 (9 years ago) parent000627c
4 files changed+105−93
hakyll.cabal+1 lib/Hakyll/Core/Identifier/Pattern.hs+10−83 lib/Hakyll/Core/Identifier/Pattern/Internal.hs+92 stack.yaml+2−10
hakyll.cabal+1
@@ -114,6 +114,7 @@ Library
114114 Hakyll.Core.File
115115 Hakyll.Core.Identifier
116116 Hakyll.Core.Identifier.Pattern
117+ Hakyll.Core.Identifier.Pattern.Internal
117118 Hakyll.Core.Item
118119 Hakyll.Core.Logger
119120 Hakyll.Core.Metadata
lib/Hakyll/Core/Identifier/Pattern.hs+10−83
@@ -28,7 +28,7 @@
2828--
2929-- The 'capture' function allows the user to get access to the elements captured
3030-- by the capture elements in a glob or regex pattern.
31−{-# LANGUAGE CPP #-}
31+{-# OPTIONS_GHC -fno-warn-orphans #-}
3232module Hakyll.Core.Identifier.Pattern
3333 ( -- * The pattern type
3434 Pattern
@@ -58,80 +58,22 @@ module Hakyll.Core.Identifier.Pattern
5858
5959
6060--------------------------------------------------------------------------------
61−import Control.Arrow ((&&&), (>>>))
62−import Control.Monad (msum)
63−import Data.Binary (Binary (..), getWord8, putWord8)
64−import Data.List (inits, isPrefixOf, tails)
65−import Data.Maybe (isJust)
66−#if MIN_VERSION_base(4,9,0)
67−import Data.Semigroup (Semigroup (..))
68−#endif
69−import Data.Set (Set)
70−import qualified Data.Set as S
61+import Control.Arrow ((&&&), (>>>))
62+import Control.Monad (msum)
63+import Data.List (inits, isPrefixOf,
64+ tails)
65+import Data.Maybe (isJust)
66+import qualified Data.Set as S
7167
7268
7369--------------------------------------------------------------------------------
74−import GHC.Exts (IsString, fromString)
75−import Text.Regex.TDFA ((=~))
70+import GHC.Exts (IsString, fromString)
71+import Text.Regex.TDFA ((=~))
7672
7773
7874--------------------------------------------------------------------------------
7975import Hakyll.Core.Identifier
80−
81−
82−--------------------------------------------------------------------------------
83−-- | Elements of a glob pattern
84−data GlobComponent
85− = Capture
86− | CaptureMany
87− | Literal String
88− deriving (Eq, Show)
89−
90−
91−--------------------------------------------------------------------------------
92−instance Binary GlobComponent where
93− put Capture = putWord8 0
94− put CaptureMany = putWord8 1
95− put (Literal s) = putWord8 2 >> put s
96−
97− get = getWord8 >>= \t -> case t of
98− 0 -> pure Capture
99− 1 -> pure CaptureMany
100− 2 -> Literal <$> get
101− _ -> error "Data.Binary.get: Invalid GlobComponent"
102−
103−
104−--------------------------------------------------------------------------------
105−-- | Type that allows matching on identifiers
106−data Pattern
107− = Everything
108− | Complement Pattern
109− | And Pattern Pattern
110− | Glob [GlobComponent]
111− | List (Set Identifier)
112− | Regex String
113− | Version (Maybe String)
114− deriving (Show)
115−
116−
117−--------------------------------------------------------------------------------
118−instance Binary Pattern where
119− put Everything = putWord8 0
120− put (Complement p) = putWord8 1 >> put p
121− put (And x y) = putWord8 2 >> put x >> put y
122− put (Glob g) = putWord8 3 >> put g
123− put (List is) = putWord8 4 >> put is
124− put (Regex r) = putWord8 5 >> put r
125− put (Version v) = putWord8 6 >> put v
126−
127− get = getWord8 >>= \t -> case t of
128− 0 -> pure Everything
129− 1 -> Complement <$> get
130− 2 -> And <$> get <*> get
131− 3 -> Glob <$> get
132− 4 -> List <$> get
133− 5 -> Regex <$> get
134− _ -> Version <$> get
76+import Hakyll.Core.Identifier.Pattern.Internal
13577
13678
13779--------------------------------------------------------------------------------
@@ -139,21 +81,6 @@ instance IsString Pattern where
13981 fromString = fromGlob
14082
14183
142−--------------------------------------------------------------------------------
143−#if MIN_VERSION_base(4,9,0)
144−instance Semigroup Pattern where
145− (<>) = (.&&.)
146−
147−instance Monoid Pattern where
148− mempty = Everything
149− mappend = (<>)
150−#else
151−instance Monoid Pattern where
152− mempty = Everything
153− mappend = (.&&.)
154−#endif
155−
156−
15784--------------------------------------------------------------------------------
15885-- | Parse a pattern from a string
15986fromGlob :: String -> Pattern
lib/Hakyll/Core/Identifier/Pattern/Internal.hsnew file+92
@@ -0,0 +1,92 @@
1+-- | This internal module is mostly here to prevent CPP conflicting with Haskell
2+-- comments.
3+{-# LANGUAGE CPP #-}
4+module Hakyll.Core.Identifier.Pattern.Internal
5+ ( GlobComponent (..)
6+ , Pattern (..)
7+ ) where
8+
9+
10+--------------------------------------------------------------------------------
11+import Data.Binary (Binary (..), getWord8, putWord8)
12+import Data.Set (Set)
13+
14+
15+--------------------------------------------------------------------------------
16+#if MIN_VERSION_base(4,9,0)
17+import Data.Semigroup (Semigroup (..))
18+#endif
19+
20+
21+--------------------------------------------------------------------------------
22+import Hakyll.Core.Identifier
23+
24+
25+--------------------------------------------------------------------------------
26+-- | Elements of a glob pattern
27+data GlobComponent
28+ = Capture
29+ | CaptureMany
30+ | Literal String
31+ deriving (Eq, Show)
32+
33+
34+--------------------------------------------------------------------------------
35+instance Binary GlobComponent where
36+ put Capture = putWord8 0
37+ put CaptureMany = putWord8 1
38+ put (Literal s) = putWord8 2 >> put s
39+
40+ get = getWord8 >>= \t -> case t of
41+ 0 -> pure Capture
42+ 1 -> pure CaptureMany
43+ 2 -> Literal <$> get
44+ _ -> error "Data.Binary.get: Invalid GlobComponent"
45+
46+
47+--------------------------------------------------------------------------------
48+-- | Type that allows matching on identifiers
49+data Pattern
50+ = Everything
51+ | Complement Pattern
52+ | And Pattern Pattern
53+ | Glob [GlobComponent]
54+ | List (Set Identifier)
55+ | Regex String
56+ | Version (Maybe String)
57+ deriving (Show)
58+
59+
60+--------------------------------------------------------------------------------
61+instance Binary Pattern where
62+ put Everything = putWord8 0
63+ put (Complement p) = putWord8 1 >> put p
64+ put (And x y) = putWord8 2 >> put x >> put y
65+ put (Glob g) = putWord8 3 >> put g
66+ put (List is) = putWord8 4 >> put is
67+ put (Regex r) = putWord8 5 >> put r
68+ put (Version v) = putWord8 6 >> put v
69+
70+ get = getWord8 >>= \t -> case t of
71+ 0 -> pure Everything
72+ 1 -> Complement <$> get
73+ 2 -> And <$> get <*> get
74+ 3 -> Glob <$> get
75+ 4 -> List <$> get
76+ 5 -> Regex <$> get
77+ _ -> Version <$> get
78+
79+
80+--------------------------------------------------------------------------------
81+#if MIN_VERSION_base(4,9,0)
82+instance Semigroup Pattern where
83+ (<>) = And
84+
85+instance Monoid Pattern where
86+ mempty = Everything
87+ mappend = (<>)
88+#else
89+instance Monoid Pattern where
90+ mempty = Everything
91+ mappend = And
92+#endif
stack.yaml+2−10
@@ -1,4 +1,4 @@
1−resolver: nightly-2018-01-15
1+resolver: lts-10.6
22extra-package-dbs: []
33
44flags:
@@ -11,16 +11,8 @@ flags:
1111packages:
1212 - '.'
1313
14−allow-newer: True
15−
1614extra-deps:
17− - 'binary-0.9.0.0'
18− - 'http-types-0.11'
19− - 'pandoc-2.1'
20− - 'pandoc-citeproc-0.13'
21− - 'QuickCheck-2.11.3'
22− - 'tasty-1.0.0.1'
23− - 'tasty-hunit-0.10.0.1'
15+ - 'pandoc-citeproc-0.13.0.1'
2416
2517nix:
2618 enable: false