[latex3-commits] [git/LaTeX3-latex3-latex3] bool_case: Add \bool_case:nTF in a branch (7115232)

Bruno Le Floch bruno at le-floch.fr
Sun Feb 10 09:43:02 CET 2019


Repository : https://github.com/latex3/latex3
On branch  : bool_case
Link       : https://github.com/latex3/latex3/commit/7115232643bc4e78747f007aba3e8375d6ceefb1

>---------------------------------------------------------------

commit 7115232643bc4e78747f007aba3e8375d6ceefb1
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sun Feb 10 09:43:02 2019 +0100

    Add \bool_case:nTF in a branch


>---------------------------------------------------------------

7115232643bc4e78747f007aba3e8375d6ceefb1
 l3kernel/l3candidates.dtx               |   70 +++++++++++++++++++++++++++++++
 l3kernel/l3int.dtx                      |    4 +-
 l3kernel/testfiles/m3expl001.luatex.tlg |    7 ++++
 l3kernel/testfiles/m3expl001.ptex.tlg   |    7 ++++
 l3kernel/testfiles/m3expl001.tlg        |    7 ++++
 l3kernel/testfiles/m3expl001.uptex.tlg  |    7 ++++
 l3kernel/testfiles/m3expl001.xetex.tlg  |    7 ++++
 l3kernel/testfiles/m3expl003.luatex.tlg |    7 ++++
 l3kernel/testfiles/m3expl003.ptex.tlg   |    7 ++++
 l3kernel/testfiles/m3expl003.tlg        |    7 ++++
 l3kernel/testfiles/m3expl003.uptex.tlg  |    7 ++++
 l3kernel/testfiles/m3expl003.xetex.tlg  |    7 ++++
 l3kernel/testfiles/m3prg005.lvt         |   24 ++++++++++-
 l3kernel/testfiles/m3prg005.tlg         |    6 +++
 14 files changed, 171 insertions(+), 3 deletions(-)

diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index 8706cf2..1418b3b 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -634,6 +634,46 @@
 %   conversely: sets it to the inverse of its current value.
 % \end{function}
 %
+% \begin{function}[added = 2019-02-10, EXP, noTF]{\bool_case:n}
+%   \begin{syntax}
+%     \cs{bool_case:nTF} \\
+%     ~~|{| \\
+%     ~~~~\Arg{boolexpr case_1} \Arg{code case_1} \\
+%     ~~~~\Arg{boolexpr case_2} \Arg{code case_2} \\
+%     ~~~~\ldots \\
+%     ~~~~\Arg{boolexpr case_n} \Arg{code case_n} \\
+%     ~~|}| \\
+%     ~~\Arg{true code}
+%     ~~\Arg{false code}
+%   \end{syntax}
+%   This function evaluates in turn each of the
+%   \meta{boolean expression cases}. If it is true then the
+%   associated \meta{code} is left in the input stream
+%   and other cases are discarded. If any of the
+%   cases is true, the \meta{true code} is also inserted into the
+%   input stream (after the code for the appropriate case), while if none
+%   match then the \meta{false code} is inserted. The function
+%   \cs{bool_case:n}, which does nothing if there is no match, is also
+%   available. For example
+%   \begin{verbatim}
+%     \bool_case:nF
+%       {
+%         { \dim_compare_p:n { \l__mypkg_wd_dim <= 10pt } }
+%             { Fits }
+%         { \int_compare_p:n { \l__mypkg_total_int >= 10 } }
+%             { Many }
+%         { \l__mypkg_special_bool }
+%             { Special }
+%       }
+%       { No idea! }
+%   \end{verbatim}
+%   leaves \enquote{\texttt{Fits}} or \enquote{\texttt{Many}} or
+%   \enquote{\texttt{Special}} or \enquote{\texttt{No idea!}} in the
+%   input stream, in a way similar to some other language's
+%   \enquote{\texttt{if} \ldots\ \texttt{elseif} \ldots\ \texttt{elseif} \ldots\
+%   \texttt{else} \ldots}.
+% \end{function}
+%
 % \section{Additions to \pkg{l3prop}}
 %
 % \begin{function}[EXP]{\prop_count:N, \prop_count:c}
