[latex3-commits] [git/LaTeX3-latex3-latex3] cctab: \currentgrouplevel alone is not enough (a413f6280)

PhelypeOleinik tex.phelype at gmail.com
Fri Jul 3 03:55:09 CEST 2020


Repository : https://github.com/latex3/latex3
On branch  : cctab
Link       : https://github.com/latex3/latex3/commit/a413f62806f8a867b40537ebd8711b25d11a1c31

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

commit a413f62806f8a867b40537ebd8711b25d11a1c31
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date:   Thu Jul 2 22:55:09 2020 -0300

    \currentgrouplevel alone is not enough


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

a413f62806f8a867b40537ebd8711b25d11a1c31
 l3kernel/l3cctab.dtx              | 34 +++++++++++++++++++++++++---------
 l3kernel/testfiles/m3cctab003.lvt | 20 ++++++++++++++++++++
 l3kernel/testfiles/m3cctab003.tlg | 11 +++++++++++
 3 files changed, 56 insertions(+), 9 deletions(-)

diff --git a/l3kernel/l3cctab.dtx b/l3kernel/l3cctab.dtx
index ec269efe1..e3f5e3373 100644
--- a/l3kernel/l3cctab.dtx
+++ b/l3kernel/l3cctab.dtx
@@ -516,9 +516,10 @@
   {
     \@@_chk_if_valid:NT #1
       {
-        \@@_chk_group_begin:
         \seq_gpop:NNF \g_@@_unused_seq \l_@@_internal_tl
           { \@@_begin_aux: }
+        \exp_args:Nx \@@_chk_group_begin:n
+          { \@@_nesting_number:N \l_@@_internal_tl }
         \seq_gpush:NV \g_@@_stack_seq \l_@@_internal_tl
         \exp_args:NV \@@_gset:n \l_@@_internal_tl
         \@@_select:N #1
@@ -541,21 +542,22 @@
       {
         \seq_gpush:NV \g_@@_unused_seq \l_@@_internal_tl
         \@@_select:N \l_@@_internal_tl
-        \@@_chk_group_end:
+        \exp_args:Nx \@@_chk_group_end:n
+          { \@@_nesting_number:N \l_@@_internal_tl }
       }
       { \__kernel_msg_error:nn { kernel } { cctab-extra-end } }
   }
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\@@_chk_group_begin:,\@@_chk_group_end:}
+% \begin{macro}{\@@_chk_group_begin:n,\@@_chk_group_end:n}
 %   Catcode tables are not allowed to be intermixed with groups, so here
 %   we check that they are properly nested regarding \TeX{} groups.
-%   \cs{@@_chk_group_begin:} stores the current group level in a stack,
+%   \cs{@@_chk_group_begin:n} stores the current group level in a stack,
 %   and locally defines a dummy control sequence
 %   \cs[no-index]{@@_group_\meta{group-level}_chk:}.
 %
-%   \cs{@@_chk_group_end:} pops the stack, and compares the returned
+%   \cs{@@_chk_group_end:n} pops the stack, and compares the returned
 %   value with \cs{tex_currentgrouplevel:D}.  If they differ,
 %   \cs{cctab_end:} is in a different grouping level than the matching
 %   \cs{cctab_begin:N}.  If they are the same, both happened at the same
@@ -568,21 +570,21 @@
 %   attempted:  usually interleaving groups and catcode tables will work
 %   as expected.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_chk_group_begin:
+\cs_new_protected:Npn \@@_chk_group_begin:n #1
   {
     \seq_gpush:Nx \g_@@_group_seq
       { \int_use:N \tex_currentgrouplevel:D }
     \cs_set_eq:cN
-      { @@_group_ \int_use:N \tex_currentgrouplevel:D _chk: }
+      { @@_group_ \int_use:N \tex_currentgrouplevel:D _ #1 _chk: }
       \prg_do_nothing:
   }
-\cs_new_protected:Npn \@@_chk_group_end:
+\cs_new_protected:Npn \@@_chk_group_end:n #1
   {
     \seq_gpop:NN \g_@@_group_seq \l_@@_internal_tl
     \int_compare:nNnTF
         { \tex_currentgrouplevel:D } = { \l_@@_internal_tl }
       {
-        \cs_if_exist:cF { @@_group_ \l_@@_internal_tl _chk: }
+        \cs_if_exist:cF { @@_group_ \l_@@_internal_tl _ #1 _chk: }
           {
             \__kernel_msg_error:nnx { kernel } { cctab-group-mismatch }
               { different~group }
@@ -597,6 +599,20 @@
           }
       }
   }
+\sys_if_engine_luatex:TF
+  { \cs_new:Npn \@@_nesting_number:N #1 {#1} }
+  {
+    \cs_new:Npn \@@_nesting_number:N #1
+      {
+        \exp_after:wN \exp_after:wN \exp_after:wN \@@_nesting_number:w
+          \exp_after:wN \token_to_str:N #1
+      }
+    \use:x
+      {
+        \cs_new:Npn \exp_not:N \@@_nesting_number:w
+          ##1 \tl_to_str:n { g_@@_ } ##2 \tl_to_str:n { _cctab } {##2}
+      }
+  }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3kernel/testfiles/m3cctab003.lvt b/l3kernel/testfiles/m3cctab003.lvt
index c30a89b43..1c412ac12 100644
--- a/l3kernel/testfiles/m3cctab003.lvt
+++ b/l3kernel/testfiles/m3cctab003.lvt
@@ -75,6 +75,26 @@
     \cctab_end:
   }
 
+\TEST { Checking~that~a~cctab~doesn't~fool~another }
+  {
+    % This test shows that it is required to store not
+    % only the group level, but the cctab level:
+    \group_begin:
+      \cctab_begin:N \c_code_cctab % This cctab starts at GL = 1,
+        % and creates a \@@_group_1_chk:
+    \group_end:
+    \group_begin:
+      \cctab_begin:N \c_code_cctab % So does this one, which would
+        % create the same \@@_group_1_chk:
+      \cctab_end:
+      \cctab_end: % then this end is in the correct group level and
+        % would see \@@_group_1_chk: and not raise an error.
+    \group_end:
+    % Indexing the sentinel macro with the cctab index solves
+    % the issue, as the first one would be \@@_group_1_1_chk:,
+    % and the second one, \@@_group_1_2_chk:.
+  }
+
 \ExplSyntaxOff
 
 \END
diff --git a/l3kernel/testfiles/m3cctab003.tlg b/l3kernel/testfiles/m3cctab003.tlg
index a08e45206..f9235d110 100644
--- a/l3kernel/testfiles/m3cctab003.tlg
+++ b/l3kernel/testfiles/m3cctab003.tlg
@@ -55,3 +55,14 @@ l. ...  }
 Catcode tables and groups must be properly nested, but you tried to interleave
 them. LaTeX will try to proceed, but results may be unexpected.
 ============================================================
+============================================================
+TEST 4: Checking that a cctab doesn't fool another
+============================================================
+! LaTeX3 Error: \cctab_end: occurred in a different group than the matching
+(LaTeX3)        \cctab_begin:N.
+For immediate help type H <return>.
+ ...                                              
+l. ...  }
+Catcode tables and groups must be properly nested, but you tried to interleave
+them. LaTeX will try to proceed, but results may be unexpected.
+============================================================





More information about the latex3-commits mailing list.