Skip to content

Commit 3ca3f6b

Browse files
committed
css3: workaround complex rgb/rgba comma grammars
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.
1 parent a41a909 commit 3ca3f6b

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

data/css3.ebnf

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6650,8 +6650,10 @@ func-rgb =
66506650
nonprop-percentage
66516651
)
66526652
)
6653-
(',' S)
6654-
nonprop-alpha-value?
6653+
(
6654+
(',' S)
6655+
nonprop-alpha-value
6656+
)?
66556657
(')' S)
66566658
) |
66576659
(
@@ -6664,8 +6666,10 @@ func-rgb =
66646666
nonprop-number
66656667
)
66666668
)
6667-
(',' S)
6668-
nonprop-alpha-value?
6669+
(
6670+
(',' S)
6671+
nonprop-alpha-value
6672+
)?
66696673
(')' S)
66706674
)
66716675
) ;
@@ -6714,8 +6718,10 @@ func-rgba =
67146718
nonprop-percentage
67156719
)
67166720
)
6717-
(',' S)
6718-
nonprop-alpha-value?
6721+
(
6722+
(',' S)
6723+
nonprop-alpha-value
6724+
)?
67196725
(')' S)
67206726
) |
67216727
(
@@ -6728,8 +6734,10 @@ func-rgba =
67286734
nonprop-number
67296735
)
67306736
)
6731-
(',' S)
6732-
nonprop-alpha-value?
6737+
(
6738+
(',' S)
6739+
nonprop-alpha-value
6740+
)?
67336741
(')' S)
67346742
)
67356743
) ;
@@ -6894,11 +6902,11 @@ nonprop-shape =
68946902
('rect' S)
68956903
('(' S)
68966904
nonprop-top
6897-
(',' S)
6905+
',' S
68986906
nonprop-right
68996907
(',' S)
69006908
nonprop-bottom
6901-
',' S
6909+
(',' S)
69026910
nonprop-left
69036911
(')' S)
69046912
) |

data/css3.vds

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@
524524
<repeat-style> = repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2}
525525
<repeating-linear-gradient()> = repeating-linear-gradient( [ <angle> | to <side-or-corner> ]? , <color-stop-list> )
526526
<repeating-radial-gradient()> = repeating-radial-gradient( [ <ending-shape> || <size> ]? [ at <position> ]? , <color-stop-list> )
527-
<rgb()> = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )
528-
<rgba()> = rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )
527+
<rgb()> = rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} [ , <alpha-value> ]? ) | rgb( <number>#{3} [ , <alpha-value> ]? )
528+
<rgba()> = rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} [ , <alpha-value> ]? ) | rgba( <number>#{3} [ , <alpha-value> ]? )
529529
<rotate()> = rotate( <angle> )
530530
<rotate3d()> = rotate3d( <number> , <number> , <number> , <angle> )
531531
<rotateX()> = rotateX( <angle> )

src/html5_css3_ebnf/css3.clj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@
6464
(= k "page-body")
6565
nil
6666

67+
;; VDS has a comma combining syntax that is difficult
68+
;; to parse but only applies to rbg and rgba currently
69+
;; so fix them up to be easier to parse. A bug related
70+
;; to this: https://github.com/mdn/data/issues/341
71+
;; Original:
72+
;; "rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} , <alpha-value>? ) | rgb( <number>#{3} , <alpha-value>? )"
73+
(= k "rgb()")
74+
[k {"syntax" "rgb( <percentage>{3} [ / <alpha-value> ]? ) | rgb( <number>{3} [ / <alpha-value> ]? ) | rgb( <percentage>#{3} [ , <alpha-value> ]? ) | rgb( <number>#{3} [ , <alpha-value> ]? )"}]
75+
76+
;; Original:
77+
;; "rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} , <alpha-value>? ) | rgba( <number>#{3} , <alpha-value>? )"
78+
(= k "rgba()")
79+
[k {"syntax" "rgba( <percentage>{3} [ / <alpha-value> ]? ) | rgba( <number>{3} [ / <alpha-value> ]? ) | rgba( <percentage>#{3} [ , <alpha-value> ]? ) | rgba( <number>#{3} [ , <alpha-value> ]? )" }]
80+
6781
:else
6882
[k v]))))
6983

0 commit comments

Comments
 (0)