Debian Codegraph @

texmf-dist/source/latex/l3kernel/l3prop.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3prop.dtx
4 %
5 % Copyright (C) 1990-2026 The LaTeX Project
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % https://www.latex-project.org/lppl.txt
13 %
14 % This file is part of the "l3kernel bundle" (The Work in LPPL)
15 % and all files in that bundle must be distributed together.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/latex3/latex3
22 %
23 % for those people who are interested.
24 %
25 %<*driver>
26 \documentclass[full,kernel]{l3doc}
27 \begin{document}
28 \DocInput{\jobname.dtx}
29 \end{document}
30 %</driver>
31 % \fi
32 %
33 % \title{^^A
34 % The \pkg{l3prop} module\\ Property lists^^A
35 % }
36 %
37 % \author{^^A
38 % The \LaTeX{} Project\thanks
39 % {^^A
40 % E-mail:
41 % \href{mailto:[email protected]}
42 % {[email protected]}^^A
43 % }^^A
44 % }
45 %
46 % \date{Released 2026-05-15}
47 %
48 % \maketitle
49 %
50 % \begin{documentation}
51 %
52 % \pkg{expl3} implements a \enquote{property list} data type, which contains
53 % an unordered list of entries each of which consists of a \meta{key} (string)
54 % and an associated \meta{value} (token list). The \meta{key} and \meta{value}
55 % may both be given as any balanced text, and the \meta{key} is processed using
56 % \cs{tl_to_str:n}, meaning that category codes are ignored. Entries can be
57 % manipulated individually, as well as collectively by applying a function to
58 % every key--value pair within the list.
59 %
60 % Each entry in a property list must have a unique \meta{key}: if an entry is
61 % added to a property list which already contains the \meta{key} then the new
62 % entry overwrites the existing one. The \meta{keys} are compared on a
63 % string basis, using the same method as \cs{str_if_eq:nnTF}.
64 %
65 % Property lists are intended for storing key-based information for use within
66 % code. They can be converted from and to key--value lists, which are a form of
67 % \emph{input} parsed by the \pkg{l3keys} module. If a key--value list contains
68 % a \meta{key} multiple times, only the last \meta{value} associated to it will
69 % be kept in the conversion to a property list.
70 %
71 % Internally, property lists can use two distinct implementations with different
72 % data storage, which are decided when declaring the property list variable
73 % using \cs{prop_new:N} (\enquote{flat} storage) or \cs{prop_new_linked:N}
74 % (\enquote{linked} storage). After a property list is declared with
75 % \cs{prop_new:N} or \cs{prop_new_linked:N}, the type of internal data storage
76 % can be changed by \cs{prop_make_flat:N} or \cs{prop_make_linked:N}, but only
77 % at the outermost group level. All other \pkg{l3prop} functions transparently
78 % manipulate either storage method and convert as needed.
79 % \begin{itemize}
80 % \item
81 % The (default) \enquote{flat} storage method is suited for a relatively
82 % small number of entries, or when the property list is likely to be
83 % manipulated (copied, mapped) as a whole rather than entry-wise. It is
84 % significantly faster for \cs{prop_set_eq:NN}, and only slightly faster for
85 % \cs{prop_clear:N}, \cs{prop_concat:NNN}, and mapping functions
86 % \cs[no-index]{prop_map_\ldots{}}.
87 %
88 % \item
89 % The \enquote{linked} storage method is meant for property lists with a
90 % large numbers of entries. It takes up more of \TeX{}'s memory during a run, but is
91 % significantly faster (for long lists) when accessing or modifying
92 % individual entries using functions such as \cs{prop_if_in:Nn},
93 % \cs{prop_item:Nn}, \cs{prop_put:Nnn}, \cs{prop_get:NnN},
94 % \cs{prop_pop:NnN}, \cs{prop_remove:Nn}, as it takes a constant
95 % time for these operations (rather than the number of items for a
96 % \enquote{flat} property list). A technical drawback is that
97 % memory is permanently used\footnote{Until the end of the run, that
98 % is.} by \meta{keys} stored in a \enquote{linked} property list,
99 % even after they are removed and the property list is deleted.
100 % \end{itemize}
101 %
102 % \section{Creating and initializing property lists}
103 %
104 % \begin{function}{\prop_new:N, \prop_new:c}
105 % \begin{syntax}
106 % \cs{prop_new:N} \meta{property list}
107 % \end{syntax}
108 % Creates a new \enquote{flat} \meta{property list} or raises an error if the
109 % name is already taken. The declaration is global. The \meta{property list}
110 % initially contains no entries. See also \cs{prop_new_linked:N}.
111 % \end{function}
112 %
113 % \begin{function}[added = 2024-02-12]{\prop_new_linked:N, \prop_new_linked:c}
114 % \begin{syntax}
115 % \cs{prop_new_linked:N} \meta{property list}
116 % \end{syntax}
117 % Creates a new \enquote{linked} \meta{property list} or raises an error if
118 % the name is already taken. The declaration is global. The \meta{property
119 % list} initially contains no entries. The internal data storage differs from
120 % that produced by \cs{prop_new:N} and it is optimized for property lists with
121 % a large number of entries.
122 % \end{function}
123 %
124 % \begin{function}
125 % {\prop_clear:N, \prop_clear:c, \prop_gclear:N, \prop_gclear:c}
126 % \begin{syntax}
127 % \cs{prop_clear:N} \meta{property list}
128 % \end{syntax}
129 % Clears all entries from the \meta{property list}.
130 % \end{function}
131 %
132 % \begin{function}
133 % {
134 % \prop_clear_new:N, \prop_clear_new:c,
135 % \prop_gclear_new:N, \prop_gclear_new:c
136 % }
137 % \begin{syntax}
138 % \cs{prop_clear_new:N} \meta{property list}
139 % \end{syntax}
140 % Ensures that the \meta{property list} exists globally by applying
141 % \cs{prop_new:N} if necessary, then applies
142 % \cs[index=prop_clear:N]{prop_(g)clear:N} to leave the list empty.
143 % \begin{texnote}
144 % If the property list exists and is of \enquote{linked} type, it
145 % is cleared but not made into a flat property list.
146 % \end{texnote}
147 % \end{function}
148 %
149 % \begin{function}[added = 2024-02-12]
150 % {
151 % \prop_clear_new_linked:N, \prop_clear_new_linked:c,
152 % \prop_gclear_new_linked:N, \prop_gclear_new_linked:c
153 % }
154 % \begin{syntax}
155 % \cs{prop_clear_new_linked:N} \meta{property list}
156 % \end{syntax}
157 % Ensures that the \meta{property list} exists globally by applying
158 % \cs{prop_new_linked:N} if necessary, then applies
159 % \cs[index=prop_clear:N]{prop_(g)clear:N} to leave the list empty.
160 % \begin{texnote}
161 % If the property list exists and is of \enquote{flat} type, it
162 % is cleared but not made into a linked property list.
163 % \end{texnote}
164 % \end{function}
165 %
166 % \begin{function}
167 % {
168 % \prop_set_eq:NN, \prop_set_eq:cN, \prop_set_eq:Nc, \prop_set_eq:cc,
169 % \prop_gset_eq:NN, \prop_gset_eq:cN, \prop_gset_eq:Nc, \prop_gset_eq:cc
170 % }
171 % \begin{syntax}
172 % \cs{prop_set_eq:NN} \meta{property list_1} \meta{property list_2}
173 % \end{syntax}
174 % Sets the content of \meta{property list_1} equal to that of \meta{property
175 % list_2}. This converts as needed between the two storage types.
176 % \end{function}
177 %
178 % \begin{function}[added = 2017-11-28, updated = 2021-11-07]
179 % {
180 % \prop_set_from_keyval:Nn, \prop_set_from_keyval:cn,
181 % \prop_gset_from_keyval:Nn, \prop_gset_from_keyval:cn,
182 % }
183 % \begin{syntax}
184 % \cs{prop_set_from_keyval:Nn} \meta{property list} \\
185 % ~~\{ \\
186 % ~~~~\meta{key_1} |=| \meta{value_1} |,| \\
187 % ~~~~\meta{key_2} |=| \meta{value_2} |,| \ldots{} \\
188 % ~~\}
189 % \end{syntax}
190 % Sets \meta{property list} to contain key--value pairs given in the second
191 % argument. If duplicate keys appear only the last of the values is kept.
192 % In contrast to most keyval lists (\emph{e.g.}~those in \pkg{l3keys}), each
193 % key here \emph{must} be followed with an \texttt{=} sign even to specify an
194 % empty \meta{value}.
195 %
196 % Spaces are trimmed around every \meta{key} and every \meta{value},
197 % and if the result of trimming spaces consists of a single brace
198 % group then a set of outer braces is removed. This enables both the
199 % \meta{key} and the \meta{value} to contain spaces, commas or equal
200 % signs. The \meta{key} is then processed by \cs{tl_to_str:n}.
201 % This function correctly detects the |=| and |,| signs provided they
202 % have the standard category code~$12$ or they are active.
203 % \end{function}
204 %
205 % \begin{function}[added = 2017-11-28, updated = 2021-11-07]
206 % {\prop_const_from_keyval:Nn, \prop_const_from_keyval:cn}
207 % \begin{syntax}
208 % \cs{prop_const_from_keyval:Nn} \meta{property list} \\
209 % ~~\{ \\
210 % ~~~~\meta{key_1} |=| \meta{value_1} |,| \\
211 % ~~~~\meta{key_2} |=| \meta{value_2} |,| \ldots{} \\
212 % ~~\}
213 % \end{syntax}
214 % Creates a new constant \enquote{flat} \meta{property list} or raises
215 % an error if the
216 % name is already taken. The \meta{property list} is set globally to
217 % contain key--value pairs given in the second argument, processed in
218 % the way described for \cs{prop_set_from_keyval:Nn}. If duplicate
219 % keys appear only the last of the values is kept.
220 % This function correctly detects the |=| and |,| signs provided they
221 % have the standard category code~$12$ or they are active.
222 % \end{function}
223 %
224 % \begin{function}[added = 2024-02-12]
225 % {\prop_const_linked_from_keyval:Nn, \prop_const_linked_from_keyval:cn}
226 % \begin{syntax}
227 % \cs{prop_const_linked_from_keyval:Nn} \meta{property list} \\
228 % ~~\{ \\
229 % ~~~~\meta{key_1} |=| \meta{value_1} |,| \\
230 % ~~~~\meta{key_2} |=| \meta{value_2} |,| \ldots{} \\
231 % ~~\}
232 % \end{syntax}
233 % Creates a new constant \enquote{linked} \meta{property list} or raises an
234 % error if the
235 % name is already taken. The \meta{property list} is set globally to
236 % contain key--value pairs given in the second argument, processed in
237 % the way described for \cs{prop_set_from_keyval:Nn}. If duplicate
238 % keys appear only the last of the values is kept.
239 % This function correctly detects the |=| and |,| signs provided they
240 % have the standard category code~$12$ or they are active.
241 % \end{function}
242 %
243 % \begin{function}[added = 2024-02-12]{\prop_make_flat:N, \prop_make_flat:c}
244 % \begin{syntax}
245 % \cs{prop_make_flat:N} \meta{property list}
246 % \end{syntax}
247 % Changes the internal storage type of the \meta{property list} to be
248 % the same \enquote{flat} storage as \cs{prop_new:N}. The key--value
249 % pairs of the \meta{property list} are preserved by the change. If
250 % the property list was already flat then nothing is done. This
251 % function can only be used at the outermost group level.
252 % \end{function}
253 %
254 % \begin{function}[added = 2024-02-12]{\prop_make_linked:N, \prop_make_linked:c}
255 % \begin{syntax}
256 % \cs{prop_make_linked:N} \meta{property list}
257 % \end{syntax}
258 % Changes the internal storage type of the \meta{property list} to be
259 % the same \enquote{linked} storage as \cs{prop_new_linked:N}. The
260 % key--value pairs of the \meta{property list} are preserved by the
261 % change. If the property list was already linked then nothing is
262 % done. This function can only be used at the outermost group level.
263 % \end{function}
264 %
265 % \section{Adding and updating property list entries}
266 %
267 % \begin{function}[updated = 2012-07-09]
268 % {
269 % \prop_put:Nnn, \prop_put:NnV, \prop_put:Nnv, \prop_put:Nne,
270 % \prop_put:NVn, \prop_put:NVV, \prop_put:NVv, \prop_put:NVe,
271 % \prop_put:Nvn, \prop_put:NvV, \prop_put:Nvv, \prop_put:Nve,
272 % \prop_put:Nen, \prop_put:NeV, \prop_put:Nev, \prop_put:Nee,
273 % \prop_put:Nno, \prop_put:Non, \prop_put:Noo,
274 % \prop_put:cnn, \prop_put:cnV, \prop_put:cnv, \prop_put:cne,
275 % \prop_put:cVn, \prop_put:cVV, \prop_put:cVv, \prop_put:cVe,
276 % \prop_put:cvn, \prop_put:cvV, \prop_put:cvv, \prop_put:cve,
277 % \prop_put:cen, \prop_put:ceV, \prop_put:cev, \prop_put:cee,
278 % \prop_put:cno, \prop_put:con, \prop_put:coo,
279 % \prop_gput:Nnn, \prop_gput:NnV, \prop_gput:Nnv, \prop_gput:Nne,
280 % \prop_gput:NVn, \prop_gput:NVV, \prop_gput:NVv, \prop_gput:NVe,
281 % \prop_gput:Nvn, \prop_gput:NvV, \prop_gput:Nvv, \prop_gput:Nve,
282 % \prop_gput:Nen, \prop_gput:NeV, \prop_gput:Nev, \prop_gput:Nee,
283 % \prop_gput:Nno, \prop_gput:Non, \prop_gput:Noo,
284 % \prop_gput:cnn, \prop_gput:cnV, \prop_gput:cnv, \prop_gput:cne,
285 % \prop_gput:cVn, \prop_gput:cVV, \prop_gput:cVv, \prop_gput:cVe,
286 % \prop_gput:cvn, \prop_gput:cvV, \prop_gput:cvv, \prop_gput:cve,
287 % \prop_gput:cen, \prop_gput:ceV, \prop_gput:cev, \prop_gput:cee,
288 % \prop_gput:cno, \prop_gput:con, \prop_gput:coo
289 % }
290 % \begin{syntax}
291 % \cs{prop_put:Nnn} \meta{property list} \Arg{key} \Arg{value}
292 % \end{syntax}
293 % Adds an entry to the \meta{property list} which may be accessed
294 % using the \meta{key} and which has \meta{value}. If the \meta{key}
295 % is already present in the \meta{property list}, the existing entry
296 % is overwritten by the new \meta{value}. Both the \meta{key} and
297 % \meta{value} may contain any \meta{balanced text}. The \meta{key} is
298 % stored after processing with \cs{tl_to_str:n}, meaning that category
299 % codes are ignored.
300 % \end{function}
301 %
302 % \begin{function}[added = 2024-03-30, updated = 2024-05-07]
303 % {
304 % \prop_put_if_not_in:Nnn, \prop_put_if_not_in:NnV, \prop_put_if_not_in:Nnv, \prop_put_if_not_in:Nne,
305 % \prop_put_if_not_in:NVn, \prop_put_if_not_in:NVV, \prop_put_if_not_in:NVv, \prop_put_if_not_in:NVe,
306 % \prop_put_if_not_in:Nvn, \prop_put_if_not_in:NvV, \prop_put_if_not_in:Nvv, \prop_put_if_not_in:Nve,
307 % \prop_put_if_not_in:Nen, \prop_put_if_not_in:NeV, \prop_put_if_not_in:Nev, \prop_put_if_not_in:Nee,
308 % \prop_put_if_not_in:cnn, \prop_put_if_not_in:cnV, \prop_put_if_not_in:cnv, \prop_put_if_not_in:cne,
309 % \prop_put_if_not_in:cVn, \prop_put_if_not_in:cVV, \prop_put_if_not_in:cVv, \prop_put_if_not_in:cVe,
310 % \prop_put_if_not_in:cvn, \prop_put_if_not_in:cvV, \prop_put_if_not_in:cvv, \prop_put_if_not_in:cve,
311 % \prop_put_if_not_in:cen, \prop_put_if_not_in:ceV, \prop_put_if_not_in:cev, \prop_put_if_not_in:cee,
312 % \prop_gput_if_not_in:Nnn, \prop_gput_if_not_in:NnV, \prop_gput_if_not_in:Nnv, \prop_gput_if_not_in:Nne,
313 % \prop_gput_if_not_in:NVn, \prop_gput_if_not_in:NVV, \prop_gput_if_not_in:NVv, \prop_gput_if_not_in:NVe,
314 % \prop_gput_if_not_in:Nvn, \prop_gput_if_not_in:NvV, \prop_gput_if_not_in:Nvv, \prop_gput_if_not_in:Nve,
315 % \prop_gput_if_not_in:Nen, \prop_gput_if_not_in:NeV, \prop_gput_if_not_in:Nev, \prop_gput_if_not_in:Nee,
316 % \prop_gput_if_not_in:cnn, \prop_gput_if_not_in:cnV, \prop_gput_if_not_in:cnv, \prop_gput_if_not_in:cne,
317 % \prop_gput_if_not_in:cVn, \prop_gput_if_not_in:cVV, \prop_gput_if_not_in:cVv, \prop_gput_if_not_in:cVe,
318 % \prop_gput_if_not_in:cvn, \prop_gput_if_not_in:cvV, \prop_gput_if_not_in:cvv, \prop_gput_if_not_in:cve,
319 % \prop_gput_if_not_in:cen, \prop_gput_if_not_in:ceV, \prop_gput_if_not_in:cev, \prop_gput_if_not_in:cee
320 % }
321 % \begin{syntax}
322 % \cs{prop_put_if_not_in:Nnn} \meta{property list} \Arg{key} \Arg{value}
323 % \end{syntax}
324 % If the \meta{key} is present in the \meta{property list} then no
325 % action is taken. Otherwise, a new entry is added as described for
326 % \cs{prop_put:Nnn}.
327 % \end{function}
328 %
329 % \begin{function}[added = 2021-05-16]
330 % {
331 % \prop_concat:NNN, \prop_concat:ccc,
332 % \prop_gconcat:NNN, \prop_gconcat:ccc
333 % }
334 % \begin{syntax}
335 % \cs{prop_concat:NNN} \meta{property list_1} \meta{property list_2} \meta{property list_3}
336 % \end{syntax}
337 % Combines the key--value pairs of \meta{property list_2} and
338 % \meta{property list_3}, and saves the result in \meta{property list_1}. If a
339 % key appears in both \meta{property list_2} and \meta{property list_3} then the
340 % last value, namely the value in \meta{property list_3} is kept.
341 % This converts as needed between the two storage types.
342 % \end{function}
343 %
344 % \begin{function}[added = 2021-05-16, updated = 2021-11-07]
345 % {
346 % \prop_put_from_keyval:Nn, \prop_put_from_keyval:cn,
347 % \prop_gput_from_keyval:Nn, \prop_gput_from_keyval:cn,
348 % }
349 % \begin{syntax}
350 % \cs{prop_put_from_keyval:Nn} \meta{property list} \\
351 % ~~\{ \\
352 % ~~~~\meta{key_1} |=| \meta{value_1} |,| \\
353 % ~~~~\meta{key_2} |=| \meta{value_2} |,| \ldots{} \\
354 % ~~\}
355 % \end{syntax}
356 % Updates the \meta{property list} by adding entries for each key--value
357 % pair given in the second argument. The addition is done through
358 % \cs{prop_put:Nnn}, hence if the \meta{property list} already contains
359 % some of the keys, the corresponding values are discarded and
360 % replaced by those given in the key--value list. If duplicate keys
361 % appear in the key--value list then only the last of the values is kept.
362 %
363 % The function is equivalent to storing the key--value pairs in a
364 % temporary property list using \cs{prop_set_from_keyval:Nn}, then
365 % combining \meta{property list} with the temporary variable using
366 % \cs{prop_concat:NNN}. In particular, the \meta{keys} and
367 % \meta{values} are space-trimmed and unbraced as described in
368 % \cs{prop_set_from_keyval:Nn}.
369 % This function correctly detects the |=| and |,| signs provided they
370 % have the standard category code~$12$ or they are active.
371 % \end{function}
372 %
373 % \section{Recovering values from property lists}
374 %
375 % \begin{function}[updated = 2011-08-28]
376 % {
377 % \prop_get:NnN, \prop_get:NVN, \prop_get:NvN, \prop_get:NeN,
378 % \prop_get:NoN,
379 % \prop_get:cnN, \prop_get:cVN, \prop_get:cvN, \prop_get:ceN,
380 % \prop_get:coN,
381 % \prop_get:cnc
382 % }
383 % \begin{syntax}
384 % \cs{prop_get:NnN} \meta{property list} \Arg{key} \meta{tl var}
385 % \end{syntax}
386 % Recovers the \meta{value} stored with \meta{key} from the
387 % \meta{property list}, and places this in the \meta{tl
388 % var}. If the \meta{key} is not found in the
389 % \meta{property list} then the \meta{tl~var} is set
390 % to the special marker \cs{q_no_value}. The \meta{tl
391 % var} is set within the current \TeX{} group. See also
392 % \cs{prop_get:NnNTF}.
393 % \end{function}
394 %
395 % \begin{function}[updated = 2011-08-18]
396 % {
397 % \prop_pop:NnN, \prop_pop:NVN,
398 % \prop_pop:NoN,
399 % \prop_pop:cnN, \prop_pop:cVN,
400 % \prop_pop:coN
401 % }
402 % \begin{syntax}
403 % \cs{prop_pop:NnN} \meta{property list} \Arg{key} \meta{tl var}
404 % \end{syntax}
405 % Recovers the \meta{value} stored with \meta{key} from the
406 % \meta{property list}, and places this in the \meta{tl
407 % var}. If the \meta{key} is not found in the
408 % \meta{property list} then the \meta{tl~var} is set
409 % to the special marker \cs{q_no_value}. The \meta{key} and
410 % \meta{value} are then deleted from the property list. Both
411 % assignments are local. See also \cs{prop_pop:NnNTF}.
412 % \end{function}
413 %
414 % \begin{function}[updated = 2011-08-18]
415 % {
416 % \prop_gpop:NnN, \prop_gpop:NVN,
417 % \prop_gpop:NoN,
418 % \prop_gpop:cnN, \prop_gpop:cVN,
419 % \prop_gpop:coN
420 % }
421 % \begin{syntax}
422 % \cs{prop_gpop:NnN} \meta{property list} \Arg{key} \meta{tl var}
423 % \end{syntax}
424 % Recovers the \meta{value} stored with \meta{key} from the
425 % \meta{property list}, and places this in the \meta{tl
426 % var}. If the \meta{key} is not found in the
427 % \meta{property list} then the \meta{tl~var} is set
428 % to the special marker \cs{q_no_value}. The \meta{key} and
429 % \meta{value} are then deleted from the property list.
430 % The \meta{property list} is modified globally, while the assignment of
431 % the \meta{tl~var} is local. See also \cs{prop_gpop:NnNTF}.
432 % \end{function}
433 %
434 % \begin{function}[EXP, added = 2014-07-17]
435 % {
436 % \prop_item:Nn, \prop_item:NV, \prop_item:Ne, \prop_item:No,
437 % \prop_item:cn, \prop_item:cV, \prop_item:ce, \prop_item:co
438 % }
439 % \begin{syntax}
440 % \cs{prop_item:Nn} \meta{property list} \Arg{key}
441 % \end{syntax}
442 % Expands to the \meta{value} corresponding to the \meta{key} in
443 % the \meta{property list}. If the \meta{key} is missing, this has
444 % an empty expansion.
445 % \begin{texnote}
446 % For \enquote{flat} property lists, this expandable function iterates
447 % through every key--value pair and is therefore slower than a
448 % non-expandable approach based on \cs{prop_get:NnN}.
449 % (For \enquote{linked} property lists both functions are fast.)
450 %
451 % The result is returned within the \tn{unexpanded}
452 % primitive (\cs{exp_not:n}), which means that the \meta{value}
453 % does not expand further when appearing in an \texttt{e}-type
454 % or \texttt{x}-type argument expansion.
455 % \end{texnote}
456 % \end{function}
457 %
458 % \begin{function}[EXP]{\prop_count:N, \prop_count:c}
459 % \begin{syntax}
460 % \cs{prop_count:N} \meta{property list}
461 % \end{syntax}
462 % Leaves the number of key--value pairs in the \meta{property list} in
463 % the input stream as an \meta{integer denotation}.
464 % \end{function}
465 %
466 % \begin{function}[EXP]{\prop_to_keyval:N}
467 % \begin{syntax}
468 % \cs{prop_to_keyval:N} \meta{property list}
469 % \end{syntax}
470 % Expands to the \meta{property list} in a key--value notation. Keep in mind
471 % that a \meta{property list} is \emph{unordered}, while key--value interfaces
472 % are not necessarily, so this cannot be used for arbitrary interfaces.
473 % \begin{texnote}
474 % The result is returned within the \tn{unexpanded} primitive
475 % (\cs{exp_not:n}), which means that the key--value list does not expand
476 % further when appearing in an \texttt{e}-type or \texttt{x}-type argument expansion.
477 % It also needs exactly two steps of expansion.
478 % \end{texnote}
479 % \end{function}
480 %
481 % \section{Modifying property lists}
482 %
483 % \begin{function}[added = 2012-05-12]
484 % {
485 % \prop_remove:Nn, \prop_remove:NV, \prop_remove:Ne,
486 % \prop_remove:cn, \prop_remove:cV, \prop_remove:ce,
487 % \prop_gremove:Nn, \prop_gremove:NV, \prop_gremove:Ne,
488 % \prop_gremove:cn, \prop_gremove:cV, \prop_gremove:ce,
489 % }
490 % \begin{syntax}
491 % \cs{prop_remove:Nn} \meta{property list} \Arg{key}
492 % \end{syntax}
493 % Removes the entry listed under \meta{key} from the
494 % \meta{property list}. If the \meta{key} is
495 % not found in the \meta{property list} no change occurs,
496 % \emph{i.e}~there is no need to test for the existence of a key before
497 % deleting it.
498 % \end{function}
499 %
500 % \section{Property list conditionals}
501 %
502 % \begin{function}[EXP, pTF, added = 2012-03-03]
503 % {\prop_if_exist:N, \prop_if_exist:c}
504 % \begin{syntax}
505 % \cs{prop_if_exist_p:N} \meta{property list}
506 % \cs{prop_if_exist:NTF} \meta{property list} \Arg{true code} \Arg{false code}
507 % \end{syntax}
508 % Tests whether the \meta{property list} is currently defined. This does not
509 % check that the \meta{property list} really is a property list variable.
510 % \end{function}
511 %
512 % \begin{function}[EXP, pTF]{\prop_if_empty:N, \prop_if_empty:c}
513 % \begin{syntax}
514 % \cs{prop_if_empty_p:N} \meta{property list}
515 % \cs{prop_if_empty:NTF} \meta{property list} \Arg{true code} \Arg{false code}
516 % \end{syntax}
517 % Tests if the \meta{property list} is empty (containing no entries).
518 % \end{function}
519 %
520 % \begin{function}[EXP, pTF, updated = 2011-09-15]
521 % {
522 % \prop_if_in:Nn, \prop_if_in:NV, \prop_if_in:Ne, \prop_if_in:No,
523 % \prop_if_in:cn, \prop_if_in:cV, \prop_if_in:ce, \prop_if_in:co
524 % }
525 % \begin{syntax}
526 % \cs{prop_if_in_p:Nn} \meta{property list} \Arg{key}
527 % \cs{prop_if_in:NnTF} \meta{property list} \Arg{key} \Arg{true code} \Arg{false code}
528 % \end{syntax}
529 % Tests if the \meta{key} is present in the \meta{property list},
530 % making the comparison using the method described by \cs{str_if_eq:nnTF}.
531 % \begin{texnote}
532 % For \enquote{flat} property lists, this expandable function iterates
533 % through every key--value pair and is therefore slower than a
534 % non-expandable approach based on \cs{prop_get:NnNTF}.
535 % (For \enquote{linked} property lists both functions are fast.)
536 % \end{texnote}
537 % \end{function}
538 %
539 % \section{Recovering values from property lists with branching}
540 %
541 % The functions in this section combine tests for the presence of a key
542 % in a property list with recovery of the associated valued. This makes them
543 % useful for cases where different code follows depending on the presence
544 % or absence of a key in a property list. They offer increased readability
545 % and performance over separate testing and recovery phases.
546 %
547 % \begin{function}[TF, updated = 2012-05-19]
548 % {
549 % \prop_get:NnN, \prop_get:NVN, \prop_get:NvN, \prop_get:NeN,
550 % \prop_get:NoN,
551 % \prop_get:cnN, \prop_get:cVN, \prop_get:cvN, \prop_get:ceN,
552 % \prop_get:coN,
553 % \prop_get:cnc
554 % }
555 % \begin{syntax}
556 % \cs{prop_get:NnNTF} \meta{property list} \Arg{key} \meta{tl~var} \\
557 % ~~\Arg{true code} \Arg{false code}
558 % \end{syntax}
559 % If the \meta{key} is not present in the \meta{property list}, leaves
560 % the \meta{false code} in the input stream. The value of the
561 % \meta{tl~var} is not defined in this case and should
562 % not be relied upon. If the \meta{key} is present in the
563 % \meta{property list}, stores the corresponding \meta{value} in the
564 % \meta{tl~var} without removing it from the
565 % \meta{property list}, then leaves the \meta{true code} in the input
566 % stream. The \meta{tl~var} is assigned locally.
567 % \end{function}
568 %
569 % \begin{function}[TF, added = 2011-08-18, updated = 2012-05-19]
570 % {
571 % \prop_pop:NnN, \prop_pop:NVN,
572 % \prop_pop:NoN,
573 % \prop_pop:cnN, \prop_pop:cVN,
574 % \prop_pop:coN
575 % }
576 % \begin{syntax}
577 % \cs{prop_pop:NnNTF} \meta{property list} \Arg{key} \meta{tl~var} \\
578 % ~~\Arg{true code} \Arg{false code}
579 % \end{syntax}
580 % If the \meta{key} is not present in the \meta{property list}, leaves
581 % the \meta{false code} in the input stream. The value of the
582 % \meta{tl~var} is not defined in this case and should
583 % not be relied upon. If the \meta{key} is present in
584 % the \meta{property list}, pops the corresponding \meta{value}
585 % in the \meta{tl~var}, i.e., removes the item from
586 % the \meta{property list}.
587 % Both the \meta{property list} and the \meta{tl~var}
588 % are assigned locally.
589 % \end{function}
590 %
591 % \begin{function}[TF, added = 2011-08-18, updated = 2012-05-19]
592 % {
593 % \prop_gpop:NnN, \prop_gpop:NVN,
594 % \prop_gpop:NoN,
595 % \prop_gpop:cnN, \prop_gpop:cVN,
596 % \prop_gpop:coN
597 % }
598 % \begin{syntax}
599 % \cs{prop_gpop:NnNTF} \meta{property list} \Arg{key} \meta{tl~var} \\
600 % ~~\Arg{true code} \Arg{false code}
601 % \end{syntax}
602 % If the \meta{key} is not present in the \meta{property list}, leaves
603 % the \meta{false code} in the input stream. The value of the
604 % \meta{tl~var} is not defined in this case and should
605 % not be relied upon. If the \meta{key} is present in
606 % the \meta{property list}, pops the corresponding \meta{value}
607 % in the \meta{tl~var}, i.e., removes the item from
608 % the \meta{property list}.
609 % The \meta{property list} is modified globally, while the
610 % \meta{tl~var} is assigned locally.
611 % \end{function}
612 %
613 % \section{Mapping over property lists}
614 %
615 % All mappings are done at the current group level, i.e., any
616 % local assignments made by the \meta{function} or \meta{code} discussed
617 % below remain in effect after the loop.
618 %
619 % \begin{function}[rEXP, updated = 2013-01-08]
620 % {\prop_map_function:NN, \prop_map_function:cN}
621 % \begin{syntax}
622 % \cs{prop_map_function:NN} \meta{property list} \meta{function}
623 % \end{syntax}
624 % Applies \meta{function} to every \meta{entry} stored in the
625 % \meta{property list}. The \meta{function} receives two arguments for
626 % each iteration: the \meta{key} and associated \meta{value}.
627 % The order in which \meta{entries} are returned is not defined and
628 % should not be relied upon.
629 % To pass further arguments to the \meta{function}, see
630 % \cs{prop_map_inline:Nn} (non-expandable) or \cs{prop_map_tokens:Nn}.
631 % \end{function}
632 %
633 % \begin{function}[updated = 2013-01-08]
634 % {\prop_map_inline:Nn, \prop_map_inline:cn}
635 % \begin{syntax}
636 % \cs{prop_map_inline:Nn} \meta{property list} \Arg{inline function}
637 % \end{syntax}
638 % Applies \meta{inline function} to every \meta{entry} stored
639 % within the \meta{property list}. The \meta{inline function} should
640 % consist of code which receives the \meta{key} as |#1| and the
641 % \meta{value} as |#2|.
642 % The order in which \meta{entries} are returned is not defined and
643 % should not be relied upon.
644 % \end{function}
645 %
646 % \begin{function}[rEXP]
647 % {\prop_map_tokens:Nn, \prop_map_tokens:cn}
648 % \begin{syntax}
649 % \cs{prop_map_tokens:Nn} \meta{property list} \Arg{code}
650 % \end{syntax}
651 % Analogue of \cs{prop_map_function:NN} which maps several tokens
652 % instead of a single function. The \meta{code} receives each
653 % key--value pair in the \meta{property list} as two trailing brace
654 % groups. For instance,
655 % \begin{verbatim}
656 % \prop_map_tokens:Nn \l_my_prop { \str_if_eq:nnT { mykey } }
657 % \end{verbatim}
658 % expands to the value corresponding to \texttt{mykey}: for each
659 % pair in |\l_my_prop| the function \cs{str_if_eq:nnT} receives
660 % \texttt{mykey}, the \meta{key} and the \meta{value} as its three
661 % arguments. For that specific task, \cs{prop_item:Nn} is faster.
662 % \end{function}
663 %
664 % \begin{function}[rEXP, updated = 2012-06-29]{\prop_map_break:}
665 % \begin{syntax}
666 % \cs{prop_map_break:}
667 % \end{syntax}
668 % Used to terminate a \cs[no-index]{prop_map_\ldots} function before all
669 % entries in the \meta{property list} have been processed. This
670 % normally takes place within a conditional statement, for example
671 % \begin{verbatim}
672 % \prop_map_inline:Nn \l_my_prop
673 % {
674 % \str_if_eq:nnTF { #1 } { bingo }
675 % { \prop_map_break: }
676 % {
677 % % Do something useful
678 % }
679 % }
680 % \end{verbatim}
681 % Use outside of a \cs[no-index]{prop_map_\ldots} scenario leads to low
682 % level \TeX{} errors.
683 % \begin{texnote}
684 % When the mapping is broken, additional tokens may be inserted
685 % before further items are taken
686 % from the input stream. This depends on the design of the mapping
687 % function.
688 % \end{texnote}
689 % \end{function}
690 %
691 % \begin{function}[rEXP, updated = 2012-06-29]{\prop_map_break:n}
692 % \begin{syntax}
693 % \cs{prop_map_break:n} \Arg{code}
694 % \end{syntax}
695 % Used to terminate a \cs[no-index]{prop_map_\ldots} function before all
696 % entries in the \meta{property list} have been processed, inserting
697 % the \meta{code} after the mapping has ended. This
698 % normally takes place within a conditional statement, for example
699 % \begin{verbatim}
700 % \prop_map_inline:Nn \l_my_prop
701 % {
702 % \str_if_eq:nnTF { #1 } { bingo }
703 % { \prop_map_break:n { <code> } }
704 % {
705 % % Do something useful
706 % }
707 % }
708 % \end{verbatim}
709 % Use outside of a \cs[no-index]{prop_map_\ldots} scenario leads to low
710 % level \TeX{} errors.
711 % \begin{texnote}
712 % When the mapping is broken, additional tokens may be inserted
713 % before the \meta{code} is
714 % inserted into the input stream.
715 % This depends on the design of the mapping function.
716 % \end{texnote}
717 % \end{function}
718 %
719 % \section{Viewing property lists}
720 %
721 % \begin{function}[updated = 2021-04-29]{\prop_show:N, \prop_show:c}
722 % \begin{syntax}
723 % \cs{prop_show:N} \meta{property list}
724 % \end{syntax}
725 % Displays the entries in the \meta{property list} in the terminal,
726 % and specifies its storage type.
727 % \end{function}
728 %
729 % \begin{function}[added = 2014-08-12, updated = 2021-04-29]{\prop_log:N, \prop_log:c}
730 % \begin{syntax}
731 % \cs{prop_log:N} \meta{property list}
732 % \end{syntax}
733 % Writes the entries in the \meta{property list} in the log file,
734 % and specifies its storage type.
735 % \end{function}
736 %
737 % \section{Scratch property lists}
738 %
739 % There is no need to include both flat and linked property lists as
740 % scratch variables. We arbitrarily pick the older implementation.
741 %
742 % \begin{variable}[added = 2012-06-23]{\l_tmpa_prop, \l_tmpb_prop}
743 % Scratch \enquote{flat} property lists for local assignment.
744 % These are never used by
745 % the kernel code, and so are safe for use with any \LaTeX3-defined
746 % function. However, they may be overwritten by other non-kernel
747 % code and so should only be used for short-term storage.
748 % \end{variable}
749 %
750 % \begin{variable}[added = 2012-06-23]{\g_tmpa_prop, \g_tmpb_prop}
751 % Scratch \enquote{flat} property lists for global assignment.
752 % These are never used by
753 % the kernel code, and so are safe for use with any \LaTeX3-defined
754 % function. However, they may be overwritten by other non-kernel
755 % code and so should only be used for short-term storage.
756 % \end{variable}
757 %
758 % \section{Constants}
759 %
760 % \begin{variable}{\c_empty_prop}
761 % A permanently-empty property list used for internal comparisons.
762 % \end{variable}
763 %
764 % \end{documentation}
765 %
766 % \begin{implementation}
767 %
768 % \section{\pkg{l3prop} implementation}
769 %
770 % \TestFiles{m3prop001, m3prop002, m3prop003, m3prop004, m3show001}
771 %
772 % \begin{macrocode}
773 %<*code>
774 % \end{macrocode}
775 %
776 % \begin{macrocode}
777 %<@@=prop>
778 % \end{macrocode}
779 %
780 % With the (default) flat data storage, a property list is a macro whose
781 % top-level expansion is of the form
782 % \begin{quote}
783 % \cs{s_@@} \cs{@@_chk:w}
784 % \cs{@@_pair:wn} \meta{key_1} \cs{s_@@} \Arg{value_1} \\
785 % \ldots{} \\
786 % \cs{@@_pair:wn} \meta{key_n} \cs{s_@@} \Arg{value_n} \\
787 % \end{quote}
788 % where \cs{s_@@} is a scan mark (equal to \cs{scan_stop:}), \cs{@@_chk:w}
789 % produces a suitable error if the property list is used directly in the input
790 % stream, and \cs{@@_pair:wn} can be used to map through the property list.
791 %
792 % With the linked data storage, each property list entry
793 % \meta{key_i}--\meta{value_i} is stored into a token list
794 % \cs[no-index]{@@~\meta{prefix}~\meta{key_i}}. The \meta{prefix} is one or
795 % more characters (no spaces), constructed automatically only once, when the
796 % property list is initially declared. The control sequence name does not
797 % conform to standard naming for variables because (1) this is an internal
798 % control sequence, not really a \pkg{expl3} variable; (2) keeping track of the
799 % scope |l| or~|g| throughout all functions would be a pretty big mess,
800 % especially if users accidentally mix local and global use (we would have to
801 % always check for such mistakes, rather than only checking when suitable debug
802 % options are set); (3) shorter control sequence names use less memory and are
803 % quicker in case of hash collisions, which may matter since we are using many
804 % control sequences.
805 %
806 % We need to enable mapping through such a property list, but without storing a
807 % list of all entries anywhere: this is achieved by making each of these token
808 % lists also store a pointer to the next entry. To enable efficient deletion,
809 % the token lists also store a pointer to the previous entry. This means we
810 % have a doubly-linked list. To avoid having to special-case the two ends of
811 % the doubly-linked list when deleting entries, we include as a zeroth entry in
812 % the doubly-linked list the property list variable itself, and we include as an
813 % $(n+1)$-th entry in the doubly-linked list an end-pointer
814 % \cs{@@~\meta{prefix}} (no trailing space, so it differs from an empty key).
815 % The space before \meta{prefix} ensures there is no collision with
816 % other \pkg{l3prop} internal functions, even if we have very many
817 % linked property lists being defined.
818 %
819 % The property list variable itself is a token list of the form
820 % \begin{quote}
821 % \cs{@@_flatten:w} \cs{@@~\meta{prefix}} \cs{s_@@} \Arg{prefix}
822 % \cs[no-index]{@@~\meta{prefix}~\meta{key_1}}
823 % \end{quote}
824 % Here, \cs{@@_flatten:w} serves as an efficiently recognized marker, and when
825 % \texttt{f}-expanded it is tasked with fully unpacking the property list into
826 % the same form as the default data storage so as to ease conversion. The
827 % \meta{prefix} is used when looking up an entry. The token list
828 % \cs{@@~\meta{prefix}} (see below) contains a pointer to the last key to help
829 % insert a new entry. The pointer to \meta{key_1} is needed to start a mapping.
830 % The token list labeled by \meta{key_i} is of the form
831 % \begin{quote}
832 % \cs{use_none:n} \cs[no-index]{@@~\meta{prefix}~\meta{key$_{i-1}$}}
833 % \cs{@@_pair:wn} \meta{key_i} \cs{s_@@} \Arg{value_i}
834 % \cs[no-index]{@@~\meta{prefix}~\meta{key$_{i+1}$}}
835 % \end{quote}
836 % where the pointer to \meta{key$_{i-1}$} is needed when deleting the
837 % \meta{key_i}. Expanding this will run \cs{@@_pair:wn} on the
838 % \meta{key_i}--\meta{value_i} pair (for speed, \meta{key_i} is kept as explicit
839 % tokens rather than slowly extracting it from a control sequence name), then
840 % move on to the next key, thus mapping through the whole list. The mapping is
841 % ended upon expanding \cs{@@~\meta{prefix}}, which is the token list
842 % \begin{quote}
843 % \cs{use_none:n} \cs[no-index]{@@~\meta{prefix}~\meta{key_n}}
844 % \end{quote}
845 % Let us think about deleting the \meta{key_i}. We need to update the
846 % \meta{key$_{i-1}$} and \meta{key$_{i+1}$} to point to each other
847 % instead of \meta{key_i}. To edit the corresponding token lists, it is
848 % important that \cs[no-index]{@@~\meta{prefix}~\meta{key_i}} be at the
849 % \enquote{same place} in the token lists also in the boundary cases
850 % $i=1$ or $i=n$, namely as the second token, or as the second argument
851 % after \cs{s_@@}.
852 %
853 % \subsection{Internal auxiliaries}
854 %
855 % \begin{macro}{\@@_tmp:w}
856 % Scratch macro, defined as needed, for instance to save \cs{@@_pair:wn} when
857 % concatenating.
858 % \begin{macrocode}
859 \cs_new_eq:NN \@@_tmp:w ?
860 % \end{macrocode}
861 % \end{macro}
862 %
863 % \begin{variable}{\l_@@_tmp_tl}
864 % Token list used in various places: for the prefix; when converting from flat
865 % to linked props; and to store the new key--value pair inserted by
866 % \cs{prop_put:Nnn}.
867 % \begin{macrocode}
868 \tl_new:N \l_@@_tmp_tl
869 % \end{macrocode}
870 % \end{variable}
871 %
872 % \begin{variable}{\s_@@_mark,\s_@@_stop}
873 % Internal scan marks.
874 % \begin{macrocode}
875 \scan_new:N \s_@@_mark
876 \scan_new:N \s_@@_stop
877 % \end{macrocode}
878 % \end{variable}
879 %
880 % \begin{variable}{\q_@@_recursion_tail,\q_@@_recursion_stop}
881 % Internal recursion quarks.
882 % \begin{macrocode}
883 \quark_new:N \q_@@_recursion_tail
884 \quark_new:N \q_@@_recursion_stop
885 % \end{macrocode}
886 % \end{variable}
887 %
888 % \begin{macro}[EXP]{\@@_if_recursion_tail_stop:n}
889 % \begin{macro}[EXP]{\@@_if_recursion_tail_stop:o}
890 % Functions to query recursion quarks.
891 % \begin{macrocode}
892 \__kernel_quark_new_test:N \@@_if_recursion_tail_stop:n
893 \cs_generate_variant:Nn \@@_if_recursion_tail_stop:n { o }
894 % \end{macrocode}
895 % \end{macro}
896 % \end{macro}
897 %
898 % \subsection{Structure of a property list}
899 %
900 % \begin{macro}{\s_@@}
901 % A private scan mark is used as a marker after each key, and at the
902 % very beginning of the property list.
903 % \begin{macrocode}
904 \scan_new:N \s_@@
905 % \end{macrocode}
906 % \end{macro}
907 %
908 % \begin{macro}{\@@_chk:w, \@@_chk_loop:nw, \@@_chk_get:nw}
909 % This removes the flat property list from the input stream and complains
910 % about a bad use of a property list. Since property lists do not have an
911 % end-marker, we slowly peek ahead in a loop. Speed does not matter since
912 % this is for an error situation. While \cs{@@_pair:wn} does not keep a fixed
913 % definition, it always includes the internal \cs{s_@@} in its argument
914 % specification, so that there is no risk of accidentally picking up a public
915 % token instead of \cs{@@_pair:wn} when doing a meaning test. We collect the
916 % keys and values to produce a more useful error message.
917 % \begin{macrocode}
918 \cs_new_protected:Npn \@@_chk:w { \@@_chk_loop:nw { } }
919 \cs_new_protected:Npn \@@_chk_loop:nw #1
920 {
921 \peek_meaning:NTF \@@_pair:wn
922 { \@@_chk_get:nw {#1} }
923 { \msg_error:nne { prop } { misused } {#1} }
924 }
925 \cs_new_protected:Npn \@@_chk_get:nw #1 \@@_pair:wn #2 \s_@@ #3
926 { \@@_chk_loop:nw { #1 , ~ {#2} = { \tl_to_str:n {#3} } } }
927 % \end{macrocode}
928 % \end{macro}
929 %
930 % \begin{macro}{\@@_pair:wn}
931 % Used as \cs{@@_pair:wn} \meta{key} \cs{s_@@} \Arg{item} for both storage
932 % types, this internal token starts each key--value pair in the property list.
933 % This default definition is changed globally by any mapping function, so
934 % there is not much point trying to make it an error. Instead, the error is
935 % produced by \cs{@@_chk:w}.
936 % \begin{macrocode}
937 \cs_new:Npn \@@_pair:wn #1 \s_@@ #2 { }
938 % \end{macrocode}
939 % \end{macro}
940 %
941 % \begin{macro}{\@@_flatten:w}
942 % We implement here the fact that \texttt{f}-expanding a linked property list
943 % gives a flat property list.
944 % Leaving a linked property list in the input stream will turn it into a flat
945 % property list so that the error implemented by \cs{@@_chk:w} will correctly
946 % be triggered.
947 % \begin{macrocode}
948 \cs_new_protected:Npn \@@_flatten:w #1 \s_@@ #2#3
949 { \use:e { \@@_flatten_aux:N #3 } }
950 % \end{macrocode}
951 % \end{macro}
952 %
953 % \begin{macro}[rEXP]
954 % {\@@_flatten:N, \@@_flatten_aux:w, \@@_flatten_aux:N, \@@_flatten_loop:w}
955 % The main function \cs{@@_flatten:N} receives a linked property list and
956 % flattens it. The auxiliary \cs{@@_flatten_aux:N} receives a pointer to the
957 % first key and flattens the linked property list into a flat property list.
958 % This is only restricted-expandable as it involves mapping through all of the
959 % property list's entries starting from \meta{key_1}. The looping function
960 % \cs{@@_flatten_loop:w} removes \cs{use_none:n} and a backwards pointer~|#2|,
961 % leaves the key--value pair for \cs{use:e} to receive, and calls itself
962 % again after expanding the next key's token list. Its argument |#3| is
963 % empty, except at the end where it is the \cs{use_none:nnnn} appearing in the
964 % definition of~\cs{@@_flatten_aux:N}, which ends the loop.
965 % \begin{macrocode}
966 \cs_new:Npn \@@_flatten:N #1
967 { \exp_after:wN \@@_flatten_aux:w #1 }
968 \cs_new:Npn \@@_flatten_aux:w #1 \s_@@ #2 { \@@_flatten_aux:N }
969 \cs_new:Npn \@@_flatten_aux:N #1
970 {
971 \s_@@ \@@_chk:w
972 \exp_after:wN \@@_flatten_loop:w #1
973 \use_none:nnnn \@@_pair:wn \s_@@ { }
974 }
975 \cs_new:Npn \@@_flatten_loop:w #1#2#3 \@@_pair:wn #4 \s_@@ #5
976 {
977 #3
978 \exp_not:n { \@@_pair:wn #4 \s_@@ {#5} }
979 \exp_after:wN \@@_flatten_loop:w
980 }
981 % \end{macrocode}
982 % \end{macro}
983 %
984 % \begin{variable}{\g_@@_prefix_int, \c_@@_basis_int}
985 % Used to assign prefixes for each linked property list. It is converted to
986 % base \cs{c_@@_basis_int}, then each digit is converted to a character,
987 % starting at |!| (the character after space).
988 % \begin{macrocode}
989 \int_new:N \g_@@_prefix_int
990 \int_const:Nn \c_@@_basis_int { \c_max_char_int - `\! }
991 % \end{macrocode}
992 % \end{variable}
993 %
994 % \begin{macro}{\@@_next_prefix:, \@@_to_prefix:n}
995 % Store in \cs{l_@@_tmp_tl} the conversion of \cs{g_@@_prefix_int} to
996 % characters, and increment this integer for use in the next linked property
997 % list. No need to optimize since this is only used when declaring the
998 % property list the first time.
999 % The aim here is to make this string as short as we can, given the
1000 % range of distinct characters available. This speeds up the work of
1001 % \cs{cs:w} \ldots{} \cs{cs_end:} that looks up keys in the hash table.
1002 % \begin{macrocode}
1003 \cs_new_protected:Npn \@@_next_prefix:
1004 {
1005 \tl_set:Ne \l_@@_tmp_tl
1006 { \@@_to_prefix:n { \g_@@_prefix_int } }
1007 \int_gincr:N \g_@@_prefix_int
1008 }
1009 \cs_new:Npn \@@_to_prefix:n #1
1010 {
1011 \int_compare:nNnTF {#1} > \c_@@_basis_int
1012 {
1013 \exp_args:Nf \@@_to_prefix:n
1014 { \int_div_truncate:nn {#1} \c_@@_basis_int }
1015 \exp_args:Nf \@@_to_prefix:n
1016 { \int_mod:nn {#1} \c_@@_basis_int }
1017 }
1018 { \char_generate:nn { `\! + #1 } { 12 } }
1019 }
1020 % \end{macrocode}
1021 % \end{macro}
1022 %
1023 % \begin{macro}{\@@_if_flat:NTF, \@@_if_flat_aux:w}
1024 % We could either test for the presence of \cs{@@_chk:w} (flat
1025 % property list) or of \cs{@@_flatten:w} (linked property list). We
1026 % make the second choice; this way props that are accidentally
1027 % \tn{relax} are treated as they were before. The auxiliary receives
1028 % \cs{use_i:nn} or \cs{use_ii:nn} as~|#3|.
1029 % As a transitional fix we avoid erroring in case the prop is undefined (the \cs{exp_after:wN} is omitted in that case, taking the flat branch).
1030 % \begin{macrocode}
1031 \cs_new:Npn \@@_if_flat:NTF #1
1032 {
1033 \prop_if_exist:NT #1
1034 \exp_after:wN \@@_if_flat_aux:w #1
1035 \s_@@_mark \use_ii:nn
1036 \@@_flatten:w \s_@@_mark \use_i:nn \s_@@_stop
1037 }
1038 \cs_new:Npn \@@_if_flat_aux:w
1039 #1 \@@_flatten:w #2 \s_@@_mark #3 #4 \s_@@_stop {#3}
1040 % \end{macrocode}
1041 % \end{macro}
1042 %
1043 % \subsection{Allocation and initialization}
1044 %
1045 % \begin{variable}[tested = m3prop004]{\c_empty_prop}
1046 % An empty flat prop.
1047 % \begin{macrocode}
1048 \tl_const:Nn \c_empty_prop { \s_@@ \@@_chk:w }
1049 % \end{macrocode}
1050 % \end{variable}
1051 %
1052 % \begin{macro}[tested = m3prop001]{\prop_new:N, \prop_new:c}
1053 % Flat property lists are initialized with the value \cs{c_empty_prop}.
1054 % \begin{macrocode}
1055 \cs_new_protected:Npn \prop_new:N #1
1056 {
1057 \__kernel_chk_if_free_cs:N #1
1058 \cs_gset_eq:NN #1 \c_empty_prop
1059 }
1060 \cs_generate_variant:Nn \prop_new:N { c }
1061 % \end{macrocode}
1062 % \end{macro}
1063 %
1064 % \begin{macro}[tested = m3prop001]{\prop_new_linked:N, \prop_new_linked:c}
1065 % \begin{macro}{\@@_new_linked:N}
1066 % The auxiliary is used in \cs{prop_make_linked:N}.
1067 % For linked property lists, get a new prefix in \cs{l_@@_tmp_tl}, then
1068 % use it to set up the internal structure: the last token in~|#1| is usually a
1069 % pointer to the first key, which is here the end-pointer. That end-pointer
1070 % has a pointer to the previous key (usually the last key), which is the
1071 % variable~|#1| itself that begins the doubly-linked list.
1072 % \begin{macrocode}
1073 \cs_new_protected:Npn \prop_new_linked:N #1
1074 {
1075 \__kernel_chk_if_free_cs:N #1
1076 \@@_new_linked:N #1
1077 }
1078 \cs_new_protected:Npn \@@_new_linked:N #1
1079 {
1080 \@@_next_prefix:
1081 \cs_gset_nopar:Npe #1
1082 {
1083 \@@_flatten:w
1084 \exp_not:c { @@ ~ \l_@@_tmp_tl }
1085 \s_@@ { \l_@@_tmp_tl }
1086 \exp_not:c { @@ ~ \l_@@_tmp_tl }
1087 }
1088 \cs_gset_nopar:cpe { @@ ~ \l_@@_tmp_tl }
1089 {
1090 \exp_not:N \use_none:n
1091 \exp_not:N #1
1092 }
1093 }
1094 \cs_generate_variant:Nn \prop_new_linked:N { c }
1095 % \end{macrocode}
1096 % \end{macro}
1097 % \end{macro}
1098 %
1099 % \begin{macro}[tested = m3prop001]{\prop_clear:N, \prop_clear:c}
1100 % \begin{macro}[tested = m3prop001]{\prop_gclear:N, \prop_gclear:c}
1101 % \begin{macro}{\@@_clear:NNN, \@@_clear:wNNN, \@@_clear_loop:Nw}
1102 % Clearing a flat property list is like declaring it anew, simply setting it
1103 % equal to \cs{c_empty_prop}. For linked property lists we must clear all of
1104 % the variables storing individual keys, which requires a loop. At each step
1105 % of the loop, \cs{@@_clear_loop:Nw} receives
1106 % \cs[index=cs_set_eq:NN]{cs_(g)set_eq:NN}, \cs{use_none:n}, the backwards
1107 % pointer, an empty~|#4| (except at the end of the loop), and the key--value
1108 % pair |#5=#6| which we disregard. The looping auxiliary undefines the
1109 % previous key's token list (this includes the main token list, but that is
1110 % fine because it is restored at the end) and calls itself after expanding the
1111 % next key's token list. The loop ends when |#4| is \cs{use_none:nnnn}.
1112 % After the loop, \cs{@@_clear:wNNN} correctly sets up the main variable~|#6|
1113 % and the end-pointer~|#1|. Importantly, this is done using
1114 % \cs[index=cs_set_nopar:Npe]{cs_(g)set_nopar:Npe} and \cs{exp_not:n} because
1115 % the almost-equivalent \cs{tl_set:Nn} would complain in debug mode about the
1116 % fact that the main variable is undefined at this stage. Importantly,
1117 % \cs{@@_clear_entries:NN} is used in the implementation of
1118 % \cs{prop_set_eq:NN}.
1119 % \begin{macrocode}
1120 \cs_new_protected:Npn \prop_clear:N
1121 { \@@_clear:NNN \cs_set_eq:NN \cs_set_nopar:Npe }
1122 \cs_generate_variant:Nn \prop_clear:N { c }
1123 \cs_new_protected:Npn \prop_gclear:N
1124 { \@@_clear:NNN \cs_gset_eq:NN \cs_gset_nopar:Npe }
1125 \cs_generate_variant:Nn \prop_gclear:N { c }
1126 \cs_new_protected:Npn \@@_clear:NNN #1#2#3
1127 {
1128 \@@_if_flat:NTF #3
1129 { #1 #3 \c_empty_prop }
1130 { \exp_after:wN \@@_clear:wNNN #3 #1 #2 #3 }
1131 }
1132 \cs_new_protected:Npn \@@_clear:wNNN
1133 \@@_flatten:w #1 \s_@@ #2#3#4#5#6
1134 {
1135 \@@_clear_entries:NN #4 #3
1136 #5 #6 { \exp_not:n { \@@_flatten:w #1 \s_@@ {#2} #1 } }
1137 #5 #1 { \exp_not:n { \use_none:n #6 } }
1138 }
1139 \cs_new_protected:Npn \@@_clear_entries:NN #1#2
1140 {
1141 \exp_after:wN \@@_clear_loop:Nw \exp_after:wN #1 #2
1142 \use_none:nnnn \@@_pair:wn \s_@@ { }
1143 }
1144 \cs_new_protected:Npn \@@_clear_loop:Nw
1145 #1#2#3#4 \@@_pair:wn #5 \s_@@ #6
1146 {
1147 #1 #3 \tex_undefined:D
1148 #4
1149 \exp_after:wN \@@_clear_loop:Nw
1150 \exp_after:wN #1
1151 }
1152 % \end{macrocode}
1153 % \end{macro}
1154 % \end{macro}
1155 % \end{macro}
1156 %
1157 % \begin{macro}[tested = m3prop001]
1158 % {
1159 % \prop_clear_new:N, \prop_clear_new:c,
1160 % \prop_gclear_new:N, \prop_gclear_new:c,
1161 % \prop_clear_new_linked:N, \prop_clear_new_linked:c,
1162 % \prop_gclear_new_linked:N, \prop_gclear_new_linked:c
1163 % }
1164 % A simple variation of the token list functions.
1165 % \begin{macrocode}
1166 \cs_new_protected:Npn \prop_clear_new:N #1
1167 { \prop_if_exist:NTF #1 { \prop_clear:N #1 } { \prop_new:N #1 } }
1168 \cs_generate_variant:Nn \prop_clear_new:N { c }
1169 \cs_new_protected:Npn \prop_gclear_new:N #1
1170 { \prop_if_exist:NTF #1 { \prop_gclear:N #1 } { \prop_new:N #1 } }
1171 \cs_generate_variant:Nn \prop_gclear_new:N { c }
1172 \cs_new_protected:Npn \prop_clear_new_linked:N #1
1173 { \prop_if_exist:NTF #1 { \prop_clear:N #1 } { \prop_new_linked:N #1 } }
1174 \cs_generate_variant:Nn \prop_clear_new_linked:N { c }
1175 \cs_new_protected:Npn \prop_gclear_new_linked:N #1
1176 { \prop_if_exist:NTF #1 { \prop_gclear:N #1 } { \prop_new_linked:N #1 } }
1177 \cs_generate_variant:Nn \prop_gclear_new_linked:N { c }
1178 % \end{macrocode}
1179 % \end{macro}
1180 %
1181 % \begin{macro}[tested = m3prop001]
1182 % {\prop_set_eq:NN, \prop_set_eq:cN, \prop_set_eq:Nc, \prop_set_eq:cc}
1183 % \begin{macro}[tested = m3prop001]
1184 % {\prop_gset_eq:NN, \prop_gset_eq:cN, \prop_gset_eq:Nc, \prop_gset_eq:cc}
1185 % \begin{macro}
1186 % {
1187 % \@@_set_eq:NNNN, \@@_set_eq:wNNNN, \@@_set_eq:nNnNN,
1188 % \@@_set_eq_loop:NNnw, \@@_set_eq_end:w
1189 % }
1190 % If both variables are accidentally the same variable (or equal flat property
1191 % lists, as it turns out) we do nothing, otherwise the following code would
1192 % lose all entries. If the target variable~|#3| is a flat prop, either copy
1193 % directly or flatten before copying. If it is a linked prop, we must clear
1194 % it, then go through the entries in~|#4| to add them to~|#3|.
1195 % \begin{macrocode}
1196 \cs_new_protected:Npn \prop_set_eq:NN
1197 { \@@_set_eq:NNNN \cs_set_eq:NN \cs_set_nopar:Npe }
1198 \cs_generate_variant:Nn \prop_set_eq:NN { Nc , cN , cc }
1199 \cs_new_protected:Npn \prop_gset_eq:NN
1200 { \@@_set_eq:NNNN \cs_gset_eq:NN \cs_gset_nopar:Npe }
1201 \cs_generate_variant:Nn \prop_gset_eq:NN { Nc , cN , cc }
1202 \cs_new_protected:Npn \@@_set_eq:NNNN #1#2#3#4
1203 {
1204 \cs_if_eq:NNF #3#4
1205 {
1206 \@@_if_flat:NTF #3
1207 {
1208 \@@_if_flat:NTF #4
1209 { #1 #3 #4 }
1210 { #2 #3 { \@@_flatten:N #4 } }
1211 }
1212 { \exp_after:wN \@@_set_eq:wNNNN #3 #1#2#3#4 }
1213 }
1214 }
1215 \cs_new_protected:Npn \@@_set_eq:wNNNN
1216 \@@_flatten:w #1 \s_@@ #2#3#4#5#6#7
1217 {
1218 \@@_clear_entries:NN #4 #3
1219 \exp_args:Nf \@@_set_eq:nNnNN {#7} #1 {#2} #5 #6
1220 }
1221 % \end{macrocode}
1222 % We have used that |f|-expanding either type of prop gives a flat prop. At
1223 % this stage \cs{@@_set_eq:nNnNN} receives the second variable as a flat prop,
1224 % the end-pointer, the prefix, the suitable
1225 % \cs[index=cs_set_nopar:Npe]{cs_(g)set_nopar:Npe} assignment, and the first
1226 % variable itself. Remove the leading \cs{s_@@} and \cs{@@_chk:w} with
1227 % \cs{use_i:nnn}, then start the loop.
1228 % \begin{macrocode}
1229 \cs_new_protected:Npn \@@_set_eq:nNnNN #1#2#3#4#5
1230 {
1231 \use_i:nnn
1232 {
1233 \@@_set_eq_loop:NNnw #5 #4 {#3}
1234 \@@_flatten:w #2 \s_@@ {#3}
1235 }
1236 #1
1237 \use_none:n \@@_pair:wn ? \s_@@
1238 }
1239 % \end{macrocode}
1240 % The looping function receives the current pointer~|#1| (initially the
1241 % variable itself), the defining function~|#2| and the prefix~|#3|, then a
1242 % partial definition~|#4| (which in later stages includes the backwards
1243 % pointer), followed by the current value as \cs{s_@@} |{#5}|. It seeks the
1244 % next key~|#7| to construct in \cs{l_@@_tmp_tl} the next pointer
1245 % \cs[no-index]{@@~\meta{prefix}~\meta{next key}} (the
1246 % argument~|#6| is empty, except at the end of the loop, where it is
1247 % \cs{use_none:n} in such a way as to delete the \meta{space} and \meta{next
1248 % key}). Then the token list (current pointer)~|#1| is set-up to contain the
1249 % partial definition and current value, as well as the newly constructed next
1250 % pointer. After a line responsible for correctly ending the loop with
1251 % \cs{@@_set_eq_end:w}, we loop, setting up the next definition, which starts
1252 % with \cs{use_none:n} and a backwards pointer to~|#1| followed by the
1253 % \meta{next key}~|#7| and so on.
1254 % \begin{macrocode}
1255 \cs_new_protected:Npn \@@_set_eq_loop:NNnw
1256 #1#2#3#4 \s_@@ #5#6 \@@_pair:wn #7 \s_@@
1257 {
1258 \tl_set:Ne \l_@@_tmp_tl { \exp_not:c { @@ ~ #3 #6 ~ #7 } }
1259 #2 #1 { \exp_not:n { #4 \s_@@ {#5} } \exp_not:o \l_@@_tmp_tl }
1260 \use_none:n #6 \@@_set_eq_end:w
1261 \exp_after:wN \@@_set_eq_loop:NNnw \l_@@_tmp_tl #2 {#3}
1262 \use_none:n #1 \@@_pair:wn #7 \s_@@
1263 }
1264 % \end{macrocode}
1265 % The end-code picks up what is needed to correctly assign the last token
1266 % list (the end pointer), which is simply \cs{use_none:n}
1267 % \cs[no-index]{@@_\meta{prefix}\meta{space}\meta{key_n}}.
1268 % \begin{macrocode}
1269 \cs_new_protected:Npn \@@_set_eq_end:w
1270 \exp_after:wN \@@_set_eq_loop:NNnw #1#2#3
1271 \use_none:n #4#5 \s_@@
1272 {
1273 \exp_after:wN #2 \l_@@_tmp_tl { \exp_not:n { \use_none:n #4 } }
1274 }
1275 % \end{macrocode}
1276 % \end{macro}
1277 % \end{macro}
1278 % \end{macro}
1279 %
1280 % \begin{macro}{\prop_make_flat:N, \prop_make_flat:c \@@_make_flat:Nn}
1281 % The only interesting case is when given a linked prop. Clear the
1282 % linked property list using \cs{@@_clear:wNNN} with local assignments
1283 % (it does not matter since we are at the outermost group level, and
1284 % \cs{cs_set_eq:NN} is very slightly faster than its global version.
1285 % Then store the contents (expanded preventively by \cs{exp_args:NNf})
1286 % with an assignment \cs{cs_set_nopar:Npe} that does not perform
1287 % \pkg{l3debug} checks.
1288 % \begin{macrocode}
1289 \cs_new_protected:Npn \prop_make_flat:N #1
1290 {
1291 \int_compare:nNnTF { \tex_currentgrouplevel:D } = 0
1292 {
1293 \@@_if_flat:NTF #1 { }
1294 { \exp_args:NNf \@@_make_flat:Nn #1 {#1} }
1295 }
1296 {
1297 \msg_error:nnee { prop } { inner-make }
1298 { \token_to_str:N \prop_make_flat:N } { \token_to_str:N #1 }
1299 }
1300 }
1301 \cs_generate_variant:Nn \prop_make_flat:N { c }
1302 \cs_new_protected:Npn \@@_make_flat:Nn #1#2
1303 {
1304 \exp_after:wN \@@_clear:wNNN #1 \cs_set_eq:NN \cs_set_nopar:Npe #1
1305 \cs_set_nopar:Npe #1 { \exp_not:n {#2} }
1306 }
1307 % \end{macrocode}
1308 % \end{macro}
1309 %
1310 % \begin{macro}{\prop_make_linked:N, \prop_make_linked:c, \@@_make_linked:Nn}
1311 % The only interesting case is when given a flat prop. We expand the
1312 % contents for later use. Then \cs{@@_new_linked:N} disregards that
1313 % previous value of~|#1| and initializes the linked prop. We can then
1314 % use an auxiliary \cs{@@_set_eq:wNNNN} underlying
1315 % \cs{prop_set_eq:NN}, with the prop contents saved as
1316 % \cs{l_@@_tmp_tl}. That step is a bit unsafe, as
1317 % \cs{l_@@_tmp_tl} (really, a flat prop here) is used within
1318 % \cs{@@_set_eq:wNNNN} itself, but it is in fact expanded early enough
1319 % to be ok.
1320 % \begin{macrocode}
1321 \cs_new_protected:Npn \prop_make_linked:N #1
1322 {
1323 \int_compare:nNnTF { \tex_currentgrouplevel:D } = 0
1324 {
1325 \@@_if_flat:NTF #1
1326 { \exp_args:NNo \@@_make_linked:Nn #1 {#1} } { }
1327 }
1328 {
1329 \msg_error:nnee { prop } { inner-make }
1330 { \token_to_str:N \prop_make_linked:N } { \token_to_str:N #1 }
1331 }
1332 }
1333 \cs_generate_variant:Nn \prop_make_linked:N { c }
1334 \cs_new_protected:Npn \@@_make_linked:Nn #1#2
1335 {
1336 \@@_new_linked:N #1
1337 \tl_set:Nn \l_@@_tmp_tl {#2}
1338 \exp_after:wN \@@_set_eq:wNNNN #1
1339 \cs_set_eq:NN \cs_set_nopar:Npe #1 \l_@@_tmp_tl
1340 }
1341 % \end{macrocode}
1342 % \end{macro}
1343 %
1344 % \begin{variable}[tested = m3prop004]{\l_tmpa_prop, \l_tmpb_prop}
1345 % \begin{variable}[tested = m3prop004]{\g_tmpa_prop, \g_tmpb_prop}
1346 % We can now initialize the scratch variables.
1347 % \begin{macrocode}
1348 \prop_new:N \l_tmpa_prop
1349 \prop_new:N \l_tmpb_prop
1350 \prop_new:N \g_tmpa_prop
1351 \prop_new:N \g_tmpb_prop
1352 % \end{macrocode}
1353 % \end{variable}
1354 % \end{variable}
1355 %
1356 % \begin{macro}
1357 % {
1358 % \prop_concat:NNN, \prop_concat:ccc,
1359 % \prop_gconcat:NNN, \prop_gconcat:ccc,
1360 % \@@_concat:NNNNN, \@@_concat:nNNN
1361 % }
1362 % The basic strategy is to copy the first variable into the target,
1363 % then loop through the second variable, calling
1364 % \cs[index=prop_put:Nnn]{prop_(g)put:Nnn} on each item. To avoid
1365 % running the \pkg{l3debug} scope checks on each of these steps, we
1366 % use the auxiliaries that underly \cs{prop_set_eq:NN} and
1367 % \cs{prop_put:Nnn}, whose syntax is a bit unwieldy.
1368 % We work directly with the target prop |#3| as a scratch space,
1369 % because copying over from a temporary variable to |#3| would be slow
1370 % in the linked case. If |#5| is |#3| itself we have to be careful
1371 % not to lose the data, and we even take the opportunity to skip the
1372 % copying step completely. To keep the correct version of the
1373 % duplicate keys we use the code underlying \cs{prop_put_if_not_in:Nnn},
1374 % which involves passing \cs{use_none:nnn} to the auxiliary instead of
1375 % nothing.
1376 % There is no need to check for the case where |#3| is equal to~|#4|
1377 % because in that case \cs[index=prop_set_eq:NN]{prop_(g)set_eq:NN}
1378 % |#3| |#4| (or rather the underlying auxiliary) is correctly set up
1379 % to do no needless work.
1380 % \begin{macrocode}
1381 \cs_new_protected:Npn \prop_concat:NNN
1382 { \@@_concat:NNNNN \cs_set_eq:NN \cs_set_nopar:Npe }
1383 \cs_generate_variant:Nn \prop_concat:NNN { ccc }
1384 \cs_new_protected:Npn \prop_gconcat:NNN
1385 { \@@_concat:NNNNN \cs_gset_eq:NN \cs_gset_nopar:Npe }
1386 \cs_generate_variant:Nn \prop_gconcat:NNN { ccc }
1387 \cs_new_protected:Npn \@@_concat:NNNNN #1#2#3#4#5
1388 {
1389 \cs_if_eq:NNTF #3 #5
1390 { \@@_concat:nNNN \use_none:nnn #2 #3 #4 }
1391 {
1392 \@@_set_eq:NNNN #1 #2 #3 #4
1393 \@@_concat:nNNN { } #2 #3 #5
1394 }
1395 }
1396 \cs_new_protected:Npn \@@_concat:nNNN #1#2#3#4
1397 {
1398 \cs_gset_eq:NN \@@_tmp:w \@@_pair:wn
1399 \cs_gset_protected:Npn \@@_pair:wn ##1 \s_@@
1400 { \@@_put:nNNnn {#1} #2 #3 {##1} }
1401 \exp_last_unbraced:Nf \use_none:nn #4
1402 \cs_gset_eq:NN \@@_pair:wn \@@_tmp:w
1403 }
1404 % \end{macrocode}
1405 % \end{macro}
1406 %
1407 % \begin{macro}
1408 % {
1409 % \prop_put_from_keyval:Nn, \prop_put_from_keyval:cn,
1410 % \prop_gput_from_keyval:Nn, \prop_gput_from_keyval:cn,
1411 % \@@_from_keyval:nn, \@@_from_keyval:Nnn,
1412 % \@@_missing_eq:n
1413 % }
1414 % The core is a call to \cs{keyval_parse:nnn}, with an error message
1415 % \cs{@@_missing_eq:n} for entries without~|=|, and a call to (essentially)
1416 % \cs[index=prop_put:Nnn]{prop_(g)put:Nnn} for valid key--value pairs.
1417 % To avoid repeated scope checks (and errors) when \pkg{l3debug} is
1418 % active, we instead use the auxiliary underlying \cs{prop_put:Nnn}.
1419 % Because blank keys are valid here, in contrast to \pkg{l3keys}, we set and
1420 % restore \cs{l__kernel_keyval_allow_blank_keys_bool}.
1421 % The key--value argument may be quite large so we avoid reading it until it
1422 % is really necessary.
1423 % \begin{macrocode}
1424 \cs_new_protected:Npn \prop_put_from_keyval:Nn #1
1425 { \@@_from_keyval:nn { \@@_put:nNNnn { } \cs_set_nopar:Npe #1 } }
1426 \cs_generate_variant:Nn \prop_put_from_keyval:Nn { c }
1427 \cs_new_protected:Npn \prop_gput_from_keyval:Nn #1
1428 { \@@_from_keyval:nn { \@@_put:nNNnn { } \cs_gset_nopar:Npe #1 } }
1429 \cs_generate_variant:Nn \prop_gput_from_keyval:Nn { c }
1430 \cs_new_protected:Npn \@@_from_keyval:nn
1431 {
1432 \bool_if:NTF \l__kernel_keyval_allow_blank_keys_bool
1433 { \@@_from_keyval:Nnn \c_true_bool }
1434 { \@@_from_keyval:Nnn \c_false_bool }
1435 }
1436 \cs_new_protected:Npn \@@_from_keyval:Nnn #1#2#3
1437 {
1438 \bool_set_eq:NN \l__kernel_keyval_allow_blank_keys_bool \c_true_bool
1439 \keyval_parse:nnn \@@_missing_eq:n {#2} {#3}
1440 \bool_set_eq:NN \l__kernel_keyval_allow_blank_keys_bool #1
1441 }
1442 \cs_new_protected:Npn \@@_missing_eq:n
1443 { \msg_error:nnn { prop } { prop-keyval } }
1444 % \end{macrocode}
1445 % \end{macro}
1446 %
1447 % \begin{macro}
1448 % {
1449 % \prop_set_from_keyval:Nn, \prop_set_from_keyval:cn,
1450 % \prop_gset_from_keyval:Nn, \prop_gset_from_keyval:cn,
1451 % }
1452 % Just empty the prop (with the auxiliary underlying
1453 % \cs{prop_clear:N} to avoid \pkg{l3debug} problems) and push
1454 % key--value entries using
1455 % \cs[index=prop_put_from_keyval:Nn]{prop_(g)put_from_keyval:Nn}.
1456 % \begin{macrocode}
1457 \cs_new_protected:Npn \prop_set_from_keyval:Nn #1
1458 {
1459 \@@_clear:NNN \cs_set_eq:NN \cs_set_nopar:Npe #1
1460 \prop_put_from_keyval:Nn #1
1461 }
1462 \cs_generate_variant:Nn \prop_set_from_keyval:Nn { c }
1463 \cs_new_protected:Npn \prop_gset_from_keyval:Nn #1
1464 {
1465 \@@_clear:NNN \cs_gset_eq:NN \cs_gset_nopar:Npe #1
1466 \prop_gput_from_keyval:Nn #1
1467 }
1468 \cs_generate_variant:Nn \prop_gset_from_keyval:Nn { c }
1469 % \end{macrocode}
1470 % \end{macro}
1471 %
1472 % \begin{macro}
1473 % {
1474 % \prop_const_from_keyval:Nn, \prop_const_from_keyval:cn,
1475 % \prop_const_linked_from_keyval:Nn, \prop_const_linked_from_keyval:cn
1476 % }
1477 % For both flat and linked constant props, we create |#1| then use the
1478 % same auxiliary as for \cs{prop_gput_from_keyval:Nn}. It is most
1479 % natural to use the already packaged \cs{prop_gput:Nnn}, but that
1480 % would mean doing an assignment on a supposedly constant property
1481 % list. To avoid errors when \pkg{l3debug} is activated, we use the
1482 % auxiliary underlying \cs{prop_gput:Nnn}.
1483 % \begin{macrocode}
1484 \cs_new_protected:Npn \prop_const_from_keyval:Nn #1
1485 {
1486 \prop_new:N #1
1487 \@@_from_keyval:nn { \@@_put:nNNnn { } \cs_gset_nopar:Npe #1 }
1488 }
1489 \cs_generate_variant:Nn \prop_const_from_keyval:Nn { c }
1490 \cs_new_protected:Npn \prop_const_linked_from_keyval:Nn #1
1491 {
1492 \prop_new_linked:N #1
1493 \@@_from_keyval:nn { \@@_put:nNNnn { } \cs_gset_nopar:Npe #1 }
1494 }
1495 \cs_generate_variant:Nn \prop_const_linked_from_keyval:Nn { c }
1496 % \end{macrocode}
1497 % \end{macro}
1498 %
1499 % \subsection{Accessing data in property lists}
1500 %
1501 % Accessing/deleting/adding entries is mostly done by \cs{@@_split:NnTFn}, which
1502 % must be fast because it is used in many \pkg{l3prop} functions. Its syntax is
1503 % as follows.
1504 % \begin{quote}
1505 % \cs{@@_split:NnTFn} \meta{property list} \Arg{key} \\
1506 % ~~\Arg{true code} \Arg{false code} \Arg{link code}
1507 % \end{quote}
1508 % If the \meta{property list} uses the linked data storage, then it runs
1509 % the \meta{link code}, otherwise it does as follows.
1510 %
1511 % It splits the \meta{property list} at the \meta{key}, giving three
1512 % token lists: the \meta{entries before} the \meta{key}, the
1513 % \meta{value} associated with the \meta{key} and the \meta{entries
1514 % after} the \meta{key}. Both the \meta{entries before} and the
1515 % \meta{entries after} can be empty or consist of some number of
1516 % consecutive entries \cs{@@_pair:wn} \meta{key_i} \cs{s_@@}
1517 % \Arg{value_i}. If the \meta{key} is present in the \meta{property
1518 % list} then the \meta{true code} is left in the input stream, with
1519 % |#1|, |#2|, and |#3| replaced by the \meta{entries before},
1520 % \meta{value}, and \meta{entries after}. If the \meta{key} is not
1521 % present in the \meta{property list} then the \meta{false code} is left
1522 % in the input stream. Only the \meta{true code} is used in the
1523 % replacement text of a macro defined internally, which requires
1524 % |##|~doubling.
1525 %
1526 % \begin{macro}
1527 % {
1528 % \@@_split:NnTFn, \@@_split_aux:nNTFn, \@@_split_test:wn,
1529 % \@@_split_flat:w, \@@_split_linked:w, \@@_split_wrong:Nw
1530 % }
1531 % The aim is to distinguish four cases: a flat prop that contains the
1532 % given \meta{key}, a flat prop that does not contain it, a linked
1533 % prop, and an invalid prop. The last case includes those that are
1534 % set to \tn{relax} by \texttt{c}-expansion, as well as unrelated
1535 % token list variables since these unfortunately used to
1536 % \enquote{work} in earlier implementations.
1537 % In the first three cases we run the \texttt{T}, \texttt{F}, and
1538 % \texttt{n} arguments, and in the last case we raise an error, set
1539 % the variable to a known state (empty prop), and run the \texttt{F}
1540 % code (some conditionals such as \cs{prop_pop:NnNTF} otherwise blow
1541 % up pretty badly).
1542 %
1543 % The first distinction between these cases is done by
1544 % \cs{@@_split_test:wn}, which looks for the argument after \cs{s_@@}.
1545 % For a flat prop it will be \cs{@@_chk:w}, which leads to running
1546 % \cs{@@_split_flat:w}, explained below. For a linked prop it is the
1547 % prefix, consisting of characters, so we end up running
1548 % \cs{@@_split_linked:w}, which cleans up and selects the
1549 % aforementioned \texttt{n} argument. For invalid props, or rather,
1550 % variables that do not contain \cs{s_@@}, the argument includes
1551 % \cs{fi:}, and we end up calling \cs{@@_split_wrong:Nw}, which calls
1552 % \cs{prop_show:N} to raise a detailed error stating how the variable
1553 % is wrong.
1554 %
1555 % Let us return to \cs{@@_split_flat:w}. This function is defined
1556 % dynamically as
1557 % \begin{quote}
1558 % \cs{cs_set:Npn} \cs{@@_split_flat:w} \cs{@@_split_linked:w} |#1| \\
1559 % \quad \cs{@@_pair:wn} \meta{key} \cs{s_@@} |#2| \\
1560 % \quad |#3| \cs{s_@@_mark} |#4| |#5| \cs{s_@@_stop} \\
1561 % \quad |{| |#4| \Arg{true code} |}|
1562 % \end{quote}
1563 % Its job is to seek the \meta{key} in the property list (known to be
1564 % flat at this stage) by using an argument |#1| delimited essentially
1565 % by that key. If indeed the variable contained the \meta{key}, then
1566 % |#1|~is the \meta{extract_1} before the key--value pair, |#2|~is the
1567 % \meta{value} associated with the \meta{key}, |#3|~is the
1568 % \meta{extract_2} after the key--value pair, |#4|~is \cs{use_i:nnn},
1569 % and we run \cs{use_i:nnn} \Arg{true code} \Arg{false code} \Arg{link
1570 % code}, selecting the \meta{true code}. Otherwise, the whole
1571 % property list together with \cs{s_@@_mark} \cs{use_i:nnn} is taken
1572 % in as |#1|, then |#2| is some tokens |?| \cs{fi:}
1573 % \cs{@@_split_wrong:Nw} \meta{variable} that were only useful in the
1574 % case of invalid props, |#3|~is empty, and most importantly |#4| is
1575 % \cs{use_ii:nnn}. This command selects the \meta{false code}.
1576 %
1577 % Note that we define \cs{@@_split_flat:w} in all cases even though it
1578 % is only used in the flat case. Indeed, to avoid taking in the whole
1579 % property list (which may be large) as an argument more than strictly
1580 % necessary, we would have to keep the \meta{true code} positioned
1581 % before the expansion of the prop variable in order to use it in the
1582 % definition. The only way to do that is to store it using an
1583 % assignment so we might as well just perform the assignment that we
1584 % can actually use in the flat case.
1585 % \begin{macrocode}
1586 \cs_new_protected:Npn \@@_split:NnTFn #1#2
1587 {
1588 \exp_after:wN \@@_split_aux:nNTFn
1589 \exp_after:wN { \tl_to_str:n {#2} } #1
1590 }
1591 \cs_new_protected:Npn \@@_split_aux:nNTFn #1#2#3
1592 {
1593 \cs_set:Npn \@@_split_flat:w \@@_split_linked:w ##1
1594 \@@_pair:wn #1 \s_@@ ##2 ##3 \s_@@_mark ##4 ##5 \s_@@_stop
1595 { ##4 {#3} }
1596 \exp_after:wN \@@_split_test:wn #2 \s_@@_mark \use_i:nnn
1597 \@@_pair:wn #1 \s_@@ { ? \fi: \@@_split_wrong:Nw #2 }
1598 \s_@@_mark \use_ii:nnn
1599 \s_@@_stop
1600 }
1601 \cs_new:Npn \@@_split_flat:w { }
1602 \cs_new_protected:Npn \@@_split_test:wn #1 \s_@@ #2
1603 {
1604 \if_meaning:w \@@_chk:w #2 \exp_after:wN \@@_split_flat:w \fi:
1605 \@@_split_linked:w
1606 }
1607 \cs_new_protected:Npn \@@_split_linked:w #1 \s_@@_stop #2#3 {#3}
1608 \cs_new_protected:Npn \@@_split_wrong:Nw #1#2 \s_@@_stop #3#4
1609 {
1610 \prop_show:N #1
1611 \cs_gset_eq:NN #1 \c_empty_prop
1612 #3
1613 }
1614 % \end{macrocode}
1615 % \end{macro}
1616 %
1617 % \begin{macro}[tested = m3prop002]
1618 % {
1619 % \prop_get:NnN, \prop_get:NVN, \prop_get:NvN, \prop_get:NeN,
1620 % \prop_get:NoN, \prop_get:NxN,
1621 % \prop_get:cnN, \prop_get:cVN, \prop_get:cvN, \prop_get:ceN,
1622 % \prop_get:coN, \prop_get:cxN,
1623 % \prop_get:cnc
1624 % }
1625 % \begin{macro}[TF, tested = m3prop004]
1626 % {
1627 % \prop_get:NnN, \prop_get:NVN, \prop_get:NvN, \prop_get:NeN,
1628 % \prop_get:NoN, \prop_get:NxN,
1629 % \prop_get:cnN, \prop_get:cVN, \prop_get:cvN, \prop_get:ceN,
1630 % \prop_get:coN, \prop_get:cxN,
1631 % \prop_get:cnc
1632 % }
1633 % \begin{macro}{\@@_get:NnnTF}
1634 % \begin{macro}[EXP]{\@@_get_linked:w, \@@_get_linked_aux:w}
1635 % Here we implement both \cs{prop_get:NnN} and its branching version through
1636 % \cs{@@_get:NnnTF}. It receives the prop and key, followed by an assignment
1637 % used when the value is found, \meta{true code} to run after the assignment,
1638 % and some fall-back \meta{false code} for absent values. It relies on
1639 % \cs{@@_split:NnTFn}. For a flat prop, the first four arguments of
1640 % \cs{@@_split:NnTFn} are used, and run either the assignment~|#3{##3}| and
1641 % \meta{true code}~|#4|, or the \meta{false code}~|#5|.
1642 % \begin{macrocode}
1643 \cs_new_protected:Npn \prop_get:NnN #1#2#3
1644 {
1645 \@@_get:NnnTF #1 {#2}
1646 { \tl_set:Nn #3 } { } { \tl_set:Nn #3 { \q_no_value } }
1647 }
1648 \cs_generate_variant:Nn \prop_get:NnN { NV , Nv , Ne , c , cV , cv , ce }
1649 \cs_generate_variant:Nn \prop_get:NnN { No , Nx , co , cx }
1650 \cs_generate_variant:Nn \prop_get:NnN { cnc }
1651 \prg_new_protected_conditional:Npnn \prop_get:NnN #1#2#3 { T , F , TF }
1652 {
1653 \@@_get:NnnTF #1 {#2}
1654 { \tl_set:Nn #3 } \prg_return_true: \prg_return_false:
1655 }
1656 \prg_generate_conditional_variant:Nnn \prop_get:NnN
1657 { NV , Nv , Ne , c , cV , cv , ce } { T , F , TF }
1658 \prg_generate_conditional_variant:Nnn \prop_get:NnN
1659 { No , Nx , co , cx } { T , F , TF }
1660 \prg_generate_conditional_variant:Nnn \prop_get:NnN
1661 { cnc } { T , F , TF }
1662 \cs_new_protected:Npn \@@_get:NnnTF #1#2#3#4#5
1663 {
1664 \@@_split:NnTFn #1 {#2}
1665 { #3 {##2} #4 }
1666 {#5}
1667 { \exp_after:wN \@@_get_linked:w #1 {#2} {#3} {#4} {#5} }
1668 }
1669 % \end{macrocode}
1670 % For a linked prop we must work a bit: \cs{@@_get_linked:w} is followed by
1671 % the expansion of the prop, then by four brace groups: the key~|#4|, the
1672 % assignment code~|#5|, \meta{true code}~|#6|, and \meta{false code}~|#7|. If
1673 % the key is present, its value is stored in the token list
1674 % \cs[no-index]{@@_}|#2~#4|. If that token list exists,
1675 % \cs{@@_get_linked_aux:w} gets called followed by the expansion of that token
1676 % list and we grab as~|#2| the value associated to that key, which we feed to
1677 % the assignment code and follow-up code. If the key is absent the token list
1678 % can be \tn{undefined} or \tn{relax}. In both cases \cs{@@_get_linked_aux:w}
1679 % finds an empty brace group as~|#2|, \cs{use_none:n} as~|#4| and the
1680 % \meta{false code} as~|#5|.
1681 % Note that we made \cs{@@_get_linked:w} and subsequent auxiliaries
1682 % expandable, because they are also used in \cs{prop_item:Nn}.
1683 % \begin{macrocode}
1684 \cs_new:Npn \@@_get_linked:w
1685 \@@_flatten:w #1 \s_@@ #2#3#4#5#6#7
1686 {
1687 \if_cs_exist:w @@ ~ #2 ~ \tl_to_str:n {#4} \cs_end:
1688 \exp_after:wN \exp_after:wN \exp_after:wN \@@_get_linked_aux:w
1689 \cs:w @@ ~ #2 ~ \tl_to_str:n {#4} \exp_after:wN \cs_end:
1690 \else:
1691 \exp_after:wN \@@_get_linked_aux:w
1692 \fi:
1693 \s_@@_mark {#5} {#6}
1694 \s_@@ { } \s_@@_mark \use_none:n {#7}
1695 \s_@@_stop
1696 }
1697 \cs_new:Npn \@@_get_linked_aux:w
1698 #1 \s_@@ #2 #3 \s_@@_mark #4 #5 #6 \s_@@_stop { #4 {#2} #5 }
1699 % \end{macrocode}
1700 % \end{macro}
1701 % \end{macro}
1702 % \end{macro}
1703 % \end{macro}
1704 %
1705 % \begin{macro}[EXP]
1706 % {
1707 % \prop_item:Nn, \prop_item:NV, \prop_item:No, \prop_item:Ne,
1708 % \prop_item:cn, \prop_item:cV, \prop_item:co, \prop_item:ce
1709 % }
1710 % \begin{macro}[EXP]{\@@_item:nnn}
1711 % Getting the value corresponding to a key in a flat property list in an
1712 % expandable fashion simply uses \cs{prop_map_tokens:Nn} to go through
1713 % the property list. The auxiliary \cs{@@_item:nnn} receives the
1714 % search string~|#1|, the key~|#2| and the value~|#3| and returns as
1715 % appropriate.
1716 % \begin{macrocode}
1717 \cs_new:Npn \prop_item:Nn #1#2
1718 {
1719 \@@_if_flat:NTF #1
1720 {
1721 \exp_args:NNo \prop_map_tokens:Nn #1
1722 {
1723 \exp_after:wN \@@_item:nnn
1724 \exp_after:wN { \tl_to_str:n {#2} }
1725 }
1726 }
1727 { \exp_after:wN \@@_get_linked:w #1 {#2} \exp_not:n { } { } }
1728 }
1729 \cs_new:Npn \@@_item:nnn #1#2#3
1730 {
1731 \str_if_eq:eeT {#1} {#2}
1732 { \prop_map_break:n { \exp_not:n {#3} } }
1733 }
1734 \cs_generate_variant:Nn \prop_item:Nn { NV , No , Ne , c , cV , co , ce }
1735 % \end{macrocode}
1736 % \end{macro}
1737 % \end{macro}
1738 %
1739 % \subsection{Removing data from property lists}
1740 %
1741 % \begin{macro}
1742 % {
1743 % \@@_pop:NnNNnTF,
1744 % \@@_pop_linked:wnNNnTF, \@@_pop_linked:NNNn,
1745 % \@@_pop_linked:w,
1746 % \@@_pop_linked_prev:w, \@@_pop_linked_next:w
1747 % }
1748 % This auxiliary is used by both the \cs[no-index]{prop_pop} family and
1749 % the \cs[no-index]{prop_remove} family of functions.
1750 % It receives a \meta{prop} and a \Arg{key}, three assignment functions
1751 % (\cs{tl_set:Nn} \cs{cs_set_eq:NN} \cs{cs_set_nopar:Npe} or their global
1752 % versions), then \Arg{code} \Arg{true code} \Arg{false code}.
1753 %
1754 % For a flat prop, split it. If the \meta{key} is there, reconstruct the rest
1755 % of the prop from the two extracts |##2| |##4| and assign using
1756 % \cs[index=tl_set:Nn]{tl_(g)set:Nn}, then run \meta{code} \Arg{value} with
1757 % the \meta{value} found, and run the \meta{true code}. If the \meta{key} is
1758 % absent, run the \meta{false code}.
1759 %
1760 % For a linked prop, the removal is done by \cs{@@_pop_linked:wnNNnTF}, which
1761 % removes the key--value pair from the doubly-linked list and runs its last
1762 % three arguments \Arg{code} \Arg{true code} \Arg{false code} depending on
1763 % whether the key--value is found, in the same way as for flat props.
1764 % \begin{macrocode}
1765 \cs_new_protected:Npn \@@_pop:NnNNnTF #1#2#3#4#5#6#7
1766 {
1767 \@@_split:NnTFn #1 {#2}
1768 {
1769 #4 #1 { \exp_not:n { \s_@@ \@@_chk:w ##1 ##3 } }
1770 #5 {##2}
1771 #6
1772 }
1773 {#7}
1774 {
1775 \exp_after:wN \@@_pop_linked:wnNNnTF #1 {#2}
1776 #3 #4 {#5} {#6} {#7}
1777 }
1778 }
1779 % \end{macrocode}
1780 % The next auxiliary \cs{@@_pop_linked:wnNNnTF}, together with the |NNNn|
1781 % auxiliary, checks if the key is present in the \meta{linked prop}, then the
1782 % corresponding value (if present) is passed as a braced argument to the
1783 % \meta{code} and the \meta{true code} or \meta{false code} is run as
1784 % appropriate. Before that, there are also three assignments: the token lists
1785 % for the previous key and next key are made to point to each other, cf.\
1786 % \cs{@@_pop_linked:w}, and the token list for the given key is made
1787 % undefined.
1788 % \begin{macrocode}
1789 \cs_new_protected:Npn \@@_pop_linked:wnNNnTF
1790 \@@_flatten:w #1 \s_@@ #2#3#4#5#6#7
1791 {
1792 \if_cs_exist:w @@ ~ #2 ~ \tl_to_str:n {#4} \cs_end:
1793 \exp_after:wN \@@_pop_linked:NNNn
1794 \cs:w @@ ~ #2 ~ \tl_to_str:n {#4} \cs_end:
1795 #5 #6 {#7}
1796 \else:
1797 \exp_after:wN \use_iii:nnn
1798 \fi:
1799 \use_i:nn
1800 }
1801 \cs_new_protected:Npn \@@_pop_linked:NNNn #1#2#3#4
1802 {
1803 \if_meaning:w \scan_stop: #1
1804 \exp_after:wN \exp_after:wN \exp_after:wN \use_iii:nnn
1805 \else:
1806 \exp_after:wN \@@_pop_linked:w #1 #1 #2 #3 {#4}
1807 \fi:
1808 }
1809 \cs_new_protected:Npn \@@_pop_linked:w
1810 \use_none:n #1#2 \s_@@ #3#4#5#6#7#8
1811 {
1812 #6 #5 \tex_undefined:D
1813 #7 #1
1814 {
1815 \exp_after:wN \@@_pop_linked_prev:w #1
1816 \exp_not:N #4
1817 }
1818 #7 #4
1819 {
1820 \exp_not:n { \use_none:n #1 }
1821 \exp_not:f { \exp_after:wN \@@_pop_linked_next:w #4 }
1822 }
1823 #8 {#3}
1824 }
1825 \cs_new:Npn \@@_pop_linked_prev:w #1 \s_@@ #2#3
1826 { \exp_not:n { #1 \s_@@ {#2} } }
1827 \cs_new:Npn \@@_pop_linked_next:w \use_none:n #1 { \exp_stop_f: }
1828 % \end{macrocode}
1829 % \end{macro}
1830 %
1831 % \begin{macro}[tested = m3prop002]
1832 % {
1833 % \prop_remove:Nn, \prop_remove:NV, \prop_remove:Ne,
1834 % \prop_remove:cn, \prop_remove:cV, \prop_remove:ce
1835 % }
1836 % \begin{macro}[tested = m3prop002]
1837 % {
1838 % \prop_gremove:Nn, \prop_gremove:NV, \prop_gremove:Ne,
1839 % \prop_gremove:cn, \prop_gremove:cV, \prop_gremove:ce
1840 % }
1841 % Deleting from a property relies on \cs{@@_pop:NnNNnTF}. The three
1842 % assignment functions are suitably local or global. The last three arguments
1843 % are \cs{use_none:n} and two empty brace groups: if the key is found we get
1844 % \cs{use_none:n} \Arg{key} \meta{empty}, which expands to nothing, and
1845 % otherwise we just get \meta{empty}. The auxiliary takes care of actually
1846 % removing the entry from the prop.
1847 % \begin{macrocode}
1848 \cs_new_protected:Npn \prop_remove:Nn #1#2
1849 {
1850 \@@_pop:NnNNnTF #1 {#2}
1851 \cs_set_eq:NN \cs_set_nopar:Npe
1852 \use_none:n { } { }
1853 }
1854 \cs_new_protected:Npn \prop_gremove:Nn #1#2
1855 {
1856 \@@_pop:NnNNnTF #1 {#2}
1857 \cs_gset_eq:NN \cs_gset_nopar:Npe
1858 \use_none:n { } { }
1859 }
1860 \cs_generate_variant:Nn \prop_remove:Nn { NV , Ne , c , cV , ce }
1861 \cs_generate_variant:Nn \prop_gremove:Nn { NV , Ne , c , cV , ce }
1862 % \end{macrocode}
1863 % \end{macro}
1864 % \end{macro}
1865 %
1866 % \begin{macro}[tested = m3prop002]
1867 % {
1868 % \prop_pop:NnN, \prop_pop:NVN, \prop_pop:NoN,
1869 % \prop_pop:cnN, \prop_pop:cVN, \prop_pop:coN,
1870 % \prop_gpop:NnN, \prop_gpop:NVN, \prop_gpop:NoN,
1871 % \prop_gpop:cnN, \prop_gpop:cVN, \prop_gpop:coN,
1872 % }
1873 % \begin{macro}[TF, tested = m3prop004]
1874 % {
1875 % \prop_pop:NnN, \prop_pop:NVN, \prop_pop:NoN,
1876 % \prop_pop:cnN, \prop_pop:cVN, \prop_pop:coN,
1877 % \prop_gpop:NnN, \prop_gpop:NVN, \prop_gpop:NoN,
1878 % \prop_gpop:cnN, \prop_gpop:cVN, \prop_gpop:coN,
1879 % }
1880 % Popping a value is almost the same, but the value found is kept.
1881 % For the non-branching version, we additionally set the target token list to
1882 % \cs{q_no_value}, while for the branching version we must produce
1883 % \cs{prg_return_true:} or \cs{prg_return_false:}.
1884 % \begin{macrocode}
1885 \cs_new_protected:Npn \prop_pop:NnN #1#2#3
1886 {
1887 \@@_pop:NnNNnTF #1 {#2}
1888 \cs_set_eq:NN \cs_set_nopar:Npe
1889 { \tl_set:Nn #3 } { } { \tl_set:Nn #3 { \q_no_value } }
1890 }
1891 \cs_new_protected:Npn \prop_gpop:NnN #1#2#3
1892 {
1893 \@@_pop:NnNNnTF #1 {#2}
1894 \cs_gset_eq:NN \cs_gset_nopar:Npe
1895 { \tl_set:Nn #3 } { } { \tl_set:Nn #3 { \q_no_value } }
1896 }
1897 \cs_generate_variant:Nn \prop_pop:NnN { NV , No }
1898 \cs_generate_variant:Nn \prop_pop:NnN { c , cV , co }
1899 \cs_generate_variant:Nn \prop_gpop:NnN { NV , No }
1900 \cs_generate_variant:Nn \prop_gpop:NnN { c , cV , co }
1901 \prg_new_protected_conditional:Npnn \prop_pop:NnN #1#2#3 { T , F , TF }
1902 {
1903 \@@_pop:NnNNnTF #1 {#2}
1904 \cs_set_eq:NN \cs_set_nopar:Npe
1905 { \tl_set:Nn #3 } \prg_return_true: \prg_return_false:
1906 }
1907 \prg_new_protected_conditional:Npnn \prop_gpop:NnN #1#2#3 { T , F , TF }
1908 {
1909 \@@_pop:NnNNnTF #1 {#2}
1910 \cs_gset_eq:NN \cs_gset_nopar:Npe
1911 { \tl_set:Nn #3 } \prg_return_true: \prg_return_false:
1912 }
1913 \prg_generate_conditional_variant:Nnn \prop_pop:NnN
1914 { NV , No , c , cV , co } { T , F , TF }
1915 \prg_generate_conditional_variant:Nnn \prop_gpop:NnN
1916 { NV , No , c , cV , co } { T , F , TF }
1917 % \end{macrocode}
1918 % \end{macro}
1919 % \end{macro}
1920 %
1921 % \subsection{Adding data to property lists}
1922 %
1923 % \begin{macro}[tested = m3prop002]
1924 % {
1925 % \prop_put:Nnn, \prop_put:NnV, \prop_put:Nnv, \prop_put:Nne,
1926 % \prop_put:NVn, \prop_put:NVV, \prop_put:NVv, \prop_put:NVe,
1927 % \prop_put:Nvn, \prop_put:NvV, \prop_put:Nvv, \prop_put:Nve,
1928 % \prop_put:Nen, \prop_put:NeV, \prop_put:Nev, \prop_put:Nee,
1929 % \prop_put:Nno, \prop_put:Non, \prop_put:Noo,
1930 % \prop_put:Nnx, \prop_put:NVx, \prop_put:NxV, \prop_put:Nxx,
1931 % \prop_put:cnn, \prop_put:cnV, \prop_put:cnv, \prop_put:cne,
1932 % \prop_put:cVn, \prop_put:cVV, \prop_put:cVv, \prop_put:cVe,
1933 % \prop_put:cvn, \prop_put:cvV, \prop_put:cvv, \prop_put:cve,
1934 % \prop_put:cen, \prop_put:ceV, \prop_put:cev, \prop_put:cee,
1935 % \prop_put:cno, \prop_put:con, \prop_put:coo,
1936 % \prop_put:cnx, \prop_put:cVx, \prop_put:cxV, \prop_put:cxx
1937 % }
1938 % \begin{macro}[tested = m3prop002]
1939 % {
1940 % \prop_gput:Nnn, \prop_gput:NnV, \prop_gput:Nnv, \prop_gput:Nne,
1941 % \prop_gput:NVn, \prop_gput:NVV, \prop_gput:NVv, \prop_gput:NVe,
1942 % \prop_gput:Nvn, \prop_gput:NvV, \prop_gput:Nvv, \prop_gput:Nve,
1943 % \prop_gput:Nen, \prop_gput:NeV, \prop_gput:Nev, \prop_gput:Nee,
1944 % \prop_gput:Nno, \prop_gput:Non, \prop_gput:Noo,
1945 % \prop_gput:Nnx, \prop_gput:NVx, \prop_gput:NxV, \prop_gput:Nxx,
1946 % \prop_gput:cnn, \prop_gput:cnV, \prop_gput:cnv, \prop_gput:cne,
1947 % \prop_gput:cVn, \prop_gput:cVV, \prop_gput:cVv, \prop_gput:cVe,
1948 % \prop_gput:cvn, \prop_gput:cvV, \prop_gput:cvv, \prop_gput:cve,
1949 % \prop_gput:cen, \prop_gput:ceV, \prop_gput:cev, \prop_gput:cee,
1950 % \prop_gput:cno, \prop_gput:con, \prop_gput:coo,
1951 % \prop_gput:cnx, \prop_gput:cVx, \prop_gput:cxV, \prop_gput:cxx
1952 % }
1953 % \begin{macro}[tested = m3prop002]
1954 % {
1955 % \prop_put_if_not_in:Nnn, \prop_put_if_not_in:NnV, \prop_put_if_not_in:Nnv, \prop_put_if_not_in:Nne,
1956 % \prop_put_if_not_in:NVn, \prop_put_if_not_in:NVV, \prop_put_if_not_in:NVv, \prop_put_if_not_in:NVe,
1957 % \prop_put_if_not_in:Nvn, \prop_put_if_not_in:NvV, \prop_put_if_not_in:Nvv, \prop_put_if_not_in:Nve,
1958 % \prop_put_if_not_in:Nen, \prop_put_if_not_in:NeV, \prop_put_if_not_in:Nev, \prop_put_if_not_in:Nee,
1959 % \prop_put_if_not_in:cnn, \prop_put_if_not_in:cnV, \prop_put_if_not_in:cnv, \prop_put_if_not_in:cne,
1960 % \prop_put_if_not_in:cVn, \prop_put_if_not_in:cVV, \prop_put_if_not_in:cVv, \prop_put_if_not_in:cVe,
1961 % \prop_put_if_not_in:cvn, \prop_put_if_not_in:cvV, \prop_put_if_not_in:cvv, \prop_put_if_not_in:cve,
1962 % \prop_put_if_not_in:cen, \prop_put_if_not_in:ceV, \prop_put_if_not_in:cev, \prop_put_if_not_in:cee,
1963 % \prop_gput_if_not_in:Nnn, \prop_gput_if_not_in:NnV, \prop_gput_if_not_in:Nnv, \prop_gput_if_not_in:Nne,
1964 % \prop_gput_if_not_in:NVn, \prop_gput_if_not_in:NVV, \prop_gput_if_not_in:NVv, \prop_gput_if_not_in:NVe,
1965 % \prop_gput_if_not_in:Nvn, \prop_gput_if_not_in:NvV, \prop_gput_if_not_in:Nvv, \prop_gput_if_not_in:Nve,
1966 % \prop_gput_if_not_in:Nen, \prop_gput_if_not_in:NeV, \prop_gput_if_not_in:Nev, \prop_gput_if_not_in:Nee,
1967 % \prop_gput_if_not_in:cnn, \prop_gput_if_not_in:cnV, \prop_gput_if_not_in:cnv, \prop_gput_if_not_in:cne,
1968 % \prop_gput_if_not_in:cVn, \prop_gput_if_not_in:cVV, \prop_gput_if_not_in:cVv, \prop_gput_if_not_in:cVe,
1969 % \prop_gput_if_not_in:cvn, \prop_gput_if_not_in:cvV, \prop_gput_if_not_in:cvv, \prop_gput_if_not_in:cve,
1970 % \prop_gput_if_not_in:cen, \prop_gput_if_not_in:ceV, \prop_gput_if_not_in:cev, \prop_gput_if_not_in:cee
1971 % }
1972 % \begin{macro}[tested = m3prop002]
1973 % {
1974 % \@@_put:NNNnn, \@@_put_linked:wnNN,
1975 % \@@_put_linked:NNNN, \@@_put_linked_old:w,
1976 % \@@_put_linked_new:w
1977 % }
1978 % All of the \cs[no-index]{prop_(g)put(_if_new):Nnn} functions are
1979 % based on the same auxiliary, which receives \meta{code} and an
1980 % \enquote{assignment}, followed by \meta{prop} \Arg{key} \Arg{new
1981 % value}. The
1982 % assignment \cs[index=cs_set_nopar:Npe]{cs_(g)set_nopar:Npe} is the
1983 % primitive assignment without any checking: in the case of linked
1984 % props it is applied to individual
1985 % pieces of the linked prop, which are typically not yet defined.
1986 % Debugging the scope of the variable is done at a higher level by
1987 % letting \pkg{l3debug} change \cs{prop_put:Nnn} and friends. This
1988 % allows other \pkg{l3prop} commands to directly call the underlying
1989 % auxiliary to skip this checking step and avoid getting multiple
1990 % error messages for the same error.
1991 % The \meta{code} (empty for |put| and \cs{use_none:nnn} for
1992 % |put_if_not_in|) is placed before the assignment in cases where the key
1993 % is already present, in order to suppress the assignment in the
1994 % |put_if_not_in| case.
1995 % \begin{macrocode}
1996 \cs_new_protected:Npn \prop_put:Nnn
1997 { \@@_put:nNNnn { } \cs_set_nopar:Npe }
1998 \cs_new_protected:Npn \prop_gput:Nnn
1999 { \@@_put:nNNnn { } \cs_gset_nopar:Npe }
2000 \cs_new_protected:Npn \prop_put_if_not_in:Nnn
2001 { \@@_put:nNNnn \use_none:nnn \cs_set_nopar:Npe }
2002 \cs_new_protected:Npn \prop_gput_if_not_in:Nnn
2003 { \@@_put:nNNnn \use_none:nnn \cs_gset_nopar:Npe }
2004 \cs_generate_variant:Nn \prop_put:Nnn
2005 {
2006 NnV , Nnv , Nne , NV , NVV , NVv , NVe ,
2007 Nv , NvV , Nvv , Nve , Ne , NeV , Nev , Nee
2008 }
2009 \cs_generate_variant:Nn \prop_put:Nnn
2010 { Nno , No , Noo , Nnx , NVx , NxV , Nxx }
2011 \cs_generate_variant:Nn \prop_put:Nnn
2012 {
2013 c , cnV , cnv , cne , cV , cVV , cVv , cVe ,
2014 cv , cvV , cvv , cve , ce , ceV , cev , cee
2015 }
2016 \cs_generate_variant:Nn \prop_put:Nnn
2017 { cno , co , coo , cnx , cVx , cxV , cxx }
2018 \cs_generate_variant:Nn \prop_gput:Nnn
2019 {
2020 NnV , Nnv , Nne , NV , NVV , NVv , NVe ,
2021 Nv , NvV , Nvv , Nve , Ne , NeV , Nev , Nee
2022 }
2023 \cs_generate_variant:Nn \prop_gput:Nnn
2024 { Nno , No , Noo , Nnx , NVx , NxV , Nxx }
2025 \cs_generate_variant:Nn \prop_gput:Nnn
2026 {
2027 c , cnV , cnv , cne , cV , cVV , cVv , cVe ,
2028 cv , cvV , cvv , cve , ce , ceV , cev , cee
2029 }
2030 \cs_generate_variant:Nn \prop_gput:Nnn
2031 { cno , co , coo , cnx , cVx , cxV , cxx }
2032 \cs_generate_variant:Nn \prop_put_if_not_in:Nnn
2033 {
2034 NnV , Nnv , Nne , NV , NVV , NVv , NVe ,
2035 Nv , NvV , Nvv , Nve , Ne , NeV , Nev , Nee ,
2036 c , cnV , cnv , cne , cV , cVV , cVv , cVe ,
2037 cv , cvV , cvv , cve , ce , ceV , cev , cee
2038 }
2039 \cs_generate_variant:Nn \prop_gput_if_not_in:Nnn
2040 {
2041 NnV , Nnv , Nne , NV , NVV , NVv , NVe ,
2042 Nv , NvV , Nvv , Nve , Ne , NeV , Nev , Nee ,
2043 c , cnV , cnv , cne , cV , cVV , cVv , cVe ,
2044 cv , cvV , cvv , cve , ce , ceV , cev , cee
2045 }
2046 % \end{macrocode}
2047 % Since the true branch of \cs{@@_split:NnTFn} is used as the
2048 % replacement text of an internal macro, and since the \meta{key} and
2049 % new \meta{value} may contain arbitrary tokens, it is not safe to
2050 % include them in the argument of \cs{@@_split:NnTFn}. We thus start
2051 % by storing in \cs{l_@@_tmp_tl} tokens which (after
2052 % \texttt{x}-expansion) encode the key--value pair. This variable can
2053 % safely be used in \cs{@@_split:NnTFn}. For a flat prop, if the
2054 % \meta{key} was absent, append the new key--value to the list;
2055 % otherwise concatenate the extracts |##2| and |##4| with the new
2056 % key--value pair \cs{l_@@_tmp_tl}. The updated entry is placed
2057 % at the same spot as the original \meta{key} in the property list,
2058 % preserving the order of entries. For a linked prop, call
2059 % \cs{@@_put_linked:wnNN}, which constructs the control sequence in
2060 % which we will place the new value. If it matches \cs{scan_stop:}
2061 % then the key was not yet there and we add it using
2062 % \cs{@@_put_linked_new:w}, otherwise it was already there and we use
2063 % \cs{@@_put_linked_old:w}.
2064 % \begin{macrocode}
2065 \cs_new_protected:Npn \@@_put:nNNnn #1#2#3#4#5
2066 {
2067 \tl_set:Nn \l_@@_tmp_tl
2068 {
2069 \exp_not:N \@@_pair:wn \tl_to_str:n {#4}
2070 \s_@@ { \exp_not:n {#5} }
2071 }
2072 \@@_split:NnTFn #3 {#4}
2073 {
2074 #1 #2 #3
2075 {
2076 \s_@@ \@@_chk:w \exp_not:n {##1}
2077 \l_@@_tmp_tl \exp_not:n {##3}
2078 }
2079 }
2080 { #2 #3 { \exp_not:o {#3} \l_@@_tmp_tl } }
2081 { \exp_after:wN \@@_put_linked:wnnN #3 {#4} {#1} #2 }
2082 }
2083 \cs_new_protected:Npn \@@_put_linked:wnnN
2084 \@@_flatten:w #1 \s_@@ #2#3#4
2085 {
2086 \exp_after:wN \@@_put_linked:NNnN
2087 \cs:w @@ ~ #2 ~ \tl_to_str:n {#4} \cs_end:
2088 #1
2089 }
2090 \cs_new_protected:Npn \@@_put_linked:NNnN #1#2#3#4
2091 {
2092 \if_meaning:w \scan_stop: #1
2093 \exp_after:wN \@@_put_linked_new:w #2 #1 #2 #4
2094 \else:
2095 \exp_after:wN \@@_put_linked_old:w #1 { #3 #4 #1 }
2096 \fi:
2097 }
2098 % \end{macrocode}
2099 % To add a new entry, \cs{@@_put_linked_new:w} receives the expansion
2100 % of the end-pointer, namely \cs{use_none:n} \meta{last key pointer},
2101 % followed by the new key pointer~|#2|, the end pointer~|#3|, and an
2102 % assignment function~|#4|. Set up the doubly-linked list in the
2103 % order |#1|, |#2|, |#3|, placing the key--value pair
2104 % \cs{l_@@_tmp_tl} in~|#2|. To replace an old entry,
2105 % \cs{@@_put_linked_old:w} receives the expansion of that entry, and
2106 % it reassigns it (|#5|) using the assignment~|#6|, by simply
2107 % replacing the payload |#2| \cs{s_@@} |#3| by \cs{l_@@_tmp_tl}.
2108 % \begin{macrocode}
2109 \cs_new_protected:Npn \@@_put_linked_new:w
2110 \use_none:n #1#2#3#4
2111 {
2112 #4 #1
2113 {
2114 \exp_after:wN \@@_pop_linked_prev:w #1
2115 \exp_not:N #2
2116 }
2117 #4 #2
2118 {
2119 \exp_not:n { \use_none:n #1 }
2120 \l_@@_tmp_tl
2121 \exp_not:N #3
2122 }
2123 #4 #3 { \exp_not:n { \use_none:n #2 } }
2124 }
2125 \cs_new_protected:Npn \@@_put_linked_old:w
2126 \use_none:n #1#2 \s_@@ #3#4#5
2127 {
2128 #5
2129 {
2130 \exp_not:n { \use_none:n #1 }
2131 \l_@@_tmp_tl
2132 \exp_not:N #4
2133 }
2134 }
2135 % \end{macrocode}
2136 % \end{macro}
2137 % \end{macro}
2138 % \end{macro}
2139 % \end{macro}
2140 %
2141 % \subsection{Property list conditionals}
2142 %
2143 % \begin{macro}[pTF, tested = m3prop004]{\prop_if_exist:N, \prop_if_exist:c}
2144 % Copies of the \texttt{cs} functions defined in \pkg{l3basics}.
2145 % \begin{macrocode}
2146 \prg_new_eq_conditional:NNn \prop_if_exist:N \cs_if_exist:N
2147 { TF , T , F , p }
2148 \prg_new_eq_conditional:NNn \prop_if_exist:c \cs_if_exist:c
2149 { TF , T , F , p }
2150 % \end{macrocode}
2151 % \end{macro}
2152 %
2153 % \begin{macro}[pTF, tested = m3prop003]{\prop_if_empty:N, \prop_if_empty:c}
2154 % \begin{macro}{\@@_if_empty_return:w}
2155 % A flat property list is empty if it matches \cs{c_empty_prop}. A linked
2156 % property list is empty if its second token (the end pointer) and last token
2157 % (the first key pointer) are equal. There cannot be false positives because
2158 % the end pointer takes the form \cs{use_none:n} \meta{pointer} while the
2159 % other pointers have more elaborate structure. The subtle code branch here
2160 % is when a non-empty flat property list is given: then \cs{@@_if_empty:w}
2161 % reads the whole property list as~|#1| and |#2|, |#3|, |#4| are |2|, |3|,
2162 % |4|, respectively.
2163 % \begin{macrocode}
2164 \prg_new_conditional:Npnn \prop_if_empty:N #1 { p , T , F , TF }
2165 {
2166 \if_meaning:w #1 \c_empty_prop
2167 \prg_return_true:
2168 \else:
2169 \exp_after:wN \@@_if_empty_return:w #1
2170 \@@_flatten:w 2 \s_@@ 34 \s_@@_stop
2171 \fi:
2172 }
2173 \cs_new:Npn \@@_if_empty_return:w
2174 #1 \@@_flatten:w #2 \s_@@ #3#4#5 \s_@@_stop
2175 {
2176 \if_meaning:w #2 #4
2177 \prg_return_true:
2178 \else:
2179 \prg_return_false:
2180 \fi:
2181 }
2182 \prg_generate_conditional_variant:Nnn \prop_if_empty:N
2183 { c } { p , T , F , TF }
2184 % \end{macrocode}
2185 % \end{macro}
2186 % \end{macro}
2187 %
2188 % \begin{macro}[pTF, tested = m3prop003]
2189 % {
2190 % \prop_if_in:Nn, \prop_if_in:NV, \prop_if_in:Ne, \prop_if_in:No,
2191 % \prop_if_in:cn, \prop_if_in:cV, \prop_if_in:ce, \prop_if_in:co
2192 % }
2193 % \begin{macro}[EXP]{\@@_if_in_flat:nnn}
2194 % For a linked prop, use \cs{@@_get_linked:w} to look up whether the control
2195 % sequence constructed from the prefix and the sought-after key exists; this
2196 % auxiliary calls \cs{use_none:n} \Arg{value} \cs{prg_return_true:} if the key
2197 % is found, and otherwise \cs{prg_return_false:}. For a flat prop, testing
2198 % expandably if a key is there requires to go through the key--value pairs one
2199 % by one. This is rather slow, and a faster test would be
2200 % \begin{verbatim}
2201 % \prg_new_protected_conditional:Npnn \prop_if_in:Nn #1 #2
2202 % {
2203 % \@@_split:NnTFn #1 {#2}
2204 % { \prg_return_true: }
2205 % { \prg_return_false: }
2206 % { ... }
2207 % }
2208 % \end{verbatim}
2209 % but \cs{@@_split:NnTFn} is non-expandable.
2210 % Instead, we use \cs{prop_map_tokens:Nn} to compare the search key to
2211 % each key in turn using \cs{str_if_eq:ee}, which is expandable.
2212 % \begin{macrocode}
2213 \prg_new_conditional:Npnn \prop_if_in:Nn #1#2 { p , T , F , TF }
2214 {
2215 \@@_if_flat:NTF #1
2216 {
2217 \exp_after:wN \prop_map_tokens:Nn \exp_after:wN #1
2218 {
2219 \exp_after:wN \@@_if_in_flat:nnn
2220 \exp_after:wN { \tl_to_str:n {#2} }
2221 }
2222 \prg_return_false:
2223 }
2224 {
2225 \exp_after:wN \@@_get_linked:w #1 {#2}
2226 \use_none:n \prg_return_true: \prg_return_false:
2227 }
2228 }
2229 \cs_new:Npn \@@_if_in_flat:nnn #1#2#3
2230 {
2231 \str_if_eq:eeT {#1} {#2}
2232 { \prop_map_break:n { \use_i:nn \prg_return_true: } }
2233 }
2234 \prg_generate_conditional_variant:Nnn \prop_if_in:Nn
2235 { NV , Ne , No , c , cV , ce , co } { p , T , F , TF }
2236 % \end{macrocode}
2237 % \end{macro}
2238 % \end{macro}
2239 %
2240 % \subsection{Mapping over property lists}
2241 %
2242 % \begin{macro}[tested = m3prop003]
2243 % {
2244 % \prop_map_function:NN, \prop_map_function:Nc,
2245 % \prop_map_function:cN, \prop_map_function:cc
2246 % }
2247 % \begin{macro}{\@@_map_function:Nw}
2248 % We first |f|-expand to flatten~|#1| in case it was a linked list.
2249 % The \cs{use_i:nnn} removes the leading \cs{s_@@} \cs{@@_chk:w} of
2250 % the flattened prop.
2251 % The even-numbered arguments of \cs{@@_map_function:Nw} are keys,
2252 % hence have string catcodes, except at the end where they are
2253 % \cs{fi:} \cs{prop_map_break:}. The \cs{fi:} ends the \cs{if_false:}
2254 % |#|\meta{even} \cs{fi:} construction and we jump out of the loop.
2255 % No need for any quark test.
2256 % \begin{macrocode}
2257 \cs_new:Npn \prop_map_function:NN #1#2
2258 {
2259 \exp_last_unbraced:Nnf
2260 \use_i:nnn { \@@_map_function:Nw #2 } #1
2261 \@@_pair:wn \fi: \prop_map_break: \s_@@ { }
2262 \@@_pair:wn \fi: \prop_map_break: \s_@@ { }
2263 \@@_pair:wn \fi: \prop_map_break: \s_@@ { }
2264 \@@_pair:wn \fi: \prop_map_break: \s_@@ { }
2265 \prg_break_point:Nn \prop_map_break: { }
2266 }
2267 \cs_new:Npn \@@_map_function:Nw #1
2268 \@@_pair:wn #2 \s_@@ #3
2269 \@@_pair:wn #4 \s_@@ #5
2270 \@@_pair:wn #6 \s_@@ #7
2271 \@@_pair:wn #8 \s_@@ #9
2272 {
2273 \if_false: #2 \fi: #1 {#2} {#3}
2274 \if_false: #4 \fi: #1 {#4} {#5}
2275 \if_false: #6 \fi: #1 {#6} {#7}
2276 \if_false: #8 \fi: #1 {#8} {#9}
2277 \@@_map_function:Nw #1
2278 }
2279 \cs_generate_variant:Nn \prop_map_function:NN { Nc , c , cc }
2280 % \end{macrocode}
2281 % \end{macro}
2282 % \end{macro}
2283 %
2284 % \begin{macro}[tested = m3prop003]{\prop_map_inline:Nn, \prop_map_inline:cn}
2285 % Mapping in line requires a nesting level counter. Store the current
2286 % definition of \cs{@@_pair:wn}, and define it anew. At the end of
2287 % the loop, revert to the earlier definition. Note that besides pairs
2288 % of the form \cs{@@_pair:wn} \meta{key} \cs{s_@@} \Arg{value}, there
2289 % are a leading and a trailing tokens, but both are equal to
2290 % \cs{scan_stop:}, hence have no effect in such inline mapping.
2291 % Such \cs{scan_stop:} could have affected ligatures if they appeared
2292 % during the mapping.
2293 % \begin{macrocode}
2294 \cs_new_protected:Npn \prop_map_inline:Nn #1#2
2295 {
2296 \cs_gset_eq:cN
2297 { @@_map_ \int_use:N \g__kernel_prg_map_int :wn } \@@_pair:wn
2298 \int_gincr:N \g__kernel_prg_map_int
2299 \cs_gset_protected:Npn \@@_pair:wn ##1 \s_@@ ##2 {#2}
2300 \exp_last_unbraced:Nf \use_none:nn #1
2301 \prg_break_point:Nn \prop_map_break:
2302 {
2303 \int_gdecr:N \g__kernel_prg_map_int
2304 \cs_gset_eq:Nc \@@_pair:wn
2305 { @@_map_ \int_use:N \g__kernel_prg_map_int :wn }
2306 }
2307 }
2308 \cs_generate_variant:Nn \prop_map_inline:Nn { c }
2309 % \end{macrocode}
2310 % \end{macro}
2311 %
2312 % \begin{macro}[rEXP]{\prop_map_tokens:Nn, \prop_map_tokens:cn}
2313 % \begin{macro}{\@@_map_tokens:nw}
2314 % The mapping is very similar to \cs{prop_map_function:NN}.
2315 % The odd construction
2316 % |\use:n {#1}| allows |#1| to contain any token without interfering
2317 % with \cs{prop_map_break:}. The loop stops when the \meta{key}
2318 % between \cs{@@_pair:wn} and \cs{s_@@} is \cs{fi:}
2319 % \cs{prop_map_break:} instead of being a string.
2320 % \begin{macrocode}
2321 \cs_new:Npn \prop_map_tokens:Nn #1#2
2322 {
2323 \exp_last_unbraced:Nnf
2324 \use_i:nnn { \@@_map_tokens:nw {#2} } #1
2325 \@@_pair:wn \fi: \prop_map_break: \s_@@ { }
2326 \@@_pair:wn \fi: \prop_map_break: \s_@@ { }
2327 \@@_pair:wn \fi: \prop_map_break: \s_@@ { }
2328 \@@_pair:wn \fi: \prop_map_break: \s_@@ { }
2329 \prg_break_point:Nn \prop_map_break: { }
2330 }
2331 \cs_new:Npn \@@_map_tokens:nw #1
2332 \@@_pair:wn #2 \s_@@ #3
2333 \@@_pair:wn #4 \s_@@ #5
2334 \@@_pair:wn #6 \s_@@ #7
2335 \@@_pair:wn #8 \s_@@ #9
2336 {
2337 \if_false: #2 \fi: \use:n {#1} {#2} {#3}
2338 \if_false: #4 \fi: \use:n {#1} {#4} {#5}
2339 \if_false: #6 \fi: \use:n {#1} {#6} {#7}
2340 \if_false: #8 \fi: \use:n {#1} {#8} {#9}
2341 \@@_map_tokens:nw {#1}
2342 }
2343 \cs_generate_variant:Nn \prop_map_tokens:Nn { c }
2344 % \end{macrocode}
2345 % \end{macro}
2346 % \end{macro}
2347 %
2348 %
2349 % \begin{macro}[tested = m3prop003]{\prop_map_break:}
2350 % \begin{macro}[tested = m3prop003]{\prop_map_break:n}
2351 % The break statements are based on the general \cs{prg_map_break:Nn}.
2352 % \begin{macrocode}
2353 \cs_new:Npn \prop_map_break:
2354 { \prg_map_break:Nn \prop_map_break: { } }
2355 \cs_new:Npn \prop_map_break:n
2356 { \prg_map_break:Nn \prop_map_break: }
2357 % \end{macrocode}
2358 % \end{macro}
2359 % \end{macro}
2360 %
2361 % \subsection{Uses of mapping over property lists}
2362 %
2363 % \begin{macro}[EXP]{\prop_count:N, \prop_count:c}
2364 % \begin{macro}[EXP]{\@@_count:nn}
2365 % Counting the key--value pairs in a property list is done using the
2366 % same approach as for other count functions: turn each entry into a
2367 % \texttt{+1} then use integer evaluation to actually do the
2368 % mathematics.
2369 % \begin{macrocode}
2370 \cs_new:Npn \prop_count:N #1
2371 {
2372 \int_eval:n
2373 {
2374 0
2375 \prop_map_function:NN #1 \@@_count:nn
2376 }
2377 }
2378 \cs_new:Npn \@@_count:nn #1#2 { + 1 }
2379 \cs_generate_variant:Nn \prop_count:N { c }
2380 % \end{macrocode}
2381 % \end{macro}
2382 % \end{macro}
2383 %
2384 % \begin{macro}[EXP]{\prop_to_keyval:N}
2385 % \begin{macro}[EXP]
2386 % {\@@_to_keyval_exp_after:wN, \@@_to_keyval:nn, \@@_to_keyval:nnw}
2387 % Each property name and value pair will be returned in the form
2388 % \verb*| |\marg{name}\verb*|= |\marg{value}. As one of the main use cases for
2389 % this macro is to pass the \meta{property list} on to a key--value parser, we
2390 % have to make sure that the behavior is as good as possible. Using a space
2391 % before the opening brace we get the correct brace stripping behavior for
2392 % most of the key--value parsers available in \LaTeX{}.
2393 % Iterate over the
2394 % \meta{property list} and remove the leading comma afterwards. Only the value
2395 % has to be protected in \cs{__kernel_exp_not:w} as the property name is
2396 % always a string. After the loop the leading comma is removed by
2397 % \cs{use_none:n} and afterwards \cs{__kernel_exp_not:w} eventually finds the
2398 % opening brace of its argument.
2399 % \begin{macrocode}
2400 \cs_new:Npn \prop_to_keyval:N #1
2401 {
2402 \__kernel_exp_not:w
2403 \prop_if_empty:NTF #1
2404 { {} }
2405 {
2406 \exp_after:wN \exp_after:wN \exp_after:wN
2407 {
2408 \tex_expanded:D
2409 {
2410 \exp_not:N \use_none:n
2411 \prop_map_function:NN #1 \@@_to_keyval:nn
2412 }
2413 }
2414 }
2415 }
2416 \cs_new:Npn \@@_to_keyval:nn #1#2
2417 { , ~ {#1} =~ { \__kernel_exp_not:w {#2} } }
2418 % \end{macrocode}
2419 % \end{macro}
2420 % \end{macro}
2421 %
2422 % \subsection{Viewing property lists}
2423 %
2424 % \begin{macro}[tested = m3show001]
2425 % {\prop_show:N, \prop_show:c, \prop_log:N, \prop_log:c}
2426 % \begin{macro}{\@@_show:NN, \@@_show_finally:NNn, \@@_show_prepare:w, \@@_show_loop:NNw, \@@_show_bad_name:NNN, \@@_show_end:NNN, \@@_show_loop_key:wNNN}
2427 % \begin{macro}[rEXP]{\@@_show_flat:w, \@@_show_linked:w}
2428 % Experience shows one source of problems is very hard to debug: when
2429 % a data structure such as a |seq| or~|prop| gets corrupted. In the
2430 % past, \cs{prop_show:N} would in some cases happily show items of
2431 % such a |prop|, even though other more demanding \pkg{l3prop}
2432 % functions would choke. It is thus best to make \cs{prop_show:N}
2433 % check very thoroughly the structure and flag issues, even though
2434 % that is very painful for linked props. Throughout the code below,
2435 % we strive to remain as safe as possible, but in the explanations we
2436 % only state what the arguments are when the prop is correctly formed,
2437 % rather than saying at every step that various arguments can be
2438 % arbitrary junk, made safe by using \cs{tl_to_str:n} generously.
2439 %
2440 % The general \cs{__kernel_chk_tl_type:NnnT} checks that its first
2441 % argument is a token list, and if it is, then it \texttt{e}-expands
2442 % its second argument and compares with the contents of its first
2443 % argument. Thus, within this \texttt{e}-expansion it is safe to use
2444 % \cs{@@_if_flat:NTF} to check if the prop is flat or linked. In the
2445 % flat case we simply reconstruct the expected structure using
2446 % \cs{@@_show_flat:w}, which loops through the prop and correctly
2447 % turns all keys to strings for instance. In the linked case, we use
2448 % \cs{@@_show_linked:w}, which ensures the form \cs{@@_flatten:w}
2449 % \cs[no-index]{@@~\meta{prefix}} \cs{s_@@} \Arg{prefix} \meta{rest},
2450 % where \meta{prefix} is made into a string and \meta{rest} cannot be
2451 % a brace group or multiple tokens since \cs{@@_show_linked:w} would
2452 % in such cases give a different result from the original token list.
2453 % \begin{macrocode}
2454 \cs_new_protected:Npn \prop_show:N { \@@_show:NN \msg_show:nneeee }
2455 \cs_generate_variant:Nn \prop_show:N { c }
2456 \cs_new_protected:Npn \prop_log:N { \@@_show:NN \msg_log:nneeee }
2457 \cs_generate_variant:Nn \prop_log:N { c }
2458 \cs_new_protected:Npn \@@_show:NN #1#2
2459 {
2460 \__kernel_chk_tl_type:NnnT #2 { prop }
2461 {
2462 \@@_if_flat:NTF #2
2463 {
2464 \s_@@ \@@_chk:w
2465 \exp_after:wN \@@_show_flat:w #2
2466 \s_@@ { }
2467 \@@_pair:wn \q_@@_recursion_tail \s_@@ { }
2468 \q_@@_recursion_stop
2469 }
2470 { \exp_after:wN \@@_show_linked:w #2 \s_@@ ! ? \s_@@_stop }
2471 }
2472 {
2473 \@@_if_flat:NTF #2
2474 { \@@_show_finally:NNn #1 #2 { flat } }
2475 {
2476 \tl_set:Nn \l_@@_tmp_tl { #1 #2 }
2477 \exp_after:wN \@@_show_prepare:w #2 #2
2478 }
2479 }
2480 }
2481 \cs_new:Npn \@@_show_flat:w #1 \@@_pair:wn #2 \s_@@ #3
2482 {
2483 \@@_if_recursion_tail_stop:n {#2}
2484 \exp_not:N \@@_pair:wn \tl_to_str:n {#2} \s_@@ \exp_not:n { {#3} }
2485 \@@_show_flat:w
2486 }
2487 \cs_new:Npn \@@_show_linked:w #1 \s_@@ #2#3#4 \s_@@_stop
2488 {
2489 \exp_not:N \@@_flatten:w
2490 \exp_not:c { @@ ~ \tl_to_str:n {#2} }
2491 \s_@@ { \tl_to_str:n {#2} }
2492 \exp_not:n {#3}
2493 }
2494 % \end{macrocode}
2495 % For flat props we are done by using \cs{msg_show:nneeee} or
2496 % \cs{msg_log:nneeee}. The auxiliary \cs{@@_show_finally:NNn} is
2497 % eventually also used in the linked case after some more tests. To
2498 % avoid having to bring along the message function and the property
2499 % list, we store them into \cs{l_@@_tmp_tl}.
2500 % \begin{macrocode}
2501 \cs_new_protected:Npn \@@_show_finally:NNn #1#2#3
2502 {
2503 #1 { prop } { show }
2504 { \token_to_str:N #2 }
2505 { \prop_map_function:NN #2 \msg_show_item:nn }
2506 {#3} { }
2507 }
2508 % \end{macrocode}
2509 % For linked props, we now know they have a reasonable form so that we
2510 % are calling \cs{@@_show_prepare:w} \cs{@@_flatten:w}
2511 % \cs[no-index]{@@~\meta{prefix}} \cs{s_@@} \Arg{prefix} \meta{token}
2512 % \meta{property list}, and the task is to loop through the linked
2513 % list and check integrity. We first set things up: the auxiliary
2514 % \cs{@@_tmp:w} will be in charge of checking that various tokens
2515 % start with \cs[no-index]{@@~\meta{prefix}} (in the sense of string
2516 % representations), and calling one of \cs{@@_show_loop_key:wNNN},
2517 % \cs{@@_show_end:NNN}, \cs{@@_show_bad_name:NNN}.
2518 % \begin{macrocode}
2519 \cs_new_protected:Npn \@@_show_prepare:w
2520 \@@_flatten:w #1 \s_@@ #2#3#4
2521 {
2522 \use:e
2523 {
2524 \cs_set_nopar:Npn \exp_not:N \@@_tmp:w
2525 ##1 \token_to_str:N #1 ##2 \s_@@_mark ##3 \s_@@_stop
2526 {
2527 \exp_not:N \tl_if_empty:nTF {##1}
2528 {
2529 \exp_not:N \tl_if_head_is_space:nTF {##2}
2530 { \exp_not:N \exp_args:Nf \@@_show_loop_key:wNNN }
2531 { \exp_not:N \tl_if_empty:nTF }
2532 {##2}
2533 }
2534 { \exp_not:N \use_ii:nn }
2535 \@@_show_end:NNN
2536 \@@_show_bad_name:NNN
2537 }
2538 }
2539 \exp_last_unbraced:NNNo \@@_show_loop:NNw #1 #4 #4
2540 }
2541 % \end{macrocode}
2542 % The loop will consist of calls to \cs{@@_show_loop:NNw}
2543 % \cs[no-index]{@@~\meta{prefix}} \meta{token} \meta{expansion}, where
2544 % \meta{token} is one of the items in the list, specifically the key
2545 % container for \meta{key$_{i-1}$} (starting at $i=1$ with the
2546 % property list variable itself), and \meta{expansion} stands for the
2547 % expansion of that token, which has already been checked, and takes
2548 % the form \meta{junk} \cs{s_@@} \Arg{value}
2549 % \cs[no-index]{@@~\meta{prefix}~\meta{key_i}}. Thus, the loop
2550 % auxiliary receives the prefix command as |#1|, and the $(i-1)$-th
2551 % and $i$-th key containers as |#2| and~|#5|. Then \cs{@@_tmp:w}
2552 % checks that the name of the $i$-th key container is valid.
2553 % \begin{macrocode}
2554 \cs_new_protected:Npn \@@_show_loop:NNw #1#2 #3 \s_@@ #4#5
2555 {
2556 \exp_last_two_unbraced:Noo \@@_tmp:w
2557 { \token_to_str:N #5 \s_@@_mark }
2558 { \token_to_str:N #1 \s_@@_mark \s_@@_stop }
2559 #1 #2 #5
2560 }
2561 % \end{macrocode}
2562 % If the $i$-th key container has the wrong name we get
2563 % \cs{@@_show_bad_name:NNN} \cs[no-index]{@@~\meta{prefix}}
2564 % \meta{previous container} \meta{current container with bad name}.
2565 % \begin{macrocode}
2566 \cs_new_protected:Npn \@@_show_bad_name:NNN #1#2#3
2567 {
2568 \msg_error:nneeee { prop } { bad-link }
2569 { \tl_tail:N \l_@@_tmp_tl }
2570 { \token_to_str:N #2 }
2571 { \token_to_str:N #3 }
2572 { \token_to_str:N #1 }
2573 }
2574 % \end{macrocode}
2575 % If the $i$-th key container has the name
2576 % \cs[no-index]{@@~\meta{prefix}} (without space), it is the trailing
2577 % one. We check that it is the right kind of macro to be a token
2578 % list, and that it has the right contents \cs{use_none:n}
2579 % \meta{previous container}. If so, we are done checking everything,
2580 % and we display the property list using the message function and
2581 % property list name stored in \cs{l_@@_tmp_tl}. Note that we
2582 % also use this \cs{l_@@_tmp_tl} in the type argument of
2583 % \cs{__kernel_chk_tl_type:NnnT}, to build up the name
2584 % \enquote{\meta{property list} prop entry} used in error messages.
2585 % \begin{macrocode}
2586 \cs_new_protected:Npn \@@_show_end:NNN #1#2#3
2587 {
2588 \__kernel_chk_tl_type:NnnT #3
2589 { \tl_tail:N \l_@@_tmp_tl prop~entry }
2590 { \exp_not:n { \use_none:n #2 } }
2591 {
2592 \exp_after:wN \@@_show_finally:NNn
2593 \l_@@_tmp_tl { linked }
2594 }
2595 }
2596 % \end{macrocode}
2597 % If the $i$-th container has a name \cs[no-index]{@@~\meta{prefix}
2598 % \meta{key}} (with a space before the key), then we have a call to
2599 % \cs{@@_show_loop_key:wNNN} \Arg{key} \meta{junk_1} \meta{junk_2}
2600 % \cs[no-index]{@@~\meta{prefix}} \meta{previous container}
2601 % \meta{current container}. (with an \texttt{f}-expansion to eliminate
2602 % the space). The first argument is the \meta{key} without a leading
2603 % space, thanks to a judicious \texttt{f}-expansion earlier on. We
2604 % check that the \meta{current container} is a token list with the
2605 % expected structure \cs{use_none:n} \meta{previous container}
2606 % \cs{@@_pair:wn} \meta{string} \cs{s_@@} \Arg{anything} \meta{single
2607 % token}. The auxiliary \cs{@@_show_flat:w} is reused to produce the
2608 % \cs{@@_pair:wn} part, and the last token is produced by
2609 % \cs{tl_item:Nn} (we don't waste a specialized auxiliary to speed
2610 % that up). If the check succeed, move on to the next item.
2611 % \begin{macrocode}
2612 \cs_new_protected:Npn \@@_show_loop_key:wNNN #1#2#3#4#5#6
2613 {
2614 \__kernel_chk_tl_type:NnnT #6
2615 { \tl_tail:N \l_@@_tmp_tl prop~entry }
2616 {
2617 \exp_not:n { \use_none:n #5 }
2618 \exp_after:wN \@@_show_flat:w #6 \s_@@ { }
2619 \@@_pair:wn \q_@@_recursion_tail \s_@@ { }
2620 \q_@@_recursion_stop
2621 \tl_item:Nn #6 { -1 }
2622 }
2623 { \exp_last_unbraced:NNNo \@@_show_loop:NNw #4 #6 #6 }
2624 }
2625 % \end{macrocode}
2626 % \end{macro}
2627 % \end{macro}
2628 % \end{macro}
2629 %
2630 % \begin{macrocode}
2631 %</code>
2632 % \end{macrocode}
2633 %
2634 % \end{implementation}
2635 %
2636 % \PrintIndex