summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaelSnoyman <>2011-08-09 07:19:26 (GMT)
committerLuite Stegeman <luite@luite.com>2011-08-09 07:19:26 (GMT)
commitb86bf11e1784add6ae4bbc9592c2b4ecd101434c (patch)
treeba41ea883f2f27023d0f96a5f8884bc45d6ee925
parentc4914039b15438035178de7d818bf4e2b17b2e1c (diff)
version 0.1.00.1.0
-rw-r--r--Text/CSS/Parse.hs41
-rw-r--r--Text/CSS/Render.hs1
-rw-r--r--css-text.cabal5
3 files changed, 32 insertions, 15 deletions
diff --git a/Text/CSS/Parse.hs b/Text/CSS/Parse.hs
index 63ca668..c7da1a9 100644
--- a/Text/CSS/Parse.hs
+++ b/Text/CSS/Parse.hs
@@ -1,6 +1,10 @@
{-# LANGUAGE OverloadedStrings #-}
module Text.CSS.Parse
- ( parseAttr
+ ( attrParser
+ , attrsParser
+ , blockParser
+ , blocksParser
+ , parseAttr
, parseAttrs
, parseBlock
, parseBlocks
@@ -9,12 +13,23 @@ module Text.CSS.Parse
import Prelude hiding (takeWhile)
import Data.Attoparsec.Text
import Data.Text (Text, strip)
-import Data.Char (isSpace)
import Control.Applicative ((<|>))
+parseAttrs :: Text -> Either String [(Text, Text)]
+parseAttrs = parseOnly attrsParser
+
+parseAttr :: Text -> Either String (Text, Text)
+parseAttr = parseOnly attrParser
+
+parseBlocks :: Text -> Either String [(Text, [(Text, Text)])]
+parseBlocks = parseOnly blocksParser
+
+parseBlock :: Text -> Either String (Text, [(Text, Text)])
+parseBlock = parseOnly blockParser
+
skipWS :: Parser ()
skipWS = (string "/*" >> endComment >> skipWS)
- <|> (satisfy isSpace >> skipSpace >> skipWS)
+ <|> (space >> skipSpace >> skipWS)
<|> return ()
where
endComment = do
@@ -24,34 +39,34 @@ skipWS = (string "/*" >> endComment >> skipWS)
(char '/' >> return ()) <|> endComment
) <|> fail "Missing end comment"
-parseAttr :: Parser (Text, Text)
-parseAttr = do
+attrParser :: Parser (Text, Text)
+attrParser = do
skipWS
key <- takeWhile1 (not . flip elem ":{}")
_ <- char ':' <|> fail "Missing colon in attribute"
value <- (takeWhile (not . flip elem ";}"))
return (strip key, strip value)
-parseAttrs :: Parser [(Text, Text)]
-parseAttrs =
+attrsParser :: Parser [(Text, Text)]
+attrsParser =
go id
where
go front = (do
- a <- parseAttr
+ a <- attrParser
(char ';' >> return ()) <|> return ()
skipWS
go $ front . (:) a
) <|> return (front [])
-parseBlock :: Parser (Text, [(Text, Text)])
-parseBlock = do
+blockParser :: Parser (Text, [(Text, Text)])
+blockParser = do
skipWS
sel <- takeWhile (/= '{')
_ <- char '{'
- attrs <- parseAttrs
+ attrs <- attrsParser
skipWS
_ <- char '}'
return (strip sel, attrs)
-parseBlocks :: Parser [(Text, [(Text, Text)])]
-parseBlocks = many parseBlock
+blocksParser :: Parser [(Text, [(Text, Text)])]
+blocksParser = many blockParser
diff --git a/Text/CSS/Render.hs b/Text/CSS/Render.hs
index 0dc661b..633df9f 100644
--- a/Text/CSS/Render.hs
+++ b/Text/CSS/Render.hs
@@ -10,6 +10,7 @@ import Data.Text (Text)
import Data.Text.Lazy.Builder (Builder, fromText, singleton)
import Data.Monoid (mappend, mempty, mconcat)
+(<>) :: Builder -> Builder -> Builder
(<>) = mappend
renderAttr :: (Text, Text) -> Builder
diff --git a/css-text.cabal b/css-text.cabal
index 4e7ce6c..5bdd94e 100644
--- a/css-text.cabal
+++ b/css-text.cabal
@@ -1,5 +1,5 @@
name: css-text
-version: 0.0.0
+version: 0.1.0
license: BSD3
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>
@@ -27,7 +27,8 @@ test-suite runtests
, attoparsec-text >= 0.8.5.1 && < 0.9
, HUnit >= 1.2 && < 1.3
, hspec >= 0.6.1 && < 0.7
+ , QuickCheck
source-repository head
type: git
- location: git://github.com/snoyberg/css-text.git
+ location: git://github.com/yesodweb/css-text.git