M src/Data/CSS/Syntax/Selector.hs => src/Data/CSS/Syntax/Selector.hs +3 -3
@@ 41,9 41,9 @@ parseSelector (Delim '.':Ident class_:tokens) = parseSelector' (Class class_) to
parseSelector (LeftSquareBracket:Ident prop:tokens) =
concatP appendPropertySel parsePropertySel parseSelector tokens
where appendPropertySel test selector = Property prop test : selector
-parseSelector (Delim ':':Delim ':':Ident p:ts) = parseSelector' (Psuedoelement p) ts
-parseSelector (Delim ':':Ident p:ts) = parseSelector' (Psuedoclass p []) ts
-parseSelector (Delim ':':Function fn:tokens) =
+parseSelector (Colon:Colon:Ident p:ts) = parseSelector' (Psuedoelement p) ts
+parseSelector (Colon:Ident p:ts) = parseSelector' (Psuedoclass p []) ts
+parseSelector (Colon:Function fn:tokens) =
concatP appendPseudo scanBlock parseSelector tokens
where appendPseudo args selector = Psuedoclass fn args : selector
parseSelector tokens = ([], tokens)
M test/Test.hs => test/Test.hs +9 -2
@@ 75,6 75,14 @@ spec = do
parse emptyStyle "a + b {}" `shouldBe` TrivialStyleSheet [
StyleRule (Adjacent (Element [Tag "a"]) [Tag "b"]) []
]
+ parse emptyStyle "a::before {}"
+ `shouldBe` TrivialStyleSheet [
+ StyleRule (Element [Tag "a", Psuedoelement "before"]) []
+ ]
+ parse emptyStyle "a:before {}"
+ `shouldBe` TrivialStyleSheet [
+ StyleRule (Element [Tag "a", Psuedoclass "before" []]) []
+ ]
describe "Style Index" $ do
it "Retrieves appropriate styles" $ do
let index = addStyleRule styleIndex 0 $ styleRule' sampleRule
@@ 272,8 280,7 @@ spec = do
style ! "color" `shouldBe` [Ident "green"]
describe "Parser freezes" $ do
it "does not regress" $ do
- -- TODO handle psuedoelements
- parse emptyStyle "output::before {content: 'Output'; pitch: high}"
+ parse emptyStyle "output: {content: 'Output'; pitch: high}"
`shouldBe` TrivialStyleSheet [
StyleRule (Element [Tag "output"]) []
] -- Turned out to just be incorrect parsing