Skip to content

Commit 33c32fa

Browse files
committed
refactor CSS::Grammar::AST from base-class to delegate of CSS::Grammar::Actions
1 parent 12fcca8 commit 33c32fa

File tree

3 files changed

+102
-89
lines changed

3 files changed

+102
-89
lines changed

Changes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{{$NEXT}}
2+
- CSS::Grammar::Actions no long inherits from CSS::Grammar::AST.
3+
Be more explict and invoke a build() method when constructing
4+
nodes. e.g. `make $.build.node($/)` becomes `make $.node($/)`
5+
This seperation is more of a win in CSS::Module, which is mixing
6+
in a lot of grammars and classes.
27

38
0.3.8 2021-05-03T08:57:52+12:00
49
- Fix combining newlines (\r\n) being accepted as non-ascii #11

lib/CSS/Grammar/AST.rakumod

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ BEGIN our %known-type =
3030
$type = CSSUnits.enums{$type}
3131
if CSSUnits.enums{$type}:exists;
3232

33-
my ($raw-type, $_class) = $type.split(':');
33+
my $raw-type = $type.split(':').head;
3434
die "unknown type: '$raw-type'"
3535
unless %known-type{$raw-type}:exists;
3636

@@ -45,21 +45,21 @@ BEGIN our %known-type =
4545

4646
# unwrap Parcels
4747
my @l = $/.can('caps')
48-
?? ($/)
48+
?? $/
4949
!! $/.grep: *.defined;
5050

5151
for @l {
5252
for .caps -> $cap {
5353
my ($key, $value) = $cap.kv;
5454
next if $key eq '0';
5555
$key = $key.lc;
56-
my ($type, $_class) = $key.split(':');
56+
my $type = $key.split(':').head;
5757

58-
$value = $value.ast
58+
$value .= ast
5959
// next;
6060

6161
if substr($key, 0, 5) eq 'expr-' {
62-
$key = 'expr:' ~ substr($key, 5);
62+
$key.substr-rw(4,1) = ':';
6363
}
6464
elsif $value.isa(Pair) {
6565
($key, $value) = $value.kv;
@@ -86,7 +86,7 @@ BEGIN our %known-type =
8686

8787
# unwrap Parcels
8888
my @l = $/.can('caps')
89-
?? ($/)
89+
?? $/
9090
!! $/.grep: *.defined;
9191

9292
for @l {
@@ -95,13 +95,13 @@ BEGIN our %known-type =
9595
next if $key eq '0';
9696
$key = $key.lc;
9797

98-
my ($type, $_class) = $key.split(':');
98+
my $type = $key.split(':').head;
9999

100-
$value = $value.ast
100+
$value .= ast
101101
// next;
102102

103103
if substr($key, 0, 5) eq 'expr-' {
104-
$key = 'expr:' ~ substr($key, 5);
104+
$key.substr-rw(4,1) = ':';
105105
}
106106
elsif $value.isa(Pair) {
107107
($key, $value) = $value.kv;
@@ -117,4 +117,28 @@ BEGIN our %known-type =
117117
@terms;
118118
}
119119

120+
method at-rule($/) {
121+
my %terms = $.node($/);
122+
%terms{ CSSValue::AtKeywordComponent } //= $0.lc;
123+
return $.token( %terms, :type(CSSObject::AtRule));
124+
}
125+
126+
method func(Str:D $ident,
127+
$args,
128+
:$type = CSSValue::FunctionComponent,
129+
:$arg-type = CSSValue::ArgumentListComponent,
130+
|c --> Pair) {
131+
my %ast = $args.isa(List)
132+
?? ($arg-type => $args)
133+
!! $args;
134+
%ast ,= :$ident;
135+
$.token( %ast, :$type, |c );
136+
}
137+
138+
method pseudo-func( Str $ident, $/ --> Pair) {
139+
my $expr = $.list($/);
140+
my %ast = :$ident, :$expr;
141+
$.token( %ast, :type(CSSSelector::PseudoFunction) );
142+
}
143+
120144
}

0 commit comments

Comments
 (0)