diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/expl3/l3tlp.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/expl3/l3tlp.dtx | 255 |
1 files changed, 185 insertions, 70 deletions
diff --git a/Master/texmf-dist/source/latex/expl3/l3tlp.dtx b/Master/texmf-dist/source/latex/expl3/l3tlp.dtx index 9cf83e3912b..8cf7b54eb5f 100644 --- a/Master/texmf-dist/source/latex/expl3/l3tlp.dtx +++ b/Master/texmf-dist/source/latex/expl3/l3tlp.dtx @@ -1,5 +1,5 @@ % \iffalse -%% File: l3tlp.dtx Copyright (C) 1990-2006 LaTeX3 project +%% File: l3tlp.dtx Copyright (C) 1990-2007 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 @@ -32,25 +32,21 @@ %% %% ----------------------------------------------------------------------- % -%<package>\RequirePackage{l3names} -%<*dtx> +%<*driver|package> +\RequirePackage{l3names} +%</driver|package> %\fi -\def\GetIdInfo$Id: #1.dtx #2 #3-#4-#5 #6 #7$#8{% - \def\fileversion{#2}% - \def\filedate{#3/#4/#5}% - \ProvidesFile{#1.dtx}[#3/#4/#5 v#2 #8]% -} -%\iffalse -%</dtx> -%\fi -\GetIdInfo$Id: l3tlp.dtx 581 2006-12-12 12:28:27Z morten $ +\GetIdInfo$Id: l3tlp.dtx 735 2008-01-14 22:31:02Z morten $ {L3 Experimental Token List Pointers} -% -% \iffalse +%\iffalse %<*driver> +%\fi +\ProvidesFile{\filename.\filenameext} + [\filedate\space v\fileversion\space\filedescription] +%\iffalse \documentclass{l3doc} \begin{document} -\DocInput{l3tlp.dtx} +\DocInput{\filename.\filenameext} \end{document} %</driver> % \fi @@ -83,7 +79,9 @@ % % \subsection{Functions} % -% \begin{function}{\tlp_new:Nn | +% \begin{function}{\tlp_new:N | +% \tlp_new:c | +% \tlp_new:Nn | % \tlp_new:cn | % \tlp_new:Nx } % \begin{syntax} @@ -92,6 +90,8 @@ % Defines <tlp> to be a new variable (or constant) of type token list % pointer. <initial token list> is the initial value of <tlp>. This % makes it possible to assign values to a constant token list pointer. +% +% The form "\tlp_new:N" initializes the token list pointer with an empty value. % \end{function} % % \begin{function}{% @@ -101,18 +101,23 @@ % \begin{syntax} % "\tlp_use:N" <tlp> % \end{syntax} -% Function that inserts the <tlp> into the processing stream. +% Function that inserts the <tlp> into the processing stream. Instead of +% |\tlp_use:N| simply placing the <tlp> into the input stream is also +% supported.|\tlp_use:c| will complain is the <tlp> hasn't been declared +% previously! % \end{function} % % \begin{function}{% % \tlp_set:Nn | % \tlp_set:Nc | % \tlp_set:No | +% \tlp_set:Nd | % \tlp_set:Nf | % \tlp_set:Nx | % \tlp_gset:Nn | % \tlp_gset:Nc | % \tlp_gset:No | +% \tlp_gset:Nd | % \tlp_gset:Nx | % \tlp_gset:cn | % \tlp_gset:cx } @@ -156,13 +161,17 @@ % \begin{function}{% % \tlp_put_left:Nn | % \tlp_put_left:No | +% \tlp_put_left:Nx | % \tlp_gput_left:Nn | % \tlp_gput_left:No | % \tlp_gput_left:Nx | % \tlp_put_right:Nn | +% \tlp_put_right:No | +% \tlp_put_right:Nx | % \tlp_put_right:cc | % \tlp_gput_right:Nn | % \tlp_gput_right:No| +% \tlp_gput_right:Nx| % \tlp_gput_right:cn| % \tlp_gput_right:co| % } @@ -174,6 +183,21 @@ % list> might be subject to expansion before assignment. % \end{function} % +% A word of warning is appropriate here: Token list pointers are +% implemented as macros and as such currently inherit some of the +% peculiarities of how \TeX\ handles "#"s in the argument of +% macros. In particular, the following actions are legal +% \begin{verbatim} +% \tlp_set:Nn \l_tmpa_tlp{##1} +% \tlp_put_right:Nn \l_tmpa_tlp{##2} +% \tlp_set:No \l_tmpb_tlp{\l_tmpa_tlp ##3} +% \end{verbatim} +% |x| type expansions where macros being expanded contain |#|s do not +% work and will not work until there is an |\expanded| primitive in +% the engine. If you want them to work you must double |#|s another +% level. +% +% % \begin{function}{% % \tlp_set_eq:NN | % \tlp_set_eq:Nc | @@ -487,9 +511,6 @@ % support arbitrary string comparison. % \end{variable} % -% \begin{function}{\tlp_put_left_aux:w} -% Used by "\tlp_put_left:Nn" and its variants. -% \end{function} % % \begin{function}{\tlp_to_str_aux:w} % Function used to implement "\tlp_to_str:N". @@ -656,6 +677,8 @@ % % We start by ensuring that the required packages are loaded. % \begin{macrocode} +%<package>\ProvidesExplPackage +%<package> {\filename}{\filedate}{\fileversion}{\filedescription} %<package&!check>\RequirePackage{l3basics} %<package&check>\RequirePackage{l3chk} % \end{macrocode} @@ -670,6 +693,8 @@ % % % +% \begin{macro}{\tlp_new:N} +% \begin{macro}{\tlp_new:c} % \begin{macro}{\tlp_new:Nn} % \begin{macro}{\tlp_new:cn} % \begin{macro}{\tlp_new:Nx} @@ -698,10 +723,14 @@ %<check> \chk_var_or_const:N #1 \gdef:Npx #1{#2} } +\def_new:Npn \tlp_new:N #1{\tlp_new:Nn #1{}} +\def_new:Npn \tlp_new:c #1{\tlp_new:cn {#1}{}} % \end{macrocode} % \end{macro} % \end{macro} % \end{macro} +% \end{macro} +% \end{macro} % % % \begin{macro}{\tlp_use:N} @@ -728,6 +757,7 @@ % % \begin{macro}{\tlp_set:Nn} % \begin{macro}{\tlp_set:No} +% \begin{macro}{\tlp_set:Nd} % \begin{macro}{\tlp_set:Nf} % \begin{macro}{\tlp_set:Nx} % \begin{macro}{\tlp_set:cn} @@ -735,6 +765,7 @@ % \begin{macro}{\tlp_set:cx} % \begin{macro}{\tlp_gset:Nn} % \begin{macro}{\tlp_gset:No} +% \begin{macro}{\tlp_gset:Nd} % \begin{macro}{\tlp_gset:Nx} % \begin{macro}{\tlp_gset:cn} % \begin{macro}{\tlp_gset:cx} @@ -789,11 +820,13 @@ % expansion module. % \begin{macrocode} \def_new:Npn \tlp_set:No {\exp_args:NNo \tlp_set:Nn} +\def_new:Npn \tlp_set:Nd {\exp_args:NNd \tlp_set:Nn} \def_new:Npn \tlp_set:Nf {\exp_args:NNf \tlp_set:Nn} \def_new:Npn \tlp_set:cn {\exp_args:Nc \tlp_set:Nn} \def_new:Npn \tlp_set:co {\exp_args:Nco \tlp_set:Nn} \def_new:Npn \tlp_set:cx {\exp_args:Nc \tlp_set:Nx} \def_new:Npn \tlp_gset:No {\exp_args:NNo \tlp_gset:Nn} +\def_new:Npn \tlp_gset:Nd {\exp_args:NNd \tlp_gset:Nn} \def_new:Npn \tlp_gset:cn {\exp_args:Nc \tlp_gset:Nn} \def_new:Npn \tlp_gset:cx {\exp_args:Nc \tlp_gset:Nx} % \end{macrocode} @@ -809,6 +842,8 @@ % \end{macro} % \end{macro} % \end{macro} +% \end{macro} +% \end{macro} % % \begin{macro}{\tlp_set_eq:NN} % \begin{macro}{\tlp_set_eq:Nc} @@ -916,37 +951,62 @@ % % \begin{macro}{\tlp_put_left:Nn} % \begin{macro}{\tlp_put_left:No} +% \begin{macro}{\tlp_put_left:Nx} % \begin{macro}{\tlp_gput_left:Nn} % \begin{macro}{\tlp_gput_left:No} % \begin{macro}{\tlp_gput_left:Nx} -% \begin{macro}{\tlp_put_left_aux:w} -% We can add tokens to the left (either globally or locally). -% \begin{macrocode} -\def_new:Npn \tlp_put_left:Nn #1{ -% \end{macrocode} -% We need expanding over a brace to ensure that if |#1| contains -% just one token within braces the braces are preserved. -% \begin{macrocode} - \exp_args:No \tlp_put_left_aux:w {#1}#1} -\def_new:Npn\tlp_put_left:No{\exp_args:NNo\tlp_put_left:Nn} -\def_new:Npn \tlp_gput_left:Nn { -%<*check> - \pref_global_chk: -%</check> -%<-check> \pref_global:D - \tlp_put_left:Nn +% We can add tokens to the left (either globally or locally). It is +% not quite as easy as we would like because we have to ensure the +% assignments +% \begin{verbatim} +% \tlp_set:Nn \l_tmpa_tlp{##1abc##2def} +% \tlp_set:Nn \l_tmpb_tlp{##1abc} +% \tlp_put_right:Nn \l_tmpb_tlp {##2def} +% \end{verbatim} +% cause |\l_tmpa_tlp| and |\l_tmpb_tlp| to be identical. The old +% code did not succeed in doing this (it gave an error) and so we +% use a different technique where the item(s) to be added are first +% stored in a temporary pointer and then added using an |x| type +% expansion combined with the appropriate level of +% non-expansion. Putting the tokens directly into one assignment +% does not work unless we want full expansion. Note (according to +% the warning earlier) \TeX\ does not allow us to treat |#|s the +% same in all cases. Tough. +% \begin{macrocode} +\def_long_new:Npn \tlp_put_left:Nn #1#2{ + \tlp_set:Nn \l_exp_tlp{#2} + \tlp_set:Nx #1{\exp_not:o{\l_exp_tlp}\exp_not:o{#1}} +%<check> \chk_local_or_pref_global:N #1 } -\def_new:Npn\tlp_gput_left:No{\exp_args:NNo\tlp_gput_left:Nn} -\def_new:Npn\tlp_gput_left:Nx{\exp_args:NNx\tlp_gput_left:Nn} -\def_long_new:Npn \tlp_put_left_aux:w #1#2#3{\tlp_set:Nn #2{#3#1} -% \end{macrocode} -% We check the type afterwards to avoid conflicts with the use of -% |\pref_global:D|. -% \begin{macrocode} -%<*check> - \chk_local_or_pref_global:N #2 -%</check> +\def_long_new:Npn \tlp_put_left:No #1#2{ + \tlp_set:Nn \l_exp_tlp{#2} + \tlp_set:Nx #1{\exp_not:d{\l_exp_tlp}\exp_not:o{#1}} +%<check> \chk_local_or_pref_global:N #1 +} +\def_long_new:Npn \tlp_put_left:Nx #1#2{ + \tlp_set:Nx #1{#2\exp_not:o{#1}} +%<check> \chk_local_or_pref_global:N #1 +} +\def_long_new:Npn \tlp_gput_left:Nn #1#2{ + \tlp_set:Nn \l_exp_tlp{#2} + \tlp_gset:Nx #1{\exp_not:o{\l_exp_tlp}\exp_not:o{#1}} +%<check> \chk_local_or_pref_global:N #1 +} +\def_long_new:Npn \tlp_gput_left:No #1#2{ + \tlp_set:Nn \l_exp_tlp{#2} + \tlp_gset:Nx #1{\exp_not:d{\l_exp_tlp}\exp_not:o{#1}} +%<check> \chk_local_or_pref_global:N #1 +} +\def_long_new:Npn \tlp_gput_left:Nx #1#2{ + \tlp_gset:Nx #1{#2\exp_not:o{#1}} +%<check> \chk_local_or_pref_global:N #1 } +\def_long_new:Npn \tlp_put_left:cn{\exp_args:Nc\tlp_put_left:Nn} +\def_long_new:Npn \tlp_put_left:co{\exp_args:Nc\tlp_put_left:No} +\def_long_new:Npn \tlp_put_left:cx{\exp_args:Nc\tlp_put_left:Nx} +\def_long_new:Npn \tlp_gput_left:cn{\exp_args:Nc\tlp_gput_left:Nn} +\def_long_new:Npn \tlp_gput_left:co{\exp_args:Nc\tlp_gput_left:No} +\def_long_new:Npn \tlp_gput_left:cx{\exp_args:Nc\tlp_gput_left:Nx} % \end{macrocode} % \end{macro} % \end{macro} @@ -967,15 +1027,37 @@ % These are variants of the functions above, but for adding tokens % to the right. % \begin{macrocode} -\def_long_new:Npn \tlp_put_right:Nn #1#2{\tlp_set:No #1{#1#2}} -\def_long_new:Npn \tlp_gput_right:Nn #1#2{\tlp_gset:No #1{#1#2}} -\def_new:Npn \tlp_gput_right:No {\exp_args:NNo \tlp_gput_right:Nn} -\def_new:Npn \tlp_gput_right:Nx {\exp_args:NNx \tlp_gput_right:Nn} +\def_long_new:Npn \tlp_put_right:Nn #1#2{ + \tlp_set:Nn \l_exp_tlp{#2} + \tlp_set:Nx #1{\exp_not:o{#1}\exp_not:o{\l_exp_tlp}} +%<check> \chk_local_or_pref_global:N #1 +} +\def_long_new:Npn \tlp_gput_right:Nn #1#2{ + \tlp_set:Nn \l_exp_tlp{#2} + \tlp_gset:Nx #1{\exp_not:o{#1}\exp_not:o{\l_exp_tlp}} +%<check> \chk_local_or_pref_global:N #1 +} +\def_long_new:Npn \tlp_put_right:No #1#2{ + \tlp_set:Nn \l_exp_tlp{#2} + \tlp_set:Nx #1{\exp_not:o{#1}\exp_not:d{\l_exp_tlp}} +%<check> \chk_local_or_pref_global:N #1 +} +\def_long_new:Npn \tlp_gput_right:No #1#2{ + \tlp_set:Nn \l_exp_tlp{#2} + \tlp_gset:Nx #1{\exp_not:o{#1}\exp_not:d{\l_exp_tlp}} +%<check> \chk_local_or_pref_global:N #1 +} +\def_long:Npn \tlp_put_right:Nx #1#2{ + \tlp_set:Nx #1{\exp_not:o{#1}#2} +%<check> \chk_local_or_pref_global:N #1 +} +\def_long:Npn \tlp_gput_right:Nx #1#2{ + \tlp_gset:Nx #1{\exp_not:o{#1}#2} +%<check> \chk_local_or_pref_global:N #1 +} \def_new:Npn \tlp_gput_right:cn {\exp_args:Nc \tlp_gput_right:Nn} -\def_new:Npn \tlp_gput_right:co {\exp_args:Nco \tlp_gput_right:Nn} +\def_new:Npn \tlp_gput_right:co {\exp_args:Nc \tlp_gput_right:No} \def_new:Npn \tlp_put_right:cc {\exp_args:Ncc \tlp_put_right:Nn} -\def_new:Npn \tlp_put_right:No {\exp_args:NNo \tlp_put_right:Nn} -\def_new:Npn \tlp_put_right:Nx {\exp_args:Nnx \tlp_put_right:Nn} % \end{macrocode} % \end{macro} % \end{macro} @@ -1297,14 +1379,14 @@ % marker will be read immediately and the loop terminated. % \begin{macrocode} \def_long_new:Npn \tlist_map_function:nN #1#2{ - \tlist_map_function_aux:Nn #2 #1 \q_nil \q_stop + \tlist_map_function_aux:Nn #2 #1 \q_recursion_tail \q_recursion_stop } \def_new:Npn \tlp_map_function:NN #1#2{ \exp_after:NN \tlist_map_function_aux:Nn - \exp_after:NN #2 #1 \q_nil \q_stop + \exp_after:NN #2 #1 \q_recursion_tail \q_recursion_stop } \def_long_new:Npn \tlist_map_function_aux:Nn #1#2{ - \quark_if_nil:nT{#2} \tlist_map_break:w + \quark_if_recursion_tail_stop:n{#2} #1{#2} \tlist_map_function_aux:Nn #1 } \def_new:Npn\tlp_map_function:cN{\exp_args:Nc\tlp_map_function:NN} @@ -1332,7 +1414,7 @@ ##1{#2} \exp_args:Nc \tlist_map_function_aux:Nn {tlist_map_inline_ \num_use:N \l_tlp_inline_level_num :n} - #1 \q_nil\q_stop + #1 \q_recursion_tail\q_recursion_stop \num_decr:N \l_tlp_inline_level_num } \def_long_new:Npn \tlp_map_inline:Nn #1#2{ @@ -1341,7 +1423,7 @@ ##1{#2} \exp_args:NcE \tlist_map_function_aux:Nn {tlist_map_inline_ \num_use:N \l_tlp_inline_level_num :n} - #1 \q_nil\q_stop + #1 \q_recursion_tail\q_recursion_stop \num_decr:N \l_tlp_inline_level_num } \def_new:Npn\tlp_map_inline:cN{\exp_args:Nc\tlp_map_inline:NN} @@ -1361,7 +1443,7 @@ % \zz{temp} to each element and executes \zz{action}. % \begin{macrocode} \def_long_new:Npn \tlist_map_variable:nNn #1#2#3{ - \tlist_map_variable_aux:Nnn #2 {#3} #1 \q_nil \q_stop + \tlist_map_variable_aux:Nnn #2 {#3} #1 \q_recursion_tail \q_recursion_stop } \def_new:Npn \tlp_map_variable:NNn {\exp_args:No \tlist_map_variable:nNn} \def_new:Npn \tlp_map_variable:cNn {\exp_args:Nc \tlp_map_variable:NNn} @@ -1377,7 +1459,7 @@ % \begin{macrocode} \def_long_new:Npn \tlist_map_variable_aux:Nnn #1#2#3{ \tlp_set:Nn #1{#3} - \quark_if_nil:NT #1 \tlist_map_break:w + \quark_if_recursion_tail_stop:N #1 #2 \tlist_map_variable_aux:Nnn #1{#2} } % \end{macrocode} @@ -1387,7 +1469,7 @@ % \begin{macro}{\tlp_map_break:w} % The break statement. % \begin{macrocode} -\let_new:NN \tlist_map_break:w \use_none_delimit_by_q_stop:w +\let_new:NN \tlist_map_break:w \use_none_delimit_by_q_recursion_stop:w \let_new:NN \tlp_map_break:w \tlist_map_break:w % \end{macrocode} % \end{macro} @@ -1459,7 +1541,7 @@ % \end{macrocode} % However all of this only makes sense if we actually have that % primitive. Therefore we disable it again if it is not there and -% define \verb|\tlist_if_eq:NN| the old fashioned (and unexpandable) +% define \verb|\tlist_if_eq:nn| the old fashioned (and unexpandable) % way. % \begin{macrocode} \cs_if_really_free:cT{pdf_strcmp:D}{ @@ -1468,12 +1550,46 @@ \tlp_set:Nx \l_testb_tlp {\exp_not:n{#2}} \if_meaning:NN\l_testa_tlp \l_testb_tlp } + \def_long_test_function:npn{tlist_if_eq:no}#1#2{ + \tlp_set:Nx \l_testa_tlp {\exp_not:n{#1}} + \tlp_set:Nx \l_testb_tlp {\exp_not:o{#2}} + \if_meaning:NN\l_testa_tlp \l_testb_tlp + } + \def_long_test_function:npn{tlist_if_eq:nx}#1#2{ + \tlp_set:Nx \l_testa_tlp {\exp_not:n{#1}} + \tlp_set:Nx \l_testb_tlp {#2} + \if_meaning:NN\l_testa_tlp \l_testb_tlp + } + \def_long_test_function:npn{tlist_if_eq:on}#1#2{ + \tlp_set:Nx \l_testa_tlp {\exp_not:o{#1}} + \tlp_set:Nx \l_testb_tlp {\exp_not:n{#2}} + \if_meaning:NN\l_testa_tlp \l_testb_tlp + } \def_long_test_function:npn{tlist_if_eq:oo}#1#2{ \tlp_set:Nx \l_testa_tlp {\exp_not:o{#1}} \tlp_set:Nx \l_testb_tlp {\exp_not:o{#2}} \if_meaning:NN\l_testa_tlp \l_testb_tlp } - \def_long:Npn\tlist_compare:xx #1#2{\ERROR} + \def_long_test_function:npn{tlist_if_eq:ox}#1#2{ + \tlp_set:Nx \l_testa_tlp {\exp_not:o{#1}} + \tlp_set:Nx \l_testb_tlp {#2} + \if_meaning:NN\l_testa_tlp \l_testb_tlp + } + \def_long_test_function:npn{tlist_if_eq:xn}#1#2{ + \tlp_set:Nx \l_testa_tlp {#1} + \tlp_set:Nx \l_testb_tlp {\exp_not:n{#2}} + \if_meaning:NN\l_testa_tlp \l_testb_tlp + } + \def_long_test_function:npn{tlist_if_eq:xo}#1#2{ + \tlp_set:Nx \l_testa_tlp {#1} + \tlp_set:Nx \l_testb_tlp {\exp_not:o{#2}} + \if_meaning:NN\l_testa_tlp \l_testb_tlp + } + \def_long_test_function:npn{tlist_if_eq:xx}#1#2{ + \tlp_set:Nx \l_testa_tlp {#1} + \tlp_set:Nx \l_testb_tlp {#2} + \if_meaning:NN\l_testa_tlp \l_testb_tlp + } } % \end{macrocode} % \end{macro} @@ -1507,7 +1623,7 @@ \def_new:Npn \tlp_if_in:cnTF {\exp_args:Nc\tlp_if_in:NnTF} \def_long:Npn \tlp_if_in:NnT #1#2{ \def_long:Npn\tmp:w ##1 #2 ##2\q_stop{ - \quark_if_no_value:nFT{##2} + \quark_if_no_value:nF{##2} } \exp_after:NN \tmp:w #1 #2 \q_no_value \q_stop } @@ -1565,14 +1681,14 @@ % again later on. % \begin{macrocode} \def_long_new:NNn \tlp_replace_in_aux:NNnn 4{ - \def:Npn \tmp:w ##1#3##2\q_stop{ + \def_long:Npn \tmp:w ##1#3##2\q_stop{ \quark_if_no_value:nF{##2} { % \end{macrocode} % At this point |##1| starts with a |\q_mark| so remove it. % \begin{macrocode} \tlp_set:Nx\l_tlp_replace_tlp{\exp_not:o{\use_none:n##1#4}} - \def:Npn \tmp:w ####1#3\q_no_value{ + \def_long:Npn \tmp:w ####1#3\q_no_value{ \tlp_put_right:Nx \l_tlp_replace_tlp {\exp_not:o{\use_none:n ####1}} } \tmp:w \q_mark ##2 @@ -1618,7 +1734,7 @@ % \begin{macrocode} \def_long:NNn \tlp_replace_all_in_aux:NNnn 4{ \tlp_clear:N \l_tlp_replace_tlp - \def:Npn \tmp:w ##1#3##2\q_stop{ + \def_long:Npn \tmp:w ##1#3##2\q_stop{ \quark_if_no_value:nTF{##2} { \tlp_put_right:Nx \l_tlp_replace_tlp {\exp_not:o{\use_none:n##1}} @@ -1812,11 +1928,10 @@ % and putting it in front of the ones before it. % \begin{macrocode} \def_long_new:Npn \tlist_reverse:n #1{ - \tlist_reverse_aux:nN {} #1 \q_nil\q_stop + \tlist_reverse_aux:nN {} #1 \q_recursion_tail\q_stop } \def_long_new:Npn \tlist_reverse_aux:nN #1#2{ - \quark_if_nil:NT #2 - { \use_arg_i_delimit_by_q_stop:nw {#1} } + \quark_if_recursion_tail_stop_do:nn {#2}{ #1 } \tlist_reverse_aux:nN {#2#1} } % \end{macrocode} |