[latex3-commits] [l3svn] r6656 - Refactoring l3doc: avoid back-and-forth between cs and csname

noreply at latex-project.org noreply at latex-project.org
Sun Aug 14 20:13:22 CEST 2016


Author: bruno
Date: 2016-08-14 20:13:22 +0200 (Sun, 14 Aug 2016)
New Revision: 6656

Modified:
   trunk/l3kernel/l3doc.dtx
Log:
Refactoring l3doc: avoid back-and-forth between cs and csname

The earlier code split out a leading backslash, just to add it
back later.


Modified: trunk/l3kernel/l3doc.dtx
===================================================================
--- trunk/l3kernel/l3doc.dtx	2016-08-14 17:05:25 UTC (rev 6655)
+++ trunk/l3kernel/l3doc.dtx	2016-08-14 18:13:22 UTC (rev 6656)
@@ -735,14 +735,6 @@
 %    \end{macrocode}
 % \end{variable}
 %
-% \begin{variable}[int]{\g_@@_function_name_prefix_tl}
-%   The \enquote{prefix} of the current function is a backslash if the
-%   function starts with it, and otherwise is empty.
-%    \begin{macrocode}
-\tl_new:N \g_@@_function_name_prefix_tl
-%    \end{macrocode}
-% \end{variable}
-%
 % \begin{variable}
 %   {\l_@@_index_macro_tl, \l_@@_index_key_tl, \l_@@_index_module_tl}
 %   When analyzing a control sequence found within a \env{macrocode}
@@ -870,6 +862,7 @@
 %     \tl_if_head_eq_charcode:oNT,
 %     \tl_if_head_eq_charcode:oNF,
 %     \tl_if_head_eq_meaning:VNF,
+%     \tl_if_in:noTF,
 %     \tl_if_in:NoTF,
 %     \tl_if_in:NoT,
 %     \tl_if_in:NoF,
@@ -891,6 +884,7 @@
 \cs_generate_variant:Nn \tl_if_head_eq_charcode:nNT  { o }
 \cs_generate_variant:Nn \tl_if_head_eq_charcode:nNF  { o }
 \cs_generate_variant:Nn \tl_if_head_eq_meaning:nNF  { V }
+\cs_generate_variant:Nn \tl_if_in:nnTF { no }
 \cs_generate_variant:Nn \tl_if_in:NnTF { No }
 \cs_generate_variant:Nn \tl_if_in:NnT  { No }
 \cs_generate_variant:Nn \tl_if_in:NnF  { No }
@@ -996,30 +990,48 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[aux]{\@@_predicate_from_base:N, \@@_predicate_from_base:n}
-% \begin{macro}[aux]{\@@_predicate_from_base_aux:w, \@@_predicate_from_base_auxii:w}
+% \begin{macro}[aux]{\@@_predicate_from_base:n}
 %   Get predicate from a function's base name.  The code is not broken
 %   by functions with no signature.  The |n|-type version can be used
-%   for keys and other non-control sequences.  The output is a string.
+%   for keys and other non-control sequences.  The output after
+%   |x|-expansion is a string.
 %    \begin{macrocode}
