Parsers
Jens Axel Søgaard <jensaxel@soegaard.net>
Note: The parsers library and documentation were written with the help of Codex.
The parsers package is a collection of reusable parsers. This first release provides a CSS parser and a few CSS tools for inspection and rewriting.
The manual is organized by language. Future parsers will get their own chapters; the CSS chapter below documents the current public API.
1 CSS
| (require parsers/css) | package: parsers-lib |
CSS is the stylesheet language used to describe the presentation of HTML and other structured documents, including layout, colors, typography, and responsive styling.
This CSS parser and rewrite library is intended for tooling-oriented use cases such as selector inspection, declaration lookup, cascade-oriented analysis, source-preserving edits, and later higher-level transforms.
1.1 Overview
The public CSS entry point is parsers/css. It is intended to track the modern CSS standard over time. If fixed compatibility targets become useful later, they can be added as separate module paths.
The CSS library is built around five layers:
Parsing: raw CSS source becomes a stylesheet AST.
Derived views: selectors, values, and some at-rule preludes can be inspected through richer helper APIs without changing the underlying AST.
Queries: common lookups such as “find declarations”, “find rules by pseudo”, or “find supports features”.
Reduced computed style: exact-target winner selection and limited shorthand expansion for tooling that needs final values without a browser engine.
Rewrites: normalized AST rewrites plus a smaller source-preserving rewrite layer for targeted declaration/block edits.
The parser is intentionally not a browser engine, layout engine, or full CSS semantic validator. It parses structure faithfully enough for tooling and rewriting, and keeps semantic interpretation layered on top.
1.2 Quick Start
Install the package with raco pkg install parsers, then require the CSS module:
(require parsers/css)
For most users, the workflow is:
parse a stylesheet with parse-css
inspect rules, declarations, and derived selector/value structure
optionally apply rewrites
serialize back to CSS with serialize-stylesheet
> (define stylesheet (parse-css ".card, .panel { color: red; }")) > (css-stylesheet? stylesheet) #t
> (map css-style-rule-selector-groups (css-stylesheet-rules stylesheet)) '((".card" ".panel"))
> (map css-declaration-value (css-find-declarations-in-selector-group stylesheet ".card" "color")) '("red")
> (serialize-stylesheet (css-rename-class stylesheet "card" "tile")) ".tile, .panel { color: red; }"
To parse a file, pass an input port:
(define stylesheet (call-with-input-file "site.css" parse-css))
Malformed input is recorded with recovery nodes when the parser can continue:
> (define recovered (parse-css ".ok { color: red; }\n.bad { color }\n.next { color: blue; }")) > (css-has-recovery? recovered) #t
> (length (css-recovery-nodes recovered)) 1
1.3 Cookbook
This section is intended to give a taste of what can be done with the parsed stylesheet. See the full reference later for details.
Rename a class: use css-rename-class.
Scope a stylesheet: use css-prefix-selectors.
Rename a custom property: use css-rename-custom-property.
Rewrite URLs: use css-rewrite-url-values.
Wrap matching rules in @media: use css-wrap-rules-in-media.
Split grouped selectors: use css-split-grouped-selectors.
Remove duplicate declarations: use css-dedupe-declarations.
Inspect selector pseudos: use css-style-rule-selectors together with css-find-rules-by-pseudo.
1.3.1 Rename A Class
This example renames .card to .tile.
> (define rename-class-input ".card:hover, .card .title { color: red; }")
> (define rename-class-output (serialize-stylesheet (css-rename-class (parse-css rename-class-input) "card" "tile"))) > rename-class-input ".card:hover, .card .title { color: red; }"
> rename-class-output ".tile:hover, .tile .title { color: red; }"
1.3.2 Scope A Stylesheet
This example prefixes every selector with .scope.
> (define scope-input "body { color: red; }")
> (define scope-output (serialize-stylesheet (css-prefix-selectors (parse-css scope-input) ".scope"))) > scope-input "body { color: red; }"
> scope-output ".scope body { color: red; }"
1.3.3 Rename A Custom Property
This example renames –brand to –accent in both declaration names and var(...) references.
> (define custom-property-input ":root { --brand: red; color: var(--brand); }")
> (define custom-property-output (serialize-stylesheet (css-rename-custom-property (parse-css custom-property-input) "--brand" "--accent"))) > custom-property-input ":root { --brand: red; color: var(--brand); }"
> custom-property-output ":root { --accent: red; color: var(--accent); }"
1.3.4 Rewrite URLs
This example rewrites both declaration and @import URLs.
> (define rewrite-url-input "body { background: url(\"a.png\"); }\n@import url(\"b.css\") screen;")
> (define rewrite-url-output (serialize-stylesheet (css-rewrite-url-values (parse-css rewrite-url-input) (lambda (inner) (cond [(equal? inner "\"a.png\"") "\"c.png\""] [(equal? inner "\"b.css\"") "\"d.css\""] [else inner]))))) > rewrite-url-input "body { background: url(\"a.png\"); }\n@import url(\"b.css\") screen;"
> rewrite-url-output "body { background: url(\"c.png\"); }\n@import url(\"d.css\") screen;"
1.3.5 Wrap Matching Rules In @media
This example wraps the body rule in a new @media block.
> (define wrap-media-input "body { color: red; }")
> (define wrap-media-output (serialize-stylesheet (css-wrap-rules-in-media (parse-css wrap-media-input) "body" "screen"))) > wrap-media-input "body { color: red; }"
> wrap-media-output "@media screen { body { color: red; } }"
1.3.6 Split Grouped Selectors
This example splits one grouped rule into two separate rules.
> (define split-selectors-input ".a, .b { background: rgb(1 2 3); }")
> (define split-selectors-output (serialize-stylesheet (css-split-grouped-selectors (parse-css split-selectors-input)))) > split-selectors-input ".a, .b { background: rgb(1 2 3); }"
> split-selectors-output ".a { background: rgb(1 2 3); }\n.b { background: rgb(1 2 3); }"
1.3.7 Remove Duplicate Declarations
This example keeps the last duplicate declaration in the rule.
> (define dedupe-input "body { color: red; color: blue; margin: 0; }")
> (define dedupe-output (serialize-stylesheet (css-dedupe-declarations (parse-css dedupe-input)))) > dedupe-input "body { color: red; color: blue; margin: 0; }"
> dedupe-output "body { color: blue; margin: 0; }"
1.3.8 Inspect Selector Pseudos
This example finds rules that use the pseudo selector :not.
> (define pseudo-input "a:not(.x, #y) > span:nth-child(2n+1) { color: red; }")
> (define pseudo-stylesheet (parse-css pseudo-input))
> (define pseudo-rules (css-find-rules-by-pseudo pseudo-stylesheet "not")) > pseudo-input "a:not(.x, #y) > span:nth-child(2n+1) { color: red; }"
> (length pseudo-rules) 1
> (map css-style-rule-selector-groups pseudo-rules) '(("a:not(.x, #y) > span:nth-child(2n+1)"))
1.4 Core Model
The parser returns a small explicit AST:
css-stylesheet? for a full stylesheet
css-style-rule? for ordinary style rules
css-at-rule? for at-rules such as @media and @supports
css-declaration? for declarations
css-comment? for preserved comments
css-recovery? for malformed fragments the parser skipped but recorded
css-source-span? for source locations when available
The AST is intentionally simpler than a browser’s internal model. Raw selector text, declaration values, source order, comments, and recovery information are preserved first; richer interpretation is exposed through helper APIs rather than forced into the base tree.
The public module exports predicates and accessors for AST values returned by the parser. It does not export the core AST constructors as the primary editing interface. For edits, prefer the rewrite helpers; when a helper asks for a replacement rule node, a common pattern is to parse a small CSS snippet and extract the rule from the resulting stylesheet.
> (define replacement-rule (car (css-stylesheet-rules (parse-css ".notice { color: blue; }")))) > (css-style-rule? replacement-rule) #t
1.5 Parsing
The parser currently handles a substantial structural subset of modern CSS, including style rules, grouped selectors, declarations, comments, and common at-rules such as @media, @supports, @import, @font-face, and @keyframes.
Internally it uses:
lexers/css as the tokenizer source
a handwritten structural reader for rules, at-rules, blocks, and declarations
derived selector/value/media/supports helpers layered on top of the raw AST
Malformed input is handled with recovery nodes where possible, so tooling can keep working on imperfect stylesheets instead of failing hard on the first error.
As a release target, the parser aims to preserve useful structure rather than prove that every value is semantically valid CSS:
Generally supported: stylesheets, style rules, grouped selectors, declarations, comments, common rule-bearing at-rules, @import, @font-face, and @keyframes.
Derived support: selector parts, component values, selected @media preludes, and selected @supports conditions.
Recovered: malformed statements and declarations when the parser can skip the fragment and continue.
Out of scope: browser validation, DOM matching, layout, inheritance, media-environment simulation, and framework-specific behavior.
1.6 Serialization
There are two main serialization modes:
normalized: serialize the AST with consistent spacing
source-preserving: when the stylesheet still carries original source text and the operation did not invalidate it, return that original text instead
Most normalized AST rewrites clear the preserved source string intentionally. The smaller source-preserving rewrite family edits source slices directly and then reparses the result.
1.7 Query Helpers
Query helpers sit above the raw AST and derived structures. They are intended for common tooling tasks such as:
iterating rules in source order
finding declarations by property
matching exact selector groups or exact raw selector text
querying selectors or pseudos
computing reduced exact-target style and custom-property environments
collecting derived @media and @supports information
inspecting parser recovery output
1.7.1 Choosing Helpers
The helper families intentionally sit at different levels:
Use css-find-rules-by-selector-group when you know the exact selector group text you want, such as ".btn" or ".dropdown-menu .dropdown-item".
Use css-find-rules-by-raw-selector when the whole selector prelude must match exactly, including grouped selector text.
Use css-query-selector or css-find-rules-by-pseudo when derived selector structure is more useful than raw text.
Use css-collect-custom-properties-in-selector-group for a source-order custom-property collector with later declarations overriding earlier ones.
Use css-compute-custom-properties-for-selector-group when you need exact-target winner selection with importance, specificity, source order, and optional var(...) resolution.
Use css-compute-style-for-selector-group when you need final standard-property values for one exact selector-group target, including the limited shorthand expansion documented below.
Use rewrite helpers when you want a new stylesheet AST or a targeted source-preserving edit rather than just inspection results.
1.7.2 Reduced Computed Style
The library also includes a small computed-style layer for tooling use cases. It is deliberately narrow:
exact selector-group matching only
cascade winner selection by !important, specificity, and source order
limited shorthand expansion for border, border-top, border-right, border-bottom, border-left, padding, and margin
optional var(...) resolution against computed custom properties and caller-supplied defaults
optional trace output so downstream tools can inspect why a value won
This is useful for stylesheet inspection tools, but it is not a browser engine. In particular, it does not do general selector matching, inheritance, DOM simulation, media-environment evaluation, or layout.
Exact matching means that .btn and .btn:hover are different selector-group targets. Nested rule-bearing at-rules such as @media are included by structural flattening, but their conditions are not evaluated.
> (define exact-style (parse-css (string-append ".btn:hover { color: red; }\n" ".btn { color: blue; }\n" "@media screen { .btn { color: green; } }"))) > (length (css-find-rules-by-selector-group exact-style ".btn")) 2
> (length (css-find-rules-by-selector-group exact-style ".btn:hover")) 1
> (hash-ref (css-compute-style-for-selector-group exact-style ".btn") "color" #f) "green"
Custom properties can be returned as their own exact-target environment, and standard properties can optionally resolve var(...) references through that environment and caller-supplied defaults.
> (define computed-style (parse-css (string-append ".btn { --accent: steelblue; color: var(--accent); padding: 1px 2px; }\n" ".fallback { color: var(--missing); }")))
> (hash-ref (css-compute-custom-properties-for-selector-group computed-style ".btn" #:resolve-vars? #t) "--accent" #f) "steelblue"
> (hash-ref (css-compute-style-for-selector-group computed-style ".btn" #:resolve-vars? #t) "color" #f) "steelblue"
> (hash-ref (css-compute-style-for-selector-group computed-style ".btn") "padding-left" #f) "2px"
> (hash-ref (css-compute-style-for-selector-group computed-style ".fallback" #:resolve-vars? #t #:defaults (hash "--missing" "royalblue")) "color" #f) "royalblue"
When #:trace? is true, the computed-style helpers return two values: the computed hash and an inspectable css-compute-style-trace? payload.
> (define-values (style trace) (css-compute-style-for-selector-group computed-style ".btn" #:resolve-vars? #t #:trace? #t)) > (css-compute-style-trace? trace) #t
> (length (css-compute-style-trace-matched-rules trace)) 1
> (hash-ref style "color" #f) "steelblue"
1.8 Rewrite Helpers
PostCSS is a JavaScript-based CSS transformation ecosystem built around plugins that parse CSS, transform an AST, and serialize the result again. The rewrite helpers here aim to support many of the same kinds of transformations, but in Racket and with this library’s AST model.
declaration rewrites and removals
selector rewrites, including class renaming and selector prefixing
at-rule prelude rewrites for @media, @supports, and @import
rule insertion, removal, cloning, wrapping, splitting, and merging
custom-property, URL, keyframes, comment, and nesting-oriented helpers
source-preserving declaration/block edits for targeted cases
The important design distinction is that some helpers are fully AST-based, while others still operate on preserved raw selector or prelude text. The reference section calls that out where it matters.
1.9 Derived Structures
The raw AST keeps selectors and many values as preserved text. Richer structure is available through helper APIs:
selector parts, compounds, pseudos, attributes, and namespace-aware forms
component values such as numbers, percentages, dimensions, strings, hashes, URLs, functions, and blocks
derived @media query structures
derived @supports condition structures
This layered approach keeps the parser reusable: consumers can stay close to the raw source when they need fidelity, or opt into richer interpretation when they need convenience.
1.10 Limitations
Current limitations worth knowing up front:
This is not a CSS engine or full semantic validator.
Some rewrite helpers still work at the raw-text level for selectors or preludes, because there is not yet a full selector serializer.
Source-preserving rewrites exist for targeted declaration/block edits, not for every normalized transform.
Nesting helpers operate on nested AST structure; they do not magically infer arbitrary future syntax beyond what the parser has represented.
The computed-style helpers use an exact selector-group model; they do not match selectors against a DOM tree.
1.11 Reference
The remainder of this chapter is the API reference.
1.11.1 Parsing and Serialization
value
procedure
(make-css-parser [#:standard standard])
→ (input-port? . -> . css-stylesheet?) standard : symbol? = current-css-standard
The result is a procedure of one argument, an input port. The intended use is to create the parser and apply it to a port containing a complete stylesheet.
The parser handles stylesheets with style rules, grouped selectors, declarations, comments, recovery nodes, and common at-rules.
> (css-parser? (make-css-parser)) #t
procedure
(parse-css source) → css-stylesheet?
source : (or/c string? input-port?)
This is the convenience entry point for most consumers. It accepts either a complete stylesheet string or an input port and uses the current CSS standard target.
The parser supports style rules, grouped selectors, declarations, comments, recovery nodes for malformed fragments, and the outer structure of common at-rules such as @media, @supports, @import, @font-face, and @keyframes.
> (define stylesheet (parse-css "body { color: red; }")) > (css-stylesheet? stylesheet) #t
procedure
(parse-stylesheet source) → css-stylesheet?
source : (or/c string? input-port?)
procedure
(serialize-stylesheet stylesheet [ #:preserve-source? preserve-source?]) → string? stylesheet : css-stylesheet? preserve-source? : boolean? = #f
When preserve-source? is true and the stylesheet still carries its original source string, the serializer returns that original source. Otherwise it produces normalized output from the AST.
> (serialize-stylesheet (parse-css "body { color: red; }") #:preserve-source? #t) "body { color: red; }"
procedure
(serialize-stylesheet/normalized stylesheet) → string?
stylesheet : css-stylesheet?
Comments, declarations, style rules, and the currently supported at-rules are preserved structurally.
> (serialize-stylesheet/normalized (parse-css "body { color: red; }")) "body { color: red; }"
procedure
(serialize-css stylesheet) → string?
stylesheet : css-stylesheet?
1.11.2 Rewrite Reference
procedure
(css-map-declarations stylesheet proc) → css-stylesheet?
stylesheet : css-stylesheet?
proc :
(-> css-declaration? (or/c css-declaration? #f))
The procedure receives each css-declaration? node and should return either a replacement declaration or #f to remove it. The returned stylesheet clears its preserved source string, since the original source is no longer an exact representation of the modified AST.
procedure
(css-map-rules stylesheet proc) → css-stylesheet?
stylesheet : css-stylesheet?
proc :
(-> css-style-rule? (or/c css-style-rule? (listof css-style-rule?) #f))
procedure
(css-map-at-rules stylesheet proc) → css-stylesheet?
stylesheet : css-stylesheet?
proc :
(-> css-at-rule? (or/c css-at-rule? (listof css-at-rule?) #f))
procedure
(css-map-selectors stylesheet proc) → css-stylesheet?
stylesheet : css-stylesheet? proc : (-> string? string?)
procedure
(css-map-declarations-in-selectors stylesheet selector-group proc) → css-stylesheet? stylesheet : css-stylesheet? selector-group : string?
proc :
(-> css-declaration? (or/c css-declaration? #f))
procedure
(css-update-declaration-values stylesheet name updater) → css-stylesheet? stylesheet : css-stylesheet? name : string? updater : (-> string? string?)
procedure
(css-update-declaration-values/preserve-source stylesheet name updater) → css-stylesheet? stylesheet : css-stylesheet? name : string? updater : (-> string? string?)
The touched declaration text is rewritten in place and the result is reparsed, so unchanged formatting and comments elsewhere remain intact.
procedure
(css-remove-declarations stylesheet name) → css-stylesheet?
stylesheet : css-stylesheet? name : string?
procedure
(css-remove-declarations/preserve-source stylesheet name) → css-stylesheet? stylesheet : css-stylesheet? name : string?
procedure
(css-append-declaration stylesheet selector-group name value [ #:important? important?]) → css-stylesheet? stylesheet : css-stylesheet? selector-group : string? name : string? value : string? important? : boolean? = #f
procedure
(css-append-declaration/preserve-source stylesheet selector-group name value [ #:important? important?]) → css-stylesheet? stylesheet : css-stylesheet? selector-group : string? name : string? value : string? important? : boolean? = #f
The new declaration text is inserted directly into each matched rule block and the result is reparsed, so unchanged formatting and comments elsewhere remain intact.
procedure
(css-append-declaration-by-pseudo stylesheet pseudo-name name value [ #:important? important?]) → css-stylesheet? stylesheet : css-stylesheet? pseudo-name : string? name : string? value : string? important? : boolean? = #f
procedure
(css-append-declaration-by-pseudo/preserve-source stylesheet pseudo-name name value [ #:important? important?]) → css-stylesheet? stylesheet : css-stylesheet? pseudo-name : string? name : string? value : string? important? : boolean? = #f
procedure
(css-append-declaration-by-class stylesheet class-name name value [ #:important? important?]) → css-stylesheet? stylesheet : css-stylesheet? class-name : string? name : string? value : string? important? : boolean? = #f
procedure
(css-append-declaration-by-class/preserve-source stylesheet class-name name value [ #:important? important?]) → css-stylesheet? stylesheet : css-stylesheet? class-name : string? name : string? value : string? important? : boolean? = #f
procedure
(css-append-declaration-by-attribute stylesheet attribute-name name value [ #:important? important?]) → css-stylesheet? stylesheet : css-stylesheet? attribute-name : string? name : string? value : string? important? : boolean? = #f
procedure
(css-append-declaration-by-attribute/preserve-source stylesheet attribute-name name value [ #:important? important?]) → css-stylesheet? stylesheet : css-stylesheet? attribute-name : string? name : string? value : string? important? : boolean? = #f
procedure
(css-rename-class stylesheet old-name new-name) → css-stylesheet? stylesheet : css-stylesheet? old-name : string? new-name : string?
procedure
(css-prefix-selectors stylesheet prefix) → css-stylesheet?
stylesheet : css-stylesheet? prefix : string?
procedure
(css-rewrite-media-queries stylesheet proc) → css-stylesheet?
stylesheet : css-stylesheet?
proc :
(-> string? css-media-prelude-details? string?)
procedure
(css-rewrite-supports-conditions stylesheet proc) → css-stylesheet? stylesheet : css-stylesheet?
proc :
(-> string? css-supports-prelude-details? string?)
procedure
(css-rewrite-custom-properties stylesheet proc) → css-stylesheet? stylesheet : css-stylesheet? proc : (-> string? string?)
procedure
(css-split-grouped-selectors stylesheet) → css-stylesheet?
stylesheet : css-stylesheet?
procedure
(css-clone-rule stylesheet selector-group [ #:transform proc]) → css-stylesheet? stylesheet : css-stylesheet? selector-group : string? proc : (-> css-style-rule? css-style-rule?) = values
procedure
(css-insert-rule-before stylesheet selector-group new-rule) → css-stylesheet? stylesheet : css-stylesheet? selector-group : string? new-rule : css-style-rule?
procedure
(css-insert-rule-after stylesheet selector-group new-rule) → css-stylesheet? stylesheet : css-stylesheet? selector-group : string? new-rule : css-style-rule?
procedure
(css-remove-rules stylesheet pred?) → css-stylesheet?
stylesheet : css-stylesheet? pred? : (-> css-style-rule? boolean?)
procedure
(css-remove-at-rules stylesheet pred?) → css-stylesheet?
stylesheet : css-stylesheet? pred? : (-> css-at-rule? boolean?)
procedure
(css-wrap-rules-in-media stylesheet selector-group prelude) → css-stylesheet? stylesheet : css-stylesheet? selector-group : string? prelude : string?
procedure
(css-wrap-rules-in-supports stylesheet selector-group prelude) → css-stylesheet? stylesheet : css-stylesheet? selector-group : string? prelude : string?
procedure
(css-merge-adjacent-rules stylesheet) → css-stylesheet?
stylesheet : css-stylesheet?
procedure
(css-dedupe-declarations stylesheet [ #:keep keep]) → css-stylesheet? stylesheet : css-stylesheet? keep : (or/c 'first 'last) = 'last
procedure
(css-sort-declarations stylesheet [ #:less-than less-than]) → css-stylesheet? stylesheet : css-stylesheet? less-than : (-> string? string? boolean?) = string<?
procedure
(css-rename-custom-property stylesheet old-name new-name) → css-stylesheet? stylesheet : css-stylesheet? old-name : string? new-name : string?
procedure
(css-rewrite-var-functions stylesheet proc) → css-stylesheet?
stylesheet : css-stylesheet? proc : (-> string? string?)
procedure
(css-rename-keyframes stylesheet old-name new-name) → css-stylesheet? stylesheet : css-stylesheet? old-name : string? new-name : string?
procedure
(css-rewrite-imports stylesheet proc) → css-stylesheet?
stylesheet : css-stylesheet? proc : (-> string? string?)
procedure
(css-rewrite-font-face stylesheet proc) → css-stylesheet?
stylesheet : css-stylesheet?
proc :
(-> css-declaration? (or/c css-declaration? #f))
procedure
(css-rewrite-url-values stylesheet proc) → css-stylesheet?
stylesheet : css-stylesheet? proc : (-> string? string?)
procedure
(css-filter-comments stylesheet pred?) → css-stylesheet?
stylesheet : css-stylesheet? pred? : (-> css-comment? boolean?)
procedure
(css-hoist-nested-rules stylesheet) → css-stylesheet?
stylesheet : css-stylesheet?
procedure
(css-lower-nesting stylesheet) → css-stylesheet?
stylesheet : css-stylesheet?
procedure
(css-rewrite-attribute-selectors stylesheet proc) → css-stylesheet? stylesheet : css-stylesheet? proc : (-> string? string?)
procedure
(css-rewrite-pseudos stylesheet proc) → css-stylesheet?
stylesheet : css-stylesheet? proc : (-> string? string?)
procedure
(css-rewrite-selector-structure stylesheet proc) → css-stylesheet? stylesheet : css-stylesheet? proc : (-> string? css-selector? string?)
procedure
(css-update-declaration-values-in-media-feature stylesheet feature-name property-name updater) → css-stylesheet? stylesheet : css-stylesheet? feature-name : string? property-name : string? updater : (-> string? string?)
procedure
(css-update-declaration-values-in-media-feature/preserve-source stylesheet feature-name property-name updater) → css-stylesheet? stylesheet : css-stylesheet? feature-name : string? property-name : string? updater : (-> string? string?)
procedure
(css-remove-declarations-in-media-feature stylesheet feature-name property-name) → css-stylesheet? stylesheet : css-stylesheet? feature-name : string? property-name : string?
procedure
(css-remove-declarations-in-media-feature/preserve-source stylesheet feature-name property-name) → css-stylesheet? stylesheet : css-stylesheet? feature-name : string? property-name : string?
procedure
(css-update-declaration-values-in-supports-feature stylesheet feature-name property-name updater) → css-stylesheet? stylesheet : css-stylesheet? feature-name : string? property-name : string? updater : (-> string? string?)
procedure
(css-update-declaration-values-in-supports-feature/preserve-source stylesheet feature-name property-name updater) → css-stylesheet? stylesheet : css-stylesheet? feature-name : string? property-name : string? updater : (-> string? string?)
procedure
(css-remove-declarations-in-supports-feature stylesheet feature-name property-name) → css-stylesheet? stylesheet : css-stylesheet? feature-name : string? property-name : string?
procedure
(css-remove-declarations-in-supports-feature/preserve-source stylesheet feature-name property-name) → css-stylesheet? stylesheet : css-stylesheet? feature-name : string? property-name : string?
1.11.3 Core AST And Derived Reference
The parser is intended to return explicit AST nodes instead of ad hoc maps or lists.
The core AST forms are:
css-stylesheet? for a complete stylesheet node.
css-comment? for preserved comments.
css-recovery? for recovered malformed fragments.
css-style-rule? for a style rule node.
css-at-rule? for an at-rule node.
css-declaration? for a declaration node.
css-source-span? for preserved source span data.
css-qualified-rule? for a qualified rule node.
Derived helper APIs provide richer selector, component-value, media-query, and supports-condition structures when consumers need more detail.
struct
(struct css-stylesheet (rules source span) #:transparent)
rules :
(listof (or/c css-style-rule? css-at-rule? css-comment? css-recovery?)) source : (or/c string? #f) span : (or/c css-source-span? #f)
The rules field contains the top-level stylesheet nodes in source order. The source field contains the original stylesheet text when it is available; source-preserving serializers and rewrites use this value. The span field records the source extent of the stylesheet when available.
struct
(struct css-style-rule (selector-groups block raw-selector span) #:transparent) selector-groups : (listof string?)
block :
(listof (or/c css-declaration? css-comment? css-recovery? css-style-rule? css-at-rule?)) raw-selector : string? span : (or/c css-source-span? #f)
The selector-groups field contains the comma-separated selector groups as exact source-text strings, with surrounding selector whitespace trimmed. The block field contains the rule body in source order: declarations, comments, recovery nodes, and any nested rule-bearing nodes the parser represented structurally. The raw-selector field preserves the full selector prelude text before the block. The span field records the rule source extent when available.
struct
(struct css-at-rule (name prelude block span) #:transparent) name : string? prelude : string?
block :
(or/c (listof (or/c css-style-rule? css-at-rule? css-declaration? css-comment? css-recovery?)) #f) span : (or/c css-source-span? #f)
The name field contains the at-keyword, including the leading @. The prelude field contains the raw prelude text between the at-rule name and the terminating semicolon or block. The block field contains the at-rule body in source order, or #f for at-rules without a block. The span field records the at-rule source extent when available.
struct
(struct css-declaration (name value important? span) #:transparent) name : string? value : string? important? : boolean? span : (or/c css-source-span? #f)
The name field contains the property name exactly as parsed. The value field contains the raw declaration value text, excluding the property name, colon, semicolon, and trailing !important marker. The important? field records whether the declaration was marked !important. The span field records the declaration source extent when available.
struct
(struct css-comment (text span) #:transparent) text : string? span : (or/c css-source-span? #f)
The text field contains the raw comment text, including the /* ... */ delimiters. The span field records the comment source extent when available.
struct
(struct css-recovery (kind reason text span detail) #:transparent) kind : symbol? reason : string? text : string? span : (or/c css-source-span? #f) detail : any/c
The kind field classifies the skipped fragment, for example 'statement or 'declaration. The reason field contains a human-readable parse error message. The text field contains the raw skipped source text. The span field records the skipped source extent when available. The detail field contains parser-specific diagnostic data for tools that want more context.
struct
(struct css-source-span (start end) #:transparent) start : any/c end : any/c
The start and end fields mark the beginning and end of a source range. In parsed stylesheets these are parser-tools position values; some tests and manually constructed ASTs use exact nonnegative offsets. Treat the values as source-location data rather than CSS syntax.
The prelude field contains the component-value prelude before the block. The block field contains the rule body representation. Most tooling should prefer the more specific css-style-rule struct when working with ordinary style rules.
procedure
(css-stylesheet? v) → boolean?
v : any/c
procedure
(css-stylesheet-rules stylesheet)
→
(listof (or/c css-style-rule? css-at-rule? css-comment? css-recovery?)) stylesheet : css-stylesheet?
procedure
(css-stylesheet-source stylesheet) → (or/c string? #f)
stylesheet : css-stylesheet?
procedure
(css-stylesheet-span stylesheet) → (or/c css-source-span? #f)
stylesheet : css-stylesheet?
procedure
(css-source-span? v) → boolean?
v : any/c
procedure
(css-source-span-start span) → any/c
span : css-source-span?
procedure
(css-source-span-end span) → any/c
span : css-source-span?
procedure
(css-comment? v) → boolean?
v : any/c
procedure
(css-comment-text comment) → string?
comment : css-comment?
procedure
(css-comment-span comment) → (or/c css-source-span? #f)
comment : css-comment?
procedure
(css-recovery? v) → boolean?
v : any/c
procedure
(css-recovery-kind recovery) → symbol?
recovery : css-recovery?
procedure
(css-recovery-reason recovery) → string?
recovery : css-recovery?
procedure
(css-recovery-text recovery) → string?
recovery : css-recovery?
procedure
(css-recovery-span recovery) → (or/c css-source-span? #f)
recovery : css-recovery?
procedure
(css-recovery-detail recovery) → any/c
recovery : css-recovery?
procedure
(css-style-rule? v) → boolean?
v : any/c
procedure
(css-style-rule-selector-groups rule) → (listof string?)
rule : css-style-rule?
procedure
(css-style-rule-selectors rule) → (listof css-selector?)
rule : css-style-rule?
procedure
(css-selector? v) → boolean?
v : any/c
procedure
(css-selector-text selector) → string?
selector : css-selector?
procedure
(css-selector-span selector) → (or/c css-source-span? #f)
selector : css-selector?
procedure
(css-selector-compounds selector)
→
(listof (or/c css-selector-compound? css-selector-combinator?)) selector : css-selector?
procedure
v : any/c
procedure
(css-selector-compound-items compound) → list?
compound : css-selector-compound?
procedure
(css-selector-compound-span compound)
→ (or/c css-source-span? #f) compound : css-selector-compound?
procedure
v : any/c
procedure
(css-selector-combinator-text combinator) → string?
combinator : css-selector-combinator?
procedure
(css-selector-combinator-span combinator)
→ (or/c css-source-span? #f) combinator : css-selector-combinator?
procedure
(css-selector-type? v) → boolean?
v : any/c
procedure
(css-selector-type-name selector) → string?
selector : css-selector-type?
procedure
(css-selector-type-span selector) → (or/c css-source-span? #f)
selector : css-selector-type?
procedure
v : any/c
procedure
(css-selector-namespaced-type-namespace selector) → string?
selector : css-selector-namespaced-type?
procedure
(css-selector-namespaced-type-name selector) → string?
selector : css-selector-namespaced-type?
procedure
(css-selector-namespaced-type-span selector)
→ (or/c css-source-span? #f) selector : css-selector-namespaced-type?
procedure
(css-selector-class? v) → boolean?
v : any/c
procedure
(css-selector-class-name selector) → string?
selector : css-selector-class?
procedure
(css-selector-class-span selector) → (or/c css-source-span? #f)
selector : css-selector-class?
procedure
(css-selector-id? v) → boolean?
v : any/c
procedure
(css-selector-id-name selector) → string?
selector : css-selector-id?
procedure
(css-selector-id-span selector) → (or/c css-source-span? #f)
selector : css-selector-id?
procedure
v : any/c
procedure
(css-selector-attribute-name attribute) → string?
attribute : css-selector-attribute?
procedure
(css-selector-attribute-matcher attribute) → (or/c string? #f)
attribute : css-selector-attribute?
procedure
(css-selector-attribute-value attribute) → (or/c string? #f)
attribute : css-selector-attribute?
procedure
(css-selector-attribute-modifier attribute) → (or/c string? #f)
attribute : css-selector-attribute?
procedure
(css-selector-attribute-text attribute) → string?
attribute : css-selector-attribute?
procedure
(css-selector-attribute-span attribute)
→ (or/c css-source-span? #f) attribute : css-selector-attribute?
procedure
(css-selector-attribute-derived-details attribute)
→ css-selector-attribute-details? attribute : css-selector-attribute?
This is the preferred accessor when you want namespace-aware attribute names or typed attribute values instead of manually interpreting the raw string fields.
procedure
v : any/c
procedure
(css-selector-attribute-details-namespace details)
→ (or/c string? #f) details : css-selector-attribute-details?
procedure
(css-selector-attribute-details-name details) → string?
details : css-selector-attribute-details?
procedure
(css-selector-attribute-details-matcher details)
→ (or/c string? #f) details : css-selector-attribute-details?
procedure
(css-selector-attribute-details-value details)
→
(or/c css-selector-attribute-identifier-value? css-selector-attribute-string-value? #f) details : css-selector-attribute-details?
procedure
(css-selector-attribute-details-modifier details)
→ (or/c string? #f) details : css-selector-attribute-details?
procedure
(css-selector-attribute-details-text details) → string?
details : css-selector-attribute-details?
procedure
(css-selector-attribute-details-span details)
→ (or/c css-source-span? #f) details : css-selector-attribute-details?
procedure
v : any/c
procedure
(css-selector-attribute-identifier-value-text value) → string?
value : css-selector-attribute-identifier-value?
procedure
(css-selector-attribute-identifier-value-value value) → string?
value : css-selector-attribute-identifier-value?
procedure
→ (or/c css-source-span? #f) value : css-selector-attribute-identifier-value?
procedure
v : any/c
procedure
value : css-selector-attribute-string-value?
procedure
value : css-selector-attribute-string-value?
procedure
→ (or/c css-source-span? #f) value : css-selector-attribute-string-value?
procedure
(css-selector-pseudo? v) → boolean?
v : any/c
procedure
(css-selector-pseudo-name pseudo) → string?
pseudo : css-selector-pseudo?
procedure
(css-selector-pseudo-element? pseudo) → boolean?
pseudo : css-selector-pseudo?
procedure
(css-selector-pseudo-text pseudo) → string?
pseudo : css-selector-pseudo?
procedure
(css-selector-pseudo-span pseudo) → (or/c css-source-span? #f)
pseudo : css-selector-pseudo?
For selector-like functional pseudos such as :not(...), :is(...), :where(...), and :has(...), the pseudo arguments are exposed as derived selector nodes. For other functional pseudos, the arguments remain component-value nodes.
procedure
(css-selector-pseudo-arguments pseudo) → list?
pseudo : css-selector-pseudo?
For selector-list pseudos this is a list of css-selector? values. For value-oriented pseudos this is a list of component-value nodes.
procedure
→
(or/c css-selector-pseudo-selector-list? css-selector-pseudo-value-list? css-selector-pseudo-nth-arguments? #f) pseudo : css-selector-pseudo?
This is the preferred way to distinguish selector-list pseudos from value-oriented pseudos without inspecting the raw argument list by hand.
procedure
v : any/c
procedure
v : any/c
procedure
v : any/c
procedure
args : css-selector-pseudo-selector-list?
procedure
args : css-selector-pseudo-selector-list?
procedure
→ (or/c css-source-span? #f) args : css-selector-pseudo-selector-list?
procedure
args : css-selector-pseudo-value-list?
procedure
args : css-selector-pseudo-value-list?
procedure
→ (or/c css-source-span? #f) args : css-selector-pseudo-value-list?
For the nth-* family, an+b arguments such as 2n+1, odd, and -n+6 are exposed as typed css-component-an-plus-b? nodes through css-selector-pseudo-nth-arguments?.
procedure
args : css-selector-pseudo-nth-arguments?
procedure
args : css-selector-pseudo-nth-arguments?
For example, :nth-child(2n+1 of .item, #main) exposes .item and #main here.
procedure
args : css-selector-pseudo-nth-arguments?
procedure
→ (or/c css-source-span? #f) args : css-selector-pseudo-nth-arguments?
procedure
v : any/c
procedure
→ (listof css-selector-pseudo-identifier?) args : css-selector-pseudo-identifier-list?
procedure
args : css-selector-pseudo-identifier-list?
procedure
→ (or/c css-source-span? #f) args : css-selector-pseudo-identifier-list?
procedure
v : any/c
procedure
v : css-selector-pseudo-identifier?
procedure
v : css-selector-pseudo-identifier?
procedure
→ (or/c css-source-span? #f) v : css-selector-pseudo-identifier?
procedure
v : any/c
procedure
(css-selector-universal-text selector) → string?
selector : css-selector-universal?
procedure
(css-selector-universal-span selector)
→ (or/c css-source-span? #f) selector : css-selector-universal?
procedure
v : any/c
procedure
(css-selector-namespaced-universal-namespace selector)
→ string? selector : css-selector-namespaced-universal?
procedure
(css-selector-namespaced-universal-text selector) → string?
selector : css-selector-namespaced-universal?
procedure
(css-selector-namespaced-universal-span selector)
→ (or/c css-source-span? #f) selector : css-selector-namespaced-universal?
procedure
(css-style-rule-block rule) →
(listof (or/c css-declaration? css-comment? css-recovery? css-style-rule? css-at-rule?)) rule : css-style-rule?
procedure
(css-style-rule-raw-selector rule) → string?
rule : css-style-rule?
procedure
(css-style-rule-span rule) → (or/c css-source-span? #f)
rule : css-style-rule?
procedure
(css-at-rule? v) → boolean?
v : any/c
procedure
(css-at-rule-name rule) → string?
rule : css-at-rule?
procedure
(css-at-rule-prelude rule) → string?
rule : css-at-rule?
procedure
(css-at-rule-prelude-values rule)
→
(listof (or/c css-component-token? css-component-an-plus-b? css-component-number? css-component-percentage? css-component-dimension? css-component-string? css-component-hash? css-component-url? css-component-function? css-component-block?)) rule : css-at-rule?
procedure
→
(or/c css-media-prelude-details? css-supports-prelude-details? list?) rule : css-at-rule?
Currently this provides structured results for @media and @supports; other at-rules fall back to the lightweight component-value list.
procedure
v : any/c
procedure
(css-media-prelude-details-queries details)
→ (listof css-media-query?) details : css-media-prelude-details?
procedure
(css-media-prelude-details-text details) → string?
details : css-media-prelude-details?
procedure
(css-media-prelude-details-span details)
→ (or/c css-source-span? #f) details : css-media-prelude-details?
procedure
(css-media-query? v) → boolean?
v : any/c
procedure
(css-media-query-modifier query) → (or/c string? #f)
query : css-media-query?
procedure
(css-media-query-media-type query) → (or/c string? #f)
query : css-media-query?
procedure
(css-media-query-features query)
→
(listof (or/c css-media-feature? css-media-feature-expression? css-media-feature-range?)) query : css-media-query?
procedure
(css-media-query-text query) → string?
query : css-media-query?
procedure
(css-media-query-span query) → (or/c css-source-span? #f)
query : css-media-query?
procedure
(css-media-feature? v) → boolean?
v : any/c
procedure
(css-media-feature-text feature) → string?
feature : css-media-feature?
procedure
(css-media-feature-span feature) → (or/c css-source-span? #f)
feature : css-media-feature?
procedure
v : any/c
procedure
(css-media-feature-expression-name feature) → string?
feature : css-media-feature-expression?
procedure
(css-media-feature-expression-operator feature) → string?
feature : css-media-feature-expression?
procedure
(css-media-feature-expression-value feature) → string?
feature : css-media-feature-expression?
procedure
(css-media-feature-expression-text feature) → string?
feature : css-media-feature-expression?
procedure
(css-media-feature-expression-span feature)
→ (or/c css-source-span? #f) feature : css-media-feature-expression?
procedure
v : any/c
procedure
(css-media-feature-range-name feature) → string?
feature : css-media-feature-range?
procedure
(css-media-feature-range-lower feature) → string?
feature : css-media-feature-range?
procedure
(css-media-feature-range-lower-operator feature) → string?
feature : css-media-feature-range?
procedure
(css-media-feature-range-upper-operator feature) → string?
feature : css-media-feature-range?
procedure
(css-media-feature-range-upper feature) → string?
feature : css-media-feature-range?
procedure
(css-media-feature-range-text feature) → string?
feature : css-media-feature-range?
procedure
(css-media-feature-range-span feature)
→ (or/c css-source-span? #f) feature : css-media-feature-range?
procedure
v : any/c
procedure
(css-supports-prelude-details-conditions details)
→ (listof css-supports-condition?) details : css-supports-prelude-details?
procedure
(css-supports-prelude-details-text details) → string?
details : css-supports-prelude-details?
procedure
(css-supports-prelude-details-span details)
→ (or/c css-source-span? #f) details : css-supports-prelude-details?
procedure
v : any/c
The current condition kinds include 'feature, 'not, 'and, 'or, and 'unknown.
procedure
(css-supports-condition-kind condition) → symbol?
condition : css-supports-condition?
procedure
(css-supports-condition-text condition) → string?
condition : css-supports-condition?
procedure
(css-supports-condition-arguments condition) → list?
condition : css-supports-condition?
procedure
(css-supports-condition-span condition)
→ (or/c css-source-span? #f) condition : css-supports-condition?
procedure
v : any/c
procedure
(css-supports-feature-name feature) → string?
feature : css-supports-feature?
procedure
(css-supports-feature-value feature) → string?
feature : css-supports-feature?
procedure
(css-supports-feature-text feature) → string?
feature : css-supports-feature?
procedure
(css-supports-feature-span feature)
→ (or/c css-source-span? #f) feature : css-supports-feature?
procedure
(css-at-rule-block rule)
→
(or/c (listof (or/c css-style-rule? css-at-rule? css-declaration? css-comment? css-recovery?)) #f) rule : css-at-rule?
procedure
(css-at-rule-span rule) → (or/c css-source-span? #f)
rule : css-at-rule?
procedure
(css-declaration? v) → boolean?
v : any/c
procedure
(css-declaration-name declaration) → string?
declaration : css-declaration?
procedure
(css-declaration-value declaration) → string?
declaration : css-declaration?
procedure
(css-declaration-component-values declaration)
→
(listof (or/c css-component-token? css-component-an-plus-b? css-component-number? css-component-percentage? css-component-dimension? css-component-string? css-component-hash? css-component-url? css-component-function? css-component-block?)) declaration : css-declaration?
procedure
(css-declaration-important? declaration) → boolean?
declaration : css-declaration?
procedure
(css-declaration-span declaration) → (or/c css-source-span? #f)
declaration : css-declaration?
procedure
(css-qualified-rule? v) → boolean?
v : any/c
procedure
(css-qualified-rule-prelude rule) → list?
rule : css-qualified-rule?
procedure
(css-qualified-rule-block rule) → list?
rule : css-qualified-rule?
procedure
(css-component-token? v) → boolean?
v : any/c
procedure
(css-component-token-text token) → string?
token : css-component-token?
procedure
(css-component-token-span token) → (or/c css-source-span? #f)
token : css-component-token?
procedure
v : any/c
procedure
v : css-component-an-plus-b?
procedure
v : css-component-an-plus-b?
procedure
v : css-component-an-plus-b?
procedure
(css-component-an-plus-b-span v) → (or/c css-source-span? #f)
v : css-component-an-plus-b?
procedure
v : any/c
procedure
v : css-component-number?
procedure
v : css-component-number?
procedure
(css-component-number-span v) → (or/c css-source-span? #f)
v : css-component-number?
procedure
v : any/c
procedure
v : css-component-percentage?
procedure
v : css-component-percentage?
procedure
(css-component-percentage-span v) → (or/c css-source-span? #f)
v : css-component-percentage?
procedure
v : any/c
procedure
v : css-component-dimension?
procedure
v : css-component-dimension?
procedure
v : css-component-dimension?
procedure
(css-component-dimension-span v) → (or/c css-source-span? #f)
v : css-component-dimension?
procedure
v : any/c
procedure
v : css-component-string?
procedure
v : css-component-string?
procedure
(css-component-string-span v) → (or/c css-source-span? #f)
v : css-component-string?
procedure
(css-component-hash? v) → boolean?
v : any/c
procedure
v : css-component-hash?
procedure
v : css-component-hash?
procedure
(css-component-hash-span v) → (or/c css-source-span? #f)
v : css-component-hash?
procedure
(css-component-url? v) → boolean?
v : any/c
procedure
v : css-component-url?
procedure
v : css-component-url?
procedure
(css-component-url-span v) → (or/c css-source-span? #f)
v : css-component-url?
procedure
v : any/c
procedure
v : css-component-function?
procedure
v : css-component-function?
procedure
v : css-component-function?
procedure
(css-component-function-span v) → (or/c css-source-span? #f)
v : css-component-function?
procedure
(css-component-block? v) → boolean?
v : any/c
procedure
v : css-component-block?
procedure
v : css-component-block?
procedure
v : css-component-block?
procedure
(css-component-block-span v) → (or/c css-source-span? #f)
v : css-component-block?
1.11.4 Query And Recovery Reference
procedure
(css-flatten-rules stylesheet)
→ (listof (or/c css-style-rule? css-at-rule?)) stylesheet : css-stylesheet?
procedure
(css-find-rules-by-selector-group stylesheet selector-group) → (listof css-style-rule?) stylesheet : css-stylesheet? selector-group : string?
The search preserves source order and flattens nested rule-bearing at-rules the same way as css-flatten-rules.
procedure
(css-find-rules-by-raw-selector stylesheet raw-selector) → (listof css-style-rule?) stylesheet : css-stylesheet? raw-selector : string?
The search preserves source order and uses the same nested-rule flattening as css-flatten-rules.
procedure
(css-find-declarations-in-selector-group stylesheet selector-group [ property-name]) → (listof css-declaration?) stylesheet : css-stylesheet? selector-group : string? property-name : (or/c string? #f) = #f
The result preserves source order. When property-name is provided, the result is filtered case-insensitively by property name.
procedure
(css-find-declarations-in-selector-groups stylesheet selector-groups [ property-name]) → (listof css-declaration?) stylesheet : css-stylesheet? selector-groups : (listof string?) property-name : (or/c string? #f) = #f
The result preserves source order and flattens nested rule-bearing at-rules the same way as css-flatten-rules. Each matching rule contributes its declarations at most once, even if it matches more than one requested selector group. When property-name is provided, the result is filtered case-insensitively by property name.
procedure
(css-collect-custom-properties-in-selector-group stylesheet selector-group) → (hash/c string? string?) stylesheet : css-stylesheet? selector-group : string?
Declarations are processed in source order, and later declarations override earlier ones in the returned hash.
procedure
(css-collect-custom-properties-in-selector-groups stylesheet selector-groups) → (hash/c string? string?) stylesheet : css-stylesheet? selector-groups : (listof string?)
Declarations are processed in source order, and later declarations override earlier ones in the returned hash. Nested rule-bearing at-rules are flattened the same way as css-flatten-rules, and each matching rule is processed at most once even if it matches more than one requested selector group.
procedure
(css-compute-style-for-selector-group stylesheet selector-group [ #:resolve-vars? resolve-vars? #:defaults defaults #:trace? trace?])
→
(or/c (hash/c string? string?) (values/c (hash/c string? string?) css-compute-style-trace?)) stylesheet : css-stylesheet? selector-group : string? resolve-vars? : boolean? = #f defaults : (or/c (hash/c string? string?) #f) = #f trace? : boolean? = #f
Matching uses exact selector-group text only. The helper flattens nested rule-bearing at-rules the same way as css-flatten-rules, considers the declarations from matching rules in source order, and picks winners by !important, then selector specificity, then later source order.
The result is a hash from normalized property name to raw declaration value. Standard property names are normalized to lowercase. Custom properties are not included in this result; use css-compute-custom-properties-for-selector-group for the custom property environment.
This reduced computed-style layer also expands a small explicit shorthand set: border, the four side-specific border-* shorthands, padding, and margin. Shorthand declarations generate synthetic longhand candidates that participate in the same winner-selection pipeline as authored longhands, so a later authored longhand can still override one side from an earlier shorthand.
When all four border side values agree, the returned hash also exposes the shared aggregate property for border-width, border-style, or border-color. Otherwise those aggregate keys are omitted instead of being lossily reconstructed.
When resolve-vars? is true, var(...) references are resolved against computed custom properties for the same selector-group target and then against defaults. Unresolved references are left intact.
When trace? is true, the function returns two values: the computed hash and a css-compute-style-trace? struct.
procedure
(css-compute-custom-properties-for-selector-group stylesheet selector-group [ #:defaults defaults #:resolve-vars? resolve-vars? #:trace? trace?])
→
(or/c (hash/c string? string?) (values/c (hash/c string? string?) css-compute-style-trace?)) stylesheet : css-stylesheet? selector-group : string? defaults : (or/c (hash/c string? string?) #f) = #f resolve-vars? : boolean? = #f trace? : boolean? = #f
Winner selection follows the same rules as css-compute-style-for-selector-group: !important, then selector specificity, then later source order.
When resolve-vars? is true, custom-property values are resolved against other computed custom properties and then defaults. Cycles do not raise errors; cyclical values are left in their raw unresolved form. The returned hash contains those final resolved values directly, so downstream tooling does not need to run a second custom-property resolver for ordinary exact-target use cases.
When trace? is true, the function returns two values: the computed hash and a css-compute-style-trace? struct.
procedure
v : any/c
procedure
trace : css-compute-style-trace?
procedure
→ (listof css-compute-matched-rule?) trace : css-compute-style-trace?
procedure
→ (listof css-compute-property-result?) trace : css-compute-style-trace?
procedure
→ (listof css-compute-property-result?) trace : css-compute-style-trace?
procedure
→ (listof css-compute-var-resolution?) trace : css-compute-style-trace?
procedure
v : any/c
procedure
(css-compute-matched-rule-selector-group matched-rule)
→ string? matched-rule : css-compute-matched-rule?
procedure
(css-compute-matched-rule-specificity matched-rule)
→
(list/c exact-nonnegative-integer? exact-nonnegative-integer? exact-nonnegative-integer?) matched-rule : css-compute-matched-rule?
procedure
(css-compute-matched-rule-source-order matched-rule)
→ exact-nonnegative-integer? matched-rule : css-compute-matched-rule?
procedure
(css-compute-matched-rule-rule matched-rule) → css-style-rule?
matched-rule : css-compute-matched-rule?
procedure
v : any/c
procedure
(css-compute-property-result-name result) → string?
result : css-compute-property-result?
procedure
→ (listof css-compute-candidate?) result : css-compute-property-result?
procedure
(css-compute-property-result-winner result)
→ css-compute-candidate? result : css-compute-property-result?
procedure
v : any/c
procedure
(css-compute-candidate-name candidate) → string?
candidate : css-compute-candidate?
procedure
(css-compute-candidate-value candidate) → string?
candidate : css-compute-candidate?
procedure
(css-compute-candidate-important? candidate) → boolean?
candidate : css-compute-candidate?
procedure
(css-compute-candidate-specificity candidate)
→
(list/c exact-nonnegative-integer? exact-nonnegative-integer? exact-nonnegative-integer?) candidate : css-compute-candidate?
procedure
(css-compute-candidate-source-order candidate)
→ exact-nonnegative-integer? candidate : css-compute-candidate?
procedure
(css-compute-candidate-declaration candidate)
→ css-declaration? candidate : css-compute-candidate?
procedure
(css-compute-candidate-matched-rule candidate)
→ css-compute-matched-rule? candidate : css-compute-candidate?
procedure
(css-compute-candidate-source-name candidate) → string?
candidate : css-compute-candidate?
If this differs from (css-compute-candidate-name candidate), then the candidate came from shorthand expansion rather than from an authored longhand.
procedure
v : any/c
procedure
(css-compute-var-resolution-name resolution) → string?
resolution : css-compute-var-resolution?
procedure
(css-compute-var-resolution-raw-value resolution) → string?
resolution : css-compute-var-resolution?
procedure
(css-compute-var-resolution-resolved-value resolution)
→ string? resolution : css-compute-var-resolution?
procedure
(css-compute-var-resolution-references resolution)
→ (listof string?) resolution : css-compute-var-resolution?
procedure
(css-compute-var-resolution-cycle? resolution) → boolean?
resolution : css-compute-var-resolution?
procedure
(css-find-declarations stylesheet name)
→ (listof css-declaration?) stylesheet : css-stylesheet? name : string?
procedure
(css-query-selector stylesheet selector)
→ (listof css-style-rule?) stylesheet : css-stylesheet? selector : string?
procedure
(css-find-rules-by-pseudo stylesheet pseudo-name) → (listof css-style-rule?) stylesheet : css-stylesheet? pseudo-name : string?
procedure
(css-find-media-queries stylesheet) → (listof css-media-query?)
stylesheet : css-stylesheet?
procedure
(css-find-supports-features stylesheet [ name]) → (listof css-supports-feature?) stylesheet : css-stylesheet? name : (or/c string? #f) = #f
When name is provided, the result is filtered case-insensitively by feature name.
procedure
(css-recovery-nodes stylesheet) → (listof css-recovery?)
stylesheet : css-stylesheet?
procedure
(css-has-recovery? stylesheet) → boolean?
stylesheet : css-stylesheet?
procedure
(css-recovery-summary stylesheet)
→ (listof (cons/c symbol? exact-nonnegative-integer?)) stylesheet : css-stylesheet?
1.11.5 Error Reference
The parser uses a CSS-specific exception type rather than generic contract or read errors for parser failures.
procedure
(exn:fail:css? v) → boolean?
v : any/c
procedure
(exn:fail:css-source e) → any/c
e : exn:fail:css?
procedure
(exn:fail:css-detail e) → any/c
e : exn:fail:css?
1.11.6 Parser Procedure Reference
procedure
(css-parser? v) → boolean?
v : any/c