[latex3-commits] [git/LaTeX3-latex3-latex3] main: Report the number of added braces in regex split/extract (see #377) (a937eaf0f)
Bruno Le Floch
blflatex at gmail.com
Thu May 13 00:27:58 CEST 2021
Repository : https://github.com/latex3/latex3
On branch : main
Link : https://github.com/latex3/latex3/commit/a937eaf0fd16aa3bf235c5c503fbdbdb632f22f4
>---------------------------------------------------------------
commit a937eaf0fd16aa3bf235c5c503fbdbdb632f22f4
Author: Bruno Le Floch <blflatex at gmail.com>
Date: Thu May 13 00:26:35 2021 +0200
Report the number of added braces in regex split/extract (see #377)
>---------------------------------------------------------------
a937eaf0fd16aa3bf235c5c503fbdbdb632f22f4
l3kernel/l3regex.dtx | 34 +++---
l3kernel/testfiles/m3regex006.lvt | 2 +-
l3kernel/testfiles/m3regex006.tlg | 228 ++++++++++++++++++++++++++++++++++++++
3 files changed, 249 insertions(+), 15 deletions(-)
diff --git a/l3kernel/l3regex.dtx b/l3kernel/l3regex.dtx
index 3cdb00818..353afa112 100644
--- a/l3kernel/l3regex.dtx
+++ b/l3kernel/l3regex.dtx
@@ -6307,8 +6307,8 @@
% \end{variable}
%
% \begin{variable}{@@_begin, @@_end}
-% Those flags are raised to indicate extra begin-group
-% or end-group tokens when extracting submatches.
+% Those flags are raised to indicate begin-group or end-group tokens
+% that had to be added when extracting submatches.
% \begin{macrocode}
\flag_new:n { @@_begin }
\flag_new:n { @@_end }
@@ -6547,17 +6547,17 @@
{ \l_@@_submatch_int - 1 }
}
\@@_extract_seq_aux:n
- \int_compare:nNnF
- {
- \flag_height:n { @@_begin } +
- \flag_height:n { @@_end }
- }
- = 0
+ \int_set:Nn \l_@@_added_begin_int
+ { \flag_height:n { @@_begin } }
+ \int_set:Nn \l_@@_added_end_int
+ { \flag_height:n { @@_end } }
+ \int_compare:nNnT
+ { \l_@@_added_begin_int + \l_@@_added_end_int } > 0
{
\__kernel_msg_error:nnxxx { regex } { result-unbalanced }
{ splitting~or~extracting~submatches }
- { \flag_height:n { @@_end } }
- { \flag_height:n { @@_begin } }
+ { \int_use:N \l_@@_added_begin_int }
+ { \int_use:N \l_@@_added_end_int }
}
\seq_set_map_x:NNn \l_@@_internal_seq \l_@@_internal_seq {##1}
\exp_args:NNNo
@@ -6581,13 +6581,19 @@
\cs_new:Npn \@@_extract_seq_aux:ww #1; #2;
{
\if_int_compare:w #1 < 0 \exp_stop_f:
- \flag_raise:n { @@_end }
- \prg_replicate:nn {-#1} { \exp_not:n { { \if_false: } \fi: } }
+ \prg_replicate:nn {-#1}
+ {
+ \flag_raise:n { @@_begin }
+ \exp_not:n { { \if_false: } \fi: }
+ }
\fi:
\@@_query_submatch:n {#2}
\if_int_compare:w #1 > 0 \exp_stop_f:
- \flag_raise:n { @@_begin }
- \prg_replicate:nn {#1} { \exp_not:n { \if_false: { \fi: } } }
+ \prg_replicate:nn {#1}
+ {
+ \flag_raise:n { @@_end }
+ \exp_not:n { \if_false: { \fi: } }
+ }
\fi:
}
% \end{macrocode}
diff --git a/l3kernel/testfiles/m3regex006.lvt b/l3kernel/testfiles/m3regex006.lvt
index 42f69b8d5..a9c9a1800 100644
--- a/l3kernel/testfiles/m3regex006.lvt
+++ b/l3kernel/testfiles/m3regex006.lvt
@@ -103,7 +103,7 @@
\test:nnNTF { } { ab{c}ade } { \TRUE } { \ERROR }
\test:nnNTF { a } { ab{c}ade } { \TRUE } { \ERROR }
\test:nnNTF { x } { ab{c}ade } { \ERROR } { \FALSE }
- % \test:nnNTF { ([^c])a } { ab{c}ade } { \TRUE } { \ERROR }
+ \test:nnNTF { ([^c].)a } { ab{{c}}ade } { \TRUE } { \ERROR }
\test:nnNTF { ([^c]..)a } { ab{c}ade } { \TRUE } { \ERROR }
\test:nnNTF { [c-z] } { ab{c}ade } { \TRUE } { \ERROR }
% \test:nnNTF { \# (.). } { a#{b}c#d } { \TRUE } { \ERROR }
diff --git a/l3kernel/testfiles/m3regex006.tlg b/l3kernel/testfiles/m3regex006.tlg
index ea8f261b7..2f1ea926f 100644
--- a/l3kernel/testfiles/m3regex006.tlg
+++ b/l3kernel/testfiles/m3regex006.tlg
@@ -224,6 +224,234 @@ FALSE
FALSE
|[ab{c}ade] |
|[ab{c}ade] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+TRUE
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+TRUE
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+TRUE
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+TRUE
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 2 left, 2 right.
+TRUE
+|[ab{{c}}] [{{}}] [de] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 2 left, 2 right.
+TRUE
+|[ab{{c}}] [{{}}] [de] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 2 left, 2 right.
+|[ab{{c}}] [{{}}] [de] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 2 left, 2 right.
+|[ab{{c}}] [{{}}] [de] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+TRUE
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+TRUE
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+TRUE
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+TRUE
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 4 left, 0 right.
+|[{{}}a] [{{}}] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 2 left, 2 right.
+TRUE
+|[ab{{c}}] [{{}}] [de] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 2 left, 2 right.
+TRUE
+|[ab{{c}}] [{{}}] [de] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 2 left, 2 right.
+|[ab{{c}}] [{{}}] [de] |
+! LaTeX3 Error: Missing brace inserted when splitting or extracting
+(LaTeX3) submatches.
+For immediate help type H <return>.
+ ...
+l. ... }
+LaTeX was asked to do some regular expression operation, and the resulting
+token list would not have the same number of begin-group and end-group tokens.
+Braces were inserted: 2 left, 2 right.
+|[ab{{c}}] [{{}}] [de] |
TRUE
|[{c}a] [{c}] |
TRUE
More information about the latex3-commits
mailing list.