[latex3-commits] [l3svn] branch master updated: Extend e-type to an E-type

noreply at latex-project.org noreply at latex-project.org
Fri Nov 18 23:01:06 CET 2016


This is an automated email from the git hooks/post-receive script.

joseph pushed a commit to branch master
in repository l3svn.

The following commit(s) were added to refs/heads/master by this push:
       new  2b93cfd   Extend e-type to an E-type
2b93cfd is described below

commit 2b93cfdcb235451fa60241b1e130c0ffa080fbaa
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Fri Nov 18 21:58:21 2016 +0000

    Extend e-type to an E-type
    
    At present I've allowed for a variable length list of defaults.
    An expandable version is still outstanding (but first let us be
    sure we can live with the syntax).
---
 l3packages/xparse/testfiles/xparse004.lvt |   22 ++++++
 l3packages/xparse/testfiles/xparse004.tlg |   41 +++++++++--
 l3packages/xparse/xparse.dtx              |  111 +++++++++++++++++++++--------
 3 files changed, 139 insertions(+), 35 deletions(-)

diff --git a/l3packages/xparse/testfiles/xparse004.lvt b/l3packages/xparse/testfiles/xparse004.lvt
index 860d825..a1181d6 100644
--- a/l3packages/xparse/testfiles/xparse004.lvt
+++ b/l3packages/xparse/testfiles/xparse004.lvt
@@ -94,6 +94,28 @@
     \foo ^ { up } _ { down } stop
   }
 
