[latex3-commits] [git/LaTeX3-latex3-latex3] master: define first token tests before token by token changes (c18fb4927)
Bruno Le Floch
blflatex at gmail.com
Tue Oct 27 09:11:58 CET 2020
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/c18fb492731b51fc7e7db4877895ba299876a137
>---------------------------------------------------------------
commit c18fb492731b51fc7e7db4877895ba299876a137
Author: Jonathan Spratte <jspratte at yahoo.de>
Date: Sat Oct 3 18:51:40 2020 +0200
define first token tests before token by token changes
>---------------------------------------------------------------
c18fb492731b51fc7e7db4877895ba299876a137
l3kernel/l3tl.dtx | 376 +++++++++++++++++++++++++++---------------------------
1 file changed, 188 insertions(+), 188 deletions(-)
diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index 52da3d627..c5a2bda6f 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -2803,194 +2803,6 @@
% Implemented in \pkg{l3sort}.
% \end{macro}
%
-% \subsection{Token by token changes}
-%
-% \begin{variable}{\q_@@_act_stop}
-% The \cs[no-index]{@@_act_\ldots{}} functions may be applied to any token list.
-% Hence, we use a private quark, to allow any token, even quarks,
-% in the token list.
-% Only \cs{q_@@_act_stop} may not appear in the token lists manipulated by
-% \cs{@@_act:NNNnn} functions.
-% \begin{macrocode}
-\quark_new:N \q_@@_act_stop
-% \end{macrocode}
-% \end{variable}
-%
-% \begin{macro}[EXP]{\@@_act:NNNnn}
-% \begin{macro}[EXP]{\@@_act_output:n, \@@_act_reverse_output:n}
-% \begin{macro}[EXP]{\@@_act_loop:w}
-% \begin{macro}[EXP]{\@@_act_normal:NwnNNN}
-% \begin{macro}[EXP]{\@@_act_group:nwnNNN}
-% \begin{macro}[EXP]{\@@_act_space:wwnNNN}
-% \begin{macro}[EXP]{\@@_act_end:w}
-% \begin{macro}[EXP]
-% {
-% \@@_act_if_head_is_space:nTF,
-% \@@_act_if_head_is_space:w,
-% \@@_act_if_head_is_space_true:w
-% }
-% \begin{macro}[EXP]{\@@_use_none_delimit_by_q_act_stop:w}
-% To help control the expansion, \cs{@@_act:NNNnn} should always
-% be proceeded by \cs{exp:w} and ends by producing \cs{exp_end:}
-% once the result has been obtained. Then loop over tokens,
-% groups, and spaces in |#5|. |{\q_@@_act_stop}| serves as the end of token
-% list marker, the |?| after it avoids losing outer braces. The result is
-% stored as an argument for the dummy function \cs{@@_act_result:n}.
-% \begin{macrocode}
-\exp_args:Nno \use:n { \cs_new:Npn \@@_act:NNNnn #1#2#3#4#5 }
- {
- \group_align_safe_begin:
- \@@_act_loop:w #5 {\q_@@_act_stop} ? \q_@@_act_stop
- {#4} #1 #3 #2
- \@@_act_result:n { }
- }
-% \end{macrocode}
-% Because \cs{q_@@_act_stop} can't appear without braces around it in the
-% argument~|#1| of \cs{@@_act_loop:w}, we can use this marker to set up a fast
-% test for leading spaces.
-% \begin{macrocode}
-\group_begin:
- \cs_set:Npn \@@_tmp:n #1
- {
- \cs_new:Npn \@@_act_if_head_is_space:nTF ##1
- {
- \@@_act_if_head_is_space:w
- \q_@@_act_stop ##1 \q_@@_act_stop \@@_act_if_head_is_space_true:w
- \q_@@_act_stop #1 \q_@@_act_stop \use_ii:nn
- }
- \cs_new:Npn \@@_act_if_head_is_space:w
- ##1 \q_@@_act_stop #1 ##2 \q_@@_act_stop
- {}
- \cs_new:Npn \@@_act_if_head_is_space_true:w
- \q_@@_act_stop #1 \q_@@_act_stop \use_ii:nn ##1 ##2
- {##1}
- }
- \@@_tmp:n { ~ }
-\group_end:
-% \end{macrocode}
-% In the loop, we check how the token list begins and act
-% accordingly. In the \enquote{group} case, we may have
-% reached \cs{q_@@_act_stop}, the end of the list. Then
-% leave \cs{exp_end:} and the result in the input stream,
-% to terminate the expansion of \cs{exp:w}.
-% Otherwise, apply the relevant function to the
-% \enquote{arguments}, |#3|
-% and to the head of the token list. Then repeat the loop.
-% The scheme is the same if the token list starts with an |N|-type
-% or with a space. Some extra work is needed to
-% make \cs{@@_act_space:wwnNNN} gobble the space.
-% \begin{macrocode}
-\group_begin:
- \cs_set_nopar:Npx \@@_tmp:
- {
- \__kernel_exp_not:w \exp_after:wN { \@@_act_if_head_is_space:nTF {#1} }
- { \exp_not:N \@@_act_space:wwnNNN }
- {
- \__kernel_exp_not:w \exp_after:wN { \tl_if_head_is_group:nTF {#1} }
- { \exp_not:N \@@_act_group:nwnNNN }
- { \exp_not:N \@@_act_normal:NwnNNN }
- }
- }
- \exp_args:Nno \use:n { \cs_new:Npn \@@_act_loop:w #1 \q_@@_act_stop }
- {
- \@@_tmp:
- #1 \q_@@_act_stop
- }
-\group_end:
-\cs_new:Npn \@@_act_normal:NwnNNN #1 #2 \q_@@_act_stop #3#4
- {
- #4 {#3} #1
- \@@_act_loop:w #2 \q_@@_act_stop
- {#3} #4
- }
-\cs_new:Npn \@@_use_none_delimit_by_q_act_stop:w #1 \q_@@_act_stop { }
-\exp_args:Nno \use:n { \cs_new:Npn \@@_act_end:wn #1 \@@_act_result:n #2 }
- { \group_align_safe_end: \exp_end: #2 }
-\cs_new:Npn \@@_act_group:nwnNNN #1 #2 \q_@@_act_stop #3#4#5#6
- {
- \@@_use_none_delimit_by_q_act_stop:w #1 \@@_act_end:wn \q_@@_act_stop
- #6 {#3} {#1}
- \@@_act_loop:w #2 \q_@@_act_stop
- {#3} #4 #5 #6
- }
-\exp_last_unbraced:NNo
- \cs_new:Npn \@@_act_space:wwnNNN \c_space_tl #1 \q_@@_act_stop #2#3#4
- {
- #4 {#2}
- \@@_act_loop:w #1 \q_@@_act_stop
- {#2} #3 #4
- }
-% \end{macrocode}
-% Typically, the output is done to the right of what was already output,
-% using \cs{@@_act_output:n}, but for the \cs{@@_act_reverse} functions,
-% it should be done to the left.
-% \begin{macrocode}
-\cs_new:Npn \@@_act_output:n #1 #2 \@@_act_result:n #3
- { #2 \@@_act_result:n { #3 #1 } }
-\cs_new:Npn \@@_act_reverse_output:n #1 #2 \@@_act_result:n #3
- { #2 \@@_act_result:n { #1 #3 } }
-% \end{macrocode}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-%
-% \begin{macro}[EXP]{\tl_reverse:n, \tl_reverse:o, \tl_reverse:V}
-% \begin{macro}[EXP]{\@@_reverse_normal:nN}
-% \begin{macro}[EXP]{\@@_reverse_group_preserve:nn}
-% \begin{macro}[EXP]{\@@_reverse_space:n}
-% The goal here is to reverse without losing spaces nor braces.
-% This is done using the general internal function \cs{@@_act:NNNnn}.
-% Spaces and \enquote{normal} tokens are output on the left of the current
-% output. Grouped tokens are output to the left but without any reversal
-% within the group. All of the internal functions here drop one argument:
-% this is needed by \cs{@@_act:NNNnn} when changing case (to record
-% which direction the change is in), but not when reversing the tokens.
-% \begin{macrocode}
-\cs_new:Npn \tl_reverse:n #1
- {
- \__kernel_exp_not:w \exp_after:wN
- {
- \exp:w
- \@@_act:NNNnn
- \@@_reverse_normal:nN
- \@@_reverse_group_preserve:nn
- \@@_reverse_space:n
- { }
- {#1}
- }
- }
-\cs_generate_variant:Nn \tl_reverse:n { o , V }
-\cs_new:Npn \@@_reverse_normal:nN #1#2
- { \@@_act_reverse_output:n {#2} }
-\cs_new:Npn \@@_reverse_group_preserve:nn #1#2
- { \@@_act_reverse_output:n { {#2} } }
-\cs_new:Npn \@@_reverse_space:n #1
- { \@@_act_reverse_output:n { ~ } }
-% \end{macrocode}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-%
-% \begin{macro}{\tl_reverse:N, \tl_reverse:c, \tl_greverse:N, \tl_greverse:c}
-% This reverses the list, leaving \cs{exp_stop_f:} in front,
-% which stops the \texttt{f}-expansion.
-% \begin{macrocode}
-\cs_new_protected:Npn \tl_reverse:N #1
- { \__kernel_tl_set:Nx #1 { \exp_args:No \tl_reverse:n { #1 } } }
-\cs_new_protected:Npn \tl_greverse:N #1
- { \__kernel_tl_gset:Nx #1 { \exp_args:No \tl_reverse:n { #1 } } }
-\cs_generate_variant:Nn \tl_reverse:N { c }
-\cs_generate_variant:Nn \tl_greverse:N { c }
-% \end{macrocode}
-% \end{macro}
-%
% \subsection{The first token from a token list}
%
% \begin{macro}{\tl_head:N, \tl_head:n, \tl_head:V, \tl_head:v, \tl_head:f}
@@ -3329,6 +3141,194 @@
% \end{macro}
% \end{macro}
%
+% \subsection{Token by token changes}
+%
+% \begin{variable}{\q_@@_act_stop}
+% The \cs[no-index]{@@_act_\ldots{}} functions may be applied to any token list.
+% Hence, we use a private quark, to allow any token, even quarks,
+% in the token list.
+% Only \cs{q_@@_act_stop} may not appear in the token lists manipulated by
+% \cs{@@_act:NNNnn} functions.
+% \begin{macrocode}
+\quark_new:N \q_@@_act_stop
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}[EXP]{\@@_act:NNNnn}
+% \begin{macro}[EXP]{\@@_act_output:n, \@@_act_reverse_output:n}
+% \begin{macro}[EXP]{\@@_act_loop:w}
+% \begin{macro}[EXP]{\@@_act_normal:NwnNNN}
+% \begin{macro}[EXP]{\@@_act_group:nwnNNN}
+% \begin{macro}[EXP]{\@@_act_space:wwnNNN}
+% \begin{macro}[EXP]{\@@_act_end:w}
+% \begin{macro}[EXP]
+% {
+% \@@_act_if_head_is_space:nTF,
+% \@@_act_if_head_is_space:w,
+% \@@_act_if_head_is_space_true:w
+% }
+% \begin{macro}[EXP]{\@@_use_none_delimit_by_q_act_stop:w}
+% To help control the expansion, \cs{@@_act:NNNnn} should always
+% be proceeded by \cs{exp:w} and ends by producing \cs{exp_end:}
+% once the result has been obtained. Then loop over tokens,
+% groups, and spaces in |#5|. |{\q_@@_act_stop}| serves as the end of token
+% list marker, the |?| after it avoids losing outer braces. The result is
+% stored as an argument for the dummy function \cs{@@_act_result:n}.
+% \begin{macrocode}
+\cs_new:Npn \@@_act:NNNnn #1#2#3#4#5
+ {
+ \group_align_safe_begin:
+ \@@_act_loop:w #5 {\q_@@_act_stop} ? \q_@@_act_stop
+ {#4} #1 #3 #2
+ \@@_act_result:n { }
+ }
+% \end{macrocode}
+% Because \cs{q_@@_act_stop} can't appear without braces around it in the
+% argument~|#1| of \cs{@@_act_loop:w}, we can use this marker to set up a fast
+% test for leading spaces.
+% \begin{macrocode}
+\group_begin:
+ \cs_set:Npn \@@_tmp:n #1
+ {
+ \cs_new:Npn \@@_act_if_head_is_space:nTF ##1
+ {
+ \@@_act_if_head_is_space:w
+ \q_@@_act_stop ##1 \q_@@_act_stop \@@_act_if_head_is_space_true:w
+ \q_@@_act_stop #1 \q_@@_act_stop \use_ii:nn
+ }
+ \cs_new:Npn \@@_act_if_head_is_space:w
+ ##1 \q_@@_act_stop #1 ##2 \q_@@_act_stop
+ {}
+ \cs_new:Npn \@@_act_if_head_is_space_true:w
+ \q_@@_act_stop #1 \q_@@_act_stop \use_ii:nn ##1 ##2
+ {##1}
+ }
+ \@@_tmp:n { ~ }
+\group_end:
+% \end{macrocode}
+% In the loop, we check how the token list begins and act
+% accordingly. In the \enquote{group} case, we may have
+% reached \cs{q_@@_act_stop}, the end of the list. Then
+% leave \cs{exp_end:} and the result in the input stream,
+% to terminate the expansion of \cs{exp:w}.
+% Otherwise, apply the relevant function to the
+% \enquote{arguments}, |#3|
+% and to the head of the token list. Then repeat the loop.
+% The scheme is the same if the token list starts with an |N|-type
+% or with a space. Some extra work is needed to
+% make \cs{@@_act_space:wwnNNN} gobble the space.
+% \begin{macrocode}
+\group_begin:
+ \cs_set_nopar:Npx \@@_tmp:
+ {
+ \__kernel_exp_not:w \exp_after:wN { \@@_act_if_head_is_space:nTF {#1} }
+ { \exp_not:N \@@_act_space:wwnNNN }
+ {
+ \__kernel_exp_not:w \exp_after:wN { \tl_if_head_is_group:nTF {#1} }
+ { \exp_not:N \@@_act_group:nwnNNN }
+ { \exp_not:N \@@_act_normal:NwnNNN }
+ }
+ }
+ \exp_args:Nno \use:n { \cs_new:Npn \@@_act_loop:w #1 \q_@@_act_stop }
+ {
+ \@@_tmp:
+ #1 \q_@@_act_stop
+ }
+\group_end:
+\cs_new:Npn \@@_act_normal:NwnNNN #1 #2 \q_@@_act_stop #3#4
+ {
+ #4 {#3} #1
+ \@@_act_loop:w #2 \q_@@_act_stop
+ {#3} #4
+ }
+\cs_new:Npn \@@_use_none_delimit_by_q_act_stop:w #1 \q_@@_act_stop { }
+\cs_new:Npn \@@_act_end:wn #1 \@@_act_result:n #2
+ { \group_align_safe_end: \exp_end: #2 }
+\cs_new:Npn \@@_act_group:nwnNNN #1 #2 \q_@@_act_stop #3#4#5#6
+ {
+ \@@_use_none_delimit_by_q_act_stop:w #1 \@@_act_end:wn \q_@@_act_stop
+ #6 {#3} {#1}
+ \@@_act_loop:w #2 \q_@@_act_stop
+ {#3} #4 #5 #6
+ }
+\exp_last_unbraced:NNo
+ \cs_new:Npn \@@_act_space:wwnNNN \c_space_tl #1 \q_@@_act_stop #2#3#4
+ {
+ #4 {#2}
+ \@@_act_loop:w #1 \q_@@_act_stop
+ {#2} #3 #4
+ }
+% \end{macrocode}
+% Typically, the output is done to the right of what was already output,
+% using \cs{@@_act_output:n}, but for the \cs{@@_act_reverse} functions,
+% it should be done to the left.
+% \begin{macrocode}
+\cs_new:Npn \@@_act_output:n #1 #2 \@@_act_result:n #3
+ { #2 \@@_act_result:n { #3 #1 } }
+\cs_new:Npn \@@_act_reverse_output:n #1 #2 \@@_act_result:n #3
+ { #2 \@@_act_result:n { #1 #3 } }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}[EXP]{\tl_reverse:n, \tl_reverse:o, \tl_reverse:V}
+% \begin{macro}[EXP]{\@@_reverse_normal:nN}
+% \begin{macro}[EXP]{\@@_reverse_group_preserve:nn}
+% \begin{macro}[EXP]{\@@_reverse_space:n}
+% The goal here is to reverse without losing spaces nor braces.
+% This is done using the general internal function \cs{@@_act:NNNnn}.
+% Spaces and \enquote{normal} tokens are output on the left of the current
+% output. Grouped tokens are output to the left but without any reversal
+% within the group. All of the internal functions here drop one argument:
+% this is needed by \cs{@@_act:NNNnn} when changing case (to record
+% which direction the change is in), but not when reversing the tokens.
+% \begin{macrocode}
+\cs_new:Npn \tl_reverse:n #1
+ {
+ \__kernel_exp_not:w \exp_after:wN
+ {
+ \exp:w
+ \@@_act:NNNnn
+ \@@_reverse_normal:nN
+ \@@_reverse_group_preserve:nn
+ \@@_reverse_space:n
+ { }
+ {#1}
+ }
+ }
+\cs_generate_variant:Nn \tl_reverse:n { o , V }
+\cs_new:Npn \@@_reverse_normal:nN #1#2
+ { \@@_act_reverse_output:n {#2} }
+\cs_new:Npn \@@_reverse_group_preserve:nn #1#2
+ { \@@_act_reverse_output:n { {#2} } }
+\cs_new:Npn \@@_reverse_space:n #1
+ { \@@_act_reverse_output:n { ~ } }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\tl_reverse:N, \tl_reverse:c, \tl_greverse:N, \tl_greverse:c}
+% This reverses the list, leaving \cs{exp_stop_f:} in front,
+% which stops the \texttt{f}-expansion.
+% \begin{macrocode}
+\cs_new_protected:Npn \tl_reverse:N #1
+ { \__kernel_tl_set:Nx #1 { \exp_args:No \tl_reverse:n { #1 } } }
+\cs_new_protected:Npn \tl_greverse:N #1
+ { \__kernel_tl_gset:Nx #1 { \exp_args:No \tl_reverse:n { #1 } } }
+\cs_generate_variant:Nn \tl_reverse:N { c }
+\cs_generate_variant:Nn \tl_greverse:N { c }
+% \end{macrocode}
+% \end{macro}
+%
% \subsection{Using a single item}
%
% \begin{macro}{\tl_item:nn, \tl_item:Nn, \tl_item:cn}
More information about the latex3-commits
mailing list.