[latex3-commits] [git/LaTeX3-latex3-latex3] l3bitset-2: use name instead of key, added a show command for the names (5f7deae4f)

Ulrike Fischer fischer at troubleshooting-tex.de
Tue Dec 29 18:48:12 CET 2020


Repository : https://github.com/latex3/latex3
On branch  : l3bitset-2
Link       : https://github.com/latex3/latex3/commit/5f7deae4fbc3e1e556b2a29d757d63d99a1df330

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

commit 5f7deae4fbc3e1e556b2a29d757d63d99a1df330
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Tue Dec 29 18:48:12 2020 +0100

    use name instead of key, added a show command for the names


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

5f7deae4fbc3e1e556b2a29d757d63d99a1df330
 l3experimental/l3bitset/l3bitset.dtx              | 153 +++++++++++++---------
 l3experimental/l3bitset/testfiles/m3bitset001.tlg |   4 +-
 l3experimental/l3bitset/testfiles/m3bitset002.tlg |   4 +-
 3 files changed, 96 insertions(+), 65 deletions(-)

diff --git a/l3experimental/l3bitset/l3bitset.dtx b/l3experimental/l3bitset/l3bitset.dtx
index 50f6e2dd4..d68467b5d 100644
--- a/l3experimental/l3bitset/l3bitset.dtx
+++ b/l3experimental/l3bitset/l3bitset.dtx
@@ -61,7 +61,7 @@
 % representation) and so the vector size is theoretically
 % unlimited, only restricted by \TeX-memory. But the functions to set and clear
 % bits uses integer functions for the index so bitsets can't be longer
-% than $2^{31} −1$.
+% than $2^{31} - 1$.
 % The export function
 % \cs{bitset_to_arabic:N} can use functions from the \texttt{int} module only if
 % the largest index used for this bitset is smaller then 32, for longer
@@ -92,29 +92,11 @@
 % argument of \cs{bitset_new:Nn} declares names for some indices,
 % which can be used to set and unset bits.
 %
-% For example after this setting
-%
-%  \begin{verbatim}
-%  \bitset_new:Nn \l_pdfannot_F_bitset
-%    {
-%      Invisible      = 1,
-%      Hidden         = 2,
-%      Print          = 3,
-%      NoZoom         = 4,
-%      NoRotate       = 5,
-%      NoView         = 6,
-%      ReadOnly       = 7,
-%      Locked         = 8,
-%      ToggleNoView   = 9,
-%      LockedContents = 10
-%    }
-%  \end{verbatim}
-%  it is possible to set bit 3 by using
-%  |\bitset_set_true:Nn \l_pdfannot_F_bitset {Print}|
-%
-% The declaration of such names is global.
-% \meta{index\ldots} should be an \meta{integer expression}
-% which evaluates to a positive number. The names \meta{name\ldots}
+
+% \meta{index\ldots} should be a positive number.
+% It can be an \meta{integer expression} which evaluates to a positive number.
+% The expression is evaluated when the index is used, not a declaration time.
+% The names \meta{name\ldots}
 % should be unique. Using a number as name, e.g |10=1|, is allowed,
 % but the index position |10| can then only be reached if some other
 % name for it exists, e.g. |ten=10|.
@@ -132,8 +114,37 @@
 %         \meta{name2} |=| \meta{index2} |,| \ldots{}
 %      \}
 %   \end{syntax}
-% This adds (or updates) the name--index pairs for \meta{bitset var}
-% as described for \cs{bitset_new:Nn}.
+% This extends or changes the name--index pairs for \meta{bitset var}
+% globally as described for \cs{bitset_new:Nn}.
+%
+% For example after these settings
+%
+%  \begin{verbatim}
+%  \bitset_new:Nn \l_pdfannot_F_bitset
+%    {
+%      Invisible      = 1,
+%      Hidden         = 2,
+%      Print          = 3,
+%      NoZoom         = 4,
+%      NoRotate       = 5,
+%      NoView         = 6,
+%      ReadOnly       = 7,
+%      Locked         = 8,
+%      ToggleNoView   = 9,
+%      LockedContents = 10
+%    }
+%  \bitset_addto_named_index:Nn \l_pdfannot_F_bitset
+%    {
+%      print = 3
+%    }
+%  \end{verbatim}
+%  it is possible to set bit 3 by using any of this alternatives:
+%  \begin{verbatim}
+%  \bitset_set_true:Nn \l_pdfannot_F_bitset {Print}
+%  \bitset_set_true:Nn \l_pdfannot_F_bitset {print}
+%  \bitset_set_true:Nn \l_pdfannot_F_bitset {3}
+%  \end{verbatim}
+
 % \end{function}
 %
 
