From 720ea2863696971ea6a6744e0f23acbb3e6936bd Mon Sep 17 00:00:00 2001 From: Tab Atkins-Bittner Date: Mon, 17 Jun 2024 13:50:25 -0700 Subject: [PATCH] [css-values-4] Add generic grammar, so the increasing number of places that use boolean exprs don't have to repeat themselves. #10457 --- css-values-4/Overview.bs | 95 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/css-values-4/Overview.bs b/css-values-4/Overview.bs index 961579d80e4..27413f7fceb 100644 --- a/css-values-4/Overview.bs +++ b/css-values-4/Overview.bs @@ -5345,6 +5345,101 @@ Appendix A: Recommended Minimum Ranges and Precision of Computed Values --> + + +

+Boolean Expressions

+ +In several contexts, CSS allows certain boolean tests +(things that can evaluate to true or false), +and allows them to be combined with the logical operators +AND, OR, and NOT to form more complicated boolean tests. +(For example, ''@media'' or ''@supports'' rules.) + +All of these locations share a common grammatical structure, +with the only difference being what "base" boolean tests +are allowed, +and whether they use simple 2-value (true/false) boolean algebra, +or 3-value (true/false/unknown) Kleene logic. + +For example, in ''@media'' only <>s are allowed, +with Kleene logic; +in ''@supports'' only <>s are allowed, +with boolean logic. + +As the overall structure of these grammars is identical +across the various usages of it, +and also complex enough to be non-trivial to reproduce +(and easy to accidentally do wrong), +this specification defines <>, +a generic grammar for all such boolean tests. + +
+	<boolean> = <> | <> [ <>* | <>* ]
+	<boolean-without-or> = <> | <> <>*
+	<bool-not> = not <>
+	<bool-and> = and <>
+	<bool-or> = or <>
+	<bool-in-parens> = ( <> ) | <> | <>
+
+	<general-enclosed> = [ <> <>? ) ] | [ ( <>? ) ]
+
+ +Each specification using <> +must define what things are valid as <bool-test> values +in that context, +and whether it uses 2-value or 3-value logic. +As well, <> values +should either be wrapped in parentheses +or be functions; +if a specification needs to express some conditions in a different way, +please contact the CSSWG for review. + +: If using 2-value logic +:: + * Every <> must be defined to evaluate to either true or false. + * <> evaluates to false. + * <> evaluates to the value of its contained <>, <>, or <> + * <> evaluates to true if its contained <> is false, + and false otherwise. + * A <> with only a <> or <> evaluates to that. + * A <> with multiple <> connected with ''and'' + evaluates to true if all of its <> are true, + and false otherwise. + * A <> with multiple <> connected with ''or'' + evaluates to true if any of its <> are true, + and false otherwise. + +: If using 3-value logic +:: + * Every <> must be defined to evaluate to either true, false, or unknown. + * <> evaluates to unknown. + * <> evaluates to the value of its contained <>, <>, or <> + * <> evaluates to true if its contained <> is false, + false if it's true, + and unknown if it's unknown. + * A <> with only a <> or <> evaluates to that. + * A <> with multiple <> connected with ''and'' + evaluates to true if all of its <> are true, + false if any of them are false, + and unknown otherwise + (at least one unknown, but no false). + * A <> with multiple <> connected with ''or'' + evaluates to true if any of its <> are true, + false if all of them are false, + and unknown otherwise + (at least one unknown, but no true). + * If a "top-level" <> is unknown, + and the containing context uses 2-value logic + (or doesn't specify otherwise), + it instead evaluates to false. + + Note: That is, unknown doesn't "escape" a 3-value expression, + similar to how NaN doesn't "escape" a [=top-level calculation=]). + + + +