summaryrefslogtreecommitdiff
path: root/macros/latex/exptl/thmtools/parseargs.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/exptl/thmtools/parseargs.dtx')
-rw-r--r--macros/latex/exptl/thmtools/parseargs.dtx80
1 files changed, 80 insertions, 0 deletions
diff --git a/macros/latex/exptl/thmtools/parseargs.dtx b/macros/latex/exptl/thmtools/parseargs.dtx
new file mode 100644
index 0000000000..8f4aa42171
--- /dev/null
+++ b/macros/latex/exptl/thmtools/parseargs.dtx
@@ -0,0 +1,80 @@
+% \iffalse meta-comment
+%
+% Copyright (C) 2008 by Ulrich M. Schwarz
+%
+% This file may be distributed and/or modified under the conditions of
+% the LaTeX Project Public License, version 1.3a.
+% The license can be obtained from
+% http://www.latex-project.org/lppl/lppl-1-3a.txt
+%
+% \fi
+%
+%\iffalse (hide this from DocInput)
+%<*parseargs>
+%\fi
+%
+% The main command provided by the package is |\parse|\marg{spec}.
+% \emph{spec} consists of groups of commands. Each group should set up the
+% command |\@parsecmd| which is then run. The important point is that
+% |\@parsecmd| will pick up its arguments from the running text, not from
+% the rest of \emph{spec}. When it's done storing the arguments,
+% |\@parsecmd| must call |\@parse| to continue with the next element of
+% \emph{spec}. The process terminates when we run out of spec.
+%
+% Helper macros are provided for the three usual argument types: mandatory,
+% optional, and flag.
+%
+%\StopEventually{}
+% \begin{macrocode}
+
+\newtoks\@parsespec
+\def\parse@endquark{\parse@endquark}
+\newcommand\parse[1]{%
+ \@parsespec{#1\parse@endquark}\@parse}
+
+\newcommand\@parse{%
+ \edef\p@tmp{\the\@parsespec}%
+ \ifx\p@tmp\parse@endquark
+ \expandafter\@gobble
+ \else
+% \typeout{parsespec remaining: \the\@parsespec}%
+ \expandafter\@firstofone
+ \fi{%
+ \@parsepop
+ }%
+}
+\def\@parsepop{%
+ \expandafter\p@rsepop\the\@parsespec\@nil
+ \@parsecmd
+}
+\def\p@rsepop#1#2\@nil{%
+ #1%
+ \@parsespec{#2}%
+}
+
+\newcommand\parseOpt[4]{%
+ %\parseOpt{openchar}{closechar}{yes}{no}
+% \typeout{attemping #1#2...}%
+ \def\@parsecmd{%
+ \@ifnextchar#1{\@@reallyparse}{#4\@parse}%
+ }%
+ \def\@@reallyparse#1##1#2{%
+ #3\@parse
+ }%
+}
+
+\newcommand\parseMand[1]{%
+ %\parseMand{code}
+ \def\@parsecmd##1{#1\@parse}%
+}
+
+\newcommand\parseFlag[3]{%
+ %\parseFlag{flagchar}{yes}{no}
+ \def\@parsecmd{%
+ \@ifnextchar#1{#2\expandafter\@parse\@gobble}{#3\@parse}%
+ }%
+}
+% \end{macrocode}
+%\iffalse
+%</parseargs>
+%\fi