Skip to content

Commit b8b3c66

Browse files
committed
pcre2test: improve binmode
Report parameters for OP_[V]REVERSE, avoid ambiguous back references, simplify code and update related documentation.
1 parent ead3652 commit b8b3c66

File tree

13 files changed

+139
-144
lines changed

13 files changed

+139
-144
lines changed

doc/pcre2pattern.3

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3184,8 +3184,8 @@ For example:
31843184
(?(VERSION>=10.4)yes|no)
31853185
.sp
31863186
This pattern matches "yes" if the PCRE2 version is greater or equal to 10.4, or
3187-
"no" otherwise. The fractional part of the version number may not contain more
3188-
than two digits.
3187+
"no" otherwise. The fractional part of the version number could be ommited and
3188+
may not contain more than two digits.
31893189
.
31903190
.
31913191
.SS "Assertion conditions"

doc/pcre2syntax.3

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -627,22 +627,26 @@ following ways:
627627
(?(condition)yes-pattern)
628628
(?(condition)yes-pattern|no-pattern)
629629
.sp
630-
(?(n) absolute reference condition
631-
(?(+n) relative reference condition (PCRE2 extension)
632-
(?(-n) relative reference condition (PCRE2 extension)
633-
(?(<name>) named reference condition (Perl)
634-
(?('name') named reference condition (Perl)
635-
(?(name) named reference condition (PCRE2, deprecated)
636-
(?(R) overall recursion condition
637-
(?(Rn) specific numbered group recursion condition
638-
(?(R&name) specific named group recursion condition
639-
(?(DEFINE) define groups for reference
640-
(?(VERSION[>]=n.m) test PCRE2 version
641-
(?(assert) assertion condition
630+
(?(n) absolute reference condition
631+
(?(+n) relative reference condition (PCRE2 extension)
632+
(?(-n) relative reference condition (PCRE2 extension)
633+
(?(<name>) named reference condition (Perl)
634+
(?('name') named reference condition (Perl)
635+
(?(name) named reference condition (PCRE2, deprecated)
636+
(?(R) overall recursion condition
637+
(?(Rn) specific numbered group recursion condition
638+
(?(R&name) specific named group recursion condition
639+
(?(DEFINE) define groups for reference
640+
(?(VERSION[>]=n[.m]) test PCRE2 version
641+
(?(assert) assertion condition
642642
.sp
643643
Note the ambiguity of (?(R) and (?(Rn) which might be named reference
644644
conditions or recursion tests. Such a condition is interpreted as a reference
645645
condition if the relevant named group exists.
646+
.sp
647+
The parts within brackets for the VERSION conditional syntax could be ommited.
648+
The fractional part of the version number defaults to 0, and can be up to two
649+
digits long.
646650
.
647651
.
648652
.SH "BACKTRACKING CONTROL"
@@ -708,16 +712,16 @@ there is additional interpretation:
708712
1. Backslash is an escape character, and the forms described in "ESCAPED
709713
CHARACTERS" above are recognized. Also:
710714
.sp
711-
\eQ...\eE can be used to suppress interpretation
712-
\el force the next character to lower case
713-
\eu force the next character to upper case
714-
\eL force subsequent characters to lower case
715-
\eU force subsequent characters to upper case
716-
\eu\eL force next character to upper case, then all lower
717-
\el\eU force next character to lower case, then all upper
718-
\eE end \eL or \eU case forcing
719-
\eb backspace character (note: as in character class in pattern)
720-
\ev vertical tab character (note: not the same as in a pattern)
715+
\eQ...\eE can be used to suppress interpretation
716+
\el force the next character to lower case
717+
\eu force the next character to upper case
718+
\eL force subsequent characters to lower case
719+
\eU force subsequent characters to upper case
720+
\eu\eL force next character to upper case, then all lower
721+
\el\eU force next character to lower case, then all upper
722+
\eE end \eL or \eU case forcing
723+
\eb backspace character (note: as in character class in pattern)
724+
\ev vertical tab character (note: not the same as in a pattern)
721725
.sp
722726
2. The Python form \eg<n>, where the angle brackets are part of the syntax and
723727
\fIn\fP is either a group name or a number, is recognized as an alternative way

src/pcre2_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1988,7 +1988,8 @@ some cases doesn't actually use these names at all). */
19881988
"Cond", \
19891989
"SBra", "SBraPos", "SCBra", "SCBraPos", \
19901990
"SCond", \
1991-
"Capture ref", "Capture dnref", "Cond rec", "Cond dnrec", \
1991+
"Capture ref", "Capture ref <", \
1992+
"Cond recurse", "Cond recurse <", \
19921993
"Cond false", "Cond true", \
19931994
"Brazero", "Braminzero", "Braposzero", \
19941995
"*MARK", "*PRUNE", "*PRUNE", "*SKIP", "*SKIP", \

src/pcre2_printint_inc.h

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -734,31 +734,22 @@ for(;;)
734734
fprintf(f, "%s", OP_names[*code]);
735735
break;
736736

737-
case OP_REVERSE:
738-
if (print_lengths) fprintf(f, "%3d ", GET2(code, 1));
739-
else fprintf(f, " ");
740-
fprintf(f, "%s", OP_names[*code]);
741-
break;
742-
743-
case OP_VREVERSE:
744-
if (print_lengths) fprintf(f, "%3d %d ", GET2(code, 1),
745-
GET2(code, 1 + IMM2_SIZE));
746-
else fprintf(f, " ");
747-
fprintf(f, "%s", OP_names[*code]);
748-
break;
749-
750737
case OP_CLOSE:
751738
fprintf(f, " %s %d", OP_names[*code], GET2(code, 1));
752739
break;
753740

754741
case OP_CREF:
755-
fprintf(f, "%3d %s", GET2(code,1), OP_names[*code]);
742+
case OP_REVERSE:
743+
case OP_VREVERSE:
744+
fprintf(f, "%3d %s", GET2(code, 1), OP_names[*code]);
745+
if (*code == OP_VREVERSE) fprintf(f, " %d", GET2(code, 1 + IMM2_SIZE));
756746
break;
757747

758748
case OP_DNCREF:
749+
case OP_DNRREF:
759750
{
760751
PCRE2_SPTR entry = nametable + (GET2(code, 1) * nesize) + IMM2_SIZE;
761-
fprintf(f, " %s Capture ref <", flag);
752+
fprintf(f, " %s %s", flag, OP_names[*code]);
762753
print_custring(f, entry);
763754
fprintf(f, ">%d", GET2(code, 1 + IMM2_SIZE));
764755
}
@@ -767,26 +758,9 @@ for(;;)
767758
case OP_RREF:
768759
c = GET2(code, 1);
769760
if (c == RREF_ANY)
770-
fprintf(f, " Cond recurse any");
761+
fprintf(f, " %s any", OP_names[*code]);
771762
else
772-
fprintf(f, " Cond recurse %d", c);
773-
break;
774-
775-
case OP_DNRREF:
776-
{
777-
PCRE2_SPTR entry = nametable + (GET2(code, 1) * nesize) + IMM2_SIZE;
778-
fprintf(f, " %s Cond recurse <", flag);
779-
print_custring(f, entry);
780-
fprintf(f, ">%d", GET2(code, 1 + IMM2_SIZE));
781-
}
782-
break;
783-
784-
case OP_FALSE:
785-
fprintf(f, " Cond false");
786-
break;
787-
788-
case OP_TRUE:
789-
fprintf(f, " Cond true");
763+
fprintf(f, " %s %d", OP_names[*code], c);
790764
break;
791765

792766
case OP_STARI:
@@ -936,7 +910,7 @@ for(;;)
936910
flag = "/i";
937911
/* Fall through */
938912
case OP_REF:
939-
fprintf(f, " %s \\%d", flag, GET2(code,1));
913+
fprintf(f, " %s \\g{%d}", flag, GET2(code, 1));
940914
i = (*code == OP_REFI)? code[1 + IMM2_SIZE] : 0;
941915
if (i != 0) fprintf(f, " 0x%02x", i);
942916
ccode = code + OP_lengths[*code];
@@ -1104,10 +1078,6 @@ for(;;)
11041078
extra += code[1];
11051079
break;
11061080

1107-
case OP_THEN:
1108-
fprintf(f, " %s", OP_names[*code]);
1109-
break;
1110-
11111081
case OP_CIRCM:
11121082
case OP_DOLLM:
11131083
flag = "/m";
@@ -1121,7 +1091,7 @@ for(;;)
11211091
}
11221092

11231093
code += OP_lengths[*code] + extra;
1124-
fprintf(f, "\n");
1094+
putc('\n', f);
11251095
}
11261096
}
11271097

testdata/testinput2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6146,6 +6146,8 @@ a)"xI
61466146

61476147
/(?(VERSION=10.3)b)((?<=b).*)/B
61486148

6149+
/(?(VERSION>=10.3)b)((?<=b).*)/B
6150+
61496151
/[aA]b[cC]/IB
61506152

61516153
/[cc]abcd/I

0 commit comments

Comments
 (0)