diff --git a/lib/CSS/Compiler/RakuAST/Actions.rakumod b/lib/CSS/Compiler/RakuAST/Actions.rakumod index f85dc69..c1ae8a0 100644 --- a/lib/CSS/Compiler/RakuAST/Actions.rakumod +++ b/lib/CSS/Compiler/RakuAST/Actions.rakumod @@ -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, + ); +} diff --git a/lib/CSS/Compiler/RakuAST/Grammars.rakumod b/lib/CSS/Compiler/RakuAST/Grammars.rakumod index f2c275c..f0636dd 100644 --- a/lib/CSS/Compiler/RakuAST/Grammars.rakumod +++ b/lib/CSS/Compiler/RakuAST/Grammars.rakumod @@ -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; - - with $def -> @props { - for @props -> $prop { +method actions { ... } +method defs { ... } - say "method expr-{$prop}(\$/) \{ make \$.build.list(\$/) \}" - if %references{'expr-' ~ $prop}:exists; - } - } - else { - my $rule = $def; - 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, + ); } diff --git a/lib/CSS/Compiler/RakuAST/Roles.rakumod b/lib/CSS/Compiler/RakuAST/Roles.rakumod index d26f09d..58bf9c3 100644 --- a/lib/CSS/Compiler/RakuAST/Roles.rakumod +++ b/lib/CSS/Compiler/RakuAST/Roles.rakumod @@ -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); diff --git a/t/build.t b/t/build.t index 7d481ad..0aa7f98 100644 --- a/t/build.t +++ b/t/build.t @@ -15,9 +15,11 @@ sub capture($code, $output-path) { my @base-id = qw; 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'); @@ -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'; diff --git a/t/lib/Test/CSS/Aural/Spec/ActionsAST.rakumod b/t/lib/Test/CSS/Aural/Spec/ActionsAST.rakumod new file mode 100644 index 0000000..79ad0b1 --- /dev/null +++ b/t/lib/Test/CSS/Aural/Spec/ActionsAST.rakumod @@ -0,0 +1 @@ +unit class Test::CSS::Aural::Spec::Actions; diff --git a/t/lib/Test/CSS/Aural/Spec/GrammarAST.rakumod b/t/lib/Test/CSS/Aural/Spec/GrammarAST.rakumod new file mode 100644 index 0000000..91994d2 --- /dev/null +++ b/t/lib/Test/CSS/Aural/Spec/GrammarAST.rakumod @@ -0,0 +1 @@ +unit grammar Test::CSS::Aural::Spec::Grammar;