Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
KommuSoft committed Mar 26, 2024
1 parent 028ce59 commit b809729
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 165 deletions.
25 changes: 13 additions & 12 deletions src/Css/Selector.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{-|
Module : Css.Selector
Description : Css 3 selectors in Haskell.
Maintainer : hapytexeu+gh@gmail.com
Stability : experimental
Portability : POSIX
A module for backwards compatibility that re-exports 'Css3.Selector'. This module is deprecated and eventually will be removed.
-}
module Css.Selector {-# DEPRECATED "Use Css3.Selector instead" #-} (
module Css3.Selector,
) where
-- |
-- Module : Css.Selector
-- Description : Css 3 selectors in Haskell.
-- Maintainer : hapytexeu+gh@gmail.com
-- Stability : experimental
-- Portability : POSIX
--
-- A module for backwards compatibility that re-exports 'Css3.Selector'. This module is deprecated and eventually will be removed.
module Css.Selector
{-# DEPRECATED "Use Css3.Selector instead" #-}
( module Css3.Selector,
)
where

import Css3.Selector
25 changes: 13 additions & 12 deletions src/Css/Selector/Core.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{-|
Module : Css.Selector.Core
Description : A module where we define the tree of types to represent and maniplate a css selector.
Maintainer : hapytexeu+gh@gmail.com
Stability : experimental
Portability : POSIX
A module for backwards compatibility that re-exports 'Css3.Selector.Core'. This module is deprecated and eventually will be removed.
-}
module Css.Selector.Core {-# DEPRECATED "Use Css3.Selector.Core instead" #-} (
module Css3.Selector.Core
) where
-- |
-- Module : Css.Selector.Core
-- Description : A module where we define the tree of types to represent and maniplate a css selector.
-- Maintainer : hapytexeu+gh@gmail.com
-- Stability : experimental
-- Portability : POSIX
--
-- A module for backwards compatibility that re-exports 'Css3.Selector.Core'. This module is deprecated and eventually will be removed.
module Css.Selector.Core
{-# DEPRECATED "Use Css3.Selector.Core instead" #-}
( module Css3.Selector.Core,
)
where

import Css3.Selector.Core
25 changes: 13 additions & 12 deletions src/Css/Selector/QuasiQuoters.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{-|
Module : Css.Selector.QuasiQuoters
Description : A module that defines a quasiquoter to parse a string to a css selector.
Maintainer : hapytexeu+gh@gmail.com
Stability : experimental
Portability : POSIX
A module for backwards compatibility that re-exports 'Css3.Selector.QuasiQuoters'. This module is deprecated and eventually will be removed.
-}
module Css.Selector.QuasiQuoters {-# DEPRECATED "Use Css3.Selector.QuasiQuoters instead" #-} (
module Css3.Selector.QuasiQuoters
) where
-- |
-- Module : Css.Selector.QuasiQuoters
-- Description : A module that defines a quasiquoter to parse a string to a css selector.
-- Maintainer : hapytexeu+gh@gmail.com
-- Stability : experimental
-- Portability : POSIX
--
-- A module for backwards compatibility that re-exports 'Css3.Selector.QuasiQuoters'. This module is deprecated and eventually will be removed.
module Css.Selector.QuasiQuoters
{-# DEPRECATED "Use Css3.Selector.QuasiQuoters instead" #-}
( module Css3.Selector.QuasiQuoters,
)
where

import Css3.Selector.QuasiQuoters
25 changes: 13 additions & 12 deletions src/Css/Selector/Utils.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{-|
Module : Css.Selector.Utils
Description : A set of utility methods to encode and decode strings.
Maintainer : hapytexeu+gh@gmail.com
Stability : experimental
Portability : POSIX
A module for backwards compatibility that re-exports 'Css3.Selector.Utils'. This module is deprecated and eventually will be removed.
-}
module Css.Selector.Utils {-# DEPRECATED "Use Css3.Selector.Utils instead" #-} (
module Css3.Selector.Utils
) where
-- |
-- Module : Css.Selector.Utils
-- Description : A set of utility methods to encode and decode strings.
-- Maintainer : hapytexeu+gh@gmail.com
-- Stability : experimental
-- Portability : POSIX
--
-- A module for backwards compatibility that re-exports 'Css3.Selector.Utils'. This module is deprecated and eventually will be removed.
module Css.Selector.Utils
{-# DEPRECATED "Use Css3.Selector.Utils instead" #-}
( module Css3.Selector.Utils,
)
where

import Css3.Selector.Utils
26 changes: 13 additions & 13 deletions src/Css3/Selector.hs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{-|
Module : Css3.Selector
Description : Css 3 selectors in Haskell.
Maintainer : hapytexeu+gh@gmail.com
Stability : experimental
Portability : POSIX
A module to define css selectors by making use of a quasiquoter, and manipulating these css selectors.
-}
module Css3.Selector (
module Css3.Selector.Core,
-- |
-- Module : Css3.Selector
-- Description : Css 3 selectors in Haskell.
-- Maintainer : hapytexeu+gh@gmail.com
-- Stability : experimental
-- Portability : POSIX
--
-- A module to define css selectors by making use of a quasiquoter, and manipulating these css selectors.
module Css3.Selector
( module Css3.Selector.Core,
module Css3.Selector.QuasiQuoters,
module Css3.Selector.Utils
) where
module Css3.Selector.Utils,
)
where

import Css3.Selector.Core
import Css3.Selector.QuasiQuoters
Expand Down
9 changes: 6 additions & 3 deletions src/Css3/Selector/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -813,17 +813,19 @@ instance IsList SelectorGroup where
_textToPattern :: Text -> Pat
_textToPattern t = ViewP (AppE (ConE '(==)) (AppE (ConE 'pack) (LitE (StringL (unpack t))))) (_constantP 'True)

_constantP :: Name -> Pat
#if MIN_VERSION_template_haskell(2,18,0)
_constantP :: Name -> Pat
_constantP = flip (`ConP` []) []
#else
_constantP :: Name -> Pat
_constantP = (`ConP` [])
#endif

_conP :: Name -> [Pat] -> Pat
#if MIN_VERSION_template_haskell(2,18,0)
_conP :: Name -> [Pat] -> Pat
_conP = (`ConP` [])
#else
_conP :: Name -> [Pat] -> Pat
_conP = ConP
#endif

Expand Down Expand Up @@ -1327,10 +1329,11 @@ instance Binary SelectorGroup where
-- Lift instances
#if MIN_VERSION_template_haskell(2,17,0)
_apply :: Quote m => Name -> [m Exp] -> m Exp
_apply = foldl appE . conE
#else
_apply :: Name -> [Q Exp] -> Q Exp
#endif
_apply = foldl appE . conE
#endif

instance Lift SelectorGroup where
lift (SelectorGroup sg) = _apply 'SelectorGroup [liftNe sg]
Expand Down
71 changes: 38 additions & 33 deletions src/Css3/Selector/QuasiQuoters.hs
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
{-# LANGUAGE TemplateHaskellQuotes #-}

{-|
Module : Css3.Selector.QuasiQuoters
Description : A module that defines a quasiquoter to parse a string to a css selector.
Maintainer : hapytexeu+gh@gmail.com
Stability : experimental
Portability : POSIX
A module that defines a quasiquoter to parse a string to a css selector.
-}
module Css3.Selector.QuasiQuoters (
csssel, cssselFile, parseCss
) where

import Css3.Selector.Core(SelectorGroup, toPattern)
import Css3.Selector.Lexer(alexScanTokens)
import Css3.Selector.Parser(cssselector)

import Data.Data(Data, cast)
import Data.Text(pack, unpack)

import Language.Haskell.TH.Quote(QuasiQuoter(QuasiQuoter, quoteExp, quotePat, quoteType, quoteDec), quoteFile)
import Language.Haskell.TH.Syntax(Exp(AppE, VarE), Q, Type(ConT), dataToExpQ, lift, reportWarning)
-- |
-- Module : Css3.Selector.QuasiQuoters
-- Description : A module that defines a quasiquoter to parse a string to a css selector.
-- Maintainer : hapytexeu+gh@gmail.com
-- Stability : experimental
-- Portability : POSIX
--
-- A module that defines a quasiquoter to parse a string to a css selector.
module Css3.Selector.QuasiQuoters
( csssel,
cssselFile,
parseCss,
)
where

import Css3.Selector.Core (SelectorGroup, toPattern)
import Css3.Selector.Lexer (alexScanTokens)
import Css3.Selector.Parser (cssselector)
import Data.Data (Data, cast)
import Data.Text (pack, unpack)
import Language.Haskell.TH.Quote (QuasiQuoter (QuasiQuoter, quoteDec, quoteExp, quotePat, quoteType), quoteFile)
import Language.Haskell.TH.Syntax (Exp (AppE, VarE), Q, Type (ConT), dataToExpQ, lift, reportWarning)

-- | Parse the string to a 'SelectorGroup'.
parseCss :: String -- ^ The string to be parsed to a 'SelectorGroup'
-> SelectorGroup -- ^ The selectorgroup that is the equivalent of the given 'String'.
parseCss ::
-- | The string to be parsed to a 'SelectorGroup'
String ->
-- | The selectorgroup that is the equivalent of the given 'String'.
SelectorGroup
parseCss st = al (alexScanTokens st')
where st' = filter ('\r' /=) st
al (Left er) = error er
al (Right val) = cssselector val
where
st' = filter ('\r' /=) st
al (Left er) = error er
al (Right val) = cssselector val

liftDataWithText :: Data a => a -> Q Exp
liftDataWithText = dataToExpQ ((((AppE (VarE 'pack) <$>) . lift . unpack) <$>) . cast)
Expand All @@ -38,12 +42,13 @@ liftDataWithText = dataToExpQ ((((AppE (VarE 'pack) <$>) . lift . unpack) <$>) .
-- css selector. In case the css selector is invalid. A compiler error will be
-- thrown (at compile time).
csssel :: QuasiQuoter
csssel = QuasiQuoter {
quoteExp = liftDataWithText . parseCss,
quotePat = pure . toPattern . parseCss,
quoteType = const (reportWarning "The type of the quasiquoter will always use the SelectorGroup type." >> pure (ConT ''SelectorGroup)),
quoteDec = const (reportWarning "The use of this quasiquoter will not make any declarations." >> pure [])
}
csssel =
QuasiQuoter
{ quoteExp = liftDataWithText . parseCss,
quotePat = pure . toPattern . parseCss,
quoteType = const (reportWarning "The type of the quasiquoter will always use the SelectorGroup type." >> pure (ConT ''SelectorGroup)),
quoteDec = const (reportWarning "The use of this quasiquoter will not make any declarations." >> pure [])
}

-- | A quasiquoter that takes the content from the file, and then runs the
-- content of that file as a 'csssel' quasiquote.
Expand Down
Loading

0 comments on commit b809729

Please sign in to comment.