[latex3-commits] [l3svn] 02/06: Add a k-type argument to xparse (closes #226)

noreply at latex-project.org noreply at latex-project.org
Sun Nov 8 22:37:01 CET 2015


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

joseph pushed a commit to branch master
in repository l3svn.

commit 97dcc7129eb30edf2d56e40029761c8200b02fa3
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sun Nov 8 16:29:40 2015 +0000

    Add a k-type argument to xparse (closes #226)
    
    In the present version, each key must be given separately
    (and thus keys are ordered). This makes the processing much easier
    and allows a simple -NoValue- return when not present. As such, this
    is all marked as experimental.
---
 l3packages/xparse/testfiles/xparse004.lvt |   36 +++++++++++-
 l3packages/xparse/testfiles/xparse004.tlg |   50 ++++++++++++++++-
 l3packages/xparse/xparse.dtx              |   86 +++++++++++++++++++++++++++++
 3 files changed, 167 insertions(+), 5 deletions(-)

diff --git a/l3packages/xparse/testfiles/xparse004.lvt b/l3packages/xparse/testfiles/xparse004.lvt
index 9ff29ec..a122f19 100644
--- a/l3packages/xparse/testfiles/xparse004.lvt
+++ b/l3packages/xparse/testfiles/xparse004.lvt
@@ -1,5 +1,5 @@
 %
-% Copyright (C) 2012,2014 LaTeX3 Project
+% Copyright (C) 2012,2014,2015 LaTeX3 Project
 %
 
 \documentclass{minimal}
@@ -9,7 +9,7 @@
 
 \begin{document}
 \START
-\AUTHOR{LaTeX3 Project}
+\AUTHOR{Joseph Wright}
 \ExplSyntaxOn
 
 \OMIT
@@ -78,6 +78,38 @@
     \foo stop
   }
 
+\TEST { Basic~k-type~argument~definitions }
+  {
+    \DeclareDocumentCommand \foo { k ^ k _ m }
+      { \TYPE { (#1) (#2) (#3) } }
+    \foo { there }
+    \foo ^ { up } { here }
+    \foo _ { down } { here }
+    \foo ^ { up } _ { down } { here }
+    \DeclareDocumentCommand \foo { k ^ k _ }
+      { \TYPE { (#1) (#2) } }
+    \foo stop
+    \foo ^ { up } stop
+    \foo _ { down } stop
+    \foo ^ { up } _ { down } stop
+  }
+
+\TEST { Basic~K-type~argument~definitions }
+  {
+    \DeclareDocumentCommand \foo { K ^ { sp } K _ { sb } m }
+      { \TYPE { (#1) (#2) (#3) } }
+    \foo { there }
+    \foo ^ { up } { here }
+    \foo _ { down } { here }
+    \foo ^ { up } _ { down } { here }
+    \DeclareDocumentCommand \foo { K ^ { sp } K _ { sb } }
+      { \TYPE { (#1) (#2) } }
+    \foo stop
+    \foo ^ { up } stop
+    \foo _ { down } stop
+    \foo ^ { up } _ { down } stop
+  }
+
 \TEST { Bad~arg~specs }
   {
     \OMIT
diff --git a/l3packages/xparse/testfiles/xparse004.tlg b/l3packages/xparse/testfiles/xparse004.tlg
index 146c9ed..1fa6879 100644
--- a/l3packages/xparse/testfiles/xparse004.tlg
+++ b/l3packages/xparse/testfiles/xparse004.tlg
@@ -16,7 +16,7 @@ Don't change this file in any respect.
 %%   Grave accent  \`     Left brace    \{     Vertical bar  \|
 %%   Right brace   \}     Tilde         \~}
 %%
-Author: LaTeX3 Project
+Author: Joseph Wright
 ============================================================
 TEST 1: Basic definitions r-type arguments
 ============================================================
@@ -274,7 +274,51 @@ l. ...  }
 (drat)(drat)
 ============================================================
 ============================================================
-TEST 5: Bad arg specs
+TEST 5: Basic k-type argument definitions
+============================================================
+.................................................
+. LaTeX info: "xparse/define-command"
+. 
+. Defining command \foo with sig. 'k^k_m' on line ....
+.................................................
+(-NoValue-)(-NoValue-)(there)
+(up)(-NoValue-)(here)
+(-NoValue-)(down)(here)
+(up)(down)(here)
+.................................................
+. LaTeX info: "xparse/redefine-command"
+. 
+. Redefining command \foo with sig. 'k^k_' on line ....
+.................................................
+(-NoValue-)(-NoValue-)
+(up)(-NoValue-)
+(-NoValue-)(down)
+(up)(down)
+============================================================
+============================================================
+TEST 6: Basic K-type argument definitions
+============================================================
+.................................................
+. LaTeX info: "xparse/define-command"
+. 
+. Defining command \foo with sig. 'K^{sp}K_{sb}m' on line ....
+.................................................
+(sp)(sb)(there)
+(up)(sb)(here)
+(sp)(down)(here)
+(up)(down)(here)
+.................................................
+. LaTeX info: "xparse/redefine-command"
+. 
+. Redefining command \foo with sig. 'K^{sp}K_{sb}' on line ....
+.................................................
+(sp)(sb)
+(up)(sb)
+(sp)(down)
+(up)(down)
+============================================================
+============================================================
+TEST 7: Bad arg specs
 ============================================================
 .................................................
 . LaTeX info: "xparse/define-command"
@@ -386,7 +430,7 @@ l. ...  }
 l. ...  }
 ============================================================
 ============================================================
-TEST 6: Stripping braces in optional args
+TEST 8: Stripping braces in optional args
 ============================================================
 .................................................
 . LaTeX info: "xparse/define-command"
diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index df5a42f..5eb5a0a 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -195,6 +195,12 @@
 %     |-NoValue-| if not present.
 %   \item[G] As for \texttt{g} but returns \meta{default} if no value
 %     is given: \texttt{G}\marg{default}.
+%   \item[k] An optional \emph{key} argument which requires a \emph{value}:
+%     the key should be a single \meta{token}. If the key is not present,
+%     returns |-NoValue-|. \emph{This is an experimental type}.
+%   \item[K] As for \texttt{K} but returns \meta{default} if no value
+%     is given: \texttt{K}\meta{token}\marg{default}.
+%     \emph{This is an experimental type}.
 % \end{itemize}
 %
 % Using these specifiers, it is possible to create complex input syntax
@@ -1141,6 +1147,8 @@
 %     \@@_count_type_D:w,
 %     \@@_count_type_g:w,
 %     \@@_count_type_G:w,
+%     \@@_count_type_k:w,
+%     \@@_count_type_K:w,
 %     \@@_count_type_m:w,
 %     \@@_count_type_r:w,
 %     \@@_count_type_R:w,
@@ -1189,6 +1197,18 @@
     \quark_if_recursion_tail_stop_do:nn {#1} { \@@_bad_arg_spec:wn }
     \@@_count_mandatory:N
   }
+\cs_new_protected:Npn \@@_count_type_k:w #1
+  {
+    \@@_single_token_check:n {#1}
+    \quark_if_recursion_tail_stop_do:nn {#1} { \@@_bad_arg_spec:wn }
+    \@@_count_mandatory:N
+  }
+\cs_new_protected:Npn \@@_count_type_K:w #1#2
+  {
+    \@@_single_token_check:n {#1}
+    \quark_if_recursion_tail_stop_do:nn {#2} { \@@_bad_arg_spec:wn }
+    \@@_count_mandatory:N
+  }
 \cs_new_protected_nopar:Npn \@@_count_type_m:w
   {
     \int_incr:N \l_@@_mandatory_args_int
@@ -1406,6 +1426,22 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\@@_add_type_k:w, \@@_add_type_K:w}
+%   Similar to |d|/|D| type but just one token to store.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_add_type_k:w #1
+  { \exp_args:NNo \@@_add_type_K:w #1 \c_@@_no_value_tl }
+\cs_new_protected:Npn \@@_add_type_K:w #1#2
+  {
+    \@@_flush_m_args:
+    \@@_add_grabber_optional:N K
+    \tl_put_right:Nn \l_@@_signature_tl { #1 { #2 } }
+    \@@_prepare_signature:N
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 % \begin{macro}{\@@_add_type_l:w}
 %   Finding \texttt{l} arguments is very simple: there is nothing to do
 %   other than add the grabber.
@@ -2061,6 +2097,56 @@
 % \end{macro}
 % \end{macro}
 %
+% \begin{macro}{\@@_grab_K:w, \@@_grab_K_long:w}
+% \begin{macro}[aux]{\@@_grab_K_aux:nnnNn}
+%   Look ahead at one token and if it matches grab an argument.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_grab_K:w #1#2#3 \l_@@_args_tl
+  {
+    \@@_grab_K_aux:nnnNn
+      {#1} {#2} {#3}
+      \cs_set_protected_nopar:Npn
+      { _ignore_spaces }
+  }
+\cs_new_protected:Npn \@@_grab_K_long:w #1#2#3 \l_@@_args_tl
+  {
+    \@@_grab_K_aux:nnnNn
+      {#1} {#2} {#3}
+      \cs_set_protected:Npn
+      { _ignore_spaces }
+  }
+\cs_new_protected:Npn \@@_grab_K_trailing:w #1#2#3 \l_@@_args_tl
+  {
+    \@@_grab_K_aux:nnnNn
+      {#1} {#2} {#3}
+      \cs_set_protected_nopar:Npn
+      { }
+  }
+\cs_new_protected:Npn \@@_grab_K_long_trailing:w #1#2#3 \l_@@_args_tl
+  {
+    \@@_grab_K_aux:nnnNn
+      {#1} {#2} {#3}
+      \cs_set_protected:Npn
+      { }
+  }
+\cs_new_protected:Npn \@@_grab_K_aux:nnnNn #1#2#3#4#5
+ {
+   \exp_after:wN #4 \l_@@_fn_tl ##1
+     {
+       \@@_add_arg:n { ##1 }
+       #3 \l_@@_args_tl
+     }
+   \use:c { peek_meaning_remove #5 :NTF } #1
+     { \l_@@_fn_tl }
+     {
+       \@@_add_arg:n { #2 }
+       #3 \l_@@_args_tl
+     }
+ }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 % \begin{macro}{\@@_grab_l:w}
 % \begin{macro}{\@@_grab_l_long:w}
 % \begin{macro}[aux]{\@@_grab_l_aux:nN}

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


More information about the latex3-commits mailing list