[latex3-commits] [git/LaTeX3-latex3-latex3] peek-refactor: Add \peek_remove_filler:n (9396d9fbe)
Joseph Wright
joseph.wright at morningstar2.co.uk
Mon Jan 10 09:10:48 CET 2022
Repository : https://github.com/latex3/latex3
On branch : peek-refactor
Link : https://github.com/latex3/latex3/commit/9396d9fbef742a4b72f6808d4aab3c929c7e4434
>---------------------------------------------------------------
commit 9396d9fbef742a4b72f6808d4aab3c929c7e4434
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Mon Jan 10 08:10:48 2022 +0000
Add \peek_remove_filler:n
>---------------------------------------------------------------
9396d9fbef742a4b72f6808d4aab3c929c7e4434
l3kernel/CHANGELOG.md | 3 ++
l3kernel/l3token.dtx | 71 ++++++++++++++++++++++++++++++++++
l3kernel/testfiles/m3peek001.lvt | 7 ++++
l3kernel/testfiles/m3peek001.ptex.tlg | 7 ++++
l3kernel/testfiles/m3peek001.tlg | 7 ++++
l3kernel/testfiles/m3peek001.uptex.tlg | 7 ++++
6 files changed, 102 insertions(+)
diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 1b8fce174..e28d174ff 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -7,6 +7,9 @@ this project uses date-based 'snapshot' version identifiers.
## [Unreleased]
+### Added
+- `\peek_remove_filler:n`
+
### Changed
- Move some color functions from `l3backend`
diff --git a/l3kernel/l3token.dtx b/l3kernel/l3token.dtx
index fa4db072c..b7977637a 100644
--- a/l3kernel/l3token.dtx
+++ b/l3kernel/l3token.dtx
@@ -904,6 +904,26 @@
% appropriate to the result of the test).
% \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$ and character code $32) 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{texnotex}
+% 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 ends the \meta{filler}.
+% \end{texnote}
+% \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}
@@ -2828,6 +2848,57 @@ 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
+ }
+\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:
+ }
+\cs_new_protected:Npn \@@_remove_filler_expand:w
+ {
+ \token_if_expandable:NTF \l_peek_token
+ { \@@_remove_filler:w }
+ { \@@_false:w }
+ }
+% \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
diff --git a/l3kernel/testfiles/m3peek001.lvt b/l3kernel/testfiles/m3peek001.lvt
index e275df6d8..6ed053154 100644
--- a/l3kernel/testfiles/m3peek001.lvt
+++ b/l3kernel/testfiles/m3peek001.lvt
@@ -189,6 +189,13 @@
\tex_lowercase:D { \peek_remove_spaces:n { \tex_show:D } ~ }
}
+
+\TEST { \peek_remove_filler:n }
+ {
+ \tl_set:Nx \l_tmpa_tl { \use:n { \scan_stop: \c_space_tl } ~ \scan_stop: }
+ \use:n { \peek_remove_filler:n { \tex_show:D } ~ \c_space_token } ~ \c_space_tl
+ \l_tmpa_tl _
+ }
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\END
diff --git a/l3kernel/testfiles/m3peek001.ptex.tlg b/l3kernel/testfiles/m3peek001.ptex.tlg
index 061ffe46f..622d8d5fb 100644
--- a/l3kernel/testfiles/m3peek001.ptex.tlg
+++ b/l3kernel/testfiles/m3peek001.ptex.tlg
@@ -169,3 +169,10 @@ l. ... }
<recently read> *
l. ... }
============================================================
+============================================================
+TEST 12: \peek_remove_filler:n
+============================================================
+> the letter _.
+<recently read> _
+l. ... }
+============================================================
diff --git a/l3kernel/testfiles/m3peek001.tlg b/l3kernel/testfiles/m3peek001.tlg
index 061ffe46f..622d8d5fb 100644
--- a/l3kernel/testfiles/m3peek001.tlg
+++ b/l3kernel/testfiles/m3peek001.tlg
@@ -169,3 +169,10 @@ l. ... }
<recently read> *
l. ... }
============================================================
+============================================================
+TEST 12: \peek_remove_filler:n
+============================================================
+> the letter _.
+<recently read> _
+l. ... }
+============================================================
diff --git a/l3kernel/testfiles/m3peek001.uptex.tlg b/l3kernel/testfiles/m3peek001.uptex.tlg
index 061ffe46f..622d8d5fb 100644
--- a/l3kernel/testfiles/m3peek001.uptex.tlg
+++ b/l3kernel/testfiles/m3peek001.uptex.tlg
@@ -169,3 +169,10 @@ l. ... }
<recently read> *
l. ... }
============================================================
+============================================================
+TEST 12: \peek_remove_filler:n
+============================================================
+> the letter _.
+<recently read> _
+l. ... }
+============================================================
More information about the latex3-commits
mailing list.