[latex3-commits] [l3svn] r6903 - Clean up experimental l3flag

noreply at latex-project.org noreply at latex-project.org
Sun Feb 12 17:59:39 CET 2017


Author: bruno
Date: 2017-02-12 17:59:39 +0100 (Sun, 12 Feb 2017)
New Revision: 6903

Modified:
   trunk/l3experimental/l3str/l3flag.dtx
   trunk/l3experimental/l3str/testfiles/m3flag001.lvt
   trunk/l3experimental/l3str/testfiles/m3flag001.tlg
   trunk/l3experimental/l3str/testfiles/m3str-convert004.tlg
Log:
Clean up experimental l3flag


Modified: trunk/l3experimental/l3str/l3flag.dtx
===================================================================
--- trunk/l3experimental/l3str/l3flag.dtx	2017-02-12 16:09:32 UTC (rev 6902)
+++ trunk/l3experimental/l3str/l3flag.dtx	2017-02-12 16:59:39 UTC (rev 6903)
@@ -1,6 +1,6 @@
 % \iffalse meta-comment
 %
-%% File: l3flag.dtx Copyright (C) 2011-2012,2014-2016 The LaTeX3 Project
+%% File: l3flag.dtx Copyright (C) 2011-2012,2014-2017 The LaTeX3 Project
 %
 % It may be distributed and/or modified under the conditions of the
 % LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -82,9 +82,10 @@
 % can also be queried expandably. However, decreasing it, or setting it
 % to zero requires non-expandable assignments.
 %
-% Flag variables are always local. They are referenced by a \meta{name}
-% of the form \meta{package}\texttt{_}\meta{flag name}, for instance,
-% \texttt{str_missing}.
+% Flag variables are always local. They are referenced by a \meta{flag
+% name} such as \texttt{str_missing}.  The \meta{flag name} is used as
+% part of \cs{use:c} constructions hence is expanded at point of use.
+% It must expand to character tokens only, with no spaces.
 %
 % \section{Setting up flags}
 %
@@ -92,11 +93,10 @@
 %   \begin{syntax}
 %     \cs{flag_new:n} \Arg{flag name}
 %   \end{syntax}
-%   Creates a new \meta{flag} with a name given by \meta{flag name}, or
-%   raises an error if the name is already taken. The \meta{flag name}
-%   must consist of character tokens only. The declaration is global,
-%   but flags are always local variables. The \meta{flag} will initially
-%   have zero height.
+%   Creates a new flag with a name given by \meta{flag name}, or raises
+%   an error if the name is already taken. The \meta{flag name} may not
+%   contain spaces. The declaration is global, but flags are always
+%   local variables. The \meta{flag} will initially have zero height.
 % \end{function}
 %
 % \begin{function}{\flag_clear:n}
@@ -115,6 +115,20 @@
 %   the height to zero locally.
 % \end{function}
 %
+% \begin{function}{\flag_show:n}
+%   \begin{syntax}
+%     \cs{flag_show:n} \Arg{flag name}
+%   \end{syntax}
+%   Displays the \meta{flag}'s height in the terminal.
+% \end{function}
+%
+% \begin{function}{\flag_log:n}
+%   \begin{syntax}
+%     \cs{flag_log:n} \Arg{flag name}
+%   \end{syntax}
+%   Writes the \meta{flag}'s height to the log file.
+% \end{function}
+%
 % \begin{function}{\flag_set_trap:nn}
 %   \begin{syntax}
 %     \cs{flag_set_trap:nn} \Arg{flag name} \Arg{inline function}
@@ -186,32 +200,41 @@
 %
 % \subsection{Non-expandable flag commands}
 %
+% The height $h$ of a flag (initially zero) is stored by setting control
+% sequences of the form \cs[no-index]{flag \meta{name} \meta{integer}}
+% to \tn{relax} for $0\leq\meta{integer}<h$.  When a flag is raised, a
+% \enquote{trap} function \cs[no-index]{flag \meta{name}} is called.
+% The existence of this function is also used to test for the existence
+% of a flag.
+%
 % \begin{macro}{\flag_new:n}
 %   For each flag, we define a \enquote{trap} function, which by default
