summaryrefslogtreecommitdiff
path: root/luatexbase-cctb.dtx
diff options
context:
space:
mode:
authorManuel Pégourié-Gonnard <mpg@elzevir.fr>2011-05-21 14:58:26 +0200
committerManuel Pégourié-Gonnard <mpg@elzevir.fr>2011-05-21 14:58:26 +0200
commit854b18e30b45d8bdfb36ee90db29c7433b3b2014 (patch)
tree20a9a339c58a503a9fff5328d5da003ba6c1b6e5 /luatexbase-cctb.dtx
parent6ae09a2795872820c7848ea496940cbabceeb204 (diff)
downloadluatexbase-854b18e30b45d8bdfb36ee90db29c7433b3b2014.tar.gz
implement catcode table (number) stacks
Diffstat (limited to 'luatexbase-cctb.dtx')
-rw-r--r--luatexbase-cctb.dtx94
1 files changed, 87 insertions, 7 deletions
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}