@@ -153,11 +164,11 @@
 % \begin{function}[added = 2020-12-13, updated=2020-12-29]
 %   { \bitset_set_true:Nn, \bitset_set_true:cn, \bitset_gset_true:Nn, \bitset_gset_true:cn  }
 %   \begin{syntax}
-%     \cs{bitset_set_true:Nn}   \meta{bitset var}  \Arg{position}\\
-%     \cs{bitset_gset_true:Nn}  \meta{bitset var}  \Arg{position}
+%     \cs{bitset_set_true:Nn}   \meta{bitset var}  \Arg{name/index}\\
+%     \cs{bitset_gset_true:Nn}  \meta{bitset var}  \Arg{name/index}
 %   \end{syntax}
-% This sets the bit of the index position represented by \Arg{position} to 1.
-% \Arg{position} should be either a declared name or a positive,
+% This sets the bit of the index position represented by \Arg{name/index} to 1.
+% \Arg{name/index} should be either a declared name or a positive,
 % unsigned explicit integer (not an integer expression).
 % If it is both a name and a number, the name will take precedence.
 % Index position are 1-based.
@@ -167,12 +178,12 @@
 % \begin{function}[added = 2020-12-13,updated=2020-12-29]
 %   { \bitset_set_false:Nn, \bitset_set_false:cn, \bitset_gset_false:Nn, \bitset_set_false:cn }
 %   \begin{syntax}
-%     \cs{bitset_set_false:Nn}   \meta{bitset var}  \Arg{position}\\
-%     \cs{bitset_gset_false:Nn}  \meta{bitset var}  \Arg{position}
+%     \cs{bitset_set_false:Nn}   \meta{bitset var}  \Arg{name/index}\\
+%     \cs{bitset_gset_false:Nn}  \meta{bitset var}  \Arg{name/index}
 %   \end{syntax}