-%   simply increases the flag by $1$.
+%   simply increases the flag by $1$ by letting the appropriate control
+%   sequence to \tn{relax}.  This can be done expandably!
 %   \begin{macrocode}
 \cs_new_protected:Npn \flag_new:n #1
   {
-    \cs_new:cpn { @@_trap_#1:w } ##1 ;
-      { \exp_after:wN \use_none:n \cs:w @@_#1_##1: \cs_end: }
+    \cs_new:cpn { flag~#1 } ##1 ;
+      { \exp_after:wN \use_none:n \cs:w flag~#1~##1 \cs_end: }
   }
 %    \end{macrocode}
 % \end{macro}
 %
 % \begin{macro}{\flag_clear:n}
 % \begin{macro}[aux]{\@@_clear:ww}
-%   Undefine control sequences, starting from the |_0| flag, upwards,
-%   until reaching an undefined control sequence.
+%   Undefine control sequences, starting from the |0| flag, upwards,
+%   until reaching an undefined control sequence.  We don't use
+%   \cs{cs_undefine:N} because that would act globally.
 %    \begin{macrocode}
 \cs_new_protected:Npn \flag_clear:n #1
   { \@@_clear:ww 0 ; #1 \q_stop }
 \cs_new_protected:Npn \@@_clear:ww #1 ; #2 \q_stop
   {
-    \if_cs_exist:w @@_#2_#1: \cs_end:
+    \if_cs_exist:w flag~#2~#1 \cs_end:
     \else:
       \exp_after:wN \use_none_delimit_by_q_stop:w
     \fi:
-    \cs_set_eq:cN { @@_#2_#1: } \tex_undefined:D
+    \cs_set_eq:cN { flag~#2~#1 } \tex_undefined:D
     \exp_after:wN \@@_clear:ww
     \__int_value:w \__int_eval:w \c_one + #1 ;
     #2 \q_stop
@@ -229,12 +252,33 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\flag_show:n, \flag_log:n}
+%   Show the height (terminal or log file) using appropriate \pkg{l3msg}
+%   auxiliaries.
+%    \begin{macrocode}
+\cs_new_protected:Npn \flag_show:n #1
+  { \__msg_show_wrap:n { > ~ flag ~ #1 ~ height = \flag_height:n {#1} } }
+\cs_new_protected:Npn \flag_log:n
+  { \__msg_log_next: \flag_show:n }
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\flag_set_trap:nn}
-%   ^^A todo: check that the flag exists.
-%   Redefine the trap.
+%   Redefine the trap if the flag exists.
 %    \begin{macrocode}
 \cs_new_protected:Npn \flag_set_trap:nn #1#2
-  { \cs_set:cpn { @@_trap_#1:w } ##1 ; {#2} }
+  {
+    \flag_if_exist:nTF {#1}
+      { \cs_set:cpn { flag~#1 } ##1 ; {#2} }
+      { \__msg_kernel_error:nnn { kernel } { flag-not-defined } {#1} }
+  }
+\__msg_kernel_new:nnnn { kernel } { flag-not-defined }
+  { Flag~#1~undefined. }
+  {
+    \c_@@_coding_error_text_tl
+    LaTeX~has~been~asked~to~affect~the~flag~#1~but~
+    this~has~not~been~defined~yet.
+  }
 %    \end{macrocode}
 % \end{macro}
 %
@@ -246,7 +290,7 @@
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \flag_if_exist:n #1 { p , T , F , TF }
   {
-    \cs_if_exist:cTF { @@_trap_#1:w }
+    \cs_if_exist:cTF { flag~#1 }
       { \prg_return_true: } { \prg_return_false: }
   }
 %    \end{macrocode}
@@ -257,7 +301,7 @@
 %    \begin{macrocode}
 \prg_new_conditional:Npnn \flag_if_raised:n #1 { p , T , F , TF }
   {
-    \if_cs_exist:w @@_#1_0: \cs_end:
+    \if_cs_exist:w flag~#1~0 \cs_end:
       \prg_return_true:
     \else:
       \prg_return_false:
@@ -269,12 +313,12 @@
 % \begin{macro}[EXP]{\flag_height:n}
 % \begin{macro}[EXP, aux]{\@@_height_loop:ww, \@@_height_end:ww}
 %   Extract the value of the flag by going through all of the
-%   |_|\meta{integer} control sequences starting from $0$.
+%   control sequences starting from |0|.
 %    \begin{macrocode}
 \cs_new:Npn \flag_height:n #1 { \@@_height_loop:ww 0; #1 \q_stop }
 \cs_new:Npn \@@_height_loop:ww #1 ; #2 \q_stop
   {
-    \if_cs_exist:w @@_#2_#1: \cs_end:
+    \if_cs_exist:w flag~#2~#1 \cs_end:
       \exp_after:wN \@@_height_loop:ww \__int_value:w \__int_eval:w \c_one +
     \else:
       \exp_after:wN \@@_height_end:ww
@@ -291,7 +335,7 @@
 %    \begin{macrocode}
 \cs_new:Npn \flag_raise:n #1
   {
-    \cs:w @@_trap_#1:w \exp_after:wN \cs_end:
+    \cs:w flag~#1 \exp_after:wN \cs_end:
     \__int_value:w \flag_height:n {#1} ;
   }
 %    \end{macrocode}

Modified: trunk/l3experimental/l3str/testfiles/m3flag001.lvt
===================================================================
--- trunk/l3experimental/l3str/testfiles/m3flag001.lvt	2017-02-12 16:09:32 UTC (rev 6902)
+++ trunk/l3experimental/l3str/testfiles/m3flag001.lvt	2017-02-12 16:59:39 UTC (rev 6903)
@@ -1,5 +1,5 @@
 %
-% Copyright (C) 2011 LaTeX3 Project
+% Copyright (C) 2011,2017 LaTeX3 Project
 %
 
 \documentclass{minimal}
@@ -24,10 +24,10 @@
     {
       \flag_if_exist:nT {A} { \ERROR }
       \flag_new:n {A}
-      \TYPE { \cs_meaning:N \__flag_trap_A:w }
+      \TYPE { \cs_meaning:c { flag~A } }
     }
     \flag_if_exist:nF {A} { \ERROR }
-    \TYPE { \cs_meaning:N \__flag_trap_A:w }
+    \TYPE { \cs_meaning:c { flag~A } }
     \flag_new:n {A}
     \flag_new:n {B}
   }
@@ -39,9 +39,9 @@
   {
     \flag_if_raised:nTF { C } { T } { F } ~
     \flag_height:n { C } ~
-    \cs_meaning:c { __flag_C_0: } ~
-    \cs_meaning:c { __flag_C_1: } ~
-    \cs_meaning:c { __flag_C_2: } ~ \NEWLINE
+    \cs_meaning:c { flag~C~0 } ~
+    \cs_meaning:c { flag~C~1 } ~
+    \cs_meaning:c { flag~C~2 } ~ \NEWLINE
   }
 \TIMO
 
@@ -63,4 +63,24 @@
     \TYPE { \test: }
   }
 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\TEST { show,~log }
+  {
+    \flag_raise:n {C}
+    \flag_show:n {C}
+    \flag_raise:n {C}
+    \flag_raise:n {C}
+    \flag_log:n {C}
+  }
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\TEST { set_trap }
+  {
+    \flag_raise:n {C}
+    \flag_raise:n {C}
+    \flag_set_trap:nn {C} { \__msg_expandable_error:n {flag~C~#1} }
+    \flag_raise:n {C}
+    \flag_log:n {C}
+  }
+
 \END

Modified: trunk/l3experimental/l3str/testfiles/m3flag001.tlg
===================================================================
--- trunk/l3experimental/l3str/testfiles/m3flag001.tlg	2017-02-12 16:09:32 UTC (rev 6902)
+++ trunk/l3experimental/l3str/testfiles/m3flag001.tlg	2017-02-12 16:59:39 UTC (rev 6903)
@@ -4,14 +4,14 @@
 ============================================================
 TEST 1: flag_new
 ============================================================
-Defining \__flag_trap_A:w on line ...
-\long macro:#1;->\exp_after:wN \use_none:n \cs:w __flag_A_#1:\cs_end: 
-\long macro:#1;->\exp_after:wN \use_none:n \cs:w __flag_A_#1:\cs_end: 
+Defining \flag A on line ...
+\long macro:#1;->\exp_after:wN \use_none:n \cs:w flag A #1\cs_end: 
+\long macro:#1;->\exp_after:wN \use_none:n \cs:w flag A #1\cs_end: 
 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 !
 ! LaTeX error: "kernel/command-already-defined"
 ! 
-! Control sequence \__flag_trap_A:w already defined.
+! Control sequence \flag A already defined.
 ! 
 ! See the LaTeX3 documentation for further information.
 ! 
@@ -21,14 +21,14 @@
 |'''''''''''''''''''''''''''''''''''''''''''''''
 | This is a coding error.
 | 
-| LaTeX has been asked to create a new control sequence '\__flag_trap_A:w' but
-| this name has already been used elsewhere.
+| LaTeX has been asked to create a new control sequence '\flag A' but this
+| name has already been used elsewhere.
 | 
 | The current meaning is:
-|   \long macro:#1;->\exp_after:wN \use_none:n \cs:w __flag_A_#1:\cs_end: 
+|   \long macro:#1;->\exp_after:wN \use_none:n \cs:w flag A #1\cs_end: 
 |...............................................
-Defining \__flag_trap_A:w on line ...
-Defining \__flag_trap_B:w on line ...
+Defining \flag A on line ...
+Defining \flag B on line ...
 ============================================================
 ============================================================
 TEST 2: raise, test, height
@@ -47,3 +47,25 @@
 T 10 \relax \relax \relax 
 F 0 undefined undefined undefined 
 ============================================================
+============================================================
+TEST 4: show, log
+============================================================
+> flag C height=1.
+<recently read> }
+l. ...  }
+> flag C height=3.
+============================================================
+============================================================
+TEST 5: set_trap
+============================================================
+! Undefined control sequence.
+<argument> \LaTeX3 error: 
+                           flag C 2
+l. ...  }
+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.
+> flag C height=2.
+============================================================

Modified: trunk/l3experimental/l3str/testfiles/m3str-convert004.tlg
===================================================================
--- trunk/l3experimental/l3str/testfiles/m3str-convert004.tlg	2017-02-12 16:09:32 UTC (rev 6902)
+++ trunk/l3experimental/l3str/testfiles/m3str-convert004.tlg	2017-02-12 16:59:39 UTC (rev 6903)
@@ -46,10 +46,10 @@
 Defining \__str_convert_encode_utf8: on line ...
 Defining \__str_encode_utf_viii_char:n on line ...
 Defining \__str_encode_utf_viii_loop:wwnnw on line ...
-Defining \__flag_trap_str_missing:w on line ...
-Defining \__flag_trap_str_extra:w on line ...
-Defining \__flag_trap_str_overlong:w on line ...
-Defining \__flag_trap_str_overflow:w on line ...
+Defining \flag str_missing on line ...
+Defining \flag str_extra on line ...
+Defining \flag str_overlong on line ...
+Defining \flag str_overflow on line ...
 Defining message LaTeX/str/utf8-decode on line ...
 Defining \__str_convert_decode_utf8: on line ...
 Defining \__str_decode_utf_viii_start:N on line ...
@@ -64,7 +64,7 @@
 Defining \__str_convert_encode_utf16le: on line ...
 Defining \__str_encode_utf_xvi_aux:N on line ...
 Defining \__str_encode_utf_xvi_char:n on line ...
-Defining \__flag_trap_str_end:w on line ...
+Defining \flag str_end on line ...
 Defining message LaTeX/str/utf16-encode on line ...
 Defining message LaTeX/str/utf16-decode on line ...
 Defining \__str_convert_decode_utf16be: on line ...



More information about the latex3-commits mailing list