Skip to content

Commit

Permalink
lthooks: \DebugPrintHook
Browse files Browse the repository at this point in the history
- new function for testing
- new dedicated `lthooks-debug.tlv`
- many `*.tlv` and `*.tlg` updated
- some `update_*_tests.sh` updated
  • Loading branch information
jlaurens committed Jan 28, 2024
1 parent 3c9a2c4 commit c7109bf
Show file tree
Hide file tree
Showing 140 changed files with 7,664 additions and 2,329 deletions.
193 changes: 190 additions & 3 deletions base/lthooks.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
%
% \begin{macrocode}
\def\lthooksversion{v1.1h}
\def\lthooksdate{2024/01/23}
\def\lthooksdate{2024/01/27}
% \end{macrocode}
%
%<*driver>
Expand Down Expand Up @@ -1000,7 +1000,7 @@
% that is, in the order they will be executed when the hook is used.
%
%
% \subsubsection{Debugging hook code}
% \subsubsection{Debugging or testing hook code}
%
% \begin{function}{\DebugHooksOn,\DebugHooksOff}
% \begin{syntax}
Expand All @@ -1011,6 +1011,15 @@
% not really intended for normal use.
% \end{function}
%
% \begin{function}{\DebugPrintHook}
% \begin{syntax}
% \cs{DebugPrintHook} \Arg{hook}
% \end{syntax}
% Prints information about the hook. The output is rather coarse and
% primarily intended for debugging or testing purposes.
% Use \cs{ShowHook} for normal use.
% \end{function}
%
%
% \subsection{L3 programming layer (\texttt{expl3}) interfaces}
% \label{sec:l3hook-interface}
Expand Down Expand Up @@ -6664,7 +6673,154 @@
% \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\DebugPrintHook}
% Print detailed hook information.
% \changes{v1.1h}{2024/01/27}
% {Add \cs{DebugPrintHook}.}
% \begin{macrocode}
\cs_new_protected:Npn \DebugPrintHook #1
{
% \end{macrocode}
% We store the argument before normalization
% \begin{macrocode}
\tl_set:Ne \l_@@_print_tl { #1 }
\@@_normalize_hook_args:Nn \@@_debug_print:n { #1 }
}
% \end{macrocode}
% Next function is for \cs{DebugPrintHook} usage only.
% \begin{macrocode}
%<latexrelease>\IncludeInRelease{2024/01/27}{\DebugPrintHook}
%<latexrelease> {Test~or~debug}
\cs_new_protected:Npn \@@_debug_print:n #1
{
\@@_preamble_hook:n { #1 }
\exp_args:NV \str_if_eq:nnF \l_@@_print_tl { #1 }
{
% \end{macrocode}
% The normalization has changed the argument, display the original argument.
% \begin{macrocode}
\iow_term:x { <<<~Hook:~'#1'(<- ~ '\l_@@_print_tl') }
\use_none:nn
}
\iow_term:n { <<<~Hook:~'#1' }
\iow_term:n { ...~Attributes: }
\cs_set:Npn \@@_tmp:w ##1
{
\iow_term:x
{
...~\space\space##1:~
\cs_if_exist_use:cF { @@_if_##1:nT }
{ \use:c { hook_if_##1:nT } }
{ #1 } { Y \use_none:n } N
}
}
\@@_tmp:w { deprecated_generic }
\@@_tmp:w { generic }
\@@_tmp:w { declared }
\@@_tmp:w { structure_exist }
\@@_tmp:w { usable }
\@@_tmp:w { disabled }
\@@_tmp:w { empty }
\@@_tmp:w { reversed }
\@@_tmp:w { generic_reversed }
\@@_tmp:w { consumed }
% \end{macrocode}
% Done with \cs[no-index]{@@_tmp:w}.
% \begin{macrocode}
\iow_term:x
{
...~\space\space\c_hash_str\space of~arguments:~
\int_eval:n { \str_count:e { \@@_parameter:n {#1} } / 3 }
}
\iow_term:n { ...~Code~chunks: }
\prop_map_inline:cn { g_@@_#1_code_prop }
{
\exp_after:wN \cs_set:Npn \exp_after:wN \@@_debug_print:n:w
\c_@@_nine_parameters_tl { ##2 }
\iow_term:x
{
...~\space\space
'##1' ~->~\cs_replacement_spec:N \@@_debug_print:n:w
}
}
\iow_term:x
{
...~\space\space'top~level'
\@@_cs_if_empty:cTF { @@_toplevel~#1 }
{ ~ empty }
{ ~ -> ~ \cs_replacement_spec:c { @@_toplevel~#1 } }
}
\iow_term:x
{
...~\space\space next-only
\@@_cs_if_empty:cTF { @@_next~#1 }
{ ~ empty }
{
~ -> ~ \exp_last_unbraced:Nf \@@_log_next_code:w
{ \cs_replacement_spec:c { @@_next~#1 } }
}
}
\iow_term:n { ...~Default~rules: }
\tl_set:Nn \l_@@_print_tl { \iow_term:x { ...~\space\space None } }
\@@_list_rules:nn {#1}
{
\str_if_eq:nnT {##3} {??}
{
\tl_set:Nn \l_@@_print_tl { ##2 }
\tl_if_in:NnTF \l_@@_print_tl { ^^J }
{
\tl_replace_once:Nnn \l_@@_print_tl { ^^J } { '~##1~' }
}
{
\tl_replace_once:Nnn \l_@@_print_tl { | } { '~##1~' }
}
\iow_term:x { ...~\space\space'\l_@@_print_tl' }
\tl_clear:N \l_@@_print_tl
}
}
\l_@@_print_tl
\iow_term:n { ...~Rules: }
\tl_set:Nn \l_@@_print_tl { \iow_term:x { ...~\space\space None } }
\@@_list_rules:nn {#1}
{
\str_if_eq:nnF {##3} {??}
{
\tl_set:Nn \l_@@_print_tl { ##2 }
\tl_if_in:NnTF \l_@@_print_tl { ^^J }
{
\tl_replace_once:Nnn \l_@@_print_tl { ^^J } { '~##1~' }
}
{
\tl_replace_once:Nnn \l_@@_print_tl { | } { '~##1~' }
}
\iow_term:x { ...~\space\space'\l_@@_print_tl' }
\tl_clear:N \l_@@_print_tl
}
}
\l_@@_print_tl
\iow_term:n { ...~Execution~order: }
\hook_if_empty:nF { #1 }
{
\clist_if_exist:cT { g_@@_#1_labels_clist }
{
\clist_if_empty:cF
{ g_@@_#1_labels_clist }
{
\iow_term:x
{
...~\space\space'
\clist_use:cn { g_@@_#1_labels_clist } { ',~' }'
}
\use_none:n
}
}
}
{ \iow_term:x { ...~\space\space None } }
\iow_term:n { >>> }
}
%<latexrelease>\EndIncludeInRelease
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Specifying code for next invocation}
Expand Down Expand Up @@ -7174,6 +7330,37 @@
% \end{macrocode}
% \end{macro}
%
% \begin{macro}[pTF]{
% \hook_if_consumed:n,
% }
% Partially redundant with \cs[no-index]{@@_execute_immediately:nTF}.
% \begin{macrocode}
\prg_new_conditional:Npnn \hook_if_consumed:n #1 { p, T, F, TF }
{
\exp_after:wN \@@_use_none_delimit_by_s_mark:w
\if:w I
\if_cs_exist:w g_@@_#1_reversed_tl \cs_end:
\cs:w g_@@_#1_reversed_tl \exp_after:wN \cs_end:
\fi:
X
\s_@@_mark \prg_return_true:
\else:
\s_@@_mark \prg_return_false:
\fi:
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{
% \IfHookConsumedTF,
% }
% \LaTeXe\ API. Not yet documented.
% \begin{macrocode}
\cs_set_eq:NN \IfHookConsumedTF \hook_if_consumed:nTF
% \end{macrocode}
% \end{macro}
%
%
% \subsection{Querying a hook}
%
% Simpler data types, like token lists, have three possible states; they
Expand Down
6 changes: 3 additions & 3 deletions base/testfiles-lthooks/filehook-003.lvt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

\begin{document}

\LogHook{include/before}
\LogHook{include/after}
\LogHook{include/end}
\DebugPrintHook{include/before}
\DebugPrintHook{include/after}
\DebugPrintHook{include/end}

\END

107 changes: 78 additions & 29 deletions base/testfiles-lthooks/filehook-003.tlg
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,81 @@ LaTeX Font Info: Checking defaults for OMX/cmex/m/n on input line ....
LaTeX Font Info: ... okay on input line ....
LaTeX Font Info: Checking defaults for U/cmr/m/n on input line ....
LaTeX Font Info: ... okay on input line ....
==> Hook: 'include/before'
> Code chunks:
> 'A' -> \typeout {A}
> 'B' -> \typeout {B}
> 'C' -> \typeout {C}
> Execution order:
> 1: 'A'
> 2: 'B'
> 3: 'C'.
==> Hook: 'include/after'
> reversed
> Code chunks:
> 'A' -> \typeout {A}
> 'B' -> \typeout {B}
> 'C' -> \typeout {C}
> Execution order:
> 1: 'C'
> 2: 'B'
> 3: 'A'.
==> Hook: 'include/end'
> reversed
> Code chunks:
> 'A' -> \typeout {A}
> 'B' -> \typeout {B}
> 'C' -> \typeout {C}
> Execution order:
> 1: 'C'
> 2: 'B'
> 3: 'A'.
<<< Hook: 'include/before'
... Attributes:
... deprecated_generic: N
... generic: N
... declared: Y
... structure_exist: Y
... usable: Y
... disabled: N
... empty: N
... reversed: N
... generic_reversed: N
... consumed: N
... # of arguments: 0
... Code chunks:
... 'A' -> \typeout {A}
... 'B' -> \typeout {B}
... 'C' -> \typeout {C}
... 'top level' empty
... next-only empty
... Default rules:
... None
... Rules:
... None
... Execution order:
... 'A', 'B', 'C'
>>>
<<< Hook: 'include/after'
... Attributes:
... deprecated_generic: N
... generic: N
... declared: Y
... structure_exist: Y
... usable: Y
... disabled: N
... empty: N
... reversed: Y
... generic_reversed: N
... consumed: N
... # of arguments: 0
... Code chunks:
... 'A' -> \typeout {A}
... 'B' -> \typeout {B}
... 'C' -> \typeout {C}
... 'top level' empty
... next-only empty
... Default rules:
... None
... Rules:
... None
... Execution order:
... 'C', 'B', 'A'
>>>
<<< Hook: 'include/end'
... Attributes:
... deprecated_generic: N
... generic: N
... declared: Y
... structure_exist: Y
... usable: Y
... disabled: N
... empty: N
... reversed: Y
... generic_reversed: N
... consumed: N
... # of arguments: 0
... Code chunks:
... 'A' -> \typeout {A}
... 'B' -> \typeout {B}
... 'C' -> \typeout {C}
... 'top level' empty
... next-only empty
... Default rules:
... None
... Rules:
... None
... Execution order:
... 'C', 'B', 'A'
>>>
2 changes: 1 addition & 1 deletion base/testfiles-lthooks/filehook-bug-140.lvt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

\START

\LogHook{file/\jobname-foo-bar.tex/before}
\DebugPrintHook{file/\jobname-foo-bar.tex/before}

\typeout{----------------------}

Expand Down
29 changes: 23 additions & 6 deletions base/testfiles-lthooks/filehook-bug-140.tlg
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
This is a generated file for the l3build validation system.
Don't change this file in any respect.
==> Hook: 'file/filehook-bug-140-foo-bar.tex/before'
> builtin generic
> Code chunks:
> 'top-level' -> \typeout {1}\typeout {2}\typeout {3}
> Execution order:
> 1: 'top-level'.
<<< Hook: 'file/filehook-bug-140-foo-bar.tex/before'
... Attributes:
... deprecated_generic: N
... generic: Y
... declared: N
... structure_exist: Y
... usable: Y
... disabled: N
... empty: N
... reversed: N
... generic_reversed: N
... consumed: N
... # of arguments: 0
... Code chunks:
... 'top level' -> \typeout {1}\typeout {2}\typeout {3}
... next-only empty
... Default rules:
... None
... Rules:
... None
... Execution order:
... None
>>>
----------------------
1
2
Expand Down
Loading

0 comments on commit c7109bf

Please sign in to comment.