[latex3-commits] [git/LaTeX3-latex3-latex3] master: Avoid wasting input stack when sorting, improve an error message (7f652a3)

Bruno Le Floch bruno at le-floch.fr
Sun Dec 30 02:24:34 CET 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/7f652a320115eb825a58602530453e2b97a3c93f

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

commit 7f652a320115eb825a58602530453e2b97a3c93f
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sun Dec 30 02:24:34 2018 +0100

    Avoid wasting input stack when sorting, improve an error message


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

7f652a320115eb825a58602530453e2b97a3c93f
 l3kernel/l3sort.dtx                     |   64 ++++++++++++++++++++-----------
 l3kernel/testfiles/m3sort001.luatex.tlg |   18 +++++----
 l3kernel/testfiles/m3sort001.tlg        |   18 +++++----
 3 files changed, 61 insertions(+), 39 deletions(-)

diff --git a/l3kernel/l3sort.dtx b/l3kernel/l3sort.dtx
index b7ff0d0..7d04157 100644
--- a/l3kernel/l3sort.dtx
+++ b/l3kernel/l3sort.dtx
@@ -551,49 +551,67 @@
       { \tex_the:D \tex_toks:D \exp_after:wN \l_@@_A_int \exp_after:wN }
       \exp_after:wN { \tex_the:D \tex_toks:D \l_@@_C_int }
     \prg_do_nothing:
-    \@@_return_mark:N
-    \@@_return_mark:N
+    \@@_return_mark:w
+    \@@_return_mark:w
+    \q_mark
     \@@_return_none_error:
   }
 %    \end{macrocode}
 % \end{macro}
 %
 % \begin{macro}{\sort_return_same:, \sort_return_swapped:}
-% \begin{macro}{\@@_return_mark:N}
-% \begin{macro}{\@@_return_none_error:, \@@_return_two_error:w}
-%   The marker removes one token.  Each comparison should call
-%   \cs{sort_return_same:} or \cs{sort_return_swapped:} exactly
-%   once.  If neither is called, \cs{@@_return_none_error:} is called.
+% \begin{macro}{\@@_return_mark:w}
+% \begin{macro}{\@@_return_none_error:, \@@_return_two_error:}
+%   Each comparison should call \cs{sort_return_same:} or
+%   \cs{sort_return_swapped:} exactly once.  If neither is called,
+%   \cs{@@_return_none_error:} is called, since the \texttt{return_mark}
+%   removes tokens until \cs{q_mark}.  If one is called, the
+%   \texttt{return_mark} auxiliary removes everything except
+%   \cs{@@_return_same:w} (or its \texttt{swapped} analogue) followed by
+%   \cs{@@_return_none_error:}.  Finally if two or more are called,
+%   \cs{@@_return_two_error:} ends up before any \cs{@@_return_mark:w},
+%   so that it produces an error.
 %    \begin{macrocode}
-\cs_new_protected:Npn \sort_return_same: #1 \@@_return_mark:N
+\cs_new_protected:Npn \sort_return_same:
+    #1 \@@_return_mark:w #2 \q_mark
   {
     #1
-    \@@_return_mark:N
-    \@@_return_two_error:w \@@_return_same:
+    #2
+    \@@_return_two_error:
+    \@@_return_mark:w
+    \q_mark
+    \@@_return_same:w
   }
-\cs_new_protected:Npn \sort_return_swapped: #1 \@@_return_mark:N
+\cs_new_protected:Npn \sort_return_swapped:
+    #1 \@@_return_mark:w #2 \q_mark
   {
     #1
-    \@@_return_mark:N
-    \@@_return_two_error:w \@@_return_swapped:
+    #2
+    \@@_return_two_error:
+    \@@_return_mark:w
+    \q_mark
+    \@@_return_swapped:w
   }
-\cs_new_protected:Npn \@@_return_mark:N #1 { }
+\cs_new_protected:Npn \@@_return_mark:w #1 \q_mark { }
 \cs_new_protected:Npn \@@_return_none_error:
   {
     \__kernel_msg_error:nnxx { kernel } { return-none }
       { \tex_the:D \tex_toks:D \l_@@_A_int }
       { \tex_the:D \tex_toks:D \l_@@_C_int }
-    \@@_return_same:
+    \@@_return_same:w \@@_return_none_error:
+  }
+\cs_new_protected:Npn \@@_return_two_error:
+  {
+    \__kernel_msg_error:nnxx { kernel } { return-two }
+      { \tex_the:D \tex_toks:D \l_@@_A_int }
+      { \tex_the:D \tex_toks:D \l_@@_C_int }
   }
-\cs_new_protected:Npn \@@_return_two_error:w
-    #1 \@@_return_none_error:
-  { \__kernel_msg_error:nn { kernel } { return-two } }
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
 % \end{macro}
 %
-% \begin{macro}{\@@_return_same:}
+% \begin{macro}{\@@_return_same:w}
 %   If the comparison function returns \texttt{same},
 %   then the second argument fed to \cs{@@_compare:nn}
 %   should remain to the right of the other one. Since
