diff options
author | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2007-06-04 14:28:58 +0000 |
---|---|---|
committer | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2007-06-04 14:28:58 +0000 |
commit | 2713a25161c167b2339b245e124932e6e3820ba7 (patch) | |
tree | 516802e8275b1f50e925ab2bedb0575caafbb544 /pcre_compile.c | |
parent | 977a33e0e05ab3378b480a7270a0d89c24644dec (diff) | |
download | pcre-2713a25161c167b2339b245e124932e6e3820ba7.tar.gz |
Support \k{name} and \g{name} a la Perl 5.10.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@171 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'pcre_compile.c')
-rw-r--r-- | pcre_compile.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/pcre_compile.c b/pcre_compile.c index c930193..3fd5432 100644 --- a/pcre_compile.c +++ b/pcre_compile.c @@ -242,7 +242,7 @@ static const char *error_texts[] = { /* 55 */ "repeating a DEFINE group is not allowed", "inconsistent NEWLINE options", - "\\g is not followed by an (optionally braced) non-zero number", + "\\g is not followed by a braced name or an optionally braced non-zero number", "(?+ or (?- or (?(+ or (?(- must be followed by a non-zero number" }; @@ -453,11 +453,22 @@ else /* \g must be followed by a number, either plain or braced. If positive, it is an absolute backreference. If negative, it is a relative backreference. - This is a Perl 5.10 feature. */ + This is a Perl 5.10 feature. Perl 5.10 also supports \g{name} as a + reference to a named group. This is part of Perl's movement towards a + unified syntax for back references. As this is synonymous with \k{name}, we + fudge it up by pretending it really was \k. */ case 'g': if (ptr[1] == '{') { + const uschar *p; + for (p = ptr+2; *p != 0 && *p != '}'; p++) + if (*p != '-' && (digitab[*p] & ctype_digit) == 0) break; + if (*p != 0 && *p != '}') + { + c = -ESC_k; + break; + } braced = TRUE; ptr++; } @@ -4470,12 +4481,13 @@ for (;; ptr++) zerofirstbyte = firstbyte; zeroreqbyte = reqbyte; - /* \k<name> or \k'name' is a back reference by name (Perl syntax) */ + /* \k<name> or \k'name' is a back reference by name (Perl syntax). + We also support \k{name} (.NET syntax) */ - if (-c == ESC_k && (ptr[1] == '<' || ptr[1] == '\'')) + if (-c == ESC_k && (ptr[1] == '<' || ptr[1] == '\'' || ptr[1] == '{')) { is_recurse = FALSE; - terminator = (*(++ptr) == '<')? '>' : '\''; + terminator = (*(++ptr) == '<')? '>' : (*ptr == '\'')? '\'' : '}'; goto NAMED_REF_OR_RECURSE; } |