@@ -7,6 +7,7 @@ import CssParser.At.Container
77import CssParser.At.FontFace
88import CssParser.At.FontFeatureValues
99import CssParser.At.FontPaletteValues
10+ import CssParser.At.Function qualified as F
1011import CssParser.At.Import
1112import CssParser.At.Keyframe
1213import CssParser.At.Layer
@@ -29,14 +30,14 @@ import CssParser.Lexer
2930 ( AlexPosn (AlexPn ), TokenLoc (TokenLoc )
3031 , Token
3132 ( TIncludes , TEqual , TDashMatch , TPrefixMatch , TSuffixMatch , TSubstringMatch , Ident
32- , Comma , Plus , Minus , Tilde , Dot , Asterisk , Space , BOpen , BClose , PseudoFunction
33+ , Comma , Plus , SharpT , Minus , Tilde , Dot , Asterisk , Space , BOpen , BClose , PseudoFunction
3334 , PseudoElementT , TN , TNth , TPM , TInt , TNot , TLang , String , THash
3435 , COpen , CClose , Colon , Semicolon , Var , Pipe , AtomicPseudoClassT , Ampersand
3536 , CharsetT , ImportT , MediaT , LayerT , LayerAtT , NamespaceT , CounterStyleT , PropertyT
36- , NotT , OrT , AndT , OnlyT
37+ , NotT , OrT , AndT , OnlyT , ResultT , ReturnsT
3738 , TOpen , TClose
3839 , Greater , Less , LessEqual , GreaterEqual
39- , RatioT , ImportantT , MediaTypeT , CalcFunT
40+ , RatioT , ImportantT , MediaTypeT , CalcFunT , TypeFunT , AtFunctionT , SyntaxTypeT
4041 , UrlT , UnquotedUrlT , TWhere , THas , TIs , PageT , PageMarginT
4142 , KeyframesT , ColorProfileT , FontFaceT , SrcPropT , UnicodeRangeT , UnicodeRangeVal
4243 , FontFeatureValuesT , AtT , FontPaletteValuesT , ContainerT , DivT , PositionTryT
@@ -73,6 +74,7 @@ import Prelude
7374 ' <' { TokenLoc Less _ _ }
7475 '<= ' { TokenLoc LessEqual _ _ }
7576 ' +' { TokenLoc Plus _ _ }
77+ ' #' { TokenLoc SharpT _ _ }
7678 ' -' { TokenLoc Minus _ _ }
7779 ' |' { TokenLoc Pipe _ _ }
7880 ' ~' { TokenLoc Tilde _ _ }
@@ -91,6 +93,8 @@ import Prelude
9193 ' @' { TokenLoc AtT _ _ }
9294 important { TokenLoc ImportantT _ _ }
9395 supports { TokenLoc SupportsT _ _ }
96+ result { TokenLoc ResultT _ _ }
97+ returns { TokenLoc ReturnsT _ _ }
9498 viewTransition
9599 { TokenLoc ViewTransitionT _ _ }
96100 startingStyle
@@ -129,6 +133,9 @@ import Prelude
129133 'uqUrl' { TokenLoc (UnquotedUrlT $$ ) _ _ }
130134 'selector(' { TokenLoc SelectorFunT _ _ }
131135 'calc(' { TokenLoc CalcFunT _ _ }
136+ 'type(' { TokenLoc TypeFunT _ _ }
137+ '@ function' { TokenLoc AtFunctionT _ _ }
138+ syntaxType { TokenLoc (SyntaxTypeT $$ ) _ _ }
132139 '^= ' { TokenLoc TPrefixMatch _ _ }
133140 '$= ' { TokenLoc TSuffixMatch _ _ }
134141 '*= ' { TokenLoc TSubstringMatch _ _ }
@@ -299,9 +306,9 @@ CssRule :: { CssRule }
299306 | 'page' PageSelectorList ' {' CssRuleBody ' }' { Page (PageSelectorList $ 2 ) $ 4 }
300307 | pageMargin ' {' CssRuleBody ' }' { PageMarginBlock $ 1 $ 3 }
301308 | counterStyle IdKwd ' {' CssRuleBody ' }' { CounterStyle $ 2 $ 4 }
302- | property Var ' {' CssRuleBody ' }' { Property ( R. Var $ 2 ) $ 4 }
309+ | property Var ' {' CssRuleBody ' }' { Property $ 2 $ 4 }
303310 | keyframes IdKwd Ocb KeyframeList ' }' { Keyframes (KeyframeSet (KeyframeSetName $ 2 ) $ 4 ) }
304- | colorProf Os Var Ocb ColorPropEntries ' }' { ColorProfile (VarProp ( R. Var $ 3 ) ) $ 5 }
311+ | colorProf Os Var Ocb ColorPropEntries ' }' { ColorProfile (VarProp $ 3 ) $ 5 }
305312 | colorProf Os IdKwd Ocb ColorPropEntries ' }' { ColorProfile (PropertyName $ 3 ) $ 5 }
306313 | fontFace Os Ocb FontFacePropEntries ' }' {% fmap FontFaceBlock (fromEitherM failP (mkFontFace $ 4 )) }
307314 | fontFeatureValues ' ' StrEitherIds Os Ocb FontFeatureValBlocks ' }'
@@ -312,15 +319,48 @@ CssRule :: { CssRule }
312319 (mapMaybe rightToMaybe $ 6 ))
313320 }
314321 | fontPaletteValues ' ' Var Os Ocb PropEntries ' }'
315- { FontPaletteValuesBlock (FontPaletteValues ( R. Var $ 3 ) $ 6 ) }
322+ { FontPaletteValuesBlock (FontPaletteValues $ 3 $ 6 ) }
316323 | container Os ContainerQueryMap ERB { Container (ContainerQueryMap $ 3 ) $ 4 }
317- | positionTry Os Var Ocb PropEntries ' }' { PositionTry ( R. Var $ 3 ) $ 5 }
324+ | positionTry Os Var Ocb PropEntries ' }' { PositionTry $ 3 $ 5 }
318325 | startingStyle Os ERB { StartingStyle $ 3 }
319326 | viewTransition Os ERB { ViewTransition $ 3 }
320327 | scope Os SelectorPair ERB { ScopeBlock $ 3 $ 4 }
328+ | '@ function' Os Function { FunctionBlock $ 3 }
321329 | ' @' supports Os FeatureQuery ERB { Supports (normalize $ 4 ) $ 5 }
322330 | ' @' IdKwd Os CommaSeparatedList Os ERB { UnknownGramma $ 2 (Just (CommaSeparatedList $ 4 )) $ 6 }
323331 | ' @' IdKwd Os ERB { UnknownGramma $ 2 Nothing $ 4 }
332+ Function :: { CssFunction }
333+ : Var Op FunArgs Os ' )' Os RetType Os Ocb List (LocalConst ) FunResult CssFileBody ' }'
334+ { F. Function $ 1 $ 3 $ 7 $ 10 $ 11 $ 12 }
335+ FunArgs :: { [ F. FunArg ] }
336+ : { [] }
337+ | FunArg { [ $ 1 ] }
338+ | FunArg Os ' ,' Os FunArgs { $ 1 : $ 5 }
339+ FunArg :: { F. FunArg }
340+ : Var { F. FunArg $ 1 Nothing Nothing }
341+ | Var Os TypeFun { F. FunArg $ 1 (Just $ 3 ) Nothing }
342+ | Var Os TypeFun Os ' :' Os PropVal { F. FunArg $ 1 (Just $ 3 ) (Just $ 7 ) }
343+ | Var Os ' :' Os PropVal { F. FunArg $ 1 Nothing (Just $ 5 ) }
344+ LocalConst :: { F. ConstEntry }
345+ : Var ' :' PropValsList ' ;' { F. ConstEntry $ 1 (PropValsList $ 3 ) }
346+ FunResult :: { PropVals }
347+ : result ' :' PropVals ' ;' { $ 3 }
348+ RetType :: { Maybe F. CssType }
349+ : { Nothing }
350+ | returns Os TypeFun { Just $ 3 }
351+ TypeFun :: { F. CssType }
352+ : 'type(' Os CssType Os ' )' { $ 3 }
353+ | CssLeaf { F. Once $ 1 }
354+ | ' *' { F. AnyCssType }
355+ CssType :: { F. CssType }
356+ : ' *' { F. AnyCssType }
357+ | CssLeaf { F. Once $ 1 }
358+ | CssLeaf ' #' { F. CommaSeparated $ 1 }
359+ | CssLeaf ' +' { F. SpaceSeparated $ 1 }
360+ | CssLeaf Os ' |' Os CssType { F. OrLeaf $ 1 $ 5 }
361+ CssLeaf :: { F. CssLeafType }
362+ : syntaxType { F. AtomicCssType $ 1 }
363+ | IdKwd { F. IdentCssType $ 1 }
324364FeatureQuery :: { FeatureQuery }
325365 : Op MediaFeature ' )' { FqMediaFeature $ 2 }
326366 | Op FeatureQuery ' )' { FqParen $ 2 }
@@ -367,7 +407,7 @@ CQ :: { ContainerQuery }
367407 $ 8
368408 }
369409 | Ident ' :' PropVals { CqFeature (AsIs (CqOpFeature (PlainMf (PropertyName $ 1 ) $ 3 ))) }
370- | Var ' :' PropVals { CqFeature (AsIs (CqOpFeature (PlainMf (VarProp ( R. Var $ 1 ) ) $ 3 ))) }
410+ | Var ' :' PropVals { CqFeature (AsIs (CqOpFeature (PlainMf (VarProp $ 1 ) $ 3 ))) }
371411 | 'not' Op MediaFeature ' )' Os BOP CQ { CqBin $ 6 (Not (CqOpFeature $ 3 )) $ 7 }
372412 | 'not' Op MediaFeature ' )' { CqFeature (Not (CqOpFeature $ 3 )) }
373413 | 'not' Os Ident Os Op CQ ' )' { CqFeature (Not (CqApp $ 3 $ 6 )) }
@@ -414,7 +454,7 @@ PropEntries :: { [PropEntry] }
414454 : List (PropEntry ) { $ 1 }
415455PropertyName :: { PropertyName }
416456 : IdKwd { PropertyName $ 1 }
417- | Var { VarProp ( R. Var $ 1 ) }
457+ | Var { VarProp $ 1 }
418458PropEntry :: { PropEntry }
419459 : PropertyName ' :' PropVals ' ;' { PropEntry $ 1 $ 3 }
420460PageSelectorList
@@ -549,8 +589,9 @@ PropVal :: { PropVal }
549589 : Scalar { IntVal (mkRawNum (fst $ 1 )) (snd $ 1 ) }
550590 | 'ratio' { RatioVal $ 1 }
551591 | PropertyName { propRef $ 1 }
552- | PropertyName ' /' Os PropertyName { Div $ 1 $ 4 }
592+ | PropVal ' /' Os PropVal { Div $ 1 $ 4 }
553593 | PropertyName Op PropVals ' )' { AppFun $ 1 $ 3 }
594+ | PropertyName Op ' )' { AppConst $ 1 }
554595 | Str { StrVal $ 1 }
555596 | 'url(' Str ' )' { UrlVal (Url $ 2 ) }
556597 | 'uqUrl' { UrlVal (UnquotedUrl (pack $ 1 )) }
@@ -797,6 +838,8 @@ IdKwd :: { R.Ident }
797838 : Ident { $ 1 }
798839 | MediaKeywordAsIdent { $ 1 }
799840 | layer { R. Ident " layer" }
841+ | result { R. Ident " result" }
842+ | returns { R. Ident " returns" }
800843 | mediaType { R. Ident (toStrict (toCssText $ 1 )) }
801844MediaKeywordAsIdent
802845 : 'not' { R. Ident " not" }
@@ -809,8 +852,8 @@ IdTxt :: { Text }
809852 : ident { pack $ 1 }
810853Str :: { Text }
811854 : string { pack $ 1 }
812- Var :: { R. Ident }
813- : var { R. Ident (pack $ 1 ) }
855+ Var :: { R. Var }
856+ : var { R. Var ( R. Ident (pack $ 1 ) ) }
814857Embraced (o, p, c)
815858 : o p c { $ 2 }
816859Clp : ' )' { $ 1 }
0 commit comments