[latex3-commits] [l3svn] branch master updated: Revised approach to k-type arguments
noreply at latex-project.org
noreply at latex-project.org
Tue Nov 8 15:15:18 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 9df4899 Revised approach to k-type arguments
9df4899 is described below
commit 9df48998cbe4589e6d0c04411efbf51a98abe04a
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Tue Nov 8 14:14:18 2016 +0000
Revised approach to k-type arguments
This allows random ordering of the arguments, at present returning
an ordered token list. Expandable code still to consider, as is the
exact nature of the return.
---
l3packages/xparse/testfiles/xparse004.lvt | 22 +---
l3packages/xparse/xparse.dtx | 191 +++++++++++++----------------
2 files changed, 85 insertions(+), 128 deletions(-)
diff --git a/l3packages/xparse/testfiles/xparse004.lvt b/l3packages/xparse/testfiles/xparse004.lvt
index 0c8bafa..cf3de7b 100644
--- a/l3packages/xparse/testfiles/xparse004.lvt
+++ b/l3packages/xparse/testfiles/xparse004.lvt
@@ -80,30 +80,14 @@
\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 _ }
+ \DeclareDocumentCommand \foo { k { ^ _ } m }
{ \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) } }
+ \DeclareDocumentCommand \foo { k { ^ _ } }
+ { \TYPE { (#1) } }
\foo stop
\foo ^ { up } stop
\foo _ { down } stop
diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index 3a142e3..4ed7805 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -195,11 +195,10 @@
% |-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}.
+% \item[k] An optional set of \emph{keys}, each of which requires a
+% \emph{value}. If a key is not present, |-NoValue-| is returned.
+% 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}.
% \end{itemize}
%
@@ -899,10 +898,12 @@
% \end{macrocode}
% \end{variable}
%
-% \begin{variable}{\l_@@_tmp_tl}
+% \begin{variable}{\l_@@_tmp_prop, \l_@@_tmpa_tl, \l_@@_tmpb_tl}
% Scratch space.
% \begin{macrocode}
-\tl_new:N \l_@@_tmp_tl
+\prop_new:N \l_@@_tmp_prop
+\tl_new:N \l_@@_tmpa_tl
+\tl_new:N \l_@@_tmpb_tl
% \end{macrocode}
% \end{variable}
%
@@ -1129,8 +1130,8 @@
\cs_new_protected:Npn \@@_count_mandatory:N #1
{
\quark_if_recursion_tail_stop:N #1
- \prop_get:NnNTF \c_@@_shorthands_prop {#1} \l_@@_tmp_tl
- { \exp_after:wN \@@_count_mandatory:N \l_@@_tmp_tl }
+ \prop_get:NnNTF \c_@@_shorthands_prop {#1} \l_@@_tmpa_tl
+ { \exp_after:wN \@@_count_mandatory:N \l_@@_tmpa_tl }
{ \@@_count_mandatory_aux:N #1 }
}
\cs_new_protected:Npn \@@_count_mandatory_aux:N #1
@@ -1152,7 +1153,6 @@
% \@@_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,
@@ -1211,14 +1211,7 @@
}
\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 }
+ \quark_if_recursion_tail_stop_do:nn {#1} { \@@_bad_arg_spec:wn }
\@@_count_mandatory:N
}
\cs_new_protected:Npn \@@_count_type_m:w
@@ -1320,8 +1313,8 @@
\cs_new_protected:Npn \@@_prepare_signature_bypass:N #1
{
\quark_if_recursion_tail_stop:N #1
- \prop_get:NnNTF \c_@@_shorthands_prop {#1} \l_@@_tmp_tl
- { \exp_after:wN \@@_prepare_signature:N \l_@@_tmp_tl }
+ \prop_get:NnNTF \c_@@_shorthands_prop {#1} \l_@@_tmpa_tl
+ { \exp_after:wN \@@_prepare_signature:N \l_@@_tmpa_tl }
{
\int_incr:N \l_@@_current_arg_int
\@@_prepare_signature_add:N #1
@@ -1438,21 +1431,18 @@
% \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{macro}{\@@_add_type_k:w}
+% No default here: there is just a token to look for.
% \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} }
+ \@@_add_grabber_optional:N k
+ \tl_put_right:Nn \l_@@_signature_tl { {#1} }
\@@_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
@@ -1728,34 +1718,6 @@
% \end{macro}
% \end{macro}
%
-% \begin{macro}{\@@_add_expandable_type_k:w}
-% \begin{macro}{\@@_add_expandable_type_K:w}
-% \begin{macrocode}
-\cs_new_protected:Npn \@@_add_expandable_type_k:w #1
- {
- \exp_args:NNo
- \@@_add_expandable_type_K:w #1 \c_@@_no_value_tl
- }
-\cs_new_protected:Npn \@@_add_expandable_type_K:w #1#2
- {
- \@@_add_expandable_grabber_optional:n { K }
- \bool_if:NTF \l_@@_all_long_bool
- { \cs_set:cpx }
- { \cs_set_nopar:cpx }
- { \l_@@_expandable_aux_name_tl } ##1 #1 ##2
- { ##1 {##2} }
- \tl_put_right:Nx \l_@@_signature_tl
- {
- \exp_not:c { \l_@@_expandable_aux_name_tl }
- \exp_not:n { #1 {#2} }
- }
- \bool_set_false:N \l_@@_long_bool
- \@@_prepare_signature:N
- }
-% \end{macrocode}
-% \end{macro}
-% \end{macro}
-%
% \begin{macro}{\@@_add_expandable_type_l:w}
% Invalid in expandable contexts (as the next left brace may have been
% inserted by \pkg{xparse} due to a failed search for an optional argument).
@@ -2067,10 +2029,10 @@
{ \@@_grab_D_nested:w \q_nil ##2 \q_stop }
\tl_if_in:NnTF \l_@@_nesting_b_tl {#1}
{
- \tl_set_eq:NN \l_@@_tmp_tl \l_@@_nesting_b_tl
+ \tl_set_eq:NN \l_@@_tmpa_tl \l_@@_nesting_b_tl
\tl_clear:N \l_@@_nesting_b_tl
\exp_after:wN \l_@@_fn_tl \exp_after:wN
- \q_nil \l_@@_tmp_tl \q_nil \q_@@ \ERROR
+ \q_nil \l_@@_tmpa_tl \q_nil \q_@@ \ERROR
}
{
\tl_put_right:No \l_@@_nesting_a_tl
@@ -2133,53 +2095,87 @@
% \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{macro}
+% {\@@_grab_k:w, \@@_grab_k_long:w, \@@_grab_k_trailing:w, \@@_grab_k_long_trailing:w}
+% \begin{macro}[aux]{\@@_grab_k:nnNn}
+% \begin{macro}[aux]{\@@_grab_k_loop:nnN}
+% \begin{macro}[aux]{\@@_grab_k_finalise:}
+% Everything here needs to point to a loop.
% \begin{macrocode}
-\cs_new_protected:Npn \@@_grab_K:w #1#2#3 \l_@@_args_tl
+\cs_new_protected:Npn \@@_grab_k:w #1#2 \l_@@_args_tl
{
- \@@_grab_K_aux:nnnNn
- {#1} {#2} {#3}
+ \@@_grab_k:nnNn
+ {#1} {#2}
\cs_set_protected_nopar:Npn
{ _ignore_spaces }
}
-\cs_new_protected:Npn \@@_grab_K_long:w #1#2#3 \l_@@_args_tl
+\cs_new_protected:Npn \@@_grab_k_long:w #1#2 \l_@@_args_tl
{
- \@@_grab_K_aux:nnnNn
- {#1} {#2} {#3}
+ \@@_grab_k:nnNn
+ {#1} {#2}
\cs_set_protected:Npn
{ _ignore_spaces }
}
-\cs_new_protected:Npn \@@_grab_K_trailing:w #1#2#3 \l_@@_args_tl
+\cs_new_protected:Npn \@@_grab_k_trailing:w #1#2 \l_@@_args_tl
{
- \@@_grab_K_aux:nnnNn
- {#1} {#2} {#3}
+ \@@_grab_k:nnNn
+ {#1} {#2}
\cs_set_protected_nopar:Npn
{ }
}
-\cs_new_protected:Npn \@@_grab_K_long_trailing:w #1#2#3 \l_@@_args_tl
+\cs_new_protected:Npn \@@_grab_k_long_trailing:w #1#2 \l_@@_args_tl
{
- \@@_grab_K_aux:nnnNn
- {#1} {#2} {#3}
+ \@@_grab_k:nnNn
+ {#1} {#2}
\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}
+% A loop is needed here to allow a random ordering of keys. These are
+% searched for one at a time, with any not found needing to be tracked:
+% 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_k:nnNn #1#2#3#4
+ {
+ \exp_after:wN #3 \l_@@_fn_tl ##1##2##3
+ {
+ \prop_put:Nnn \l_@@_tmp_prop {##1} {##3}
+ \@@_grab_k_loop:nnN {#4} { } ##2 \q_recursion_stop
+ }
+ \prop_clear:N \l_@@_tmp_prop
+ \cs_set_protected:Npn \@@_grab_k_finalise:
+ {
+ \tl_clear:N \l_@@_tmpa_tl
+ \tl_map_inline:nn {#1}
+ {
+ \prop_get:NnNF \l_@@_tmp_prop {####1} \l_@@_tmpb_tl
+ { \tl_set_eq:NN \l_@@_tmpb_tl \c_@@_no_value_tl }
+ \tl_set:Nx \l_@@_tmpa_tl
+ {
+ \exp_not:V \l_@@_tmpa_tl
+ { \exp_not:V \l_@@_tmpb_tl }
+ }
+ }
+ \@@_add_arg:V \l_@@_tmpa_tl
+ #2 \l_@@_args_tl
+ }
+ \@@_grab_k_loop:nnN {#4} { } #1 \q_recursion_tail \q_recursion_stop
+ }
+\cs_new_protected:Npn \@@_grab_k_loop:nnN #1#2#3#4 \q_recursion_stop
+ {
+ \cs_if_eq:NNTF #3 \q_recursion_tail
+ { \@@_grab_k_finalise: }
+ {
+ \use:c { peek_meaning_remove #1 :NTF } #3
+ { \l_@@_fn_tl #3 {#2#4} }
+ { \@@_grab_k_loop:nnN {#1} {#2#3} #4 \q_recursion_stop }
+ }
+ }
+\cs_new_protected:Npn \@@_grab_k_finalise: { }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
% \end{macro}
% \end{macro}
%
@@ -2901,29 +2897,6 @@
% \end{macro}
% \end{macro}
%
-% \begin{macro}[EXP]{\@@_expandable_grab_K:w}
-% \begin{macro}[EXP, aux]{\@@_expandable_grab_K_aux:NNwn}
-% As for the |D|-type grabber, use the auxiliary to do the look ahead
-% test then reuse it for the grabbing.
-% \begin{macrocode}
-\cs_new:Npn \@@_expandable_grab_K:w #1 \q_@@ #2
- { #2 { \@@_expandable_grab_K_aux:NNwn #1 \q_@@ #2 } }
-\cs_new:Npn \@@_expandable_grab_K_aux:NNwn #1#2#3#4 \q_@@ #5#6
- {
- \str_if_eq:onTF { #1 { } #6 { } #2 { } } { { } #2 { } }
- {
- #1
- { \@@_expandable_grab_K_aux:Nwn #5 #4 \q_@@ }
- #6
- }
- { #4 {#3} \q_@@ #5 {#6} }
- }
-\cs_new:Npn \@@_expandable_grab_K_aux:Nwn #1#2 \q_@@ #3
- { #2 {#3} \q_@@ #1 }
-% \end{macrocode}
-% \end{macro}
-% \end{macro}
-%
% \begin{macro}[EXP]{\@@_expandable_grab_m:w}
% \begin{macro}[EXP, aux]{\@@_expandable_grab_m_aux:wNn}
% The mandatory case is easy: find the auxiliary after the \cs{q_@@}, and
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the latex3-commits
mailing list