Skip to content

Commit

Permalink
fixed whitespacing handling around quantifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
dwarring committed Jan 18, 2017
1 parent 9d9b6e9 commit 48b79a3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,3 +1,4 @@
0.4.4 Fixed whitespace handling on quantifiers
0.4.3 Move test classes into lib path; t::CSS::Aural::Grammar, etc.
0.4.2 Bugfix a length can be a percentage quantity
- Also reinstate t/terms.t, lost around 538f043
Expand Down
2 changes: 1 addition & 1 deletion META.info
@@ -1,6 +1,6 @@
{ "perl" : "6.c",
"name" : "CSS::Specification",
"version" : "0.4.3",
"version" : "0.4.4",
"description" : "CSS Property definition grammar and generation tools",
"depends" : [ "CSS::Grammar" ],
"source-url" : "git://github.com/p6-css/perl6-CSS-Specification.git",
Expand Down
2 changes: 1 addition & 1 deletion lib/CSS/Specification.pm
Expand Up @@ -39,7 +39,7 @@ grammar CSS::Specification:ver<000.04> {
token id-quoted { <.quote> <id> <.quote> }
rule keyw { <id> }
rule digits { \d+ }
rule rule { '<'~'>' <id> }
rule rule { '<'~'>' <id> }
rule terms { <term=.term-options>+ }
rule term-options { <term=.term-combo> +% '|' }
Expand Down
10 changes: 5 additions & 5 deletions lib/CSS/Specification/Actions.pm
Expand Up @@ -79,7 +79,7 @@ class CSS::Specification::Actions {
!! @choices[0];
}

method _choose(@choices) {
method !choose(@choices) {
my $choices := @choices.map({[~] ($_, ' <!seen(', $*CHOICE++, ')>')}).join(' | ');
return [~] '[ ', $choices, ' ]';
}
Expand All @@ -88,15 +88,15 @@ class CSS::Specification::Actions {
my @choices = @<term>>>.ast;

make @choices > 1
?? $._choose( @choices ) ~ '+'
?? self!choose( @choices ) ~ '+'
!! @choices[0];
}

method term-required($/) {
my @choices = $<term>>>.ast;

make @choices > 1
?? [~] $._choose( @choices ), '**', @choices.Int
?? [~] self!choose( @choices ), '**', @choices.Int
!! @choices[0];
}

Expand All @@ -117,11 +117,11 @@ class CSS::Specification::Actions {
method occurs:sym<zero-plus>($/) { make '*' }
method occurs:sym<list>($/) {
my $quant = $<range> ?? $<range>.ast !! '+';
make " {$quant}% <op(',')>"
make "{$quant}% <op(',')>"
}
method occurs:sym<range>($/) { make $<range>.ast }
method range($/) {
my $range = '**' ~ $<min>.ast;
my $range = ' ** ' ~ $<min>.ast;
$range ~= '..' ~ $<max>.ast
if $<max>;

Expand Down
8 changes: 4 additions & 4 deletions lib/CSS/Specification/Build.pm
Expand Up @@ -130,7 +130,7 @@ module CSS::Specification::Build {
with $def<props> -> @props {
my $perl6 = $def<perl6>;
my $synopsis = $def<synopsis>;
my $box = $perl6 ~~ / '**1..4' $/;
my $box = $perl6 ~~ /:s '**' '1..4' $/;

for @props -> $name {
my %details = :$name, :$synopsis;
Expand Down Expand Up @@ -184,13 +184,13 @@ module CSS::Specification::Build {
my $synopsis = $def<synopsis>;

# boxed repeating property. repeat the expr
my $box = $perl6 ~~ / '**1..4' $/
my $box = $perl6 ~~ /:s '**' '1..4' $/
?? ', :box'
!! '';
my $repeats = '';
if $box {
$perl6 ~~ s/ '**1..4' $//;
$repeats = '**1..4';
$perl6 ~~ s/:s '**' '1..4' $//;
$repeats = ' ** 1..4';
}

for @props -> $prop {
Expand Down
8 changes: 4 additions & 4 deletions lib/t/CSS/Aural/Spec/Grammar.pm
Expand Up @@ -26,7 +26,7 @@ grammar t::CSS::Aural::Spec::Grammar {

#| pause: [ [<time> | <percentage>]{1,2} ]
rule decl:sym<pause> {:i (pause) ':' <val( rx{ <expr=.expr-pause> }, &?ROUTINE.WHY)> }
rule expr-pause {:i [ [ [ <time> || <percentage> ] ]**1..2 ] }
rule expr-pause {:i [ [ [ <time> || <percentage> ] ] ** 1..2 ] }

#| pause-after: <time> | <percentage>
rule decl:sym<pause-after> {:i (pause\-after) ':' <val( rx{ <expr=.expr-pause-after> }, &?ROUTINE.WHY)> }
Expand Down Expand Up @@ -78,7 +78,7 @@ grammar t::CSS::Aural::Spec::Grammar {

#| voice-family: [<generic-voice> | <specific-voice> ]#
rule decl:sym<voice-family> {:i (voice\-family) ':' <val( rx{ <expr=.expr-voice-family> }, &?ROUTINE.WHY)> }
rule expr-voice-family {:i [ [ <generic-voice> || <specific-voice> ] ] +% <op(',')> }
rule expr-voice-family {:i [ [ <generic-voice> || <specific-voice> ] ]+% <op(',')> }

#| generic-voice: male | female | child
rule generic-voice {:i [ male | female | child ] & <keyw> }
Expand All @@ -91,8 +91,8 @@ grammar t::CSS::Aural::Spec::Grammar {
rule expr-volume {:i [ <number> || <percentage> || [ silent | x\-soft | soft | medium | loud | x\-loud ] & <keyw> ] }

#| border-color: [ <color> | transparent ]{1,4}
rule decl:sym<border-color> {:i (border\-color) ':' <val( rx{ <expr=.expr-border-color>**1..4 }, &?ROUTINE.WHY)> }
rule expr-border-color {:i [ [ <color> || transparent & <keyw> ] ] }
rule decl:sym<border-color> {:i (border\-color) ':' <val( rx{ <expr=.expr-border-color> ** 1..4 }, &?ROUTINE.WHY)> }
rule expr-border-color {:i [ [ <color> || transparent & <keyw> ] ] }

#| border-top-color: <color> | transparent
rule decl:sym<border-top-color> {:i (border\-top\-color) ':' <val( rx{ <expr=.expr-border-top-color> }, &?ROUTINE.WHY)> }
Expand Down
4 changes: 2 additions & 2 deletions t/00basic.t
Expand Up @@ -20,10 +20,10 @@ for (
ast => "<rule-ref> [ <op(',')> [ [ <expr-css21-prop-ref> || <expr-css3-prop-ref> ] ] ]*",
},
'spec' => {input => '<length>{4}',
ast => '<length>**4',
ast => '<length> ** 4',
},
'spec' => {input => '<length>#{1,4}',
ast => "<length> **1..4% <op(',')>",
ast => "<length> ** 1..4% <op(',')>",
},
# precedence tests taken from: https://developer.mozilla.org/en-US/docs/CSS/Value_definition_syntax
'spec' => {input => 'bold thin && <length>',
Expand Down

0 comments on commit 48b79a3

Please sign in to comment.