| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2008-2014 by Ulrich M. Schwarz |
| 4 |
% Copyright (C) 2019 by Frank Mittelbach |
| 5 |
% Copyright (C) 2020- by Yukai Chou |
| 6 |
% |
| 7 |
% This file may be distributed and/or modified under the conditions of |
| 8 |
% the LaTeX Project Public License, version 1.3c. |
| 9 |
% The license can be obtained from |
| 10 |
% http://www.latex-project.org/lppl/lppl-1-3c.txt |
| 11 |
% |
| 12 |
% \fi |
| 13 |
% |
| 14 |
%\iffalse (hide this from DocInput) |
| 15 |
%<*parseargs> |
| 16 |
%\fi |
| 17 |
% |
| 18 |
% The main command provided by the package is |\parse|\marg{spec}. |
| 19 |
% \emph{spec} consists of groups of commands. Each group should set up the |
| 20 |
% command |\@parsecmd| which is then run. The important point is that |
| 21 |
% |\@parsecmd| will pick up its arguments from the running text, not from |
| 22 |
% the rest of \emph{spec}. When it's done storing the arguments, |
| 23 |
% |\@parsecmd| must call |\@parse| to continue with the next element of |
| 24 |
% \emph{spec}. The process terminates when we run out of spec. |
| 25 |
% |
| 26 |
% Helper macros are provided for the three usual argument types: mandatory, |
| 27 |
% optional, and flag. |
| 28 |
% |
| 29 |
%\StopEventually{} |
| 30 |
% \begin{macrocode} |
| 31 |
|
| 32 |
\newtoks\@parsespec |
| 33 |
\def\parse@endquark{\parse@endquark} |
| 34 |
\newcommand\parse[1]{% |
| 35 |
\@parsespec{#1\parse@endquark}\@parse} |
| 36 |
|
| 37 |
\newcommand\@parse{% |
| 38 |
\edef\p@tmp{\the\@parsespec}% |
| 39 |
\ifx\p@tmp\parse@endquark |
| 40 |
\expandafter\@gobble |
| 41 |
\else |
| 42 |
% \typeout{parsespec remaining: \the\@parsespec}% |
| 43 |
\expandafter\@firstofone |
| 44 |
\fi{% |
| 45 |
\@parsepop |
| 46 |
}% |
| 47 |
} |
| 48 |
\def\@parsepop{% |
| 49 |
\expandafter\p@rsepop\the\@parsespec\@nil |
| 50 |
\@parsecmd |
| 51 |
} |
| 52 |
\def\p@rsepop#1#2\@nil{% |
| 53 |
#1% |
| 54 |
\@parsespec{#2}% |
| 55 |
} |
| 56 |
|
| 57 |
\newcommand\parseOpt[4]{% |
| 58 |
%\parseOpt{openchar}{closechar}{yes}{no} |
| 59 |
% \typeout{attemping #1#2...}% |
| 60 |
\def\@parsecmd{% |
| 61 |
\@ifnextchar#1{\@@reallyparse}{#4\@parse}% |
| 62 |
}% |
| 63 |
\def\@@reallyparse#1##1#2{% |
| 64 |
#3\@parse |
| 65 |
}% |
| 66 |
} |
| 67 |
|
| 68 |
\newcommand\parseMand[1]{% |
| 69 |
%\parseMand{code} |
| 70 |
\def\@parsecmd##1{#1\@parse}% |
| 71 |
} |
| 72 |
|
| 73 |
\newcommand\parseFlag[3]{% |
| 74 |
%\parseFlag{flagchar}{yes}{no} |
| 75 |
\def\@parsecmd{% |
| 76 |
\@ifnextchar#1{#2\expandafter\@parse\@gobble}{#3\@parse}% |
| 77 |
}% |
| 78 |
} |
| 79 |
% \end{macrocode} |
| 80 |
%\iffalse |
| 81 |
%</parseargs> |
| 82 |
%\fi |