[latex3-commits] [git/LaTeX3-latex3-latex3] master: Use some expandable errors in l3regex rather than ugly brace tricks (589ed44)

Bruno Le Floch bruno at le-floch.fr
Sun Apr 1 22:22:20 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/589ed44aaff5a727d8229ec6e5f9642a2c533af9

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

commit 589ed44aaff5a727d8229ec6e5f9642a2c533af9
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sun Apr 1 16:22:20 2018 -0400

    Use some expandable errors in l3regex rather than ugly brace tricks


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

589ed44aaff5a727d8229ec6e5f9642a2c533af9
 l3kernel/l3regex.dtx              |   78 ++++++++++++----------------------
 l3kernel/testfiles/m3regex009.tlg |   85 ++++++++++++++-----------------------
 2 files changed, 60 insertions(+), 103 deletions(-)

diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index 3a8c92c..0f9beff 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -1460,24 +1460,20 @@
 % character, then fed to \meta{inline~3}. The result is then left in the
 % input stream. Spaces are ignored unless escaped.
 %
-% The conversion is mostly done within an \texttt{x}-expanding
-% assignment, except for the |\x| escape sequence, which is not amenable
-% to that in general. For this, we use the general framework of |tl_build|.
+% The conversion is done within an \texttt{x}-expanding assignment.
 %
 % \begin{macro}{\@@_escape_use:nnnn}
-%   The result is built in \cs{l_@@_internal_a_tl}, which is then
-%   left in the input stream.  Go through |#4| once, applying |#1|,
+%   The result is built in \cs{l_@@_internal_a_tl}, which is then left
+%   in the input stream.  Tracing code is added as appropriate inside
+%   this token list.  Go through |#4| once, applying |#1|,
 %   |#2|, or |#3| as relevant to each character (after de-escaping
-%   it). Note that we cannot replace \cs{tl_set:Nx} and
-%   \cs{tl_build_put_right:Nx} by a single call to \cs{tl_build_put_right:Nx}, because
-%   the \texttt{x}-expanding assignment may be interrupted by |\x|.
+%   it).
 %    \begin{macrocode}
 \__kernel_patch:nnNNpn
   {
     \@@_trace_push:nnN { regex } { 1 } \@@_escape_use:nnnn
     \group_begin:
-      \tl_build_begin:N \l_@@_build_tl
-      \tl_build_put_right:Nn \l_@@_build_tl
+      \tl_set:Nx \l_@@_internal_a_tl
         { \@@_trace_pop:nnN { regex } { 1 } \@@_escape_use:nnnn }
       \use_none:nnn
   }
