Skip to content

Commit

Permalink
start stubbing Actions and Grammar ASTs
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Apr 14, 2024
1 parent b0da5d0 commit aab2f9d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
16 changes: 16 additions & 0 deletions lib/CSS/Compiler/RakuAST/Actions.rakumod
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
unit role CSS::Compiler::RakuAST::Actions;

use CSS::Compiler::RakuAST;

use experimental :rakuast;

method actions { ... }
method defs { ... }

method actions-package(@actions-id) {
# stub
my RakuAST::Name $name .= from-identifier-parts(|@actions-id);
RakuAST::Class.new(
:$name,
:scope<unit>,
);
}
30 changes: 11 additions & 19 deletions lib/CSS/Compiler/RakuAST/Grammars.rakumod
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
unit role CSS::Compiler::RakuAST::Grammars;

method actions { ... }
method defs { ... }

method actions-raku(@actions-id) {
my %references = $.actions.rule-refs;
use CSS::Compiler::RakuAST;

for @.defs -> $def {
use experimental :rakuast;

my $synopsis = $def<synopsis>;

with $def<props> -> @props {
for @props -> $prop {
method actions { ... }
method defs { ... }

say "method expr-{$prop}(\$/) \{ make \$.build.list(\$/) \}"
if %references{'expr-' ~ $prop}:exists;
}
}
else {
my $rule = $def<rule>;
say "method $rule\(\$/\) \{ make \$.build.rule(\$/) \}"
}
}
method grammar-package(@grammar-id) {
# stub
my RakuAST::Name $name .= from-identifier-parts(|@grammar-id);
RakuAST::Grammar.new(
:$name,
:scope<unit>,
);
}
2 changes: 1 addition & 1 deletion lib/CSS/Compiler/RakuAST/Roles.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use experimental :rakuast;

method actions { ... }

method role-ast(@role-id) {
method role-package(@role-id) {
my RakuAST::Method @methods = self!interface-methods;
my @expression = @methods.map(-> $expression { RakuAST::Statement::Expression.new: :$expression });
my RakuAST::Blockoid $body .= new: RakuAST::StatementList.new(|@expression);
Expand Down
18 changes: 14 additions & 4 deletions t/build.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ sub capture($code, $output-path) {

my @base-id = qw<Test CSS Aural Spec>;
my $base-name = @base-id.join: '::';
my $grammar-name = $base-name ~ '::Grammar';
my $actions-name = $base-name ~ '::Actions';
my @actions-id = @base-id.Slip, 'Actions';
my $actions-name = @actions-id.join: '::';
my @role-id = @base-id.Slip, 'Interface';
my @grammar-id = @base-id.Slip, 'Grammar';
my $grammar-name = @grammar-id.join: '::';

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

Expand All @@ -33,14 +35,22 @@ capture({
}, 't/lib/Test/CSS/Aural/Spec/Grammar.rakumod');
lives-ok {require ::($grammar-name)}, "$grammar-name compilation";

my RakuAST::Package $grammar-pkg = $compiler.grammar-package(@grammar-id);

't/lib/Test/CSS/Aural/Spec/GrammarAST.rakumod'.IO.spurt: $grammar-pkg.DEPARSE;

capture({
CSS::Specification::Build::generate( 'actions', $actions-name, :$input-path );
}, 't/lib/Test/CSS/Aural/Spec/Actions.rakumod');
lives-ok {require ::($actions-name)}, "$actions-name compilation";

my RakuAST::Package $actions-pkg = $compiler.actions-package(@actions-id);

't/lib/Test/CSS/Aural/Spec/ActionsAST.rakumod'.IO.spurt: $actions-pkg.DEPARSE;

my $role-name = @role-id.join: '::';
my RakuAST::Package $interface = $compiler.role-ast(@role-id);
't/lib/Test/CSS/Aural/Spec/Interface.rakumod'.IO.spurt: $interface.DEPARSE;
my RakuAST::Package $interface-pkg = $compiler.role-package(@role-id);
't/lib/Test/CSS/Aural/Spec/Interface.rakumod'.IO.spurt: $interface-pkg.DEPARSE;
lives-ok {require ::($role-name)}, "$role-name compilation";

dies-ok {require ::("Test::CSS::Aural::BadGrammar")}, 'grammar composition, unimplemented interface - dies';
Expand Down
1 change: 1 addition & 0 deletions t/lib/Test/CSS/Aural/Spec/ActionsAST.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unit class Test::CSS::Aural::Spec::Actions;
1 change: 1 addition & 0 deletions t/lib/Test/CSS/Aural/Spec/GrammarAST.rakumod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
unit grammar Test::CSS::Aural::Spec::Grammar;

0 comments on commit aab2f9d

Please sign in to comment.