Skip to content

Commit

Permalink
use compiler to generate build.t interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Oct 5, 2023
1 parent 677f1d4 commit b31aed3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
8 changes: 4 additions & 4 deletions lib/CSS/Specification/Compiler.rakumod
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
unit class CSS::Specification::Compiler;
use CSS::Specification;
##use CSS::Specification::Actions;
##has CSS::Specification::Actions:D $.actions is required;
has $.actions is required;
use CSS::Specification::Compiler::Actions;
has CSS::Specification::Compiler::Actions:D $.actions .= new;
has @.defs;

use experimental :rakuast;
Expand Down Expand Up @@ -37,12 +36,13 @@ method role-ast($actions: @role-id) {
:declarator<role>,
:$name,
:body(RakuAST::Block.new: :$body),
:scope<unit>,
);
}

#= generate an interface class for all unresolved terms.
method !interface-methods {
my %unresolved = $!actions.prop-refs;
my %unresolved = $!actions.rule-refs;
%unresolved{'expr-' ~ $_}:delete
for $!actions.props.keys;
%unresolved{$_}:delete
Expand Down
9 changes: 3 additions & 6 deletions lib/CSS/Specification/Compiler/Actions.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ has %.props is rw;
has %.rules is rw;
has %.child-props is rw;

method TOP($/) is DEPRECATED { make $<def>>>.ast };
method TOP($/) { make $<def>>>.ast };

method property-spec($/) {
my @props = @($<prop-names>.ast);
%.props{$_}++ for @props;

my $spec = $<spec>.ast;
my $synopsis = ~$<spec>;

my %prop-def = (
props => @props,
synopsis => ~$<spec>,
raku-ast => $spec,
);
my %prop-def = (:@props, :$synopsis, :$spec);

%prop-def<inherit> = .ast with $<inherit>;

Expand Down
3 changes: 1 addition & 2 deletions t/00compile.t
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ for (
ast => {
:props['direction'],
:default<ltr>,
:raku-ast(:keywords["ltr", "rtl", "inherit"]),
:spec(:keywords["ltr", "rtl", "inherit"]),
:synopsis("ltr | rtl | inherit"),
:inherit
},
## deparse => 'xxx';
},
## # precedence tests taken from: https://developer.mozilla.org/en-US/docs/CSS/Value_definition_syntax
'spec' => {
Expand Down
11 changes: 7 additions & 4 deletions t/build.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use Test;
use CSS::Grammar::Test;
use CSS::Grammar::CSS21;
use CSS::Specification::Build;
use CSS::Specification::Compiler;
use lib 't';
use experimental :rakuast;

Expand All @@ -19,6 +20,10 @@ my $actions-name = $base-name ~ '::Actions';
my @role-id = @base-id.Slip, 'Interface';

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

my CSS::Specification::Compiler $compiler .= new;
$compiler.load-defs($input-path);

my @summary = CSS::Specification::Build::summary( :$input-path );
is +@summary, 25, 'number of summary items';
is-deeply [@summary.grep({ .<box> })], [{:box, :!inherit, :name<border-color>, :edges["border-top-color", "border-right-color", "border-bottom-color", "border-left-color"], :synopsis("[ <color> | transparent ]\{1,4}")},], 'summary item';
Expand All @@ -34,10 +39,8 @@ capture({
lives-ok {require ::($actions-name)}, "$actions-name compilation";

my $role-name = @role-id.join: '::';

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

dies-ok {require ::("Test::CSS::Aural::BadGrammar")}, 'grammar composition, unimplemented interface - dies';
Expand Down
26 changes: 11 additions & 15 deletions t/lib/Test/CSS/Aural/Spec/Interface.rakumod
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
use v6;
# -- DO NOT EDIT --
# generated by: t/build.t
unit role Test::CSS::Aural::Spec::Interface;

method angle($/) { ... }
method color($/) { ... }
method frequency($/) { ... }
method generic-voice($/) { ... }
method identifier($/) { ... }
method number($/) { ... }
method percentage($/) { ... }
method specific-voice($/) { ... }
method string($/) { ... }
method time($/) { ... }
method uri($/) { ... }
method angle ($/) ...
method color ($/) ...
method frequency ($/) ...
method generic-voice ($/) ...
method identifier ($/) ...
method number ($/) ...
method percentage ($/) ...
method specific-voice ($/) ...
method string ($/) ...
method time ($/) ...
method uri ($/) ...

0 comments on commit b31aed3

Please sign in to comment.