Rand Stats



[Raku CSS Project] / [CSS-Grammar Module]


CSS::Grammar is a set of Raku grammars for the W3C family of CSS standards.

It aims to implement a reasonable portion of the base grammars with an emphasis on:

This module performs generic parsing of declarations in style-sheet rules.


Base Grammars

The CSS 3.0 core grammar, CSS::Grammar::CSS3, is based on CSS2.1; it understands:

Parser Actions

CSS::Grammar::Actions can be used with in conjunction with any of the CSS1 CSS21 or CSS3 base grammars. It produces an abstract syntax tree (AST), plus warnings for any unexpected input.

use v6;
use CSS::Grammar::CSS3;
use CSS::Grammar::Actions;

my $css = 'H1 { color: blue; gunk }';

my $actions =  CSS::Grammar::Actions.new;
my $p = CSS::Grammar::CSS3.parse($css, :actions($actions));
.note for $actions.warnings;
say "H1: " ~ $p.ast<stylesheet>[0]<ruleset><selectors>;
# output:
# dropping term: gunk
# H1: selector    simple-selector qname   element-name    h1

Actions Options


You can use the Raku zef module installer to test and install CSS::Grammar:

% zef install CSS::Grammar

To try parsing some content:

% raku -MCSS::Grammar::CSS3 -e"say CSS::Grammar::CSS3.parse('H1 {color:blue}')"

See Also


This module been built from the W3C CSS Specifications. In particular: