Skip to content

Commit 5a05967

Browse files
committed
Adding actions body
1 parent ac1f8a4 commit 5a05967

File tree

6 files changed

+87
-22
lines changed

6 files changed

+87
-22
lines changed

lib/CSS/Specification/Build.rakumod

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,6 @@ module CSS::Specification::Build {
216216
sub generate-raku-actions(@defs, %references) {
217217

218218
for @defs -> $def {
219-
220-
my $synopsis = $def<synopsis>;
221-
222219
with $def<props> -> @props {
223220
for @props -> $prop {
224221

lib/CSS/Specification/Compiler/RakuAST.rakumod

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,17 @@ sub param(Str:D $name) is export {
99
target => RakuAST::ParameterTarget::Var.new(:$name)
1010
)
1111
}
12+
13+
sub expression($expression) is export {
14+
RakuAST::Statement::Expression.new: :$expression;
15+
}
16+
17+
proto statements($) is export {*}
18+
19+
multi sub statements(@exprs) {
20+
RakuAST::StatementList.new(|@exprs);
21+
}
22+
multi sub statements($expr) {
23+
RakuAST::StatementList.new($expr);
24+
}
25+

lib/CSS/Specification/Compiler/RakuAST/Actions.rakumod

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,67 @@ method actions { ... }
88
method defs { ... }
99

1010
method build-actions(@actions-id) {
11-
# stub
11+
my RakuAST::Method @methods = self!actions-methods;
12+
my RakuAST::Statement::Expression @expressions = @methods.map(&expression);
13+
my RakuAST::Blockoid $body .= new: @expressions.&statements;
1214
my RakuAST::Name $name .= from-identifier-parts(|@actions-id);
1315
RakuAST::Class.new(
1416
:$name,
1517
:scope<unit>,
18+
:$body,
1619
);
1720
}
21+
22+
sub build-action(Str $id) {
23+
RakuAST::Blockoid.new(
24+
RakuAST::Call::Name::WithoutParentheses.new(
25+
name => RakuAST::Name.from-identifier("make"),
26+
args => RakuAST::ArgList.new(
27+
RakuAST::ApplyPostfix.new(
28+
operand => RakuAST::Var::Attribute::Public.new(
29+
name => "\$.build"
30+
),
31+
postfix => RakuAST::Call::Method.new(
32+
name => RakuAST::Name.from-identifier($id),
33+
args => RakuAST::ArgList.new(
34+
RakuAST::Var::Lexical.new("\$/")
35+
)
36+
)
37+
)
38+
)
39+
).&expression.&statements
40+
);
41+
}
42+
43+
44+
45+
method !actions-methods {
46+
my RakuAST::Method @methods;
47+
my %references = $.actions.rule-refs;
48+
49+
my RakuAST::Signature $signature .= new(
50+
:parameters( '$/'.&param )
51+
);
52+
53+
my $expr-body = 'list'.&build-action;
54+
my $rule-body = 'rule'.&build-action;
55+
56+
for @.defs -> $def {
57+
with $def<props> -> @props {
58+
for @props -> $prop {
59+
my $expr = 'expr-' ~ $prop;
60+
if %references{$expr}:delete {
61+
my RakuAST::Name $name = $expr.&name;
62+
@methods.push: RakuAST::Method.new: :$name, :$signature, body => $expr-body;
63+
}
64+
}
65+
}
66+
else {
67+
my $rule = $def<rule>;
68+
my RakuAST::Name $name = $rule.&name;
69+
@methods.push: RakuAST::Method.new: :$name, :$signature, body => $rule-body;
70+
}
71+
}
72+
73+
@methods;
74+
}

lib/CSS/Specification/Compiler/RakuAST/Grammars.rakumod

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@ sub rule(RakuAST::Name:D :$name!, RakuAST::Regex:D :$body!) {
2020
)
2121
}
2222

23-
multi sub statements(@exprs) {
24-
RakuAST::StatementList.new(|@exprs);
25-
}
26-
multi sub statements($expr) {
27-
RakuAST::StatementList.new($expr);
28-
}
29-
30-
sub expression($expression) {
31-
RakuAST::Statement::Expression.new: :$expression;
32-
}
33-
3423
sub property-decl(Str:D $prop-name) {
3524
my RakuAST::Name $name = "decl:sym<$prop-name>".&name;
3625
rule(

lib/CSS/Specification/Compiler/RakuAST/Roles.rakumod

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ method actions { ... }
88

99
method build-role(@role-id) {
1010
my RakuAST::Method @methods = self!interface-methods;
11-
my @expressions = @methods.map(-> $expression { RakuAST::Statement::Expression.new: :$expression });
12-
my RakuAST::Blockoid $body .= new: RakuAST::StatementList.new(|@expressions);
11+
my RakuAST::Statement::Expression @expressions = @methods.map(&expression);
12+
my RakuAST::Blockoid $body .= new: @expressions.&statements;
1313
my RakuAST::Name $name .= from-identifier-parts(|@role-id);
1414

1515
RakuAST::Role.new(
@@ -32,11 +32,7 @@ method !interface-methods {
3232
);
3333

3434
my RakuAST::Blockoid $body .= new(
35-
RakuAST::StatementList.new(
36-
RakuAST::Statement::Expression.new(
37-
expression => RakuAST::Stub::Fail.new
38-
)
39-
)
35+
RakuAST::Stub::Fail.new.&expression.&statements
4036
);
4137

4238
my Str @stubs = %unresolved.keys.sort;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
11
unit class Test::CSS::Aural::Spec::ActionsAST;
2+
method expr-cue-after ($/) {
3+
make $.build.list($/)
4+
}
5+
method expr-cue-before ($/) {
6+
make $.build.list($/)
7+
}
8+
method generic-voice ($/) {
9+
make $.build.rule($/)
10+
}
11+
method specific-voice ($/) {
12+
make $.build.rule($/)
13+
}

0 commit comments

Comments
 (0)