[latex3-commits] [latex3/latex3] main: In tl-analysis, undefine active characters only when needed (see #1243) (d59dc3d0f)

github at latex-project.org github at latex-project.org
Wed Oct 11 10:31:30 CEST 2023


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/d59dc3d0f55d7bb2c717a3551ba2d432c6cefd88

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

commit d59dc3d0f55d7bb2c717a3551ba2d432c6cefd88
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Wed Oct 11 10:31:30 2023 +0200

    In tl-analysis, undefine active characters only when needed (see #1243)


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

d59dc3d0f55d7bb2c717a3551ba2d432c6cefd88
 l3kernel/l3tl-analysis.dtx                     | 38 +++++++++++++++++++++++++-
 l3kernel/testfiles/m3tl-analysis001.luatex.tlg |  9 ++++++
 l3kernel/testfiles/m3tl-analysis001.lvt        | 15 ++++++++++
 l3kernel/testfiles/m3tl-analysis001.tlg        |  9 ++++++
 l3kernel/testfiles/m3tl-analysis001.xetex.tlg  |  9 ++++++
 5 files changed, 79 insertions(+), 1 deletion(-)

diff --git a/l3kernel/l3tl-analysis.dtx b/l3kernel/l3tl-analysis.dtx
index 9cadf04e8..b7ec5caba 100644
--- a/l3kernel/l3tl-analysis.dtx
+++ b/l3kernel/l3tl-analysis.dtx
@@ -443,6 +443,42 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\@@_analysis_disable_char:N}
+%   Similar to \cs{@@_analysis_disable:n}, but it receives a normal
+%   character token, tests if that token is active (by turning it into
+%   a space: the active space has been undefined at this point), and
+%   if so, disables it.  Even if the character is active and set equal
+%   to a primitive conditional, nothing blows up.
+%   Again, in \pTeX{} and \upTeX{} we skip characters beyond $[0,255]$,
+%   which cannot be active anyways.
+%    \begin{macrocode}
+\group_begin:
+  \char_set_catcode_active:N \^^@
+  \cs_new_protected:Npn \@@_analysis_disable_char:N #1
+    {
+      \tex_lccode:D `#1 = 32 \exp_stop_f:
+      \tex_lowercase:D { \if_meaning:w #1 } \tex_undefined:D
+        \tex_let:D #1 \tex_undefined:D
+      \fi:
+    }
+  \bool_lazy_or:nnT
+    { \sys_if_engine_ptex_p: }
+    { \sys_if_engine_uptex_p: }
+    {
+      \cs_gset_protected:Npn \@@_analysis_disable_char:N #1
+        {
+          \if_int_compare:w 256 > `#1 \exp_stop_f:
+            \tex_lccode:D `#1 = 32 \exp_stop_f:
+            \tex_lowercase:D { \if_meaning:w #1 } \tex_undefined:D
+              \tex_let:D #1 \tex_undefined:D
+            \fi:
+          \fi:
+        }
+    }
+\group_end:
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsection{First pass}
 %
 % The goal of this pass is to detect special (non-\texttt{N}-type) tokens,
@@ -737,7 +773,7 @@
       \exp_after:wN \use_ii:nn
     \fi:
       {
-        \@@_analysis_disable:n { `#1 }
+        \@@_analysis_disable_char:N #1
         \int_incr:N \l_@@_analysis_normal_int
       }
       { \@@_analysis_cs_space_count:NN \@@_analysis_a_cs:ww #1 }
diff --git a/l3kernel/testfiles/m3tl-analysis001.luatex.tlg b/l3kernel/testfiles/m3tl-analysis001.luatex.tlg
index faa4b149a..cccd81e9a 100644
--- a/l3kernel/testfiles/m3tl-analysis001.luatex.tlg
+++ b/l3kernel/testfiles/m3tl-analysis001.luatex.tlg
@@ -103,3 +103,12 @@ The token list contains the tokens:
 <recently read> }
 l. ...  }
 ============================================================
+============================================================
+TEST 5: Active primitive conditionals
+============================================================
+The token list contains the tokens:
+>  ( (active character=\if)
+>  ) (active character=\fi).
+<recently read> }
+l. ...  }
+============================================================
diff --git a/l3kernel/testfiles/m3tl-analysis001.lvt b/l3kernel/testfiles/m3tl-analysis001.lvt
index c154a7168..fc2a234a9 100644
--- a/l3kernel/testfiles/m3tl-analysis001.lvt
+++ b/l3kernel/testfiles/m3tl-analysis001.lvt
@@ -98,4 +98,19 @@
       }
   }
 
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\OMIT
+\char_set_active_eq:NN ( \if:w
+\char_set_active_eq:NN ) \fi:
+\char_set_catcode_active:N \(
+\char_set_catcode_active:N \)
+\TIMO
+
+\TEST { Active~primitive~conditionals }
+  {
+    \tl_analysis_show:n { ( ) }
+  }
+
+
 \END
diff --git a/l3kernel/testfiles/m3tl-analysis001.tlg b/l3kernel/testfiles/m3tl-analysis001.tlg
index 0447d3cc3..b670f8493 100644
--- a/l3kernel/testfiles/m3tl-analysis001.tlg
+++ b/l3kernel/testfiles/m3tl-analysis001.tlg
@@ -103,3 +103,12 @@ The token list contains the tokens:
 <recently read> }
 l. ...  }
 ============================================================
+============================================================
+TEST 5: Active primitive conditionals
+============================================================
+The token list contains the tokens:
+>  ( (active character=\if)
+>  ) (active character=\fi).
+<recently read> }
+l. ...  }
+============================================================
diff --git a/l3kernel/testfiles/m3tl-analysis001.xetex.tlg b/l3kernel/testfiles/m3tl-analysis001.xetex.tlg
index faa4b149a..cccd81e9a 100644
--- a/l3kernel/testfiles/m3tl-analysis001.xetex.tlg
+++ b/l3kernel/testfiles/m3tl-analysis001.xetex.tlg
@@ -103,3 +103,12 @@ The token list contains the tokens:
 <recently read> }
 l. ...  }
 ============================================================
+============================================================
+TEST 5: Active primitive conditionals
+============================================================
+The token list contains the tokens:
+>  ( (active character=\if)
+>  ) (active character=\fi).
+<recently read> }
+l. ...  }
+============================================================





More information about the latex3-commits mailing list.