[latex3-commits] [git/LaTeX3-latex3-latex3] master: Rearrange cctab code to collect LuaTeX branch (6681c50)

Joseph Wright joseph.wright at morningstar2.co.uk
Mon Oct 1 22:34:12 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/6681c50cb65e04296087b8a96610993066386dcf

>---------------------------------------------------------------

commit 6681c50cb65e04296087b8a96610993066386dcf
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Mon Oct 1 20:49:47 2018 +0100

    Rearrange cctab code to collect LuaTeX branch


>---------------------------------------------------------------

6681c50cb65e04296087b8a96610993066386dcf
 l3experimental/l3cctab/l3cctab.dtx |  165 +++++++++++++++++++-----------------
 1 file changed, 85 insertions(+), 80 deletions(-)

diff --git a/l3experimental/l3cctab/l3cctab.dtx b/l3experimental/l3cctab/l3cctab.dtx
index 4508821..963c3e5 100644
--- a/l3experimental/l3cctab/l3cctab.dtx
+++ b/l3experimental/l3cctab/l3cctab.dtx
@@ -157,7 +157,30 @@
 % \end{variable}
 % \end{variable}
 %
+% \begin{variable}{\l_@@_tmp_tl}
+%   Scratch space.
+%    \begin{macrocode}
+%<*initex>
+\tl_new:N \l_@@_tmp_tl
+%</initex>
+%    \end{macrocode}
+% \end{variable}
+%
 % \begin{macro}{\cctab_new:N}
+% \begin{macro}{\cctab_begin:N}
+% \begin{macro}{\cctab_end:}
+% \begin{macro}{\cctab_gset:Nn}
+%   As \LuaTeX{} offers engine support for category code tables, and this is
+%   entirely lacking from the other engines, we need two complementary
+%   approaches here. Rather than intermix them, we split the set up based on
+%   engine. (Some future \XeTeX{} may add support, at which point the
+%   conditional here would be subtly different.)
+%
+%   First, the \LuaTeX{} case.
+%    \begin{macrocode}
+\sys_if_engine_luatex:TF
+  {
+%    \end{macrocode}
 %   Creating a new category code table is done slightly differently
 %   from other registers. Low-numbered tables are more efficiently-stored
 %   than high-numbered ones. There is also a need to have a stack of
@@ -166,113 +189,95 @@
 %   tables, and even ones for the stack. Here, therefore, the odd numbers
 %   are allocated.
 %    \begin{macrocode}
-\cs_new_protected:Npn \cctab_new:N #1
-  {
-    \__kernel_chk_if_free_cs:N #1
-    \int_gadd:Nn \g_@@_allocate_int { 2 }
-    \int_compare:nNnTF
-      \g_@@_allocate_int <  { \c_max_register_int + 1 }
-       {
-         \tex_global:D \tex_chardef:D #1 \g_@@_allocate_int
-         \tex_initcatcodetable:D #1
-       }
-       { \__kernel_msg_fatal:nnx { kernel } { out-of-registers } { cctab } }
-  }
-\sys_if_engine_luatex:F
-  {
-    \cs_set_protected:Npn \cctab_new:N #1
-      {
-        \__kernel_msg_error:nnx { kernel } { bad-engine }
-          { \exp_not:N \cctab_new:N }
-      }
-  }
-%<*package>
-\sys_if_engine_luatex:T
-  {
-    \cs_set_protected:Npn \cctab_new:N #1
+    \cs_new_protected:Npn \cctab_new:N #1
       {
         \__kernel_chk_if_free_cs:N #1
+%<*initex>
+        \int_gadd:Nn \g_@@_allocate_int { 2 }
+        \int_compare:nNnTF
+          \g_@@_allocate_int < { \c_max_register_int + 1 }
+           {
+             \tex_global:D \tex_chardef:D #1 \g_@@_allocate_int
+             \tex_initcatcodetable:D #1
+           }
+           {
+             \__kernel_msg_fatal:nnx
+               { kernel } { out-of-registers } { cctab }
+           }
+%</initex>
+%<*package>
         \newcatcodetable #1
         \tex_initcatcodetable:D #1
-      }
-  }
 %</package>
+      }
 %    \end{macrocode}
-% \end{macro}
-%
-% \begin{macro}{\cctab_begin:N}
-% \begin{macro}{\cctab_end:}
-% \begin{variable}{\l_@@_tmp_tl}
 %   The aim here is to ensure that the saved tables are read-only. This is
 %   done by using a stack of tables which are not read only, and actually
 %   having them as \enquote{in use} copies.
 %    \begin{macrocode}
