[latex3-commits] [git/LaTeX3-latex3-latex3] xparse: Tweak internals of xparse environments to track environment name (021f524)
Bruno Le Floch
bruno at le-floch.fr
Wed Feb 27 16:27:19 CET 2019
Repository : https://github.com/latex3/latex3
On branch : xparse
Link : https://github.com/latex3/latex3/commit/021f524e6b094e17add2b78aeef76948939ae626
>---------------------------------------------------------------
commit 021f524e6b094e17add2b78aeef76948939ae626
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Wed Feb 27 16:27:00 2019 +0100
Tweak internals of xparse environments to track environment name
>---------------------------------------------------------------
021f524e6b094e17add2b78aeef76948939ae626
l3packages/xparse/testfiles/xparse001.ptex.tlg | 33 +++++-----
l3packages/xparse/testfiles/xparse001.tlg | 33 +++++-----
l3packages/xparse/testfiles/xparse001.uptex.tlg | 33 +++++-----
l3packages/xparse/xparse.dtx | 74 +++++++++++++++++------
4 files changed, 103 insertions(+), 70 deletions(-)
diff --git a/l3packages/xparse/testfiles/xparse001.ptex.tlg b/l3packages/xparse/testfiles/xparse001.ptex.tlg
index 96241cb..3e0c97a 100644
--- a/l3packages/xparse/testfiles/xparse001.ptex.tlg
+++ b/l3packages/xparse/testfiles/xparse001.ptex.tlg
@@ -551,8 +551,7 @@ l. ...}
You have used \RenewDocumentEnvironment with an environment that was never
defined.
LaTeX will ignore this entire definition.
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {}\environment
-foo \environment foo code {}{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn {}{foo}{}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:->\cs_set_nopar:Npx \environment
@@ -564,8 +563,8 @@ l. ...}
============================================================
TEST 13: Valid environment declarations
============================================================
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {mmm}\environment
-foo \environment foo code {\__xparse_grab_m_3:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{mmm}{foo}{\__xparse_grab_m_3:w }{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -573,9 +572,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {som}\environment
-foo \environment foo code {\__xparse_grab_t:w *\__xparse_grab_D:w
-[]\__xparse_grab_m_1:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{som}{foo}{\__xparse_grab_t:w *\__xparse_grab_D:w []\__xparse_grab_m_1:w
+}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -583,9 +582,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn
-{so+m}\environment foo \environment foo code {\__xparse_grab_t:w
-*\__xparse_grab_D:w []\__xparse_grab_m_long:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{so+m}{foo}{\__xparse_grab_t:w *\__xparse_grab_D:w []\__xparse_grab_m_long:w
+}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -593,9 +592,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn
-{u{stop}om}\environment foo \environment foo code {\__xparse_grab_u:w
-{stop}\__xparse_grab_D:w []\__xparse_grab_m_1:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{u{stop}om}{foo}{\__xparse_grab_u:w {stop}\__xparse_grab_D:w
+[]\__xparse_grab_m_1:w }{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -603,9 +602,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {moo}\environment
-foo \environment foo code {\__xparse_grab_m_1:w \__xparse_grab_D:w
-[]\__xparse_grab_D:w []}{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{moo}{foo}{\__xparse_grab_m_1:w \__xparse_grab_D:w []\__xparse_grab_D:w
+[]}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -800,7 +799,7 @@ TEST 19: (ab)using xparse commands in csnames
l. ... }
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
-\test- \xparse function is not expandable \__xparse_start_aux:nNNnnn {D...}\foo code {\__xparse_grab_D:w ..}{{.}}{}....\cs_end:
+\test- \xparse function is not expandable \bool_set_false:N \l__xparse_environment_bool \__xparse_start_aux:NNnnnn \foo code {D...}{\__xparse_grab_D:w ..}{{.}}{}....\cs_end:
============================================================
============================================================
TEST 20: Checking for existing expandable definitions
diff --git a/l3packages/xparse/testfiles/xparse001.tlg b/l3packages/xparse/testfiles/xparse001.tlg
index c1ebb3f..a4c9216 100644
--- a/l3packages/xparse/testfiles/xparse001.tlg
+++ b/l3packages/xparse/testfiles/xparse001.tlg
@@ -551,8 +551,7 @@ l. ...}
You have used \RenewDocumentEnvironment with an environment that was never
defined.
LaTeX will ignore this entire definition.
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {}\environment
-foo \environment foo code {}{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn {}{foo}{}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:->\cs_set_nopar:Npx \environment
@@ -564,8 +563,8 @@ l. ...}
============================================================
TEST 13: Valid environment declarations
============================================================
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {mmm}\environment
-foo \environment foo code {\__xparse_grab_m_3:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{mmm}{foo}{\__xparse_grab_m_3:w }{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -573,9 +572,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {som}\environment
-foo \environment foo code {\__xparse_grab_t:w *\__xparse_grab_D:w
-[]\__xparse_grab_m_1:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{som}{foo}{\__xparse_grab_t:w *\__xparse_grab_D:w []\__xparse_grab_m_1:w
+}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -583,9 +582,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn
-{so+m}\environment foo \environment foo code {\__xparse_grab_t:w
-*\__xparse_grab_D:w []\__xparse_grab_m_long:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{so+m}{foo}{\__xparse_grab_t:w *\__xparse_grab_D:w []\__xparse_grab_m_long:w
+}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -593,9 +592,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn
-{u{stop}om}\environment foo \environment foo code {\__xparse_grab_u:w
-{stop}\__xparse_grab_D:w []\__xparse_grab_m_1:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{u{stop}om}{foo}{\__xparse_grab_u:w {stop}\__xparse_grab_D:w
+[]\__xparse_grab_m_1:w }{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -603,9 +602,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {moo}\environment
-foo \environment foo code {\__xparse_grab_m_1:w \__xparse_grab_D:w
-[]\__xparse_grab_D:w []}{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{moo}{foo}{\__xparse_grab_m_1:w \__xparse_grab_D:w []\__xparse_grab_D:w
+[]}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -796,7 +795,7 @@ TEST 19: (ab)using xparse commands in csnames
l. ... }
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
-\test- \xparse function is not expandable \__xparse_start_aux:nNNnnn {D...}\foo code {\__xparse_grab_D:w ..}{{.}}{}....\cs_end:
+\test- \xparse function is not expandable \bool_set_false:N \l__xparse_environment_bool \__xparse_start_aux:NNnnnn \foo code {D...}{\__xparse_grab_D:w ..}{{.}}{}....\cs_end:
============================================================
============================================================
TEST 20: Checking for existing expandable definitions
diff --git a/l3packages/xparse/testfiles/xparse001.uptex.tlg b/l3packages/xparse/testfiles/xparse001.uptex.tlg
index 96241cb..3e0c97a 100644
--- a/l3packages/xparse/testfiles/xparse001.uptex.tlg
+++ b/l3packages/xparse/testfiles/xparse001.uptex.tlg
@@ -551,8 +551,7 @@ l. ...}
You have used \RenewDocumentEnvironment with an environment that was never
defined.
LaTeX will ignore this entire definition.
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {}\environment
-foo \environment foo code {}{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn {}{foo}{}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:->\cs_set_nopar:Npx \environment
@@ -564,8 +563,8 @@ l. ...}
============================================================
TEST 13: Valid environment declarations
============================================================
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {mmm}\environment
-foo \environment foo code {\__xparse_grab_m_3:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{mmm}{foo}{\__xparse_grab_m_3:w }{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -573,9 +572,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {som}\environment
-foo \environment foo code {\__xparse_grab_t:w *\__xparse_grab_D:w
-[]\__xparse_grab_m_1:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{som}{foo}{\__xparse_grab_t:w *\__xparse_grab_D:w []\__xparse_grab_m_1:w
+}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -583,9 +582,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn
-{so+m}\environment foo \environment foo code {\__xparse_grab_t:w
-*\__xparse_grab_D:w []\__xparse_grab_m_long:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{so+m}{foo}{\__xparse_grab_t:w *\__xparse_grab_D:w []\__xparse_grab_m_long:w
+}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -593,9 +592,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn
-{u{stop}om}\environment foo \environment foo code {\__xparse_grab_u:w
-{stop}\__xparse_grab_D:w []\__xparse_grab_m_1:w }{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{u{stop}om}{foo}{\__xparse_grab_u:w {stop}\__xparse_grab_D:w
+[]\__xparse_grab_m_1:w }{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -603,9 +602,9 @@ l. ...}
\l__xparse_args_tl }(#1)(#2)(#3).
<recently read> }
l. ...}
-> \environment foo=\protected macro:->\__xparse_start:nNNnnn {moo}\environment
-foo \environment foo code {\__xparse_grab_m_1:w \__xparse_grab_D:w
-[]\__xparse_grab_D:w []}{}{}.
+> \environment foo=\protected macro:->\__xparse_start_env:nnnnn
+{moo}{foo}{\__xparse_grab_m_1:w \__xparse_grab_D:w []\__xparse_grab_D:w
+[]}{}{}.
<recently read> }
l. ...}
> \environment foo code=\protected\long macro:#1#2#3->\cs_set_nopar:Npx
@@ -800,7 +799,7 @@ TEST 19: (ab)using xparse commands in csnames
l. ... }
The control sequence marked <to be read again> should
not appear between \csname and \endcsname.
-\test- \xparse function is not expandable \__xparse_start_aux:nNNnnn {D...}\foo code {\__xparse_grab_D:w ..}{{.}}{}....\cs_end:
+\test- \xparse function is not expandable \bool_set_false:N \l__xparse_environment_bool \__xparse_start_aux:NNnnnn \foo code {D...}{\__xparse_grab_D:w ..}{{.}}{}....\cs_end:
============================================================
============================================================
TEST 20: Checking for existing expandable definitions
diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index 8b165b2..cef5804 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -944,11 +944,19 @@
% Generating environments uses the same mechanism as generating functions.
% However, full processing of arguments is always needed for environments,
% and so the function-generating code needs to know this.
+% This variable is also used at run time to give correct error messages.
% \begin{macrocode}
\bool_new:N \l_@@_environment_bool
% \end{macrocode}
% \end{variable}
%
+% \begin{variable}{\l_@@_environment_str}
+% Name of the environment, used at definition time and at run time.
+% \begin{macrocode}
+\str_new:N \l_@@_environment_str
+% \end{macrocode}
+% \end{variable}
+%
% \begin{variable}{\l_@@_expandable_bool}
% Used to indicate if an expandable command is begin generated, as this
% affects both the acceptable argument types and how they are implemented.
@@ -1205,10 +1213,16 @@
\cs_set_protected:Npn \l_@@_current_arg_int {#3}
\cs_set_protected_nopar:Npx #1
{
- \@@_start:nNNnnn
- { \exp_not:n {#2} }
- \exp_not:c { \l_@@_function_tl \c_space_tl }
- \exp_not:c { \l_@@_function_tl \c_space_tl code }
+ \bool_if:NTF \l_@@_environment_bool
+ {
+ \@@_start_env:nnnnn { \exp_not:n {#2} }
+ { \l_@@_environment_str }
+ }
+ {
+ \@@_start:nNNnnn { \exp_not:n {#2} }
+ \exp_not:c { \l_@@_function_tl \c_space_tl }
+ \exp_not:c { \l_@@_function_tl \c_space_tl code }
+ }
{ \exp_not:o \l_@@_signature_tl }
{
\bool_if:NT \l_@@_defaults_bool
@@ -1309,6 +1323,7 @@
}
\bool_set_false:N \l_@@_expandable_bool
\bool_set_true:N \l_@@_environment_bool
+ \str_set:Nx \l_@@_environment_str {#1}
\@@_declare_env_internal:nnnn {#1} {#2}
}
% \end{macrocode}
@@ -1347,32 +1362,52 @@
%
% \subsection{Structure of \pkg{xparse} commands}
%
-% \begin{macro}{\@@_start:nNNnnn}
-% \begin{macro}{\@@_start_aux:nNNnnn}
-% This sets up a few variables to minimize the boilerplate code
-% included in all \pkg{xparse}-defined commands. It then runs the
-% grabbers~|#4|. Again, the argument specification |#1| is only for
-% diagnostics. The control sequence equal to \cs{scan_stop:} protects
-% against \texttt{f}-expansion and ensures errors are more reasonable
-% when an \pkg{xparse} command is placed in a csname.
+% \begin{macro}{\@@_start_env:nnnnn, \@@_start:nNNnnn}
+% For error messages that occur during run-time when getting arguments
+% of environments it is necessary to keep track of the environment
+% name. We begin non-expandable commands with a token equal to
+% \cs{scan_stop:}, whose name gives a reasonable error message if the
+% command is used inside a csname and protects against
+% \texttt{f}-expansion. This is useless for environments since
+% \cs{begin} is already not expandable.
% \begin{macrocode}
-\cs_new_protected:Npx \@@_start:nNNnnn
+\cs_new_protected:Npn \@@_start_env:nnnnn #1#2
+ {
+ \str_set:Nn \l_@@_environment_str {#2}
+ \bool_set_true:N \l_@@_environment_bool
+ \@@_start_aux:ccnnnn
+ { environment~ \l_@@_environment_str \c_space_tl }
+ { environment~ \l_@@_environment_str \c_space_tl code }
+ {#1}
+ }
+\cs_new_protected:Npx \@@_start:nNNnnn #1#2#3
{
\exp_not:c { xparse~function~is~not~expandable }
- \exp_not:N \@@_start_aux:nNNnnn
+ \exp_not:n { \bool_set_false:N \l_@@_environment_bool }
+ \exp_not:N \@@_start_aux:NNnnnn
+ #2 #3 {#1}
}
-\cs_new_protected:Npn \@@_start_aux:nNNnnn #1#2#3#4#5#6
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_start_aux:NNnnnn, \@@_start_aux:ccnnnn}
+% This sets up a few variables to minimize the boilerplate code
+% included in all \pkg{xparse}-defined commands. It then runs the
+% grabbers~|#4|. Again, the argument specification |#1| is only for
+% diagnostics.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_start_aux:NNnnnn #1#2#3#4#5#6
{
\tl_clear:N \l_@@_args_tl
- \tl_set:Nn \l_@@_fn_tl {#2}
- \tl_set:Nn \l_@@_fn_code_tl {#3}
+ \tl_set:Nn \l_@@_fn_tl {#1}
+ \tl_set:Nn \l_@@_fn_code_tl {#2}
\tl_set:Nn \l_@@_defaults_tl {#5}
\tl_set:Nn \l_@@_process_all_tl {#6}
#4 \@@_run_code:
}
+\cs_generate_variant:Nn \@@_start_aux:NNnnnn { cc }
% \end{macrocode}
% \end{macro}
-% \end{macro}
%
% \begin{macro}{\@@_run_code:}
% After arguments are grabbed, this function is responsible for
@@ -4209,7 +4244,7 @@
% that its |arg_spec| is empty (this also excludes non-macros) and
% that its |replacement_spec| starts with either \cs{@@_start:nNNnnn}
% (non-expandable command) or \cs{@@_start_expandable:nNNNNn}
-% (expandable command).
+% (expandable command) or \cs{@@_start_env:nnnnn} (environment).
% \begin{macrocode}
\cs_new_protected:Npn \@@_cmd_if_xparse:NTF #1
{
@@ -4224,6 +4259,7 @@
{
{ \token_to_str:N \@@_start:nNNnnn } { }
{ \token_to_str:N \@@_start_expandable:nNNNNn } { }
+ { \token_to_str:N \@@_start_env:nnnnn } { }
}
}
\cs_new:Npn \@@_cmd_if_xparse_aux:w #1 ~ #2 \q_stop {#1}
More information about the latex3-commits
mailing list