diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/base/catc-ini.mkiv')
-rw-r--r-- | Master/texmf-dist/tex/context/base/catc-ini.mkiv | 390 |
1 files changed, 180 insertions, 210 deletions
diff --git a/Master/texmf-dist/tex/context/base/catc-ini.mkiv b/Master/texmf-dist/tex/context/base/catc-ini.mkiv index 9221d17c51f..26c3ceee990 100644 --- a/Master/texmf-dist/tex/context/base/catc-ini.mkiv +++ b/Master/texmf-dist/tex/context/base/catc-ini.mkiv @@ -5,7 +5,7 @@ %D subtitle=Catcode Handling, %D author=Hans Hagen, %D date=\currentdate, -%D copyright={PRAGMA / Hans Hagen \& Ton Otten}] +%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}] %C %C This module is part of the \CONTEXT\ macro||package and is %C therefore copyrighted by \PRAGMA. See mreadme.pdf for @@ -16,53 +16,65 @@ \registerctxluafile{catc-ini}{1.001} +\unprotect + %D A long standing wish has been the availability of catcode %D arrays. Because traditional \TEX\ does not provide this we %D implement a fake method in the \MKII\ file. There is some %D overlap in code with \MKII\ but we take that for granted. -\setnewconstant\escapecatcode 0 -\setnewconstant\begingroupcatcode 1 -\setnewconstant\endgroupcatcode 2 -\setnewconstant\mathshiftcatcode 3 -\setnewconstant\alignmentcatcode 4 -\setnewconstant\endoflinecatcode 5 -\setnewconstant\parametercatcode 6 -\setnewconstant\superscriptcatcode 7 -\setnewconstant\subscriptcatcode 8 -\setnewconstant\ignorecatcode 9 -\setnewconstant\spacecatcode 10 -\setnewconstant\lettercatcode 11 -\setnewconstant\othercatcode 12 \let\other \othercatcode -\setnewconstant\activecatcode 13 \let\active\activecatcode -\setnewconstant\commentcatcode 14 -\setnewconstant\invalidcatcode 15 - -\setnewconstant\tabasciicode 9 -\setnewconstant\newlineasciicode 10 % don't confuse this one with \endoflineasciicode -\setnewconstant\formfeedasciicode 12 -\setnewconstant\endoflineasciicode 13 % somewhat messy but this can be the active \par -\setnewconstant\endoffileasciicode 26 -\setnewconstant\spaceasciicode 32 -\setnewconstant\hashasciicode 35 -\setnewconstant\dollarasciicode 36 -\setnewconstant\commentasciicode 37 -\setnewconstant\ampersandasciicode 38 -\setnewconstant\backslashasciicode 92 % `\\ -\setnewconstant\circumflexasciicode 94 -\setnewconstant\underscoreasciicode 95 -\setnewconstant\leftbraceasciicode 123 % `\{ -\setnewconstant\barasciicode 124 % `\| -\setnewconstant\rightbraceasciicode 125 % `\} -\setnewconstant\tildeasciicode 126 % `\~ -\setnewconstant\delasciicode 127 - -\bgroup +\setnewconstant\escapecatcode 0 +\setnewconstant\begingroupcatcode 1 +\setnewconstant\endgroupcatcode 2 +\setnewconstant\mathshiftcatcode 3 +\setnewconstant\alignmentcatcode 4 +\setnewconstant\endoflinecatcode 5 +\setnewconstant\parametercatcode 6 +\setnewconstant\superscriptcatcode 7 +\setnewconstant\subscriptcatcode 8 +\setnewconstant\ignorecatcode 9 +\setnewconstant\spacecatcode 10 +\setnewconstant\lettercatcode 11 +\setnewconstant\othercatcode 12 % finally obsolete: \let\other \othercatcode +\setnewconstant\activecatcode 13 % finally obsolete: \let\active\activecatcode +\setnewconstant\commentcatcode 14 +\setnewconstant\invalidcatcode 15 + +\setnewconstant\tabasciicode 9 +\setnewconstant\newlineasciicode 10 % don't confuse this one with \endoflineasciicode +\setnewconstant\formfeedasciicode 12 +\setnewconstant\endoflineasciicode 13 % somewhat messy but this can be the active \par +\setnewconstant\endoffileasciicode 26 +\setnewconstant\spaceasciicode 32 +\setnewconstant\exclamationmarkasciicode 33 % ! used in namespace protection +\setnewconstant\doublequoteasciicode 34 % " +\setnewconstant\hashasciicode 35 +\setnewconstant\dollarasciicode 36 +\setnewconstant\commentasciicode 37 +\setnewconstant\ampersandasciicode 38 +\setnewconstant\singlequoteasciicode 39 % ' +\setnewconstant\primeasciicode 39 % ' +\setnewconstant\forwardslashasciicode 47 % / +\setnewconstant\colonasciicode 58 +\setnewconstant\lessthanasciicode 60 % < used as alternative verbatim { +\setnewconstant\morethanasciicode 62 % > used as alternative verbatim } +\setnewconstant\questionmarkasciicode 63 % ? used in namespace protection +\setnewconstant\atsignasciicode 64 % @ used in namespace protection +\setnewconstant\backslashasciicode 92 % `\\ +\setnewconstant\circumflexasciicode 94 +\setnewconstant\underscoreasciicode 95 +\setnewconstant\leftbraceasciicode 123 % `\{ +\setnewconstant\barasciicode 124 % `\| +\setnewconstant\rightbraceasciicode 125 % `\} +\setnewconstant\tildeasciicode 126 % `\~ +\setnewconstant\delasciicode 127 + +\begingroup \catcode \tabasciicode \activecatcode \gdef\activetabtoken {^^I} \gdef\outputnewlinechar {^^J} \catcode \formfeedasciicode \activecatcode \gdef\activeformfeedtoken {^^L} \catcode \endoflineasciicode \activecatcode \gdef\activeendoflinetoken{^^M} -\egroup +\endgroup % \endlinechar = \endoflineasciicode % appended to input lines % \newlinechar = \newlineasciicode % can be used in write @@ -70,33 +82,26 @@ % rather special and used in writing to file: \let\par\outputnewlinechar \def\initializenewlinechar % operating system dependent - {\bgroup + {\begingroup \newlinechar\newlineasciicode \xdef\outputnewlinechar{^^J}% - \egroup} - -\ifx\gobbleoneargument\undefined \long\def\gobbleoneargument#1{} \fi - -\newif \ifrecatcodeuppercharacters % only used in good old tex + \endgroup} -\newcount\cctdefcounter \cctdefcounter\zerocount % 0 = signal, so advance before allocate +\newcount\c_syst_catcodes_n \c_syst_catcodes_n\zerocount % 0 = signal, so advance before allocate +\newcount\c_syst_catcodes_a +\newcount\c_syst_catcodes_b +\newcount\c_syst_catcodes_c -\newcount\cctcountera -\newcount\cctcounterb -\newcount\cctcounterc - -\def\newcatcodetable#1% - {\global\advance\cctdefcounter\plusone - \expandafter\xdef\csname @@ccn:\number\cctdefcounter\endcsname{\string#1}% logging +\normalprotected\def\newcatcodetable#1% we could move the cctdefcounter to lua + {\global\advance\c_syst_catcodes_n\plusone + \expandafter\xdef\csname\??qm:n:\number\c_syst_catcodes_n\endcsname{\string#1}% logging \newconstant#1% - #1\cctdefcounter + #1\c_syst_catcodes_n \ctxlua{catcodes.register("\expandafter\gobbleoneargument\string#1",\number#1)}} -\newcatcodetable \scratchcatcodes \initcatcodetable\scratchcatcodes - -\newtoks \setdefaultcatcodes +\newtoks \everysetdefaultcatcodes -\setdefaultcatcodes +\everysetdefaultcatcodes % this might get dropped {\catcode\backslashasciicode\othercatcode \catcode\endoflineasciicode\othercatcode \catcode\spaceasciicode \othercatcode @@ -104,27 +109,29 @@ \catcode\delasciicode \othercatcode} \long\normalprotected\def\startcatcodetable#1#2\stopcatcodetable - {\bgroup - \catcodetable\scratchcatcodes - \the\setdefaultcatcodes + {\begingroup + \catcodetable\inicatcodes + \the\everysetdefaultcatcodes #2% \savecatcodetable#1\relax - \egroup} + \endgroup} -\def\permitcircumflexescape % to be used grouped - {\catcode\circumflexasciicode\superscriptcatcode} - -\let\permitcaretescape\permitcircumflexescape - -\newcatcodetable\dummycatcodes +\let\stopcatcodetable\relax \long\normalprotected\def\startextendcatcodetable#1#2\stopextendcatcodetable - {\bgroup + {\begingroup \catcodetable#1\relax \globaldefs\plusone #2% \globaldefs\zerocount - \egroup} + \endgroup} + +\let\stopextendcatcodetable\relax + +\normalprotected\def\permitcircumflexescape % to be used grouped + {\catcode\circumflexasciicode\superscriptcatcode} + +\let\permitcaretescape\permitcircumflexescape % == % @@ -135,101 +142,93 @@ % \catcodetable\scratchcounter % \egroup} -\def\letcatcodecommand - {\afterassignment\letcatcodecommanda\cctcountera} - -\def\letcatcodecommanda - {\afterassignment\letcatcodecommandb\cctcounterb} - -\let\currentcatcodetable\catcodetable - %D The next command can be defined in a cleaner way in the %D Mk IV file but we want to have a fast one with a minimal %D chance for interference. Do we still need this complex %D mechanism? Future versions of \MKIV\ might only use %D active characters for very special cases. -\setnewconstant\activehackcode \tildeasciicode +\setnewconstant\c_syst_catcodes_hack\tildeasciicode + +%D Once a catcode is assigned, the next assignments will happen +%D faster. We predefine some prefixes ahead of mult-sys. -%D Once a catcode is assigned, the next assignments will happen faster. +\def\??ql{@@ql} % let : \let +\def\??qd{@@qd} % def : \def +\def\??qu{@@qu} % ued : \unexpanded\def +\def\??qm{@@qm} % \meaning -% (expandable) let +\def\letcatcodecommand{\afterassignment\syst_catcodes_let_a\c_syst_catcodes_a} +\def\defcatcodecommand{\afterassignment\syst_catcodes_def_a\c_syst_catcodes_a} +\def\uedcatcodecommand{\afterassignment\syst_catcodes_ued_a\c_syst_catcodes_a} -\def\letcatcodecommand {\afterassignment\letcatcodecommanda\cctcountera} -\def\letcatcodecommanda{\afterassignment\letcatcodecommandb\cctcounterb} +\def\syst_catcodes_let_a{\afterassignment\syst_catcodes_let_b\c_syst_catcodes_b} +\def\syst_catcodes_def_a{\afterassignment\syst_catcodes_def_b\c_syst_catcodes_b} +\def\syst_catcodes_ued_a{\afterassignment\syst_catcodes_ued_b\c_syst_catcodes_b} -\def\letcatcodecommandb % each time - {\ifcsname CCL:\number\cctcountera:\number\cctcounterb\endcsname - \csname CCL:\number\cctcountera:\number\cctcounterb\expandafter\endcsname +\def\syst_catcodes_let_b % each time + {\ifcsname\??ql:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname + \csname\??ql:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\expandafter\endcsname \else - \expandafter\letcatcodecommandc + \expandafter\syst_catcodes_let_c \fi} -\def\letcatcodecommandc % only first time - {\expandafter\gdef\csname CCL:\number\cctcountera:\number\cctcounterb\expandafter\endcsname\expandafter - {\expandafter\let\csname CCC:\number\cctcountera:\number\cctcounterb\endcsname}% - \reinstatecatcodecommandua % unexpanded - \csname CCL:\number\cctcountera:\number\cctcounterb\endcsname} - -% expandable def - -\def\defcatcodecommand {\afterassignment\defcatcodecommanda\cctcountera} -\def\defcatcodecommanda{\afterassignment\defcatcodecommandb\cctcounterb} - -\def\defcatcodecommandb % each time - {\ifcsname CCD:\number\cctcountera:\number\cctcounterb\endcsname - \csname CCD:\number\cctcountera:\number\cctcounterb\expandafter\endcsname +\def\syst_catcodes_def_b % each time + {\ifcsname\??qd:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname + \csname\??qd:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\expandafter\endcsname \else - \expandafter\defcatcodecommandc + \expandafter\syst_catcodes_def_c \fi} -\def\defcatcodecommandc % only first time (we could use \normalexpanded here) - {\expandafter\gdef\csname CCD:\number\cctcountera:\number\cctcounterb\expandafter\endcsname - \expandafter##\expandafter1\expandafter - {\expandafter\def\csname CCC:\number\cctcountera:\number\cctcounterb\endcsname{##1}}% - \reinstatecatcodecommanda - \csname CCD:\number\cctcountera:\number\cctcounterb\endcsname} +\def\syst_catcodes_ued_b % each time + {\ifcsname\??qu:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname + \csname\??qu:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\expandafter\endcsname + \else + \expandafter\syst_catcodes_ued_c + \fi} -% unexpandable def (e.g. used for discretionaries) +\def\syst_catcodes_let_c % only first time + {\expandafter\gdef\csname\??ql:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\expandafter\endcsname\expandafter + {\expandafter\let\csname\??qm:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname}% + \syst_catcodes_reinstate_unexpanded + \csname\??ql:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname} -\def\uedcatcodecommand {\afterassignment\uedcatcodecommanda\cctcountera} -\def\uedcatcodecommanda{\afterassignment\uedcatcodecommandb\cctcounterb} -\def\uedcatcodecommandb % each time - {\ifcsname CCU:\number\cctcountera:\number\cctcounterb\endcsname - \csname CCU:\number\cctcountera:\number\cctcounterb\expandafter\endcsname - \else - \expandafter\uedcatcodecommandc - \fi} +\def\syst_catcodes_def_c % only first time (we could use \normalexpanded here) + {\expandafter\gdef\csname\??qd:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\expandafter\endcsname + \expandafter##\expandafter1\expandafter + {\expandafter\def\csname\??qm:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname{##1}}% + \syst_catcodes_reinstate_normal + \csname\??qd:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname} -\def\uedcatcodecommandc % only first time - {\expandafter\gdef\csname CCU:\number\cctcountera:\number\cctcounterb\expandafter\endcsname +\def\syst_catcodes_ued_c % only first time + {\expandafter\gdef\csname\??qu:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\expandafter\endcsname \expandafter##\expandafter1\expandafter - {\expandafter\normalprotected\expandafter\def\csname CCC:\number\cctcountera:\number\cctcounterb\endcsname{##1}}% - \reinstatecatcodecommandua % unexpanded - \csname CCU:\number\cctcountera:\number\cctcounterb\endcsname} - -\def\reinstatecatcodecommand{\afterassignment\reinstatecatcodecommanda\cctcounterb} - -\def\reinstatecatcodecommanda % can be used when a direct definition has been done - {\bgroup % and the selector has been lost - \uccode\activehackcode\cctcounterb - \catcode\uccode\activehackcode\activecatcode - \uppercase{\xdef~{\noexpand\catcodecommand{\number\cctcounterb}}}% - \egroup} - -\def\reinstatecatcodecommandua % can be used when a direct definition has been done - {\bgroup % and the selector has been lost - \uccode\activehackcode\cctcounterb - \catcode\uccode\activehackcode\activecatcode - \uppercase{\normalprotected\xdef~{\noexpand\catcodecommand{\number\cctcounterb}}}% - \egroup} + {\expandafter\normalprotected\expandafter\def\csname\??qm:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname{##1}}% + \syst_catcodes_reinstate_unexpanded + \csname\??qu:\number\c_syst_catcodes_a:\number\c_syst_catcodes_b\endcsname} + +\def\reinstatecatcodecommand{\afterassignment\syst_catcodes_reinstate_normal\c_syst_catcodes_b} + +\def\syst_catcodes_reinstate_normal % can be used when a direct definition has been done + {\begingroup % and the selector has been lost + \uccode\c_syst_catcodes_hack\c_syst_catcodes_b + \catcode\uccode\c_syst_catcodes_hack\activecatcode + \uppercase{\xdef~{\noexpand\catcodecommand{\number\c_syst_catcodes_b}}}% + \endgroup} + +\def\syst_catcodes_reinstate_unexpanded % can be used when a direct definition has been done + {\begingroup % and the selector has been lost + \uccode\c_syst_catcodes_hack\c_syst_catcodes_b + \catcode\uccode\c_syst_catcodes_hack\activecatcode + \uppercase{\normalprotected\xdef~{\noexpand\catcodecommand{\number\c_syst_catcodes_b}}}% + \endgroup} \newconstant\defaultcatcodetable \def\catcodecommand#1% - {\csname CCC:\number - \ifcsname CCC:\number\currentcatcodetable:\number#1\endcsname + {\csname\??qm:\number + \ifcsname\??qm:\number\currentcatcodetable:\number#1\endcsname \currentcatcodetable \else \defaultcatcodetable \fi :\number#1\endcsname} @@ -247,108 +246,79 @@ %D what the next macros do. Saving the catcodes can be %D disabled by saying \type{\localcatcodestrue}. -% quite likely we will define \unexpanded earlier on so -% that \normalprotected will go - -\let\savedcatcodetable\relax - -\newcount\catcoderestorelevel +\newcount\c_syst_catcodes_level \normalprotected\def\pushcatcodetable - {\advance\catcoderestorelevel\plusone - \tracepushcatcodetable - \expandafter\chardef\csname scct:\number\catcoderestorelevel\endcsname\currentcatcodetable} + {\advance\c_syst_catcodes_level\plusone + \syst_catcodes_trace_push + \expandafter\chardef\csname\??qm:t:\number\c_syst_catcodes_level\endcsname\currentcatcodetable} \normalprotected\def\popcatcodetable - {\ifcase\catcoderestorelevel - \showcatcodenestingerror + {\ifcase\c_syst_catcodes_level + \syst_catcodes_trace_nesting_error \else - \expandafter\catcodetable\csname scct:\number\catcoderestorelevel\endcsname - \tracepopcatcodetable - \advance\catcoderestorelevel\minusone + \expandafter\catcodetable\csname\??qm:t:\number\c_syst_catcodes_level\endcsname + \syst_catcodes_trace_pop + \advance\c_syst_catcodes_level\minusone \fi} -\normalprotected\def\showcatcodenestingerror % can be overloaded +\normalprotected\def\syst_catcodes_trace_nesting_error {\immediate\write16{}% - \immediate\write16{Fatal error: catcode push/pop mismatch. Fix this!}\wait\end + \immediate\write16{Fatal error: catcode push/pop mismatch. Fix this! (restore level: \number\c_syst_catcodes_level)}\wait\end \immediate\write16{}} \normalprotected\def\restorecatcodes % takes previous level - {\ifnum\catcoderestorelevel>\plusone - \expandafter\catcodetable\csname scct:\number\numexpr\catcoderestorelevel-1\relax\endcsname + {\ifnum\c_syst_catcodes_level>\plusone + \expandafter\catcodetable\csname\??qm:t:\number\numexpr\c_syst_catcodes_level-1\relax\endcsname \fi} -\newtoks\everycatcodetable +% \newtoks\everycatcodetable \normalprotected\def\setcatcodetable#1% {\catcodetable#1% - \the\everycatcodetable - \tracesetcatcodetable} +% \the\everycatcodetable + \syst_catcodes_trace_set} + +%D Handy for debugging: +%D +%D \starttyping +%D \tracecatcodetables +%D \stoptyping -\def\dotracecatcodetable#1{\immediate\write16{[#1]}} +\normalprotected\def\tracecatcodetables + {\def\syst_catcodes_trace_set {\syst_catcodes_trace{set \catcodetablename\space at \number\c_syst_catcodes_level}}% + \def\syst_catcodes_trace_push{\syst_catcodes_trace{push \catcodetablename\space from \syst_catcodes_prev\space at \number\c_syst_catcodes_level}}% + \def\syst_catcodes_trace_pop {\syst_catcodes_trace{pop \catcodetablename\space to \syst_catcodes_prev\space at \number\c_syst_catcodes_level}}} -\def\tracecatcodetables - {\def\tracesetcatcodetable {\dotracecatcodetable{set \catcodetablename\space at \number\catcoderestorelevel}}% - \def\tracepushcatcodetable{\dotracecatcodetable{push \catcodetablename\space from \catcodetableprev\space at \number\catcoderestorelevel}}% - \def\tracepopcatcodetable {\dotracecatcodetable{pop \catcodetablename\space to \catcodetableprev\space at \number\catcoderestorelevel}}} +\def\syst_catcodes_trace#1{\immediate\write16{[#1]}} -\def\catcodetableprev - {\ifnum\numexpr\catcoderestorelevel-1\relax>\zerocount - \csname @@ccn:\number\csname scct:\number\numexpr\catcoderestorelevel-1\relax\endcsname\endcsname +\def\syst_catcodes_prev + {\ifnum\numexpr\c_syst_catcodes_level-1\relax>\zerocount + \csname\??qm:n:\number\csname\??qm:t:\number\numexpr\c_syst_catcodes_level-1\relax\endcsname\endcsname \else -% \fi} \def\catcodetablename {\ifnum\currentcatcodetable>\zerocount - \csname @@ccn:\number\currentcatcodetable\endcsname + \csname\??qm:n:\number\currentcatcodetable\endcsname \else -% \fi} -\ifx\empty\undefined \def\empty{} \fi +\let\syst_catcodes_trace_set \empty +\let\syst_catcodes_trace_push\empty +\let\syst_catcodes_trace_pop \empty -\let\tracesetcatcodetable \empty -\let\tracepushcatcodetable\empty -\let\tracepopcatcodetable \empty +% \tracecatcodetables -%D Handy for debugging: +\protect -% \tracecatcodetables +%D We still have to define these so let's do that now: -% D Only in \MKIV\ (to be used when crossing pages with changed catcodes -% D in the current vector): -% D -% D \starttyping -% D \normalprotected\def\startcrap -% D {\bgroup -% D \pushcatcodes -% D \whitespace -% D \obeylines -% D \activatespacehandler\v!yes -% D \strut} -% D -% D \normalprotected\def\stopcrap -% D {\popcatcodes -% D \egroup} -% D \stoptyping -% -% \newcount\catcodetablelevel -% -% \def\pushcatcodes -% {\bgroup -% \global\advance\catcodetablelevel\plusone -% \ifcsname @@ccf:\number\catcodetablelevel\endcsname \else -% \global\advance\cctdefcounter\plusone -% \expandafter\global\expandafter\chardef\csname @@ccf:\number\catcodetablelevel\endcsname\cctdefcounter -% \fi -% \catcodetable\ctxcatcodes -% \expandafter\savecatcodetable\csname @@ccf:\number\catcodetablelevel\endcsname -% \egroup -% \expandafter\catcodetable\csname @@ccf:\number\catcodetablelevel\endcsname} -% -% \def\popcatcodes -% {\global\advance\catcodetablelevel\minusone} +\newcatcodetable \inicatcodes +\initcatcodetable\inicatcodes -\endinput +\let\currentcatcodetable\catcodetable +\endinput |