summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/l3packages/xparse.dtx
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-08-30 03:01:17 +0000
committerNorbert Preining <norbert@preining.info>2023-08-30 03:01:17 +0000
commit4fee29360f7566a474b6143951b0744fa151edc9 (patch)
tree1af77d3ca21368f054b09f30dd60e8028a91be62 /macros/latex/contrib/l3packages/xparse.dtx
parent64e26532c685fd24d6983508c6239e3c268b810b (diff)
CTAN sync 202308300301
Diffstat (limited to 'macros/latex/contrib/l3packages/xparse.dtx')
-rw-r--r--macros/latex/contrib/l3packages/xparse.dtx147
1 files changed, 145 insertions, 2 deletions
diff --git a/macros/latex/contrib/l3packages/xparse.dtx b/macros/latex/contrib/l3packages/xparse.dtx
index b5adb20dae..72a31e6871 100644
--- a/macros/latex/contrib/l3packages/xparse.dtx
+++ b/macros/latex/contrib/l3packages/xparse.dtx
@@ -67,7 +67,7 @@
% }^^A
% }
%
-% \date{Released 2023-02-02}
+% \date{Released 2023-08-29}
%
% \maketitle
%
@@ -1064,7 +1064,7 @@
% \end{macrocode}
%
% \begin{macrocode}
-\ProvidesExplPackage{xparse}{2023-02-02}{}
+\ProvidesExplPackage{xparse}{2023-08-29}{}
{L3 Experimental document command parser}
% \end{macrocode}
%
@@ -1380,6 +1380,149 @@
% \end{macrocode}
% \end{macro}
%
+% \subsection{Access to the argument specification}
+%
+% At one point this was included in the kernel, so we have to use
+% \texttt{gset} (or similar) throughout this subsection.
+%
+% \begin{macro}{\@@_get_arg_spec_error:N, \@@_get_arg_spec_error:n}
+% \begin{macro}{\@@_get_arg_spec_error_aux:n}
+% Provide an informative error when trying to get the argument
+% specification of a non-\pkg{xparse} command or environment.
+% \begin{macrocode}
+\cs_gset_protected:Npn \@@_get_arg_spec_error:N #1
+ {
+ \bool_set_false:N \l_@@_environment_bool
+ \tl_set:Nn \l_@@_fn_tl {#1}
+ \@@_get_arg_spec_error_aux:n { \cs_if_exist:NTF #1 }
+ }
+\cs_gset_protected:Npn \@@_get_arg_spec_error:n #1
+ {
+ \bool_set_true:N \l_@@_environment_bool
+ \str_set:Nx \l_@@_environment_str {#1}
+ \@@_get_arg_spec_error_aux:n
+ { \cs_if_exist:cTF { \l_@@_environment_str } }
+ }
+\cs_gset_protected:Npn \@@_get_arg_spec_error_aux:n #1
+ {
+ #1
+ {
+ \msg_error:nnx { cmd } { non-xparse }
+ { \@@_environment_or_command: }
+ }
+ {
+ \msg_error:nnx { cmd } { unknown }
+ { \@@_environment_or_command: }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_get_arg_spec:NTF}
+% If the command is not an \pkg{xparse} command, complain. If it is,
+% its second \enquote{item} is the argument specification.
+% \begin{macrocode}
+\cs_gset_protected:Npn \@@_get_arg_spec:NTF #1#2#3
+ {
+ \__kernel_cmd_if_xparse:NTF #1
+ {
+ \tl_set:Nx \ArgumentSpecification { \tl_item:Nn #1 { 2 } }
+ #2
+ }
+ {#3}
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{variable}{\ArgumentSpecification}
+% \begin{macrocode}
+\tl_clear_new:N \ArgumentSpecification
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}{\@@_get_arg_spec:N}
+% \begin{macro}{\@@_get_arg_spec:n}
+% Recovering the argument specification is now trivial.
+% \begin{macrocode}
+\cs_gset_protected:Npn \@@_get_arg_spec:N #1
+ {
+ \@@_get_arg_spec:NTF #1 { }
+ { \@@_get_arg_spec_error:N #1 }
+ }
+\cs_gset_protected:Npn \@@_get_arg_spec:n #1
+ {
+ \exp_args:Nc \@@_get_arg_spec:NTF
+ { environment~ \tl_to_str:n {#1} }
+ { }
+ { \@@_get_arg_spec_error:n {#1} }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\@@_show_arg_spec:N}
+% \begin{macro}{\@@_show_arg_spec:n}
+% Showing the argument specification simply means finding it and then
+% calling the \cs{tl_show:N} function.
+% \begin{macrocode}
+\cs_gset_protected:Npn \@@_show_arg_spec:N #1
+ {
+ \@@_get_arg_spec:NTF #1
+ { \tl_show:N \ArgumentSpecification }
+ { \@@_get_arg_spec_error:N #1 }
+ }
+\cs_gset_protected:Npn \@@_show_arg_spec:n #1
+ {
+ \exp_args:Nc \@@_get_arg_spec:NTF
+ { environment~ \tl_to_str:n {#1} }
+ { \tl_show:N \ArgumentSpecification }
+ { \@@_get_arg_spec_error:n {#1} }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}{\GetDocumentCommandArgSpec}
+% \begin{macro}{\GetDocumentEnvironmentArgSpec}
+% \begin{macro}{\ShowDocumentCommandArgSpec}
+% \begin{macro}{\ShowDocumentEnvironmentArgSpec}
+% Simple mappings, with a check that the argument is a single
+% control sequence or active character.
+% \begin{macrocode}
+\cs_gset_protected:Npn \GetDocumentCommandArgSpec #1
+ {
+ \@@_check_definable:nNT {#1} \GetDocumentCommandArgSpec
+ { \@@_get_arg_spec:N #1 }
+ }
+\cs_gset_eq:NN \GetDocumentEnvironmentArgSpec \@@_get_arg_spec:n
+\cs_gset_protected:Npn \ShowDocumentCommandArgSpec #1
+ {
+ \@@_check_definable:nNT {#1} \ShowDocumentCommandArgSpec
+ { \@@_show_arg_spec:N #1 }
+ }
+\cs_gset_eq:NN \ShowDocumentEnvironmentArgSpec \@@_show_arg_spec:n
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macrocode}
+\msg_set:nnnn { cmd } { non-xparse }
+ { \str_uppercase:n #1~not~defined~using~xparse. }
+ {
+ You~have~asked~for~the~argument~specification~for~the~#1,~
+ but~this~was~not~defined~using~xparse.
+ }
+\msg_set:nnnn { cmd } { unknown }
+ { Unknown~document~#1. }
+ {
+ You~have~asked~for~the~argument~specification~for~the~#1,~
+ but~it~is~not~defined.
+ }
+% \end{macrocode}
+%
% \begin{macrocode}
%</package>
% \end{macrocode}