| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% File: expkv-pop.dtx Copyright (C) 2020-2024 Jonathan P. Spratte |
| 4 |
% |
| 5 |
% This work may be distributed and/or modified under the conditions of the |
| 6 |
% LaTeX Project Public License (LPPL), either version 1.3c of this license or |
| 7 |
% (at your option) any later version. The latest version of this license is in |
| 8 |
% the file: |
| 9 |
% |
| 10 |
% http://www.latex-project.org/lppl.txt |
| 11 |
% |
| 12 |
% ------------------------------------------------------------------------------ |
| 13 |
% |
| 14 |
%<*driver>^^A>>= |
| 15 |
\def\expkvDocNoGenerate{} |
| 16 |
\input expkv-bundle.ins |
| 17 |
\generate{\file{expkv-pop.sty}{\from{expkv-pop.dtx}{pkg}}} |
| 18 |
\generate{\file{expkv-pop.tex}{\from{expkv-pop.dtx}{tex}}} |
| 19 |
\generate{\file{t-expkv-pop.tex}{\from{expkv-pop.dtx}{ctx}}} |
| 20 |
\endbatchfile |
| 21 |
%</driver>^^A=<< |
| 22 |
% \fi |
| 23 |
% |
| 24 |
% \section{\expkvp} |
| 25 |
%^^A the LaTeX package >>= |
| 26 |
% \subsection{The \LaTeX\ Package} |
| 27 |
% Set up the \LaTeX\ package. |
| 28 |
% \gobbledocstriptag |
| 29 |
%<*pkg> |
| 30 |
% \begin{macrocode} |
| 31 |
\RequirePackage{expkv} |
| 32 |
\def\ekvp@tmp |
| 33 |
{% |
| 34 |
\ProvidesFile{expkv-pop.tex}% |
| 35 |
[\ekvpDate\space v\ekvpVersion\space a prefix oriented parser]% |
| 36 |
} |
| 37 |
\input{expkv-pop.tex} |
| 38 |
\ProvidesPackage{expkv-pop}% |
| 39 |
[\ekvpDate\space v\ekvpVersion\space a prefix oriented parser] |
| 40 |
% \end{macrocode} |
| 41 |
% \gobbledocstriptag |
| 42 |
%</pkg> |
| 43 |
%^^A=<< |
| 44 |
%^^A the ConTeXt module >>= |
| 45 |
% \subsection{The \ConTeXt\ module} |
| 46 |
% Set up the \ConTeXt\ module. |
| 47 |
% \gobbledocstriptag |
| 48 |
%<*ctx> |
| 49 |
% \begin{macrocode} |
| 50 |
\writestatus{loading}{ConTeXt User Module / expkv-pop} |
| 51 |
\usemodule[expkv] |
| 52 |
\unprotect |
| 53 |
\input expkv-pop.tex |
| 54 |
\writestatus{loading} |
| 55 |
{ConTeXt User Module / expkv-pop / Version \ekvpVersion\space loaded} |
| 56 |
\protect\endinput |
| 57 |
% \end{macrocode} |
| 58 |
% \gobbledocstriptag |
| 59 |
%</ctx> |
| 60 |
%^^A=<< |
| 61 |
%^^A main file >>= |
| 62 |
% \subsection{The Generic Code} |
| 63 |
% And another generic code package we need to set up. |
| 64 |
% \gobbledocstriptag |
| 65 |
%<*tex> |
| 66 |
% |
| 67 |
% Loading the generic \expkv\ package if it wasn't already loaded, utilizing |
| 68 |
% that \expkv\ prevents itself from loading multiple times. |
| 69 |
% \begin{macrocode} |
| 70 |
\input expkv |
| 71 |
% \end{macrocode} |
| 72 |
% |
| 73 |
% Introduce an own guard against being loaded multiple times: |
| 74 |
% \begin{macrocode} |
| 75 |
\expandafter\ifx\csname ekvpVersion\endcsname\relax |
| 76 |
\else |
| 77 |
\expandafter\endinput |
| 78 |
\fi |
| 79 |
% \end{macrocode} |
| 80 |
% |
| 81 |
% \begin{macro}{\ekvpVersion,\ekvpDate} |
| 82 |
% Specify the own version and date |
| 83 |
% \begin{macrocode} |
| 84 |
\def\ekvpVersion{1.0} |
| 85 |
\def\ekvpDate{2023-01-23} |
| 86 |
% \end{macrocode} |
| 87 |
% \end{macro} |
| 88 |
% |
| 89 |
% Reporting back who we are for \LaTeX\ (the package will have set up things for |
| 90 |
% us). |
| 91 |
% \begin{macrocode} |
| 92 |
\csname ekvp@tmp\endcsname |
| 93 |
% \end{macrocode} |
| 94 |
% |
| 95 |
% Package internal category code setup (stored to restore it at the end -- we |
| 96 |
% have to be careful to not lose this definition of |\ekvp@tmp| inside the |
| 97 |
% package). |
| 98 |
% \begin{macrocode} |
| 99 |
\expandafter\chardef\csname ekvp@tmp\endcsname=\catcode`\@ |
| 100 |
\catcode`\@=11 |
| 101 |
% \end{macrocode} |
| 102 |
% |
| 103 |
% \subsubsection{Parsing}^^A>>= |
| 104 |
% |
| 105 |
% \begin{macro}{\ekvpParse} |
| 106 |
% \begin{macro}[internal] |
| 107 |
% { |
| 108 |
% \ekvpParse@a,\ekvpParse@b,\ekvpParse@c, |
| 109 |
% \ekvpParse@unsafe,\ekvpParse@unsafe@auto |
| 110 |
% } |
| 111 |
% Parsing should be done in two steps of expansion, hence we put |
| 112 |
% |\unexpanded\expanded| around it. Next we check whether the parser is |
| 113 |
% defined, and afterwards run |\ekvparse|. For that we expand it once and |
| 114 |
% remove the |\unexpanded| which it uses itself. |
| 115 |
% \begin{macrocode} |
| 116 |
\long\def\ekvpParse#1#2% |
| 117 |
{% |
| 118 |
\ekv@unexpanded\ekv@expanded |
| 119 |
{{\expandafter\ekvpParse@a\detokenize{#1}\ekv@mark{#2}}}% |
| 120 |
} |
| 121 |
\def\ekvpParse@a#1\ekv@mark |
| 122 |
{% |
| 123 |
\ekv@ifdefined{ekvp@@p@#1}% |
| 124 |
{\expandafter\ekvpParse@b\csname ekvp@@p@#1\endcsname}% |
| 125 |
{\ekvp@err@unknownparser{#1}\@gobble}% |
| 126 |
} |
| 127 |
\def\ekvpParse@b#1% |
| 128 |
{% |
| 129 |
\ekv@ifdefined{#1{ppa}}% |
| 130 |
{% |
| 131 |
\expandafter\ekvpParse@c\expandafter |
| 132 |
{\expandafter#1\csname#1{ppa}\endcsname}% |
| 133 |
}% |
| 134 |
{\ekvpParse@c{#1{}}}% |
| 135 |
} |
| 136 |
\def\ekvpParse@c#1#2#3{#2#3} |
| 137 |
\ekv@expargtwice{\long\def\ekvpParse@c#1#2}% |
| 138 |
{\expandafter\ekvpParse@c\ekvparse{\ekvp@k#1}{\ekvp@p#1}{#2}} |
| 139 |
\long\def\ekvpParse@unsafe#1#2#3{\ekv@unexpanded\ekv@expanded{{#2#3}}} |
| 140 |
\ekv@expargtwice{\long\def\ekvpParse@unsafe@auto#1#2#3} |
| 141 |
{\expandafter\ekvpParse@unsafe\ekvparse{\ekvp@k#1#2}{\ekvp@p#1#2}{#3}} |
| 142 |
\ekv@expargtwice{\long\def\ekvpParse@unsafe#1#2}% |
| 143 |
{\expandafter\ekvpParse@unsafe\ekvparse{\ekvp@k#1{}}{\ekvp@p#1{}}{#2}} |
| 144 |
% \end{macrocode} |
| 145 |
% \end{macro} |
| 146 |
% \end{macro} |
| 147 |
% |
| 148 |
% \begin{macro}[internal]{\ekvp@k} |
| 149 |
% For |NoVal| we use the parser specific rule. |
| 150 |
% \begin{macrocode} |
| 151 |
\def\ekvp@k#1{\csname #1k\endcsname#1} |
| 152 |
% \end{macrocode} |
| 153 |
% \end{macro} |
| 154 |
% |
| 155 |
% \begin{macro}[internal]{\ekvp@ifspace,\ekvp@ifspace@} |
| 156 |
% This checks whether a space is inside its argument (gobbling up to the first |
| 157 |
% space and checking for an empty remainder). |
| 158 |
% \begin{macrocode} |
| 159 |
\long\def\ekvp@ifspace#1% |
| 160 |
{% |
| 161 |
\ekvp@ifspace@#1 \ekv@ifempty@B\ekv@ifempty@false |
| 162 |
\ekv@ifempty@A\ekv@ifempty@B\@firstoftwo |
| 163 |
} |
| 164 |
\long\def\ekvp@ifspace@#1 % keep this space |
| 165 |
{\ekv@ifempty@\ekv@ifempty@A} |
| 166 |
% \end{macrocode} |
| 167 |
% \end{macro} |
| 168 |
% |
| 169 |
% \begin{macro}[internal]{\ekvp@p} |
| 170 |
% \begin{macro}[internal]{\ekvp@prefix} |
| 171 |
% \begin{macro}[internal]{\ekvp@prefix@a,\ekvp@prefix@b} |
| 172 |
% If there should be a prefix there needs to be a space, so we check for one. |
| 173 |
% Then we split the first prefix of the rest. |
| 174 |
% \begin{macrocode} |
| 175 |
\ekv@exparg{\long\def\ekvp@prefix#1}% |
| 176 |
{% |
| 177 |
\ekvp@ifspace{#1}% |
| 178 |
{\ekvp@prefix@a#1\ekv@stop}% |
| 179 |
{\ekvp@noprefix{#1}}% |
| 180 |
} |
| 181 |
% \end{macrocode} |
| 182 |
% A prefix is parsed with a few additional logical groups. The input |#1| is |
| 183 |
% the parser's name macro, |#2| is the full item which should be parsed. And |
| 184 |
% we place an additional group in which the prefix macros will be collected. |
| 185 |
% \begin{macrocode} |
| 186 |
\ekv@exparg{\long\def\ekvp@p#1#2#3}{\ekvp@prefix{#3}#1{#2}{#3}} |
| 187 |
% \end{macrocode} |
| 188 |
% The prefix is |\detokenize|d and forwarded. Then we check whether it's a |
| 189 |
% defined type or prefix. |
| 190 |
% \begin{macrocode} |
| 191 |
\long\def\ekvp@prefix@a#1 % keep this space |
| 192 |
{\expandafter\ekvp@prefix@b\detokenize{#1}\ekv@mark{#1}} |
| 193 |
\ekv@exparg{\long\def\ekvp@prefix@b#1\ekv@mark#2#3\ekv@stop#4}% |
| 194 |
{% |
| 195 |
\ekv@ifdefined{#4{pt}@#1} |
| 196 |
{\expandafter\ekvp@prefix@pt\csname #4{pt}@#1\endcsname{#1}}% |
| 197 |
{% |
| 198 |
\ekv@ifdefined{#4{pp}@#1}% |
| 199 |
{\expandafter\ekvp@prefix@pp\csname #4{pp}@#1\endcsname}% |
| 200 |
{\@firstoftwo{\ekvp@noprefix{#2 #3}}}% |
| 201 |
}% |
| 202 |
{#3}#4% |
| 203 |
} |
| 204 |
% \end{macrocode} |
| 205 |
% \end{macro} |
| 206 |
% \end{macro} |
| 207 |
% \end{macro} |
| 208 |
% |
| 209 |
% \begin{macro}[internal]{\ekvp@prefix@pt,\ekvp@prefix@pt@} |
| 210 |
% A type ends the prefix parsing (every item can only have one type). The |
| 211 |
% argument |#1| is that type macro, and in |#2| is the types name. |#3| then |
| 212 |
% contains the name of the element, |#4| is the parser's name macro (which is |
| 213 |
% no longer needed here), |#5| is the list of prefix macros, |#6| the entire |
| 214 |
% unchanged item, and |#7| is the value provided to the current item. The |
| 215 |
% prefix macro list will be stepped through, each macro will get the type |
| 216 |
% name, element name, and complete unprocessed item, whereas the type macro |
| 217 |
% will not receive the type string (but instead the value), which is why we |
| 218 |
% put a |\@firstoftwo| there to remove the type. |\ekvp@prefix@pt@| is a |
| 219 |
% helper to fetch the first prefix macro (or the type should |#5| be empty). |
| 220 |
% \begin{macrocode} |
| 221 |
\long\def\ekvp@prefix@pt#1#2#3#4#5#6#7% |
| 222 |
{% |
| 223 |
\ekvp@prefix@pt@{#2}{#3}{#6}#5{\@firstoftwo#1}{#7}\ekvpEOT |
| 224 |
\ekv@unexpanded{\ekvpEOA{#6}}% |
| 225 |
} |
| 226 |
\long\def\ekvp@prefix@pt@#1#2#3#4{#4{#1}{#2}{#3}} |
| 227 |
% \end{macrocode} |
| 228 |
% \end{macro} |
| 229 |
% |
| 230 |
% \begin{macro}[internal]{\ekvp@prefix@pp} |
| 231 |
% A prefix macro is added to the list of prefixes (argument |#4|) and the next |
| 232 |
% prefix is searched. |
| 233 |
% \begin{macrocode} |
| 234 |
\ekv@exparg{\long\def\ekvp@prefix@pp#1#2#3#4}{\ekvp@prefix{#2}#3{#4#1}} |
| 235 |
% \end{macrocode} |
| 236 |
% \end{macro} |
| 237 |
% |
| 238 |
% \begin{macro}[internal]{\ekvp@noprefix} |
| 239 |
% If no prefix was found (either because there was no space, or the first |
| 240 |
% space delimited thing wasn't a valid prefix) we check if there is a notype |
| 241 |
% rule or throw an error. |
| 242 |
% \begin{macrocode} |
| 243 |
\long\def\ekvp@noprefix#1#2% |
| 244 |
{% |
| 245 |
\ekv@ifdefined{#2{pn}} |
| 246 |
{\expandafter\ekvp@prefix@pt\csname #2{pn}\endcsname{}{#1}} |
| 247 |
\ekvp@err@missingtype |
| 248 |
#2% |
| 249 |
} |
| 250 |
% \end{macrocode} |
| 251 |
% \end{macro} |
| 252 |
% |
| 253 |
%^^A=<< |
| 254 |
% |
| 255 |
% \subsubsection{Defining Parsers}^^A>>= |
| 256 |
% |
| 257 |
% \begin{macro}{\ekvpNewParser} |
| 258 |
% \begin{macro}[internal]{\ekvpNewParser@} |
| 259 |
% To define a new parser we need to assert that it doesn't already exists (if |
| 260 |
% so we throw an error) and define the parser name. A parser name is defined |
| 261 |
% as the macro \cs[no-index]{ekvp@@p@\meta{name}}, that macro will take one |
| 262 |
% argument and build the name of a prefix or type. Additionally a new parser |
| 263 |
% gets its |NoVal| rule set up as the default rule. |
| 264 |
% \begin{macrocode} |
| 265 |
\protected\long\def\ekvpNewParser#1% |
| 266 |
{\expandafter\ekvpNewParser@\detokenize{#1}\ekv@mark} |
| 267 |
\protected\def\ekvpNewParser@#1\ekv@mark |
| 268 |
{% |
| 269 |
\ekv@ifdefined{ekvp@@p@#1}% |
| 270 |
{\ekvp@errm{Parser `#1' already defined}}% |
| 271 |
{% |
| 272 |
\expandafter\def\csname ekvp@@p@#1\endcsname##1{ekvp@@##1@#1} |
| 273 |
\expandafter |
| 274 |
\let\csname\csname ekvp@@p@#1\endcsname k\endcsname\ekvp@k@default |
| 275 |
}% |
| 276 |
} |
| 277 |
% \end{macrocode} |
| 278 |
% \end{macro} |
| 279 |
% \end{macro} |
| 280 |
% |
| 281 |
% \begin{macro}{\ekvpValueAlwaysRequired} |
| 282 |
% \begin{macro}[internal]{\ekvpValueAlwaysRequired@} |
| 283 |
% This just changes the default |NoVal| rule to throw an error. |
| 284 |
% \begin{macrocode} |
| 285 |
\protected\long\def\ekvpValueAlwaysRequired#1% |
| 286 |
{\ekvp@parser@def{#1}\ekvpValueAlwaysRequired@{}} |
| 287 |
\protected\def\ekvpValueAlwaysRequired@#1% |
| 288 |
{\expandafter\let\csname#1k\endcsname\ekvp@err@noval} |
| 289 |
% \end{macrocode} |
| 290 |
% \end{macro} |
| 291 |
% \end{macro} |
| 292 |
% |
| 293 |
% \begin{macro}{\ekvpDefNoValue} |
| 294 |
% \begin{macro}[internal]{\ekvpDefNoValue@} |
| 295 |
% \begin{macrocode} |
| 296 |
\protected\long\def\ekvpDefNoValue#1% |
| 297 |
{\ekvp@parser@def{#1}\ekvpDefNoValue@\@gobble} |
| 298 |
\protected\long\def\ekvpDefNoValue@#1#2% |
| 299 |
{% |
| 300 |
\def\ekvp@tmp##1{\ekv@unexpanded{#2}}% |
| 301 |
\ekv@exparg{\long\expandafter\def\csname#1k\endcsname##1##2##3}% |
| 302 |
{\ekvp@tmp{##3}}% |
| 303 |
} |
| 304 |
% \end{macrocode} |
| 305 |
% \end{macro} |
| 306 |
% \end{macro} |
| 307 |
% |
| 308 |
% \begin{macro}{\ekvpUseNoValueMarker} |
| 309 |
% \begin{macro}[internal]{\ekvpUseNoValueMarker@} |
| 310 |
% |
| 311 |
% \begin{macrocode} |
| 312 |
\protected\long\def\ekvpUseNoValueMarker#1% |
| 313 |
{\ekvp@parser@def{#1}\ekvpUseNoValueMarker@\@gobble} |
| 314 |
\protected\long\def\ekvpUseNoValueMarker@#1#2% |
| 315 |
{% |
| 316 |
\long\expandafter\edef\csname#1k\endcsname##1##2##3% |
| 317 |
{\ekv@unexpanded{\ekvp@p}##1{##2}{##3}{\ekv@unexpanded{#2}}}% |
| 318 |
} |
| 319 |
% \end{macrocode} |
| 320 |
% \end{macro} |
| 321 |
% \end{macro} |
| 322 |
% |
| 323 |
% \begin{macro}{\ekvpDefNoValuePrefix} |
| 324 |
% \begin{macro}[internal]{\ekvpDefNoValuePrefix@,\ekvpDefNoValuePrefix@@} |
| 325 |
% This might be the most complicated of the |NoVal|-behaviour changes. The |
| 326 |
% first two steps should be clear. |
| 327 |
% \begin{macrocode} |
| 328 |
\protected\long\def\ekvpDefNoValuePrefix#1% |
| 329 |
{\ekvp@parser@def{#1}\ekvpDefNoValuePrefix@\@gobbletwo} |
| 330 |
\protected\def\ekvpDefNoValuePrefix@#1% |
| 331 |
{\expandafter\ekvpDefNoValuePrefix@@\csname#1{ppn}\endcsname#1} |
| 332 |
% \end{macrocode} |
| 333 |
% This step is the complicated one combining the effects of \cs{ekvpDefPrefix} |
| 334 |
% with the standard |NoVal|-rule (but for which the no-value marker might have |
| 335 |
% been changed), so here's what happens: |
| 336 |
% We set up a temporary meaning for the control sequence name |
| 337 |
% forwarded as |#1| to extract the no-value marker of the current parser. Then |
| 338 |
% we set up the |NoVal|-macro of the current parser to expand to the normal |
| 339 |
% parsing route, there we inject |#1| as the first prefix macro in the |
| 340 |
% corresponding first argument of \cs[no-index]{ekvp@p}, and we extract the |
| 341 |
% no-value marker with the |\expandafter#1|-chain. This last step might |
| 342 |
% actually fail badly if \cs{ekvpValueAlwaysRequired} or \cs{ekvpDefNoValue} |
| 343 |
% was used. |
| 344 |
% \begin{macrocode} |
| 345 |
\protected\long\def\ekvpDefNoValuePrefix@@#1#2% |
| 346 |
{% |
| 347 |
\long\def#1\ekvp@p##1##2##3% |
| 348 |
{% |
| 349 |
\ekv@unexpanded{\ekvp@p}% |
| 350 |
####1{####2\ekv@unexpanded{#1}}{####3}{\ekv@unexpanded{##3}}% |
| 351 |
}% |
| 352 |
\long\expandafter\edef\csname#2k\endcsname##1##2##3% |
| 353 |
{\expandafter\expandafter\expandafter#1\csname#2k\endcsname{}{}{}}% |
| 354 |
\ekvp@parser@def@prefix#1% |
| 355 |
} |
| 356 |
% \end{macrocode} |
| 357 |
% \end{macro} |
| 358 |
% \end{macro} |
| 359 |
% |
| 360 |
% \begin{macro}{\ekvpDefAutoPrefix} |
| 361 |
% \begin{macro}[internal]{\ekvpDefAutoPrefix@} |
| 362 |
% \begin{macrocode} |
| 363 |
\protected\long\def\ekvpDefAutoPrefix#1% |
| 364 |
{\ekvp@parser@def{#1}\ekvpDefAutoPrefix@\@gobbletwo} |
| 365 |
\protected\long\def\ekvpDefAutoPrefix@#1% |
| 366 |
{\expandafter\ekvp@parser@def@prefix\csname#1{ppa}\endcsname} |
| 367 |
% \end{macrocode} |
| 368 |
% \end{macro} |
| 369 |
% \end{macro} |
| 370 |
% |
| 371 |
% \begin{macro}[internal]{\ekvp@parser@def,\ekvp@parser@def@} |
| 372 |
% This just makes sure that the parser is defined and builds the parser name. |
| 373 |
% |#1| should be the user-level parser name, |#2| the macro that gets the |
| 374 |
% code-level parser forwarded, and |#3| should gobble all additional arguments |
| 375 |
% needed by whichever frontend macro this is used for in case of an error. |
| 376 |
% \begin{macrocode} |
| 377 |
\long\def\ekvp@parser@def#1% |
| 378 |
{\expandafter\ekvp@parser@def@\detokenize{#1}\ekv@mark} |
| 379 |
\def\ekvp@parser@def@#1\ekv@mark#2#3% |
| 380 |
{% |
| 381 |
\ekv@ifdefined{ekvp@@p@#1}% |
| 382 |
{\ekv@exparg{#2}{\csname ekvp@@p@#1\endcsname}}% |
| 383 |
{\ekvp@errm{Parser `#1' not defined}#3}% |
| 384 |
} |
| 385 |
% \end{macrocode} |
| 386 |
% \end{macro} |
| 387 |
% |
| 388 |
% \begin{macro}{\ekvpDefPrefix} |
| 389 |
% \begin{macro}[internal]{\ekvpDefPrefix@,\ekvp@parser@def@prefix} |
| 390 |
% A prefix is stored as a macro. At first we define a temporary meaning just |
| 391 |
% to make sure that the user uses only the first three arguments. |
| 392 |
% The real macro is a bit more complicated. It places the user provided before |
| 393 |
% action (|#3|) where it currently is, the after action (|#4|) after |
| 394 |
% |\ekvpEOT| (so after the type action). It also fetches the next prefix or |
| 395 |
% the type macro and forwards the arguments to it. |
| 396 |
% \begin{macrocode} |
| 397 |
\protected\long\def\ekvpDefPrefix#1% |
| 398 |
{\ekvp@parser@def{#1}\ekvpDefPrefix@\@gobblethree} |
| 399 |
\protected\long\def\ekvpDefPrefix@#1#2% |
| 400 |
{\expandafter\ekvp@parser@def@prefix\csname#1{pp}@\detokenize{#2}\endcsname} |
| 401 |
\protected\long\def\ekvp@parser@def@prefix#1#2#3% |
| 402 |
{% |
| 403 |
\def#1##1##2##3{#2#3}% |
| 404 |
\long\def#1##1##2##3##4##5\ekvpEOT |
| 405 |
{\ekv@unexpanded{#2}##4{##1}{##2}{##3}##5\ekvpEOT\ekv@unexpanded{#3}}% |
| 406 |
} |
| 407 |
% \end{macrocode} |
| 408 |
% \end{macro} |
| 409 |
% \end{macro} |
| 410 |
% |
| 411 |
% \begin{macro}{\ekvpDefPrefixLet,\ekvpDefPrefixStore} |
| 412 |
% These are just special cases of |\ekvpDefPrefix|, so nothing complicated |
| 413 |
% here. |
| 414 |
% \begin{macrocode} |
| 415 |
\ekv@exparg{\protected\long\def\ekvpDefPrefixLet#1#2#3#4#5}% |
| 416 |
{\ekvpDefPrefix{#1}{#2}{\ekvpProtect{\let#3= #4}}{\ekvpProtect{\let#3= #5}}} |
| 417 |
\ekv@exparg{\protected\long\def\ekvpDefPrefixStore#1#2#3#4#5}% |
| 418 |
{% |
| 419 |
\ekvpDefPrefix{#1}{#2}% |
| 420 |
{\ekvpProtect{\edef#3{\ekv@unexpanded{#4}}}}% |
| 421 |
{\ekvpProtect{\edef#3{\ekv@unexpanded{#5}}}}% |
| 422 |
} |
| 423 |
% \end{macrocode} |
| 424 |
% \end{macro} |
| 425 |
% |
| 426 |
% \begin{macro}{\ekvpDefType,\ekvpDefNoType} |
| 427 |
% \begin{macro}[internal]{\ekvpDefType@,\ekvpDefNoType@,\ekvpDefType@NoType} |
| 428 |
% A type macro and a notype-macro are pretty similar, the whole difference is |
| 429 |
% the naming scheme. The macro leaves the user definition in the input and |
| 430 |
% places the |\ekvpEOP| and |\ekvpEOT| markers. |
| 431 |
% \begin{macrocode} |
| 432 |
\protected\long\def\ekvpDefType#1{\ekvp@parser@def{#1}\ekvpDefType@\@gobbletwo} |
| 433 |
\protected\long\def\ekvpDefType@#1#2% |
| 434 |
{\ekvpDefType@NoType{#1{pt}@\detokenize{#2}}}% |
| 435 |
\protected\long\def\ekvpDefNoType#1{\ekvp@parser@def{#1}\ekvpDefNoType@\@gobble} |
| 436 |
\protected\long\def\ekvpDefNoType@#1{\ekvpDefType@NoType{#1{pn}}} |
| 437 |
\protected\long\def\ekvpDefType@NoType#1#2% |
| 438 |
{% |
| 439 |
\long\expandafter\def\csname#1\endcsname##1##2##3\ekvpEOT |
| 440 |
{\ekv@unexpanded{\ekvpEOP{##2}#2\ekvpEOT{##2}}}% |
| 441 |
}% |
| 442 |
% \end{macrocode} |
| 443 |
% \end{macro} |
| 444 |
% \end{macro} |
| 445 |
% |
| 446 |
% \begin{macro}{\ekvpLet} |
| 447 |
% \begin{macro}[internal]{\ekvpLet@a,\ekvpLet@b,\ekvpLet@c,\ekvpLet@d} |
| 448 |
% Letting has an optional argument, so we can't use |\ekvp@parser@def| |
| 449 |
% directly here, first we need to convert the optional argument to a normal |
| 450 |
% one so that we can gobble it normally. Then we check that the two parsers |
| 451 |
% are defined, and afterwards that the copy macro is. If all this is correct |
| 452 |
% we do the |\let|. Since arguments are shuffled around here, I'll list them |
| 453 |
% each time they get reordered (some might be curried). |
| 454 |
% |
| 455 |
% |#1| is the parser name, |#2| the type, |#3| the new \prefix/\type\ name, |
| 456 |
% |#4| the optional other parser name, |#5| the already existing |
| 457 |
% \prefix/\type\ which should be copied. |
| 458 |
% \begin{macrocode} |
| 459 |
\protected\long\def\ekvpLet#1#2#3{\ekvoptarg{\ekvpLet@a{#1}{#2}{#3}}{#1}} |
| 460 |
\protected\long\def\ekvpLet@a#1% |
| 461 |
{\ekvp@parser@def{#1}\ekvpLet@b{\@firstoftwo\@gobblethree}} |
| 462 |
\protected\long\def\ekvpLet@b#1#2#3#4% |
| 463 |
{\ekvp@parser@def{#4}\ekvpLet@c{\@firstoftwo\@gobblethree}#1{#2}{#3}} |
| 464 |
% \end{macrocode} |
| 465 |
% |#1| the other parser's macro, |#2| the parser's macro, |#3| the type, |#4| |
| 466 |
% the new \prefix/\type, |#5| the already existing \prefix/\type. |
| 467 |
% \begin{macrocode} |
| 468 |
\protected\long\def\ekvpLet@c#1#2#3% |
| 469 |
{% |
| 470 |
\ekv@ifdefined{ekvpLet@@\detokenize{#3}}% |
| 471 |
{\expandafter\ekvpLet@d\csname ekvpLet@@\detokenize{#3}\endcsname{#1}{#2}}% |
| 472 |
{\ekvp@errm{unknown type \detokenize{#3}}\@gobbletwo}% |
| 473 |
} |
| 474 |
% \end{macrocode} |
| 475 |
% |#1| the type's macro, |#2| the other parser's macro, |#3| the parser's |
| 476 |
% macro, |#4| the new \prefix/\type, |#5| the already existing \prefix/\type. |
| 477 |
% \begin{macrocode} |
| 478 |
\protected\long\def\ekvpLet@d#1#2#3#4#5% |
| 479 |
{% |
| 480 |
\ekv@ifdefined{#2{#1}@\detokenize{#5}}% |
| 481 |
{% |
| 482 |
\expandafter\let |
| 483 |
\csname#3{#1}@\detokenize{#4}\expandafter\endcsname |
| 484 |
\csname#2{#1}@\detokenize{#5}\endcsname |
| 485 |
}% |
| 486 |
{\ekvp@errm{Undefined prefix/type \detokenize{#5} can't be copied}}% |
| 487 |
} |
| 488 |
\def\ekvpLet@@prefix{pp} |
| 489 |
\def\ekvpLet@@type{pt} |
| 490 |
% \end{macrocode} |
| 491 |
% \end{macro} |
| 492 |
% \end{macro} |
| 493 |
% |
| 494 |
%^^A=<< |
| 495 |
% |
| 496 |
% \subsubsection{\texttt{NoVal} Handling}^^A>>= |
| 497 |
% |
| 498 |
% The idea of |NoVal| handling is taken from \pkg{expl3}. We define a marker |
| 499 |
% (or directly use \pkg{expl3}'s). The defined test is not as robust as |
| 500 |
% \pkg{expl3}'s, but pretty fast (and based on |\ekv@ifempty|). |
| 501 |
% |
| 502 |
% \begin{macro}{\ekvpIfNoVal} |
| 503 |
% \begin{macro}[internal]{\ekvp@novalflag,\ekvp@ifnoval} |
| 504 |
% \begin{macro}[internal]{\ekvp@k@default} |
| 505 |
% \begin{macrocode} |
| 506 |
\ekv@ifdefined{c_novalue_tl} |
| 507 |
{\expandafter\let\expandafter\ekvp@novalflag\csname c_novalue_tl\endcsname} |
| 508 |
{% |
| 509 |
\begingroup |
| 510 |
\lccode`\Z=`\- |
| 511 |
\lccode`\:=`\- |
| 512 |
\lccode`\N=\z@ |
| 513 |
\lccode`\V=\z@ |
| 514 |
\lowercase{\endgroup\def\ekvp@novalflag{ZNoValue:}}% |
| 515 |
} |
| 516 |
\def\ekvpIfNoVal#1% |
| 517 |
{% |
| 518 |
\long\def\ekvpIfNoVal##1% |
| 519 |
{% |
| 520 |
\ekvp@ifnoval{}##1{}?!#1??!\ekv@ifempty@B\ekv@ifempty@true |
| 521 |
\ekv@ifempty@A\ekv@ifempty@B\@secondoftwo |
| 522 |
}% |
| 523 |
\long\def\ekvp@ifnoval##1#1##2?##3?!{\ekv@ifempty@\ekv@ifempty@A##1##2}% |
| 524 |
\long\def\ekvp@k@default##1##2##3{\ekvp@p##1{##2}{##3}{#1}}% |
| 525 |
} |
| 526 |
\expandafter\ekvpIfNoVal\expandafter{\ekvp@novalflag} |
| 527 |
\let\ekvp@novalflag\ekvp@undefined |
| 528 |
% \end{macrocode} |
| 529 |
% \end{macro} |
| 530 |
% \end{macro} |
| 531 |
% \end{macro} |
| 532 |
% |
| 533 |
%^^A=<< |
| 534 |
% |
| 535 |
% \subsubsection{Assertions}^^A>>= |
| 536 |
% |
| 537 |
% Assertions are just wrappers around user provided code to throw errors. Each |
| 538 |
% of them |
| 539 |
% |
| 540 |
% \begin{macro}{\ekvpAssertIf,\ekvpAssertIfNot} |
| 541 |
% \begin{macro}[internal]{\ekvpAssertIf@,\ekvpAssertIf@good,\ekvpAssert@notgood} |
| 542 |
% \begin{macrocode} |
| 543 |
\def\ekvpAssertIf{\romannumeral\ekv@alignsafe\ekvoptarg{\ekvpAssertIf@{}}{EOT}} |
| 544 |
\def\ekvpAssertIfNot |
| 545 |
{\romannumeral\ekv@alignsafe\ekvoptarg{\ekvpAssertIf@\else}{EOT}} |
| 546 |
\long\def\ekvpAssertIf@#1#2#3% |
| 547 |
{% |
| 548 |
#3#1\ekvpAssertIf@good\fi |
| 549 |
\ekvpAssert@notgood{#2}% |
| 550 |
} |
| 551 |
\long\def\ekvpAssertIf@good\fi\ekvpAssert@notgood#1#2% |
| 552 |
{\fi\ekv@endalignsafe\ekv@zero} |
| 553 |
\long\def\ekvpAssert@notgood#1% |
| 554 |
{% |
| 555 |
\ekv@ifdefined{ekvpAssert@@#1}% |
| 556 |
{\csname ekvpAssert@@#1\endcsname}% |
| 557 |
{\ekvp@err@unknownmarker{#1}\ekvpAssert@@EOA}% |
| 558 |
} |
| 559 |
% \end{macrocode} |
| 560 |
% \end{macro} |
| 561 |
% \end{macro} |
| 562 |
% |
| 563 |
% \begin{macro}{\ekvpAssertTF,\ekvpAssertTFNot} |
| 564 |
% \begin{macro}[internal]{\ekvpAssertTF@} |
| 565 |
% \begin{macrocode} |
| 566 |
\def\ekvpAssertTF{\ekvoptarg{\ekvpAssertTF@{}}{EOT}} |
| 567 |
\def\ekvpAssertTFNot{\ekvoptarg{\ekvpAssertTF@{\@secondoftwo\@firstoftwo}}{EOT}} |
| 568 |
\long\def\ekvpAssertTF@#1#2#3% |
| 569 |
{% |
| 570 |
\ekv@alignsafe |
| 571 |
#3#1% |
| 572 |
{\ekv@endalignsafe\@gobble}% |
| 573 |
{\romannumeral\ekvpAssert@notgood{#2}}% |
| 574 |
} |
| 575 |
% \end{macrocode} |
| 576 |
% \end{macro} |
| 577 |
% \end{macro} |
| 578 |
% |
| 579 |
% \begin{macro} |
| 580 |
% { |
| 581 |
% \ekvpAssertValue,\ekvpAssertNoValue,\ekvpAssertOneValue, |
| 582 |
% \ekvpAssertTwoValues |
| 583 |
% } |
| 584 |
% \begin{macro}[internal]{\ekvpAssert@further} |
| 585 |
% \begin{macro}[internal]{\ekvp@assert@num@args} |
| 586 |
% These here are special cases of assertions. First we define a helper, the |
| 587 |
% following might look like a recursive call, but we'll redefine the helper |
| 588 |
% later and need this definition only temporary. |
| 589 |
% \begin{macrocode} |
| 590 |
\ekv@exparg{\def\ekvpAssert@further#1#2#3}% |
| 591 |
{\ekvoptarg{\ekvpAssert@further{#1}{#2}{#3}}{EOT}} |
| 592 |
% \end{macrocode} |
| 593 |
% Now the definitions, we just need to set up the tests and corresponding |
| 594 |
% error messages. All this passes through the \cs{ekvpAssertTF} check (which |
| 595 |
% we shortcut to its internal auxiliary function here). |
| 596 |
% \begin{macrocode} |
| 597 |
\ekv@exparg{\def\ekvpAssertValue}% |
| 598 |
{\ekvpAssert@further{\@secondoftwo\@firstoftwo}{\ekvpIfNoVal}{missing value}} |
| 599 |
\ekv@exparg{\def\ekvpAssertNoValue}% |
| 600 |
{\ekvpAssert@further{}{\ekvpIfNoVal}{superfluous value}} |
| 601 |
\ekv@exparg{\def\ekvpAssertOneValue}% |
| 602 |
{\ekvpAssert@further{}{\ekvp@assert@num@args\@gobble}{argument count != 1}} |
| 603 |
\ekv@exparg{\def\ekvpAssertTwoValues}% |
| 604 |
{\ekvpAssert@further{}{\ekvp@assert@num@args\@gobbletwo}{argument count != 2}} |
| 605 |
\long\def\ekvp@assert@num@args#1#2% |
| 606 |
{% |
| 607 |
\expandafter\ekv@ifempty@\expandafter\ekv@ifempty@A#1#2\ekv@ifempty@B |
| 608 |
\ekv@ifempty@true\ekv@ifempty@A\ekv@ifempty@B\@secondoftwo |
| 609 |
} |
| 610 |
% \end{macrocode} |
| 611 |
% And finally redefine our auxiliary that just does a bit of argument |
| 612 |
% reordering for us. |
| 613 |
% \begin{macrocode} |
| 614 |
\long\def\ekvpAssert@further#1#2#3#4#5{\ekvpAssertTF@{#1}{#4}{#2{#5}}{#3}} |
| 615 |
% \end{macrocode} |
| 616 |
% \end{macro} |
| 617 |
% \end{macro} |
| 618 |
% \end{macro} |
| 619 |
% |
| 620 |
% \begin{macro}[internal]{\ekvpAssert@@EOP,\ekvpAssert@@EOT,\ekvpAssert@@EOA} |
| 621 |
% \begin{macrocode} |
| 622 |
\def\ekvpAssert@@EOA#1#2% |
| 623 |
{\long\def#1##1##2#2##3{\ekvp@err{##1 at `##3'}\ekv@endalignsafe\ekv@zero}} |
| 624 |
\ekvpAssert@@EOA\ekvpAssert@@EOP\ekvpEOP |
| 625 |
\ekvpAssert@@EOA\ekvpAssert@@EOT\ekvpEOT |
| 626 |
\ekvpAssert@@EOA\ekvpAssert@@EOA\ekvpEOA |
| 627 |
% \end{macrocode} |
| 628 |
% \end{macro} |
| 629 |
% |
| 630 |
%^^A=<< |
| 631 |
% |
| 632 |
% \subsubsection{Markers}^^A>>= |
| 633 |
% |
| 634 |
% \begin{macro} |
| 635 |
% {\ekvpGobbleP,\ekvpGobbleT,\ekvpGobbleA,\ekvpEOP,\ekvpEOT,\ekvpEOA} |
| 636 |
% Since after the |\ekvpEOT|, \emph{etc.} markers the full element is placed, |
| 637 |
% they are defined as |\@gobble|, and the functions gobbling up to them gobble |
| 638 |
% that argument as well. |
| 639 |
% \begin{macrocode} |
| 640 |
\long\def\ekvpGobbleP#1\ekvpEOP#2{} |
| 641 |
\long\def\ekvpGobbleT#1\ekvpEOT#2{} |
| 642 |
\long\def\ekvpGobbleA#1\ekvpEOA#2{} |
| 643 |
\let\ekvpEOP\@gobble |
| 644 |
\let\ekvpEOT\@gobble |
| 645 |
\let\ekvpEOA\@gobble |
| 646 |
% \end{macrocode} |
| 647 |
% \end{macro} |
| 648 |
% |
| 649 |
%^^A=<< |
| 650 |
% |
| 651 |
% \subsubsection{Miscellaneous Auxiliaries}^^A>>= |
| 652 |
% |
| 653 |
% \begin{macro}{\ekvpProtect} |
| 654 |
% \begin{macro}[internal]{\ekvpProtect@,\ekvpProtect@@} |
| 655 |
% The idea of this macro is pretty simple. In contexts in which a |\protected| |
| 656 |
% macro isn't expanded the |\ekvpProtect@@| expansion will just expand to |
| 657 |
% itself and in the process protect the argument using |\unexpanded|. If a |
| 658 |
% |\protected| macro would be expanded the |\ekvpProtect@| will remove |
| 659 |
% |\ekvpProtect@@| and unpack the argument. |
| 660 |
% \begin{macrocode} |
| 661 |
\def\ekvpProtect{\ekvpProtect@\ekvpProtect@@} |
| 662 |
\protected\long\def\ekvpProtect@\ekvpProtect@@#1{#1} |
| 663 |
\long\def\ekvpProtect@@#1{\ekv@unexpanded{\ekvpProtect@@{#1}}} |
| 664 |
% \end{macrocode} |
| 665 |
% \end{macro} |
| 666 |
% \end{macro} |
| 667 |
% |
| 668 |
%^^A=<< |
| 669 |
% |
| 670 |
% \subsubsection{Error messages}^^A>>= |
| 671 |
% |
| 672 |
% \begin{macro}[internal] |
| 673 |
% { |
| 674 |
% \ekvp@err,\ekvp@err@unknownparser,\ekvp@err@noval,\ekvp@err@missingtype, |
| 675 |
% \ekvp@errm |
| 676 |
% } |
| 677 |
% These should be pretty straight forward. We use |\ekverr| to throw |
| 678 |
% expandable errors. |
| 679 |
% \begin{macrocode} |
| 680 |
\protected\long\def\ekvp@errm#1{\errmessage{expkv-pop Error: #1}} |
| 681 |
\ekv@exparg{\long\def\ekvp@err#1}{\ekverr{expkv-pop}{#1}} |
| 682 |
\def\ekvp@err@unknownparser#1{\ekvp@err{unknown parser `#1'}} |
| 683 |
\long\def\ekvp@err@noval#1#2#3{\ekvp@err{missing value for `#3'}} |
| 684 |
\long\def\ekvp@err@missingtype#1#2#3#4{\ekvp@err{missing type in `#3'}} |
| 685 |
\long\def\ekvp@err@unknownmarker#1{\ekvp@err{unknown marker `#1'}} |
| 686 |
% \end{macrocode} |
| 687 |
% \end{macro} |
| 688 |
% |
| 689 |
%^^A=<< |
| 690 |
% |
| 691 |
% Undefine the no longer needed |\ekvp@prefix| and restore the category code of |
| 692 |
% |@|: |
| 693 |
% \begin{macrocode} |
| 694 |
\let\ekvp@prefix\ekvp@undefined |
| 695 |
\catcode`\@=\ekvp@tmp |
| 696 |
% \end{macrocode} |
| 697 |
% |
| 698 |
% \gobbledocstriptag |
| 699 |
%</tex> |
| 700 |
%^^A=<< |