summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/l3kernel/l3tl-analysis.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/l3kernel/l3tl-analysis.dtx')
-rw-r--r--macros/latex/contrib/l3kernel/l3tl-analysis.dtx79
1 files changed, 42 insertions, 37 deletions
diff --git a/macros/latex/contrib/l3kernel/l3tl-analysis.dtx b/macros/latex/contrib/l3kernel/l3tl-analysis.dtx
index 9ff2ec04e7..62ce80c145 100644
--- a/macros/latex/contrib/l3kernel/l3tl-analysis.dtx
+++ b/macros/latex/contrib/l3kernel/l3tl-analysis.dtx
@@ -44,7 +44,7 @@
% }^^A
% }
%
-% \date{Released 2024-02-13}
+% \date{Released 2024-02-18}
%
% \maketitle
%
@@ -1216,7 +1216,7 @@
% {
% \peek_analysis_map_inline:n,
% \@@_peek_analysis_loop:NNn, \@@_peek_analysis_test:,
-% \@@_peek_analysis_exp:N, \@@_peek_analysis_exp_active:N,
+% \@@_peek_analysis_exp:N, \@@_peek_analysis_exp_aux:N,
% \@@_peek_analysis_nonexp:N, \@@_peek_analysis_cs:N,
% \@@_peek_analysis_char:N, \@@_peek_analysis_char:w,
% \@@_peek_analysis_special:, \@@_peek_analysis_retest:,
@@ -1230,9 +1230,11 @@
% Save the user's code in a control sequence that is suitable for
% nested maps. We may wish to pass to this function an \tn{outer}
% control sequence or active character; for this we will undefine
-% potentially-\tn{outer} tokens within a group, closed after the
-% function reads its arguments (for an \tn{outer} active character
-% there is no good alternative). This user's code function also
+% any expandable token (testing if it is \tn{outer} is much slower)
+% within a group, closed immediately after the function reads its
+% arguments to avoid affecting the user's code or even our peek code
+% (there is no risk of undefining \cs{group_end:} itself since that is
+% not expandable). This user's code function also
% calls the loop auxiliary, and includes the trailing
% \cs{prg_break_point:Nn} for when the user wants to stop the loop.
% The loop auxiliary must remove that break point because it must look
@@ -1261,7 +1263,11 @@
% The loop starts a group (closed by the user-code function defined
% above) with a normalized escape character, and checks if the next
% token is special or \texttt{N}-type (distinguishing expandable from
-% non-expandable tokens).
+% non-expandable tokens). The test for nonexpandable tokens in
+% \cs{@@_peek_analysis_test:} must be done after the tests for
+% begin-group, end-group, and space tokens, in case \cs{l_peek_token}
+% is either \tn{outer} or is a primitive \TeX{} conditional, as such
+% tokens cannot be skipped over correctly by conditional code.
% \begin{macrocode}
\cs_new_protected:Npn \@@_peek_analysis_loop:NNn #1#2#3
{
@@ -1317,11 +1323,9 @@
% the two cases is easy: since we have made the escape character
% printable, \cs{token_to_str:N} gives at least two characters for a
% control sequence versus a single one for an active character
-% (possibly being a space). Producing the right outcome is trickier,
-% as |#1| cannot appear in either branch of the conditional (it could
-% be \tn{outer}, or simply a \TeX{} conditional), and can only be
-% safely discarded by \cs{use_none:n} if it is first hit with
-% \cs{exp_not:N}.
+% (possibly being a space). Importantly, once we apply
+% \cs{token_to_str:N} we no longer need to worry about \tn{outer}
+% tokens.
% \begin{macrocode}
\cs_new_protected:Npn \@@_peek_analysis_exp:N #1
{
@@ -1333,22 +1337,19 @@
\exp_not:n { \__kernel_exp_not:w \exp_after:wN }
{ \exp_not:N \exp_not:N \exp_not:N #1 }
}
- \if:w \scan_stop:
- \exp_after:wN \use_none:n \token_to_str:N #1 \prg_do_nothing:
- \scan_stop:
- \exp_after:wN \exp_after:wN
- \exp_after:wN \@@_peek_analysis_exp_active:N
- \else:
- { -1 } 0
- \exp_after:wN \exp_after:wN
- \exp_after:wN \use_none:n
- \fi:
- \exp_not:N #1
+ \exp_after:wN \@@_peek_analysis_exp_aux:Nw
+ \token_to_str:N #1 \prg_do_nothing: \s_@@
}
\l_@@_peek_code_tl
}
-\cs_new:Npe \@@_peek_analysis_exp_active:N #1
- { { \exp_not:N \int_value:w `#1 } \token_to_str:N D }
+\cs_new:Npe \@@_peek_analysis_exp_aux:Nw #1#2 \s_@@
+ {
+ \exp_not:N \if:w \scan_stop: #2 \scan_stop:
+ { \exp_not:N \int_value:w `#1 } \token_to_str:N D
+ \exp_not:N \else:
+ { -1 } 0
+ \exp_not:N \fi:
+ }
% \end{macrocode}
% For normal non-expandable tokens we must distinguish characters
% (including active ones and macro parameter characters) from control
@@ -1357,10 +1358,9 @@
% sequence call the user code with suitable arguments, wrapping |#1|
% within \cs{exp_not:n} just in case it happens to be equal to a macro
% parameter character. We do not skip \cs{exp_not:n} when
-% unnecessary, because there might be situations where the argument
-% could be used by the user after further redefinitions of the token,
-% and it seems more convenient to know that \cs{exp_not:n} is always
-% used.
+% unnecessary, because this auxiliary is also called in
+% \cs{@@_peek_analysis_retest:} where we have changed some control
+% sequences or active characters to \cs{scan_stop:} temporarily.
% \begin{macrocode}
\cs_new_protected:Npn \@@_peek_analysis_nonexp:N #1
{
@@ -1389,12 +1389,17 @@
% characters to anything else than character code~$32$), then we apply
% \cs{@@_analysis_b_char:Nn}, which detects active characters by
% comparing them to \cs{tex_undefined:D}, and we must have undefined
-% the active space for this test to work ---we use an |e|-expanding
-% assignment to get the active space in the right place. Finally
-% \cs{@@_peek_analysis_char:w} puts the arguments in the correct
-% order, including \cs{exp_not:n} for macro parameter characters and
-% active characters (the latter could be macro parameter characters,
-% and it seems more uniform to always put \cs{exp_not:n}).
+% the active space (locally) for this test to work.
+% To define \cs{@@_peek_analysis_char:N} itself we use an
+% |e|-expanding assignment to get the active space in the right place
+% after making it (just for this definition) unexpandable.
+% Finally \cs{@@_peek_analysis_char:w} receives the \meta{charcode},
+% \meta{user function}, \meta{catcode}, and \meta{token}, and places
+% the arguments in the correct order. It keeps \cs{exp_not:n} for
+% macro parameter characters and active characters (the latter could
+% be macro parameter characters, and it seems more uniform to always
+% put \cs{exp_not:n}), and otherwise eliminates it by expanding once
+% with \cs{exp_args:NNNo}.
% \begin{macrocode}
\group_begin:
\char_set_active_eq:NN \ \scan_stop:
@@ -1457,7 +1462,7 @@
\cs_new_protected:Npn \@@_peek_analysis_retest:
{
\if_meaning:w \l_@@_analysis_token \scan_stop:
- \exp_after:wN \@@_peek_analysis_normal:N
+ \exp_after:wN \@@_peek_analysis_nonexp:N
\else:
\exp_after:wN \@@_peek_analysis_str:
\fi:
@@ -1607,8 +1612,8 @@
\@@_peek_analysis_collect:w
}
% \end{macrocode}
-% End by calling the user code with suitable arguments (here |#1|,
-% |#2| are \cs{fi:}), which closes the group begun early on.
+% As in all other cases, end by calling the user code with suitable
+% arguments (here |#1| is \cs{fi:}).
% \begin{macrocode}
\cs_new_protected:Npn \@@_peek_analysis_collect_end:NNNN #1#2#3#4
{