summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx')
-rw-r--r--Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx133
1 files changed, 119 insertions, 14 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx b/Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx
index 43c19185279..f64f954a9f3 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3candidates.dtx
@@ -42,7 +42,7 @@
% }^^A
% }
%
-% \date{Released 2018-08-23}
+% \date{Released 2018-09-24}
%
% \maketitle
%
@@ -1467,6 +1467,39 @@
% (as appropriate to the result of the test).
% \end{function}
%
+% \begin{function}[added = 2018-09-23]
+% {
+% \peek_catcode_collect_inline:Nn,
+% \peek_charcode_collect_inline:Nn,
+% \peek_meaning_collect_inline:Nn
+% }
+% \begin{syntax}
+% \cs{peek_catcode_collect_inline:Nn} \meta{test token} \Arg{inline code}
+% \cs{peek_charcode_collect_inline:Nn} \meta{test token} \Arg{inline code}
+% \cs{peek_meaning_collect_inline:Nn} \meta{test token} \Arg{inline code}
+% \end{syntax}
+% Collects and removes tokens from the input stream until finding a
+% token that does not match the \meta{test token} (as defined by the
+% test \cs{token_if_eq_catcode:NNTF} or \cs{token_if_eq_charcode:NNTF}
+% or \cs{token_if_eq_meaning:NNTF}). The collected tokens are passed
+% to the \meta{inline code} as~|#1|. When begin-group or end-group
+% tokens (usually |{| or~|}|) are collected they are replaced by
+% implicit \cs{c_group_begin_token} and \cs{c_group_end_token}, and
+% when spaces (including \cs{c_space_token}) are collected they are
+% replaced by explicit spaces.
+%
+% For example the following code prints ``Hello'' to the terminal and
+% leave ``, world!'' in the input stream.
+% \begin{verbatim}
+% \peek_catcode_collect_inline:Nn A { \iow_term:n {#1} } Hello,~world!
+% \end{verbatim}
+% Another example is that the following code tests if the next token is |*|, ignoring intervening spaces, but putting them back using |#1| if there is no~|*|.
+% \begin{verbatim}
+% \peek_meaning_collect_inline:Nn \c_space_token
+% { \peek_charcode:NTF * { star } { no~star #1 } }
+% \end{verbatim}
+% \end{function}
+%
% \end{documentation}
%
% \begin{implementation}
@@ -1488,21 +1521,13 @@
% this will switch to horizontal mode and insert \tn{everypar} tokens and
% nothing else. Unlike the \LaTeXe{} version, the availability of \eTeX{}
% means using a mode test can be done at for example the start of an
-% \tn{halign}. The \tn{quitvmode} primitive essentially wraps the same
-% code up at the engine level.
+% \tn{halign}.
% \begin{macrocode}
-\cs_new_protected:Npx \mode_leave_vertical:
+\cs_new_protected:Npn \mode_leave_vertical:
{
- \cs_if_exist:NTF \tex_quitvmode:D
- { \tex_quitvmode:D }
- {
- \exp_not:n
- {
- \if_mode_vertical:
- \exp_after:wN \tex_indent:D
- \fi:
- }
- }
+ \if_mode_vertical:
+ \exp_after:wN \tex_indent:D
+ \fi:
}
% \end{macrocode}
% \end{macro}
@@ -5229,6 +5254,86 @@
% \end{macro}
% \end{macro}
%
+% \begin{variable}{\l_@@_collect_tl}
+% \begin{macrocode}
+\tl_new:N \l_@@_collect_tl
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}
+% {
+% \peek_catcode_collect_inline:Nn,
+% \peek_charcode_collect_inline:Nn,
+% \peek_meaning_collect_inline:Nn
+% }
+% \begin{macro}
+% {
+% \@@_collect:NNn, \@@_collect_true:w,
+% \@@_collect_remove:nw, \@@_collect:N
+% }
+% Most of the work is done by \cs{@@_execute_branches_\ldots{}:},
+% which calls either \cs{@@_true:w} or \cs{@@_false:w} according to
+% whether the next token \cs{l_peek_token} matches the search token
+% (stored in \cs{l_@@_search_token} and \cs{l_@@_search_tl}).
+% Here, in the \texttt{true} case we run \cs{@@_collect_true:w},
+% which generally calls \cs{@@_collect:N} to store the peeked token
+% into \cs{l_@@_collect_tl}, except in special non-\texttt{N}-type
+% cases (begin-group, end-group, or space), where a frozen token is
+% stored. The \texttt{true} branch calls
+% \cs{@@_execute_branches_\ldots{}:} to fetch more matching tokens.
+% Once there are no more, \cs{@@_false_aux:n} closes the safe-align
+% group and runs the user's inline code.
+% \begin{macrocode}
+\cs_new_protected:Npn \peek_catcode_collect_inline:Nn
+ { \@@_collect:NNn \@@_execute_branches_catcode: }
+\cs_new_protected:Npn \peek_charcode_collect_inline:Nn
+ { \@@_collect:NNn \@@_execute_branches_charcode: }
+\cs_new_protected:Npn \peek_meaning_collect_inline:Nn
+ { \@@_collect:NNn \@@_execute_branches_meaning: }
+\cs_new_protected:Npn \@@_collect:NNn #1#2#3
+ {
+ \group_align_safe_begin:
+ \cs_set_eq:NN \l_@@_search_token #2
+ \tl_set:Nn \l_@@_search_tl {#2}
+ \tl_clear:N \l_@@_collect_tl
+ \cs_set:Npn \@@_false:w
+ { \exp_args:No \@@_false_aux:n \l_@@_collect_tl }
+ \cs_set:Npn \@@_false_aux:n ##1
+ {
+ \group_align_safe_end:
+ #3
+ }
+ \cs_set_eq:NN \@@_true:w \@@_collect_true:w
+ \cs_set:Npn \@@_true_aux:w { \peek_after:Nw #1 }
+ \@@_true_aux:w
+ }
+\cs_new_protected:Npn \@@_collect_true:w
+ {
+ \if_case:w
+ \if_catcode:w \exp_not:N \l_peek_token { 1 \exp_stop_f: \fi:
+ \if_catcode:w \exp_not:N \l_peek_token } 2 \exp_stop_f: \fi:
+ \if_meaning:w \l_peek_token \c_space_token 3 \exp_stop_f: \fi:
+ 0 \exp_stop_f:
+ \exp_after:wN \@@_collect:N
+ \or: \@@_collect_remove:nw { \c_group_begin_token }
+ \or: \@@_collect_remove:nw { \c_group_end_token }
+ \or: \@@_collect_remove:nw { ~ }
+ \fi:
+ }
+\cs_new_protected:Npn \@@_collect:N #1
+ {
+ \tl_put_right:Nn \l_@@_collect_tl {#1}
+ \@@_true_aux:w
+ }
+\cs_new_protected:Npn \@@_collect_remove:nw #1
+ {
+ \tl_put_right:Nn \l_@@_collect_tl {#1}
+ \exp_after:wN \@@_true_remove:w
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
% \begin{macrocode}
%</initex|package>
% \end{macrocode}