blob: c364c35076a0c8f517d09f23d8a897637a84c78d (
plain)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
%D \module
%D [ file=mult-aux,
%D version=2010.08.2,
%D title=\CONTEXT\ Multilingual Macros,
%D subtitle=Definitions,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright=PRAGMA]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
%D A generalization of \MKIV-like inheritance. Just something to play
%D with (interface might change).
\unprotect
%D \starttyping
%D \unprotect
%D \def\????aa{@@@@aa}
%D
%D \installparameterhandler \????aa {whatever}
%D \installsetuphandler \????aa {whatever}
%D \installdefinehandler \????aa {whatever} \????aa % #3 == defaultroot
%D \installattributehandler \????aa {whatever}
%D
%D % \installcommandhandler \????aa {whatever} \????aa
%D \protect
%D
%D % \whateverparameter \c!test
%D % \whateverparameterhash \c!test
%D % \namedwhateverparameter \mycurrentwhatever \c!test
%D % \dosetwhateverattributes \c!style \c!color
%D % \everydefinewhatever (sets \currentwhatever)
%D % \everypresetwhatever (can be used to reset parameters as we can redefine)
%D % \everysetupwhatever (sets \currentwhatever)
%D
%D \starttext
%D \definewhatever[first] \definewhatever[second][first]
%D test: \def\currentwhatever{first} \whateverparameter{method} \par
%D \setupwhatever [method=unset] test: \def\currentwhatever{first} \whateverparameter{method} \par
%D \setupwhatever[first] [method=first] test: \def\currentwhatever{first} \whateverparameter{method} \par
%D test: \def\currentwhatever{second} \whateverparameter{method} \par
%D \setupwhatever[second][method=second] test: \def\currentwhatever{second} \whateverparameter{method} \par
%D \stoptext
%D \stoptyping
% problem: every* could clash
% faster but assumes \c!always
%
% \unexpanded\def\doinstallparameterhandler#1#2#3#4#5#6#7#8#9% \??aa {whatever} \current..
% {\def#3##1{\csname#6{#1#2}##1\endcsname}%
% \def#4##1{#7{#1#2}##1}%
% \def#5##1##2{\csname#6{#1##2}##1\endcsname}%
% \def#6##1##2{\ifcsname##1##2\endcsname##1##2\else\expandafter#8\csname##1\s!parent\endcsname##2\fi}%
% \def#7##1##2{\ifcsname##1##2\endcsname ##1\else\expandafter#9\csname##1\s!parent\endcsname##2\fi}%
% \def#8##1##2{\ifx##1\relax\s!empty\else#6{##1}##2\fi}%
% \def#9##1##2{\ifx##1\relax \else#7{##1}##2\fi}}
\unexpanded\def\doinstallparameterhandler#1#2#3#4#5#6#7#8#9% \??aa {whatever} \current..
{\def#3##1{\csname#6{#1#2}{##1}\endcsname}%
\def#4##1{#7{#1#2}{##1}}%
\def#5##1##2{\csname#6{#1##1}{##2}\endcsname}%
\def#6##1##2{\ifcsname##1##2\endcsname##1##2\else\expandafter#8\csname##1\s!parent\endcsname{##2}\fi}%
\def#7##1##2{\ifcsname##1##2\endcsname ##1\else\expandafter#9\csname##1\s!parent\endcsname{##2}\fi}%
\def#8##1##2{\ifx##1\relax\s!empty\else#6{##1}{##2}\fi}%
\def#9##1##2{\ifx##1\relax \else#7{##1}{##2}\fi}}
% todo: \def\detokenized...parameter#1{\detokenize\expandafter\expandafter\expandafter{\csname#1#2\endcsname}} % always root
\def\installparameterhandler#1#2%
{\normalexpanded
{\doinstallparameterhandler
{\noexpand#1}% \??aa
\expandafter\noexpand\csname current#2\endcsname
\expandafter\noexpand\csname #2parameter\endcsname % can move
\expandafter\noexpand\csname #2parameterhash\endcsname % can move
\expandafter\noexpand\csname named#2parameter\endcsname % can move
\expandafter\noexpand\csname do#2parameter\endcsname
\expandafter\noexpand\csname do#2parameterhash\endcsname
\expandafter\noexpand\csname do#2parentparameter\endcsname
\expandafter\noexpand\csname do#2parentparameterhash\endcsname}}
% faster but assumes \c!always
%
% \unexpanded\def\doinstallattributehandler#1#2#3% #1 not used here
% {\expandafter\def\csname doset#2attributes\endcsname##1##2% style color
% {\edef\fontattributehash {#3##1}%
% \edef\colorattributehash{#3##2}%
% \ifx\fontattributehash \empty\else\dosetfontattribute \fontattributehash ##1\fi
% \ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash##2\fi}}
\unexpanded\def\doinstallattributehandler#1#2#3% #1 not used here
{\expandafter\def\csname doset#2attributes\endcsname##1##2% style color
{\edef\fontattributehash {#3{##1}}%
\edef\colorattributehash{#3{##2}}%
\ifx\fontattributehash \empty\else\dosetfontattribute \fontattributehash {##1}\fi
\ifx\colorattributehash\empty\else\dosetcolorattribute\colorattributehash{##2}\fi}}
\def\installattributehandler#1#2%
{\normalexpanded
{\doinstallattributehandler
{\noexpand#1}% \??aa
{\noexpand#2}% whatever
\expandafter\noexpand\csname #2parameterhash\endcsname}}
\unexpanded\def\doinstalldefinehandler#1#2#3#4#5#6#7%
{\unexpanded\expandafter\def\csname define#2\endcsname{\dodoubleempty#5}%
\expandafter\newtoks\csname everydefine#2\endcsname
\def#5[##1][##2]%
{\edef#4{##1}%
\the#6% predefine
\ifsecondargument
\getparameters[#1#4][\s!parent=#1,##2]%
\else
\getparameters[#1#4][\s!parent=#3]%
\fi
\the#7}}
\def\installdefinehandler#1#2#3%
{\normalexpanded
{\doinstalldefinehandler
{\noexpand#1}% \??aa
{#2}% whatever
{#3}% root
\expandafter\noexpand\csname current#2\endcsname
\expandafter\noexpand\csname dodefine#2\endcsname
\expandafter\noexpand\csname everypreset#2\endcsname
\expandafter\noexpand\csname everydefine#2\endcsname}}
\unexpanded\def\doinstallsetuphandler#1#2#3#4#5%
{\unexpanded\expandafter\def\csname setup#2\endcsname{\dodoubleempty#4}%
\expandafter\newtoks\csname everysetup#2\endcsname
\def#4[##1][##2]%
{\ifsecondargument
\def\docommand####1% we will have a simple one as well
{\edef#3{##1#1}%
\getparameters[#1#3][##2]%
\the#5}%
\processcommalist[##1]\docommand
\else
\let#3\empty
\getparameters[#1][##1]%
\the#5%
\fi}}
\def\installsetuphandler#1#2%
{\normalexpanded
{\doinstallsetuphandler
{\noexpand#1}% \??aa
{#2}% whatever
\expandafter\noexpand\csname current#2\endcsname
\expandafter\noexpand\csname dosetup#2\endcsname
\expandafter\noexpand\csname everysetup#2\endcsname}}
\def\installcommandhandler#1#2#3% \??self name \??parent (can be \??self)
{\installparameterhandler{#1}{#2}%
\installdefinehandler {#1}{#2}#3%
\installsetuphandler {#1}{#2}%
\installattributehandler{#1}{#2}}
\protect
|