From 3ca3f6bc3fa0e084bb39dd66700a70cf31b12629 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 28 Aug 2019 22:45:26 -0500 Subject: [PATCH] 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 https://github.com/mdn/data/issues/341. However, looks like the workaround is unlikely to be incorporated since the contextual comma removal appears desired for ease of specifying those cases. --- data/css3.ebnf | 28 ++++++++++++++++++---------- data/css3.vds | 4 ++-- src/html5_css3_ebnf/css3.clj | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/data/css3.ebnf b/data/css3.ebnf index ca2f3b3..c57daf5 100644 --- a/data/css3.ebnf +++ b/data/css3.ebnf @@ -6650,8 +6650,10 @@ func-rgb = nonprop-percentage ) ) - (',' S) - nonprop-alpha-value? + ( + (',' S) + nonprop-alpha-value + )? (')' S) ) | ( @@ -6664,8 +6666,10 @@ func-rgb = nonprop-number ) ) - (',' S) - nonprop-alpha-value? + ( + (',' S) + nonprop-alpha-value + )? (')' S) ) ) ; @@ -6714,8 +6718,10 @@ func-rgba = nonprop-percentage ) ) - (',' S) - nonprop-alpha-value? + ( + (',' S) + nonprop-alpha-value + )? (')' S) ) | ( @@ -6728,8 +6734,10 @@ func-rgba = nonprop-number ) ) - (',' S) - nonprop-alpha-value? + ( + (',' S) + nonprop-alpha-value + )? (')' S) ) ) ; @@ -6894,11 +6902,11 @@ nonprop-shape = ('rect' S) ('(' S) nonprop-top - (',' S) + ',' S nonprop-right (',' S) nonprop-bottom - ',' S + (',' S) nonprop-left (')' S) ) | diff --git a/data/css3.vds b/data/css3.vds index 71d08a7..4e05b34 100644 --- a/data/css3.vds +++ b/data/css3.vds @@ -524,8 +524,8 @@ = repeat-x | repeat-y | [ repeat | space | round | no-repeat ]{1,2} = repeating-linear-gradient( [ | to ]? , ) = repeating-radial-gradient( [ || ]? [ at ]? , ) - = rgb( {3} [ / ]? ) | rgb( {3} [ / ]? ) | rgb( #{3} , ? ) | rgb( #{3} , ? ) - = rgba( {3} [ / ]? ) | rgba( {3} [ / ]? ) | rgba( #{3} , ? ) | rgba( #{3} , ? ) + = rgb( {3} [ / ]? ) | rgb( {3} [ / ]? ) | rgb( #{3} [ , ]? ) | rgb( #{3} [ , ]? ) + = rgba( {3} [ / ]? ) | rgba( {3} [ / ]? ) | rgba( #{3} [ , ]? ) | rgba( #{3} [ , ]? ) = rotate( ) = rotate3d( , , , ) = rotateX( ) diff --git a/src/html5_css3_ebnf/css3.clj b/src/html5_css3_ebnf/css3.clj index 55e8b49..8607a55 100644 --- a/src/html5_css3_ebnf/css3.clj +++ b/src/html5_css3_ebnf/css3.clj @@ -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( {3} [ / ]? ) | rgb( {3} [ / ]? ) | rgb( #{3} , ? ) | rgb( #{3} , ? )" + (= k "rgb()") + [k {"syntax" "rgb( {3} [ / ]? ) | rgb( {3} [ / ]? ) | rgb( #{3} [ , ]? ) | rgb( #{3} [ , ]? )"}] + + ;; Original: + ;; "rgba( {3} [ / ]? ) | rgba( {3} [ / ]? ) | rgba( #{3} , ? ) | rgba( #{3} , ? )" + (= k "rgba()") + [k {"syntax" "rgba( {3} [ / ]? ) | rgba( {3} [ / ]? ) | rgba( #{3} [ , ]? ) | rgba( #{3} [ , ]? )" }] + :else [k v]))))