-\cs_new_protected:Npn \cctab_begin:N #1
-  {
-    \seq_gpush:Nx \g_@@_stack_seq { \tex_the:D \tex_catcodetable:D }
-    \tex_catcodetable:D #1
-    \int_gadd:Nn \g_@@_stack_int { 2 }
-    \int_compare:nNnT \g_@@_stack_int > \c_max_register_int
-      { \__kernel_msg_fatal:nn { kernel } { cctab-stack-full } }
-    \tex_savecatcodetable:D \g_@@_stack_int
-    \tex_catcodetable:D \g_@@_stack_int
-  }
-\cs_new_protected_nopar:Npn \cctab_end:
-  {
-    \int_gsub:Nn \g_@@_stack_int { 2 }
-    \seq_if_empty:NTF \g_@@_stack_seq
-      { \tl_set:Nn \l_@@_tmp_tl { 0 } }
-      { \seq_gpop:NN \g_@@_stack_seq \l_@@_tmp_tl }
-    \tex_catcodetable:D \l_@@_tmp_tl \scan_stop:
-  }
-\sys_if_engine_luatex:F
-  {
-    \cs_set_protected:Npn \cctab_begin:N #1
+    \cs_new_protected:Npn \cctab_begin:N #1
       {
-        \__kernel_msg_error:nnxx { kernel } { bad-engine }
-          { \exp_not:N \cctab_begin:N } {#1}
+%<*initex>
+        \seq_gpush:Nx \g_@@_stack_seq { \tex_the:D \tex_catcodetable:D }
+        \tex_catcodetable:D #1
+        \int_gadd:Nn \g_@@_stack_int { 2 }
+        \int_compare:nNnT \g_@@_stack_int > \c_max_register_int
+          { \__kernel_msg_fatal:nn { kernel } { cctab-stack-full } }
+        \tex_savecatcodetable:D \g_@@_stack_int
+        \tex_catcodetable:D \g_@@_stack_int
+%</initex>
+%<*package>
+        \BeginCatcodeRegime #1
+%</package>
       }
-    \cs_set_protected_nopar:Npn \cctab_end:
+    \cs_new_protected:Npn \cctab_end:
       {
-        \__kernel_msg_error:nnx { kernel } { bad-engine }
-          { \exp_not:N \cctab_end: }
-      }
-  }
+%<*initex>
+        \int_gsub:Nn \g_@@_stack_int { 2 }
+        \seq_if_empty:NTF \g_@@_stack_seq
+          { \tl_set:Nn \l_@@_tmp_tl { 0 } }
+          { \seq_gpop:NN \g_@@_stack_seq \l_@@_tmp_tl }
+        \tex_catcodetable:D \l_@@_tmp_tl \scan_stop:
+%</initex>
 %<*package>
-\sys_if_engine_luatex:T
-  {
-    \cs_set_protected:Npn \cctab_begin:N #1 { \BeginCatcodeRegime #1 }
-    \cs_set_protected_nopar:Npn \cctab_end: { \EndCatcodeRegime }
-  }
+        \EndCatcodeRegime
 %</package>
-\tl_new:N \l_@@_tmp_tl
+      }
 %    \end{macrocode}
-% \end{variable}
-% \end{macro}
-% \end{macro}
-%
-% \begin{macro}{\cctab_gset:Nn}
 %   Category code tables are always global, so only one version is needed.
 %   The set up here is simple, and means that at the point of use there is
 %   no need to worry about escaping category codes.
 %    \begin{macrocode}
-\cs_new_protected:Npn \cctab_gset:Nn #1#2
-  {
-    \group_begin:
-      #2
-      \tex_savecatcodetable:D #1
-    \group_end:
+    \cs_new_protected:Npn \cctab_gset:Nn #1#2
+      {
+        \group_begin:
+          #2
+          \tex_savecatcodetable:D #1
+        \group_end:
+      }
   }
-\sys_if_engine_luatex:F
+%    \end{macrocode}
+%   Now the case for other engines.
+%    \begin{macrocode}
   {
-    \cs_set_protected:Npn \cctab_gset:Nn #1#2
+    \cs_new_protected:Npn \cctab_new:N #1
+      {
+      }
+    \cs_new_protected:Npn \cctab_begin:N #1
+      {
+      }
+    \cs_new_protected:Npn \cctab_end:
+      {
+      }
+    \cs_new_protected:Npn \cctab_gset:Nn #1#2
       {
-        \__kernel_msg_error:nnxx { kernel } { bad-engine }
-          { \exp_not:N \cctab_gset:Nn } { #1 {#2} }
       }
   }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
 %
 % \begin{variable}{\c_code_cctab}
 % \begin{variable}{\c_document_cctab}





More information about the latex3-commits mailing list