[latex3-commits] [git/LaTeX3-latex3-latex3] master: fix #808 (3db75c3f8)
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/3db75c3f835a5e78617e0f365b3587a6e4c7bfab
>---------------------------------------------------------------
commit 3db75c3f835a5e78617e0f365b3587a6e4c7bfab
Author: Jonathan Spratte <jspratte at yahoo.de>
Date: Sat Sep 19 22:14:44 2020 +0200
fix #808
>---------------------------------------------------------------
3db75c3f835a5e78617e0f365b3587a6e4c7bfab
l3kernel/l3tl.dtx | 57 +++++++++++++++++++++++++++++++++++--------------------
1 file changed, 36 insertions(+), 21 deletions(-)
diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index f8e2e8a40..5f97365c8 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -3042,6 +3042,8 @@
% \begin{macro}[pTF]{\tl_if_head_eq_charcode:nN}
% \begin{macro}[pTF]{\tl_if_head_eq_charcode:fN}
% \begin{macro}[pTF]{\tl_if_head_eq_catcode:nN}
+% \begin{macro}[EXP]{\@@_head_exp_not:w}
+% \begin{macro}[EXP]{\@@_if_head_eq_empty_arg:w}
% Accessing the first token of a token list is tricky in three cases:
% when it has category code $1$ (begin-group token), when it is an
% explicit space, with category code $10$ and character code $32$, or
@@ -3061,21 +3063,17 @@
% cases, the first token is a character, and since we only care about
% its character code, we can use \cs{str_head:n} to access it (this
% works even if it is a space character). An empty argument
-% results in \cs{tl_head:w} leaving two tokens: |?| which is taken in
-% the \cs{if_charcode:w} test, and \cs{use_none:nn}, which ensures
-% that \cs{prg_return_false:} is returned regardless of whether the
-% charcode test was \texttt{true} or \texttt{false}.
+% results in \cs{tl_head:w} leaving two token: |^| and
+% \cs{@@_if_head_eq_empty_arg:w} which will result in the \cs{if_charcode:w}
+% test being false and remove \cs{exp_not:N} and |#2|.
% \begin{macrocode}
\prg_new_conditional:Npnn \tl_if_head_eq_charcode:nN #1#2 { p , T , F , TF }
{
\if_charcode:w
- \exp_not:N #2
\tl_if_head_is_N_type:nTF { #1 ? }
- {
- \exp_after:wN \exp_not:N
- \@@_tl_head:w #1 { ? \use_none:nn } \s_@@_stop
- }
+ { \@@_head_exp_not:w #1 { ^ \@@_if_head_eq_empty_arg:w } \s_@@_stop }
{ \str_head:n {#1} }
+ \exp_not:N #2
\prg_return_true:
\else:
\prg_return_false:
@@ -3089,24 +3087,20 @@
% first token is a begin-group token or an explicit space token, and
% produce the relevant token, either \cs{c_group_begin_token} or
% \cs{c_space_token}. Again, for an empty argument, a hack is used,
-% removing \cs{prg_return_true:} and \cs{else:} with \cs{use_none:nn}
-% in case the catcode test with the (arbitrarily chosen) |?| is
-% \texttt{true}.
+% removing the token given by the user and leaving two tokens in the input
+% stream which will make the \cs{if_catcode:w} test return \texttt{false}.
% \begin{macrocode}
\prg_new_conditional:Npnn \tl_if_head_eq_catcode:nN #1 #2 { p , T , F , TF }
{
\if_catcode:w
- \exp_not:N #2
\tl_if_head_is_N_type:nTF { #1 ? }
- {
- \exp_after:wN \exp_not:N
- \@@_tl_head:w #1 { ? \use_none:nn } \s_@@_stop
- }
+ { \@@_head_exp_not:w #1 { ^ \@@_if_head_eq_empty_arg:w } \s_@@_stop }
{
\tl_if_head_is_group:nTF {#1}
- { \c_group_begin_token }
- { \c_space_token }
+ \c_group_begin_token
+ \c_space_token
}
+ \exp_not:N #2
\prg_return_true:
\else:
\prg_return_false:
@@ -3129,8 +3123,8 @@
\prg_new_conditional:Npnn \tl_if_head_eq_meaning:nN #1#2 { p , T , F , TF }
{
\tl_if_head_is_N_type:nTF { #1 ? }
- { \@@_if_head_eq_meaning_normal:nN }
- { \@@_if_head_eq_meaning_special:nN }
+ \@@_if_head_eq_meaning_normal:nN
+ \@@_if_head_eq_meaning_special:nN
{#1} #2
}
\cs_new:Npn \@@_if_head_eq_meaning_normal:nN #1 #2
@@ -3162,6 +3156,27 @@
}
}
% \end{macrocode}
+%
+% Both \cs{tl_if_head_eq_charcode:nN} and \cs{tl_if_head_eq_catcode:nN} will
+% need to get the first token of their argument and apply \cs{exp_not:N} to
+% it. \cs{@@_head_exp_not:w} does exactly that.
+% \begin{macrocode}
+\cs_new:Npn \@@_head_exp_not:w #1 #2 \s_@@_stop
+ { \exp_not:N #1 }
+% \end{macrocode}
+%
+% If the argument of \cs{tl_if_head_eq_charcode:nN} and
+% \cs{tl_if_head_eq_catcode:nN} was empty \cs{@@_if_head_eq_empty_arg:w} will
+% be left in the input stream. This macro has to remove \cs{exp_not:N} and
+% the following token from the input stream to make sure no unbalanced
+% if-construct is created and leave tokens there which make the two tests
+% return \texttt{false}.
+% \begin{macrocode}
+\cs_new:Npn \@@_if_head_eq_empty_arg:w \exp_not:N #1
+ { ? }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
More information about the latex3-commits
mailing list.