summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--luatexbase-cctb.dtx94
2 files changed, 87 insertions, 9 deletions
diff --git a/TODO b/TODO
index 40cded7..1882671 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
Next actions
------------
-1. Do the catcode table stack à la luatex.sty.
2. Merge with luatex.sty (inc test suite).
3. Coordinate release with Heiko.
@@ -33,7 +32,6 @@ modutils
cctb
----
-- stack à la luatex.sty
- support for unicode-letters?
mcb
diff --git a/luatexbase-cctb.dtx b/luatexbase-cctb.dtx
index e127e5a..0baf01e 100644
--- a/luatexbase-cctb.dtx
+++ b/luatexbase-cctb.dtx
@@ -253,8 +253,8 @@ See source file '\inFileName' for details.
% \begin{quote}
% |\PushCatcodeTableNumStack|\\
% |\IncCatcodeTableStack|\\
-% |\setluatexcatcodetable\CatcodeTableStack{\catcodetable#1}%|\\
-% |\catcodetable\CatcodeTableStack|
+% |\setluatexcatcodetable\CatcodeTableStack{\luatexcatcodetable#1}%|\\
+% |\luatexcatcodetable\CatcodeTableStack|
% \end{quote}
% and \cs{EndCatcodeRegime} is defined as
% \begin{quote}
@@ -387,15 +387,21 @@ See source file '\inFileName' for details.
\luatexbase@ensure@primitive{savecatcodetable}
% \end{macrocode}
%
-% \subsubsection{User macros}
+% \subsubsection{Allocation and temporary tables}
%
-% The allocation macro. Allocate tables starting with 1, since table 0 is
-% the default table. Allocate only odd numbers to allow using even numbers
-% as a stack.
+% Counters for the allocated and temporary tables.
%
% \begin{macrocode}
\newcount\lltxb@catcodetable@alloc
\lltxb@catcodetable@alloc\m@ne
+\newcount\CatcodeTableStack
+\CatcodeTableStack\z@
+% \end{macrocode}
+%
+% The allocation macro. Allocate only odd numbers to allow using even
+% numbers for temporary tables.
+%
+% \begin{macrocode}
\def\newluatexcatcodetable#1{%
\ifnum\lltxb@catcodetable@alloc<65535\relax
\global\advance\lltxb@catcodetable@alloc\tw@
@@ -412,6 +418,30 @@ See source file '\inFileName' for details.
\fi}
% \end{macrocode}
%
+% Allocate a new temporary table, using even numbers.
+%
+% \begin{macrocode}
+\def\IncCatcodeTableStack{%
+ \ifnum\CatcodeTableStack<65534\relax
+ \global\advance\CatcodeTableStack\tw@
+ \else
+ \errmessage{CatcodeTableStack overflow}%
+ \fi}
+% \end{macrocode}
+%
+% Free a temporary table.
+%
+% \begin{macrocode}
+\def\DecCatcodeTableStack{%
+ \ifnum\CatcodeTableStack>\z@
+ \global\advance\CatcodeTableStack-2\relax
+ \else
+ \errmessage{CatcodeTableStack underflow}%
+ \fi}
+% \end{macrocode}
+%
+% \subsubsection{Setting catcode tables}
+%
% A small patch to get two new counters in Plain too.
%
% \begin{macrocode}
@@ -524,12 +554,62 @@ See source file '\inFileName' for details.
}
% \end{macrocode}
%
-% Finally do the shortcuts.
+% Now do the shortcuts.
%
% \begin{macrocode}
\luatexbase@directlua{luatexbase.catcodetable_do_shortcuts()}
% \end{macrocode}
%
+% \subsubsection{Catcode table number stack and regimes}
+%
+% The stack is implemented as a list of (brace-enclosed) \tex arguments.
+% Initially, in contains only $0$, the number of the active table when
+% \luatex starts.
+%
+% \begin{macrocode}
+\def\lltxb@cctb@numstack{0}
+% \end{macrocode}
+%
+% Pushing a number on the stack actually means adding it to the beginning
+% of the list (ie, unshifting it).
+%
+% \begin{macrocode}
+\def\PushCatcodeTableNumStack{%
+ \xdef\lltxb@cctb@numstack{{\the\catcodetable}\lltxb@cctb@numstack}}
+% \end{macrocode}
+%
+% Popping a number off the stack means shifting it.
+%
+% \begin{macrocode}
+\def\PopCatcodeTableNumStack{%
+ \expandafter\lltxb@cctb@numstack@pop\lltxb@cctb@numstack\@nil}
+\def\lltxb@cctb@numstack@pop#1#2\@nil{%
+ \ifx\empty#2\empty
+ \errormessage{Popping from and empty CatcoteTableNumStack}%
+ \luatexcatcodetable\z@
+ \else
+ \def\lltxb@numstack@pop{#2}%
+ \luatexcatcodetable#1\relax
+ \fi}
+% \end{macrocode}
+%
+% Now the catcode regime pseudo-environment as presented in the
+% documentation.
+%
+% \begin{macrocode}
+\def\BeginCatcodeRegime#1{%
+ \PushCatcodeTableNumStack
+ \IncCatcodeTableStack
+ \setluatexcatcodetable\CatcodeTableStack{\luatexcatcodetable#1}%
+ \luatexcatcodetable\CatcodeTableStack}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\def\EndCatcodeRegime{%
+ \DecCatcodeTableStack
+ \PopCatcodeTableNumStack}
+% \end{macrocode}
+%
% That's all, folks!
%
% \begin{macrocode}