+\TEST { Basic~E-type~argument~definitions }
+  {
+    \DeclareDocumentCommand \foo { E { ^ _ } { } }
+      { \TYPE { (#1) } }
+    \foo { there }
+    \foo ^ { up } { here }
+    \foo _ { down } { here }
+    \foo ^ { up } _ { down } { here }
+    \DeclareDocumentCommand \foo { E { ^ _ } { { UP } } }
+      { \TYPE { (#1) } }
+    \foo { there }
+    \foo ^ { up } { here }
+    \foo _ { down } { here }
+    \foo ^ { up } _ { down } { here }
+    \DeclareDocumentCommand \foo { E { ^ _ } { { UP } { DOWN } } }
+      { \TYPE { (#1) } }
+    \foo { there }
+    \foo ^ { up } { here }
+    \foo _ { down } { here }
+    \foo ^ { up } _ { down } { here }
+  }
+
 \TEST { Bad~arg~specs }
   {
     \OMIT
diff --git a/l3packages/xparse/testfiles/xparse004.tlg b/l3packages/xparse/testfiles/xparse004.tlg
index 4c94524..2666695 100644
--- a/l3packages/xparse/testfiles/xparse004.tlg
+++ b/l3packages/xparse/testfiles/xparse004.tlg
@@ -280,7 +280,38 @@ TEST 5: Basic e-type argument definitions
 ({up}{down})
 ============================================================
 ============================================================
-TEST 6: Bad arg specs
+TEST 6: Basic E-type argument definitions
+============================================================
+.................................................
+. LaTeX info: "xparse/define-command"
+. 
+. Defining command \foo with sig. 'E{^_}{}' on line ....
+.................................................
+({-NoValue-}{-NoValue-})
+({up}{-NoValue-})
+({-NoValue-}{down})
+({up}{down})
+.................................................
+. LaTeX info: "xparse/redefine-command"
+. 
+. Redefining command \foo with sig. 'E{^_}{{UP}}' on line ....
+.................................................
+({UP}{-NoValue-})
+({up}{-NoValue-})
+({UP}{down})
+({up}{down})
+.................................................
+. LaTeX info: "xparse/redefine-command"
+. 
+. Redefining command \foo with sig. 'E{^_}{{UP}{DOWN}}' on line ....
+.................................................
+({UP}{DOWN})
+({up}{DOWN})
+({UP}{down})
+({up}{down})
+============================================================
+============================================================
+TEST 7: Bad arg specs
 ============================================================
 .................................................
 . LaTeX info: "xparse/define-command"
@@ -459,7 +490,7 @@ l. ...  }
 > \foo=undefined.
 ============================================================
 ============================================================
-TEST 7: Stripping braces in optional args
+TEST 8: Stripping braces in optional args
 ============================================================
 .................................................
 . LaTeX info: "xparse/define-command"
@@ -478,7 +509,7 @@ TEST 7: Stripping braces in optional args
 ([{bar}])(baz)
 ============================================================
 ============================================================
-TEST 8: Get and show argument spec
+TEST 9: Get and show argument spec
 ============================================================
 ||
 > \ArgumentSpecification=.
@@ -498,7 +529,7 @@ l. ...  }
 l. ...  }
 ============================================================
 ============================================================
-TEST 9: First argument must be a command
+TEST 10: First argument must be a command
 ============================================================
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !
@@ -956,7 +987,7 @@ l. ...  }
 l. ...  }
 ============================================================
 ============================================================
-TEST 10: SplitList
+TEST 11: SplitList
 ============================================================
 .................................................
 . LaTeX info: "xparse/define-command"
diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index b9e3f87..e211db3 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -200,6 +200,9 @@
 %     The returned data is a token list comprising one braced entry per key,
 %     ordered as for the key list in the signature.
 %     \emph{This is an experimental type}.
+%   \item[E] As for \texttt{E} but returns one or more \meta{defaults}
+%     if values are not given: \texttt{E}\marg{defaults}. See
+%     Section~\ref{sec:embellishment} for more details.
 % \end{itemize}
 %
 % Using these specifiers, it is possible to create complex input syntax
@@ -483,6 +486,25 @@
 %   take based on this information.
 % \end{function}
 %
+% \subsection{Default values for \enquote{embellishments}}
+% \label{sec:embellishment}
+%
+% The \texttt{E}-type argument allows one default value per test token.
+% This is achieved by giving a list of defaults for each entry in the
+% list, for example:
+% \begin{verbatim}
+%   E{^_}{{UP}{DOWN}}
+% \end{verbatim}
+% If the list of default values is \emph{shorter} than the list of test tokens,
+% the special \cs{NoValue} marker will be returned (as for the \texttt{e}-type
+% argument). Thus for example
+% \begin{verbatim}
+%   E{^_}{{UP}}
+% \end{verbatim}
+% has default \texttt{UP} for the |^| test token, but will return the
+% \cs{NoValue} marker as a default for |_|. This allows mixing of explicit
+% defaults with testing for missing values.
+%
 % \subsection{Argument processors}
 % \label{sec:processors}
 %
@@ -1151,6 +1173,7 @@
 %     \@@_count_type_d:w,
 %     \@@_count_type_D:w,
 %     \@@_count_type_e:w,
+%     \@@_count_type_E:w,
 %     \@@_count_type_g:w,
 %     \@@_count_type_G:w,
 %     \@@_count_type_m:w,
@@ -1207,6 +1230,11 @@
     \quark_if_recursion_tail_stop_do:nn {#1} { \@@_bad_arg_spec:wn }
     \@@_count_mandatory:N
   }
+\cs_new_protected:Npn \@@_count_type_E:w #1#2
+  {
+    \quark_if_recursion_tail_stop_do:nn {#2} { \@@_bad_arg_spec:wn }
+    \@@_count_mandatory:N
+  }
 \cs_new_protected:Npn \@@_count_type_g:w
   { \@@_count_mandatory:N }
 \cs_new_protected:Npn \@@_count_type_G:w #1
@@ -1408,14 +1436,18 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\@@_add_type_e:w}
-%   No default here: there is just a token to look for.
+% \begin{macro}{\@@_add_type_e:w, \@@_add_type_E:w}
+%   Setting up for the \texttt{e}-type argument is somewhat specialised as
+%   the |-NoValue-| tokens are inserted by the grabber rather than here. As
+%   such, all that is needed is to pass data straight through.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_add_type_e:w #1
+  { \@@_add_type_E:w {#1} { } }
+\cs_new_protected:Npn \@@_add_type_E:w #1#2
   {
     \@@_flush_m_args:
-    \@@_add_grabber_optional:N e
-    \tl_put_right:Nn \l_@@_signature_tl { {#1} }
+    \@@_add_grabber_optional:N E
+    \tl_put_right:Nn \l_@@_signature_tl { {#1} {#2} }
     \@@_prepare_signature:N
   }
 %    \end{macrocode}
@@ -2054,37 +2086,41 @@
 % \end{macro}
 %
 % \begin{macro}
-%   {\@@_grab_e:w, \@@_grab_e_long:w, \@@_grab_e_trailing:w, \@@_grab_e_long_trailing:w}
-% \begin{macro}[aux]{\@@_grab_e:nnNn}
-% \begin{macro}[aux]{\@@_grab_e_loop:nnN}
-% \begin{macro}[aux]{\@@_grab_e_finalise:}
+%   {
+%     \@@_grab_E:w, \@@_grab_E_long:w,
+%     \@@_grab_E_trailing:w, \@@_grab_E_long_trailing:w
+%   }
+% \begin{macro}[aux]{\@@_grab_E:nnnNn}
+% \begin{macro}[aux]{\@@_grab_E_setup:Nw}
+% \begin{macro}[aux]{\@@_grab_E_loop:nnN}
+% \begin{macro}[aux]{\@@_grab_E_finalise:}
 %   Everything here needs to point to a loop.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_grab_e:w #1#2 \l_@@_args_tl
+\cs_new_protected:Npn \@@_grab_E:w #1#2#3 \l_@@_args_tl
   {
-    \@@_grab_e:nnNn
-       {#1} {#2}
+    \@@_grab_E:nnnNn
+       {#1} {#2} {#3}
       \cs_set_protected_nopar:Npn
       { _ignore_spaces }
   }
-\cs_new_protected:Npn \@@_grab_e_long:w #1#2 \l_@@_args_tl
+\cs_new_protected:Npn \@@_grab_E_long:w #1#2#3 \l_@@_args_tl
   {
-    \@@_grab_e:nnNn
-      {#1} {#2}
+    \@@_grab_E:nnnNn
+       {#1} {#2} {#3}
       \cs_set_protected:Npn
       { _ignore_spaces }
   }
-\cs_new_protected:Npn \@@_grab_e_trailing:w #1#2 \l_@@_args_tl
+\cs_new_protected:Npn \@@_grab_E_trailing:w #1#2#3 \l_@@_args_tl
   {
-    \@@_grab_e:nnNn
-      {#1} {#2}
+    \@@_grab_E:nnnNn
+       {#1} {#2} {#3}
       \cs_set_protected_nopar:Npn
       { }
   }
-\cs_new_protected:Npn \@@_grab_e_long_trailing:w #1#2 \l_@@_args_tl
+\cs_new_protected:Npn \@@_grab_E_long_trailing:w #1#2#3 \l_@@_args_tl
   {
-    \@@_grab_e:nnNn
-      {#1} {#2}
+    \@@_grab_E:nnnNn
+       {#1} {#2} {#3}
       \cs_set_protected:Npn
       { }
   }
@@ -2094,15 +2130,17 @@
 %   they can appear later. The grabbed values are held in a property list
 %   which is then turned into an ordered list to be passed back to the user.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_grab_e:nnNn #1#2#3#4
+\cs_new_protected:Npn \@@_grab_E:nnnNn #1#2#3#4#5
   {
-    \exp_after:wN #3 \l_@@_fn_tl ##1##2##3
+    \exp_after:wN #4 \l_@@_fn_tl ##1##2##3
       {
         \prop_put:Nnn \l_@@_tmp_prop {##1} {##3}
-        \@@_grab_e_loop:nnN {#4} { } ##2 \q_recursion_stop
+        \@@_grab_E_loop:nnN {#5} { } ##2 \q_recursion_stop
       }
     \prop_clear:N \l_@@_tmp_prop
-    \cs_set_protected:Npn \@@_grab_e_finalise:
+    \@@_grab_E_setup:Nw
+      #1 \q_recursion_tail \q_mark #2 \q_recursion_tail \q_recursion_stop
+    \cs_set_protected:Npn \@@_grab_E_finalise:
       {
         \tl_clear:N \l_@@_tmpa_tl
         \tl_map_inline:nn {#1}
@@ -2116,26 +2154,39 @@
               }
           }
         \@@_add_arg:V \l_@@_tmpa_tl
-        #2 \l_@@_args_tl
+        #3 \l_@@_args_tl
       }
-    \@@_grab_e_loop:nnN {#4} { } #1 \q_recursion_tail \q_recursion_stop
+    \@@_grab_E_loop:nnN {#5} { } #1 \q_recursion_tail \q_recursion_stop
+  }
+%    \end{macrocode}
+%   To allow for flexible default values, the list of those given may be
+%   shorter than the number of test tokens. This can readily be achieved
+%   by storing only the given defaults in the property list.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_grab_E_setup:Nw #1#2 \q_mark #3
+  {
+    \quark_if_recursion_tail_stop:N #1
+    \quark_if_recursion_tail_stop:n {#3}
+    \prop_put:Nnn \l_@@_tmp_prop {#1} {#3}
+    \@@_grab_E_setup:Nw #2 \q_mark
   }
-\cs_new_protected:Npn \@@_grab_e_loop:nnN #1#2#3#4 \q_recursion_stop
+\cs_new_protected:Npn \@@_grab_E_loop:nnN #1#2#3#4 \q_recursion_stop
   {
     \cs_if_eq:NNTF #3 \q_recursion_tail
-      { \@@_grab_e_finalise: }
+      { \@@_grab_E_finalise: }
       {
         \use:c { peek_meaning_remove #1 :NTF } #3
           { \l_@@_fn_tl #3 {#2#4} }
-          { \@@_grab_e_loop:nnN {#1} {#2#3} #4 \q_recursion_stop }
+          { \@@_grab_E_loop:nnN {#1} {#2#3} #4 \q_recursion_stop }
       }
   }
-\cs_new_protected:Npn \@@_grab_e_finalise: { }
+\cs_new_protected:Npn \@@_grab_E_finalise: { }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
 % \end{macro}
 % \end{macro}
+% \end{macro}
 %
 % \begin{macro}{\@@_grab_G:w}
 % \begin{macro}{\@@_grab_G_long:w}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the latex3-commits mailing list