summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/l3experimental/l3dt/l3dt.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/l3experimental/l3dt/l3dt.dtx')
-rw-r--r--Master/texmf-dist/source/latex/l3experimental/l3dt/l3dt.dtx155
1 files changed, 73 insertions, 82 deletions
diff --git a/Master/texmf-dist/source/latex/l3experimental/l3dt/l3dt.dtx b/Master/texmf-dist/source/latex/l3experimental/l3dt/l3dt.dtx
index 250fbd7bdf5..e6560eb79e1 100644
--- a/Master/texmf-dist/source/latex/l3experimental/l3dt/l3dt.dtx
+++ b/Master/texmf-dist/source/latex/l3experimental/l3dt/l3dt.dtx
@@ -36,7 +36,7 @@
%
%<*driver|package>
\RequirePackage{expl3}
-\GetIdInfo$Id: l3dt.dtx 3991 2012-07-16 19:00:35Z joseph $
+\GetIdInfo$Id: l3dt.dtx 4153 2012-08-29 07:18:26Z joseph $
{L3 Experimental data tables}
%</driver|package>
%<*driver>
@@ -71,9 +71,9 @@
% \LaTeX3 implements a \enquote{data table} variable type, which is made up of
% a series of rows each of which contain a number of key--value pairs. Thus
% a data table is in effect an array of property lists. The rows of the table
-% are stored in a fixed order, and are numbered consecutively from zero.
+% are stored in a fixed order, and are numbered consecutively from one.
% In the same way, the order of keys (columns) is recorded in a sequence-like
-% manner, again indexed from zero.
+% manner, again indexed from one.
%
% Within each row in a data table each entry must have a unique \meta{key}: if
% an entry is added to a row within a data table which already contains the
@@ -393,7 +393,7 @@
% \begin{macrocode}
%<*initex|package>
% \end{macrocode}
-%
+%
% \begin{macrocode}
%<@@=dt>
% \end{macrocode}
@@ -416,20 +416,21 @@
% numbered:
% \begin{quote}
% \Arg{rows} \\
-% \cs{q_@@} \meta{key$_0$} \cs{q_@@} \meta{key$_1$} \cs{q_@@} \ldots \\
+% \Arg{columns} \\
+% \cs{q_@@} \meta{key_1} \cs{q_@@} \meta{key_2} \cs{q_@@} \ldots \\
% \cs{q_nil} \\
% \cs{q_@@_header} \\
% \cs{q_@@_row} \\
-% \meta{row$_0$} \\
-% \cs{q_@@} \meta{key$_0$} \cs{q_@@} \Arg{data$_{0,0}$} \\
-% \cs{q_@@} \meta{key$_1$} \cs{q_@@} \Arg{data$_{0,1}$} \\
+% \meta{row_1} \\
+% \cs{q_@@} \meta{key_1} \cs{q_@@} \Arg{data_{1,1}} \\
+% \cs{q_@@} \meta{key_2} \cs{q_@@} \Arg{data_{1,2}} \\
% \ldots \\
% \cs{q_@@} \\
% \cs{q_nil} \\
% \cs{q_@@_row} \\
-% \meta{row$_2$} \\
-% \cs{q_@@} \meta{key$_0$} \cs{q_@@} \Arg{data$_{1,0}$} \\
-% \cs{q_@@} \meta{key$_1$} \cs{q_@@} \Arg{data$_{1,1}$} \\
+% \meta{row_2} \\
+% \cs{q_@@} \meta{key_1} \cs{q_@@} \Arg{data_{2,1}} \\
+% \cs{q_@@} \meta{key_2} \cs{q_@@} \Arg{data_{2,2}} \\
% \ldots \\
% \cs{q_@@} \\
% \cs{q_nil} \\
@@ -454,6 +455,7 @@
\tl_const:Nn \c_empty_dt
{
{ 0 }
+ { 0 }
\q_@@
\q_nil
\q_@@_header
@@ -468,15 +470,15 @@
% Internally, data tables are token lists, but an empty dt
% is not an empty tl.
% \begin{macrocode}
-\cs_new_protected:Npn \dt_new:N #1 { \cs_new_eq:NN #1 \c_empty_dt }
+\cs_new_protected:Npn \dt_new:N #1 { \cs_new_eq:NN #1 \c_empty_dt }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\dt_clear:N, \dt_gclear:N}
% The same idea for clearing.
% \begin{macrocode}
-\cs_new_protected:Npn \dt_clear:N #1 { \cs_set_eq:NN #1 \c_empty_dt }
-\cs_new_protected:Npn \dt_gclear:N #1 { \cs_gset_eq:NN #1 \c_empty_dt }
+\cs_new_protected:Npn \dt_clear:N #1 { \cs_set_eq:NN #1 \c_empty_dt }
+\cs_new_protected:Npn \dt_gclear:N #1 { \cs_gset_eq:NN #1 \c_empty_dt }
% \end{macrocode}
% \end{macro}
%
@@ -564,21 +566,21 @@
% Finding a key in the header uses a similar approach to finding a key in
% a property list. Here, if the key is found there will always be at least
% one token between \cs{q_@@} and \cs{q_@@_header} due to the \cs{q_nil}
-% which is part of a new table. The use of |##1##2| in \cs{@@_split:w}
-% here is to deal with the overall number of rows. The set up here means
-% that this will always be unbraced then rebraced: simply grabbing |##1|
-% to include this and anything before the key of interest will give variable
-% results depending on whether the match is to the very first key or not.
+% which is part of a new table. The use of |##1##2##3| in \cs{@@_split:w}
+% here is to deal with the overall number of rows and keys. The set up here
+% means that these will always be unbraced then rebraced: simply grabbing
+% |##1##2| to include this and anything before the key of interest will give
+% variable results depending on whether the match is to the very first key or not.
% \begin{macrocode}
\cs_new_protected:Npn \@@_split_key_list:NnTF #1#2
{ \exp_args:NNo \@@_split_key_list_aux:NnTF #1 { \tl_to_str:n {#2} } }
\cs_new_protected:Npn \@@_split_key_list_aux:NnTF #1#2
{
\cs_set_protected:Npn \@@_split:w
- ##1##2 \q_@@ #2 \q_@@ ##3##4 \q_@@_header ##5 \q_mark ##6 \q_stop
+ ##1##2##3 \q_@@ #2 \q_@@ ##4##5 \q_@@_header ##6 \q_mark ##7 \q_stop
{
- \@@_split:nnnn ##3
- { { {##1} ##2 \q_@@ } { ##3##4 \q_@@_header ##5 } }
+ \@@_split:nnnn ##4
+ { { {##1} {##2} ##3 \q_@@ } { ##4##5 \q_@@_header ##6 } }
}
\exp_after:wN \@@_split:w #1 \q_mark
\q_@@ #2 \q_@@ { ? \use_ii:nn { } } \q_@@_header \q_mark \q_stop
@@ -618,6 +620,7 @@
% \begin{macro}{\dt_add_key:Nn, \dt_gadd_key:Nn}
% \begin{macro}[aux]{\@@_add_key:NNn}
% \begin{macro}[aux]{\@@_add_key:NNnnn}
+% \begin{macro}[aux]{\@@_add_key:NNnnn}
% Here, there are two stages. If the key is already present in the list of
% known keys then no action is taken, and the split list is thrown away.
% On the other hand, if the key is not present then the header and body
@@ -637,22 +640,27 @@
}
}
\cs_new_protected:Npn \@@_add_key:NNnnn #1#2#3#4#5
+ { \@@_add_key:NNnnnwnn #1 #2 #4 \q_stop {#3} {#5} }
+\cs_new_protected:Npn \@@_add_key:NNnnnwnn #1#2#3#4#5 \q_stop #6#7
{
#1 #2
{
- \exp_not:n {#4}
- \tl_to_str:n {#3}
- \exp_not:n { \q_@@ \q_nil #5 }
+ {#3}
+ { \int_eval:n { #4 + \c_one } }
+ \exp_not:n {#5}
+ \tl_to_str:n {#6}
+ \exp_not:n { \q_@@ \q_nil #7 }
}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
+% \end{macro}
%
% \begin{macro}{\dt_add_row:N, \dt_gadd_row:N}
% \begin{macro}[aux]{\@@_add_row:NN}
-% \begin{macro}[aux]{\@@_add_row:NnN}
+% \begin{macro}[aux]{\@@_add_row:NnN, \@@_add_row:NfN}
% \begin{macro}[aux,EXP]{\@@_add_row:nw}
% Adding a row means incrementing the total number and adding the structure
% of an empty row. As finding the rows will get slow for large tables, this
@@ -661,17 +669,18 @@
\cs_new_protected_nopar:Npn \dt_add_row:N { \@@_add_row:NN \tl_set:Nx }
\cs_new_protected_nopar:Npn \dt_gadd_row:N { \@@_add_row:NN \tl_gset:Nx }
\cs_new_protected:Npn \@@_add_row:NN #1#2
- { \exp_args:NNf \@@_add_row:NnN #1 { \dt_rows:N #2 } #2 }
+ { \@@_add_row:NfN #1 { \int_eval:n { \dt_rows:N #2 + \c_one } } #2 }
\cs_new_protected:Npn \@@_add_row:NnN #1#2#3
{
#1 #3
{
- { \int_eval:n { #2 + \c_one } }
+ {#2}
\exp_after:wN \@@_add_row:nw #3 \q_stop
#2
\exp_not:n { \q_@@ \q_nil \q_@@_row }
}
}
+\cs_generate_variant:Nn \@@_add_row:NnN { Nf }
\cs_new:Npn \@@_add_row:nw #1#2 \q_stop { \exp_not:n {#2} }
% \end{macrocode}
% \end{macro}
@@ -684,9 +693,9 @@
% arbitrary row.
% \begin{macrocode}
\cs_new_protected:Npn \dt_put:Nnn #1
- { \dt_put:Nnnn #1 { \dt_rows:N #1 - \c_one } }
+ { \dt_put:Nnnn #1 { \dt_rows:N #1 } }
\cs_new_protected:Npn \dt_gput:Nnn #1
- { \dt_gput:Nnnn #1 { \dt_rows:N #1 - \c_one } }
+ { \dt_gput:Nnnn #1 { \dt_rows:N #1 } }
% \end{macrocode}
% \end{macro}
%
@@ -790,42 +799,19 @@
% \end{macro}
%
% \begin{macro}[EXP]{\dt_keys:N}
-% \begin{macro}[aux, EXP]{\@@_keys:nn}
-% \begin{macro}[aux, EXP]{\@@_keys:wN}
-% A quick mapping is needed to count keys. The \cs{use_none:nn} here
-% is used to remove the number of rows and initial \cs{q_@@}. This could
-% also be handled by starting from $-1$ rather than $0$, but this makes
-% the logic hopefully slightly clearer.
-% \begin{macrocode}
-\cs_new:Npn \dt_keys:N #1
- { \@@_split_header:NT #1 { \@@_keys:nn } }
-\cs_new:Npn \@@_keys:nn #1#2
- {
- \int_eval:n
- {
- 0
- \exp_after:wN \@@_keys:wN \use_none:nn #1 \q_recursion_tail \q_@@
- \__prg_break_point:Nn \dt_map_break: { }
- }
- }
-\cs_new:Npn \@@_keys:wN #1 \q_@@
- {
- \__quark_if_recursion_tail_break:nN {#1} \dt_map_break:
- +1
- \@@_keys:wN
- }
-% \end{macrocode}
-% \end{macro}
-% \end{macro}
-% \end{macro}
-%
+% \begin{macro}[EXP, aux]{\@@_keys:nnw}
% \begin{macro}[EXP]{\dt_rows:N}
-% The number of rows in a dt is the very first entry.
+% The number of rows in a dt is the very first entry. Getting the number of
+% keys is almost the same, except a custom auxiliary is needed.
% \begin{macrocode}
+\cs_new:Npn \dt_keys:N #1 { \exp_after:wN \@@_keys:nnw #1 \q_stop }
+\cs_new:Npn \@@_keys:nnw #1#2#3 \q_stop {#2}
\cs_new:Npn \dt_rows:N #1
{ \exp_after:wN \use_i_delimit_by_q_stop:nw #1 \q_stop }
% \end{macrocode}
% \end{macro}
+% \end{macro}
+% \end{macro}
%
% \subsection{Removing data}
%
@@ -833,10 +819,10 @@
% Deleting to the current row is simply a special case of deleting to an
% arbitrary row.
% \begin{macrocode}
-\cs_new_protected:Npn \dt_remove:Nn #1 { \dt_remove:Nnn #1
- { \dt_rows:N #1 - \c_one } }
-\cs_new_protected:Npn \dt_gremove:Nn #1 { \dt_gremove:Nnn #1
- { \dt_rows:N #1 - \c_one } }
+\cs_new_protected:Npn \dt_remove:Nn #1
+ { \dt_remove:Nnn #1 { \dt_rows:N #1 } }
+\cs_new_protected:Npn \dt_gremove:Nn #1
+ { \dt_gremove:Nnn #1 { \dt_rows:N #1 } }
% \end{macrocode}
% \end{macro}
%
@@ -892,6 +878,8 @@
{ }
}
\cs_new_protected:Npn \dt_remove_key_aux:nNNnn #1#2#3#4#5
+ { \dt_remove_key_aux:nNNnnwn {#1} #2 #3 #4 \q_stop {#5} }
+\cs_new_protected:Npn \dt_remove_key_aux:nNNnnwn #1#2#3#4#5#6 \q_stop #7
{
\cs_set:Npn \dt_remove_key_aux:w ##1 \q_@@ #1 \q_@@ ##2 ##3
{
@@ -899,10 +887,13 @@
\__quark_if_recursion_tail_break:nN {##3} \dt_map_break:
\dt_remove_key_aux:w ##3
}
+
#2 #3
{
- \exp_not:n {#4}
- \dt_remove_key_aux:w #5 \q_@@ #1 \q_@@ { } \q_recursion_tail
+ {#4}
+ { \int_eval:n { #5 - \c_one } }
+ \exp_not:n {#6}
+ \dt_remove_key_aux:w #7 \q_@@ #1 \q_@@ { } \q_recursion_tail
\__prg_break_point:Nn \dt_map_break: { }
}
}
@@ -1022,14 +1013,14 @@
% \begin{macro}[TF]{\dt_get:NnN}
% Simple wrappers.
% \begin{macrocode}
-\cs_new_protected:Npn \dt_get:NnN #1 { \dt_get:NnnN #1
- { \dt_rows:N #1 - \c_one } }
-\cs_new_protected:Npn \dt_get:NnNT #1 { \dt_get:NnnNF #1
- { \dt_rows:N #1 - \c_one } }
-\cs_new_protected:Npn \dt_get:NnNF #1 { \dt_get:NnnNF #1
- { \dt_rows:N #1 - \c_one } }
-\cs_new_protected:Npn \dt_get:NnNTF #1 { \dt_get:NnnNTF #1
- { \dt_rows:N #1 - \c_one } }
+\cs_new_protected:Npn \dt_get:NnN #1
+ { \dt_get:NnnN #1 { \dt_rows:N #1 } }
+\cs_new_protected:Npn \dt_get:NnNT #1
+ { \dt_get:NnnNF #1 { \dt_rows:N #1 } }
+\cs_new_protected:Npn \dt_get:NnNF #1
+ { \dt_get:NnnNF #1 { \dt_rows:N #1 } }
+\cs_new_protected:Npn \dt_get:NnNTF #1
+ { \dt_get:NnnNTF #1 { \dt_rows:N #1 } }
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -1236,14 +1227,14 @@
% \begin{macro}[pTF, EXP]{\dt_if_in_row:Nn}
% Simple wrappers.
% \begin{macrocode}
-\cs_new:Npn \dt_if_in_row_p:Nn #1 { \dt_if_in_row_p:Nnn #1
- { \dt_rows:N #1 - \c_one } }
-\cs_new:Npn \dt_if_in_row:NnT #1 { \dt_if_in_row:NnnT #1
- { \dt_rows:N #1 - \c_one } }
-\cs_new:Npn \dt_if_in_row:NnF #1 { \dt_if_in_row:NnnF #1
- { \dt_rows:N #1 - \c_one } }
-\cs_new:Npn \dt_if_in_row:NnTF #1 { \dt_if_in_row:NnnTF #1
- { \dt_rows:N #1 - \c_one } }
+\cs_new:Npn \dt_if_in_row_p:Nn #1
+ { \dt_if_in_row_p:Nnn #1 { \dt_rows:N #1 } }
+\cs_new:Npn \dt_if_in_row:NnT #1
+ { \dt_if_in_row:NnnT #1 { \dt_rows:N #1 } }
+\cs_new:Npn \dt_if_in_row:NnF #1
+ { \dt_if_in_row:NnnF #1 { \dt_rows:N #1 } }
+\cs_new:Npn \dt_if_in_row:NnTF #1
+ { \dt_if_in_row:NnnTF #1 { \dt_rows:N #1 } }
% \end{macrocode}
% \end{macro}
%