diff options
author | Karl Berry <karl@freefriends.org> | 2012-01-19 22:49:40 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2012-01-19 22:49:40 +0000 |
commit | 1148f4718708f720f250d1e258b9cc429bf30168 (patch) | |
tree | 53fa63c41b0c657d758836916573cc5a1cd10652 /Master/texmf-dist/source | |
parent | 8764984f07460a77b8200111ddb513c8af6c23f3 (diff) |
l3packages 3209 (19jan12)
git-svn-id: svn://tug.org/texlive/trunk@25159 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source')
4 files changed, 1587 insertions, 1216 deletions
diff --git a/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e-demo.tex b/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e-demo.tex new file mode 100644 index 00000000000..96d007999ac --- /dev/null +++ b/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e-demo.tex @@ -0,0 +1,43 @@ +% This file demonstrates the use of the l3keys2e module to allow +% LaTeX3 keyvals (created using l3keys) to be used as LaTeX2e +% package or class options. +% + +% First, create a class +\begin{filecontents}{l3keys2e-class.cls} + \LoadClass{article} + \RequirePackage{l3keys2e} + \ProvidesExplClass{l3keys2e-class}{0000/00/00}{0.0}{test} + \keys_define:nn { test1 } { + option1 .code:n = {\wlog{You~gave~`#1'~for~option1}} + } + \ProcessKeysOptions { test1 } +\end{filecontents} + +% Load the class with some options. +% The class itself recognises `option1', leaving `option2' and +% `option3' as global optons which are not yet used. +\documentclass[option1=check,option2=more stuff,option3=unused] + {l3keys2e-class} + +%Now create a package +\begin{filecontents}{l3keys2e-package.sty} + \RequirePackage{l3keys2e} + \ProvidesExplPackage{l3keys2e-package}{0000/00/00}{0.0}{test} + \keys_define:nn { test2 } { + option1 .code:n = {\wlog{You~gave~`#1'~for~option1~(again)}}, + option2 .code:n = {\wlog{You~gave~`#1'~for~option2}}, + option4 .code:n = {\wlog{You~gave~`#1'~for~option4}}, + } + \ProcessKeysOptions { test2 } +\end{filecontents} + +% Load the package. +\usepackage[option4={extra stuff},option5=undefined!] + {l3keys2e-package} + +\begin{document} +% The log should show that option3 is an unused global option, and that +% option5 is not known by the l3keys2e-demo package. Everything else +% should simply be listed in the log. +\end{document} diff --git a/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.dtx b/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.dtx index 240b7f2ceb2..23904106533 100644 --- a/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.dtx +++ b/Master/texmf-dist/source/latex/l3packages/l3keys2e/l3keys2e.dtx @@ -1,6 +1,6 @@ % \iffalse meta-comment % -%% File: l3keys2e.dtx (C) Copyright 2009,2011 The LaTeX3 Project +%% File: l3keys2e.dtx (C) Copyright 2009,2011,2012 The LaTeX3 Project %% %% It may be distributed and/or modified under the conditions of the %% LaTeX Project Public License (LPPL), either version 1.3c of this @@ -35,8 +35,22 @@ %% % %<*driver|package> +% The version of expl3 required is tested as early as possible, as +% some really old versions do not define \ProvidesExplPackage. +\RequirePackage{expl3}[2012/01/19] +%<package>\@ifpackagelater{expl3}{2012/01/19} +%<package> {} +%<package> { +%<package> \PackageError{l3keys2e}{Support package l3kernel too old.} +%<package> { +%<package> Please install an up to date~version of l3kernel +%<package> using your TeX package manager or from CTAN.\\ \\ +%<package> Loading l3keys2e will abort! +%<package> } +%<package> \endinput +%<package> } \RequirePackage{xparse} -\GetIdInfo$Id: l3keys2e.dtx 3109 2011-12-29 10:42:27Z joseph $ +\GetIdInfo$Id: l3keys2e.dtx 3207 2012-01-19 08:50:24Z joseph $ {LaTeX2e option processing using LaTeX3 keys} %</driver|package> %<*driver> @@ -134,21 +148,6 @@ \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} % \end{macrocode} -% -% A check to make sure that \pkg{expl3} is not too old -% \begin{macrocode} -\@ifpackagelater { expl3 } { 2011/12/29 } - { } - { - \PackageError { l3keys2e } { Support~package~l3kernel~too~old. } - { - Please~install~an~up~to~date~version~of~l3kernel~ - using~your~TeX~package~manager~or~from~CTAN.\\ \\ - Loading~l3keys2e~will~abort! - } - \tex_endinput:D - } -% \end{macrocode} % % \begin{macro}{\keys_latexe_options_clist} % A single list is used for all options, into which they are collected diff --git a/Master/texmf-dist/source/latex/l3packages/xparse/xparse.dtx b/Master/texmf-dist/source/latex/l3packages/xparse/xparse.dtx index acde2c3914e..e6fbc7a4b6a 100644 --- a/Master/texmf-dist/source/latex/l3packages/xparse/xparse.dtx +++ b/Master/texmf-dist/source/latex/l3packages/xparse/xparse.dtx @@ -4,7 +4,7 @@ %% David Carlisle %% (C) Copyright 2004-2008 Frank Mittelbach, %% The LaTeX3 Project -%% (C) Copyright 2009-2011 The LaTeX3 Project +%% (C) Copyright 2009-2012 The LaTeX3 Project %% %% It may be distributed and/or modified under the conditions of the %% LaTeX Project Public License (LPPL), either version 1.3c of this @@ -39,8 +39,21 @@ %% % %<*driver|package> -\RequirePackage{expl3} -\GetIdInfo$Id: xparse.dtx 3109 2011-12-29 10:42:27Z joseph $ +% The version of expl3 required is tested as early as possible, as +% some really old versions do not define \ProvidesExplPackage. +\RequirePackage{expl3}[2012/01/19] +%<package>\@ifpackagelater{expl3}{2012/01/19} +%<package> {} +%<package> { +%<package> \PackageError{xparse}{Support package l3kernel too old.} +%<package> { +%<package> Please install an up to date~version of l3kernel +%<package> using your TeX package manager or from CTAN.\\ \\ +%<package> Loading xparse will abort! +%<package> } +%<package> \endinput +%<package> } +\GetIdInfo$Id: xparse.dtx 3209 2012-01-19 09:21:50Z joseph $ {L3 Experimental document command parser} %</driver|package> %<*driver> @@ -132,7 +145,15 @@ % type specifier for a normal \TeX{} argument. % \item[l] An argument which reads everything up to the first % open group token: in standard \LaTeX{} this is a left brace. -% \item[u] Reads an argument `until' \meta{tokens} are encountered, +% \item[r] Reads a \enquote{required} delimited argument, where the +% delimiters are given as \meta{token1} and \meta{token2}: +% \texttt{r}\meta{token1}\meta{token2}. If the opening \meta{token} +% is missing, the default value \cs{NoValue} will be inserted after +% a suitable error. +% \item[R] As for \texttt{r}, this is a \enquote{required} delimited +% argument but has a user-definable recovery \meta{default}, given +% as \texttt{R}\meta{token1}\meta{token2}\marg{default}. +% \item[u] Reads an argument \enquote{until} \meta{tokens} are encountered, % where the desired \meta{tokens} are given as an argument to the % specifier: \texttt{u}\marg{tokens}. % \item[v] Reads an argument \enquote{verbatim}, between the following @@ -147,7 +168,7 @@ % \end{itemize} % The types which define optional arguments are: % \begin{itemize}[font=\ttfamily] -% \item[o] A standard \LaTeX\ optional argument, surrounded with square +% \item[o] A standard \LaTeX{} optional argument, surrounded with square % brackets, which will supply % the special \cs{NoValue} token if not given (as described later). % \item[d] An optional argument which is delimited by \meta{token1} @@ -166,7 +187,7 @@ % \item[t] An optional \meta{token}, which will result in a value % \cs{BooleanTrue} if \meta{token} is present and \cs{BooleanFalse} % otherwise. Given as \texttt{t}\meta{token}. -% \item[g] An optional argument given inside a pair of \TeX\ group +% \item[g] An optional argument given inside a pair of \TeX{} group % tokens (in standard \LaTeX, |{| \ldots |}|), which returns % \cs{NoValue} if not present. % \item[G] As for \texttt{g} but returns \meta{default} if no value @@ -237,6 +258,23 @@ % \verb*|\foo{arg1} [arg2]| will not. This is so that trailing optional % arguments are not picked up \enquote{by accident} in input. % +% \subsection{Required delimited arguments} +% +% The contrast between a delimited (\texttt{D}-type) and \enquote{required +% delimited} (\texttt{R}-type) argument is that an error will be raised if +% the latter is missing. Thus for example +% \begin{verbatim} +% \DeclareDocumentCommand\foo{r()m} +% \foo{oops} +% \end{verbatim} +% will lead to an error message being issued. The marker \cs{NoValue} +% (\texttt{r}-type) or user-specified default (for \texttt{R}-type) will be +% inserted to allow error recovery. +% +% Users should note that support for required delimited arguments is somewhat +% experimental. Feedback is therefore very welcome on the \texttt{LaTeX-L} +% mailing list. +% % \subsection{Verbatim arguments} % % Arguments of type \enquote{\texttt{v}} are read in verbatim mode, which will @@ -488,6 +526,22 @@ % before the split takes place. % \end{function} % +% \begin{function}[EXP]{\ProcessList} +% \begin{syntax} +% \cs{ProcessList} \Arg{list} \Arg{function} +% \end{syntax} +% To support \cs{SplitList}, the function \cs{ProcessList} is available +% to apply a \meta{function} to every entry in a \meta{list}. The +% \meta{function} should absorb one argument: the list entry. For example +% \begin{verbatim} +% \DeclareDocumentCommand \foo +% { > { \SplitList { ; } } m } +% { \ProcessList {#1} { \SomeDocumentFunction } } +% \end{verbatim} +% +% \textbf{This function is experimental.} +% \end{function} +% % \begin{function}{\TrimSpaces} % \begin{syntax} % \cs{TrimSpaces} @@ -512,35 +566,6 @@ % \textbf{This function is experimental.} % \end{function} % -% \subsection{Separating interface and implementation} -% -% One \emph{experimental} idea implemented in \pkg{xparse} is to -% separate out document command interfaces (the argument specification) -% from the implementation (code). This is carried out using a -% pair of functions, \cs{DeclareDocumentCommandInterface} and -% \cs{DeclareDocumentCommandImplementation} -% -% \begin{function}{\DeclareDocumentCommandInterface} -% \begin{syntax} -% \cs{DeclareDocumentCommandInterface} \meta{function} -% ~~~~\Arg{implementation} \Arg{arg spec} -% \end{syntax} -% This declares a \meta{function}, which will take arguments as detailed -% in the \meta{arg spec}. When executed, the \meta{function} will look for -% code stored as an \meta{implementation}. -% \end{function} -% -% \begin{function}{\DeclareDocumentCommandImplementation} -% \begin{syntax} -% \cs{DeclareDocumentCommandImplementation} -% ~~~~\Arg{implementation} \meta{args} \Arg{code} -% \end{syntax} -% Declares the \meta{implementation} for a function to accept \meta{args} -% arguments and expand to \meta{code}. An implementation must take the -% same number of arguments as a linked interface, although this is not -% enforced by the code. -% \end{function} -% % \subsection{Fully-expandable document commands} % % There are \emph{very rare} occasion when it may be useful to create @@ -570,8 +595,8 @@ % available: % \begin{itemize} % \item The last argument (if any are present) must be one of the -% mandatory types \texttt{m} or \texttt{u}. (Type \texttt{l} is -% not available.) +% mandatory types \texttt{m} or \texttt{r}. (Types \texttt{l} and +% \texttt{u} are not available.) % \item All arguments are either short or long: it is not possible % to mix short and long argument types. % \item The \enquote{optional group} argument types \texttt{g} and @@ -645,22 +670,6 @@ % \begin{macrocode} \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} -\RequirePackage{expl3} -% \end{macrocode} -% -% A check to make sure that \pkg{expl3} is not too old -% \begin{macrocode} -\@ifpackagelater { expl3 } { 2011/12/29 } - { } - { - \PackageError { xparse } { Support~package~l3kernel~too~old. } - { - Please~install~an~up~to~date~version~of~l3kernel~ - using~your~TeX~package~manager~or~from~CTAN.\\ \\ - Loading~xparse~will~abort! - } - \tex_endinput:D - } % \end{macrocode} % % \subsection{Variables and constants} @@ -681,16 +690,19 @@ % Maybe |$| or |&| will have to be added later. % \begin{macrocode} %<*initex> +\seq_new:N \c_xparse_special_chars_seq \seq_set_from_clist:Nn \c_xparse_special_chars_seq { \ , \\ , \{ , \} , \# , \^ , \_ , \% , \~ } %</initex> % \end{macrocode} % \end{variable} % -% \begin{variable}{\l_xparse_arg_tl} -% Token list variable for single grabbed argument when post-processing. +% \begin{variable}{\l_xparse_all_long_bool} +% For expandable commands, all arguments have the same long status, but this +% needs to be checked. A flag is therefore needed to track whether arguments +% are long at all. % \begin{macrocode} -\tl_new:N \l_xparse_arg_tl +\bool_new:N \l_xparse_all_long_bool % \end{macrocode} % \end{variable} % @@ -701,67 +713,109 @@ % \end{macrocode} % \end{variable} % +% \begin{variable}{\l_xparse_command_arg_specs_prop} +% Used to record all document commands created, and the argument +% specifications that go with these. +% \begin{macrocode} +\prop_new:N \l_xparse_command_arg_specs_prop +% \end{macrocode} +% \end{variable} +% +% \begin{variable}{\l_xparse_current_arg_int} +% The number of the current argument being set up: this is used for creating +% the expandable auxiliary functions, and also to indicate if all arguments +% are \texttt{m}-type. +% \begin{macrocode} +\int_new:N \l_xparse_current_arg_int +% \end{macrocode} +% \end{variable} +% % \begin{variable}{\l_xparse_environment_bool} -% Generating environments uses the same mechanism as generating -% functions. However, full processing of arguments is always needed -% for environments, and so the function-generating code needs to -% know this. +% Generating environments uses the same mechanism as generating functions. +% However, full processing of arguments is always needed for environments, +% and so the function-generating code needs to know this. % \begin{macrocode} \bool_new:N \l_xparse_environment_bool % \end{macrocode} % \end{variable} % -% \begin{variable}{\l_xparse_function_tl} -% When creating expandable functions, the current function name needs -% to be passed along. +% \begin{variable}{\l_xparse_environment_arg_specs_prop} +% Used to record all document environment created, and the argument +% specifications that go with these. % \begin{macrocode} -\tl_new:N \l_xparse_function_tl +\prop_new:N \l_xparse_environment_arg_specs_prop % \end{macrocode} % \end{variable} % -% \begin{variable}{\l_xparse_last_arg_tl} -% Used when creating expandable arguments. +% \begin{variable}{\l_xparse_expandable_bool} +% Used to indicate if an expandable command is begin generated, as this +% affects both the acceptable argument types and how they are implemented. % \begin{macrocode} -\tl_new:N \l_xparse_last_arg_tl +\bool_new:N \l_xparse_expandable_bool % \end{macrocode} % \end{variable} % -% \begin{variable}{\l_xparse_long_bool} -% A flag for \cs{long} arguments. +% \begin{variable}{\l_xparse_expandable_aux_name_tl} +% Used to create pretty-printing names for the auxiliaries: although the +% immediate definition does not vary, the full expansion does and so it +% does not count as a constant. % \begin{macrocode} -\bool_new:N \l_xparse_long_bool +\tl_new:N \l_xparse_expandable_aux_name_tl +\tl_set:Nn \l_xparse_expandable_aux_name_tl + { + \l_xparse_function_tl \c_space_tl + ( arg~ \int_use:N \l_xparse_current_arg_int ) + } % \end{macrocode} % \end{variable} % -% \begin{variable}{\l_xparse_m_args_int} -% The number of simple \texttt{m} arguments is tracked so they can be -% dumped \emph{en masse}. +% \begin{variable}{\l_xparse_fn_tl} +% For passing the pre-formed name of the auxiliary to be used as the +% parsing function. % \begin{macrocode} -\int_new:N \l_xparse_m_args_int +\tl_new:N \l_xparse_fn_tl +% \end{macrocode} +% \end{variable} +% +% \begin{variable}{\l_xparse_function_tl} +% Holds the control sequence name of the function currently being +% defined: used to avoid passing this as an argument and to avoid repeated +% use of \cs{cs_to_str:N}. +% \begin{macrocode} +\tl_new:N \l_xparse_function_tl +% \end{macrocode} +% \end{variable} +% +% \begin{variable}{\l_xparse_long_bool} +% Used to indicate that an argument is long: this is used on a per-argument +% basis for non-expandable functions, or for the entire set of arguments +% when working expandably. +% \begin{macrocode} +\bool_new:N \l_xparse_long_bool % \end{macrocode} % \end{variable} % -% \begin{variable}{\l_xparse_m_only_bool} -% A flag to indicate that only \texttt{m} arguments have been found. +% \begin{variable}{\l_xparse_m_args_int} +% The number of \texttt{m} arguments: if this is the same as the total +% number of arguments, then a short-cut can be taken in the creation of +% the grabber code. % \begin{macrocode} -\bool_new:N \l_xparse_m_only_bool +\int_new:N \l_xparse_m_args_int % \end{macrocode} % \end{variable} % % \begin{variable}{\l_xparse_mandatory_args_int} -% So that trailing optional arguments can be picked up, a count has to -% be taken of all mandatory arguments. This is then decreased as -% mandatory arguments are added to the signature, so will be zero -% only if there are no more mandatory arguments to add. +% Holds the total number of mandatory arguments for a function, which is +% needed to tell whether further mandatory arguments follow an optional +% one. % \begin{macrocode} \int_new:N \l_xparse_mandatory_args_int % \end{macrocode} % \end{variable} % % \begin{variable}{\l_xparse_processor_bool} -% When reading through the argument specifier, a flag is needed to -% show that a processor has been found for the current argument. This -% is used when checking how to handle \texttt{m} arguments. +% Indicates that the current argument will be followed by one or more +% processors. % \begin{macrocode} \bool_new:N \l_xparse_processor_bool % \end{macrocode} @@ -777,66 +831,460 @@ % \end{variable} % % \begin{variable}{\l_xparse_signature_tl} -% Token list variable for constructing signatures. +% Used when constructing the signature (code for argument grabbing) to +% hold what will become the implementation of the main function. % \begin{macrocode} \tl_new:N \l_xparse_signature_tl % \end{macrocode} -%\end{variable} +% \end{variable} % % \begin{variable}{\l_xparse_tmp_tl} -% A general purpose token list variable. +% Scratch space. % \begin{macrocode} \tl_new:N \l_xparse_tmp_tl % \end{macrocode} % \end{variable} % -% \begin{variable}{\l_xparse_total_args_int} -% The total number of arguments is used to create the internal function -% which has a fixed number of arguments. +% \subsection{Declaring commands and environments} +% +% \begin{macro}{\xparse_declare_cmd:Nnn, \xparse_declare_expandable_cmd:Nnn} +% \begin{macro}[aux]{\xparse_declare_cmd_aux:Nnn} +% \begin{macro}[int] +% {\xparse_declare_cmd_internal:Nnn, \xparse_declare_cmd_internal:cnx} +% The main functions for creating commands set the appropriate flag then +% use the same internal code to do the definition. % \begin{macrocode} -\int_new:N \l_xparse_total_args_int +\cs_new_protected_nopar:Npn \xparse_declare_cmd:Nnn + { + \bool_set_false:N \l_xparse_expandable_bool + \xparse_declare_cmd_aux:Nnn + } +\cs_new_protected_nopar:Npn \xparse_declare_expandable_cmd:Nnn + { + \bool_set_true:N \l_xparse_expandable_bool + \xparse_declare_cmd_aux:Nnn + } % \end{macrocode} -% \end{variable} +% The first stage is to log information, both for the user in the log and +% for programmatic use in a property list of all declared commands. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_declare_cmd_aux:Nnn #1#2 + { + \cs_if_exist:NTF #1 + { + \msg_kernel_warning:nnxx { xparse } { redefine-command } + { \token_to_str:N #1 } { \tl_to_str:n {#2} } + } + { + \msg_kernel_info:nnxx { xparse } { define-command } + { \token_to_str:N #1 } { \tl_to_str:n {#2} } + } + \prop_put:Nnn \l_xparse_command_arg_specs_prop {#1} {#2} + \bool_set_false:N \l_xparse_environment_bool + \xparse_declare_cmd_internal:Nnn #1 {#2} + } +% \end{macrocode} +% The real business of defining a document command starts with setting up +% the appropriate name, then counting up the number of mandatory arguments. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_declare_cmd_internal:Nnn #1#2#3 + { + \tl_set:Nx \l_xparse_function_tl { \cs_to_str:N #1 } + \xparse_count_mandatory:n {#2} + \xparse_prepare_signature:n {#2} + \int_compare:nNnTF \l_xparse_current_arg_int = \l_xparse_m_args_int + { + \bool_if:NTF \l_xparse_environment_bool + { \xparse_declare_cmd_mixed:Nn #1 {#3} } + { \xparse_declare_cmd_all_m:Nn #1 {#3} } + } + { \xparse_declare_cmd_mixed:Nn #1 {#3} } + \xparse_break_point:n {#2} + } +\cs_generate_variant:Nn \xparse_declare_cmd_internal:Nnn { cnx } +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\xparse_break_point:n} +% A marker used to escape from creating a definition if necessary. +% \begin{macrocode} +\cs_new_eq:NN \xparse_break_point:n \use_none:n +% \end{macrocode} +% \end{macro} % -% \subsection{Turning the argument specifier into grabbers} +% \begin{macro}{\xparse_declare_cmd_all_m:Nn, \xparse_declare_cmd_mixed:Nn} +% \begin{macro}[aux] +% {\xparse_declare_cmd_mixed_aux:Nn, \xparse_declare_cmd_mixed_expandable:Nn} +% When all of the arguments to grab are simple \texttt{m}-type, a short +% cut can be taken to provide only a single function. In the case of +% expandable commands, this can also happen for \texttt{+m} (as all arguments +% in this case must be long). +% \begin{macrocode} +\cs_new_protected:Npn \xparse_declare_cmd_all_m:Nn #1#2 + { + \cs_generate_from_arg_count:Ncnn #1 + { + cs_set + \bool_if:NF \l_xparse_expandable_bool { _protected } + \bool_if:NF \l_xparse_all_long_bool { _nopar } + :Npn + } + \l_xparse_current_arg_int {#2} + } +% \end{macrocode} +% In the case of mixed arguments, any remaining \texttt{m}-type ones are +% first added to the signature, then the appropriate auxiliary is called. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_declare_cmd_mixed:Nn + { + \bool_if:NTF \l_xparse_expandable_bool + { \xparse_declare_cmd_mixed_expandable:Nn } + { \xparse_declare_cmd_mixed_aux:Nn } + } +% \end{macrocode} +% Creating standard functions with mixed arg.~specs sets up the main function +% to zero the number of processors, set the name of the function (for the +% grabber) and clears the list of grabbed arguments. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_declare_cmd_mixed_aux:Nn #1#2 + { + \xparse_flush_m_args: + \cs_generate_from_arg_count:cNnn + { \l_xparse_function_tl \c_space_tl code } + \cs_set_protected:Npn \l_xparse_current_arg_int {#2} + \cs_set_protected_nopar:Npx #1 + { + \int_zero:N \l_xparse_processor_int + \tl_set:Nn \exp_not:N \l_xparse_args_tl + { \exp_not:c { \l_xparse_function_tl \c_space_tl code } } + \tl_set:Nn \exp_not:N \l_xparse_fn_tl + { \exp_not:c { \l_xparse_function_tl \c_space_tl } } + \exp_not:o \l_xparse_signature_tl + \exp_not:N \l_xparse_args_tl + } + } +\cs_new_protected:Npn \xparse_declare_cmd_mixed_expandable:Nn #1#2 + { + \cs_generate_from_arg_count:cNnn + { \l_xparse_function_tl \c_space_tl code } + \cs_set:Npn \l_xparse_current_arg_int {#2} + \cs_set_nopar:Npx #1 + { + \exp_not:o \l_xparse_signature_tl + \exp_not:N \xparse_grab_expandable_end:wN + \exp_not:c { \l_xparse_function_tl \c_space_tl code } + \exp_not:N \q_xparse + \exp_not:c { \l_xparse_function_tl \c_space_tl } + } + \bool_if:NTF \l_xparse_long_bool + { \cs_set:cpx } + { \cs_set_nopar:cpx } + { \l_xparse_function_tl \c_space_tl } ##1##2 { ##1 {##2} } + } +% \end{macrocode} +% \end{macro} +% \end{macro} % -% \begin{macro}{\xparse_add_grabber_mandatory:N} -% \begin{macro}{\xparse_add_grabber_optional:N} -% To keep the various checks needed in one place, adding the grabber to -% the signature is done here. For mandatory arguments, the only question -% is whether to add a long grabber. For optional arguments, there is -% also a check to see if any mandatory arguments are still to be added. -% This is used to determine whether to skip spaces or not where -% searching for the argument. +% \begin{macro}{\xparse_declare_env:nnnn} +% \begin{macro}[int]{\xparse_declare_env_internal:nnnn} +% The lead-off to creating an environment is much the same as that for +% creating a command: issue the appropriate message, store the argument +% specification then hand off to an internal function. % \begin{macrocode} -\cs_new_protected_nopar:Npn \xparse_add_grabber_mandatory:N #1 +\cs_new_protected:Npn \xparse_declare_env:nnnn #1#2 { - \tl_put_right:Nx \l_xparse_signature_tl +%<*initex> + \cs_if_exist:cTF { environment~ #1 } +%</initex> +%<*package> + \cs_if_exist:cTF {#1} +%</package> { - \exp_not:c - { xparse_grab_ #1 \bool_if:NT \l_xparse_long_bool { _long } :w } + \msg_kernel_warning:nnxx { xparse } { redefine-environment } + {#1} { \tl_to_str:n {#2} } } - \bool_set_false:N \l_xparse_long_bool - \int_decr:N \l_xparse_mandatory_args_int + { + \msg_kernel_info:nnxx { xparse } { define-environment } + {#1} { \tl_to_str:n {#2} } + } + \prop_put:Nnn \l_xparse_environment_arg_specs_prop {#1} {#2} + \bool_set_true:N \l_xparse_environment_bool + \xparse_declare_env_internal:nnnn {#1} {#2} } -\cs_new_protected_nopar:Npn \xparse_add_grabber_optional:N #1 +% \end{macrocode} +% Creating a document environment requires a few more steps than creating +% a single command. In order to pass the arguments of the command to the +% end of the function, it is necessary to store the grabbed arguments. +% To do that, the function used at the end of the environment has to be +% redefined to contain the appropriate information. To minimize the amount +% of expansion at point of use, the code here is expanded now as well as +% when used. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_declare_env_internal:nnnn #1#2#3#4 { - \tl_put_right:Nx \l_xparse_signature_tl + \xparse_declare_cmd_internal:cnx { environment~ #1 } {#2} { - \exp_not:c - { - xparse_grab_ #1 - \bool_if:NT \l_xparse_long_bool { _long } - \int_compare:nNnF \l_xparse_mandatory_args_int > \c_zero - { _trailing } - :w - } + \group_begin: + \cs_set_protected_nopar:Npx \exp_not:c { environment_ #1 _end_aux: } + { + \exp_not:c { environment_ #1 _end_aux:w } + \exp_not:n + { + \exp_args:No \exp_not:o + { \exp_after:wN \use_none:n \l_xparse_args_tl } + \exp_not:n + { + \if@endpe + \exp_after:wN \group_end: + \exp_after:wN \@endpetrue + \else + \exp_after:wN \group_end: + \fi + } + } + } + \exp_not:n {#3} } + \cs_set_protected_nopar:cpx { environment~ #1 ~end } + { \exp_not:c { environment_ #1 _end_aux: } } + \cs_generate_from_arg_count:cNnn + { environment_ #1 _end_aux:w } \cs_set_protected:Npn + \l_xparse_current_arg_int {#4} +%<*package> + \cs_set_eq:cc {#1} { environment~ #1 } + \cs_set_eq:cc { end #1 } { environment~ #1 ~end } +%</package> + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \subsection{Counting mandatory arguments} +% +% \begin{macro}{\xparse_count_mandatory:n} +% \begin{macro}{\xparse_count_mandatory:N} +% \begin{macro}[aux]{\xparse_count_mandatory:N} +% To count up mandatory arguments before the main parsing run, the same +% approach is used. First, check if the current token is a short-cut for +% another argument type. If it is, expand it and loop again. If not, then +% look for a \enquote{counting} function to check the argument type. No error +% is raised here if one is not found as one will be raised by later code. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_count_mandatory:n #1 + { + \int_zero:N \l_xparse_mandatory_args_int + \xparse_count_mandatory:N #1 + \q_recursion_tail \q_recursion_tail \q_recursion_tail \q_recursion_stop + } +\cs_new_protected:Npn \xparse_count_mandatory:N #1 + { + \quark_if_recursion_tail_stop:N #1 + \prop_get:NnNTF \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl + { \exp_after:wN \xparse_count_mandatory:N \l_xparse_tmp_tl } + { \xparse_count_mandatory_aux:N #1 } + } +\cs_new_protected:Npn \xparse_count_mandatory_aux:N #1 + { + \cs_if_free:cTF { xparse_count_type_ \token_to_str:N #1 :w } + { \xparse_count_type_m:w } + { \use:c { xparse_count_type_ \token_to_str:N #1 :w } } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro} +% { +% \xparse_count_type_>:w, +% \xparse_count_type_+:w, +% \xparse_count_type_d:w, +% \xparse_count_type_D:w, +% \xparse_count_type_g:w, +% \xparse_count_type_G:w, +% \xparse_count_type_m:w, +% \xparse_count_type_t:w, +% \xparse_count_type_u:w +% } +% For counting the mandatory arguments, a function is provided for each +% argument type that will mop any extra arguments and call the loop function. +% Only the counting functions for mandatory arguments actually do anything: +% the rest are simply there to ensure the loop continues correctly. There are +% no count functions for \texttt{l} or \texttt{v} argument types as they are +% exactly the same as \texttt{m}, and so a little code can be saved. +% +% The second thing that can be done here is to check that the signature is +% actually valid, such that all of the various argument types have the +% correct number of data items associated with them. If this fails to be +% the case, the entire set up is abandoned to avoid any strange internal +% errors. The opportunity is also taken to make sure that where a single +% token is required, one has actually been supplied. +% \begin{macrocode} +\cs_new_protected:cpn { xparse_count_type_>:w } #1 + { + \quark_if_recursion_tail_stop_do:nn {#1} { \xparse_bad_signature:wn } + \xparse_count_mandatory:N + } +\cs_new_protected_nopar:cpn { xparse_count_type_+:w } + { \xparse_count_mandatory:N } +\cs_new_protected:Npn \xparse_count_type_d:w #1#2 + { + \xparse_single_token_check:n {#1} + \xparse_single_token_check:n {#2} + \quark_if_recursion_tail_stop_do:Nn #2 { \xparse_bad_signature:wn } + \xparse_count_mandatory:N + } +\cs_new_protected:Npn \xparse_count_type_D:w #1#2#3 + { + \xparse_single_token_check:n {#1} + \xparse_single_token_check:n {#2} + \quark_if_recursion_tail_stop_do:nn {#3} { \xparse_bad_signature:wn } + \xparse_count_mandatory:N + } +\cs_new_protected_nopar:Npn \xparse_count_type_g:w + { \xparse_count_mandatory:N } +\cs_new_protected:Npn \xparse_count_type_G:w #1 + { + \quark_if_recursion_tail_stop_do:nn {#1} { \xparse_bad_signature:wn } + \xparse_count_mandatory:N + } +\cs_new_protected_nopar:Npn \xparse_count_type_m:w + { + \int_incr:N \l_xparse_mandatory_args_int + \xparse_count_mandatory:N + } +\cs_new_protected:Npn \xparse_count_type_r:w #1#2 + { + \xparse_single_token_check:n {#1} + \xparse_single_token_check:n {#2} + \quark_if_recursion_tail_stop_do:Nn #2 { \xparse_bad_signature:wn } + \int_incr:N \l_xparse_mandatory_args_int + \xparse_count_mandatory:N + } +\cs_new_protected:Npn \xparse_count_type_R:w #1#2#3 + { + \xparse_single_token_check:n {#1} + \xparse_single_token_check:n {#2} + \quark_if_recursion_tail_stop_do:nn {#3} { \xparse_bad_signature:wn } + \int_incr:N \l_xparse_mandatory_args_int + \xparse_count_mandatory:N + } +\cs_new_protected:Npn \xparse_count_type_t:w #1 + { + \xparse_single_token_check:n {#1} + \quark_if_recursion_tail_stop_do:Nn #1 { \xparse_bad_signature:wn } + \xparse_count_mandatory:N + } +\cs_new_protected:Npn \xparse_count_type_u:w #1 + { + \quark_if_recursion_tail_stop_do:nn {#1} { \xparse_bad_signature:wn } + \int_incr:N \l_xparse_mandatory_args_int + \xparse_count_mandatory:N + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\xparse_single_token_check:n} +% \begin{macro}[aux]{\xparse_single_token_check_aux:nwn} +% A spin-out function to check that what should be single tokens really +% are single tokens. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_single_token_check:n #1 + { + \tl_if_single:nF {#1} + { \xparse_single_token_check_aux:nwn {#1} } + } +\cs_new_protected:Npn \xparse_single_token_check_aux:nwn + #1#2 \xparse_break_point:n #3 + { + \msg_kernel_error:nnx { xparse } { not-single-token } + { \tl_to_str:n {#1} } { \tl_to_str:n {#3} } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{macro}{\xparse_bad_signature:wn} +% If the signature is wrong, this provides an escape from the entire +% definition process. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_bad_signature:wn #1 \xparse_break_point:n #2 + { \msg_kernel_error:nnx { xparse } { bad-signature } { \tl_to_str:n {#2} } } +% \end{macrocode} +% \end{macro} +% +% \subsection{Preparing the signature: general mechanism} +% +% \begin{macro}{\xparse_prepare_signature:n} +% \begin{macro}{\xparse_prepare_signature:N} +% \begin{macro}{\xparse_prepare_signature_bypass:N} +% \begin{macro}[aux]{\xparse_prepare_signature_add:N} +% Actually creating the signature uses the same loop approach as counting +% up mandatory arguments. There are first a number of variables which need +% to be set to track what is going on. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_prepare_signature:n #1 + { + \bool_set_false:N \l_xparse_all_long_bool + \int_zero:N \l_xparse_current_arg_int \bool_set_false:N \l_xparse_long_bool + \int_zero:N \l_xparse_m_args_int + \bool_set_false:N \l_xparse_processor_bool + \tl_clear:N \l_xparse_signature_tl + \xparse_prepare_signature:N #1 \q_recursion_tail \q_recursion_stop + } +% \end{macrocode} +% The main looping function does not take an argument,but carries out the +% reset on the processor boolean. This is split off from the rest of the +% process so that when actually setting up processors the flag-reset can +% be bypassed. +% \begin{macrocode} +\cs_new_protected_nopar:Npn \xparse_prepare_signature:N + { + \bool_set_false:N \l_xparse_processor_bool + \xparse_prepare_signature_bypass:N + } +\cs_new_protected:Npn \xparse_prepare_signature_bypass:N #1 + { + \quark_if_recursion_tail_stop:N #1 + \prop_get:NnNTF \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl + { \exp_after:wN \xparse_prepare_signature:N \l_xparse_tmp_tl } + { + \int_incr:N \l_xparse_current_arg_int + \xparse_prepare_signature_add:N #1 + } + } +% \end{macrocode} +% For each known argument type there is an appropriate function to actually +% do the addition to the signature. These are separate for expandable and +% standard functions, as the approaches are different. Of course, if the type +% is not known at all then a fall-back is needed. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_prepare_signature_add:N #1 + { + \cs_if_exist_use:cF + { + xparse_add + \bool_if:NT \l_xparse_expandable_bool { _expandable } + _type_ \token_to_str:N #1 :w + } + { + \msg_kernel_error:nnx { xparse } { unknown-argument-type } + { \token_to_str:N #1 } + \bool_if:NTF \l_xparse_expandable_bool + { \xparse_add_expandable_type_m:w } + { \xparse_add_type_m:w } + } } % \end{macrocode} % \end{macro} % \end{macro} +% \end{macro} +% \end{macro} +% +% \subsection{Setting up a standard signature} % % All of the argument-adding functions work in essentially the same % way, except the one for \texttt{m} arguments. Any collected \texttt{m} @@ -846,58 +1294,46 @@ % functions then call the loop function \cs{xparse_prepare_signature:N}. % % \begin{macro}{\xparse_add_type_+:w} -% Making the next argument \cs{long} means setting the flag and -% knocking one back off the total argument count. The \texttt{m} -% arguments are recorded here as this has to be done for every case -% where there is then a \cs{long} argument. +% Making the next argument long means setting the flag and knocking one back +% off the total argument count. The \texttt{m} arguments are recorded here as +% this has to be done for every case where there is then a long argument. % \begin{macrocode} \cs_new_protected_nopar:cpn { xparse_add_type_+:w } { \xparse_flush_m_args: \bool_set_true:N \l_xparse_long_bool - \bool_set_false:N \l_xparse_m_only_bool - \int_decr:N \l_xparse_total_args_int + \int_decr:N \l_xparse_current_arg_int \xparse_prepare_signature:N } % \end{macrocode} % \end{macro} % % \begin{macro}{\xparse_add_type_>:w} -% When a processor is found, the function \cs{xparse_process_arg:n} -% is added to the signature along with the processor code itself. When -% the signature is used, the code will be added to an execution list by +% When a processor is found, the function \cs{xparse_process_arg:n} is added +% to the signature along with the processor code itself. When the signature +% is used, the code will be added to an execution list by % \cs{xparse_process_arg:n}. Here, the loop calls -% \cs{xparse_prepare_signature_aux:N} rather than +% \cs{xparse_prepare_signature_bypass:N} rather than % \cs{xparse_prepare_signature:N} so that the flag is not reset. % \begin{macrocode} \cs_new_protected:cpn { xparse_add_type_>:w } #1 { \bool_set_true:N \l_xparse_processor_bool \xparse_flush_m_args: - \int_decr:N \l_xparse_total_args_int + \int_decr:N \l_xparse_current_arg_int \tl_put_right:Nn \l_xparse_signature_tl { \xparse_process_arg:n {#1} } - \xparse_prepare_signature_aux:N + \xparse_prepare_signature_bypass:N } % \end{macrocode} % \end{macro} % -% \begin{macro}{\xparse_add_type_d:w} -% To save on repeated code, \texttt{d} is actually turned into -% the same grabber as is used by \texttt{D}, by putting the -% \cs{NoValue} default in the correct place. So there is some -% simple argument re-arrangement to do. Remember that |#1| and |#2| -% should be single tokens. +% \begin{macro}{\xparse_add_type_d:w, \xparse_add_type_D:w} +% To save on repeated code, \texttt{d} is actually turned into the same +% grabber as is used by \texttt{D}, by putting the \cs{NoValue} default in +% the correct place. % \begin{macrocode} \cs_new_protected:Npn \xparse_add_type_d:w #1#2 { \xparse_add_type_D:w #1 #2 { \NoValue } } -% \end{macrocode} -%\end{macro} -% -% \begin{macro}{\xparse_add_type_D:w} -% All of the optional delimited arguments are handled internally by -% the \texttt{D} type. At this stage, the two delimiters are stored -% along with the default value. -% \begin{macrocode} \cs_new_protected:Npn \xparse_add_type_D:w #1#2#3 { \xparse_flush_m_args: @@ -909,8 +1345,8 @@ % \end{macro} % % \begin{macro}{\xparse_add_type_g:w} -% The \texttt{g} type is simply an alias for \texttt{G} with the -% correct default built-in. +% The \texttt{g} type is simply an alias for \texttt{G} with the correct +% default built-in. % \begin{macrocode} \cs_new_protected_nopar:Npn \xparse_add_type_g:w { \xparse_add_type_G:w { \NoValue } } @@ -918,8 +1354,8 @@ % \end{macro} % % \begin{macro}{\xparse_add_type_G:w} -% For the \texttt{G} type, the grabber and the default are added to -% the signature. +% For the \texttt{G} type, the grabber and the default are added to the +% signature. % \begin{macrocode} \cs_new_protected:Npn \xparse_add_type_G:w #1 { @@ -965,9 +1401,25 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}{\xparse_add_type_r:w, \xparse_add_type_R:w} +% The \texttt{r}- and \texttt{R}-type arguments are very similar to the +% \texttt{d}- and \texttt{D}-types. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_add_type_r:w #1#2 + { \xparse_add_type_R:w #1 #2 { \NoValue } } +\cs_new_protected:Npn \xparse_add_type_R:w #1#2#3 + { + \xparse_flush_m_args: + \xparse_add_grabber_mandatory:N R + \tl_put_right:Nn \l_xparse_signature_tl { #1 #2 {#3} } + \xparse_prepare_signature:N + } +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\xparse_add_type_t:w} -% Setting up a \texttt{t} argument means collecting one token for the -% test, and adding it along with the grabber to the signature. +% Setting up a \texttt{t} argument means collecting one token for the test, +% and adding it along with the grabber to the signature. % \begin{macrocode} \cs_new_protected:Npn \xparse_add_type_t:w #1 { @@ -991,7 +1443,7 @@ \xparse_prepare_signature:N } % \end{macrocode} -%\end{macro} +% \end{macro} % % \begin{macro}{\xparse_add_type_v:w} % At this stage, the \texttt{v} argument is identical to \texttt{l}. @@ -1005,435 +1457,318 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}{\xparse_check_and_add:N} -% This function checks if the argument type actually exists and gives -% an error if it doesn't. +% \begin{macro}{\xparse_flush_m_args:} +% As \texttt{m} arguments are simply counted, there is a need to add +% them to the token register in a block. As this function can only +% be called if something other than \texttt{m} turns up, the flag can +% be switched here. The total number of mandatory arguments added to +% the signature is also decreased by the appropriate amount. % \begin{macrocode} -\cs_new_protected_nopar:Npn \xparse_check_and_add:N #1 +\cs_new_protected_nopar:Npn \xparse_flush_m_args: { - \cs_if_free:cTF { xparse_add_type_ #1 :w } + \int_compare:nNnT \l_xparse_m_args_int > \c_zero { - \msg_error:nnx { xparse } { unknown-argument-type } - { \tl_to_str:n {#1} } - \xparse_add_type_m:w + \tl_put_right:Nx \l_xparse_signature_tl + { \exp_not:c { xparse_grab_m_ \int_use:N \l_xparse_m_args_int :w } } + \int_set:Nn \l_xparse_mandatory_args_int + { \l_xparse_mandatory_args_int - \l_xparse_m_args_int } } - { \use:c { xparse_add_type_ #1 :w } } + \int_zero:N \l_xparse_m_args_int } % \end{macrocode} % \end{macro} % -% \begin{macro}{\xparse_count_mandatory:n} -% \begin{macro}{\xparse_count_mandatory:N} -% \begin{macro}[aux]{\xparse_count_mandatory_aux:N} -% To count up mandatory arguments before the main parsing run, the -% same approach is used. First, check if the current token is a -% short-cut for another argument type. If it is, expand it and loop -% again. If not, then look for a `counting' function to check the -% argument type. No error is raised here if one is not found as one -% will be raised by later code. +% \begin{macro}{\xparse_add_grabber_mandatory:N} +% \begin{macro}{\xparse_add_grabber_optional:N} +% To keep the various checks needed in one place, adding the grabber to +% the signature is done here. For mandatory arguments, the only question +% is whether to add a long grabber. For optional arguments, there is +% also a check to see if any mandatory arguments are still to be added. +% This is used to determine whether to skip spaces or not where +% searching for the argument. % \begin{macrocode} -\cs_new_protected:Npn \xparse_count_mandatory:n #1 - { - \int_zero:N \l_xparse_mandatory_args_int - \xparse_count_mandatory:N #1 \q_nil - } -\cs_new_protected:Npn \xparse_count_mandatory:N #1 +\cs_new_protected_nopar:Npn \xparse_add_grabber_mandatory:N #1 { - \quark_if_nil:NF #1 + \tl_put_right:Nx \l_xparse_signature_tl { - \prop_get:NnNTF \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl - { \exp_last_unbraced:NV \xparse_count_mandatory:N \l_xparse_tmp_tl } - { \xparse_count_mandatory_aux:N #1 } + \exp_not:c + { xparse_grab_ #1 \bool_if:NT \l_xparse_long_bool { _long } :w } } + \bool_set_false:N \l_xparse_long_bool + \int_decr:N \l_xparse_mandatory_args_int } -\cs_new_protected:Npn \xparse_count_mandatory_aux:N #1 +\cs_new_protected_nopar:Npn \xparse_add_grabber_optional:N #1 { - \cs_if_free:cTF { xparse_count_type_ #1 :w } - { \xparse_count_type_m:w } - { \use:c { xparse_count_type_ #1 :w } } + \tl_put_right:Nx \l_xparse_signature_tl + { + \exp_not:c + { + xparse_grab_ #1 + \bool_if:NT \l_xparse_long_bool { _long } + \int_compare:nNnF \l_xparse_mandatory_args_int > \c_zero + { _trailing } + :w + } + } + \bool_set_false:N \l_xparse_long_bool } % \end{macrocode} % \end{macro} % \end{macro} -% \end{macro} % -% \begin{macro}{\xparse_count_type_>:w} -% \begin{macro}{\xparse_count_type_+:w} -% \begin{macro}{\xparse_count_type_d:w} -% \begin{macro}{\xparse_count_type_D:w} -% \begin{macro}{\xparse_count_type_g:w} -% \begin{macro}{\xparse_count_type_G:w} -% \begin{macro}{\xparse_count_type_l:w} -% \begin{macro}{\xparse_count_type_m:w} -% \begin{macro}{\xparse_count_type_t:w} -% \begin{macro}{\xparse_count_type_u:w} -% \begin{macro}{\xparse_count_type_v:w} -% For counting the mandatory arguments, a function is provided for -% each argument type that will mop any extra arguments and call the -% loop function. Only the counting functions for mandatory arguments -% actually do anything: the rest are simply there to ensure the loop -% continues correctly. +% \subsection{Setting up expandable types} +% +% The approach here is not dissimilar to that for standard types, although +% types which are not supported in expandable functions give an error. There is +% also a need to define the per-function auxiliaries: this is done here, while +% the general grabbers are dealt with later. +% +% \begin{macro}{\xparse_add_expandable_type_+:w} +% Check that a plus is given only if it occurs for every argument. % \begin{macrocode} -\cs_new_protected:cpn { xparse_count_type_>:w } #1 - { \xparse_count_mandatory:N } -\cs_new_protected_nopar:cpn { xparse_count_type_+:w } - { \xparse_count_mandatory:N } -\cs_new_protected:Npn \xparse_count_type_d:w #1#2 - { \xparse_count_mandatory:N } -\cs_new_protected:Npn \xparse_count_type_D:w #1#2#3 - { \xparse_count_mandatory:N } -\cs_new_protected_nopar:Npn \xparse_count_type_g:w - { \xparse_count_mandatory:N } -\cs_new_protected:Npn \xparse_count_type_G:w #1 - { \xparse_count_mandatory:N } -\cs_new_protected_nopar:Npn \xparse_count_type_l:w - { - \int_incr:N \l_xparse_mandatory_args_int - \xparse_count_mandatory:N - } -\cs_new_protected_nopar:Npn \xparse_count_type_m:w - { - \int_incr:N \l_xparse_mandatory_args_int - \xparse_count_mandatory:N - } -\cs_new_protected:Npn \xparse_count_type_t:w #1 - { \xparse_count_mandatory:N } -\cs_new_protected:Npn \xparse_count_type_u:w #1 +\cs_new_protected_nopar:cpn { xparse_add_expandable_type_+:w } { - \int_incr:N \l_xparse_mandatory_args_int - \xparse_count_mandatory:N + \bool_set_true:N \l_xparse_long_bool + \int_compare:nNnTF \l_xparse_current_arg_int = \c_one + { \bool_set_true:N \l_xparse_all_long_bool } + { + \bool_if:NF \l_xparse_all_long_bool + { \msg_kernel_error:nn { xparse } { inconsistent-long } } + } + \int_decr:N \l_xparse_current_arg_int + \xparse_prepare_signature:N } -\cs_new_protected_nopar:Npn \xparse_count_type_v:w +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\xparse_add_expandable_type_>:w} +% No processors in expandable arguments, so this issues an error. +% \begin{macrocode} +\cs_new_protected:cpn { xparse_add_expandable_type_>:w } #1 { - \int_incr:N \l_xparse_mandatory_args_int - \xparse_count_mandatory:N + \msg_kernel_error:nnx { xparse } { processor-in-expandable } + { \token_to_str:c { \l_xparse_function_tl } } + \int_decr:N \l_xparse_current_arg_int + \xparse_prepare_signature:N } % \end{macrocode} % \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} % -% \begin{macro}{\xparse_declare_cmd:Nnn} -% \begin{macro}[aux]{\xparse_declare_cmd_aux:Nnn} -% \begin{macro}[aux]{\xparse_declare_cmd_aux:cnn} -% \begin{macro}[aux]{\xparse_declare_cmd_all_m:Nn} -% \begin{macro}[aux]{\xparse_declare_cmd_mixed:Nn} -% First, the signature is set up from the argument specification. There -% is then a check: if only \texttt{m} arguments are needed (which -% includes functions with no arguments at all) then the definition is -% simple. On the other hand, if the signature is more complex then an -% internal function actually contains the code with the user function -% as a simple wrapper. -% \begin{macrocode} -\cs_new_protected:Npn \xparse_declare_cmd:Nnn #1#2 +% \begin{macro}{\xparse_add_expandable_type_d:w} +% \begin{macro}{\xparse_add_expandable_type_D:w} +% \begin{macro}{\xparse_add_expandable_type_D_aux:NNn} +% \begin{macro}{\xparse_add_expandable_type_D_aux:Nn} +% The set up for \texttt{d}- and \texttt{D}-type arguments is the same, +% and involves constructing a rather complex auxiliary which is used +% repeatedly when grabbing. There is an auxiliary here so that the +% \texttt{R}-type can share code readily. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_add_expandable_type_d:w #1#2 + { \xparse_add_expandable_type_D:w #1 #2 { \NoValue } } +\cs_new_protected:Npn \xparse_add_expandable_type_D:w #1#2 { - \cs_if_exist:NTF #1 + \token_if_eq_meaning:NNTF #1 #2 { - \msg_warning:nnxx { xparse } { redefine-command } - { \token_to_str:N #1 } { \tl_to_str:n {#2} } + \xparse_add_expandable_grabber_optional:n { D_alt } + \xparse_add_expandable_type_D_aux:Nn #1 } { - \msg_info:nnxx { xparse } { define-command } - { \token_to_str:N #1 } { \tl_to_str:n {#2} } + \xparse_add_expandable_grabber_optional:n { D } + \xparse_add_expandable_type_D_aux:NNn #1#2 } - \xparse_declare_cmd_aux:Nnn #1 {#2} } -\cs_new_protected:Npn \xparse_declare_cmd_aux:Nnn #1#2#3 +\cs_new_protected:Npn \xparse_add_expandable_type_D_aux:NNn #1#2#3 { - \tl_clear_new:c { l_xparse_ \token_to_str:N #1 _arg_spec_tl } - \tl_set:cn { l_xparse_ \token_to_str:N #1 _arg_spec_tl } {#2} - \xparse_count_mandatory:n {#2} - \xparse_prepare_signature:n {#2} - \bool_if:NTF \l_xparse_m_only_bool - { \xparse_declare_cmd_all_m:Nn #1 {#3} } - { \xparse_declare_cmd_mixed:Nn #1 {#3} } - } -\cs_generate_variant:Nn \xparse_declare_cmd_aux:Nnn { cnn } -\cs_new_protected:Npn \xparse_declare_cmd_all_m:Nn #1#2 - { - \cs_generate_from_arg_count:NNnn - #1 \cs_set_protected_nopar:Npn \l_xparse_total_args_int {#2} + \bool_if:NTF \l_xparse_long_bool + { \cs_set:cpx } + { \cs_set_nopar:cpx } + { \l_xparse_expandable_aux_name_tl } ##1 ##2 #1 ##3 \q_xparse ##4 #2 + { ##1 {##2} {##3} {##4} } + \tl_put_right:Nx \l_xparse_signature_tl + { + \exp_not:c { \l_xparse_expandable_aux_name_tl } + \exp_not:n { #1 #2 {#3} } + } + \bool_set_false:N \l_xparse_long_bool + \xparse_prepare_signature:N } -\cs_new_protected:Npn \xparse_declare_cmd_mixed:Nn #1#2 +% \end{macrocode} +% This route is needed if the two delimiting tokens are identical: in +% contrast to the non-expandable route, the grabber here has to act +% differently for this case. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_add_expandable_type_D_aux:Nn #1#2 { - \group_begin: - \tex_escapechar:D 92 \scan_stop: - \tl_set:Nx \l_xparse_function_tl { \token_to_str:N #1 } - \exp_args:NNNo \group_end: - \tl_set:Nn \l_xparse_function_tl { \l_xparse_function_tl } - \cs_set_protected_nopar:Npx #1 + \bool_if:NTF \l_xparse_long_bool + { \cs_set:cpx } + { \cs_set_nopar:cpx } + { \l_xparse_expandable_aux_name_tl } ##1 #1 ##2 #1 + { ##1 {##2} } + \tl_put_right:Nx \l_xparse_signature_tl { - \exp_not:n - { - \int_zero:N \l_xparse_processor_int - \tl_set:Nn \l_xparse_args_tl - } - { \exp_not:c { \l_xparse_function_tl } } - \exp_not:o \l_xparse_signature_tl - \exp_not:N \l_xparse_args_tl + \exp_not:c { \l_xparse_expandable_aux_name_tl } + \exp_not:n { #1 {#2} } } - \cs_generate_from_arg_count:cNnn - { \token_to_str:N #1 } \cs_set:Npn \l_xparse_total_args_int {#2} + \bool_set_false:N \l_xparse_long_bool + \xparse_prepare_signature:N } % \end{macrocode} % \end{macro} % \end{macro} -%\end{macro} -%\end{macro} -%\end{macro} +% \end{macro} +% \end{macro} % -% \begin{macro}{\xparse_declare_cmd_implementation:nNn} -% Creating a stand-alone implementation using the \enquote{two-part} -% mechanism is quite easy as this is just a wrapper for -% \cs{cs_generate_from_arg_count:cNnn}. +% \begin{macro}{\xparse_add_expandable_type_g:w} +% \begin{macro}{\xparse_add_expandable_type_G:w} +% These are not allowed at all, so there is a complaint and a fall-back. % \begin{macrocode} -\cs_new_protected:Npn \xparse_declare_cmd_implementation:nNn #1#2#3 +\cs_new_protected_nopar:Npn \xparse_add_expandable_type_g:w { - \cs_generate_from_arg_count:cNnn { implementation_ #1 :w } - \cs_set:Npn {#2} {#3} + \msg_kernel_error:nnx { xparse } { invalid-expandable-argument-type } { g } + \xparse_add_expandable_type_m:w + } +\cs_new_protected_nopar:Npn \xparse_add_expandable_type_G:w #1 + { + \msg_kernel_error:nnx { xparse } { invalid-expandable-argument-type } { G } + \xparse_add_expandable_type_m:w } % \end{macrocode} % \end{macro} +% \end{macro} % -% \begin{macro}{\xparse_declare_cmd_interface:Nnn} -% \begin{macro}[aux]{\xparse_declare_cmd_interface_all_m:Nn} -% \begin{macro}[aux]{\xparse_declare_cmd_interface_mixed:Nn} -% As with the basic function \cs{xparse_declare_cmd:Nnn}, there are -% three things to do here. First, generate a signature from the -% argument specification. Then use that to create a function which -% will call the implementation part. Finally, a holder implementation -% is created. As before, there is a short-cut for functions which only -% have \texttt{m} type arguments. +% \begin{macro}{\xparse_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). % \begin{macrocode} -\cs_new_protected:Npn \xparse_declare_cmd_interface:Nnn #1#2#3 +\cs_new_protected_nopar:Npn \xparse_add_expandable_type_l:w { - \xparse_prepare_signature:n {#3} - \bool_if:NTF \l_xparse_m_only_bool - { \xparse_declare_cmd_interface_all_m:Nn #1 {#2} } - { \xparse_declare_cmd_interface_mixed:Nn #1 {#2} } - \cs_generate_from_arg_count:cNnn { implementation_ #2 :w } - \cs_set:Npn \l_xparse_total_args_int { '#2' } - } -\cs_new_protected:Npn \xparse_declare_cmd_interface_all_m:Nn #1#2 - { - \cs_generate_from_arg_count:NNnn - #1 \cs_set_protected_nopar:Npn \l_xparse_total_args_int - { \use:c { implementation_ #2 :w } } - } -\cs_new_protected:Npn \xparse_declare_cmd_interface_mixed:Nn #1#2 - { - \cs_set_protected_nopar:Npx #1 - { - \exp_not:n - { - \int_zero:N \l_xparse_processor_int - \tl_set:Nn \l_xparse_args_tl - } - { \exp_not:c { \token_to_str:N #1 } } - \exp_not:o \l_xparse_signature_tl - \exp_not:N \l_xparse_args_tl - } - \cs_generate_from_arg_count:cNnn - { \token_to_str:N #1 } \cs_set:Npn \l_xparse_total_args_int - { \use:c { implementation_ #2 :w } } + \msg_kernel_error:nnx { xparse } { invalid-expandable-argument-type } { l } + \xparse_add_expandable_type_m:w } % \end{macrocode} % \end{macro} -% \end{macro} -% \end{macro} % -% \begin{macro}{\xparse_declare_env:nnnn} -% The idea here is to make sure that the end of the environment has the -% same arguments available as the beginning. +% \begin{macro}{\xparse_add_expandable_type_m:w} +% Unlike the standard case, when working expandably each argument is always +% grabbed separately unless the function takes only \texttt{m}-type +% arguments. To deal with the latter case, the value of +% \cs{l_xparse_m_args_int} needs to be increased appropriately. % \begin{macrocode} -\cs_new_protected:Npn \xparse_declare_env:nnnn #1#2#3#4 +\cs_new_protected_nopar:Npn \xparse_add_expandable_type_m:w { - \bool_set_true:N \l_xparse_environment_bool - \cs_if_exist:cTF {#1} - { - \msg_warning:nnxx { xparse } { redefine-environment } - { \tl_to_str:n {#1} } { \tl_to_str:n {#2} } - } - { - \msg_info:nnxx { xparse } { define-environment } - { \tl_to_str:n {#1} } { \tl_to_str:n {#2} } - } - \xparse_declare_cmd_aux:cnn { environment_begin_ #1 :w } {#2} - { - \group_begin: - \cs_set_protected_nopar:cpx { environment_end_ #1 :w } - { - \exp_not:c { environment_end_ #1 _aux:N } - \exp_not:o \l_xparse_args_tl - \exp_not:n - { - \if@endpe - \exp_after:wN \group_end: - \cs:w @endpetrue \exp_after:wN \cs_end: - \else - \exp_after:wN \group_end: - \fi - } - } - #3 - } - \cs_set_protected_nopar:cpx { environment_end_ #1 : } - { \exp_not:c { environment_end_ #1 :w } } - \bool_set_false:N \l_xparse_environment_bool - \cs_set_nopar:cpx { environment_end_ #1 _aux:N } ##1 - { \exp_not:c { environment_end_ #1 _aux :w } } - \cs_generate_from_arg_count:cNnn - { environment_end_ #1 _aux :w } \cs_set:Npn - \l_xparse_total_args_int {#4} - \cs_set_eq:cc {#1} { environment_begin_ #1 :w } - \cs_set_eq:cc { end #1 } { environment_end_ #1 : } + \int_incr:N \l_xparse_m_args_int + \xparse_add_expandable_grabber_mandatory:n { m } + \bool_set_false:N \l_xparse_long_bool + \xparse_prepare_signature:N } % \end{macrocode} % \end{macro} % -% \begin{macro}{\xparse_flush_m_args:} -% As \texttt{m} arguments are simply counted, there is a need to add -% them to the token register in a block. As this function can only -% be called if something other than \texttt{m} turns up, the flag can -% be switched here. The total number of mandatory arguments added to -% the signature is also decreased by the appropriate amount. +% \begin{macro}{\xparse_add_expandable_type_r:w} +% \begin{macro}{\xparse_add_expandable_type_R:w} +% The \texttt{r}- and \texttt{R}-types are very similar to \texttt{D}-type +% arguments, and so the same internals are used. % \begin{macrocode} -\cs_new_protected_nopar:Npn \xparse_flush_m_args: +\cs_new_protected:Npn \xparse_add_expandable_type_r:w #1#2 + { \xparse_add_expandable_type_R:w #1 #2 { \NoValue } } +\cs_new_protected:Npn \xparse_add_expandable_type_R:w #1#2 { - \cs_if_exist:cT { xparse_grab_m_ \int_use:N \l_xparse_m_args_int :w } + \token_if_eq_meaning:NNTF #1 #2 { - \tl_put_right:Nx \l_xparse_signature_tl - { \exp_not:c { xparse_grab_m_ \int_use:N \l_xparse_m_args_int :w } } - \int_set:Nn \l_xparse_mandatory_args_int - { \l_xparse_mandatory_args_int - \l_xparse_m_args_int } + \xparse_add_expandable_grabber_optional:n { R_alt } + \xparse_add_expandable_type_D_aux:Nn #1 + } + { + \xparse_add_expandable_grabber_optional:n { R } + \xparse_add_expandable_type_D_aux:NNn #1#2 } - \int_zero:N \l_xparse_m_args_int - \bool_set_false:N \l_xparse_m_only_bool } % \end{macrocode} % \end{macro} -% -% \begin{macro}[TF]{\xparse_if_no_value:n} -% Tests for \cs{NoValue}. -% \begin{macrocode} -\prg_new_conditional:Npnn \xparse_if_no_value:n #1 { T , F , TF } - { \str_if_eq:nnTF {#1} { \NoValue } \prg_return_true: \prg_return_false: } -% \end{macrocode} % \end{macro} % -% \begin{macro}{\xparse_prepare_signature:n} -% Creating the signature is a case of working through the input and -% turning into the output in \cs{l_xparse_signature_tl}. A track is -% also kept of the total number of arguments. This function sets -% everything up then hands off to the parser. +% \begin{macro}{\xparse_add_expandable_type_t:w} % \begin{macrocode} -\cs_new_protected:Npn \xparse_prepare_signature:n #1 +\cs_new_protected_nopar:Npn \xparse_add_expandable_type_t:w #1 { + \xparse_add_expandable_grabber_optional:n { t } + \bool_if:NTF \l_xparse_long_bool + { \cs_set:cpn } + { \cs_set_nopar:cpn } + { \l_xparse_expandable_aux_name_tl } ##1 #1 {##1} + \tl_put_right:Nx \l_xparse_signature_tl + { + \exp_not:c { \l_xparse_expandable_aux_name_tl } + \exp_not:N #1 + } \bool_set_false:N \l_xparse_long_bool - \int_zero:N \l_xparse_m_args_int - \bool_if:NTF \l_xparse_environment_bool - { \bool_set_false:N \l_xparse_m_only_bool } - { \bool_set_true:N \l_xparse_m_only_bool } - \bool_set_false:N \l_xparse_processor_bool - \tl_clear:N \l_xparse_signature_tl - \int_zero:N \l_xparse_total_args_int - \xparse_prepare_signature:N #1 \q_nil + \xparse_prepare_signature:N } % \end{macrocode} % \end{macro} % -% \begin{macro}{\xparse_prepare_signature:N} -% \begin{macro}[aux]{\xparse_prepare_signature_aux:N} -% The main signature-preparation loop is in two parts, to keep the code -% a little clearer. Most of the checks here is pretty clear, with a key -% point to watch what is next on the stack so that the loop continues -% correctly. +% \begin{macro}{\xparse_add_expandable_type_u:w} +% Invalid in an expandable context as any preceding optional argument may +% wrap part of the delimiter up in braces. % \begin{macrocode} -\cs_new_protected:Npn \xparse_prepare_signature:N #1 - { - \bool_set_false:N \l_xparse_processor_bool - \xparse_prepare_signature_aux:N #1 - } -\cs_new_protected:Npn \xparse_prepare_signature_aux:N #1 +\cs_new_protected_nopar:Npn \xparse_add_expandable_type_u:w #1 { - \quark_if_nil:NTF #1 - { \bool_if:NF \l_xparse_m_only_bool { \xparse_flush_m_args: } } - { - \prop_get:NnNTF \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl - { \exp_after:wN \xparse_prepare_signature:N \l_xparse_tmp_tl } - { - \int_incr:N \l_xparse_total_args_int - \xparse_check_and_add:N #1 - } - } + \msg_kernel_error:nnx { xparse } { invalid-expandable-argument-type } { u } + \xparse_add_expandable_type_m:w } % \end{macrocode} % \end{macro} -% \end{macro} % -% \begin{macro}{\xparse_process_arg:n} -% Processors are saved for use later during the grabbing process. +% \begin{macro}{\xparse_add_expandable_type_v:w} +% Another forbidden type. % \begin{macrocode} -\cs_new_protected:Npn \xparse_process_arg:n #1 +\cs_new_protected_nopar:Npn \xparse_add_expandable_type_v:w { - \int_incr:N \l_xparse_processor_int - \cs_set:cpn { xparse_processor_ \int_use:N \l_xparse_processor_int :n } ##1 - { #1 {##1} } + \msg_kernel_error:nnx { xparse } { invalid-expandable-argument-type } { v } + \xparse_add_expandable_type_m:w } % \end{macrocode} % \end{macro} % -% \subsection{Grabbing arguments} -% -% \begin{macro}{\xparse_add_arg:n, \xparse_add_arg:V} -% \begin{macro}[aux]{\xparse_add_arg_aux:n, \xparse_add_arg_aux:V} -% The argument-storing system provides a single point for interfacing -% with processors. They are done in a loop, counting downward. In this -% way, the processor which was found last is executed first. The result -% is that processors apply from right to left, as intended. Notice that -% a set of braces are added back around the result of processing so that -% the internal function will correctly pick up one argument for each -% input argument. +% \begin{macro} +% { +% \xparse_add_expandable_grabber_mandatory:n, +% \xparse_add_expandable_grabber_optional:n +% } +% \begin{macro}[aux]{\xparse_add_expandable_long_check:} +% Adding a grabber to the signature is very simple here, with only a test to +% ensure that optional arguments still have mandatory ones to follow. This +% is also a good place to check on the consistency of the long status of +% arguments. % \begin{macrocode} -\cs_new_protected:Npn \xparse_add_arg:n #1 +\cs_new_protected_nopar:Npn \xparse_add_expandable_grabber_mandatory:n #1 { - \int_compare:nNnTF \l_xparse_processor_int = \c_zero - { \tl_put_right:Nn \l_xparse_args_tl { {#1} } } - { - \xparse_if_no_value:nTF {#1} - { - \int_zero:N \l_xparse_processor_int - \tl_put_right:Nn \l_xparse_args_tl { {#1} } - } - { \xparse_add_arg_aux:n {#1} } - } + \xparse_add_expandable_long_check: + \tl_put_right:Nx \l_xparse_signature_tl + { \exp_not:c { xparse_expandable_grab_ #1 :w } } + \bool_set_false:N \l_xparse_long_bool + \int_decr:N \l_xparse_mandatory_args_int } -\cs_generate_variant:Nn \xparse_add_arg:n { V } -\cs_new_protected:Npn \xparse_add_arg_aux:n #1 +\cs_new_protected_nopar:Npn \xparse_add_expandable_grabber_optional:n #1 { - \tl_set_eq:NN \ProcessedArgument \l_xparse_arg_tl - \use:c { xparse_processor_ \int_use:N \l_xparse_processor_int :n } {#1} - \int_decr:N \l_xparse_processor_int - \int_compare:nNnTF \l_xparse_processor_int = \c_zero - { - \tl_put_right:Nx \l_xparse_args_tl - { { \exp_not:V \ProcessedArgument } } - } - { \xparse_add_arg_aux:V \ProcessedArgument } -} -\cs_generate_variant:Nn \xparse_add_arg_aux:n { V } + \xparse_add_expandable_long_check: + \int_compare:nNnF \l_xparse_mandatory_args_int > \c_zero + { \msg_kernel_error:nn { xparse } { expandable-ending-optional } } + \tl_put_right:Nx \l_xparse_signature_tl + { \exp_not:c { xparse_expandable_grab_ #1 :w } } + \bool_set_false:N \l_xparse_long_bool + } +\cs_new_protected_nopar:Npn \xparse_add_expandable_long_check: + { + \bool_if:nT { \l_xparse_all_long_bool && ! ( \l_xparse_long_bool ) } + { \msg_kernel_error:nn { xparse } { inconsistent-long } } + } % \end{macrocode} % \end{macro} % \end{macro} % +% \subsection{Grabbing arguments} +% % All of the grabbers follow the same basic pattern. The initial % function sets up the appropriate information to define % \cs{parse_grab_arg:w} to grab the argument. This means determining @@ -1483,55 +1818,81 @@ { \xparse_grab_D_aux:NNnnNn #1 #2 {#3} {#4} \cs_set_protected:Npn { } } % \end{macrocode} % \begin{macro}[aux]{\xparse_grab_D_aux:NNnnNn} +% \begin{macro}[aux]{\xparse_grab_D_aux:NNnN} % This is a bit complicated. The idea is that, in order to check for % nested optional argument tokens (\texttt{[[...]]} and so on) the % argument needs to be grabbed without removing any braces at all. If % this is not done, then cases like |[{[}]| fail. So after testing for -% an optional argument, it is collected piece-wise. First, the opening -% token is removed, then a check is made for a group. If it looks like -% the entire argument is a group, then an extra set of braces are -% added back in. The closing token is then used to collect everything -% else. There is then a test to see if there is nesting, by looking -% for a \enquote{spare} open-argument token. If that is found, things hand -% off to a loop to deal with that. +% an optional argument, it is collected piece-wise. Inserting a quark +% prevents loss of braces, and there is then a test to see if there are +% nested delimiters to handle. % \begin{macrocode} \cs_new_protected:Npn \xparse_grab_D_aux:NNnnNn #1#2#3#4#5#6 { - #5 \xparse_grab_arg:w #1 - { - \peek_meaning:NTF \c_group_begin_token - { \xparse_grab_arg_aux_i:w } - { \xparse_grab_arg_aux_ii:w } - } - #5 \xparse_grab_arg_aux_i:w ##1 - { - \peek_charcode:NTF #2 - { \xparse_grab_arg_aux_ii:w { {##1} } } - { \xparse_grab_arg_aux_ii:w {##1} } - } - #5 \xparse_grab_arg_aux_ii:w ##1 #2 - { - \tl_if_in:nnTF {##1} {#1} - { \xparse_grab_D_nested:NNnnN #1 #2 {##1} {#4} #5 } - { - \xparse_add_arg:n {##1} - #4 \l_xparse_args_tl - } - } - \use:c { peek_charcode #6 :NTF } #1 + \xparse_grab_D_aux:NNnN #1#2 {#4} #5 + \use:c { peek_meaning_remove #6 :NTF } #1 { \xparse_grab_arg:w } { \xparse_add_arg:n {#3} #4 \l_xparse_args_tl } } +\cs_new_protected:Npn \xparse_grab_D_aux:NNnN #1#2#3#4 + { + \cs_set_protected_nopar:Npn \xparse_grab_arg:w + { + \exp_after:wN #4 \l_xparse_fn_tl ####1 #2 + { + \tl_if_in:nnTF {####1} {#1} + { \xparse_grab_D_nested:NNnnN #1 #2 {####1} {#3} #4 } + { + \xparse_add_arg:o { \use_none:n ####1 } + #3 \l_xparse_args_tl + } + } +% \end{macrocode} +% This section needs a little explanation. In order to avoid loosing any +% braces, a token needs to be inserted before the argument to be grabbed. +% If the argument runs away because the closing token is missing then this +% inserted token shows up in the terminal. Ideally, |#1| would therefore be +% used directly, but that is no good as it will mess up the rest of the +% grabber. Instead, a copy of |#1| with an altered category code is used, +% as this will look right in the terminal but will not mess up the grabber. +% The only issue then is that the category code of |#1| is unknown. So there +% is a quick test to ensure that the inserted token can never be matched by +% the grabber. (This assumes that |#1| and |#2| are not the same character +% with different category codes, but that really should not happen in any +% sensible document-level syntax.) +% \begin{macrocode} + \group_begin: + \token_if_eq_catcode:NNTF #1 ^ + { + \char_set_lccode:nn { `A } { `#1 } + \tl_to_lowercase:n + { + \group_end: + \l_xparse_fn_tl A + } + } + { + \char_set_lccode:nn { `^ } { `#1 } + \tl_to_lowercase:n + { + \group_end: + \l_xparse_fn_tl ^ + } + } + } + } % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} % \end{macro} +% \end{macro} % \begin{macro}[aux]{\xparse_grab_D_nested:NNnnN} +% \begin{macro}[aux]{\xparse_grab_D_nested:w} % \begin{macro}{\l_xparse_nesting_a_tl} % \begin{macro}{\l_xparse_nesting_b_tl} % \begin{macro}{\q_xparse} @@ -1545,7 +1906,12 @@ % tokens, then there is a second check to see if there are any % opening tokens in the second part of the argument (for things % like |[][]|). Once everything has been found, the entire collected -% material is added to the output as a single argument. +% material is added to the output as a single argument. The only tricky part +% here is ensuring that any grabbing function that might run away is named +% after the function currently being parsed and not after \pkg{xparse}. That +% leads to some rather complex nesting! There is also a need to prevent the +% loss of any braces, hence the insertion and removal of quarks along the +% way. % \begin{macrocode} \tl_new:N \l_xparse_nesting_a_tl \tl_new:N \l_xparse_nesting_b_tl @@ -1554,19 +1920,24 @@ { \tl_clear:N \l_xparse_nesting_a_tl \tl_clear:N \l_xparse_nesting_b_tl - #5 \xparse_grab_arg:w ##1 #1 ##2 \q_xparse ##3 #2 + \exp_after:wN #5 \l_xparse_fn_tl ##1 #1 ##2 \q_xparse ##3 #2 { - \tl_put_right:Nn \l_xparse_nesting_a_tl { ##1 #1 } - \tl_put_right:Nn \l_xparse_nesting_b_tl { #2 ##3 } + \tl_put_right:No \l_xparse_nesting_a_tl { \use_none:n ##1 #1 } + \tl_put_right:No \l_xparse_nesting_b_tl { \use_i:nn #2 ##3 } \tl_if_in:nnTF {##2} {#1} - { \xparse_grab_arg:w ##2 \q_xparse } { - \tl_put_right:Nn \l_xparse_nesting_a_tl {##2} + \l_xparse_fn_tl + \q_nil ##2 \q_xparse \ERROR + } + { + \tl_put_right:Nx \l_xparse_nesting_a_tl + { \xparse_grab_D_nested:w \q_nil ##2 \q_stop } \tl_if_in:NnTF \l_xparse_nesting_b_tl {#1} { \tl_set_eq:NN \l_xparse_tmp_tl \l_xparse_nesting_b_tl \tl_clear:N \l_xparse_nesting_b_tl - \exp_after:wN \xparse_grab_arg:w \l_xparse_tmp_tl \q_xparse + \exp_after:wN \l_xparse_fn_tl \exp_after:wN + \q_nil \l_xparse_tmp_tl \q_nil \q_xparse \ERROR } { \tl_put_right:No \l_xparse_nesting_a_tl @@ -1576,13 +1947,16 @@ } } } - \xparse_grab_arg:w #3 \q_xparse + \l_xparse_fn_tl #3 \q_nil \q_xparse \ERROR } +\cs_new:Npn \xparse_grab_D_nested:w #1 \q_nil \q_stop + { \exp_not:o { \use_none:n #1 } } % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} % \end{macro} +% \end{macro} % % \begin{macro}{\xparse_grab_G:w} % \begin{macro}{\xparse_grab_G_long:w} @@ -1607,13 +1981,13 @@ { \xparse_grab_G_aux:nnNn {#1} {#2} \cs_set_protected:Npn { } } \cs_new_protected:Npn \xparse_grab_G_aux:nnNn #1#2#3#4 { - #3 \xparse_grab_arg:w ##1 + \exp_after:wN #3 \l_xparse_fn_tl ##1 { \xparse_add_arg:n {##1} #2 \l_xparse_args_tl } \use:c { peek_meaning #4 :NTF } \c_group_begin_token - { \xparse_grab_arg:w } + { \l_xparse_fn_tl } { \xparse_add_arg:n {#1} #2 \l_xparse_args_tl @@ -1629,7 +2003,7 @@ % \begin{macro}{\xparse_grab_l:w} % \begin{macro}{\xparse_grab_l_long:w} % \begin{macro}[aux]{\xparse_grab_l_aux:nN} -% Argument grabbers for mandatory \TeX\ arguments are pretty simple. +% Argument grabbers for mandatory \TeX{} arguments are pretty simple. % \begin{macrocode} \cs_new_protected:Npn \xparse_grab_l:w #1 \l_xparse_args_tl { \xparse_grab_l_aux:nN {#1} \cs_set_protected_nopar:Npn } @@ -1637,12 +2011,12 @@ { \xparse_grab_l_aux:nN {#1} \cs_set_protected:Npn } \cs_new_protected:Npn \xparse_grab_l_aux:nN #1#2 { - #2 \xparse_grab_arg:w ##1## + \exp_after:wN #2 \l_xparse_fn_tl ##1## { \xparse_add_arg:n {##1} #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } % \end{macrocode} % \end{macro} @@ -1655,21 +2029,21 @@ % \begin{macrocode} \cs_new_protected:Npn \xparse_grab_m:w #1 \l_xparse_args_tl { - \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1 + \exp_after:wN \cs_set_protected_nopar:Npn \l_xparse_fn_tl ##1 { \xparse_add_arg:n {##1} #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } \cs_new_protected:Npn \xparse_grab_m_long:w #1 \l_xparse_args_tl { - \cs_set_protected:Npn \xparse_grab_arg:w ##1 + \exp_after:wN \cs_set_protected:Npn \l_xparse_fn_tl ##1 { \xparse_add_arg:n {##1} #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } % \end{macrocode} % \end{macro} @@ -1690,78 +2064,85 @@ % \begin{macrocode} \cs_new_protected:cpn { xparse_grab_m_1:w } #1 \l_xparse_args_tl { - \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1 + \exp_after:wN \cs_set_protected_nopar:Npn \l_xparse_fn_tl ##1 { \tl_put_right:Nn \l_xparse_args_tl { {##1} } #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } \cs_new_protected:cpn { xparse_grab_m_2:w } #1 \l_xparse_args_tl { - \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2 + \exp_after:wN \cs_set_protected_nopar:Npn \l_xparse_fn_tl + ##1##2 { \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} } #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } \cs_new_protected:cpn { xparse_grab_m_3:w } #1 \l_xparse_args_tl { - \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3 + \exp_after:wN \cs_set_protected_nopar:Npn \l_xparse_fn_tl + ##1##2##3 { \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} } #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } \cs_new_protected:cpn { xparse_grab_m_4:w } #1 \l_xparse_args_tl { - \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4 + \exp_after:wN \cs_set_protected_nopar:Npn \l_xparse_fn_tl + ##1##2##3##4 { \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} {##4} } #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } \cs_new_protected:cpn { xparse_grab_m_5:w } #1 \l_xparse_args_tl { - \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5 + \exp_after:wN \cs_set_protected_nopar:Npn \l_xparse_fn_tl + ##1##2##3##4##5 { \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} {##4} {##5} } #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } \cs_new_protected:cpn { xparse_grab_m_6:w } #1 \l_xparse_args_tl { - \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5##6 + \exp_after:wN \cs_set_protected_nopar:Npn \l_xparse_fn_tl + ##1##2##3##4##5##6 { \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} {##4} {##5} {##6} } #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } \cs_new_protected:cpn { xparse_grab_m_7:w } #1 \l_xparse_args_tl { - \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5##6##7 + \exp_after:wN \cs_set_protected_nopar:Npn \l_xparse_fn_tl + ##1##2##3##4##5##6##7 { \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} {##4} {##5} {##6} {##7} } #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } \cs_new_protected:cpn { xparse_grab_m_8:w } #1 \l_xparse_args_tl { - \cs_set_protected_nopar:Npn \xparse_grab_arg:w ##1##2##3##4##5##6##7##8 + \exp_after:wN \cs_set_protected_nopar:Npn \l_xparse_fn_tl + ##1##2##3##4##5##6##7##8 { \tl_put_right:Nn \l_xparse_args_tl { {##1} {##2} {##3} {##4} {##5} {##6} {##7} {##8} } #1 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } % \end{macrocode} % \end{macro} @@ -1773,6 +2154,32 @@ % \end{macro} % \end{macro} % +% \begin{macro}{\xparse_grab_R:w, \xparse_grab_R_long:w} +% \begin{macro}[aux]{\xparse_grab_R_aux:NNnnN} +% The grabber for \texttt{R}-type arguments is basically the same as +% that for \texttt{D}-type ones, but always skips spaces (as it is mandatory) +% and has a hard-coded error message. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_grab_R:w #1#2#3#4 \l_xparse_args_tl + { \xparse_grab_R_aux:NNnnN #1 #2 {#3} {#4} \cs_set_protected_nopar:Npn } +\cs_new_protected:Npn \xparse_grab_R_long:w #1#2#3#4 \l_xparse_args_tl + { \xparse_grab_R_aux:NNnnN #1 #2 {#3} {#4} \cs_set_protected:Npn } +\cs_new_protected:Npn \xparse_grab_R_aux:NNnnN #1#2#3#4#5 + { + \xparse_grab_D_aux:NNnN #1 #2 {#4} #5 + \peek_meaning_remove_ignore_spaces:NTF #1 + { \xparse_grab_arg:w } + { + \msg_kernel_error:nnxx { xparse } { missing-required } + { \token_to_str:N #1 } { \tl_to_str:n {#3} } + \xparse_add_arg:n {#3} + #4 \l_xparse_args_tl + } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% % \begin{macro}{\xparse_grab_t:w} % \begin{macro}{\xparse_grab_t_long:w} % \begin{macro}{\xparse_grab_t_trailing:w} @@ -1794,9 +2201,9 @@ { \xparse_grab_t_aux:NnNn #1 {#2} \cs_set_protected:Npn { } } \cs_new_protected:Npn \xparse_grab_t_aux:NnNn #1#2#3#4 { - #3 \xparse_grab_arg:w + \exp_after:wN #3 \l_xparse_fn_tl { - \use:c { peek_charcode_remove #4 :NTF } #1 + \use:c { peek_meaning_remove #4 :NTF } #1 { \xparse_add_arg:n { \BooleanTrue } #2 \l_xparse_args_tl @@ -1806,7 +2213,7 @@ #2 \l_xparse_args_tl } } - \xparse_grab_arg:w + \l_xparse_fn_tl } % \end{macrocode} % \end{macro} @@ -1827,12 +2234,12 @@ { \xparse_grab_u_aux:nnN {#1} {#2} \cs_set_protected:Npn } \cs_new_protected:Npn \xparse_grab_u_aux:nnN #1#2#3 { - #3 \xparse_grab_arg:w ##1 #1 + \exp_after:wN #3 \l_xparse_fn_tl ##1 #1 { \xparse_add_arg:n {##1} #2 \l_xparse_args_tl } - \xparse_grab_arg:w + \l_xparse_fn_tl } % \end{macrocode} % \end{macro} @@ -1975,11 +2382,8 @@ % \end{macro} % % \begin{macro}{\xparse_grab_v_bgroup:} -% \begin{macro} -% { -% \xparse_grab_v_bgroup_loop:, -% \xparse_grab_v_bgroup_loop_ii:N -% } +% \begin{macro}{\xparse_grab_v_bgroup_loop:} +% \begin{macro}{\xparse_grab_v_bgroup_loop_ii:N} % \begin{variable}{\l_xparse_v_nesting_int} % If the opening delimiter is a left brace, we keep track of % how many left and right braces were encountered so far in @@ -2034,9 +2438,11 @@ % \end{variable} % \end{macro} % \end{macro} +% \end{macro} % % \begin{macro}{\xparse_grab_v_aux_catcodes:} -% \begin{macro}{\xparse_grab_v_aux_abort:, \xparse_grab_v_aux_abort_ii:w} +% \begin{macro}{\xparse_grab_v_aux_abort:} +% \begin{macro}{\xparse_grab_v_aux_abort_ii:w} % In a standalone format, the list of special characters is kept % as a sequence, \cs{c_xparse_special_chars_seq}, and we use % \tn{dospecials} in package mode. @@ -2074,14 +2480,14 @@ \tl_to_lowercase:n { \group_end: \peek_meaning_remove:NTF ## } { - \msg_error:nnxx { xparse } { verbatim-newline } - { \cs_to_str:N #1 } + \msg_kernel_error:nnxx { xparse } { verbatim-newline } + { \token_to_str:N #1 } { \tl_to_str:N \l_xparse_v_arg_tl } \l_xparse_v_rest_of_signature_tl \l_xparse_args_tl } { - \msg_error:nnxx { xparse } { verbatim-already-tokenized } - { \cs_to_str:N #1 } + \msg_kernel_error:nnxx { xparse } { verbatim-already-tokenized } + { \token_to_str:N #1 } { \tl_to_str:N \l_xparse_v_arg_tl } \l_xparse_v_rest_of_signature_tl \l_xparse_args_tl } @@ -2089,6 +2495,7 @@ % \end{macrocode} % \end{macro} % \end{macro} +% \end{macro} % % \begin{macro}{\xparse_grab_v_token_if_char:NTF} % This function assumes that the escape character is printable. @@ -2103,8 +2510,305 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}{\xparse_add_arg:n, \xparse_add_arg:V, \xparse_add_arg:o} +% \begin{macro}[aux]{\xparse_add_arg_aux:n, \xparse_add_arg_aux:V} +% The argument-storing system provides a single point for interfacing +% with processors. They are done in a loop, counting downward. In this +% way, the processor which was found last is executed first. The result +% is that processors apply from right to left, as intended. Notice that +% a set of braces are added back around the result of processing so that +% the internal function will correctly pick up one argument for each +% input argument. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_add_arg:n #1 + { + \int_compare:nNnTF \l_xparse_processor_int = \c_zero + { \tl_put_right:Nn \l_xparse_args_tl { {#1} } } + { + \tl_clear:N \ProcessedArgument + \xparse_if_no_value:nTF {#1} + { + \int_zero:N \l_xparse_processor_int + \tl_put_right:Nn \l_xparse_args_tl { {#1} } + } + { \xparse_add_arg_aux:n {#1} } + } + } +\cs_generate_variant:Nn \xparse_add_arg:n { V , o } +\cs_new_protected:Npn \xparse_add_arg_aux:n #1 + { + \use:c { xparse_processor_ \int_use:N \l_xparse_processor_int :n } {#1} + \int_decr:N \l_xparse_processor_int + \int_compare:nNnTF \l_xparse_processor_int = \c_zero + { + \tl_put_right:Nx \l_xparse_args_tl + { { \exp_not:V \ProcessedArgument } } + } + { \xparse_add_arg_aux:V \ProcessedArgument } +} +\cs_generate_variant:Nn \xparse_add_arg_aux:n { V } +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \subsection{Grabbing arguments expandably} +% +% \begin{macro}[EXP]{\xparse_expandable_grab_D:w} +% \begin{macro}[EXP, aux]{\xparse_expandable_grab_D_i:NNNnwN} +% \begin{macro}[EXP, aux]{\xparse_expandable_grab_D_ii:NNNwNnnn} +% \begin{macro}[EXP, aux]{\xparse_expandable_grab_D_iii:Nw} +% \begin{macro}[EXP, aux]{\xparse_expandable_grab_D_iv:nnNNNwN} +% The first step is to grab the first token or group. The generic grabber +% \cs{\meta{function}}\verb*| | is just after \cs{q_xparse}, we go and find +% it. +% \begin{macrocode} +\cs_new:Npn \xparse_expandable_grab_D:w #1 \q_xparse #2 + { #2 { \xparse_expandable_grab_D_i:NNNnwNn #1 \q_xparse #2 } } +% \end{macrocode} +% We then wish to test whether |#7|, which we just grabbed, is exactly |#2|. +% Expand the only grabber function we have, |#1|, once: the two strings below +% are equal if and only if |#7| matches |#2| exactly.\footnote{It is obvious +% that if \texttt{\#7} matches \texttt{\#2} then the strings are equal. We +% must check the converse. The right-hand-side of \cs{str_if_eq:onTF} does +% not end with \texttt{\#3}, implying that the grabber function took +% everything as its arguments. The first brace group can only be empty if +% \texttt{\#7} starts with \texttt{\#2}, otherwise the brace group preceding +% \texttt{\#7} would not vanish. The third brace group is empty, thus the +% \cs{q_xparse} that was used by our grabber \texttt{\#1} must be the one +% that we inserted (not some token in \texttt{\#7}), hence the second brace +% group contains the end of \texttt{\#7} followed by \texttt{\#2}. Since this +% is \texttt{\#2} on the right-hand-side, and no brace can be lost there, +% \texttt{\#7} must contain nothing else than its leading \texttt{\#2}.} If +% |#7| does not match |#2|, then the optional argument is missing, we use the +% default |#4|, and put back the argument |#7| in the input stream. +% %^^A There is probably a bug similar to the non-expandable O{\par} bug. +% +% If it does match, then interesting things need to be done. We will grab the +% argument piece by piece, with the following pattern: +% \begin{quote} +% \meta{grabber} \Arg{tokens} \\ +% ~~\cs{q_nil} \Arg{piece 1} \meta{piece 2} \cs{ERROR} \cs{q_xparse}\\ +% ~~\cs{q_nil} \meta{input stream} +% \end{quote} +% The \meta{grabber} will find an opening delimiter in \meta{piece 2}, take +% the \cs{q_xparse} as a second delimiter, and find more material delimited +% by the closing delimiter in the \meta{input stream}. We then move the part +% before the opening delimiter from \meta{piece 2} to \meta{piece 1}, and the +% material taken from the \meta{input stream} to the \meta{piece 2}. Thus, +% the argument moves gradually from the \meta{input stream} to the +% \meta{piece 2}, then to the \meta{piece 1} when we have made sure to find +% all opening and closing delimiters. This two-step process ensures that +% nesting works: the number of opening delimiters minus closing delimiters in +% \meta{piece 1} is always equal to the number of closing delimiters in +% \meta{piece 2}. We stop grabbing arguments once the \meta{piece 2} contains +% no opening delimiter any more, hence the balance is reached, and the final +% argument is \meta{piece 1} \meta{piece 2}. +% \begin{macrocode} +\cs_new:Npn \xparse_expandable_grab_D_i:NNNnwNn #1#2#3#4#5 \q_xparse #6#7 + { + \str_if_eq:onTF + { #1 { } { } #7 #2 \q_xparse #3 } + { { } { #2 } { } } + { + #1 + { \xparse_expandable_grab_D_ii:NNNwNnnn #1#2#3#5 \q_xparse #6 } + \q_nil { } #2 \ERROR \q_xparse \ERROR + } + { #5 {#4} \q_xparse #6 {#7} } + } +% \end{macrocode} +% At this stage, |#6| is \cs{q_nil} \Arg{piece 1} \meta{more for piece 1}, +% and we want to concatenate all that, removing \cs{q_nil}, and keeping the +% opening delimiter |#2|. Simply use \cs{use_ii:nn}. Also, |#7| is +% \meta{remainder of piece 2} \cs{ERROR}, and |#8| is \cs{ERROR} \meta{more +% for piece 2}. We concatenate those, replacing the two \cs{ERROR} by the +% closing delimiter |#3|. +% \begin{macrocode} +\cs_new:Npn \xparse_expandable_grab_D_ii:NNNwNnnn #1#2#3#4 \q_xparse #5#6#7#8 + { + \exp_args:Nof \xparse_expandable_grab_D_iv:nnNNNwN + { \use_ii:nn #6 #2 } + { \xparse_expandable_grab_D_iii:Nw #3 \exp_stop_f: #7 #8 } + #1#2#3 #4 \q_xparse #5 + } +\cs_new:Npn \xparse_expandable_grab_D_iii:Nw #1#2 \ERROR \ERROR { #2 #1 } +% \end{macrocode} +% Armed with our two new \meta{pieces}, we are ready to loop. However, we +% must first see if \meta{piece 2} (here |#2|) contains any opening +% delimiter |#4|. Again, we expand |#3|, this time removing its whole output +% with \cs{use_none:nnn}. The test is similar to \cs{tl_if_in:nnTF}. The +% token list is empty if and only if |#2| does not contain the opening +% delimiter. In that case, we are done, and put the argument (from which we +% remove a spurious pair of delimiters coming from how we started the loop). +% Otherwise, we go back to looping with +% \cs{xparse_expandable_grab_D_ii:NNNwNnnn}. +% \begin{macrocode} +\cs_new:Npn \xparse_expandable_grab_D_iv:nnNNNwN #1#2#3#4#5#6 \q_xparse #7 + { + \exp_args:No \tl_if_empty:oTF + { #3 { \use_none:nnn } #2 \q_xparse #5 #4 \q_xparse #5 } + { + \xparse_put_arg_expandable:ow { \use_none:nn #1#2 } + #6 \q_xparse #7 + } + { + #3 + { \xparse_expandable_grab_D_ii:NNNwNnnn #3#4#5#6 \q_xparse #7 } + \q_nil {#1} #2 \ERROR \q_xparse \ERROR + } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro}[EXP]{\xparse_expandable_grab_D_alt:w} +% \begin{macro}[EXP]{\xparse_expandable_grab_D_alt_i:NNnwNn} +% \begin{macro}[EXP]{\xparse_expandable_grab_D_alt_ii:Nw} +% When the delimiters are identical, nesting is not possble and a simplified +% approach is used. The test concept here is the same as for the case where +% the delimiters are different. +% \begin{macrocode} +\cs_new:Npn \xparse_expandable_grab_D_alt:w #1 \q_xparse #2 + { #2 { \xparse_expandable_grab_D_alt_i:NNnwNn #1 \q_xparse #2 } } +\cs_new:Npn \xparse_expandable_grab_D_alt_i:NNnwNn #1#2#3#4 \q_xparse #5#6 + { + \str_if_eq:onTF + { #1 { } #6 #2 #2 } + { { } #2 } + { + #1 + { \xparse_expandable_grab_D_alt_ii:Nwn #5 #4 \q_xparse } + #6 \ERROR + } + { #4 {#3} \q_xparse #5 {#6} } + } +\cs_new:Npn \xparse_expandable_grab_D_alt_ii:Nwn #1#2 \q_xparse #3 + { \xparse_put_arg_expandable:ow { \use_none:n #3 } #2 \q_xparse #1 } +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% +% \begin{macro}[EXP]{\xparse_expandable_grab_m:w} +% \begin{macro}[EXP, aux]{\xparse_expandable_grab_m_aux:wNn} +% The mandatory case is easy: find the auxiliary after the \cs{q_xparse}, and +% use it directly to grab the argument. +% \begin{macrocode} +\cs_new:Npn \xparse_expandable_grab_m:w #1 \q_xparse #2 + { #2 { \xparse_expandable_grab_m_aux:wNn #1 \q_xparse #2 } } +\cs_new:Npn \xparse_expandable_grab_m_aux:wNn #1 \q_xparse #2#3 + { #1 {#3} \q_xparse #2 } +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{macro}[EXP]{\xparse_expandable_grab_R:w} +% \begin{macro}[EXP, aux]{\xparse_expandable_grab_R_aux:NNwn} +% Much the same as for the \texttt{D}-type argument, with only the lead-off +% function varying. +% \begin{macrocode} +\cs_new:Npn \xparse_expandable_grab_R:w #1 \q_xparse #2 + { #2 { \xparse_expandable_grab_R_aux:NNNnwNn #1 \q_xparse #2 } } +\cs_new:Npn \xparse_expandable_grab_R_aux:NNNnwNn #1#2#3#4#5 \q_xparse #6#7 + { + \str_if_eq:onTF + { #1 { } { } #7 #2 \q_xparse #3 } + { { } { #2 } { } } + { + #1 + { \xparse_expandable_grab_D_ii:NNNwNnnn #1#2#3#5 \q_xparse #6 } + \q_nil { } #2 \ERROR \q_xparse \ERROR + } + { + \msg_expandable_kernel_error:nnn + { xparse } { missing-required } {#2} + #5 {#4} \q_xparse #6 {#7} + } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{macro}[EXP]{\xparse_expandable_grab_R_alt:w} +% \begin{macro}[EXP]{\xparse_expandable_grab_R_alt_aux:NNnwNn} +% When the delimiters are identical, nesting is not possble and a simplified +% approach is used. The test concept here is the same as for the case where +% the delimiters are different. +% \begin{macrocode} +\cs_new:Npn \xparse_expandable_grab_R_alt:w #1 \q_xparse #2 + { #2 { \xparse_expandable_grab_R_alt_aux:NNnwNn #1 \q_xparse #2 } } +\cs_new:Npn \xparse_expandable_grab_R_alt_aux:NNnwNn #1#2#3#4 \q_xparse #5#6 + { + \str_if_eq:onTF + { #1 { } #6 #2 #2 } + { { } #2 } + { + #1 + { \xparse_expandable_grab_D_alt_ii:Nwn #5 #4 \q_xparse } + #6 \ERROR + } + { + \msg_expandable_kernel_error:nnn + { xparse } { missing-required } {#2} + #4 {#3} \q_xparse #5 {#6} + } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{macro}[EXP]{\xparse_expandable_grab_t:w} +% \begin{macro}[EXP, aux]{\xparse_expandable_grab_t_aux:NNwn} +% As for a \texttt{D}-type argument, here we compare the grabbed tokens using +% the only parser we have in order to work out if |#2| is exactly equal to +% the output of the grabber. +% \begin{macrocode} +\cs_new:Npn \xparse_expandable_grab_t:w #1 \q_xparse #2 + { #2 { \xparse_expandable_grab_t_aux:NNwn #1 \q_xparse #2 } } +\cs_new:Npn \xparse_expandable_grab_t_aux:NNwn #1#2#3 \q_xparse #4#5 + { + \str_if_eq:onTF { #1 { } #5 #2 } { #2 } + { #3 { \BooleanTrue } \q_xparse #4 } + { #3 { \BooleanFalse } \q_xparse #4 {#5} } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% +% \begin{macro}[EXP] +% {\xparse_put_arg_expandable:nw, \xparse_put_arg_expandable:ow} +% A useful helper, to store arguments when they are ready. +% \begin{macrocode} +\cs_new:Npn \xparse_put_arg_expandable:nw #1#2 \q_xparse { #2 {#1} \q_xparse } +\cs_generate_variant:Nn \xparse_put_arg_expandable:nw { o } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}[EXP]{\xparse_grab_expandable_end:wN} +% For the end of the grabbing sequence: get rid of the generic grabber and +% insert the code function followed by its arguments. +% \begin{macrocode} +\cs_new:Npn \xparse_grab_expandable_end:wN #1 \q_xparse #2 {#1} +% \end{macrocode} +%\end{macro} +% % \subsection{Argument processors} % +% \begin{macro}{\xparse_process_arg:n} +% Processors are saved for use later during the grabbing process. +% \begin{macrocode} +\cs_new_protected:Npn \xparse_process_arg:n #1 + { + \int_incr:N \l_xparse_processor_int + \cs_set:cpn { xparse_processor_ \int_use:N \l_xparse_processor_int :n } ##1 + { #1 {##1} } + } +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\xparse_process_to_str:n} % A basic argument processor: as much an example as anything else. % \begin{macrocode} @@ -2157,7 +2861,7 @@ { \IfNoValueF {##1} { - \msg_error:nnxxx { xparse } { split-excess-tokens } + \msg_kernel_error:nnxxx { xparse } { split-excess-tokens } { \tl_to_str:n {#2} } { \tl_to_str:n {#1} } { \tl_to_str:n {#3} } } @@ -2247,397 +2951,6 @@ % \end{macrocode} % \end{macro} % -% \subsection{Creating expandable functions} -% -% The trick here is to pass each grabbed argument along a chain of -% auxiliary functions. Each one ultimately calls the next in the chain, -% so that all of the arguments are passed along delimited using -% \cs{q_xparse}. At the end of the chain, the marker is removed -% so that the user-supplied code can be passed the correct number -% of arguments. All of this is done by expansion! -% -% \begin{macro}{\xparse_exp_add_type_d:w} -% As in the standard case, the trick here is to slot in the default -% and treat as type \texttt{D}. -% \begin{macrocode} -\cs_new_protected:Npn \xparse_exp_add_type_d:w #1#2 - { \xparse_exp_add_type_D:w #1 #2 { \NoValue } } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\xparse_exp_add_type_D:w} -% \begin{macro}[aux]{\xparse_exp_add_type_D_aux:nnNNn} -% The most complex argument to grab in an expandable manner is the -% general delimited one. Life gets so complicated here that the first thing -% to do is to expand the name of the current function and the current -% argument number so that a slightly less complex auxiliary can be employed. -% \begin{macrocode} -\cs_new_protected:Npn \xparse_exp_add_type_D:w #1#2#3 - { - \exp_args:NVV \xparse_exp_add_type_D_aux:nnNNn - \l_xparse_function_tl \l_xparse_total_args_int #1 #2 {#3} - \xparse_exp_prepare_function:N - } -% \end{macrocode} -% The general idea here is to use the same strategy as is employed in the -% non-expandable code, using a grabbed argument plus string test in place -% of \cs{peek_...} and employing a stack approach for the nesting part. -% Unlike the non-expandable code, all of the nesting here requires that -% the tests are set up in advance, which includes a dedicated copy of the -% \cs{tl_if_in:nnTF} auxiliary for the optional opening token. Several -% of the internal functions are also built with expansion as this is -% needed so that at point of use the number of expansions required is known. -% \begin{macrocode} -\cs_new_protected:Npn \xparse_exp_add_type_D_aux:nnNNn #1#2#3#4#5 - { - \xparse_exp_set:cpx { #1 _arg_ #2 :w } ##1 \q_xparse ##2 - { - \exp_not:N \str_if_eq:nnTF {##2} {#3} - { \exp_not:c { #1 _arg_ #2 _aux:w } ##1 \exp_not:N \q_xparse } - { - \exp_not:c { #1 _arg_ \int_eval:n { #2 + \c_one } :w } - ##1 {#5} \exp_not:N \q_xparse {##2} - } - } - \xparse_exp_set:cpx { #1 _arg_ #2 _aux:w } ##1 \q_xparse ##2 #4 - { - \exp_not:N \tl_if_empty:oTF - { \exp_not:c { #1 _arg_ #2 _open_check:w } ##2 { } { } #3 } - { - \exp_not:c { #1 _arg_ \int_eval:n { #2 + \c_one } :w } - ##1 {##2} \exp_not:N \q_xparse - } - { - \exp_not:c { #1 _arg_ #2 _nested:wnnw } ##1 \exp_not:N \q_xparse - { } { } ##2 \exp_not:N \q_xparse - } - } - \cs_set:cpn { #1 _arg_ #2 _open_check:w } ##1 #3 { } - \xparse_exp_set:cpx { #1 _arg_ #2 _nested:wnnw } - ##1 \q_xparse ##2##3 ##4 #3 ##5 \q_xparse ##6 #4 - { - \exp_not:N \tl_if_empty:oTF - { \exp_not:c { #1 _arg_ #2 _open_check:w } ##5 { } { } #3 } - { - \exp_not:N \tl_if_empty:oTF - { - \exp_not:c { #1 _arg_ #2 _open_check:w } ##3 #4 ##6 { } { } #3 - } - { - \exp_not:c { #1 _arg_ \int_eval:n { #2 + \c_one } :w } - ##1 { ##2 ##4 #3 ##5 ##3 #4 ##6 } \exp_not:N \q_xparse - } - { - \exp_not:c { #1 _arg_ #2 _nested:wnnw } - ##1 \exp_not:N \q_xparse { ##2 ##4 #3 ##5 } { } - ##3 #4 ##6 \exp_not:N \q_xparse - } - } - { - \exp_not:c { #1 _arg_ #2 _nested:w } ##1 \exp_not:N \q_xparse - { ##2 ##4 #3 } - { ##3 #4 ##6 } - ##5 \exp_not:N \q_xparse - } - } - } -% \end{macrocode} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\xparse_exp_add_type_m:w} -% The grabber for the current argument is created to simply get the -% necessary argument and pass it along with any others through to the -% next function in the chain. -% \begin{macrocode} -\cs_new_protected_nopar:Npn \xparse_exp_add_type_m:w - { - \int_incr:N \l_xparse_m_args_int - \xparse_exp_set:cpx - { - \l_xparse_function_tl - _arg_ - \int_use:N \l_xparse_total_args_int - :w - } - ##1 \q_xparse ##2 - { - \exp_not:c - { - \l_xparse_function_tl - _arg_ - \int_eval:n { \l_xparse_total_args_int + \c_one } - :w - } - ##1 {##2} \exp_not:N \q_xparse - } - \xparse_exp_prepare_function:N - } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\xparse_exp_add_type_t:w} -% Looking for a single token is a simpler version of the \texttt{D} -% code. The same idea of picking up one argument is used, but there is -% no need for a second function as there is no closing token to find. So -% either \cs{BooleanTrue} or \cs{BooleanFalse} are added to the list of -% arguments. In the later case, the grabber argument must be -% \enquote{recycled}. -% \begin{macrocode} -\cs_new_protected:Npn \xparse_exp_add_type_t:w #1 - { - \xparse_exp_set:cpx - { - \l_xparse_function_tl - _arg_ - \int_use:N \l_xparse_total_args_int - :w - } - ##1 \q_xparse ##2 - { - \exp_not:N \str_if_eq:nnTF {##2} {#1} - { - \exp_not:c - { - \l_xparse_function_tl - _arg_ - \int_eval:n { \l_xparse_total_args_int + \c_one } - :w - } - ##1 \exp_not:n { { \BooleanTrue } \q_xparse } - } - { - \exp_not:c - { - \l_xparse_function_tl - _arg_ - \int_eval:n { \l_xparse_total_args_int + \c_one } - :w - } - ##1 \exp_not:n { { \BooleanFalse } \q_xparse } {##2} - } - } - \xparse_exp_prepare_function:N - } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\xparse_exp_add_type_u:w} -% Setting up for a \texttt{u} argument is a case of defining the -% grabber for the current argument in a delimited fashion. The rest of -% the process is as the other grabbers: add to the chain and call the -% next function. -% \begin{macrocode} -\cs_new_protected:Npn \xparse_exp_add_type_u:w #1 - { - \xparse_exp_set:cpx - { - \l_xparse_function_tl - _arg_ - \int_use:N \l_xparse_total_args_int - :w - } - ##1 \q_xparse ##2 #1 - { - \exp_not:c - { - \l_xparse_function_tl - _arg_ - \int_eval:n { \l_xparse_total_args_int + \c_one } - :w - } - ##1 {##2} \exp_not:N \q_xparse - } - \xparse_exp_prepare_function:N - } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\xparse_exp_check_and_add:N} -% Virtually identical to the normal version, except calling the -% expandable \texttt{add} functions rather than the standard versions. -% \begin{macrocode} -\cs_new_protected_nopar:Npn \xparse_exp_check_and_add:N #1 - { - \cs_if_free:cTF { xparse_exp_add_type_ #1 :w } - { - \msg_error:nnx { xparse } - { unknown-expandable-argument-type } - { \tl_to_str:n {#1} } - \tl_set:Nn \l_xparse_last_arg_tl { m } - \xparse_exp_add_type_m:w - } - { - \tl_set:Nn \l_xparse_last_arg_tl {#1} - \use:c { xparse_exp_add_type_ #1 :w } - } - } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{\xparse_exp_declare_cmd:Nnn} -% \begin{macro}[aux]{\xparse_exp_declare_cmd_all_m:Nn} -% \begin{macro}[aux]{\xparse_exp_declare_cmd_mixed:Nn} -% \begin{macro}[aux]{\xparse_exp_declare_cmd_mixed_aux:Nn} -% The overall scheme here is very different from the standard method. -% For each argument, an internal function is created to grab an argument -% and pass along previous ones. Each \enquote{daisy chains} to call the next -% one in the sequence. Thus at the end of the chain, an extra -% \enquote{argument} function is included to unwind the chain and pass data -% to the the internal function containing the actual code. If all of the -% arguments are type \texttt{m}, then the same tick is used as in the -% standard version. The \texttt{x} in the lead-off and mop-up functions makes -% sure that the braces around the first argument are not lost. -% \begin{macrocode} -\cs_new_protected:Npn \xparse_exp_declare_cmd:Nnn #1#2#3 - { - \cs_if_exist:NTF #1 - { - \msg_warning:nnxx { xparse } { redefine-command } - { \token_to_str:N #1 } { \tl_to_str:n {#2} } - } - { - \msg_info:nnxx { xparse } { define-command } - { \token_to_str:N #1 } { \tl_to_str:n {#2} } - } - \group_begin: - \tex_escapechar:D 92 \scan_stop: - \tl_set:Nx \l_xparse_function_tl { \token_to_str:N #1 } - \exp_args:NNNV \group_end: - \tl_set:Nn \l_xparse_function_tl \l_xparse_function_tl - \xparse_exp_prepare_function:n {#2} - \int_compare:nNnTF \l_xparse_total_args_int = \l_xparse_m_args_int - { \xparse_exp_declare_cmd_all_m:Nn #1 {#3} } - { \xparse_exp_declare_cmd_mixed:Nn #1 {#3} } - } -\cs_new_protected:Npn \xparse_exp_declare_cmd_all_m:Nn #1#2 - { - \bool_if:NTF \l_xparse_long_bool - { - \cs_generate_from_arg_count:NNnn - #1 \cs_set:Npn \l_xparse_total_args_int {#2} - } - { - \cs_generate_from_arg_count:NNnn - #1 \cs_set_nopar:Npn \l_xparse_total_args_int {#2} - } - } -\cs_new_protected:Npn \xparse_exp_declare_cmd_mixed:Nn #1#2 - { - \tl_if_in:noTF { l m u } \l_xparse_last_arg_tl - { \xparse_exp_declare_cmd_mixed_aux:Nn #1 {#2} } - { \msg_error:nn { xparse } { expandable-ending-optional } } - } -\cs_new_protected:Npn \xparse_exp_declare_cmd_mixed_aux:Nn #1#2 - { - \cs_set_nopar:Npx #1 - { - \exp_not:c { \l_xparse_function_tl _arg_ 1 :w } x \exp_not:N \q_xparse - } - \cs_set_nopar:cpx - { - \l_xparse_function_tl - _arg_ - \int_eval:n { \l_xparse_total_args_int + \c_one } - :w - } - x ##1 \q_xparse - { \exp_not:c { \l_xparse_function_tl } ##1 } - \cs_generate_from_arg_count:cNnn - { \l_xparse_function_tl } \cs_set:Npn \l_xparse_total_args_int {#2} - } -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\xparse_exp_prepare_function:n} -% \begin{macro}[aux]{\xparse_exp_prepare_function_aux:n} -% Processors are forbidden in expandable functions. -% \begin{macrocode} -\cs_new_protected:Npn \xparse_exp_prepare_function:n #1 - { - \tl_if_in:nnTF {#1} { > } - { - \msg_error:nnxx { xparse } { processor-in-expandable } - { \tl_to_str:n {#1} } - } - { \xparse_exp_prepare_function_aux:n {#1} } - } -\cs_new_protected:Npn \xparse_exp_prepare_function_aux:n #1 - { - \cs_set_eq:NN \xparse_prepare_next:w \xparse_exp_prepare_function:N - \cs_set_eq:NN \xparse_exp_set:cpx \cs_set_nopar:cpx - \bool_set_false:N \l_xparse_long_bool - \int_zero:N \l_xparse_m_args_int - \int_zero:N \l_xparse_total_args_int - \tl_if_in:nnT {#1} { + } - { - \bool_set_true:N \l_xparse_long_bool - \cs_set_eq:NN \xparse_exp_set:cpx \cs_set:cpx - } - \xparse_exp_prepare_function:N #1 \q_nil - } -% \end{macrocode} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\xparse_exp_prepare_function:N} -% \begin{macro}[aux]{\xparse_exp_prepare_function_long:N} -% \begin{macro}[aux]{\xparse_exp_prepare_function_short:N} -% Preparing functions is a case of reading the signature, as in the -% normal case. However, everything has to be either short or long, and -% so there is an extra step to make sure that once one \texttt{+} has -% been seen everything has one. That detour then takes us back to -% a standard looping concept. -% \begin{macrocode} -\cs_new_protected:Npn \xparse_exp_prepare_function:N #1 - { - \bool_if:NTF \l_xparse_long_bool - { \xparse_exp_prepare_function_long:N #1 } - { \xparse_exp_prepare_function_short:N #1 } -} -\cs_new_protected:Npn \xparse_exp_prepare_function_long:N #1 - { - \quark_if_nil:NF #1 - { - \str_if_eq:nnTF {#1} { + } - { \xparse_exp_prepare_function_short:N } - { - \msg_error:nn { xparse } { inconsistent-long } - \xparse_exp_prepare_function_short:N #1 - } - } - } -\cs_new_protected:Npn \xparse_exp_prepare_function_short:N #1 - { - \quark_if_nil:NF #1 - { - \prop_get:NnNTF \c_xparse_shorthands_prop {#1} \l_xparse_tmp_tl - { - \bool_if:NT \l_xparse_long_bool - { \tl_put_left:Nn \l_xparse_tmp_tl { + } } - \exp_after:wN \xparse_exp_prepare_function:N \l_xparse_tmp_tl - } - { - \int_incr:N \l_xparse_total_args_int - \xparse_exp_check_and_add:N #1 - } - } - } -% \end{macrocode} -% \end{macro} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\xparse_exp_set:cpx} -% A short-cut to save constantly re-testing \cs{l_xparse_long_bool}. -% \begin{macrocode} -\cs_new_eq:NN \xparse_exp_set:cpx \cs_set_nopar:cpx -% \end{macrocode} -% \end{macro} -% % \subsection{Access to the argument specification} % % \begin{macro}{\xparse_get_arg_spec:N} @@ -2648,22 +2961,19 @@ % \begin{macrocode} \cs_new_protected:Npn \xparse_get_arg_spec:N #1 { - \cs_if_exist:cTF { l_xparse_ \token_to_str:N #1 _arg_spec_tl } + \prop_get:NnNF \l_xparse_command_arg_specs_prop {#1} + \ArgumentSpecification { - \tl_set_eq:Nc \ArgumentSpecification - { l_xparse_ \token_to_str:N #1 _arg_spec_tl } - } - { - \msg_error:nnx { xparse } { unknown-document-command } + \msg_kernel_error:nnx { xparse } { unknown-document-command } { \token_to_str:N #1 } } } \cs_new_protected:Npn \xparse_get_arg_spec:n #1 { - \cs_if_exist:cTF { l_xparse_ #1 _arg_spec_tl } - { \tl_set_eq:Nc \ArgumentSpecification { l_xparse_ #1 _arg_spec_tl } } + \prop_get:NnNF \l_xparse_environment_arg_specs_prop {#1} + \ArgumentSpecification { - \msg_error:nnx { xparse } { unknown-document-environment } + \msg_kernel_error:nnx { xparse } { unknown-document-environment } { \tl_to_str:n {#1} } } } @@ -2680,26 +2990,22 @@ % \begin{macrocode} \cs_new_protected:Npn \xparse_show_arg_spec:N #1 { - \cs_if_exist:cTF { l_xparse_ \token_to_str:N #1 _arg_spec_tl } - { - \tl_set_eq:Nc \ArgumentSpecification - { l_xparse_ \token_to_str:N #1 _arg_spec_tl } - \tl_show:N \ArgumentSpecification - } + \tl_set:Nx \l_xparse_function_tl { \cs_to_str:N #1 } + \prop_get:NnNTF \l_xparse_command_arg_specs_prop {#1} + \ArgumentSpecification + { \tl_show:N \ArgumentSpecification } { - \msg_error:nnx { xparse } { unknown-document-command } + \msg_kernel_error:nnx { xparse } { unknown-document-command } { \token_to_str:N #1 } } } \cs_new_protected:Npn \xparse_show_arg_spec:n #1 { - \cs_if_exist:cTF { l_xparse_ #1 _arg_spec_tl } + \prop_get:NnNTF \l_xparse_environment_arg_specs_prop {#1} + \ArgumentSpecification + { \tl_show:N \ArgumentSpecification } { - \tl_set_eq:Nc \ArgumentSpecification { l_xparse_ #1 _arg_spec_tl } - \tl_show:N \ArgumentSpecification - } - { - \msg_error:nnx { xparse } { unknown-document-environment } + \msg_kernel_error:nnx { xparse } { unknown-document-environment } { \tl_to_str:n {#1} } } } @@ -2707,52 +3013,72 @@ % \end{macro} % \end{macro} % +% \subsection{Utilities} +% +% \begin{macro}[TF]{\xparse_if_no_value:n} +% Tests for \cs{NoValue}. +% \begin{macrocode} +\prg_new_conditional:Npnn \xparse_if_no_value:n #1 { T , F , TF } + { \str_if_eq:nnTF {#1} { \NoValue } \prg_return_true: \prg_return_false: } +% \end{macrocode} +% \end{macro} +% +% \subsection{Messages} +% %\subsection{Messages} % % Some messages intended as errors. % \begin{macrocode} -\msg_new:nnnn { xparse } { command-already-defined } +\msg_kernel_new:nnnn { xparse } { bad-signature } + { Bad~signature~'#1'. } + { + \c_msg_coding_error_text_tl + The~signature~provided~was~not~valid:~one~or~more~mandatory~pieces~ + of~information~were~missing. \\ \\ + LaTeX~will~ignore~this~entire~definition. + } +\msg_kernel_new:nnnn { xparse } { command-already-defined } { Command~'#1'~already~defined! } { You~have~used~\NewDocumentCommand with~a~command~that~already~has~a~definition. \\ The~existing~definition~of~'#1'~will~be~overwritten. } -\msg_new:nnnn { xparse } { command-not-yet-defined } +\msg_kernel_new:nnnn { xparse } { command-not-yet-defined } { Command ~'#1'~not~yet~defined! } { You~have~used~\RenewDocumentCommand with~a~command~that~was~never~defined.\\ A~new~command~'#1'~will~be~created. } -\msg_new:nnnn { xparse } { environment-already-defined } +\msg_kernel_new:nnnn { xparse } { environment-already-defined } { Environment~'#1'~already~defined! } { You~have~used~\NewDocumentEnvironment with~an~environment~that~already~has~a~definition.\\ The~existing~definition~of~'#1'~will~be~overwritten. } -\msg_new:nnnn { xparse } { environment-mismatch } +\msg_kernel_new:nnnn { xparse } { environment-mismatch } { Mismatch~between~start~and~end~of~environment. } { The~current~environment~is~called~'#1',~but~you~have~tried~to~ end~one~called~'#2'.~Environments~have~to~be~properly~nested. } -\msg_new:nnnn { xparse } { environment-not-yet-defined } +\msg_kernel_new:nnnn { xparse } { environment-not-yet-defined } { Environment~'#1'~not~yet~defined! } { You~have~used~\RenewDocumentEnvironment with~an~environment~that~was~never~defined.\\ A~new~environment~'#1'~will~be~created. } -\msg_new:nnnn { xparse } { environment-unknown } +\msg_kernel_new:nnnn { xparse } { environment-unknown } { Environment~'#1'~undefined. } { You~have~tried~to~start~an~environment~called~'#1',~ but~this~has~never~been~defined.\\ The~command~will~be~ignored. } -\msg_new:nnnn { xparse } { expandable-ending-optional } +\msg_kernel_new:nnnn { xparse } { expandable-ending-optional } { Signature~for~expandable~command~ends~with~optional~argument. } { \c_msg_coding_error_text_tl @@ -2760,87 +3086,107 @@ (or~no~arguments~at~all).~You~cannot~have~a~terminal~optional~ argument~with~expandable~commands. } -\msg_new:nnnn { xparse } { inconsistent-long } +\msg_kernel_new:nnnn { xparse } { inconsistent-long } { Inconsistent~long~arguments~for~expandable~command. } { \c_msg_coding_error_text_tl The~arguments~for~an~expandable~command~must~either~all~be~ short~or~all~be~long.~You~have~tried~to~mix~the~two~types. } -\msg_new:nnnn { xparse } { processor-in-expandable } +\msg_kernel_new:nnnn { xparse } { invalid-expandable-argument-type } + { Unknown~argument~type~'#1'~replaced~by~'m'. } + { + \c_msg_coding_error_text_tl + The~letter~'#1'~does~not~specify~an~argument~type~which~can~be~used~ + in~an~expandable~function. + \\ \\ + LaTeX~will~assume~you~want~a~standard~mandatory~argument~(type~'m'). + } +\msg_kernel_new:nnnn { xparse } { missing-required } + { Failed~to~find~required~argument~starting~with~'#1'. } + { + There~is~supposed~to~be~an~argument~to~the~current~function~starting~with~ + '#1'.~LaTeX~did~not~find~it,~and~will~insert~'#2'~as~the~value~to~be~ + processed. + } +\msg_kernel_new:nnnn { xparse } { not-single-token } + { Argument~delimiter~should~be~a~single~token:~'#1'. } + { + \c_msg_coding_error_text_tl + The~signature~provided~was~not~valid:~in~a~place~where~a~single~token~is~ + required,~LaTeX~found~'#1'. \\ \\ + LaTeX~will~ignore~this~entire~definition. + } +\msg_kernel_new:nnnn { xparse } { processor-in-expandable } { Argument~processors~cannot~be~used~with~expandable~functions. } { \c_msg_coding_error_text_tl - Argument~specification~'#1'~contains~a~processor~function:~ + The~argument~specification~for~#1~contains~a~processor~function:~ this~is~only~supported~for~standard~robust~functions. } -\msg_new:nnnn { xparse } { split-excess-tokens } +\msg_kernel_new:nnnn { xparse } { split-excess-tokens } { Too~many~'#1'~tokens~when~trying~to~split~argument. } { LaTeX~was~asked~to~split~the~input~'#3'~ at~each~occurrence~of~the~token~'#1',~up~to~a~maximum~of~#2~parts.~ There~were~too~many~'#1'~tokens. } -\msg_new:nnnn { xparse } { unknown-argument-type } +\msg_kernel_new:nnnn { xparse } { unknown-argument-type } { Unknown~argument~type~'#1'~replaced~by~'m'. } { \c_msg_coding_error_text_tl The~letter~'#1'~does~not~specify~a~known~argument~type.~ LaTeX~will~assume~you~want~a~standard~mandatory~argument~(type~'m'). } -\msg_new:nnnn { xparse } { unknown-document-command } +\msg_kernel_new:nnnn { xparse } { unknown-document-command } { Unknown~document~command~'#1'. } { You~have~asked~for~the~argument~specification~for~a~command~'#1',~ but~this~is~not~a~document~command. } -\msg_new:nnnn { xparse } { unknown-document-environment } +\msg_kernel_new:nnnn { xparse } { unknown-document-environment } { Unknown~document~environment~'#1'. } { You~have~asked~for~the~argument~specification~for~a~command~'#1',~ but~this~is~not~a~document~environment. } -\msg_new:nnnn { xparse } { unknown-expandable-argument-type } - { Unknown~argument~type~'#1'~replaced~by~'m'. } - { - \c_msg_coding_error_text_tl - The~letter~'#1'~does~not~specify~an~argument~type~which~can~be~used~ - in~an~expandable~function. - LaTeX~will~assume~you~want~a~standard~mandatory~argument~(type~'m'). - } -\msg_new:nnnn { xparse } { verbatim-newline } +\msg_kernel_new:nnnn { xparse } { verbatim-newline } { Verbatim~argument~of~#1~ended~by~end~of~line. } { - Short~verbatim~arguments~cannot~contain~newlines.~ - I~suspect~you've~forgotten~the~closing~delimiter~of~#1. - I~will~ignore~'#2'. + The~verbatim~argument~of~#1~cannot~contain~more~than~one~line,~but~the~end~ + of~the~current~line~has~been~reached.~You~have~probably~forgotten~the~ + closing~delimiter. + \\ \\ + LaTeX~will~ignored~'#2'. } -\msg_new:nnnn { xparse } { verbatim-already-tokenized } +\msg_kernel_new:nnnn { xparse } { verbatim-already-tokenized } { Verbatim~command~#1~illegal~in~command~argument. } { The~command~#1~takes~a~verbatim~argument.~It~may~not~appear~within~ - the~argument~of~another~function.~I~will~ignore~'#2'. + the~argument~of~another~function. + \\ \\ + LaTeX~will~ignore~'#2'. } % \end{macrocode} % % Intended more for information. % \begin{macrocode} -\msg_new:nnn { xparse } { define-command } +\msg_kernel_new:nnn { xparse } { define-command } { Defining~document~command~#1~ with~arg.~spec.~'#2'~\msg_line_context:. } -\msg_new:nnn { xparse } { define-environment } +\msg_kernel_new:nnn { xparse } { define-environment } { Defining~document~environment~'#1'~ with~arg.~spec.~'#2'~\msg_line_context:. } -\msg_new:nnn { xparse } { redefine-command } +\msg_kernel_new:nnn { xparse } { redefine-command } { Redefining~document~command~#1~ with~arg.~spec.~'#2'~\msg_line_context:. } -\msg_new:nnn { xparse } { redefine-environment } +\msg_kernel_new:nnn { xparse } { redefine-environment } { Redefining~document~environment~'#1'~ with~arg.~spec.~'#2'~\msg_line_context:. @@ -2874,7 +3220,7 @@ { \cs_if_exist:NTF #1 { - \msg_error:nnx { xparse } { command-already-defined } + \msg_kernel_error:nnx { xparse } { command-already-defined } { \token_to_str:N #1 } } { \xparse_declare_cmd:Nnn #1 {#2} {#3} } @@ -2882,9 +3228,9 @@ \cs_new_protected:Npn \RenewDocumentCommand #1#2#3 { \cs_if_exist:NTF #1 - { \xparse_declare_cmd_aux:Nnn #1 {#2} {#3} } + { \xparse_declare_cmd:Nnn #1 {#2} {#3} } { - \msg_error:nnx { xparse } { command-not-yet-defined } + \msg_kernel_error:nnx { xparse } { command-not-yet-defined } { \token_to_str:N #1 } } } @@ -2896,19 +3242,6 @@ % \end{macro} % \end{macro} % -% \begin{macro}{\DeclareDocumentCommandImplementation} -% \begin{macro}{\DeclareDocumentCommandInterface} -% The separate implementation/interface system is again pretty simple -% to create at the outer layer. -% \begin{macrocode} -\cs_new_protected:Npn \DeclareDocumentCommandImplementation #1#2#3 - { \xparse_declare_cmd_implementation:nNn {#1} #2 {#3} } -\cs_new_protected:Npn \DeclareDocumentCommandInterface #1#2#3 - { \xparse_declare_cmd_interface:Nnn #1 {#2} {#3} } -% \end{macrocode} -% \end{macro} -% \end{macro} -% % \begin{macro}{\DeclareDocumentEnvironment} % \begin{macro}{\NewDocumentEnvironment} % \begin{macro}{\RenewDocumentEnvironment} @@ -2920,14 +3253,14 @@ \cs_new_protected:Npn \NewDocumentEnvironment #1#2#3#4 { \cs_if_exist:cTF {#1} - { \msg_error:nnx { xparse } { environment-already-defined } {#1} } + { \msg_kernel_error:nnx { xparse } { environment-already-defined } {#1} } { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} } } \cs_new_protected:Npn \RenewDocumentEnvironment #1#2#3#4 { \cs_if_exist:cTF {#1} { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} } - { \msg_error:nnx { xparse } { environment-not-yet-defined } {#1} } + { \msg_kernel_error:nnx { xparse } { environment-not-yet-defined } {#1} } } \cs_new_protected:Npn \ProvideDocumentEnvironment #1#2#3#4 { \cs_if_exist:cF { #1 } { \xparse_declare_env:nnnn {#1} {#2} {#3} {#4} } } @@ -2941,7 +3274,7 @@ % The expandable version of the basic function is essentially the same. % \begin{macrocode} \cs_new_protected:Npn \DeclareExpandableDocumentCommand #1#2#3 - { \xparse_exp_declare_cmd:Nnn #1 {#2} {#3} } + { \xparse_declare_expandable_cmd:Nnn #1 {#2} {#3} } % \end{macrocode} % \end{macro} % @@ -2990,19 +3323,20 @@ % \end{macrocode} % \end{macro} % -% \begin{macro}{\ReverseBoolean} -% A processor to reverse the logic for token detection. +% \begin{macro}{\ReverseBoolean, \SplitArgument, \SplitList, \TrimSpaces} +% Simple copies. % \begin{macrocode} \cs_new_eq:NN \ReverseBoolean \xparse_bool_reverse:N +\cs_new_eq:NN \SplitArgument \xparse_split_argument:nnn +\cs_new_eq:NN \SplitList \xparse_split_list:nn +\cs_new_eq:NN \TrimSpaces \xparse_trim_spaces:n % \end{macrocode} % \end{macro} % -% \begin{macro}{\SplitArgument, \SplitList, \TrimSpaces} -% Simple copies +% \begin{macro}{\ProcessList} +% To support \cs{SplitList}. % \begin{macrocode} -\cs_new_eq:NN \SplitArgument \xparse_split_argument:nnn -\cs_new_eq:NN \SplitList \xparse_split_list:nn -\cs_new_eq:NN \TrimSpaces \xparse_trim_spaces:n +\cs_new_eq:NN \ProcessList \tl_map_function:nN % \end{macrocode} % \end{macro} % @@ -3043,4 +3377,4 @@ % % \end{implementation} % -% \PrintIndex +% \PrintIndex
\ No newline at end of file diff --git a/Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.dtx b/Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.dtx index bacc031f584..1dbbd0afd15 100644 --- a/Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.dtx +++ b/Master/texmf-dist/source/latex/l3packages/xtemplate/xtemplate.dtx @@ -4,7 +4,7 @@ %% David Carlisle %% (C) Copyright 2004-2010 Frank Mittelbach, %% The LaTeX3 Project -%% (C) Copyright 2011 The LaTeX3 Project +%% (C) Copyright 2011,2012 The LaTeX3 Project %% %% It may be distributed and/or modified under the conditions of the %% LaTeX Project Public License (LPPL), either version 1.3c of this @@ -39,8 +39,21 @@ %% % %<*driver|package> -\RequirePackage{expl3} -\GetIdInfo$Id: xtemplate.dtx 3109 2011-12-29 10:42:27Z joseph $ +% The version of expl3 required is tested as early as possible, as +% some really old versions do not define \ProvidesExplPackage. +\RequirePackage{expl3}[2012/01/19] +%<package>\@ifpackagelater{expl3}{2012/01/19} +%<package> {} +%<package> { +%<package> \PackageError{xtemplate}{Support package l3kernel too old.} +%<package> { +%<package> Please install an up to date~version of l3kernel +%<package> using your TeX package manager or from CTAN.\\ \\ +%<package> Loading xtemplate will abort! +%<package> } +%<package> \endinput +%<package> } +\GetIdInfo$Id: xtemplate.dtx 3207 2012-01-19 08:50:24Z joseph $ {L3 Experimental prototype document functions} %</driver|package> %<*driver> @@ -51,13 +64,13 @@ \end{document} %</driver> % \fi -% +% % \title{^^A % The \textsf{xtemplate} package\\ Prototype document functions^^A % \thanks{This file describes v\ExplFileVersion, % last revised \ExplFileDate.}^^A % } -% +% % \author{^^A % The \LaTeX3 Project\thanks % {^^A @@ -216,7 +229,7 @@ % agree with the object type declaration. The interface itself is % defined by the \meta{key list}, which is itself a key--value list % taking a specialized format: -% +% % \begin{syntax} % \meta{key1}~":"~\meta{key type1}~"," % \meta{key2}~":"~\meta{key type2}~"," @@ -247,9 +260,9 @@ % boolean & \texttt{true} or \texttt{false} \\ % choice\Arg{choices} % & A list of pre-defined \meta{choices} \\ -% code +% code % & Generalised key type: use |#1| as the input to the key \\ -% commalist & A comma-separated list \\ +% commalist & A comma-separated list \\ % function\Arg{$N$} % & A function definition with $N$ arguments % ($N$ from $0$ to $9$) \\ @@ -300,7 +313,7 @@ % argument is a key--value list which specifies the relationship % between each \meta{key} of the template interface with an % underlying\meta{variable}. -% +% % \begin{syntax} % \meta{key1}~"="~\meta{variable1}, % \meta{key2}~"="~\meta{variable2}, @@ -314,14 +327,14 @@ % may be included in the listing to indicate that the \meta{variable} % should be assigned globally. A full list of variable bindings is % given in Table~\ref{tab:key-vars}. -% +% % The \meta{code} argument of \cs{DeclareTemplateCode} is used % as the replacement text for the template when it is used, either % directly or as an instance. This may therefore accept arguments % |#1|, |#2|, \emph{etc}.~as detailed by the \meta{number of arguments} % taken by the object type. % \end{function} -% +% % \begin{table} % \centering % \begin{tabular}{>{\ttfamily}ll} @@ -329,12 +342,12 @@ % \multicolumn{1}{l}{Key-type} & Description of binding \\ % \midrule % boolean & Boolean variable, \emph{e.g}.~\cs{l_tmpa_bool} \\ -% choice +% choice % & List of choice implementations % (see Section~\ref{sec:choices-key}) \\ % code % & \meta{code} using |#1| as input to the key \\ -% commalist & Comma list, \emph{e.g}.~\cs{l_tmpa_clist} \\ +% commalist & Comma list, \emph{e.g}.~\cs{l_tmpa_clist} \\ % function % & Function taking $N$ arguments, \emph{e.g}.~\cs{use_i:nn} \\ % instance \\ @@ -353,7 +366,7 @@ % out a global assignment.} % \label{tab:key-vars} % \end{table} -% +% % \begin{function}{\AssignTemplateKeys} % \begin{syntax} % \cs{AssignTemplateKeys} @@ -363,7 +376,7 @@ % \cs{AssignTemplateKeys}. Thus no keys are assigned if this is missing % from the \meta{code} used. % \end{function} -% +% % \begin{function}{\EvaluateNow} % \begin{syntax} % \cs{EvaluteNow} \Arg{expression} @@ -373,8 +386,8 @@ % be desirable to calculate the value when declared, which can be % forced using \cs{EvaluateNow}. Currently, this functionality is % regarded as experimental: the team have not found an example where it -% is actually needed, and so it may be dropped \emph{if} no good -% examples are suggested! +% is actually needed, and so it may be dropped \emph{if} no good +% examples are suggested! % \end{function} % % \section{Multiple choices} @@ -461,7 +474,7 @@ % to create an \meta{instance}. The \meta{instance} will be set % up using the \meta{parameters}, which will set some of the % \meta{keys} in the \meta{template}. -% +% % As a practical example, consider an object type for document sections % (which might include chapters, parts, sections, \emph{etc}.), which % is called \texttt{sectioning}. One possible template for this @@ -512,7 +525,7 @@ % and immediately using it with \cs{UseInstance}, but without the % instance having any further existence. It is therefore useful where % a template needs to be used once. -% +% % This function can also be used as the argument to \texttt{instance} % key types: % \begin{verbatim} @@ -589,7 +602,7 @@ % Shows the \meta{values} for an \meta{instance} of the given % \meta{object type} at the terminal. % \end{function} -% +% % \begin{function}{\ShowCollectionInstanceValues} % \begin{syntax} % \cs{ShowInstanceValues} \Arg{collection} \Arg{object type} \Arg{instance} @@ -649,7 +662,7 @@ % \begin{implementation} % % \section{\pkg{xtemplate} Implementation} -% +% % \begin{macrocode} %<*package> % \end{macrocode} @@ -658,22 +671,7 @@ \ProvidesExplPackage {\ExplFileName}{\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription} % \end{macrocode} -% -% A check to make sure that \pkg{expl3} is not too old -% \begin{macrocode} -\@ifpackagelater { expl3 } { 2011/12/29 } - { } - { - \PackageError { xtemplate } { Support~package~l3kernel~too~old. } - { - Please~install~an~up~to~date~version~of~l3kernel~ - using~your~TeX~package~manager~or~from~CTAN.\\ \\ - Loading~xtemplate~will~abort! - } - \tex_endinput:D - } -% \end{macrocode} -% +% % \subsection{Variables and constants} % % \begin{variable}{\c_xtemplate_code_root_tl} @@ -718,12 +716,12 @@ % \begin{variable}{\g_xtemplate_object_type_prop} % For storing types and the associated number of arguments. % \begin{macrocode} -\prop_new:N \g_xtemplate_object_type_prop +\prop_new:N \g_xtemplate_object_type_prop % \end{macrocode} % \end{variable} % % \begin{variable}{\l_xtemplate_assignments_tl} -% When creating an instance, the assigned values are collected here. +% When creating an instance, the assigned values are collected here. % \begin{macrocode} \tl_new:N \l_xtemplate_assignments_tl % \end{macrocode} @@ -824,7 +822,7 @@ % \begin{variable}{\l_xtemplate_tmp_int} % \begin{variable}{\l_xtemplate_tmp_muskip} % \begin{variable}{\l_xtemplate_tmp_skip} -% For pre-processing the data stored by \pkg{xtemplate}, a number of +% For pre-processing the data stored by \pkg{xtemplate}, a number of % scratch variables are needed. The assignments are made to these in the % first instance, unless evaluation is delayed. % \begin{macrocode} @@ -864,7 +862,7 @@ % There are a number of checks needed for either the existence of % a object type, template or instance. There are also some for the % validity of a particular call. All of these are collected up here. -% +% % \begin{macro}{\xtemplate_execute_if_arg_agree:nnT} % A test agreement between the number of arguments for the template % type and that specified when creating a template. This is not done as a @@ -876,7 +874,7 @@ \int_compare:nNnTF {#2} = \l_xtemplate_tmp_tl {#3} { - \msg_error:nnxxx { xtemplate } + \msg_error:nnxxx { xtemplate } { argument-number-mismatch } {#1} { \l_xtemplate_tmp_tl } {#2} } } @@ -884,15 +882,15 @@ % \end{macro} % % \begin{macro}{\xtemplate_execute_if_code_exist:nnT} -% A template is only fully declared if the code has been set up, +% A template is only fully declared if the code has been set up, % which can be checked by looking for the template function itself. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_execute_if_code_exist:nnT #1#2#3 { - \cs_if_exist:cTF { \c_xtemplate_code_root_tl #1 / #2 } + \cs_if_exist:cTF { \c_xtemplate_code_root_tl #1 / #2 } {#3} { - \msg_error:nnxx { xtemplate } { no-template-code } + \msg_error:nnxx { xtemplate } { no-template-code } {#1} {#2} } } @@ -903,11 +901,11 @@ % \begin{macro}{\xtemplate_execute_if_keytype_exist:oT} % The test for valid keytypes looks for a function to set up the key, % which is part of the \enquote{code} side of the template definition. -% This avoids having different lists for the two parts of the process. +% This avoids having different lists for the two parts of the process. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_execute_if_keytype_exist:nT #1#2 { - \cs_if_exist:cTF { xtemplate_store_value_ #1 :n } + \cs_if_exist:cTF { xtemplate_store_value_ #1 :n } {#2} { \msg_error:nnx { xtemplate } { unknown-keytype } {#1} } } @@ -921,7 +919,7 @@ % \begin{macrocode} \cs_new_protected:Npn \xtemplate_execute_if_type_exist:nT #1#2 { - \prop_if_in:NnTF \g_xtemplate_object_type_prop {#1} + \prop_if_in:NnTF \g_xtemplate_object_type_prop {#1} {#2} { \msg_error:nnx { xtemplate } { unknown-object-type } {#1} } } @@ -935,10 +933,10 @@ % \begin{macrocode} \cs_new_protected:Npn \xtemplate_if_keys_exist:nnT #1#2#3 { - \cs_if_exist:cTF { \c_xtemplate_keytypes_root_tl #1 / #2 } + \cs_if_exist:cTF { \c_xtemplate_keytypes_root_tl #1 / #2 } {#3} { - \msg_error:nnxx { xtemplate } { unknown-template } + \msg_error:nnxx { xtemplate } { unknown-template } {#1} {#2} } } @@ -974,8 +972,8 @@ % \begin{macro}[TF]{\xtemplate_if_instance_exist:nnn} % Testing for an instance is collection dependent. % \begin{macrocode} -\prg_new_conditional:Npnn \xtemplate_if_instance_exist:nnn #1#2#3 - { T, F, TF } +\prg_new_conditional:Npnn \xtemplate_if_instance_exist:nnn #1#2#3 + { T, F, TF } { \cs_if_exist:cTF { \c_xtemplate_instances_root_tl #1 / #2 / #3 } { \prg_return_true: } @@ -1054,8 +1052,8 @@ % \begin{macro}{\xtemplate_recover_restrictions:n} % \begin{macro}{\xtemplate_recover_values:n} % \begin{macro}{\xtemplate_recover_vars:n} -% Recovering the stored data for a template is rather less complex -% than storing it. All that happens is the data is transferred from +% Recovering the stored data for a template is rather less complex +% than storing it. All that happens is the data is transferred from % the permanent to the scratch storage. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_recover_defaults:n #1 @@ -1091,13 +1089,13 @@ % \end{macro} % \end{macro} % \end{macro} -% +% % \subsection{Creating new object types} % % \begin{macro}{\xtemplate_declare_object_type:nn} % Although the object type is the \enquote{top level} of the template % system, it is actually very easy to implement. All that happens is that -% the number of arguments required is recorded, indexed by the name of the +% the number of arguments required is recorded, indexed by the name of the % object type. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_declare_object_type:nn #1#2 @@ -1107,15 +1105,15 @@ { \int_compare_p:nNn {#2} > \c_nine || \int_compare_p:nNn {#2} < \c_zero - } + } { - \msg_error:nnxx { xtemplate } { bad-number-of-arguments } + \msg_error:nnxx { xtemplate } { bad-number-of-arguments } {#1} { \exp_not:V \l_xtemplate_tmp_int } } { - \msg_info:nnxx { xtemplate } { declare-object-type } + \msg_info:nnxx { xtemplate } { declare-object-type } {#1} {#2} - \prop_gput:NnV \g_xtemplate_object_type_prop {#1} + \prop_gput:NnV \g_xtemplate_object_type_prop {#1} \l_xtemplate_tmp_int } } @@ -1129,19 +1127,19 @@ % not include the implementation. This means that what happens here is % the two properties are saved to appropriate lists, which can then % be used later to recover the information when implementing the keys. -% +% % \begin{macro}{\xtemplate_declare_template_keys:nnnn} % The main function for the \enquote{design} part of creating a template -% starts by checking that the object type exists and that the number of +% starts by checking that the object type exists and that the number of % arguments required agree. If that is all fine, then the two storage % areas for defaults and keytypes are initialised. The mechanism is then -% set up for the \pkg{l3keys} module to actually parse the keys. +% set up for the \pkg{l3keys} module to actually parse the keys. % Finally, the code hands of to the storage routine to save the parsed % information properly. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_declare_template_keys:nnnn #1#2#3#4 { - \xtemplate_execute_if_type_exist:nT {#1} + \xtemplate_execute_if_type_exist:nT {#1} { \xtemplate_execute_if_arg_agree:nnT {#1} {#3} { @@ -1163,7 +1161,7 @@ % \begin{macro}[aux]{\xtemplate_parse_keys_elt_aux:} % Processing the key part of the key--value pair is always carried out % using this function, even if a value was found. First, the key name -% is separated from the keytype, and if necessary the keytype is +% is separated from the keytype, and if necessary the keytype is % separated into two parts. This information is then used to check that % the keytype is valid, before storing the keytype (plus argument if % necessary) as a property of the key name. The key name is also stored @@ -1173,41 +1171,41 @@ \cs_new_protected:Npn \xtemplate_parse_keys_elt:n #1 { \xtemplate_split_keytype:n {#1} - \bool_if:NF \l_xtemplate_error_bool + \bool_if:NF \l_xtemplate_error_bool { - \xtemplate_execute_if_keytype_exist:oT \l_xtemplate_keytype_tl + \xtemplate_execute_if_keytype_exist:oT \l_xtemplate_keytype_tl { \seq_map_function:NN \c_xtemplate_keytypes_arg_seq \xtemplate_parse_keys_elt_aux:n - \bool_if:NF \l_xtemplate_error_bool - { - \seq_if_in:NoTF \l_xtemplate_key_order_seq - \l_xtemplate_key_name_tl + \bool_if:NF \l_xtemplate_error_bool + { + \seq_if_in:NoTF \l_xtemplate_key_order_seq + \l_xtemplate_key_name_tl { - \msg_error:nnx { xtemplate } - { duplicate-key-interface } + \msg_error:nnx { xtemplate } + { duplicate-key-interface } { \l_xtemplate_key_name_tl } } { \xtemplate_parse_keys_elt_aux: } } } } - } + } \cs_new_protected_nopar:Npn \xtemplate_parse_keys_elt_aux:n #1 { \str_if_eq:onT \l_xtemplate_keytype_tl {#1} { \tl_if_empty:NT \l_xtemplate_keytype_arg_tl { - \msg_error:nnx { xtemplate } + \msg_error:nnx { xtemplate } { keytype-requires-argument } {#1} \bool_set_true:N \l_xtemplate_error_bool - \seq_map_break: + \seq_map_break: } } } \cs_new_nopar:Npn \xtemplate_parse_keys_elt_aux: - { + { \tl_set:Nx \l_xtemplate_tmp_tl { \l_xtemplate_keytype_tl @@ -1216,7 +1214,7 @@ } \prop_put:Noo \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl \l_xtemplate_tmp_tl - \seq_put_right:No \l_xtemplate_key_order_seq \l_xtemplate_key_name_tl + \seq_put_right:No \l_xtemplate_key_order_seq \l_xtemplate_key_name_tl \str_if_eq:onT \l_xtemplate_keytype_tl { choice } { \clist_if_in:NnT \l_xtemplate_keytype_arg_tl { unknown } @@ -1272,7 +1270,7 @@ \msg_error:nnx { xtemplate } { missing-keytype } {#1} } } - \cs_new_protected:Npn \xtemplate_split_keytype_aux:w #1 @ #2 \q_stop + \cs_new_protected:Npn \xtemplate_split_keytype_aux:w #1 @ #2 \q_stop { \tl_put_right:Nx \l_xtemplate_key_name_tl { \tl_to_str:n {#1} } \tl_if_in:nnTF {#2} { @ } @@ -1299,7 +1297,7 @@ % a check is made instead for each possible text value for the keytype. % To keep things faster, this only involves the keytypes that need an % argument. If a match is made, then a check is also needed to see that -% it is at the start of the keytype information. All being well, the +% it is at the start of the keytype information. All being well, the % split can then be applied. Any non-matching keytypes are assumed to % be \enquote{correct} as given, and are left alone (this is checked by % other code). @@ -1312,7 +1310,7 @@ { \tl_if_in:nnT {#1} {##1} { - \cs_set:Npn \xtemplate_split_keytype_arg_aux:w + \cs_set:Npn \xtemplate_split_keytype_arg_aux:w ####1 ##1 ####2 \q_stop { \tl_if_empty:nT {####1} @@ -1323,7 +1321,7 @@ } } \xtemplate_split_keytype_arg_aux:w #1 \q_stop - } + } } \seq_map_function:NN \c_xtemplate_keytypes_arg_seq \xtemplate_split_keytype_arg_aux:n @@ -1346,7 +1344,7 @@ % used, and so there has to be some intermediate storage. Furthermore, % the ability to delay evaluation of results is needed. To achieve these % aims, a series of \enquote{process and store} functions are defined here. -% +% % All of the information about the key (the key name and the keytype) % is already stored as variables. The same property list is always used % to store the data, meaning that the only argument required is the @@ -1356,7 +1354,7 @@ % Storing Boolean values requires a test for delayed evaluation, but % is different to the various numerical variable types as there are % only two possible values to store. So the code here tests the default -% switch and then records the meaning (either \texttt{true} or +% switch and then records the meaning (either \texttt{true} or % \texttt{false}). % \begin{macrocode} \cs_new_protected:Npn \xtemplate_store_value_boolean:n #1 @@ -1469,14 +1467,14 @@ % \end{macro} % \end{macro} % \end{macro} -% +% % \subsection{Implementation part of template declaration} % % \begin{macro}{\xtemplate_declare_template_code:nnnnn} % The main function for implementing a template starts with a couple of % simple checks to make sure that there are no obvious mistakes: the % number of arguments must agree and the template keys must have been -% declared. +% declared. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_declare_template_code:nnnnn #1#2#3#4#5 { @@ -1484,10 +1482,10 @@ { \xtemplate_execute_if_arg_agree:nnT {#1}{#3} { - \xtemplate_if_keys_exist:nnT {#1} {#2} + \xtemplate_if_keys_exist:nnT {#1} {#2} { \xtemplate_store_key_implementation:nnn {#1} {#2} {#4} - \cs_generate_from_arg_count:cNnn + \cs_generate_from_arg_count:cNnn { \c_xtemplate_code_root_tl #1 / #2 } \cs_gset_protected:Npn {#3} {#5} } @@ -1499,10 +1497,10 @@ % % \begin{macro}{\xtemplate_store_key_implementation:nnn} % Actually storing the implementation part of a template is quite easy -% as it only requires the list of keys given to be turned into a +% as it only requires the list of keys given to be turned into a % property list. There is also some error-checking to do, hence the need -% to have the list of defined keytypes available. In certain cases -% (when choices are involved) parsing the key results in changes to the +% to have the list of defined keytypes available. In certain cases +% (when choices are involved) parsing the key results in changes to the % default values. That is why they are loaded and then saved again. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_store_key_implementation:nnn #1#2#3 @@ -1559,34 +1557,34 @@ % \begin{macro}[aux]{\xtemplate_parse_vars_elt_aux:n} % \begin{macro}[aux]{\xtemplate_parse_vars_elt_aux:w} % There now needs to be some sanity checking on the variable name -% given. This does not apply for \texttt{choice} or +% given. This does not apply for \texttt{choice} or % \texttt{code} \enquote{variables}, but in all other cases the variable -% needs to exist. Also, the only prefix acceptable is \texttt{global}. So +% needs to exist. Also, the only prefix acceptable is \texttt{global}. So % there are a few related checks to make. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_parse_vars_elt_aux:n #1 { - \str_if_eq:onTF \l_xtemplate_keytype_tl { choice } + \str_if_eq:onTF \l_xtemplate_keytype_tl { choice } { \xtemplate_implement_choices:n {#1} } { - \str_if_eq:onTF \l_xtemplate_keytype_tl { code } + \str_if_eq:onTF \l_xtemplate_keytype_tl { code } { - \prop_put:Non \l_xtemplate_vars_prop + \prop_put:Non \l_xtemplate_vars_prop \l_xtemplate_key_name_tl {#1} } { \tl_if_single:nTF {#1} { - \cs_if_exist:NF #1 + \cs_if_exist:NF #1 { \xtemplate_create_variable:N #1 } \prop_put:Non \l_xtemplate_vars_prop \l_xtemplate_key_name_tl {#1} } { - \tl_if_in:nnTF {#1} { global } + \tl_if_in:nnTF {#1} { global } { \xtemplate_parse_vars_elt_aux:w #1 \q_stop } { - \msg_error:nnx { xtemplate } { bad-variable } + \msg_error:nnx { xtemplate } { bad-variable } { \tl_to_str:n {#1} } } } @@ -1595,29 +1593,29 @@ } \cs_new_protected:Npn \xtemplate_parse_vars_elt_aux:w #1 global #2 \q_stop { - \tl_if_empty:nTF {#1} + \tl_if_empty:nTF {#1} { \tl_if_single:nTF {#2} { \cs_if_exist:NF #2 { \xtemplate_create_variable:N #2 } - \prop_put:Non \l_xtemplate_vars_prop + \prop_put:Non \l_xtemplate_vars_prop \l_xtemplate_key_name_tl { #1 global #2 } } { - \msg_error:nnx { xtemplate } { bad-variable } + \msg_error:nnx { xtemplate } { bad-variable } { \tl_to_str:n { #1 global #2 } } } } { - \msg_error:nnx { xtemplate } { bad-variable } + \msg_error:nnx { xtemplate } { bad-variable } { \tl_to_str:n { #1 global #2 } } } } % \end{macrocode} % \end{macro} % \end{macro} -% +% % \begin{macro}{\xtemplate_create_variable:N} % A shortcut to create non-declared variables. Some types need a name % mapping, others can be used directly. @@ -1661,7 +1659,7 @@ \msg_error:nnx { xtemplate } { choice-not-implemented } {##1} } - } + } } % \end{macrocode} % A sanity check for the default value, so that an error is raised @@ -1682,11 +1680,11 @@ \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl \prop_get:NoN \l_xtemplate_values_prop \l_xtemplate_key_name_tl \l_xtemplate_tmp_tl - \msg_error:nnxxx { xtemplate } { unknown-default-choice } + \msg_error:nnxxx { xtemplate } { unknown-default-choice } { \l_xtemplate_key_name_tl } { \l_xtemplate_key_name_tl } { \l_xtemplate_keytype_arg_tl } - } - } + } + } } % \end{macrocode} % \end{macro} @@ -1696,7 +1694,7 @@ % \begin{macro}{\xtemplate_implement_choice_elt:nn} % The actual storage of the implementation of a choice is mainly about % error checking. The code here ensures that all choices have to have -% been declared, apart from the special \texttt{unknown} choice, which +% been declared, apart from the special \texttt{unknown} choice, which % must come last. The code for each choice is stored along with the % key name in the variables property list. % \begin{macrocode} @@ -1721,7 +1719,7 @@ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl \l_xtemplate_tmp_tl \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl - \msg_error:nnxxx { xtemplate } { unknown-choice } + \msg_error:nnxxx { xtemplate } { unknown-choice } { \l_xtemplate_key_name_tl } {#1} { \l_xtemplate_keytype_arg_tl } } @@ -1730,7 +1728,7 @@ \cs_new_protected:Npn \xtemplate_implement_choice_elt:nn #1#2 { \xtemplate_implement_choice_elt:n {#1} - \tl_set:Nx \l_xtemplate_tmp_tl + \tl_set:Nx \l_xtemplate_tmp_tl { \l_xtemplate_key_name_tl \c_space_tl #1 } \prop_put:Non \l_xtemplate_vars_prop \l_xtemplate_tmp_tl {#2} } @@ -1742,16 +1740,16 @@ % % Template defaults can be edited either with no other changes or % to prevent further editing, forming a \enquote{restricted template}. -% In the later case, a new template results, whereas simple editing +% In the later case, a new template results, whereas simple editing % does not produce a new template name. -% +% % \begin{macro}{\xtemplate_declare_restricted:nnnn} % Creating a restricted template means copying the old template to the % new one first. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_declare_restricted:nnnn #1#2#3#4 { - \xtemplate_if_keys_exist:nnT {#1} {#2} + \xtemplate_if_keys_exist:nnT {#1} {#2} { \xtemplate_set_template_eq:nn { #1 / #3 } { #1 / #2 } \bool_set_true:N \l_xtemplate_restrict_bool @@ -1771,11 +1769,11 @@ \cs_new_protected:Npn \xtemplate_edit_defaults:nnn { \bool_set_false:N \l_xtemplate_restrict_bool - \xtemplate_edit_defaults_aux:nnn + \xtemplate_edit_defaults_aux:nnn } \cs_new_protected:Npn \xtemplate_edit_defaults_aux:nnn #1#2#3 { - \xtemplate_if_keys_exist:nnT {#1} {#2} + \xtemplate_if_keys_exist:nnT {#1} {#2} { \xtemplate_recover_defaults:n { #1 / #2 } \xtemplate_recover_restrictions:n { #1 / #2 } @@ -1789,7 +1787,7 @@ % \end{macro} % % \begin{macro}{\xtemplate_parse_values:nn} -% The routine to parse values is the same for both editing a +% The routine to parse values is the same for both editing a % template and setting up an instance. So the code here does only the % minimum necessary for reading the values. % \begin{macrocode} @@ -1818,7 +1816,7 @@ % \begin{macro}[aux]{\xtemplate_parse_values_elt_aux:n} % To store the value, find the keytype then call the saving function. % These need the current key name saved as \cs{l_xtemplate_key_name_tl}. -% When a template is being restricted, the setting code will be +% When a template is being restricted, the setting code will be % skipped for restricted keys. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_parse_values_elt:nn #1#2 @@ -1830,14 +1828,14 @@ { \bool_if:NTF \l_xtemplate_restrict_bool { - \clist_if_in:NoF \l_xtemplate_restrict_clist + \clist_if_in:NoF \l_xtemplate_restrict_clist \l_xtemplate_key_name_tl { \xtemplate_parse_values_elt_aux:n {#2} } } { \xtemplate_parse_values_elt_aux:n {#2} } } { - \msg_error:nnx { xtemplate } { unknown-key } + \msg_error:nnx { xtemplate } { unknown-key } { \l_xtemplate_key_name_tl } } } @@ -1863,9 +1861,9 @@ \xtemplate_recover_keytypes:n {#2} \xtemplate_store_keytypes:n {#1} \xtemplate_recover_vars:n {#2} - \xtemplate_store_vars:n {#1} + \xtemplate_store_vars:n {#1} \cs_gset_eq:cc { \c_xtemplate_code_root_tl #1 } - { \c_xtemplate_code_root_tl #2 } + { \c_xtemplate_code_root_tl #2 } } % \end{macrocode} % \end{macro} @@ -1884,7 +1882,7 @@ % \begin{macrocode} \cs_new_protected:Npn \xtemplate_declare_instance:nnnnn #1#2#3#4#5 { - \xtemplate_execute_if_code_exist:nnT {#1} {#2} + \xtemplate_execute_if_code_exist:nnT {#1} {#2} { \xtemplate_recover_defaults:n { #1 / #2 } \xtemplate_recover_vars:n { #1 / #2 } @@ -1927,23 +1925,23 @@ % \begin{macrocode} \cs_new_protected:Npn \xtemplate_edit_instance:nnnn #1#2#3 { - \xtemplate_if_instance_exist:nnnTF {#1} {#2} {#3} + \xtemplate_if_instance_exist:nnnTF {#1} {#2} {#3} { \xtemplate_recover_values:n { #1 / #2 / #3 } \prop_get:NnN \l_xtemplate_values_prop { from~template } \l_xtemplate_tmp_tl - \xtemplate_edit_instance_aux:nonnn {#1} \l_xtemplate_tmp_tl + \xtemplate_edit_instance_aux:nonnn {#1} \l_xtemplate_tmp_tl {#2} {#3} } - { - \msg_error:nnxx { xtemplate } { unknown-instance } + { + \msg_error:nnxx { xtemplate } { unknown-instance } {#1} {#3} } } \cs_new_protected:Npn \xtemplate_edit_instance_aux:nnnnn #1#2 { \xtemplate_recover_vars:n { #1 / #2 } - \xtemplate_declare_instance_aux:nnnnn {#1} {#2} + \xtemplate_declare_instance_aux:nnnnn {#1} {#2} } \cs_generate_variant:Nn \xtemplate_edit_instance_aux:nnnnn { no } % \end{macrocode} @@ -1964,7 +1962,7 @@ { \tl_clear:N \l_xtemplate_assignments_tl \seq_map_function:NN \l_xtemplate_key_order_seq - \xtemplate_convert_to_assignments_aux:n + \xtemplate_convert_to_assignments_aux:n } \cs_new_protected:Npn \xtemplate_convert_to_assignments_aux:n #1 { @@ -1973,10 +1971,10 @@ } % \end{macrocode} % The second auxiliary function actually does the work. The -% arguments here are the key name (|#1|) and the keytype (|#2|). +% arguments here are the key name (|#1|) and the keytype (|#2|). % From those, the value to assign and the name of the appropriate % variable are recovered. A bit of work is then needed to sort out -% keytypes with arguments (for example instances), and to look for +% keytypes with arguments (for example instances), and to look for % global assignments. Once that is done, a hand-off can be made to the % handler for the relevant keytype. % \begin{macrocode} @@ -1992,7 +1990,7 @@ \str_if_eq:onF \l_xtemplate_keytype_tl { code } { \xtemplate_find_global: } } - \tl_set:Nn \l_xtemplate_key_name_tl {#1} + \tl_set:Nn \l_xtemplate_key_name_tl {#1} \use:c { xtemplate_assign_ \l_xtemplate_keytype_tl : } } { \msg_error:nnx { xtemplate } { unknown-attribute } {#1} } @@ -2007,7 +2005,7 @@ % % \begin{macro}{\xtemplate_find_global:} % \begin{macro}[aux]{\xtemplate_find_global_aux:w} -% Global assignments should have the phrase |global| at the front. +% Global assignments should have the phrase |global| at the front. % This is pretty easy to find: no other error checking, though. % \begin{macrocode} \cs_new_protected_nopar:Npn \xtemplate_find_global: @@ -2032,12 +2030,12 @@ % \begin{macro}{\xtemplate_use_template:nnn} % Directly use a template with a particular parameter setting. % This is also picked up if used in a nested fashion inside a parameter -% list. The idea is essentially the same as creating an instance, +% list. The idea is essentially the same as creating an instance, % just with no saving of the result. % \begin{macrocode} \cs_new_protected:Npn \xtemplate_use_template:nnn #1#2#3 { - \xtemplate_execute_if_code_exist:nnT {#1} {#2} + \xtemplate_execute_if_code_exist:nnT {#1} {#2} { \xtemplate_recover_defaults:n { #1 / #2 } \xtemplate_recover_vars:n { #1 / #2 } @@ -2053,9 +2051,9 @@ % % \begin{macro}{\xtemplate_assign_boolean:} % \begin{macro}[aux]{\xtemplate_assign_boolean_aux:n} -% Setting a Boolean value is slightly different to everything else +% Setting a Boolean value is slightly different to everything else % as the value can be used to work out which \texttt{set} function to -% call. As long as there is no need to recover things from another +% call. As long as there is no need to recover things from another % variable, everything is pretty easy. % \begin{macrocode} \cs_new_protected_nopar:Npn \xtemplate_assign_boolean: @@ -2095,8 +2093,8 @@ \prop_get:NoN \l_xtemplate_keytypes_prop \l_xtemplate_key_name_tl \l_xtemplate_tmp_tl \xtemplate_split_keytype_arg:o \l_xtemplate_tmp_tl - \msg_error:nnxxx { xtemplate } { unknown-choice } - { \l_xtemplate_key_name_tl } { \l_xtemplate_value_tl } + \msg_error:nnxxx { xtemplate } { unknown-choice } + { \l_xtemplate_key_name_tl } { \l_xtemplate_value_tl } { \l_xtemplate_keytype_arg_tl } } } @@ -2124,7 +2122,7 @@ { \tl_put_left:Nx \l_xtemplate_assignments_tl { - \cs_set_protected:Npn \xtemplate_assign_code:n \exp_not:n {##1} + \cs_set_protected:Npn \xtemplate_assign_code:n \exp_not:n {##1} { \exp_not:o \l_xtemplate_var_tl } \xtemplate_assign_code:n { \exp_not:o \l_xtemplate_value_tl } } @@ -2162,7 +2160,7 @@ % \begin{macro}{\xtemplate_assign_instance:} % \begin{macro}[aux]{\xtemplate_assign_instance_aux:N} % Using an instance means adding the appropriate function creation to -% the tl. No checks are made at this stage, so if the instance is +% the tl. No checks are made at this stage, so if the instance is % not valid then errors will arise later. % \begin{macrocode} \cs_new_protected_nopar:Npn \xtemplate_assign_instance: @@ -2231,7 +2229,7 @@ % \end{macro} % \end{macro} % \end{macro} -% +% % \begin{macro}{\xtemplate_assign_tokenlist:} % \begin{macro}[aux]{\xtemplate_assign_tokenlist_aux:N} % Storing lists of tokens is easy: no complex calculations and no @@ -2249,7 +2247,7 @@ { \xtemplate_key_to_value: } \tl_put_left:Nx \l_xtemplate_assignments_tl { - #1 \exp_not:o \l_xtemplate_var_tl + #1 \exp_not:o \l_xtemplate_var_tl { \exp_not:o \l_xtemplate_value_tl } } } @@ -2270,7 +2268,7 @@ % \end{macro} % % \begin{macro}{\xtemplate_assign_variable:N} -% A general-purpose function for all of the numerical assignments. +% A general-purpose function for all of the numerical assignments. % As long as the value is not coming from another variable, the stored % value is simply transferred for output. % \begin{macrocode} @@ -2280,7 +2278,7 @@ { \xtemplate_key_to_value: } \tl_put_left:Nx \l_xtemplate_assignments_tl { - #1 \exp_not:o \l_xtemplate_var_tl + #1 \exp_not:o \l_xtemplate_var_tl { \exp_not:o \l_xtemplate_value_tl } } } @@ -2291,7 +2289,7 @@ % \begin{macro}[aux]{\xtemplate_key_to_value_aux:w} % The idea here is to recover the attribute value of another key. To % do that, the marker is removed and a look up takes place. If this -% is successful, then the name of the variable of the attribute is +% is successful, then the name of the variable of the attribute is % returned. This assumes that the value will be used in context where % it will be converted to a value, for example when setting a number. % \begin{macrocode} @@ -2306,7 +2304,7 @@ \l_xtemplate_tmp_tl \l_xtemplate_value_tl { - \msg_error:nnx { xtemplate } { unknown-attribute } + \msg_error:nnx { xtemplate } { unknown-attribute } { \l_xtemplate_tmp_tl } } } @@ -2342,20 +2340,20 @@ \cs_new_protected:Npn \xtemplate_use_instance_aux:nn #1#2 { \xtemplate_get_collection:n {#1} - \xtemplate_if_instance_exist:nnnTF + \xtemplate_if_instance_exist:nnnTF {#1} { \l_xtemplate_collection_tl } {#2} { \use:c - { - \c_xtemplate_instances_root_tl #1 / - \l_xtemplate_collection_tl / #2 + { + \c_xtemplate_instances_root_tl #1 / + \l_xtemplate_collection_tl / #2 } - } + } { \xtemplate_if_instance_exist:nnnTF {#1} { } {#2} { \use:c { \c_xtemplate_instances_root_tl #1 / / #2 } } { - \msg_error:nnxx { xtemplate } { unknown-instance } + \msg_error:nnxx { xtemplate } { unknown-instance } {#1} {#2} } } @@ -2391,7 +2389,7 @@ % % A few functions to transfer assignments about, as this is needed by % \cs{AssignTemplateKeys}. -% +% % \begin{macro}{\xtemplate_assignments_pop:} % To actually use the assignments. % \begin{macrocode} @@ -2689,24 +2687,21 @@ \msg_line_context:. } \msg_new:nnn { xtemplate } { show-no-attribute } - { Template~'#2'~of~object~type~'#1'~has~no~#3 . } + { The~template~'#2'~of~object~type~'#1'~has~no~#3 . } \msg_new:nnn { xtemplate } { show-attribute } - { Template~'#2'~of~object~type~'#1'~has~#3 : } + { The~template~'#2'~of~object~type~'#1'~has~#3 : } \msg_new:nnn { xtemplate } { show-no-values } { - \tl_if_empty:nTF {#2} - { Instance~'#3'~ } - { Collection instance~'#3'~(from~collection~'#2')~ } + The~ \tl_if_empty:nF {#2} {collection~} instance~'#3'~ + \tl_if_empty:nF {#2} { (from~collection~'#2')~ } of~object~type~'#1'~has~no~values. } \msg_new:nnn { xtemplate } { show-values } { - \tl_if_empty:nTF {#2} - { Instance~'#3'~ } - { Collection instance~'#3'~(from~collection~'#2')~ } - of~object~type~'#1' - \quark_if_no_value:NF #4 - { ~(from~template~'#4')~ } + The~ \tl_if_empty:nF {#2} {collection~} instance~'#3'~ + \tl_if_empty:nF {#2} { (from~collection~'#2')~ } + of~object~type~'#1'~ + \quark_if_no_value:NF #4 { (from~template~'#4')~ } has~values: } % \end{macrocode} @@ -2828,11 +2823,11 @@ { \xtemplate_assignments_pop: } % \end{macrocode} % \end{macro} -% +% % \begin{macrocode} \cs_new_eq:NN \ShowTemplateKeytypes \ShowTemplateInterface % \end{macrocode} -% +% % \begin{macrocode} %</package> % \end{macrocode} |