-% This unsets the bit of the index position represented by \Arg{position} (sets
+% This unsets the bit of the index position represented by \Arg{name/index} (sets
 % it to 0).
-% \Arg{position} should be either a declared name or a positive,
+% \Arg{name/index} should be either a declared name or a positive,
 % unsigned explicit integer (not an integer expression).
 % If it is both a name and a number, the name will take precedence.
 % The index is 1-based. If the index position is larger
@@ -196,11 +207,11 @@
 % \begin{function}[EXP,added = 2020-12-14, updated=2020-12-29]
 %   { \bitset_item:Nn, \bitset_item:cn }
 %   \begin{syntax}
-%     \cs{bitset_item:Nn}   \meta{bitset var}  \Arg{position}
+%     \cs{bitset_item:Nn}   \meta{bitset var}  \Arg{name/index}
 %   \end{syntax}
 % \cs{bitset_item:Nn} outputs \texttt{1} if the bit with
-% the index number represented by \Arg{position} is set and \texttt{0} otherwise.
-%  \Arg{position} is a declared name or a positiv, unsigned explicit number.
+% the index number represented by \Arg{name/index} is set and \texttt{0} otherwise.
+%  \Arg{name/index} is a declared name or a positiv, unsigned explicit number.
 % \end{function}
 %
 % \begin{function}[EXP,added = 2020-12-13]
@@ -268,16 +279,16 @@
   {
     \__kernel_chk_if_free_cs:N #1
     \cs_gset_eq:NN #1 \c_zero_str
-    \prop_new:c { g__bitset_\cs_to_str:N #1 _key_prop }
+    \prop_new:c { g__bitset_\cs_to_str:N #1 _name_prop }
   }
 
 \cs_new_protected:Npn \bitset_new:Nn #1 #2
   {
     \__kernel_chk_if_free_cs:N #1
     \cs_gset_eq:NN #1 \c_zero_str
-    \prop_new:c { g__bitset_\cs_to_str:N #1 _key_prop }
+    \prop_new:c { g__bitset_\cs_to_str:N #1 _name_prop }
     \prop_gset_from_keyval:cn
-       { g__bitset_\cs_to_str:N #1 _key_prop }
+       { g__bitset_\cs_to_str:N #1 _name_prop }
        { #2 }
   }
 \cs_generate_variant:Nn \bitset_new:N {c}
@@ -301,7 +312,7 @@
      \prop_map_inline:Nn \l_@@_tmpa_prop
        {
          \prop_gput:cnn
-           { g_@@_\cs_to_str:N #1 _key_prop }
+           { g_@@_\cs_to_str:N #1 _name_prop }
            { ##1 }
            { ##2 }
        }
@@ -390,11 +401,11 @@
 % #1 name, #2 index (name or number)
 \cs_new_protected:Npn \bitset_set_true:Nn #1 #2
   {
-    \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
+    \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _name_prop } {#2}
       {
         \@@_set_true:Nn #1
           {
-            \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
+            \prop_item:cn{ g_@@_\cs_to_str:N #1 _name_prop }{#2}
           }
       }
       {
@@ -402,10 +413,10 @@
           {
             %is number
             \@@_set_true:Nn #1 { #2}
-            \prop_gput:cnn { g_@@_\cs_to_str:N #1 _key_prop }{#2} {#2}
+            \prop_gput:cnn { g_@@_\cs_to_str:N #1 _name_prop }{#2} {#2}
           }
           {
-            \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-key }
+            \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-name }
               { \token_to_str:N #1 }
               { \tl_to_str:n { #2} }
           }
@@ -415,11 +426,11 @@
 %#1 name, #2 index (name or number)
 \cs_new_protected:Npn \bitset_gset_true:Nn #1 #2
   {
-    \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
+    \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _name_prop } {#2}
       {
         \@@_gset_true:Nn #1
           {
-            \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
+            \prop_item:cn{ g_@@_\cs_to_str:N #1 _name_prop }{#2}
           }
       }
       {
@@ -427,10 +438,10 @@
           {
             %is number
             \@@_gset_true:Nn #1 { #2}
-            \prop_gput:cnn { g_@@_\cs_to_str:N #1 _key_prop }{#2} {#2}
+            \prop_gput:cnn { g_@@_\cs_to_str:N #1 _name_prop }{#2} {#2}
           }
           {
-            \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-key }
+            \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-name }
               { \token_to_str:N #1 }
               { \tl_to_str:n { #2} }
           }
@@ -493,11 +504,11 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \bitset_set_false:Nn #1 #2  %#1 name, #2 index (1-based)
  {
-    \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
+    \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _name_prop } {#2}
       {
         \@@_set_false:Nn #1
           {
-            \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
+            \prop_item:cn{ g_@@_\cs_to_str:N #1 _name_prop }{#2}
           }
       }
       {
@@ -505,10 +516,10 @@
           {
             %is number
             \@@_set_false:Nn #1 { #2}
-            \prop_gput:cnn { g_@@_\cs_to_str:N #1 _key_prop }{#2} {#2}
+            \prop_gput:cnn { g_@@_\cs_to_str:N #1 _name_prop }{#2} {#2}
           }
           {
-            \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-key }
+            \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-name }
               { \token_to_str:N #1 }
               { \tl_to_str:n { #2} }
           }
@@ -517,11 +528,11 @@
 
 \cs_new_protected:Npn \bitset_gset_false:Nn #1 #2  %#1 name, #2 index (1-based)
  {
-   \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
+   \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _name_prop } {#2}
      {
        \@@_gset_false:Nn #1
          {
-           \prop_item:cn{ g_@@_\cs_to_str:N #1 _key_prop }{#2}
+           \prop_item:cn{ g_@@_\cs_to_str:N #1 _name_prop }{#2}
          }
      }
      {
@@ -529,10 +540,10 @@
          {
            %is number
            \@@_gset_false:Nn #1 { #2}
-           \prop_gput:cnn { g_@@_\cs_to_str:N #1 _key_prop }{#2} {#2}
+           \prop_gput:cnn { g_@@_\cs_to_str:N #1 _name_prop }{#2} {#2}
          }
          {
-           \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-key }
+           \__kernel_msg_warning:nnxx { bitset } { bitset-unknown-name }
              { \token_to_str:N #1 }
              { \tl_to_str:n { #2} }
          }
@@ -604,12 +615,12 @@
 %    \begin{macrocode}
 \cs_new:Npn \bitset_item:Nn #1 #2
   {
-    \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _key_prop } {#2}
+    \prop_if_in:cnTF { g_@@_\cs_to_str:N #1 _name_prop } {#2}
       {
         \int_eval:n
           {
             \str_item:Nn #1
-              { 0 - ( \prop_item:cn { g_@@_\cs_to_str:N #1 _key_prop }{#2} ) }
+              { 0 - ( \prop_item:cn { g_@@_\cs_to_str:N #1 _name_prop }{#2} ) }
             +0
           }
      }
@@ -631,6 +642,8 @@
 \cs_generate_variant:Nn \bitset_show:N { c }
 \cs_new_protected:Npn   \bitset_log:N  { \@@_show:NN \msg_log:nnxxxx }
 \cs_generate_variant:Nn \bitset_log:N  { c }
+\cs_new_protected:Npn   \bitset_show_named_index:N { \@@_show_named_index:NN \msg_show:nnxxxx }
+\cs_generate_variant:Nn \bitset_show_named_index:N { c }
 \cs_new_protected:Npn \__bitset_show:NN #1#2
   {
     \__kernel_chk_defined:NT #2
@@ -643,6 +656,17 @@
       }
   }
 
+\cs_new_protected:Npn \__bitset_show_named_index:NN #1#2
+  {
+    \__kernel_chk_defined:NT #2
+      {
+        #1 { LaTeX/bitset } { show-names }
+           { \token_to_str:N #2 }
+           { \prop_map_function:cN { g_@@_\cs_to_str:N #2 _name_prop }  \msg_show_item:nn  }
+           { }
+           { }
+      }
+  }
 %    \end{macrocode}
 % \end{macro}
 
@@ -654,8 +678,15 @@
     >~binary:~#2  \\
     >~arabic:~#3 .
   }
-\__kernel_msg_new:nnn { bitset } { bitset-unknown-key }
-  { The~key~'#2'~is~unknown~for~bitset~\tl_to_str:n {#1} }
+\__kernel_msg_new:nnn { bitset } { show-names }
+  {
+    The~bitset~#1~
+    \tl_if_empty:nTF {#2}
+      { knows~no~names~yet \\>~ . }
+      { knows~the~name/index~pairs~(without~outer~braces): #2 . }
+  }
+\__kernel_msg_new:nnn { bitset } { bitset-unknown-name }
+  { The~name~'#2'~is~unknown~for~bitset~\tl_to_str:n {#1} }
 
 %    \end{macrocode}
 %    \begin{macrocode}
diff --git a/l3experimental/l3bitset/testfiles/m3bitset001.tlg b/l3experimental/l3bitset/testfiles/m3bitset001.tlg
index a349aa2ff..7b52fe34e 100644
--- a/l3experimental/l3bitset/testfiles/m3bitset001.tlg
+++ b/l3experimental/l3bitset/testfiles/m3bitset001.tlg
@@ -47,7 +47,7 @@ l. ... }
 ============================================================
 TEST 6: set negative index
 ============================================================
-LaTeX3 Warning: The key '-2' is unknown for bitset \l_my_test_bitset
+LaTeX3 Warning: The name '-2' is unknown for bitset \l_my_test_bitset
 The bitset \l_my_test_bitset has the representation:
 > binary: 1
 > arabic: 1.
@@ -57,7 +57,7 @@ l. ... }
 ============================================================
 TEST 7: set negative index global
 ============================================================
-LaTeX3 Warning: The key '-2' is unknown for bitset \g_my_test_bitset
+LaTeX3 Warning: The name '-2' is unknown for bitset \g_my_test_bitset
 The bitset \g_my_test_bitset has the representation:
 > binary: 1
 > arabic: 1.
diff --git a/l3experimental/l3bitset/testfiles/m3bitset002.tlg b/l3experimental/l3bitset/testfiles/m3bitset002.tlg
index f4fdcc682..9f80cb7a8 100644
--- a/l3experimental/l3bitset/testfiles/m3bitset002.tlg
+++ b/l3experimental/l3bitset/testfiles/m3bitset002.tlg
@@ -17,8 +17,8 @@ TEST 2: set Invisible (index 1)
 ============================================================
 TEST 3: set unknown key
 ============================================================
-LaTeX3 Warning: The key 'unknown' is unknown for bitset \l_my_test_bitset
-LaTeX3 Warning: The key 'unknown' is unknown for bitset \g_my_test_bitset
+LaTeX3 Warning: The name 'unknown' is unknown for bitset \l_my_test_bitset
+LaTeX3 Warning: The name 'unknown' is unknown for bitset \g_my_test_bitset
 The bitset \l_my_test_bitset has the representation:
 > binary: 1
 > arabic: 1.





More information about the latex3-commits mailing list.