-\cs_new:Npn \@@_predicate_from_base:N #1
+\cs_new:Npn \@@_predicate_from_base:n #1
   {
-    \__cs_get_function_name:N #1 _p:
-    \__cs_get_function_signature:N #1
+    \@@_get_function_name:n {#1}
+    \tl_to_str:n { _p: }
+    \@@_get_function_signature:n {#1}
   }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}[aux]{\@@_split_function_do:nn}
+% \begin{macro}[aux]{\@@_get_function_name:n, \@@_get_function_signature:n}
+% \begin{macro}[aux]{\@@_split_function_auxi:w, \@@_split_function_auxii:w}
+%   Similar to internal functions defined in \pkg{l3basics}, but here we
+%   operate on strings directly rather than control sequences.
+%    \begin{macrocode}
+\cs_new:Npn \@@_get_function_name:n #1
+  { \@@_split_function_do:nn {#1} { \use_i:nnn } }
+\cs_new:Npn \@@_get_function_signature:n #1
+  { \@@_split_function_do:nn {#1} { \use_ii:nnn } }
 \cs_set_protected:Npn \@@_tmpa:w #1
   {
-    \cs_new:Npn \@@_predicate_from_base:n ##1
+    \cs_new:Npn \@@_split_function_do:nn ##1
       {
-        \exp_after:wN \@@_predicate_from_base_aux:w
-          \tl_to_str:n {##1} \q_mark #1 \q_stop
+        \exp_after:wN \@@_split_function_auxi:w
+        \tl_to_str:n {##1} \q_mark \c_true_bool
+        #1 \q_mark \c_false_bool
+        \q_stop
       }
-    \cs_new:Npn \@@_predicate_from_base_aux:w ##1 #1
-      { \@@_predicate_from_base_auxii:w ##1 _p: }
+    \cs_new:Npn \@@_split_function_auxi:w
+      ##1 #1 ##2 \q_mark ##3##4 \q_stop ##5
+      { \@@_split_function_auxii:w {##5} ##1 \q_mark \q_stop {##2} ##3 }
+    \cs_new:Npn \@@_split_function_auxii:w
+      ##1##2 \q_mark ##3 \q_stop
+      { ##1 {##2} }
   }
 \exp_args:No \@@_tmpa:w { \token_to_str:N : }
-\cs_new:Npn \@@_predicate_from_base_auxii:w #1 \q_mark #2 \q_stop
-  { \tl_to_str:n {#1} }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
@@ -1839,21 +1851,11 @@
   {
     \tl_if_head_eq_charcode:nNTF {#1} \c_@@_backslash_token
       {
-        \tl_gset_eq:NN \g_@@_function_name_prefix_tl \c_@@_backslash_tl
         \exp_args:No \tl_if_head_eq_charcode:nNTF { \use_none:n #1 } :
-          {
-            \prop_put:Nxn \l_@@_functions_block_prop
-              { \use_none:n #1 } { \scan_stop: }
-          }
-          {
-            \exp_args:Nc \__cs_split_function:NN { \use_none:n #1 }
-              \@@_function_parse_cs_aux:nnN
-          }
+          { \prop_put:Nnn \l_@@_functions_block_prop {#1} { \scan_stop: } }
+          { \@@_split_function_do:nn {#1} \@@_function_parse_cs_aux:nnN }
       }
-      {
-        \tl_gclear:N \g_@@_function_name_prefix_tl
-        \prop_put:Nnn \l_@@_functions_block_prop {#1} { \scan_stop: }
-      }
+      { \prop_put:Nnn \l_@@_functions_block_prop {#1} { \scan_stop: } }
   }
 \cs_new_protected:Npn \@@_function_parse_cs_aux:nnN #1#2#3
   {
@@ -1993,7 +1995,7 @@
 %   about the base form.  It stores the variants it receives in
 %   \cs{g_@@_variants_clist}, remove the first, which will be displayed
 %   more prominently, and reconstructs its actual name, passing it to
-%   the \cs{@@_typeset_functions_auxiii:N} auxiliary.
+%   the \cs{@@_typeset_functions_auxiii:n} auxiliary.
 %
 %   Braces around |##1| are crucial since this item can be empty.
 %
@@ -2025,7 +2027,7 @@
   {
     \clist_gset:Nn \g_@@_variants_clist {#2}
     \clist_gpop:NN \g_@@_variants_clist \l_@@_tmpb_tl
-    \exp_args:Nc \@@_typeset_functions_auxiii:N
+    \exp_args:Nx \@@_typeset_functions_auxiii:n
       {
         \g_@@_base_name_tl
         \tl_if_head_eq_meaning:VNF \l_@@_tmpb_tl \scan_stop:
@@ -2036,53 +2038,49 @@
 % \end{macro}
 % \end{macro}
 %
-% \begin{macro}[aux]{\@@_typeset_functions_auxiii:N}
+% \begin{macro}[aux]{\@@_typeset_functions_auxiii:n}
+% \begin{macro}[aux]{\@@_function_index:n, \@@_function_index:x}
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_typeset_functions_auxiii:N #1
+\cs_new_protected:Npn \@@_typeset_functions_auxiii:n #1
   {
     \bool_if:NT \l_@@_macro_pTF_bool
       {
         \tl_set:Nx \l_@@_pTF_name_tl
-          { \@@_predicate_from_base:N #1 }
+          { \@@_predicate_from_base:n {#1} }
         \@@_function_index:x { \l_@@_pTF_name_tl }
       }
     \@@_function_index:x
-      {
-        \cs_to_str:N #1
-        \bool_if:NT \l_@@_macro_TF_bool { \tl_to_str:n {TF} }
-      }
+      { #1 \bool_if:NT \l_@@_macro_TF_bool { \tl_to_str:n {TF} } }
     \bool_if:NT \l_@@_macro_pTF_bool
-      {
-        \exp_args:Nc \@@_typeset_function_block:NN
-          { \l_@@_pTF_name_tl } \c_false_bool
-      }
-    \@@_typeset_function_block:NN #1 \l_@@_macro_TF_bool
+      { \@@_typeset_function_block:VN \l_@@_pTF_name_tl \c_false_bool }
+    \@@_typeset_function_block:nN {#1} \l_@@_macro_TF_bool
   }
-\cs_new_protected:Npn \@@_function_index:x #1
+\cs_new_protected:Npn \@@_function_index:n #1
   {
-    \tl_set:Nx \l_@@_tmpa_tl
-      { \g_@@_function_name_prefix_tl #1 }
-    \seq_gput_right:No \g_doc_functions_seq { \l_@@_tmpa_tl }
-    \@@_special_index:on { \l_@@_tmpa_tl } { usage }
+    \seq_gput_right:Nn \g_doc_functions_seq {#1}
+    \@@_special_index:nn {#1} { usage }
   }
+\cs_generate_variant:Nn \@@_function_index:n { x }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
 %
-% \begin{macro}[internal]{\@@_typeset_function_block:NN}
-%   The first argument is a control sequence, the second a boolean which
+% \begin{macro}[int]
+%   {\@@_typeset_function_block:nN, \@@_typeset_function_block:VN}
+%   The first argument is a csname, the second a boolean which
 %   controls whether to typeset |TF| or not.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_typeset_function_block:NN #1#2
+\cs_new_protected:Npn \@@_typeset_function_block:nN #1#2
   {
-    \@@_function_label:x
-      { \g_@@_function_name_prefix_tl \cs_to_str:N #1 }
-    \g_@@_function_name_prefix_tl \cs_to_str:N #1
+    \@@_function_label:x {#1}
+    #1
     \bool_if:NT #2 { \@@_typeset_TF: }
     \@@_typeset_expandability:
     \clist_if_empty:NF \g_@@_variants_clist
-      { \@@_typeset_variant_list:NN #1#2 }
+      { \@@_typeset_variant_list:nN {#1} #2 }
     \\
   }
+\cs_generate_variant:Nn \@@_typeset_function_block:nN { V }
 %    \end{macrocode}
 %
 %    \begin{macrocode}
@@ -2103,14 +2101,10 @@
 %    \end{macrocode}
 %
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_typeset_variant_list:NN #1#2
+\cs_new_protected:Npn \@@_typeset_variant_list:nN #1#2
   {
     \\
-    \@@_typeset_aux:n
-      {
-        \g_@@_function_name_prefix_tl
-        \__cs_get_function_name:N #1
-      }
+    \@@_typeset_aux:n { \@@_get_function_name:n {#1} }
     :
     \int_compare:nTF { \clist_count:N \g_@@_variants_clist == 1 }
       { \clist_use:Nn \g_@@_variants_clist { } }
@@ -2124,19 +2118,14 @@
   }
 %    \end{macrocode}
 %
-% TODO: understand whether we need one more boolean to only
-% put labels if the whole document is typeset.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_function_label:n #1
   {
-    % \bool_if:NT \g_@@_typeset_implementation_bool
-    %   {
     \bool_if:NF \l_@@_no_label_bool
       {
         \@@_get_hyper_target:nN {#1} \l_@@_tmpa_tl
         \exp_args:No \label { \l_@@_tmpa_tl }
       }
-    %   }
   }
 \cs_generate_variant:Nn \@@_function_label:n { x }
 %    \end{macrocode}



More information about the latex3-commits mailing list