@@ -605,7 +623,7 @@
 %   is already in the correct registers and we are done
 %   with merging those two blocks.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_return_same:
+\cs_new_protected:Npn \@@_return_same:w #1 \@@_return_none_error:
   {
     \tex_toks:D \l_@@_B_int \tex_toks:D \l_@@_C_int
     \int_decr:N \l_@@_B_int
@@ -618,7 +636,7 @@
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\@@_return_swapped:}
+% \begin{macro}{\@@_return_swapped:w}
 %   If the comparison function returns \texttt{swapped},
 %   then the next item to add to the merger is the first
 %   argument, contents of the \tn{toks} register $A$.
@@ -629,7 +647,7 @@
 %   the second block, indexed by $C$, are copied
 %   to the merger by \cs{@@_merge_blocks_end:}.
 %    \begin{macrocode}
-\cs_new_protected:Npn \@@_return_swapped:
+\cs_new_protected:Npn \@@_return_swapped:w #1 \@@_return_none_error:
   {
     \tex_toks:D \l_@@_B_int \tex_toks:D \l_@@_A_int
     \int_decr:N \l_@@_B_int
@@ -1067,7 +1085,7 @@
 \__kernel_msg_new:nnnn { kernel } { return-two }
   { The~comparison~code~returned~multiple~times. }
   {
-    When~sorting~a~list,~the~code~to~compare~items~called~
+    When~sorting~a~list,~the~code~to~compare~items~#1~and~#2~called~
     \iow_char:N\\sort_return_same: ~or~
     \iow_char:N\\sort_return_swapped: ~multiple~times.~
     Exactly~one~of~these~should~be~called.
diff --git a/l3kernel/testfiles/m3sort001.luatex.tlg b/l3kernel/testfiles/m3sort001.luatex.tlg
index a20f209..9ec41ec 100644
--- a/l3kernel/testfiles/m3sort001.luatex.tlg
+++ b/l3kernel/testfiles/m3sort001.luatex.tlg
@@ -68,8 +68,16 @@ dcba
 For immediate help type H <return>.
  ...                                              
 l. ...  }
-When sorting a list, the code to compare items called \sort_return_same: or
-\sort_return_swapped: multiple times. Exactly one of these should be called.
+When sorting a list, the code to compare items d and c called
+\sort_return_same: or \sort_return_swapped: multiple times. Exactly one of
+these should be called.
+! LaTeX3 Error: The comparison code returned multiple times.
+For immediate help type H <return>.
+ ...                                              
+l. ...  }
+When sorting a list, the code to compare items d and b called
+\sort_return_same: or \sort_return_swapped: multiple times. Exactly one of
+these should be called.
 ! LaTeX3 Error: The comparison code did not return.
 For immediate help type H <return>.
  ...                                              
@@ -84,11 +92,5 @@ l. ...  }
 When sorting a list, the code to compare items c and a did not call
 \sort_return_same: nor \sort_return_swapped:. Exactly one of these should be
 called.
-! LaTeX3 Error: The comparison code returned multiple times.
-For immediate help type H <return>.
- ...                                              
-l. ...  }
-When sorting a list, the code to compare items called \sort_return_same: or
-\sort_return_swapped: multiple times. Exactly one of these should be called.
 {c}{a}{b}{d}
 ============================================================
diff --git a/l3kernel/testfiles/m3sort001.tlg b/l3kernel/testfiles/m3sort001.tlg
index 026bc7e..0685164 100644
--- a/l3kernel/testfiles/m3sort001.tlg
+++ b/l3kernel/testfiles/m3sort001.tlg
@@ -68,8 +68,16 @@ dcba
 For immediate help type H <return>.
  ...                                              
 l. ...  }
-When sorting a list, the code to compare items called \sort_return_same: or
-\sort_return_swapped: multiple times. Exactly one of these should be called.
+When sorting a list, the code to compare items d and c called
+\sort_return_same: or \sort_return_swapped: multiple times. Exactly one of
+these should be called.
+! LaTeX3 Error: The comparison code returned multiple times.
+For immediate help type H <return>.
+ ...                                              
+l. ...  }
+When sorting a list, the code to compare items d and b called
+\sort_return_same: or \sort_return_swapped: multiple times. Exactly one of
+these should be called.
 ! LaTeX3 Error: The comparison code did not return.
 For immediate help type H <return>.
  ...                                              
@@ -84,11 +92,5 @@ l. ...  }
 When sorting a list, the code to compare items c and a did not call
 \sort_return_same: nor \sort_return_swapped:. Exactly one of these should be
 called.
-! LaTeX3 Error: The comparison code returned multiple times.
-For immediate help type H <return>.
- ...                                              
-l. ...  }
-When sorting a list, the code to compare items called \sort_return_same: or
-\sort_return_swapped: multiple times. Exactly one of these should be called.
 {c}{a}{b}{d}
 ============================================================





More information about the latex3-commits mailing list