Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ormolu #31

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
linux5:
strategy:
matrix:
resolver: [lts-10, lts-11, lts-12, lts-13, lts-14, lts-15, lts-16, lts-17, lts-18, lts-19, lts-20, lts-21]
resolver: [lts-10, lts-11, lts-12, lts-13, lts-14, lts-15, lts-16, lts-18, lts-19, lts-20, lts-21]

name: Run the tests
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion css-selectors.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test-suite css-selectors-test
main-is: Spec.hs
build-depends:
base
, binary >=0.2 && <0.8.8.0
, binary >=0.2
, css-selectors
, hashable >=1.2.7.0
, text
Expand Down
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
11 changes: 7 additions & 4 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 Expand Up @@ -1532,7 +1535,7 @@ instance Arbitrary Class where
shrink (Class a) = Class <$> _shrinkIdent a

instance Arbitrary Nth where
arbitrary = Nth <$> ((1+) . abs <$> arbitrary) <*> arbitrary
arbitrary = Nth . (1+) . abs <$> arbitrary <*> arbitrary
shrink nth
| nth == nnth = []
| otherwise = [nnth]
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
Loading