[latex3-commits] [l3svn] r6798 - Force comparison code to call \sort_return_... exactly once

noreply at latex-project.org noreply at latex-project.org
Thu Dec 15 07:56:09 CET 2016


Author: bruno
Date: 2016-12-15 07:56:09 +0100 (Thu, 15 Dec 2016)
New Revision: 6798

Modified:
   trunk/l3experimental/l3sort/l3sort.dtx
   trunk/l3experimental/l3sort/testfiles/m3sort001.luatex.tlg
   trunk/l3experimental/l3sort/testfiles/m3sort001.lvt
   trunk/l3experimental/l3sort/testfiles/m3sort001.tlg
Log:
Force comparison code to call \sort_return_... exactly once


Modified: trunk/l3experimental/l3sort/l3sort.dtx
===================================================================
--- trunk/l3experimental/l3sort/l3sort.dtx	2016-12-15 06:25:57 UTC (rev 6797)
+++ trunk/l3experimental/l3sort/l3sort.dtx	2016-12-15 06:56:09 UTC (rev 6798)
@@ -640,11 +640,43 @@
     \exp_after:wN \@@_compare:nn \exp_after:wN
       { \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_none_error:
   }
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}[aux]{\sort_return_unchanged:}
+%
+% \begin{macro}{\sort_return_unchanged:, \sort_return_reversed:}
+% \begin{macro}[aux]{\@@_return_mark:N}
+% \begin{macro}[aux]{\@@_return_none_error:, \@@_return_two_error:w}
+%   The marker removes one token.  Each comparison should call
+%   \cs{sort_return_unchanged:} or \cs{sort_return_reversed:} exactly
+%   once.  If neither is called, \cs{@@_return_none_error:} is called.
+%    \begin{macrocode}
+\cs_new_protected:Npn \sort_return_unchanged: #1 \@@_return_mark:N
+  { #1 \@@_return_mark:N \@@_return_two_error:w \@@_return_unchanged: }
+\cs_new_protected:Npn \sort_return_reversed: #1 \@@_return_mark:N
+  { #1 \@@_return_mark:N \@@_return_two_error:w \@@_return_reversed: }
+\cs_new_protected:Npn \@@_return_mark:N #1 { }
+\cs_new_protected:Npn \@@_return_none_error:
+  {
+    \__msg_kernel_error:nnxx { sort } { return-none }
+      { \tex_the:D \tex_toks:D \l_@@_A_int }
+      { \tex_the:D \tex_toks:D \l_@@_C_int }
+    \@@_return_unchanged:
+  }
+\cs_new_protected:Npn \@@_return_two_error:w
+    #1 \@@_return_none_error:
+  { \__msg_kernel_error:nn { sort } { return-two } }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
+% \begin{macro}[aux]{\@@_return_unchanged:}
 %   If the comparison function returns \texttt{ordered},
 %   then the second argument fed to \cs{@@_compare:nn}
 %   should remain to the right of the other one. Since
@@ -656,7 +688,7 @@
 %   is already in the correct registers and we are done
 %   with merging those two blocks.
 %    \begin{macrocode}
-\cs_new_protected:Npn \sort_return_unchanged:
+\cs_new_protected:Npn \@@_return_unchanged:
   {
     \tex_toks:D \l_@@_B_int \tex_toks:D \l_@@_C_int
     \tex_advance:D \l_@@_B_int - \c_one
@@ -668,8 +700,9 @@
   }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
 %
-% \begin{macro}[aux]{\sort_return_reversed:}
+% \begin{macro}[aux]{\@@_return_reversed:}
 %   If the comparison function returns \texttt{reversed},
 %   then the next item to add to the merger is the first
 %   argument, contents of the \tn{toks} register $A$.
@@ -680,7 +713,7 @@
 %   the second block, indexed by $C$, are copied
 %   to the merger by \cs{@@_merge_blocks_end:}.
 %    \begin{macrocode}
-\cs_new_protected:Npn \sort_return_reversed:
+\cs_new_protected:Npn \@@_return_reversed:
   {
     \tex_toks:D \l_@@_B_int \tex_toks:D \l_@@_A_int
     \tex_advance:D \l_@@_B_int - \c_one
@@ -1099,6 +1132,26 @@
 %    \end{macrocode}
 % \end{macro}
 %
+%    \begin{macrocode}
+\__msg_kernel_new:nnnn { sort } { return-none }
+  { The~comparison~code~did~not~return. }
+  {
+    When~sorting~a~list,~the~code~to~compare~items~#1~and~#2~
+    did~not~call~
+    \iow_char:N\\sort_return_unchanged: ~nor~
+    \iow_char:N\\sort_return_reversed: .~
+    Exactly~one~of~these~should~be~called.
+  }
+\__msg_kernel_new:nnnn { sort } { return-two }
+  { The~comparison~code~returned~multiple~times. }
+  {
+    When~sorting~a~list,~the~code~to~compare~items~called~
+    \iow_char:N\\sort_return_unchanged: ~or~
+    \iow_char:N\\sort_return_reversed: ~multiple~times.~
+    Exactly~one~of~these~should~be~called.
+  }
+%    \end{macrocode}
+%
 % \subsection{Deprecated}
 %
 % \begin{macro}[deprecated=2017-12-31]{\sort_ordered:, \sort_reversed:}

Modified: trunk/l3experimental/l3sort/testfiles/m3sort001.luatex.tlg
===================================================================
--- trunk/l3experimental/l3sort/testfiles/m3sort001.luatex.tlg	2016-12-15 06:25:57 UTC (rev 6797)
+++ trunk/l3experimental/l3sort/testfiles/m3sort001.luatex.tlg	2016-12-15 06:56:09 UTC (rev 6798)
@@ -77,7 +77,7 @@
 |...............................................
 ============================================================
 ============================================================
-TEST 5: sort newtoks error
+TEST 5: sort errors
 ============================================================
 dc
 ba
@@ -99,4 +99,70 @@
 | The list will not be sorted.
 |...............................................
 \l_test_toks=\toks303
+dcba
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "sort/return-two"
+! 
+! The comparison code returned multiple times.
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| When sorting a list, the code to compare items called
+| \sort_return_unchanged: or \sort_return_reversed: multiple times. Exactly
+| one of these should be called.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "sort/return-none"
+! 
+! The comparison code did not return.
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| When sorting a list, the code to compare items c and b did not call
+| \sort_return_unchanged: nor \sort_return_reversed:. Exactly one of these
+| should be called.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "sort/return-none"
+! 
+! The comparison code did not return.
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| When sorting a list, the code to compare items c and a did not call
+| \sort_return_unchanged: nor \sort_return_reversed:. Exactly one of these
+| should be called.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "sort/return-two"
+! 
+! The comparison code returned multiple times.
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| When sorting a list, the code to compare items called
+| \sort_return_unchanged: or \sort_return_reversed: multiple times. Exactly
+| one of these should be called.
+|...............................................
+{c}{a}{b}{d}
 ============================================================

Modified: trunk/l3experimental/l3sort/testfiles/m3sort001.lvt
===================================================================
--- trunk/l3experimental/l3sort/testfiles/m3sort001.lvt	2016-12-15 06:25:57 UTC (rev 6797)
+++ trunk/l3experimental/l3sort/testfiles/m3sort001.lvt	2016-12-15 06:56:09 UTC (rev 6798)
@@ -124,7 +124,7 @@
 
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\TEST { sort~newtoks~error }
+\TEST { sort~errors }
   {
     \tl_set:Nn \l_tmpa_tl { dcba }
     \tl_sort:Nn \l_tmpa_tl
@@ -134,6 +134,16 @@
           { \use:c { newtoks } \l_test_toks }
         \sort_return_unchanged:
       }
+    \TYPE { \l_tmpa_tl }
+    \tl_sort:Nn \l_tmpa_tl
+      {
+        \str_case:nn {#1}
+          {
+            { b }  { \sort_return_reversed: }
+            { d }  { \sort_return_reversed: \sort_return_reversed: }
+          }
+      }
+    \TYPE { \l_tmpa_tl }
   }
 
 

Modified: trunk/l3experimental/l3sort/testfiles/m3sort001.tlg
===================================================================
--- trunk/l3experimental/l3sort/testfiles/m3sort001.tlg	2016-12-15 06:25:57 UTC (rev 6797)
+++ trunk/l3experimental/l3sort/testfiles/m3sort001.tlg	2016-12-15 06:56:09 UTC (rev 6798)
@@ -77,7 +77,7 @@
 |...............................................
 ============================================================
 ============================================================
-TEST 5: sort newtoks error
+TEST 5: sort errors
 ============================================================
 dc
 ba
@@ -99,4 +99,70 @@
 | The list will not be sorted.
 |...............................................
 \l_test_toks=\toks303
+dcba
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "sort/return-two"
+! 
+! The comparison code returned multiple times.
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| When sorting a list, the code to compare items called
+| \sort_return_unchanged: or \sort_return_reversed: multiple times. Exactly
+| one of these should be called.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "sort/return-none"
+! 
+! The comparison code did not return.
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| When sorting a list, the code to compare items c and b did not call
+| \sort_return_unchanged: nor \sort_return_reversed:. Exactly one of these
+| should be called.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "sort/return-none"
+! 
+! The comparison code did not return.
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| When sorting a list, the code to compare items c and a did not call
+| \sort_return_unchanged: nor \sort_return_reversed:. Exactly one of these
+| should be called.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "sort/return-two"
+! 
+! The comparison code returned multiple times.
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| When sorting a list, the code to compare items called
+| \sort_return_unchanged: or \sort_return_reversed: multiple times. Exactly
+| one of these should be called.
+|...............................................
+{c}{a}{b}{d}
 ============================================================



More information about the latex3-commits mailing list