Skip to content

Commit

Permalink
Copying xparse (robust) commands
Browse files Browse the repository at this point in the history
part of #795
  • Loading branch information
PhelypeOleinik committed Jan 14, 2021
1 parent a796b73 commit 3e2a7ad
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions l3packages/xparse/xparse.dtx
Expand Up @@ -1266,6 +1266,13 @@
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\s_@@}
% Scratch space.
% \begin{macrocode}
\scan_new:N \s_@@
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\l_@@_tmp_prop, \l_@@_tmpa_tl, \l_@@_tmpb_tl}
% \begin{macro}{\@@_tmp:w}
% Scratch space.
Expand Down Expand Up @@ -4300,6 +4307,39 @@
% \end{macrocode}
% \end{macro}
%
% At this point we know that the command has the right shape, so we can
% just do the copying.
%
% \subsubsection{Robust commands}
%
% \begin{macro}{\@@_robust_cmd_set_eq:NN}
% Copying a robust command is rather easy. The tricky part is to
% define the top-level expansion of the command, because it needs to
% cope with possibly expandable defaults to optional arguments (that
% must not be expanded at this point) and with optional arguments
% whose default is another argument, so parameter tokens may be
% involved. Copying the actual code of the command is just a matter
% of copying \cs[no-index]{\meta{name} code}.
% \begin{macrocode}
\cs_new_protected:Npn \@@_robust_cmd_set_eq:NN #1 #2
{
\tl_set:Nx \l_@@_tmpa_tl { \cs_to_str:N #1 ~ }
\tl_set:Nx \l_@@_tmpb_tl { \cs_to_str:N #2 ~ }
\cs_set:Npn \@@_tmp:w ##1
{ ####1 \exp_not:c {##1} \exp_not:c { ##1 code } ####2 }
\use:e
{
\cs_set:Npx \exp_not:N \@@_tmp:w
\@@_tmp:w \l_@@_tmpb_tl \s_@@
{ \@@_tmp:w \l_@@_tmpa_tl }
}
\cs_set_protected_nopar:Npx #1
{ \exp_args:No \exp_not:o { \exp_after:wN \@@_tmp:w #2 \s_@@ } }
\cs_set_eq:cc { \l_@@_tmpa_tl code } { \l_@@_tmpb_tl code }
}
% \end{macrocode}
% \end{macro}
%
% \subsection{Argument processors}
%
% \begin{macro}{\@@_bool_reverse:N}
Expand Down

0 comments on commit 3e2a7ad

Please sign in to comment.