Skip to content

Commit b1a6dfe

Browse files
committed
Fix combo rule generation
1 parent 1a4ebf7 commit b1a6dfe

File tree

7 files changed

+34
-37
lines changed

7 files changed

+34
-37
lines changed

lib/CSS/Specification/Actions.rakumod

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ unit class CSS::Specification::Actions;
22

33
use Method::Also;
44

5-
# these actions translate a CSS property specification to Raku
6-
# rules or actions.
5+
# these actions translate a CSS property specification to an
6+
# intermediate AST
77
has %.rule-refs is rw;
88
has %.props is rw;
99
has %.rules is rw;
@@ -93,14 +93,9 @@ method occurs:sym<maybe>($/) { make '?' }
9393
method occurs:sym<once-plus>($/) { make '+' }
9494
method occurs:sym<zero-plus>($/) { make '*' }
9595
method occurs:sym<list>($/) {
96-
with $<range> {
97-
given .ast {
98-
make [.[0], .[1], ',' ];
99-
}
100-
}
101-
else {
102-
make ',';
103-
}
96+
make $<range>
97+
?? $<range>.ast.clone.append: ','
98+
!! ','
10499
}
105100
method occurs:sym<range>($/) { make $<range>.ast }
106101
method range($/) {

lib/CSS/Specification/Compiler/Grammars.rakumod

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ sub alt(@choices) is export {
151151
RakuAST::Regex::Alternation.new: |@choices;
152152
}
153153

154-
multi sub seq(@seq) is export { RakuAST::Regex::Sequence.new: |@seq }
154+
multi sub seq(@seq) is export {
155+
RakuAST::Regex::Sequence.new(|@seq);
156+
}
155157
multi sub seq($seq) is export { $seq }
156158

157159
multi sub seq-alt(@seq) is export { RakuAST::Regex::SequentialAlternation.new: |@seq }
@@ -176,21 +178,31 @@ sub call(Str:D $id, :@args) is export {
176178
RakuAST::Call::Method.new: :$name, :$args;
177179
}
178180

179-
sub postfix($operand, $postfix) {
181+
sub prefix($operand, Str:D $op) {
182+
my RakuAST::Prefix $prefix .= new($op);
183+
RakuAST::ApplyPrefix.new(
184+
:$operand, :$prefix
185+
)
186+
}
187+
188+
multi sub postfix($operand, Str:D $operator) {
189+
$operand.&postfix: RakuAST::Postfix.new(:$operator);
190+
}
191+
192+
multi sub postfix($operand, $postfix) {
180193
RakuAST::ApplyPostfix.new(
181194
:$operand, :$postfix
182195
)
183196
}
184197

198+
185199
sub seen(Int:D $id) is export {
186200
my RakuAST::Postcircumfix $op = $id.&arg.&array-index;
187201
my RakuAST::Var $operand = '@S'.&lexical;
188202
my RakuAST::Block $block .= new(
189203
body => RakuAST::Blockoid.new(
190204
statements(
191-
expression $operand.&postfix($op).&postfix(
192-
RakuAST::Postfix.new(operator => "++")
193-
)
205+
expression $operand.&postfix($op).&postfix('++').&prefix('!')
194206
)
195207
)
196208
);

lib/CSS/Specification/Defs.rakumod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
unit grammar CSS::Specification::Defs;
22

3-
warn "this grammar is deprecated. Please use CSS::Specification::Runtime::BaseActions";
3+
## warn "this grammar is deprecated. Please use CSS::Specification::Runtime::Grammar";
44

55
use CSS::Specification::Runtime::Grammar;
66
also is CSS::Specification::Runtime::Grammar;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
unit class CSS::Specification::Defs::Actions;
22

3-
warn "this class is deprecated. Please use CSS::Runtime::Actions";
3+
# warn "this class is deprecated. Please use CSS::Specification::Runtime::Actions";
44

5-
use CSS::Specification::Runtime::BaseActions;
6-
also is CSS::Specification::Runtime::BaseActions;
5+
use CSS::Specification::Runtime::Actions;
6+
also is CSS::Specification::Runtime::Actions;

t/00compile.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ for (
106106
'spec' => {
107107
input => 'bold thin && <length>',
108108
ast => :required[:seq[:keywords["bold"], :keywords["thin"]], :rule("length")],
109-
deparse => "[:my \@S\n; bold \& <keyw> thin \& <keyw> <!\{\n \@S[0]++\n}>| <length><!\{\n \@S[1]++\n}>]** 2",
109+
deparse => "[:my \@S\n; bold \& <keyw> thin \& <keyw> <!\{\n !\@S[0]++\n}>| <length><!\{\n !\@S[1]++\n}>]** 2",
110110
rule-refs => ['length'],
111111
},
112112
'spec' => {
113113
input => 'bold || thin && <length>',
114114
ast => :combo[:keywords["bold"], :required[:keywords["thin"], :rule("length")]],
115-
deparse => "[:my \@S\n; bold \& <keyw><!\{\n \@S[0]++\n}>| [:my \@S\n; thin \& <keyw><!\{\n \@S[0]++\n}>| <length><!\{\n \@S[1]++\n}>]** 2<!\{\n \@S[1]++\n}>]+",
115+
deparse => "[:my \@S\n; bold \& <keyw><!\{\n !\@S[0]++\n}>| [:my \@S\n; thin \& <keyw><!\{\n !\@S[0]++\n}>| <length><!\{\n !\@S[1]++\n}>]** 2<!\{\n !\@S[1]++\n}>]+",
116116
rule-refs => ['length'],
117117
},
118118
'property-spec' => {

t/build.t

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,10 @@ use CSS::Specification::Compiler;
55
use lib 't';
66
use experimental :rakuast;
77

8-
sub capture($code, $output-path) {
9-
my $*OUT = open $output-path, :w;
10-
$code();
11-
$*OUT.close;
12-
$output-path;
13-
}
14-
158
my @base-id = qw<Test CSS Aural Spec>;
16-
my $base-name = @base-id.join: '::';
179
my @actions-id = @base-id.Slip, 'Actions';
18-
my $actions-name = @actions-id.join: '::';
1910
my @role-id = @base-id.Slip, 'Interface';
2011
my @grammar-id = @base-id.Slip, 'Grammar';
21-
my $grammar-name = @grammar-id.join: '::';
2212

2313
my $input-path = $*SPEC.catfile('examples', 'css21-aural.txt');
2414

t/lib/Test/CSS/Aural/Spec/Grammar.rakumod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ unit grammar Test::CSS::Aural::Spec::Grammar;
22
#| azimuth: <angle> | [[ left-side | far-left | left | center-left | center | center-right | right | far-right | right-side ] || behind ] | leftwards | rightwards
33
rule decl:sym<azimuth> { :i (azimuth) ":" <val(/<expr=.expr-azimuth> /, &?ROUTINE.WHY)> }
44
rule expr-azimuth { :i <angle> || [[:my @S; [["left-side" | "far-left" | left | "center-left" | center | "center-right" | right | "far-right" | "right-side" ]& <keyw>]<!{
5-
@S[0]++
5+
!@S[0]++
66
}>| behind & <keyw><!{
7-
@S[1]++
7+
!@S[1]++
88
}>]+] || [leftwards | rightwards ]& <keyw> }
99
#| cue-after: <uri> | none
1010
rule decl:sym<cue-after> { :i ("cue-after") ":" <val(/<expr=.expr-cue-after> /, &?ROUTINE.WHY)> }
@@ -15,9 +15,9 @@ rule expr-cue-before { :i <uri> || none & <keyw> }
1515
#| cue: [ 'cue-before' || 'cue-after' ]
1616
rule decl:sym<cue> { :i (cue) ":" <val(/<expr=.expr-cue> /, &?ROUTINE.WHY)> }
1717
rule expr-cue { :i [[:my @S; <expr-cue-before><!{
18-
@S[0]++
18+
!@S[0]++
1919
}>| <expr-cue-after><!{
20-
@S[1]++
20+
!@S[1]++
2121
}>]+] }
2222
#| elevation: <angle> | below | level | above | higher | lower
2323
rule decl:sym<elevation> { :i (elevation) ":" <val(/<expr=.expr-elevation> /, &?ROUTINE.WHY)> }
@@ -40,9 +40,9 @@ rule expr-pitch { :i <frequency> || ["x-low" | low | medium | high | "x-high" ]&
4040
#| play-during: <uri> [ mix || repeat ]? | auto | none
4141
rule decl:sym<play-during> { :i ("play-during") ":" <val(/<expr=.expr-play-during> /, &?ROUTINE.WHY)> }
4242
rule expr-play-during { :i <uri> [[:my @S; mix & <keyw><!{
43-
@S[0]++
43+
!@S[0]++
4444
}>| repeat & <keyw><!{
45-
@S[1]++
45+
!@S[1]++
4646
}>]+]? || [auto | none ]& <keyw> }
4747
#| richness: <number>
4848
rule decl:sym<richness> { :i (richness) ":" <val(/<expr=.expr-richness> /, &?ROUTINE.WHY)> }

0 commit comments

Comments
 (0)