diff options
Diffstat (limited to 'macros/latex/contrib/l3kernel/l3tl-analysis.dtx')
-rw-r--r-- | macros/latex/contrib/l3kernel/l3tl-analysis.dtx | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/macros/latex/contrib/l3kernel/l3tl-analysis.dtx b/macros/latex/contrib/l3kernel/l3tl-analysis.dtx index 9f6527b505..0db5f15d7a 100644 --- a/macros/latex/contrib/l3kernel/l3tl-analysis.dtx +++ b/macros/latex/contrib/l3kernel/l3tl-analysis.dtx @@ -44,7 +44,7 @@ % }^^A % } % -% \date{Released 2022-02-24} +% \date{Released 2022-04-10} % % \maketitle % @@ -90,7 +90,7 @@ % characters, and the value of registers. % \end{function} % -% \begin{function}[added = 2018-04-09] +% \begin{function}[added = 2018-04-09, updated = 2022-03-26] % {\tl_analysis_map_inline:nn, \tl_analysis_map_inline:Nn} % \begin{syntax} % \cs{tl_analysis_map_inline:nn} \Arg{token list} \Arg{inline function} @@ -935,47 +935,46 @@ % % \subsection{Mapping through the analysis} % -% \begin{macro}{\tl_analysis_map_inline:nn, \tl_analysis_map_inline:Nn} -% \begin{macro}{\@@_analysis_map_inline_aux:Nn} -% \begin{macro}{\@@_analysis_map_inline_aux:nnn} +% \begin{macro}{\tl_analysis_map_inline:Nn, \tl_analysis_map_inline:nn} +% \begin{macro}{\@@_analysis_map:Nn} +% \begin{macro}{\@@_analysis_map:NwNw} % First obtain the analysis of the token list into % \cs{g_@@_analysis_result_tl}. To allow nested mappings, increase the -% nesting depth \cs{g__kernel_prg_map_int} (shared between all modules), then -% define the looping macro, which has a name specific to that nesting -% depth. That looping grabs the \meta{tokens}, \meta{catcode} and -% \meta{char code}; it checks for the end of the loop with -% \cs{use_none:n} |##2|, normally empty, but which becomes -% \cs{tl_map_break:} at the end; it then performs the user's code -% |#2|, and loops by calling itself. When the loop ends, remember to -% decrease the nesting depth. +% nesting depth \cs{g__kernel_prg_map_int} (shared between all +% modules), then define the payload macro, which runs the user code +% and has a name specific to that nesting depth. The looping macro +% grabs the \meta{tokens}, \meta{catcode} and \meta{char code}; it +% checks for the end of the loop with \cs{use_none:n} |##2|, normally +% empty, but which becomes \cs{tl_map_break:} at the end; it then +% calls the payload macro with the arguments in the correct order +% (this is the reason why we cannot directly use the same macro for +% looping and payload), and loops by calling itself. When the loop +% ends, remember to decrease the nesting depth. % \begin{macrocode} +\cs_new_protected:Npn \tl_analysis_map_inline:Nn #1 + { \exp_args:No \tl_analysis_map_inline:nn #1 } \cs_new_protected:Npn \tl_analysis_map_inline:nn #1 { \@@_analysis:n {#1} \int_gincr:N \g__kernel_prg_map_int - \exp_args:Nc \@@_analysis_map_inline_aux:Nn + \exp_args:Nc \@@_analysis_map:Nn { @@_analysis_map_inline_ \int_use:N \g__kernel_prg_map_int :wNw } } -\cs_new_protected:Npn \tl_analysis_map_inline:Nn #1 - { \exp_args:No \tl_analysis_map_inline:nn #1 } -\cs_new_protected:Npn \@@_analysis_map_inline_aux:Nn #1#2 +\cs_new_protected:Npn \@@_analysis_map:Nn #1#2 { - \cs_gset_protected:Npn #1 ##1 \s_@@ ##2 ##3 \s_@@ - { - \use_none:n ##2 - \@@_analysis_map_inline_aux:nnn {##1} {##3} {##2} - } - \cs_gset_protected:Npn \@@_analysis_map_inline_aux:nnn ##1##2##3 - { - #2 - #1 - } - \exp_after:wN #1 + \cs_gset_protected:Npn #1 ##1##2##3 {#2} + \exp_after:wN \@@_analysis_map:NwNw \exp_after:wN #1 \g_@@_analysis_result_tl \s_@@ { ? \tl_map_break: } \s_@@ \prg_break_point:Nn \tl_map_break: { \int_gdecr:N \g__kernel_prg_map_int } } +\cs_new_protected:Npn \@@_analysis_map:NwNw #1 #2 \s_@@ #3 #4 \s_@@ + { + \use_none:n #3 + #1 {#2} {#4} {#3} + \@@_analysis_map:NwNw #1 + } % \end{macrocode} % \end{macro} % \end{macro} |