@@ -1485,23 +1481,20 @@
 \cs_new_protected:Npn \@@_escape_use:nnnn #1#2#3#4
   {
     \group_begin:
-      \tl_build_begin:N \l_@@_build_tl
+      \tl_clear:N \l_@@_internal_a_tl
       \cs_set:Npn \@@_escape_unescaped:N ##1 { #1 }
       \cs_set:Npn \@@_escape_escaped:N ##1 { #2 }
       \cs_set:Npn \@@_escape_raw:N ##1 { #3 }
       \@@_standard_escapechar:
       \tl_gset:Nx \g_@@_internal_tl { \__str_to_other_fast:n {#4} }
-      \tl_set:Nx \l_@@_internal_b_tl
+      \tl_put_right:Nx \l_@@_internal_a_tl
         {
           \exp_after:wN \@@_escape_loop:N \g_@@_internal_tl
           { break } \prg_break_point:
         }
-      \tl_build_put_right:Nx \l_@@_build_tl
-        { \exp_not:o \l_@@_internal_b_tl }
-      \tl_build_end:N \l_@@_build_tl
       \exp_after:wN
     \group_end:
-    \l_@@_build_tl
+    \l_@@_internal_a_tl
   }
 %    \end{macrocode}
 % \end{macro}
@@ -1556,9 +1549,8 @@
 \cs_new_eq:NN \@@_escape_break:w \prg_break:
 \cs_new:cpn { @@_escape_/break:w }
   {
-    \if_false: { \fi: }
-    \__kernel_msg_error:nn { kernel } { trailing-backslash }
-    \exp_after:wN \use_none:n \exp_after:wN { \if_false: } \fi:
+    \__kernel_msg_expandable_error:nn { kernel } { trailing-backslash }
+    \prg_break:
   }
 \cs_new:cpn { @@_escape_~:w } { }
 \cs_new:cpx { @@_escape_/a:w }
@@ -1594,12 +1586,8 @@
   {
     \int_compare:nNnTF {#1} > \c_max_char_int
       {
-        \if_false: { \fi: }
-        \tl_build_put_right:Nx \l_@@_build_tl
-          { \exp_not:o \l_@@_internal_b_tl }
-        \__kernel_msg_error:nnx { kernel } { x-overflow } {#1}
-        \tl_set:Nx \l_@@_internal_b_tl
-          { \if_false: } \fi:
+        \__kernel_msg_expandable_error:nnff { kernel } { x-overflow }
+          {#1} { \int_to_Hex:n {#1} }
       }
       {
         \exp_last_unbraced:Nf \@@_escape_raw:N
@@ -1684,12 +1672,8 @@
   }
 \cs_new:Npn \@@_escape_x_loop_error:n #1
   {
-    \if_false: { \fi: }
-    \tl_build_put_right:Nx \l_@@_build_tl
-      { \exp_not:o \l_@@_internal_b_tl }
-    \__kernel_msg_error:nnx { kernel } { x-missing-rbrace } {#1}
-    \tl_set:Nx \l_@@_internal_b_tl
-      { \if_false: } \fi: \@@_escape_loop:N #1
+    \__kernel_msg_expandable_error:nnn { kernel } { x-missing-rbrace } {#1}
+    \@@_escape_loop:N #1
   }
 %    \end{macrocode}
 % \end{macro}
@@ -6223,26 +6207,20 @@
 %
 % Messages for the preparsing phase.
 %    \begin{macrocode}
-\__kernel_msg_new:nnnn { kernel } { trailing-backslash }
-  { Trailing~escape~character~'\iow_char:N\\'. }
+\use:x
   {
-    A~regular~expression~or~its~replacement~text~ends~with~
-    the~escape~character~'\iow_char:N\\'.~It~will~be~ignored.
-  }
-\__kernel_msg_new:nnnn { kernel } { x-missing-rbrace }
-  { Missing~closing~brace~in~'\iow_char:N\\x'~hexadecimal~sequence. }
-  {
-    You~wrote~something~like~
-    '\iow_char:N\\x\{...#1'.~
-    The~closing~brace~is~missing.
-  }
-\__kernel_msg_new:nnnn { kernel } { x-overflow }
-  { Character~code~'#1'~too~large~in~'\iow_char:N\\x'~hexadecimal~sequence. }
-  {
-    You~wrote~something~like~
-    '\iow_char:N\\x\{\int_to_Hex:n{#1}\}'.~
-    The~character~code~#1~is~larger~than~
-    the~maximum~value~\int_use:N \c_max_char_int.
+    \__kernel_msg_new:nnn { kernel } { trailing-backslash }
+      { Trailing~escape~char~'\iow_char:N\\'~in~regex~or~replacement. }
+    \__kernel_msg_new:nnn { kernel } { x-missing-rbrace }
+      {
+        Missing~brace~'\iow_char:N\}'~in~regex~
+        '...\iow_char:N\\x\iow_char:N\{...##1'.
+      }
+    \__kernel_msg_new:nnn { kernel } { x-overflow }
+      {
+        Character~code~##1~too~large~in~
+        \iow_char:N\\x\iow_char:N\{##2\iow_char:N\}~regex.
+      }
   }
 %    \end{macrocode}
 %
diff --git a/l3kernel/testfiles/m3regex009.tlg b/l3kernel/testfiles/m3regex009.tlg
index 869af33..7c0d49b 100644
--- a/l3kernel/testfiles/m3regex009.tlg
+++ b/l3kernel/testfiles/m3regex009.tlg
@@ -5,21 +5,15 @@ Author: Bruno Le Floch
 TEST 1: Malformed letter escapes
 ============================================================
 "\"
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!
-! LaTeX error: "kernel/trailing-backslash"
-! 
-! Trailing escape character '\'.
-! 
-! See the LaTeX3 documentation for further information.
-! 
-! For immediate help type H <return>.
-!...............................................  
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Trailing escape char '\' in regex or replacement.
 l. ...  }
-|'''''''''''''''''''''''''''''''''''''''''''''''
-| A regular expression or its replacement text ends with the escape character
-| '\'. It will be ignored.
-|...............................................
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
 "\g"
 "\i"
 "\j"
@@ -51,51 +45,36 @@ TEST 2: Malformed x escapes
 ============================================================
 "\x"
 "\x{"
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!
-! LaTeX error: "kernel/x-missing-rbrace"
-! 
-! Missing closing brace in '\x' hexadecimal sequence.
-! 
-! See the LaTeX3 documentation for further information.
-! 
-! For immediate help type H <return>.
-!...............................................  
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Missing brace '}' in regex '...\x{...'.
 l. ...  }
-|'''''''''''''''''''''''''''''''''''''''''''''''
-| You wrote something like '\x{...'. The closing brace is missing.
-|...............................................
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
 "\x{}"
 "\x{45"
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!
-! LaTeX error: "kernel/x-missing-rbrace"
-! 
-! Missing closing brace in '\x' hexadecimal sequence.
-! 
-! See the LaTeX3 documentation for further information.
-! 
-! For immediate help type H <return>.
-!...............................................  
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Missing brace '}' in regex '...\x{...'.
 l. ...  }
-|'''''''''''''''''''''''''''''''''''''''''''''''
-| You wrote something like '\x{...'. The closing brace is missing.
-|...............................................
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
 "\x{34k}"
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!
-! LaTeX error: "kernel/x-missing-rbrace"
-! 
-! Missing closing brace in '\x' hexadecimal sequence.
-! 
-! See the LaTeX3 documentation for further information.
-! 
-! For immediate help type H <return>.
-!...............................................  
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           Missing brace '}' in regex '...\x{...k'.
 l. ...  }
-|'''''''''''''''''''''''''''''''''''''''''''''''
-| You wrote something like '\x{...k'. The closing brace is missing.
-|...............................................
+The control sequence at the end of the top line
+of your error message was never \def'ed. If you have
+misspelled it (e.g., `\hobx'), type `I' and the correct
+spelling (e.g., `I\hbox'). Otherwise just continue,
+and I'll forget about whatever was undefined.
 ============================================================
 ============================================================
 TEST 3: Malformed classes





More information about the latex3-commits mailing list