[latex3-commits] [git/LaTeX3-latex3-latex3] master: Category code tables for non-LuaTeX cases (3dba388)

Joseph Wright joseph.wright at morningstar2.co.uk
Mon Oct 1 23:38:38 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/3dba3889fe6045a7f3e511745a5d18c62f011cdf

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

commit 3dba3889fe6045a7f3e511745a5d18c62f011cdf
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Mon Oct 1 22:38:38 2018 +0100

    Category code tables for non-LuaTeX cases


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

3dba3889fe6045a7f3e511745a5d18c62f011cdf
 l3experimental/l3cctab/l3cctab.dtx |   67 +++++++++++++++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)

diff --git a/l3experimental/l3cctab/l3cctab.dtx b/l3experimental/l3cctab/l3cctab.dtx
index 963c3e5..3c25dc3 100644
--- a/l3experimental/l3cctab/l3cctab.dtx
+++ b/l3experimental/l3cctab/l3cctab.dtx
@@ -257,20 +257,85 @@
       }
   }
 %    \end{macrocode}
-%   Now the case for other engines.
+%   Now the case for other engines. Here, we use an integer array for each
+%   table. The index base is out-by-one, so we have an internal function to
+%   handle that. The rest of the approach here is pretty simple: use a stack
+%   of tables, and save to them at each |begin|. Unlike the \LuaTeX{} case,
+%   we can't accidentally alter a saved table, which makes life a little
+%   easier.
 %    \begin{macrocode}
   {
+    \cs_new_protected:Npn \@@_gstore:Nnn #1#2#3
+      { \intarray_gset:Nnn #1 { #2 + 1 } {#3} }
+%    \end{macrocode}
+%   Following the \LuaTeX{} pattern, a new table starts with \IniTeX{} codes.
+%    \begin{macrocode}
     \cs_new_protected:Npn \cctab_new:N #1
       {
+        \intarray_new:Nn #1 { 256 }
+        \int_step_inline:nn { 256 }
+          { \intarray_gset:Nnn #1 {##1} { 12 } }
+        \@@_gstore:Nnn #1 { 0 } { 9 }
+        \@@_gstore:Nnn #1 { 13 } { 5 }
+        \@@_gstore:Nnn #1 { 32 } { 10 }
+        \@@_gstore:Nnn #1 { 37 } { 14 }
+        \int_step_inline:nnn { 65 } { 90 }
+          { \intarray_gset:Nnn #1 {##1} { 11 } }
+        \@@_gstore:Nnn #1 { 92 } { 0 }
+        \int_step_inline:nnn { 97 } { 122 }
+          { \@@_gstore:Nnn #1 {##1} { 11 } }
+        \@@_gstore:Nnn #1 { 127 } { 15 }
       }
     \cs_new_protected:Npn \cctab_begin:N #1
       {
+        \int_gadd:Nn \g_@@_stack_int { 1 }
+        \int_compare:nNnT \g_@@_stack_int > \c_max_register_int
+          { \__kernel_msg_fatal:nn { kernel } { cctab-stack-full } }
+        \cs_if_exist:cF { g_@@_ \int_use:N \g_@@_stack_int _cctab }
+          {
+            \intarray_new:cn
+              { g_@@_ \int_use:N \g_@@_stack_int _cctab }
+              { 256 }
+          }
+        \int_step_inline:nn { 256 }
+          {
+            \intarray_gset:cnn
+              { g_@@_ \int_use:N \g_@@_stack_int _cctab }
+              {##1}
+              { \char_value_catcode:n { ##1 - 1 } }
+          }
+        \int_step_inline:nn { 256 }
+          {
+            \char_set_catcode:nn { ##1 - 1 }
+              { \intarray_item:Nn #1 {##1} }
+          }
       }
+    \cs_generate_variant:Nn \intarray_new:Nn { c }
+    \cs_generate_variant:Nn \intarray_gset:Nnn { c }
     \cs_new_protected:Npn \cctab_end:
       {
+        \int_step_inline:nn { 256 }
+          {
+            \char_set_catcode:nn { ##1 - 1 }
+              {
+                \intarray_item:cn
+                  { g_@@_ \int_use:N \g_@@_stack_int _cctab }
+                  {##1}
+              }
+          }
+        \int_gsub:Nn \g_@@_stack_int { 1 }
       }
+    \cs_generate_variant:Nn \intarray_item:Nn { c }
     \cs_new_protected:Npn \cctab_gset:Nn #1#2
       {
+        \group_begin:
+          #2
+          \int_step_inline:nn { 256 }
+            {
+              \intarray_gset:Nnn #1 {##1}
+                { \char_value_catcode:n { ##1 - 1 } }
+            }
+        \group_end:
       }
   }
 %    \end{macrocode}





More information about the latex3-commits mailing list