1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17\registerctxluafile{catcini}{}
18
19\unprotect
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\def\promote#1{\scratchcounter#1\let#1\undefined\newcount#1#1\scratchcounter}
60
61\promote\escapecatcode
62\promote\begingroupcatcode
63\promote\endgroupcatcode
64\promote\mathshiftcatcode
65\promote\alignmentcatcode
66\promote\endoflinecatcode
67\promote\parametercatcode
68\promote\superscriptcatcode
69\promote\subscriptcatcode
70\promote\ignorecatcode
71\promote\spacecatcode
72\promote\lettercatcode
73\promote\othercatcode
74\promote\activecatcode
75\promote\commentcatcode
76\promote\invalidcatcode
77
78\promote\tabasciicode
79\promote\newlineasciicode
80\promote\formfeedasciicode
81\promote\endoflineasciicode
82\promote\endoffileasciicode
83\promote\spaceasciicode
84\promote\exclamationmarkasciicode
85\promote\doublequoteasciicode
86\promote\hashasciicode
87\promote\dollarasciicode
88\promote\commentasciicode
89\promote\ampersandasciicode
90\promote\singlequoteasciicode
91\promote\primeasciicode
92\promote\hyphenasciicode
93\promote\forwardslashasciicode
94\promote\colonasciicode
95\promote\lessthanasciicode
96\promote\morethanasciicode
97\promote\questionmarkasciicode
98\promote\atsignasciicode
99\promote\backslashasciicode
100\promote\circumflexasciicode
101\promote\underscoreasciicode
102\promote\leftbraceasciicode
103\promote\barasciicode
104\promote\rightbraceasciicode
105\promote\tildeasciicode
106\promote\delasciicode
107
108\let\promote\undefined
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128\begingroup
129 \letcharcode\newlineasciicode\relax \xdef\outputnewlinechar{\Uchar\newlineasciicode}
130\endgroup
131
132
133
134
135
136
137
138
139
140
141
142
143\protected\def\initializenewlinechar
144 {\begingroup
145 \letcharcode\newlineasciicode\relax
146 \newlinechar\newlineasciicode
147 \xdef\outputnewlinechar{\Uchar\newlineasciicode}
148 \endgroup}
149
150
151
152
153
154
155
156
157
158
159
160
161
162\installsystemnamespace {catcodelet}
163\installsystemnamespace {catcodedef}
164\installsystemnamespace {catcodeued}
165\installsystemnamespace {catcodeget}
166
167\installsystemnamespace {catcodetablet}
168\installsystemnamespace {catcodetablen}
169
170\newcount\c_syst_catcodes_n \c_syst_catcodes_n\zerocount
171\newcount\c_syst_catcodes_a
172\newcount\c_syst_catcodes_b
173\newcount\c_syst_catcodes_c
174
175\protected\def\newcatcodetable#1
176 {\global\advance\c_syst_catcodes_n\plusone
177 \expandafter\xdef\csname\??catcodetablen\number\c_syst_catcodes_n\endcsname{\string#1}
178 \newconstant#1
179 #1\c_syst_catcodes_n
180 \ctxlua{catcodes.register("\expandafter\gobbleoneargument\string#1",\number#1)}}
181
182\newtoks \everysetdefaultcatcodes
183
184\everysetdefaultcatcodes
185 {\catcode\backslashasciicode\othercatcode
186 \catcode\endoflineasciicode\othercatcode
187 \catcode\spaceasciicode \othercatcode
188 \catcode\commentasciicode \othercatcode
189 \catcode\delasciicode \othercatcode}
190
191\protected\def\startcatcodetable#1#2\stopcatcodetable
192 {\begingroup
193 \catcodetable\inicatcodes
194 \the\everysetdefaultcatcodes
195 #2
196 \savecatcodetable#1\relax
197 \endgroup}
198
199\let\stopcatcodetable\relax
200
201\protected\def\startextendcatcodetable#1#2\stopextendcatcodetable
202 {\begingroup
203 \catcodetable#1\relax
204 \globaldefs\plusone
205 #2
206 \globaldefs\zerocount
207 \endgroup}
208
209\let\stopextendcatcodetable\relax
210
211\protected\def\permitcircumflexescape
212 {\catcode\circumflexasciicode\superscriptcatcode}
213
214\let\permitcaretescape\permitcircumflexescape
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230\setnewconstant\c_syst_catcodes_hack\tildeasciicode
231
232
233
234
235\def\letcatcodecommand{\afterassignment\syst_catcodes_let_a\c_syst_catcodes_a}
236\def\defcatcodecommand{\afterassignment\syst_catcodes_def_a\c_syst_catcodes_a}
237\def\uedcatcodecommand{\afterassignment\syst_catcodes_ued_a\c_syst_catcodes_a}
238
239\def\syst_catcodes_let_a{\afterassignment\syst_catcodes_let_b\c_syst_catcodes_b}
240\def\syst_catcodes_def_a{\afterassignment\syst_catcodes_def_b\c_syst_catcodes_b}
241\def\syst_catcodes_ued_a{\afterassignment\syst_catcodes_ued_b\c_syst_catcodes_b}
242
243\def\syst_catcodes_let_b
244 {\ifcsname\??catcodelet\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname
245 \expandafter\lastnamedcs
246 \else
247 \expandafter\syst_catcodes_let_c
248 \fi}
249
250\def\syst_catcodes_def_b
251 {\ifcsname\??catcodedef\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname
252 \expandafter\lastnamedcs
253 \else
254 \expandafter\syst_catcodes_def_c
255 \fi}
256
257\def\syst_catcodes_ued_b
258 {\ifcsname\??catcodeued\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname
259 \expandafter\lastnamedcs
260 \else
261 \expandafter\syst_catcodes_ued_c
262 \fi}
263
264\def\syst_catcodes_let_c
265 {\expandafter\gdef\csname\??catcodelet\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\expandafter\endcsname\expandafter
266 {\expandafter\let\csname\??catcodeget\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname}
267 \syst_catcodes_reinstate_unexpanded
268 \csname\??catcodelet\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname}
269
270\def\syst_catcodes_def_c
271 {\expandafter\gdef\csname\??catcodedef\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\expandafter\endcsname
272 \expandafter##\expandafter1\expandafter
273 {\expandafter\def\csname\??catcodeget\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname{##1}}
274 \syst_catcodes_reinstate_normal
275 \csname\??catcodedef\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname}
276
277\def\syst_catcodes_ued_c
278 {\expandafter\gdef\csname\??catcodeued\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\expandafter\endcsname
279 \expandafter##\expandafter1\expandafter
280 {\expandafter\protected\expandafter\def\csname\??catcodeget\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname{##1}}
281 \syst_catcodes_reinstate_unexpanded
282 \csname\??catcodeued\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname}
283
284\def\reinstatecatcodecommand{\afterassignment\syst_catcodes_reinstate_normal\c_syst_catcodes_b}
285
286\def\syst_catcodes_reinstate_normal
287 {\begingroup
288 \uccode\c_syst_catcodes_hack\c_syst_catcodes_b
289 \catcode\uccode\c_syst_catcodes_hack\activecatcode
290 \uppercase{\xdef{\noexpand\catcodecommand{\number\c_syst_catcodes_b}}}
291 \endgroup}
292
293\def\syst_catcodes_reinstate_unexpanded
294 {\begingroup
295 \uccode\c_syst_catcodes_hack\c_syst_catcodes_b
296 \catcode\uccode\c_syst_catcodes_hack\activecatcode
297 \uppercase{\protected\xdef{\noexpand\catcodecommand{\number\c_syst_catcodes_b}}}
298 \endgroup}
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317\newconstant\defaultcatcodetable
318
319\def\catcodecommand#1
320 {\csname\??catcodeget\number
321 \ifcsname\??catcodeget\number\currentcatcodetable:\number#1\endcsname
322 \currentcatcodetable \else \defaultcatcodetable
323 \fi
324 :\number#1\endcsname}
325
326
327
328
329
330
331
332
333
334
335
336
337
338\newcount\c_syst_catcodes_level
339
340\protected\def\pushcatcodetable
341 {\advance\c_syst_catcodes_level\plusone
342 \syst_catcodes_trace_push
343 \expandafter\chardef\csname\??catcodetablet\number\c_syst_catcodes_level\endcsname\currentcatcodetable}
344
345\protected\def\popcatcodetable
346 {\ifcase\c_syst_catcodes_level
347 \syst_catcodes_trace_nesting_error
348 \else
349 \expandafter\catcodetable\csname\??catcodetablet\number\c_syst_catcodes_level\endcsname
350 \syst_catcodes_trace_pop
351 \advance\c_syst_catcodes_level\minusone
352 \fi}
353
354\protected\def\syst_catcodes_trace_nesting_error
355 {\immediate\write\statuswrite{}
356 \immediate\write\statuswrite{Fatal error: catcode pushpop mismatch. Fix this! (restore level: \number\c_syst_catcodes_level)}\wait\end
357 \immediate\write\statuswrite{}}
358
359\protected\def\restorecatcodes
360 {\ifnum\c_syst_catcodes_level>\plusone
361 \expandafter\catcodetable\csname\??catcodetablet\number\numexpr\c_syst_catcodes_level1\relax\endcsname
362 \fi}
363
364
365
366\protected\def\setcatcodetable#1
367 {\catcodetable#1
368
369 \syst_catcodes_trace_set}
370
371
372
373
374
375
376
377\protected\def\tracecatcodetables
378 {\def\syst_catcodes_trace_set {\syst_catcodes_trace{set \catcodetablename\space at \number\c_syst_catcodes_level}}
379 \def\syst_catcodes_trace_push{\syst_catcodes_trace{push \catcodetablename\space from \syst_catcodes_prev\space at \number\c_syst_catcodes_level}}
380 \def\syst_catcodes_trace_pop {\syst_catcodes_trace{pop \catcodetablename\space to \syst_catcodes_prev\space at \number\c_syst_catcodes_level}}}
381
382\def\syst_catcodes_trace#1{\immediate\write\statuswrite{[#1]}}
383
384\def\syst_catcodes_prev
385 {\ifnum\numexpr\c_syst_catcodes_level1\relax>\zerocount
386 \csname\??catcodetablen\number\csname\??catcodetablet\number\numexpr\c_syst_catcodes_level1\relax\endcsname\endcsname
387 \else
388
389 \fi}
390
391\def\catcodetablename
392 {\ifnum\currentcatcodetable>\zerocount
393 \csname\??catcodetablen\number\currentcatcodetable\endcsname
394 \else
395
396 \fi}
397
398\let\syst_catcodes_trace_set \empty
399\let\syst_catcodes_trace_push\empty
400\let\syst_catcodes_trace_pop \empty
401
402
403
404\protect
405
406
407
408\newcatcodetable \inicatcodes
409\initcatcodetable\inicatcodes
410
411\let\currentcatcodetable\catcodetable
412
413\endinput
414 |