@@ -2484,6 +2524,10 @@
 %
 % \subsection{Additions to \pkg{l3prg}}
 %
+%    \begin{macrocode}
+%<@@=bool>
+%    \end{macrocode}
+%
 % \begin{macro}[added = 2017-11-28]{\bool_const:Nn, \bool_const:cn}
 %   A merger between \cs{tl_const:Nn} and \cs{bool_set:Nn}.
 %    \begin{macrocode}
@@ -2510,6 +2554,32 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}[EXP, noTF]{\bool_case:n}
+% \begin{macro}{\@@_case:nTF}
+% \begin{macro}{\@@_case:w, \@@_case_end:nw}
+%   For boolean cases the overall idea is the same as for
+%   \cs{tl_case:nn(TF)} as described in \pkg{l3tl}, but with one fewer
+%   argument to track.
+%    \begin{macrocode}
+\cs_new:Npn \bool_case:nTF { \exp:w \@@_case:nTF }
+\cs_new:Npn \bool_case:nT #1#2 { \exp:w \@@_case:nTF {#1} {#2} { } }
+\cs_new:Npn \bool_case:nF #1 { \exp:w \@@_case:nTF {#1} { } }
+\cs_new:Npn \bool_case:n #1 { \exp:w \@@_case:nTF {#1} { } { } }
+\cs_new:Npn \@@_case:nTF #1#2#3
+  { \@@_case:w #1 \c_true_bool { } \q_mark {#2} \q_mark {#3} \q_stop }
+\cs_new:Npn \@@_case:w #1#2
+  {
+    \bool_if:nTF {#1}
+      { \@@_case_end:nw {#2} }
+      { \@@_case:w }
+  }
+\cs_new:Npn \@@_case_end:nw #1#2#3 \q_mark #4#5 \q_stop
+  { \exp_end: #1 #4 }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
 % \subsection{Additions to \pkg{l3prop}}
 %
 %    \begin{macrocode}
diff --git a/l3kernel/l3int.dtx b/l3kernel/l3int.dtx
index c660c5b..200ff7a 100644
--- a/l3kernel/l3int.dtx
+++ b/l3kernel/l3int.dtx
@@ -379,8 +379,8 @@
 %         { -2 * 10 } { Negative }
 %       }
 %       { No idea! }
-%    \end{verbatim}
-%    leaves \enquote{\texttt{Medium}} in the input stream.
+%   \end{verbatim}
+%   leaves \enquote{\texttt{Medium}} in the input stream.
 % \end{function}
 %
 % \begin{function}[EXP,pTF]{\int_if_even:n, \int_if_odd:n}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index f7850a0..df4d1a1 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -5966,6 +5966,13 @@ Defining \bool_set_inverse:N on line ...
 Defining \bool_set_inverse:c on line ...
 Defining \bool_gset_inverse:N on line ...
 Defining \bool_gset_inverse:c on line ...
+Defining \bool_case:nTF on line ...
+Defining \bool_case:nT on line ...
+Defining \bool_case:nF on line ...
+Defining \bool_case:n on line ...
+Defining \__bool_case:nTF on line ...
+Defining \__bool_case:w on line ...
+Defining \__bool_case_end:nw on line ...
 Defining \prop_count:N on line ...
 Defining \__prop_count:nn on line ...
 Defining \prop_count:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 04f5df2..4dd34d6 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -5999,6 +5999,13 @@ Defining \bool_set_inverse:N on line ...
 Defining \bool_set_inverse:c on line ...
 Defining \bool_gset_inverse:N on line ...
 Defining \bool_gset_inverse:c on line ...
+Defining \bool_case:nTF on line ...
+Defining \bool_case:nT on line ...
+Defining \bool_case:nF on line ...
+Defining \bool_case:n on line ...
+Defining \__bool_case:nTF on line ...
+Defining \__bool_case:w on line ...
+Defining \__bool_case_end:nw on line ...
 Defining \prop_count:N on line ...
 Defining \__prop_count:nn on line ...
 Defining \prop_count:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 09f5d96..f7f2f5c 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -5999,6 +5999,13 @@ Defining \bool_set_inverse:N on line ...
 Defining \bool_set_inverse:c on line ...
 Defining \bool_gset_inverse:N on line ...
 Defining \bool_gset_inverse:c on line ...
+Defining \bool_case:nTF on line ...
+Defining \bool_case:nT on line ...
+Defining \bool_case:nF on line ...
+Defining \bool_case:n on line ...
+Defining \__bool_case:nTF on line ...
+Defining \__bool_case:w on line ...
+Defining \__bool_case_end:nw on line ...
 Defining \prop_count:N on line ...
 Defining \__prop_count:nn on line ...
 Defining \prop_count:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 6724ff3..abdd600 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -5996,6 +5996,13 @@ Defining \bool_set_inverse:N on line ...
 Defining \bool_set_inverse:c on line ...
 Defining \bool_gset_inverse:N on line ...
 Defining \bool_gset_inverse:c on line ...
+Defining \bool_case:nTF on line ...
+Defining \bool_case:nT on line ...
+Defining \bool_case:nF on line ...
+Defining \bool_case:n on line ...
+Defining \__bool_case:nTF on line ...
+Defining \__bool_case:w on line ...
+Defining \__bool_case_end:nw on line ...
 Defining \prop_count:N on line ...
 Defining \__prop_count:nn on line ...
 Defining \prop_count:c on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 2c275a6..cff283d 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -5977,6 +5977,13 @@ Defining \bool_set_inverse:N on line ...
 Defining \bool_set_inverse:c on line ...
 Defining \bool_gset_inverse:N on line ...
 Defining \bool_gset_inverse:c on line ...
+Defining \bool_case:nTF on line ...
+Defining \bool_case:nT on line ...
+Defining \bool_case:nF on line ...
+Defining \bool_case:n on line ...
+Defining \__bool_case:nTF on line ...
+Defining \__bool_case:w on line ...
+Defining \__bool_case_end:nw on line ...
 Defining \prop_count:N on line ...
 Defining \__prop_count:nn on line ...
 Defining \prop_count:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index f7850a0..df4d1a1 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -5966,6 +5966,13 @@ Defining \bool_set_inverse:N on line ...
 Defining \bool_set_inverse:c on line ...
 Defining \bool_gset_inverse:N on line ...
 Defining \bool_gset_inverse:c on line ...
+Defining \bool_case:nTF on line ...
+Defining \bool_case:nT on line ...
+Defining \bool_case:nF on line ...
+Defining \bool_case:n on line ...
+Defining \__bool_case:nTF on line ...
+Defining \__bool_case:w on line ...
+Defining \__bool_case_end:nw on line ...
 Defining \prop_count:N on line ...
 Defining \__prop_count:nn on line ...
 Defining \prop_count:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 04f5df2..4dd34d6 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -5999,6 +5999,13 @@ Defining \bool_set_inverse:N on line ...
 Defining \bool_set_inverse:c on line ...
 Defining \bool_gset_inverse:N on line ...
 Defining \bool_gset_inverse:c on line ...
+Defining \bool_case:nTF on line ...
+Defining \bool_case:nT on line ...
+Defining \bool_case:nF on line ...
+Defining \bool_case:n on line ...
+Defining \__bool_case:nTF on line ...
+Defining \__bool_case:w on line ...
+Defining \__bool_case_end:nw on line ...
 Defining \prop_count:N on line ...
 Defining \__prop_count:nn on line ...
 Defining \prop_count:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 09f5d96..f7f2f5c 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -5999,6 +5999,13 @@ Defining \bool_set_inverse:N on line ...
 Defining \bool_set_inverse:c on line ...
 Defining \bool_gset_inverse:N on line ...
 Defining \bool_gset_inverse:c on line ...
+Defining \bool_case:nTF on line ...
+Defining \bool_case:nT on line ...
+Defining \bool_case:nF on line ...
+Defining \bool_case:n on line ...
+Defining \__bool_case:nTF on line ...
+Defining \__bool_case:w on line ...
+Defining \__bool_case_end:nw on line ...
 Defining \prop_count:N on line ...
 Defining \__prop_count:nn on line ...
 Defining \prop_count:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 6724ff3..abdd600 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -5996,6 +5996,13 @@ Defining \bool_set_inverse:N on line ...
 Defining \bool_set_inverse:c on line ...
 Defining \bool_gset_inverse:N on line ...
 Defining \bool_gset_inverse:c on line ...
+Defining \bool_case:nTF on line ...
+Defining \bool_case:nT on line ...
+Defining \bool_case:nF on line ...
+Defining \bool_case:n on line ...
+Defining \__bool_case:nTF on line ...
+Defining \__bool_case:w on line ...
+Defining \__bool_case_end:nw on line ...
 Defining \prop_count:N on line ...
 Defining \__prop_count:nn on line ...
 Defining \prop_count:c on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 2c275a6..cff283d 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -5977,6 +5977,13 @@ Defining \bool_set_inverse:N on line ...
 Defining \bool_set_inverse:c on line ...
 Defining \bool_gset_inverse:N on line ...
 Defining \bool_gset_inverse:c on line ...
+Defining \bool_case:nTF on line ...
+Defining \bool_case:nT on line ...
+Defining \bool_case:nF on line ...
+Defining \bool_case:n on line ...
+Defining \__bool_case:nTF on line ...
+Defining \__bool_case:w on line ...
+Defining \__bool_case_end:nw on line ...
 Defining \prop_count:N on line ...
 Defining \__prop_count:nn on line ...
 Defining \prop_count:c on line ...
diff --git a/l3kernel/testfiles/m3prg005.lvt b/l3kernel/testfiles/m3prg005.lvt
index 21e744f..71530b2 100644
--- a/l3kernel/testfiles/m3prg005.lvt
+++ b/l3kernel/testfiles/m3prg005.lvt
@@ -1,5 +1,5 @@
 %
-% Copyright (C) 2015 The LaTeX3 project
+% Copyright (C) 2015,2018 The LaTeX3 project
 %
 
 \documentclass{minimal}
@@ -71,4 +71,26 @@
     \bool_lazy_or_p:nn { \c_false_bool }{ \c_false_bool }
   }
 
+\TESTEXP { bool_case }
+  {
+    \bool_case:nTF
+      {
+        { \int_compare_p:n { 1 > 2 } } { \ERROR }
+        { \dim_compare_p:n { 10pt < 20pt } } { \TRUE }
+        \ERROR \ERROR
+      }
+      { \TRUE }
+      { \ERROR }
+    \NEWLINE
+    \bool_case:nTF
+      {
+        { \int_compare_p:n { 1 > 2 } } { \ERROR }
+        { \dim_compare_p:n { 10pt < 20pt } && \c_false_bool } { \ERROR }
+        { \c_false_bool } { \ERROR }
+      }
+      { \ERROR }
+      { \FALSE }
+    \NEWLINE
+  }
+
 \END
diff --git a/l3kernel/testfiles/m3prg005.tlg b/l3kernel/testfiles/m3prg005.tlg
index 5cfd72a..32975a8 100644
--- a/l3kernel/testfiles/m3prg005.tlg
+++ b/l3kernel/testfiles/m3prg005.tlg
@@ -49,3 +49,9 @@ TRUE
 \c_true_bool 
 \c_false_bool 
 ============================================================
+============================================================
+TEST 5: bool_case
+============================================================
+TRUETRUE
+FALSE
+============================================================





More information about the latex3-commits mailing list