summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/l3kernel/l3token.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/l3kernel/l3token.dtx')
-rw-r--r--macros/latex/contrib/l3kernel/l3token.dtx205
1 files changed, 98 insertions, 107 deletions
diff --git a/macros/latex/contrib/l3kernel/l3token.dtx b/macros/latex/contrib/l3kernel/l3token.dtx
index e438173651..42236e0021 100644
--- a/macros/latex/contrib/l3kernel/l3token.dtx
+++ b/macros/latex/contrib/l3kernel/l3token.dtx
@@ -2,7 +2,7 @@
%
%% File: l3token.dtx
%
-% Copyright (C) 2005-2021 The LaTeX Project
+% Copyright (C) 2005-2022 The LaTeX Project
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -43,7 +43,7 @@
% }^^A
% }
%
-% \date{Released 2021-11-22}
+% \date{Released 2022-01-12}
%
% \maketitle
%
@@ -841,19 +841,6 @@
% result of the test).
% \end{function}
%
-% \begin{function}[updated = 2012-12-20, TF]{\peek_catcode_ignore_spaces:N}
-% \begin{syntax}
-% \cs{peek_catcode_ignore_spaces:NTF} \meta{test token} \Arg{true code} \Arg{false code}
-% \end{syntax}
-% Tests if the next non-space \meta{token} in the input stream has the
-% same category code as the \meta{test token} (as defined by the test
-% \cs{token_if_eq_catcode:NNTF}). Explicit and implicit space tokens
-% (with character code 32 and category code 10) are ignored and
-% removed by the test and the \meta{token} is left in the input
-% stream after the \meta{true code} or \meta{false code} (as
-% appropriate to the result of the test).
-% \end{function}
-%
% \begin{function}[updated = 2012-12-20, TF]{\peek_catcode_remove:N}
% \begin{syntax}
% \cs{peek_catcode_remove:NTF} \meta{test token} \Arg{true code} \Arg{false code}
@@ -867,21 +854,6 @@
% appropriate to the result of the test).
% \end{function}
%
-% \begin{function}[updated = 2012-12-20, TF]
-% {\peek_catcode_remove_ignore_spaces:N}
-% \begin{syntax}
-% \cs{peek_catcode_remove_ignore_spaces:NTF} \meta{test token} \Arg{true code} \Arg{false code}
-% \end{syntax}
-% Tests if the next non-space \meta{token} in the input stream has the
-% same category code as the \meta{test token} (as defined by the test
-% \cs{token_if_eq_catcode:NNTF}). Explicit and implicit space tokens
-% (with character code 32 and category code 10) are ignored and
-% removed by the test and the \meta{token} is removed from the
-% input stream if the test is true. The function then places
-% either the \meta{true code} or \meta{false code} in the input stream
-% (as appropriate to the result of the test).
-% \end{function}
-%
% \begin{function}[updated = 2012-12-20, TF]{\peek_charcode:N}
% \begin{syntax}
% \cs{peek_charcode:NTF} \meta{test token} \Arg{true code} \Arg{false code}
@@ -894,19 +866,6 @@
% result of the test).
% \end{function}
%
-% \begin{function}[updated = 2012-12-20, TF]{\peek_charcode_ignore_spaces:N}
-% \begin{syntax}
-% \cs{peek_charcode_ignore_spaces:NTF} \meta{test token} \Arg{true code} \Arg{false code}
-% \end{syntax}
-% Tests if the next non-space \meta{token} in the input stream has the
-% same character code as the \meta{test token} (as defined by the test
-% \cs{token_if_eq_charcode:NNTF}). Explicit and implicit space tokens
-% (with character code 32 and category code 10) are ignored and removed by
-% the test and the \meta{token} is left in the input stream after
-% the \meta{true code} or \meta{false code} (as appropriate to the
-% result of the test).
-% \end{function}
-%
% \begin{function}[updated = 2012-12-20, TF]{\peek_charcode_remove:N}
% \begin{syntax}
% \cs{peek_charcode_remove:NTF} \meta{test token} \Arg{true code} \Arg{false code}
@@ -920,22 +879,6 @@
% appropriate to the result of the test).
% \end{function}
%
-% \begin{function}[updated = 2012-12-20, TF]
-% {\peek_charcode_remove_ignore_spaces:N}
-% \begin{syntax}
-% \cs{peek_charcode_remove_ignore_spaces:NTF} \meta{test token}
-% ~~\Arg{true code} \Arg{false code}
-% \end{syntax}
-% Tests if the next non-space \meta{token} in the input stream has the
-% same character code as the \meta{test token} (as defined by the test
-% \cs{token_if_eq_charcode:NNTF}). Explicit and implicit space tokens
-% (with character code 32 and category code 10) are ignored and
-% removed by the test and the \meta{token} is removed from the
-% input stream if the test is true. The function then places
-% either the \meta{true code} or \meta{false code} in the input stream
-% (as appropriate to the result of the test).
-% \end{function}
-%
% \begin{function}[updated = 2011-07-02, TF]{\peek_meaning:N}
% \begin{syntax}
% \cs{peek_meaning:NTF} \meta{test token} \Arg{true code} \Arg{false code}
@@ -948,19 +891,6 @@
% result of the test).
% \end{function}
%
-% \begin{function}[updated = 2012-12-05, TF]{\peek_meaning_ignore_spaces:N}
-% \begin{syntax}
-% \cs{peek_meaning_ignore_spaces:NTF} \meta{test token} \Arg{true code} \Arg{false code}
-% \end{syntax}
-% Tests if the next non-space \meta{token} in the input stream has the
-% same meaning as the \meta{test token} (as defined by the test
-% \cs{token_if_eq_meaning:NNTF}). Explicit and implicit space tokens
-% (with character code 32 and category code 10) are ignored and
-% removed by the test and the \meta{token} is left in the input
-% stream after the \meta{true code} or \meta{false code} (as
-% appropriate to the result of the test).
-% \end{function}
-%
% \begin{function}[updated = 2011-07-02, TF]{\peek_meaning_remove:N}
% \begin{syntax}
% \cs{peek_meaning_remove:NTF} \meta{test token} \Arg{true code} \Arg{false code}
@@ -974,6 +904,40 @@
% appropriate to the result of the test).
% \end{function}
%
+% \begin{function}[added = 2018-10-01]{\peek_remove_spaces:n}
+% \begin{syntax}
+% \cs{peek_remove_spaces:n} \Arg{code}
+% \end{syntax}
+% Peeks ahead and detect if the following token is a space (category code
+% $10$ and character code $32$). If so, removes the token and checks the
+% next token. Once a non-space token is found, the \meta{code} will be
+% inserted into the input stream. Typically this will contain a \texttt{peek}
+% operation, but this is not required.
+% \end{function}
+%
+% \begin{function}[added = 2022-01-10]{\peek_remove_filler:n}
+% \begin{syntax}
+% \cs{peek_remove_filler:n} \Arg{code}
+% \end{syntax}
+% Peeks ahead and detect if the following token is a space (category code
+% $10$) or has meaning equal to \cs{scan_stop:}. If so,
+% removes the token and checks the next token. If neither of these cases
+% apply, expands the next token using \texttt{f}-type expansion, then checks
+% the resulting leading token in the same way. If after expansion the next
+% token is neither of the two test cases, the \meta{code} will be inserted
+% into the input stream. Typically this will contain a \texttt{peek}
+% operation, but this is not required.
+% \begin{texnote}
+% This is essentially a macro-based implementation of how \TeX{} handles
+% the search for a left brace after for example \tn{everypar}, except that
+% any non-expandable token cleanly ends the \meta{filler} (i.e.~it does not
+% lead to a \TeX{} error).
+%
+% In contrast to \TeX{}'s filler removal, a construct
+% \verb|\exp_not:N \foo| will be treated in the same way as \verb|\foo|.
+% \end{texnote}
+% \end{function}
+%
% \begin{function}[updated = 2012-12-05, TF]
% {\peek_meaning_remove_ignore_spaces:N}
% \begin{syntax}
@@ -2914,6 +2878,68 @@ end
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\peek_remove_filler:n}
+% \begin{macro}{\@@_remove_filler:w}
+% \begin{macro}{\@@_remove_filler:}
+% \begin{macro}{\@@_remove_filler_expand:w}
+% Here we expand the input, removing spaces and \cs{scan_stop:} tokens until
+% we reach a non-expandable token. At that stage we re-insert the payload.
+% To deal with the problem of |&| tokens, we have to put the align-safe
+% group in the correct place.
+% \begin{macrocode}
+\cs_new_protected:Npn \peek_remove_filler:n #1
+ {
+ \cs_set:Npn \@@_true_aux:w { \@@_remove_filler:w }
+ \cs_set:Npx \@@_false:w
+ {
+ \exp_not:N \group_align_safe_end:
+ \exp_not:n {#1}
+ }
+ \group_align_safe_begin:
+ \@@_remove_filler:w
+ }
+\cs_new_protected:Npn \@@_remove_filler:w
+ {
+ \exp_after:wN \peek_after:Nw \exp_after:wN \@@_remove_filler:
+ \exp:w \exp_end_continue_f:w
+ }
+% \end{macrocode}
+% Here we can nest conditionals as \cs{l_peek_token} is only skipped over in
+% the nested one if it's a space: no problems with conditionals or outer
+% tokens.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_remove_filler:
+ {
+ \if_catcode:w \exp_not:N \l_peek_token \c_space_token
+ \exp_after:wN \@@_true_remove:w
+ \else:
+ \if_meaning:w \l_peek_token \scan_stop:
+ \exp_after:wN \exp_after:wN \exp_after:wN
+ \@@_true_remove:w
+ \else:
+ \exp_after:wN \exp_after:wN \exp_after:wN
+ \@@_remove_filler_expand:w
+ \fi:
+ \fi:
+ }
+% \end{macrocode}
+% To deal with undefined control sequences in the same way \TeX{} does,
+% we need to check for expansion manually.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_remove_filler_expand:w
+ {
+ \exp_after:wN \if_meaning:w \exp_not:N \l_peek_token \l_peek_token
+ \exp_after:wN \@@_false:w
+ \else:
+ \exp_after:wN \@@_remove_filler:w
+ \fi:
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
% \begin{macro}{\@@_token_generic_aux:NNNTF}
% The generic functions store the test token in both implicit and
% explicit modes, and the \texttt{true} and \texttt{false} code as
@@ -3080,41 +3106,6 @@ end
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}[TF]
-% {
-% \peek_catcode_ignore_spaces:N, \peek_catcode_remove_ignore_spaces:N,
-% \peek_charcode_ignore_spaces:N, \peek_charcode_remove_ignore_spaces:N,
-% \peek_meaning_ignore_spaces:N, \peek_meaning_remove_ignore_spaces:N
-% }
-% To ignore spaces, remove them using \cs{peek_remove_spaces:n}
-% before running the tests.
-% \begin{macrocode}
-\tl_map_inline:nn
- {
- { catcode } { catcode_remove }
- { charcode } { charcode_remove }
- { meaning } { meaning_remove }
- }
- {
- \cs_new_protected:cpx { peek_#1_ignore_spaces:NTF } ##1##2##3
- {
- \peek_remove_spaces:n
- { \exp_not:c { peek_#1:NTF } ##1 {##2} {##3} }
- }
- \cs_new_protected:cpx { peek_#1_ignore_spaces:NT } ##1##2
- {
- \peek_remove_spaces:n
- { \exp_not:c { peek_#1:NT } ##1 {##2} }
- }
- \cs_new_protected:cpx { peek_#1_ignore_spaces:NF } ##1##2
- {
- \peek_remove_spaces:n
- { \exp_not:c { peek_#1:NF } ##1 {##2} }
- }
- }
-% \end{macrocode}
-% \end{macro}
-%
% \begin{macro}[TF]{\peek_N_type:}
% \begin{macro}
% {\@@_execute_branches_N_type:, \@@_N_type:w, \@@_N_type_aux:nnw}