[latex3-commits] [git/LaTeX3-latex3-latex3] master: Remove user-provided setup for xparse b-type arguments (55fa39f)

Joseph Wright joseph.wright at morningstar2.co.uk
Mon Mar 4 14:54:38 CET 2019


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/55fa39f056b1540f6c7eba25b1beaef102ab7fa6

>---------------------------------------------------------------

commit 55fa39f056b1540f6c7eba25b1beaef102ab7fa6
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Wed Feb 27 18:30:12 2019 +0100

    Remove user-provided setup for xparse b-type arguments


>---------------------------------------------------------------

55fa39f056b1540f6c7eba25b1beaef102ab7fa6
 l3packages/xparse/testfiles/xparse005.lvt |    9 ++--
 l3packages/xparse/testfiles/xparse005.tlg |    2 +-
 l3packages/xparse/xparse.dtx              |   77 ++++++++++++++---------------
 3 files changed, 42 insertions(+), 46 deletions(-)

diff --git a/l3packages/xparse/testfiles/xparse005.lvt b/l3packages/xparse/testfiles/xparse005.lvt
index aed6486..1ac1a46 100644
--- a/l3packages/xparse/testfiles/xparse005.lvt
+++ b/l3packages/xparse/testfiles/xparse005.lvt
@@ -72,10 +72,10 @@
 % The following tests are outside to allow \ExplSyntaxOff and \obeylines
 \TEST { Environment~body~valid } { }
 
