[latex3-commits] [git/LaTeX3-latex3-latex3] master: Tweak some brace tricks to ensure braces remain always balanced (dd6d03e)
Bruno Le Floch
bruno at le-floch.fr
Thu Feb 28 09:41:15 CET 2019
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/dd6d03e86bca9f387874227eb334db25fe4ab646
>---------------------------------------------------------------
commit dd6d03e86bca9f387874227eb334db25fe4ab646
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Thu Feb 28 09:41:15 2019 +0100
Tweak some brace tricks to ensure braces remain always balanced
>---------------------------------------------------------------
dd6d03e86bca9f387874227eb334db25fe4ab646
l3kernel/l3candidates.dtx | 2 +-
l3kernel/l3expan.dtx | 5 +++++
l3kernel/l3tl.dtx | 21 +++++++++++++--------
l3kernel/source3body.tex | 2 +-
4 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index 01e8ceb..aca1af3 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -2477,8 +2477,8 @@
\prg_return_false:
}
{
- \if_false: { \fi:
\group_begin:
+ \if_false: { \fi:
\int_set_eq:NN \tex_tracingnesting:D \c_zero_int
\exp_args:No \tex_everyeof:D { \c_@@_marker_tl }
#2 \scan_stop:
diff --git a/l3kernel/l3expan.dtx b/l3kernel/l3expan.dtx
index c93e326..e15fefa 100644
--- a/l3kernel/l3expan.dtx
+++ b/l3kernel/l3expan.dtx
@@ -1790,6 +1790,11 @@
% stream, followed by the result of the expansion. There are many
% special cases: spaces, brace groups, \tn{noexpand}, \tn{unexpanded},
% \tn{the}, \tn{primitive}.
+% While we use brace tricks \cs{if_false:} |{| \cs{fi:}, the expansion
+% of this function is always triggered by \cs{exp:w} so brace balance
+% is eventually restored after that is hit with a single step of
+% expansion. Otherwise we could not nest \texttt{e}-type expansions
+% within each other.
% \begin{macrocode}
\cs_new:Npn \@@_e:nn #1
{
diff --git a/l3kernel/l3tl.dtx b/l3kernel/l3tl.dtx
index 1cecc62..c4465ad 100644
--- a/l3kernel/l3tl.dtx
+++ b/l3kernel/l3tl.dtx
@@ -1581,6 +1581,10 @@
%
% The two \cs{if_false:} \ldots{} \cs{fi:} are there to prevent
% alignment tabs to cause a change of tabular cell while rescanning.
+% We put the \enquote{opening} one after \cs{group_begin:} so that if
+% one accidentally \texttt{f}-expands \cs{tl_set_rescan:Nnn} braces
+% remain balanced. This is essential in \texttt{e}-type arguments
+% when \tn{expanded} is not available.
% \begin{macrocode}
\cs_new_protected:Npn \tl_set_rescan:Nnn
{ \@@_set_rescan:NNnn \tl_set:No }
@@ -1594,8 +1598,8 @@
}
\cs_new_protected:Npn \@@_set_rescan:NNnn #1#2#3#4
{
- \if_false: { \fi:
\group_begin:
+ \if_false: { \fi:
\int_set_eq:NN \tex_tracingnesting:D \c_zero_int
\exp_args:No \tex_everyeof:D { \c_@@_rescan_marker_tl }
\int_compare:nNnT \tex_endlinechar:D = { 32 }
@@ -2136,9 +2140,12 @@
% groups makes the test work also for empty arguments.
% The \cs{if_false:} constructions are a faster way to do
% \cs{group_align_safe_begin:} and \cs{group_align_safe_end:}.
+% The \cs{scan_stop:} ensures that \texttt{f}-expanding
+% \cs{tl_if_in:nn} does not lead to unbalanced braces.
% \begin{macrocode}
\prg_new_protected_conditional:Npnn \tl_if_in:nn #1#2 { T , F , TF }
{
+ \scan_stop:
\if_false: { \fi:
\cs_set:Npn \@@_tmp:w ##1 #2 { }
\tl_if_empty:oTF { \@@_tmp:w #1 {} {} #2 }
@@ -2985,13 +2992,11 @@
% \end{macro}
%
% \begin{macro}[EXP,pTF]{\tl_if_head_is_group:n}
-% Pass the first token of |#1| through \cs{token_to_str:N},
-% then check for the brace balance. The extra \texttt{?}
-% caters for an empty argument.\footnote{Bruno: this could
-% be made faster, but we don't: if we hope to ever have
-% an \texttt{e}-type argument, we need all brace \enquote{tricks}
-% to happen in one step of expansion, keeping the token
-% list brace balanced at all times.}
+% Pass the first token of |#1| through \cs{token_to_str:N}, then check
+% for the brace balance. The extra \texttt{?} caters for an empty
+% argument. This could be made faster, but we need all brace tricks
+% to happen in one step of expansion, keeping the token list brace
+% balanced at all times.
% \begin{macrocode}
\prg_new_conditional:Npnn \tl_if_head_is_group:n #1 { p , T , F , TF }
{
diff --git a/l3kernel/source3body.tex b/l3kernel/source3body.tex
index cbe37a8..aa01477 100644
--- a/l3kernel/source3body.tex
+++ b/l3kernel/source3body.tex
@@ -321,7 +321,7 @@ different types of argument:
\paragraph{Fully expandable functions}
\hypertarget{expstar}{Some functions are fully expandable},
which allows them to be used within
-an \texttt{x}-type or \texttt{e}-type argument (in plain \TeX{} terms, inside an \cs{edef}),
+an \texttt{x}-type or \texttt{e}-type argument (in plain \TeX{} terms, inside an \tn{edef} or \tn{expanded}),
as well as within an \texttt{f}-type argument.
These fully expandable functions are indicated in the documentation by
a star:
More information about the latex3-commits
mailing list