Skip to content

Commit fe6ccf1

Browse files
committed
Add CSS::Grammar::Defs
1 parent 419b754 commit fe6ccf1

File tree

5 files changed

+100
-85
lines changed

5 files changed

+100
-85
lines changed

Changes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Release 0.3.5 2021-01-03
2+
- Add CSS::Grammar::Defs
13
Release 0.3.4 2020-02-11
24
- rename sources *.pm -> *.rakumod
35
- moved repo p6-css/CSS-Grammar-p6 -> css-raku/CSS-Grammar-raku

META6.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"CSS::Grammar::CSS21": "lib/CSS/Grammar/CSS21.rakumod",
1616
"CSS::Grammar::CSS3": "lib/CSS/Grammar/CSS3.rakumod",
1717
"CSS::Grammar::Core": "lib/CSS/Grammar.rakumod",
18+
"CSS::Grammar::Defs": "lib/CSS/Grammar/Defs.rakumod",
1819
"CSS::Grammar::Test": "lib/CSS/Grammar/Test.rakumod"
1920
},
2021
"source-url": "git://github.com/css-raku/CSS-Grammar-raku.git",

lib/CSS/Grammar/AST.rakumod

Lines changed: 8 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,14 @@ use v6;
22

33
class CSS::Grammar::AST {
44

5-
# These tables map AST types to standard W3C component definitions.
6-
7-
# CSS object definitions based on http://dev.w3.org/csswg/cssom/
8-
# for example 6.4.1 CSSRuleList maps to CSSObject::RuleList
9-
our Str enum CSSObject is export(:CSSObject) «
10-
:AtRule<at-rule>
11-
:Priority<prio>
12-
:RuleSet<ruleset>
13-
:RuleList<rule-list>
14-
:StyleDeclaration<style>
15-
:StyleRule<style-rule>
16-
:StyleSheet<stylesheet>
17-
»;
18-
19-
# CSS value types based on http://dev.w3.org/csswg/cssom-values/
20-
# for example 3.3 CSSStyleDeclarationValue maps to CSSValue::StyleDeclaration
21-
our Str enum CSSValue is export(:CSSValue) «
22-
:ColorComponent<color>
23-
:Component<value>
24-
:IdentifierComponent<ident>
25-
:KeywordComponent<keyw>
26-
:LengthComponent<length>
27-
:Map<map>
28-
:PercentageComponent<percent>
29-
:Property<property>
30-
:PropertyList<declarations>
31-
:StringComponent<string>
32-
:URLComponent<url>
33-
34-
:NameComponent<name>
35-
:NumberComponent<num>
36-
:IntegerComponent<int>
37-
:AngleComponent<angle>
38-
:FrequencyComponent<freq>
39-
:FunctionComponent<func>
40-
:ResolutionComponent<resolution>
41-
:TimeComponent<time>
42-
:QnameComponent<qname>
43-
:OtherUnitComponent<units>
44-
:NamespacePrefixComponent<ns-prefix>
45-
:ElementNameComponent<element-name>
46-
:OperatorComponent<op>
47-
:ExpressionComponent<expr>
48-
:ArgumentListComponent<args>
49-
:AtKeywordComponent<at-keyw>
50-
:UnicodeRangeComponent<unicode-range>
51-
»;
52-
53-
our Str enum CSSSelector is export(:CSSSelector) «
54-
:AttributeSelector<attrib>
55-
:Class<class>
56-
:Id<id>
57-
:MediaList<media-list>
58-
:MediaQuery<media-query>
59-
:PseudoClass<pseudo-class>
60-
:PseudoElement<pseudo-elem>
61-
:PseudoFunction<pseudo-func>
62-
:SelectorList<selectors>
63-
:Selector<selector>
64-
:SelectorComponent<simple-selector>
65-
»;
66-
67-
# an enumerated list of all unit types for validation purposes.
68-
# Adapted from the out-of-date http://www.w3.org/TR/DOM-Level-2-Style/css.html
69-
70-
our Str enum CSSUnits is export(:CSSUnits) «
71-
:ems<length> :exs<length> :px<length> :cm<length> :mm<length> :in<length> :pt<length> :pc<length>
72-
:em<length> :ex<length> :rem<length> :ch<length> :vw<length> :vh<length> :vmin<length> :vmax<length>
73-
:dpi<resolution> :dpcm<resolution> :dppx<resolution>
74-
:deg<angle> :rad<angle> :grad<angle> :turn<angle>
75-
:ms<time> :s<time>
76-
:hz<freq> :khz<freq>
77-
:rgb<color> :rgba<color> :hsl<color> :hsla<color>
78-
»;
79-
80-
# from http://dev.w3.org/csswg/cssom-view/
81-
our Str enum CSSTrait is export(:CSSTrait) «:Box<box>»;
5+
use CSS::Grammar::Defs :CSSObject, :CSSValue, :CSSSelector, :CSSUnits, :CSSTrait;
6+
7+
# re-exports (may be deprecated)
8+
constant css-obj is export(:CSSObject) = CSSObject;
9+
constant css-val is export(:CSSObject) = CSSValue;
10+
constant css-sel is export(:CSSSelector) = CSSValue;
11+
constant css-units is export(:CSSUnits) = CSSUnits;
12+
constant css-trait is export(:CSSTrait) = CSSTrait;
8213

8314
BEGIN our %known-type =
8415
%( CSSObject.enums.invert ),

lib/CSS/Grammar/Actions.rakumod

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ class X::CSS::Ignored is Exception {
3333
method Str {$.message}
3434
}
3535

36-
use CSS::Grammar::AST :CSSObject, :CSSValue, :CSSUnits, :CSSSelector;
36+
use CSS::Grammar::AST;
3737

3838
class CSS::Grammar::Actions
3939
is CSS::Grammar::AST {
4040

41+
use CSS::Grammar::Defs :CSSObject, :CSSValue, :CSSUnits, :CSSSelector;
42+
4143
# variable encoding - not yet supported
4244
has Str $.encoding is rw = 'UTF-8';
4345
has Bool $.lax = False;
@@ -90,8 +92,7 @@ class CSS::Grammar::Actions
9092
method any($/) {}
9193

9294
method dropped-decl:sym<forward-compat>($/) {
93-
$.warning('dropping term', .Str) with $0;
94-
$.warning('dropping term', .Str) with $1;
95+
$.warning('dropping term', .Str) with $0 // $1;
9596
$.warning('dropping declaration', .ast)
9697
with $<property>;
9798
}
@@ -140,11 +141,11 @@ class CSS::Grammar::Actions
140141
my Str $name = [~] flat @<nmchar>.map( *.ast);
141142
make $.token( $name, :type(CSSValue::NameComponent));
142143
}
143-
method num($/) { my $num = $/.Rat;
144-
make $.token( $num % 1
145-
?? $num
146-
!! $num.Int, :type(CSSValue::NumberComponent))
147-
}
144+
method num($/) {
145+
my $num = $/.Rat;
146+
$num .= Int if $num %% 1;
147+
make $.token($num, :type(CSSValue::NumberComponent));
148+
}
148149
method uint($/) { make $/.Int }
149150
method op($/) { make $/.lc }
150151

lib/CSS/Grammar/Defs.rakumod

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
unit module CSS::Grammar::Defs;
2+
3+
# These tables map AST types to standard W3C component definitions.
4+
5+
# CSS object definitions based on http://dev.w3.org/csswg/cssom/
6+
# for example 6.4.1 CSSRuleList maps to CSSObject::RuleList
7+
our Str enum CSSObject is export(:CSSObject) «
8+
:AtRule<at-rule>
9+
:Priority<prio>
10+
:RuleSet<ruleset>
11+
:RuleList<rule-list>
12+
:StyleDeclaration<style>
13+
:StyleRule<style-rule>
14+
:StyleSheet<stylesheet>
15+
»;
16+
17+
# CSS value types based on http://dev.w3.org/csswg/cssom-values/
18+
# for example 3.3 CSSStyleDeclarationValue maps to CSSValue::StyleDeclaration
19+
our Str enum CSSValue is export(:CSSValue) «
20+
:ColorComponent<color>
21+
:Component<value>
22+
:IdentifierComponent<ident>
23+
:KeywordComponent<keyw>
24+
:LengthComponent<length>
25+
:Map<map>
26+
:PercentageComponent<percent>
27+
:Property<property>
28+
:PropertyList<declarations>
29+
:StringComponent<string>
30+
:URLComponent<url>
31+
32+
:NameComponent<name>
33+
:NumberComponent<num>
34+
:IntegerComponent<int>
35+
:AngleComponent<angle>
36+
:FrequencyComponent<freq>
37+
:FunctionComponent<func>
38+
:ResolutionComponent<resolution>
39+
:TimeComponent<time>
40+
:QnameComponent<qname>
41+
:OtherUnitComponent<units>
42+
:NamespacePrefixComponent<ns-prefix>
43+
:ElementNameComponent<element-name>
44+
:OperatorComponent<op>
45+
:ExpressionComponent<expr>
46+
:ArgumentListComponent<args>
47+
:AtKeywordComponent<at-keyw>
48+
:UnicodeRangeComponent<unicode-range>
49+
»;
50+
51+
our Str enum CSSSelector is export(:CSSSelector) «
52+
:AttributeSelector<attrib>
53+
:Class<class>
54+
:Id<id>
55+
:MediaList<media-list>
56+
:MediaQuery<media-query>
57+
:PseudoClass<pseudo-class>
58+
:PseudoElement<pseudo-elem>
59+
:PseudoFunction<pseudo-func>
60+
:SelectorList<selectors>
61+
:Selector<selector>
62+
:SelectorComponent<simple-selector>
63+
»;
64+
65+
# an enumerated list of all unit types for validation purposes.
66+
# Adapted from the out-of-date http://www.w3.org/TR/DOM-Level-2-Style/css.html
67+
68+
our Str enum CSSUnits is export(:CSSUnits) «
69+
:ems<length> :exs<length> :px<length> :cm<length> :mm<length> :in<length> :pt<length> :pc<length>
70+
:em<length> :ex<length> :rem<length> :ch<length> :vw<length> :vh<length> :vmin<length> :vmax<length>
71+
:dpi<resolution> :dpcm<resolution> :dppx<resolution>
72+
:deg<angle> :rad<angle> :grad<angle> :turn<angle>
73+
:ms<time> :s<time>
74+
:hz<freq> :khz<freq>
75+
:rgb<color> :rgba<color> :hsl<color> :hsla<color>
76+
»;
77+
78+
# from http://dev.w3.org/csswg/cssom-view/
79+
our Str enum CSSTrait is export(:CSSTrait) «:Box<box>»;
80+

0 commit comments

Comments
 (0)