summaryrefslogtreecommitdiff
path: root/tex/context/base/syst-cat.mkiv
blob: b387eb2edbeb707cd5bf0bca4e19217c3d729299 (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
%D \module
%D   [       file=syst-cat,
%D        version=2006.09.18,
%D          title=\CONTEXT\ System Macros,
%D       subtitle=Catcode Handling,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\unprotect

\def\newcatcodetable#1%
  {\global\advance\cctdefcounter\plusone
   \expandafter\xdef\csname @@ccn:\number\cctdefcounter\endcsname{\string#1}% logging
   \global\mathchardef#1\cctdefcounter}

\newcatcodetable \scratchcatcodetable \initcatcodetable\scratchcatcodetable

\ifx\nilcatcodes \undefined \newcatcodetable \nilcatcodes  \fi
\ifx\texcatcodes \undefined \newcatcodetable \texcatcodes  \fi
\ifx\ctxcatcodes \undefined \newcatcodetable \ctxcatcodes  \fi
\ifx\notcatcodes \undefined \newcatcodetable \notcatcodes  \fi
\ifx\mthcatcodes \undefined \newcatcodetable \mthcatcodes  \fi % brrr
\ifx\vrbcatcodes \undefined \newcatcodetable \vrbcatcodes  \fi
\ifx\prtcatcodes \undefined \newcatcodetable \prtcatcodes  \fi
\ifx\xmlcatcodesn\undefined \newcatcodetable \xmlcatcodesn \fi % normal
\ifx\xmlcatcodese\undefined \newcatcodetable \xmlcatcodese \fi % entitle
\ifx\xmlcatcodesr\undefined \newcatcodetable \xmlcatcodesr \fi % reduce
\ifx\typcatcodesa\undefined \newcatcodetable \typcatcodesa \fi % { }
\ifx\typcatcodesb\undefined \newcatcodetable \typcatcodesb \fi % < >

\newtoks \setdefaultcatcodes

\setdefaultcatcodes
  {\catcode`\\   12
   \catcode`\^^M 12
   \catcode`\    12
   \catcode`\%   12
   \catcode127   12 }

\long\def\startcatcodetable#1#2\stopcatcodetable
  {\bgroup
   \catcodetable\scratchcatcodetable
   \the\setdefaultcatcodes
   #2%
   \savecatcodetable#1\relax
   \egroup}

\newcatcodetable\dummycatcodes

% \long\def\startextendcatcodetable#1#2\stopextendcatcodetable
%   {\bgroup
%    \catcodetable#1\relax
%    #2%
%    \savecatcodetable\dummycatcodes
%    \catcodetable\dummycatcodes
%    \savecatcodetable#1\relax
%    \egroup}

\long\def\startextendcatcodetable#1#2\stopextendcatcodetable
  {\bgroup
   \catcodetable#1\relax
   \globaldefs\plusone
   #2%
   \globaldefs\zerocount
   \egroup}

% ==
%
% \long\def\startextendcatcodetable#1#2\stopextendcatcodetable
%   {\bgroup
%    \scratchcounter\the\catcodetable
%    \catcodetable #1 #2
%    \catcodetable\scratchcounter
%    \egroup}

\def\letcatcodecommand
  {\afterassignment\letcatcodecommanda\cctcountera}

\def\letcatcodecommanda
  {\afterassignment\letcatcodecommandb\cctcounterb}

% construct the definition in lua
%
% \def\letcatcodecommandb
%   {\scratchcounter\catcode\cctcounterb \catcode\cctcounterb=13
%    \directlua\CTXlua{tex.print(tex.texcatcodes,"\\xdef " .. string.char(\number\cctcounterb)
%     .. "{\\noexpand\\catcodecommand{\number\cctcounterb}}")}%
%    \catcode\cctcounterb\scratchcounter
%    \expandafter\let\csname cc:\number\cctcountera:\number\cctcounterb\endcsname}
%
% or less messy:
%
% \def\letcatcodecommandb
%   {\chardef\savedcctcode\catcode\cctcounterb
%    \catcode\cctcounterb=13
%    \expandafter\edef\directlua\CTXlua{tex.sprint(tex.texcatcodes,string.char(\number\cctcounterb))}%
%      {\noexpand\catcodecommand{\number\cctcounterb}}%
%    \catcode\cctcounterb\savedcctcode
%    \expandafter\let\csname cc:\number\cctcountera:\number\cctcounterb\endcsname}

\let\currentcatcodetable\catcodetable

\startruntimectxluacode
    tex.nilcatcodes  = \number\nilcatcodes  ;
    tex.texcatcodes  = \number\texcatcodes  ;
    tex.ctxcatcodes  = \number\ctxcatcodes  ;
    tex.notcatcodes  = \number\notcatcodes  ;
    tex.mthcatcodes  = \number\mthcatcodes  ;
    tex.vrbcatcodes  = \number\vrbcatcodes  ;
    tex.prtcatcodes  = \number\prtcatcodes  ;
    tex.xmlcatcodes  = \number\xmlcatcodesn ;
    tex.xmlcatcodesn = \number\xmlcatcodesn ; % normal
    tex.xmlcatcodese = \number\xmlcatcodese ; % entitle
    tex.xmlcatcodesr = \number\xmlcatcodesr ; % reduce
    tex.typcatcodesa = \number\typcatcodesa ; % { }
    tex.typcatcodesb = \number\typcatcodesb ; % < >
\stopruntimectxluacode

\protect \endinput