Skip to content

Commit

Permalink
Make \regex_show:n show printable characters (fixes #590)
Browse files Browse the repository at this point in the history
Previously only the charcode was shown, which made it harder to
debug things.
  • Loading branch information
blefloch committed Apr 27, 2021
1 parent aecd3a5 commit ab92696
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 112 deletions.
1 change: 1 addition & 0 deletions l3kernel/CHANGELOG.md
Expand Up @@ -20,6 +20,7 @@ this project uses date-based 'snapshot' version identifiers.
- `\pdf_version_gset:n` for `dvips`.
- Improve handling of `\exp_not:n` in `\text_expand:n` (issue #875)
- `\file_full_name:n` now avoids calling `\pdffilesize` multiple times on the same file.
- Show printable characters explicitly in `\regex_show:n`

### Fixed
- Evalutate integer constants only once (issue#861)
Expand Down
25 changes: 19 additions & 6 deletions l3kernel/l3regex.dtx
Expand Up @@ -509,7 +509,7 @@
% which never change.
% \end{function}
%
% \begin{function}[added = 2017-05-26]{\regex_show:n, \regex_show:N}
% \begin{function}[added = 2017-05-26, updated = 2021-04-15]{\regex_show:n, \regex_show:N}
% \begin{syntax}
% \cs{regex_show:n} \Arg{regex}
% \end{syntax}
Expand Down Expand Up @@ -3554,18 +3554,18 @@
\cs_set:Npn \@@_A_test: { anchor~at~start~(\iow_char:N\\A) }
\cs_set:Npn \@@_G_test: { anchor~at~start~of~match~(\iow_char:N\\G) }
\cs_set_protected:Npn \@@_item_caseful_equal:n ##1
{ \@@_show_one:n { char~code~\int_eval:n{##1} } }
{ \@@_show_one:n { char~code~\@@_show_char:n{##1} } }
\cs_set_protected:Npn \@@_item_caseful_range:nn ##1##2
{
\@@_show_one:n
{ range~[\int_eval:n{##1}, \int_eval:n{##2}] }
{ range~[\@@_show_char:n{##1}, \@@_show_char:n{##2}] }
}
\cs_set_protected:Npn \@@_item_caseless_equal:n ##1
{ \@@_show_one:n { char~code~\int_eval:n{##1}~(caseless) } }
{ \@@_show_one:n { char~code~\@@_show_char:n{##1}~(caseless) } }
\cs_set_protected:Npn \@@_item_caseless_range:nn ##1##2
{
\@@_show_one:n
{ Range~[\int_eval:n{##1}, \int_eval:n{##2}]~(caseless) }
{ Range~[\@@_show_char:n{##1}, \@@_show_char:n{##2}]~(caseless) }
}
\cs_set_protected:Npn \@@_item_catcode:nT
{ \@@_show_item_catcode:NnT \c_true_bool }
Expand All @@ -3574,7 +3574,7 @@
\cs_set_protected:Npn \@@_item_reverse:n
{ \@@_show_scope:nn { Reversed~match } }
\cs_set_protected:Npn \@@_item_exact:nn ##1##2
{ \@@_show_one:n { char~##2,~catcode~##1 } }
{ \@@_show_one:n { char~\@@_show_char:n{##2},~catcode~##1 } }
\cs_set_eq:NN \@@_item_exact_cs:n \@@_show_item_exact_cs:n
\cs_set_protected:Npn \@@_item_cs:n
{ \@@_show_scope:nn { control~sequence } }
Expand All @@ -3590,6 +3590,19 @@
% \end{macrocode}
% \end{macro}
%
% \begin{macro}[EXP]{\@@_show_char:n}
% Show a single character, together with its ascii representation if available.
% This could be extended to beyond ascii. It is not ideal for parentheses themselves.
% \begin{macrocode}
\cs_new:Npn \@@_show_char:n #1
{
\int_eval:n {#1}
\int_compare:nT { 32 <= #1 <= 126 }
{ ~ ( \char_generate:nn {#1} {12} ) }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_show_one:n}
% Every part of the final message go through this function, which adds
% one line to the output, with the appropriate prefix.
Expand Down

0 comments on commit ab92696

Please sign in to comment.