Skip to content

Commit

Permalink
css3: workaround complex rgb/rgba comma grammars
Browse files Browse the repository at this point in the history
The VDS syntax allows a non-context free mode of automatic comma
removal (requires at least some sort of lookahead/backtracking). So
workaround the main two grammars where we encounter this: rgb/rgba. We
group the comma and the following alpha value and make the whole group
optional.

Add to ticket mdn/data#341. However, looks
like the workaround is unlikely to be incorporated since the
contextual comma removal appears desired for ease of specifying those
cases.
  • Loading branch information
kanaka committed Aug 29, 2019
1 parent a41a909 commit 3ca3f6b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
28 changes: 18 additions & 10 deletions data/css3.ebnf
Original file line number Diff line number Diff line change
Expand Up @@ -6650,8 +6650,10 @@ func-rgb =
nonprop-percentage
)
)
(',' S)
nonprop-alpha-value?
(
(',' S)
nonprop-alpha-value
)?
(')' S)
) |
(
Expand All @@ -6664,8 +6666,10 @@ func-rgb =
nonprop-number
)
)
(',' S)
nonprop-alpha-value?
(
(',' S)
nonprop-alpha-value
)?
(')' S)
)
) ;
Expand Down Expand Up @@ -6714,8 +6718,10 @@ func-rgba =
nonprop-percentage
)
)
(',' S)
nonprop-alpha-value?
(
(',' S)
nonprop-alpha-value
)?
(')' S)
) |
(
Expand All @@ -6728,8 +6734,10 @@ func-rgba =
nonprop-number
)
)
(',' S)
nonprop-alpha-value?
(
(',' S)
nonprop-alpha-value
)?
(')' S)
)
) ;
Expand Down Expand Up @@ -6894,11 +6902,11 @@ nonprop-shape =
('rect' S)
('(' S)
nonprop-top
(',' S)
',' S
nonprop-right
(',' S)
nonprop-bottom
',' S
(',' S)
nonprop-left
(')' S)
) |
Expand Down
4 changes: 2 additions & 2 deletions data/css3.vds
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@
<repeat-style> = repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}
<repeating-linear-gradient()> = repeating-linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
<repeating-radial-gradient()> = repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
<rgb()> = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )
<rgba()> = rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )
<rgb()> = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} [ , <alpha-value> ]? ) | rgb( <number>#{3} [ , <alpha-value> ]? )
<rgba()> = rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} [ , <alpha-value> ]? ) | rgba( <number>#{3} [ , <alpha-value> ]? )
<rotate()> = rotate( <angle> )
<rotate3d()> = rotate3d( <number> , <number> , <number> , <angle> )
<rotateX()> = rotateX( <angle> )
Expand Down
14 changes: 14 additions & 0 deletions src/html5_css3_ebnf/css3.clj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@
(= k "page-body")
nil

;; VDS has a comma combining syntax that is difficult
;; to parse but only applies to rbg and rgba currently
;; so fix them up to be easier to parse. A bug related
;; to this: https://github.com/mdn/data/issues/341
;; Original:
;; "rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )"
(= k "rgb()")
[k {"syntax" "rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} [ , <alpha-value> ]? ) | rgb( <number>#{3} [ , <alpha-value> ]? )"}]

;; Original:
;; "rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )"
(= k "rgba()")
[k {"syntax" "rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} [ , <alpha-value> ]? ) | rgba( <number>#{3} [ , <alpha-value> ]? )" }]

:else
[k v]))))

Expand Down

0 comments on commit 3ca3f6b

Please sign in to comment.