-\NewDocumentEnvironment { env1 } { o >{\SplitList{\par}} + b { } }
+\NewDocumentEnvironment { env1 } { o >{\SplitList{\par}} + b }
   { \TYPE { \tl_to_str:n {|#1|#2|} } }
   { \TYPE { \tl_to_str:n {|#1|} } }
-\NewDocumentEnvironment { env2 } { ! o ! b { \obeylines } }
+\NewDocumentEnvironment { env2 } { ! o ! b }
   { \TYPE { \tl_to_str:n {|#1|#2|} } }
   { \TYPE { \tl_to_str:n {|#1|} } }
 \ExplSyntaxOff
@@ -108,10 +108,9 @@
     \begin{env1}\end{env2}
     \begin{env2}
       \par
-      \endgroup % error recovery for runaway args is not great: we need this \endgroup
     \end{env2}
-    \NewDocumentCommand{\testE} { b{} } { }
-    \NewDocumentEnvironment{env3} { b{} m } { } { }
+    \NewDocumentCommand{\testE} { b } { }
+    \NewDocumentEnvironment{env3} { b m } { } { }
   }
 
 % The rest of this test tests all of xparse's messages.
diff --git a/l3packages/xparse/testfiles/xparse005.tlg b/l3packages/xparse/testfiles/xparse005.tlg
index 10ef228..6a8f71f 100644
--- a/l3packages/xparse/testfiles/xparse005.tlg
+++ b/l3packages/xparse/testfiles/xparse005.tlg
@@ -119,7 +119,7 @@ TEST 4: Environment body valid
 ============================================================
 |...|{\begin {any} \begin {unbalanced} \end {environments} \begin {provided}}{\end {nesting} \end {works} \begin {out} \end {!}}|
 |...|
-|-NoValue-| [...]^^M\begin {any}^^M\begin {unbalanced}^^M\end {environments}^^M\begin {provided}^^M\end {nesting}^^M\end {works}^^M\begin {out}^^M\end {!}^^M|
+|-NoValue-| [...] \begin {any} \begin {unbalanced} \end {environments} \begin {provided} \end {nesting} \end {works} \begin {out} \end {!} |
 |-NoValue-|
 ============================================================
 TEST 5: Body invalid
diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index 048f5bf..3c5a619 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -149,10 +149,8 @@
 %     argument will produce an error when it appears within an argument of
 %     another function.
 %   \item[b] Only suitable in the argument specification of an
-%     environment, \texttt{b}\marg{code} denotes the body of the
-%     environment, between |\begin|\marg{environment} and
-%       |\end|\marg{environment}.  The \meta{code} is run before
-%     \pkg{xparse} reads the environment's body.  See
+%     environment, it denotes the body of the environment, between
+%     |\begin|\marg{environment} and |\end|\marg{environment}.  See
 %     Section~\ref{sec:body} for details.
 % \end{itemize}
 % The types which define optional arguments are:
@@ -398,7 +396,7 @@
 % useful to have the body as a standard argument.
 %
 % This is achieved in \pkg{xparse} by ending the argument specification
-% with \texttt{b}\marg{code}. The approach taken in \pkg{xparse} is
+% with~\texttt{b}. The approach taken in \pkg{xparse} is
 % different from the earlier packages \pkg{environ} or \pkg{newenviron}:
 % the body of the environment is provided to the code part as a usual
 % argument |#1|, |#2| etc.\@, rather than stored in a macro such as
@@ -407,7 +405,7 @@
 % For instance
 % \begin{verbatim}
 %   \NewDocumentEnvironment { twice }
-%     { O{\ttfamily} +b{} }
+%     { O{\ttfamily} +b }
 %     {#2#1#2} {}
 %   \begin{twice}[\itshape]
 %     Hello world!
@@ -417,18 +415,14 @@
 %
 % The prefix |+| is used to allow multiple paragraphs in the
 % environment's body.  Argument processors can also be applied to
-% \texttt{b}-type arguments.
+% \texttt{b}~arguments.
 %
 % By default, spaces are trimmed at both ends of the body: in the
 % example there would otherwise be spaces coming from the ends the lines
 % after |[\itshape]| and |world!|.  Putting the prefix |!| before
 % \texttt{b} suppresses space-trimming.
 %
-% In \texttt{b}\marg{code} the \meta{code} is some set-up, run before
-% \pkg{xparse} grabs the body of the environment.  This can be used to
-% preserve spaces or lines when grabbing environments.
-%
-% When \texttt{b}\marg{code} is used in the argument specification,
+% When \texttt{b} is used in the argument specification,
 % the last argument of \cs{NewDocumentEnvironment}, which consists of
 % an \meta{end code} to insert at |\end|\marg{environment}, is
 % redundant since one can simply put that code at the end of the
@@ -1078,6 +1072,14 @@
 %    \end{macrocode}
 % \end{variable}
 %
+% \begin{variable}{\l_@@_saved_args_tl}
+%   Stores \cs{l_@@_args_tl} to deal with space-trimming of
+%   \texttt{b}-type arguments.
+%    \begin{macrocode}
+\tl_new:N \l_@@_saved_args_tl
+%    \end{macrocode}
+% \end{variable}
+%
 % \begin{variable}{\l_@@_signature_tl}
 %   Used when constructing the signature (code for argument grabbing) to
 %   hold what will become the implementation of the main function.
@@ -1958,11 +1960,11 @@
 % \end{macro}
 %
 % \begin{macro}{\@@_normalize_type_b:w}
-%   This argument type is not allowed for commands.  This takes one
-%   argument and is only allowed at the end of the argument
-%   specification, hence we check both |#1| and |#2| for being the end.
+%   This argument type is not allowed for commands.  This is only
+%   allowed at the end of the argument specification, hence we check
+%   that |#1| is the end.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_normalize_type_b:w #1#2
+\cs_new_protected:Npn \@@_normalize_type_b:w #1
   {
     \bool_if:NF \l_@@_environment_bool
       {
@@ -1971,13 +1973,12 @@
           { \@@_environment_or_command: } { b }
         \@@_bad_def:wn
       }
-    \quark_if_recursion_tail_stop_do:nn {#1} { \@@_bad_arg_spec:wn }
     \tl_clear:N \l_@@_last_delimiters_tl
-    \@@_add_arg_spec:n { b {#1} }
-    \quark_if_recursion_tail_stop:n {#2}
+    \@@_add_arg_spec:n { b }
+    \quark_if_recursion_tail_stop:n {#1}
     \__kernel_msg_error:nnxx { xparse } { arg-after-body }
       { \@@_environment_or_command: }
-      { \tl_to_str:n {#2} }
+      { \tl_to_str:n {#1} }
     \@@_bad_def:wn
   }
 %    \end{macrocode}
@@ -2239,12 +2240,11 @@
 %
 % \begin{macro}{\@@_add_type_b:w}
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_add_type_b:w #1
+\cs_new_protected:Npn \@@_add_type_b:w
   {
     \@@_flush_m_args:
     \@@_add_default:
     \@@_add_grabber:N b
-    \tl_put_right:Nn \l_@@_signature_tl { {#1} }
     \@@_prepare_signature:N
   }
 %    \end{macrocode}
@@ -2726,49 +2726,46 @@
 %     \@@_grab_b_long:w,
 %     \@@_grab_b_obey_spaces:w,
 %     \@@_grab_b_long_obey_spaces:w,
-%     \@@_grab_b_aux:NNnw,
+%     \@@_grab_b_aux:NNw,
 %     \@@_grab_b_end:Nw
 %   }
 %   This uses the well-tested code of \texttt{D}-type arguments,
 %   skipping the peeking step because the \texttt{b}-type argument is
 %   always present, and adding a cleanup stage at the end by hijacking
-%   the signature.  The user-provided set-up code |#3| is run in a group
-%   and the clean-up consists of closing that group while properly
+%   the signature.  The clean-up consists of properly
 %   dealing with \cs{l_@@_args_tl} and also putting back the \cs{end}
 %   that served as an end-delimiter: this \cs{end} receives the
 %   environment name as its argument and is run normally.  The
 %   \texttt{D}-type code stores the argument found (body of the
 %   environment) as a brace group in \cs{l_@@_args_tl} and depending on
 %   the presence of a prefix~|!| we trim spaces or not before adding
-%   this braced argument into \cs{l_@@_args_tl} outside the group.
+%   this braced argument into the saved \cs{l_@@_args_tl}.
 %   The strange \verb*|\begin | control sequence is there for display
 %     purposes only: it has to look like |\begin| in the terminal but
 %       not to delimited arguments.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_grab_b:w
-  { \@@_grab_b_aux:NNnw \cs_set_protected_nopar:Npn \tl_trim_spaces:n }
+  { \@@_grab_b_aux:NNw \cs_set_protected_nopar:Npn \tl_trim_spaces:n }
 \cs_new_protected:Npn \@@_grab_b_long:w
-  { \@@_grab_b_aux:NNnw \cs_set_protected:Npn \tl_trim_spaces:n }
+  { \@@_grab_b_aux:NNw \cs_set_protected:Npn \tl_trim_spaces:n }
 \cs_new_protected:Npn \@@_grab_b_obey_spaces:w
-  { \@@_grab_b_aux:NNnw \cs_set_protected_nopar:Npn \exp_not:n }
+  { \@@_grab_b_aux:NNw \cs_set_protected_nopar:Npn \exp_not:n }
 \cs_new_protected:Npn \@@_grab_b_long_obey_spaces:w
-  { \@@_grab_b_aux:NNnw \cs_set_protected:Npn \exp_not:n }
-\cs_new_protected:Npn \@@_grab_b_aux:NNnw #1#2#3#4 \@@_run_code:
+  { \@@_grab_b_aux:NNw \cs_set_protected:Npn \exp_not:n }
+\cs_new_protected:Npn \@@_grab_b_aux:NNw #1#2#3 \@@_run_code:
   {
-    \@@_grab_D_aux:NNnN \begin \end {#4} #1
+    \@@_grab_D_aux:NNnN \begin \end {#3} #1
     \tl_put_left:Nn \l_@@_signature_tl { \@@_grab_b_end:Nw #2 }
-    \group_begin:
-      \tl_clear:N \l_@@_args_tl
-      #3
-      \exp_args:Nc \l_@@_fn_tl { begin ~ }
+    \tl_set_eq:NN \l_@@_saved_args_tl \l_@@_args_tl
+    \tl_clear:N \l_@@_args_tl
+    \exp_args:Nc \l_@@_fn_tl { begin ~ }
   }
 \cs_new_protected:Npn \@@_grab_b_end:Nw #1#2 \@@_run_code:
   {
-    \use:x
+    \tl_set:Nx \l_@@_args_tl
       {
-        \group_end:
-        \tl_put_right:Nn \exp_not:N \l_@@_args_tl
-          { { \exp_after:wN #1 \l_@@_args_tl } }
+        \exp_not:V \l_@@_saved_args_tl
+        { \exp_after:wN #1 \l_@@_args_tl }
       }
     #2
     \@@_run_code:





More information about the latex3-commits mailing list