File: parseargs.dtx

package info (click to toggle)
texlive-extra 2022.20230122-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,466,588 kB
  • sloc: perl: 398,710; xml: 35,871; python: 29,125; cs: 25,850; sh: 17,610; makefile: 17,304; ansic: 15,490; java: 12,811; javascript: 9,898; lisp: 1,755; csh: 1,129; ruby: 1,072; awk: 151; tcl: 142; pascal: 138; cpp: 41; sed: 36; haskell: 5
file content (82 lines) | stat: -rw-r--r-- 2,046 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
% \iffalse meta-comment
%
% Copyright (C) 2008-2014 by Ulrich M. Schwarz
% Copyright (C) 2019      by Frank Mittelbach
% Copyright (C) 2020-     by Yukai Chou
%
% This file may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, version 1.3c.
% The license can be obtained from
% http://www.latex-project.org/lppl/lppl-1-3c.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