From 6c87d764952f4d6eb0d273c68f6033a0b5536fdb Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 3 May 2019 22:30:06 +0000 Subject: l3 (3may19) git-svn-id: svn://tug.org/texlive/trunk@50972 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/source/latex/l3kernel/l3token.dtx | 93 +++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) (limited to 'Master/texmf-dist/source/latex/l3kernel/l3token.dtx') diff --git a/Master/texmf-dist/source/latex/l3kernel/l3token.dtx b/Master/texmf-dist/source/latex/l3kernel/l3token.dtx index f8d6b75ffac..17961a9129b 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3token.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3token.dtx @@ -43,7 +43,7 @@ % }^^A % } % -% \date{Released 2019-04-21} +% \date{Released 2019-05-03} % % \maketitle % @@ -931,6 +931,26 @@ % (as appropriate to the result of the test). % \end{function} % +% \begin{function}[TF, updated = 2012-12-20]{\peek_N_type:} +% \begin{syntax} +% \cs{peek_N_type:TF} \Arg{true code} \Arg{false code} +% \end{syntax} +% Tests if the next \meta{token} in the input stream can be safely +% grabbed as an \texttt{N}-type argument. The test is \meta{false} +% if the next \meta{token} is either an explicit or implicit +% begin-group or end-group token (with any character code), or +% an explicit or implicit space character (with character code $32$ +% and category code $10$), or an outer token (never used in \LaTeX3) +% and \meta{true} in all other cases. +% Note that a \meta{true} result ensures that the next \meta{token} is +% a valid \texttt{N}-type argument. However, if the next \meta{token} +% is for instance \cs{c_space_token}, the test takes the +% \meta{false} branch, even though the next \meta{token} is in fact +% a valid \texttt{N}-type argument. 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} +% % \section{Description of all possible tokens} % \label{sec:l3token:all-tokens} % @@ -2405,6 +2425,77 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}[TF]{\peek_N_type:} +% \begin{macro} +% {\@@_execute_branches_N_type:, \@@_N_type:w, \@@_N_type_aux:nnw} +% All tokens are \texttt{N}-type tokens, except in four cases: +% begin-group tokens, end-group tokens, space tokens with character +% code~$32$, and outer tokens. Since \cs{l_peek_token} might be +% outer, we cannot use the convenient \cs{bool_if:nTF} function, and +% must resort to the old trick of using \tn{ifodd} to expand a set of +% tests. The \texttt{false} branch of this test is taken if the token +% is one of the first three kinds of non-\texttt{N}-type tokens +% (explicit or implicit), thus we call \cs{@@_false:w}. In the +% \texttt{true} branch, we must detect outer tokens, without impacting +% performance too much for non-outer tokens. The first filter is to +% search for \texttt{outer} in the \tn{meaning} of \cs{l_peek_token}. +% If that is absent, \cs{use_none_delimit_by_q_stop:w} cleans up, and +% we call \cs{@@_true:w}. Otherwise, the token can be a non-outer +% macro or a primitive mark whose parameter or replacement text +% contains \texttt{outer}, it can be the primitive \tn{outer}, or it +% can be an outer token. Macros and marks would have \texttt{ma} in +% the part before the first occurrence of \texttt{outer}; the meaning +% of \tn{outer} has nothing after \texttt{outer}, contrarily to outer +% macros; and that covers all cases, calling \cs{@@_true:w} or +% \cs{@@_false:w} as appropriate. Here, there is no \meta{search +% token}, so we feed a dummy \cs{scan_stop:} to the +% \cs{@@_token_generic:NNTF} function. +% \begin{macrocode} +\group_begin: + \cs_set_protected:Npn \@@_tmp:w #1 \q_stop + { + \cs_new_protected:Npn \@@_execute_branches_N_type: + { + \if_int_odd:w + \if_catcode:w \exp_not:N \l_peek_token { 0 \exp_stop_f: \fi: + \if_catcode:w \exp_not:N \l_peek_token } 0 \exp_stop_f: \fi: + \if_meaning:w \l_peek_token \c_space_token 0 \exp_stop_f: \fi: + 1 \exp_stop_f: + \exp_after:wN \@@_N_type:w + \token_to_meaning:N \l_peek_token + \q_mark \@@_N_type_aux:nnw + #1 \q_mark \use_none_delimit_by_q_stop:w + \q_stop + \exp_after:wN \@@_true:w + \else: + \exp_after:wN \@@_false:w + \fi: + } + \cs_new_protected:Npn \@@_N_type:w ##1 #1 ##2 \q_mark ##3 + { ##3 {##1} {##2} } + } + \exp_after:wN \@@_tmp:w \tl_to_str:n { outer } \q_stop +\group_end: +\cs_new_protected:Npn \@@_N_type_aux:nnw #1 #2 #3 \fi: + { + \fi: + \tl_if_in:noTF {#1} { \tl_to_str:n {ma} } + { \@@_true:w } + { \tl_if_empty:nTF {#2} { \@@_true:w } { \@@_false:w } } + } +\cs_new_protected:Npn \peek_N_type:TF + { + \@@_token_generic:NNTF + \@@_execute_branches_N_type: \scan_stop: + } +\cs_new_protected:Npn \peek_N_type:T + { \@@_token_generic:NNT \@@_execute_branches_N_type: \scan_stop: } +\cs_new_protected:Npn \peek_N_type:F + { \@@_token_generic:NNF \@@_execute_branches_N_type: \scan_stop: } +% \end{macrocode} +% \end{macro} +% \end{macro} +% % \begin{macrocode} % % \end{macrocode} -- cgit v1.2.3