summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/l3kernel/l3token.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3token.dtx')
-rw-r--r--Master/texmf-dist/source/latex/l3kernel/l3token.dtx196
1 files changed, 80 insertions, 116 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3token.dtx b/Master/texmf-dist/source/latex/l3kernel/l3token.dtx
index b5ed9de6bf9..5b31b97cbde 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3token.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3token.dtx
@@ -41,7 +41,7 @@
% }^^A
% }
%
-% \date{Released 2018-09-24}
+% \date{Released 2018-10-17}
%
% \maketitle
%
@@ -2234,6 +2234,29 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\peek_remove_spaces:n, \@@_remove_spaces:}
+% Repeatedly use \cs{@@_true_remove:w} to remove a space and call
+% \cs{@@_true_aux:w}.
+% \begin{macrocode}
+\cs_new_protected:Npn \peek_remove_spaces:n #1
+ {
+ \cs_set:Npx \@@_false:w { \exp_not:n {#1} }
+ \group_align_safe_begin:
+ \cs_set:Npn \@@_true_aux:w { \peek_after:Nw \@@_remove_spaces: }
+ \@@_true_aux:w
+ }
+\cs_new_protected:Npn \@@_remove_spaces:
+ {
+ \if_meaning:w \l_peek_token \c_space_token
+ \exp_after:wN \@@_true_remove:w
+ \else:
+ \group_align_safe_end:
+ \exp_after:wN \@@_false:w
+ \fi:
+ }
+% \end{macrocode}
+% \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
@@ -2366,131 +2389,72 @@
% \end{macro}
% \end{macro}
%
-% \begin{macro}{\@@_ignore_spaces_execute_branches:}
-% This function removes one space token at a time, and calls
-% \cs{@@_execute_branches:} when encountering the first non-space
-% token. We directly use the primitive meaning test rather than
-% \cs{token_if_eq_meaning:NNTF} because \cs{l_peek_token} may be an
-% outer macro (coming from non-\LaTeX3 packages). Spaces are removed
-% using a side-effect of \texttt{f}-expansion:
-% |\exp:w \exp_end_continue_f:w| removes one space.
-% \begin{macrocode}
-\cs_new_protected:Npn \@@_ignore_spaces_execute_branches:
- {
- \if_meaning:w \l_peek_token \c_space_token
- \exp_after:wN \peek_after:Nw
- \exp_after:wN \@@_ignore_spaces_execute_branches:
- \exp:w \exp_end_continue_f:w
- \else:
- \exp_after:wN \@@_execute_branches:
- \fi:
- }
-% \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\@@_def:nnnn}
-% \begin{macro}{\@@_def:nnnnn}
-% The public functions themselves cannot be defined using
-% \cs{prg_new_conditional:Npnn} and so a couple of auxiliary functions
-% are used. As a result, everything is done inside a group. As a result
-% things are a bit complicated.
-% \begin{macrocode}
-\group_begin:
- \cs_set:Npn \@@_def:nnnn #1#2#3#4
- {
- \@@_def:nnnnn {#1} {#2} {#3} {#4} { TF }
- \@@_def:nnnnn {#1} {#2} {#3} {#4} { T }
- \@@_def:nnnnn {#1} {#2} {#3} {#4} { F }
- }
- \cs_set:Npn \@@_def:nnnnn #1#2#3#4#5
- {
- \cs_new_protected:cpx { #1 #5 }
- {
- \tl_if_empty:nF {#2}
- { \exp_not:n { \cs_set_eq:NN \@@_execute_branches: #2 } }
- \exp_not:c { #3 #5 }
- \exp_not:n {#4}
- }
- }
-% \end{macrocode}
-% \end{macro}
-% \end{macro}
% \begin{macro}[TF]
% {
-% \peek_catcode:N, \peek_catcode_ignore_spaces:N,
-% \peek_catcode_remove:N, \peek_catcode_remove_ignore_spaces:N
+% \peek_catcode:N,
+% \peek_catcode_remove:N,
+% \peek_charcode:N,
+% \peek_charcode_remove:N,
+% \peek_meaning:N,
+% \peek_meaning_remove:N,
% }
-% With everything in place the definitions can take place. First for
-% category codes.
-% \begin{macrocode}
- \@@_def:nnnn { peek_catcode:N }
- { }
- { @@_token_generic:NN }
- { \@@_execute_branches_catcode: }
- \@@_def:nnnn { peek_catcode_ignore_spaces:N }
- { \@@_execute_branches_catcode: }
- { @@_token_generic:NN }
- { \@@_ignore_spaces_execute_branches: }
- \@@_def:nnnn { peek_catcode_remove:N }
- { }
- { @@_token_remove_generic:NN }
- { \@@_execute_branches_catcode: }
- \@@_def:nnnn { peek_catcode_remove_ignore_spaces:N }
- { \@@_execute_branches_catcode: }
- { @@_token_remove_generic:NN }
- { \@@_ignore_spaces_execute_branches: }
-% \end{macrocode}
-% \end{macro}
-% \begin{macro}[TF]
-% {
-% \peek_charcode:N, \peek_charcode_ignore_spaces:N,
-% \peek_charcode_remove:N, \peek_charcode_remove_ignore_spaces:N
-% }
-% Then for character codes.
+% The public functions themselves cannot be defined using
+% \cs{prg_new_conditional:Npnn}. Instead, the |TF|, |T|, |F| variants
+% are defined in terms of corresponding variants of
+% \cs{@@_token_generic:NNTF} or \cs{@@_token_remove_generic:NNTF},
+% with first argument one of \cs{@@_execute_branches_catcode:},
+% \cs{@@_execute_branches_charcode:}, or
+% \cs{@@_execute_branches_meaning:}.
% \begin{macrocode}
- \@@_def:nnnn { peek_charcode:N }
- { }
- { @@_token_generic:NN }
- { \@@_execute_branches_charcode: }
- \@@_def:nnnn { peek_charcode_ignore_spaces:N }
- { \@@_execute_branches_charcode: }
- { @@_token_generic:NN }
- { \@@_ignore_spaces_execute_branches: }
- \@@_def:nnnn { peek_charcode_remove:N }
- { }
- { @@_token_remove_generic:NN }
- { \@@_execute_branches_charcode: }
- \@@_def:nnnn { peek_charcode_remove_ignore_spaces:N }
- { \@@_execute_branches_charcode: }
- { @@_token_remove_generic:NN }
- { \@@_ignore_spaces_execute_branches: }
+\tl_map_inline:nn { { catcode } { charcode } { meaning } }
+ {
+ \tl_map_inline:nn { { } { _remove } }
+ {
+ \tl_map_inline:nn { { TF } { T } { F } }
+ {
+ \cs_new_protected:cpx { peek_ #1 ##1 :N ####1 }
+ {
+ \exp_not:c { @@_token ##1 _generic:NN ####1 }
+ \exp_not:c { @@_execute_branches_ #1 : }
+ }
+ }
+ }
+ }
% \end{macrocode}
% \end{macro}
+%
% \begin{macro}[TF]
% {
-% \peek_meaning:N, \peek_meaning_ignore_spaces:N,
-% \peek_meaning_remove:N, \peek_meaning_remove_ignore_spaces:N
+% \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
% }
-% Finally for meaning, with the group closed to remove the temporary
-% definition functions.
+% To ignore spaces, remove them using \cs{peek_remove_spaces:n}
+% before running the tests.
% \begin{macrocode}
- \@@_def:nnnn { peek_meaning:N }
- { }
- { @@_token_generic:NN }
- { \@@_execute_branches_meaning: }
- \@@_def:nnnn { peek_meaning_ignore_spaces:N }
- { \@@_execute_branches_meaning: }
- { @@_token_generic:NN }
- { \@@_ignore_spaces_execute_branches: }
- \@@_def:nnnn { peek_meaning_remove:N }
- { }
- { @@_token_remove_generic:NN }
- { \@@_execute_branches_meaning: }
- \@@_def:nnnn { peek_meaning_remove_ignore_spaces:N }
- { \@@_execute_branches_meaning: }
- { @@_token_remove_generic:NN }
- { \@@_ignore_spaces_execute_branches: }
-\group_end:
+\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}
%