[latex3-commits] [git/LaTeX3-latex3-latex3] cs-delimited-args: Check if two \csnames are equal (69e6f7ee2)

PhelypeOleinik tex.phelype at gmail.com
Tue Feb 25 23:11:16 CET 2020


Repository : https://github.com/latex3/latex3
On branch  : cs-delimited-args
Link       : https://github.com/latex3/latex3/commit/69e6f7ee269d7b78da21aa6d1a0e1bc01f08a581

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

commit 69e6f7ee269d7b78da21aa6d1a0e1bc01f08a581
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date:   Tue Feb 25 19:11:16 2020 -0300

    Check if two \csnames are equal
    
    When grabbing an argument delimited by a control sequence, we want to make sure that not only the meaning of the token matches, but also the actual control sequence name.


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

69e6f7ee269d7b78da21aa6d1a0e1bc01f08a581
 l3packages/xparse/xparse.dtx | 59 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 52 insertions(+), 7 deletions(-)

diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index 4e6f4c7a0..95358b2c4 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -2842,12 +2842,12 @@
 \cs_new_protected:Npn \@@_grab_D_obey_spaces:w #1#2#3 \@@_run_code:
   {
     \@@_grab_D_aux:NNnNN #1 #2 {#3} \cs_set_protected_nopar:Npn
-      \peek_meaning_remove:NTF
+      \@@_peek_meaning_remove:NTF
   }
 \cs_new_protected:Npn \@@_grab_D_long_obey_spaces:w #1#2#3 \@@_run_code:
   {
     \@@_grab_D_aux:NNnNN #1 #2 {#3} \cs_set_protected:Npn
-      \peek_meaning_remove:NTF
+      \@@_peek_meaning_remove:NTF
   }
 %    \end{macrocode}
 % \begin{macro}{\@@_grab_D_aux:NNnNN}
@@ -3035,13 +3035,13 @@
   {
     \@@_grab_E:nnNN {#1} {#2}
       \cs_set_protected_nopar:Npn
-      \peek_meaning_remove:NTF
+      \@@_peek_meaning_remove:NTF
   }
 \cs_new_protected:Npn \@@_grab_E_long_obey_spaces:w #1#2 \@@_run_code:
   {
     \@@_grab_E:nnNN {#1} {#2}
       \cs_set_protected:Npn
-      \peek_meaning_remove:NTF
+      \@@_peek_meaning_remove:NTF
   }
 %    \end{macrocode}
 %   A loop is needed here to allow a random ordering of keys. These are
@@ -3296,7 +3296,7 @@
 \cs_new_protected:Npn \@@_grab_t:w
   { \@@_grab_t_aux:NNw \@@_peek_nonspace_remove:NTF }
 \cs_new_protected:Npn \@@_grab_t_obey_spaces:w
-  { \@@_grab_t_aux:NNw \peek_meaning_remove:NTF }
+  { \@@_grab_t_aux:NNw \@@_peek_meaning_remove:NTF }
 \cs_new_protected:Npn \@@_grab_t_aux:NNw #1#2#3 \@@_run_code:
   {
     \tl_set:Nn \l_@@_signature_tl {#3}
@@ -4353,9 +4353,9 @@
 %   \cs{peek_meaning_remove:NTF}.
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_peek_nonspace:NTF
-  { \@@_peek_nonspace_aux:nNNTF { } \peek_meaning:NTF }
+  { \@@_peek_nonspace_aux:nNNTF { } \@@_peek_meaning:NTF }
 \cs_new_protected:Npn \@@_peek_nonspace_remove:NTF
-  { \@@_peek_nonspace_aux:nNNTF { } \peek_meaning_remove:NTF }
+  { \@@_peek_nonspace_aux:nNNTF { } \@@_peek_meaning_remove:NTF }
 \cs_new_protected:Npn \@@_peek_nonspace_aux:nNNTF #1#2#3#4#5
   {
     \peek_meaning_remove:NTF \c_space_token
@@ -4365,6 +4365,51 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\@@_peek_meaning:NTF, \@@_peek_meaning_remove:NTF}
+% \begin{macro}{\@@_peek_cs_check_equal:NNN, \@@_peek_meaning_aux:NNTF, \@@_peek_true_remove:NNw}
+%   Peek ahead for a token with a given meaning.  In case the search
+%   token is a control sequence, also check that the \meta{csname} is
+%   the same as the control sequence peeked at.  This extra verification
+%   is necessary when the command is delimited by control sequence tokens
+%   (as opposed to character tokens), and we want the the exact same
+%   control sequence to match.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_peek_meaning:NTF
+  { \@@_peek_meaning_aux:NNTF \c_false_bool }
+\cs_new_protected:Npn \@@_peek_meaning_remove:NTF
+  { \@@_peek_meaning_aux:NNTF \c_true_bool }
+\cs_new_protected:Npn \@@_peek_meaning_aux:NNTF #1#2#3#4
+  {
+    \tl_set:Nn \l_@@_tmpa_tl {#3}
+    \tl_set:Nn \l_@@_tmpb_tl {#4}
+    \peek_meaning:NTF #2
+      {
+        \token_if_cs:NTF #2
+          { \@@_peek_cs_check_equal:NNN #1 #2 }
+          { \@@_peek_true_remove:NNw #1 \l_@@_tmpa_tl }
+      }
+      { \l_@@_tmpb_tl }
+  }
+\cs_new_protected:Npn \@@_peek_cs_check_equal:NNN #1#2#3
+  {
+    \str_if_eq:nnTF {#2} {#3}
+      { \@@_peek_true_remove:NNw #1 \l_@@_tmpa_tl }
+      { \l_@@_tmpb_tl }
+    #3
+  }
+\cs_new_protected:Npn \@@_peek_true_remove:NNw #1 #2
+  {
+    \bool_if:NTF #1
+      {
+        \tex_afterassignment:D #2
+        \cs_set_eq:NN \@@_tmp:w
+      }
+      {#2}
+  }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 % \subsection{Messages}
 %
 % \begin{macro}{\@@_environment_or_command:}





More information about the latex3-commits mailing list.