/[pcre]/code/trunk/pcre_compile.c
ViewVC logotype

Diff of /code/trunk/pcre_compile.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 332 by ph10, Sat Mar 8 19:38:30 2008 UTC revision 333 by ph10, Thu Apr 10 19:55:57 2008 UTC
# Line 295  static const char error_texts[] = Line 295  static const char error_texts[] =
295    /* 55 */    /* 55 */
296    "repeating a DEFINE group is not allowed\0"    "repeating a DEFINE group is not allowed\0"
297    "inconsistent NEWLINE options\0"    "inconsistent NEWLINE options\0"
298    "\\g is not followed by a braced name or an optionally braced non-zero number\0"    "\\g is not followed by a braced, angle-bracketed, or quoted name/number or by a plain number\0"
299    "(?+ or (?- or (?(+ or (?(- must be followed by a non-zero number\0"    "a numbered reference must not be zero\0"
300    "(*VERB) with an argument is not supported\0"    "(*VERB) with an argument is not supported\0"
301    /* 60 */    /* 60 */
302    "(*VERB) not recognized\0"    "(*VERB) not recognized\0"
# Line 531  else Line 531  else
531      *errorcodeptr = ERR37;      *errorcodeptr = ERR37;
532      break;      break;
533    
534      /* \g must be followed by a number, either plain or braced. If positive, it      /* \g must be followed by one of a number of specific things:
535      is an absolute backreference. If negative, it is a relative backreference.  
536      This is a Perl 5.10 feature. Perl 5.10 also supports \g{name} as a      (1) A number, either plain or braced. If positive, it is an absolute
537      reference to a named group. This is part of Perl's movement towards a      backreference. If negative, it is a relative backreference. This is a Perl
538      unified syntax for back references. As this is synonymous with \k{name}, we      5.10 feature.
539      fudge it up by pretending it really was \k. */  
540        (2) Perl 5.10 also supports \g{name} as a reference to a named group. This
541        is part of Perl's movement towards a unified syntax for back references. As
542        this is synonymous with \k{name}, we fudge it up by pretending it really
543        was \k.
544    
545        (3) For Oniguruma compatibility we also support \g followed by a name or a
546        number either in angle brackets or in single quotes. However, these are
547        (possibly recursive) subroutine calls, _not_ backreferences. Just return
548        the -ESC_g code (cf \k). */
549    
550      case 'g':      case 'g':
551        if (ptr[1] == '<' || ptr[1] == '\'')
552          {
553          c = -ESC_g;
554          break;
555          }
556    
557        /* Handle the Perl-compatible cases */
558    
559      if (ptr[1] == '{')      if (ptr[1] == '{')
560        {        {
561        const uschar *p;        const uschar *p;
# Line 565  else Line 582  else
582      while ((digitab[ptr[1]] & ctype_digit) != 0)      while ((digitab[ptr[1]] & ctype_digit) != 0)
583        c = c * 10 + *(++ptr) - '0';        c = c * 10 + *(++ptr) - '0';
584    
585      if (c < 0)      if (c < 0)   /* Integer overflow */
586        {        {
587        *errorcodeptr = ERR61;        *errorcodeptr = ERR61;
588        break;        break;
589        }        }
590    
591      if (c == 0 || (braced && *(++ptr) != '}'))      if (braced && *(++ptr) != '}')
592        {        {
593        *errorcodeptr = ERR57;        *errorcodeptr = ERR57;
594        break;        break;
595        }        }
596    
597        if (c == 0)
598          {
599          *errorcodeptr = ERR58;
600          break;
601          }
602    
603      if (negated)      if (negated)
604        {        {
# Line 611  else Line 634  else
634        c -= '0';        c -= '0';
635        while ((digitab[ptr[1]] & ctype_digit) != 0)        while ((digitab[ptr[1]] & ctype_digit) != 0)
636          c = c * 10 + *(++ptr) - '0';          c = c * 10 + *(++ptr) - '0';
637        if (c < 0)        if (c < 0)    /* Integer overflow */
638          {          {
639          *errorcodeptr = ERR61;          *errorcodeptr = ERR61;
640          break;          break;
# Line 4567  we set the flag only if there is a liter Line 4590  we set the flag only if there is a liter
4590          references (?P=name) and recursion (?P>name), as well as falling          references (?P=name) and recursion (?P>name), as well as falling
4591          through from the Perl recursion syntax (?&name). We also come here from          through from the Perl recursion syntax (?&name). We also come here from
4592          the Perl \k<name> or \k'name' back reference syntax and the \k{name}          the Perl \k<name> or \k'name' back reference syntax and the \k{name}
4593          .NET syntax. */          .NET syntax, and the Oniguruma \g<...> and \g'...' subroutine syntax. */
4594    
4595          NAMED_REF_OR_RECURSE:          NAMED_REF_OR_RECURSE:
4596          name = ++ptr;          name = ++ptr;
# Line 4645  we set the flag only if there is a liter Line 4668  we set the flag only if there is a liter
4668          case '5': case '6': case '7': case '8': case '9':   /* subroutine */          case '5': case '6': case '7': case '8': case '9':   /* subroutine */
4669            {            {
4670            const uschar *called;            const uschar *called;
4671              terminator = ')';
4672    
4673              /* Come here from the \g<...> and \g'...' code (Oniguruma
4674              compatibility). However, the syntax has been checked to ensure that
4675              the ... are a (signed) number, so that neither ERR63 nor ERR29 will
4676              be called on this path, nor with the jump to OTHER_CHAR_AFTER_QUERY
4677              ever be taken. */
4678    
4679              HANDLE_NUMERICAL_RECURSION:
4680    
4681            if ((refsign = *ptr) == '+')            if ((refsign = *ptr) == '+')
4682              {              {
# Line 4666  we set the flag only if there is a liter Line 4698  we set the flag only if there is a liter
4698            while((digitab[*ptr] & ctype_digit) != 0)            while((digitab[*ptr] & ctype_digit) != 0)
4699              recno = recno * 10 + *ptr++ - '0';              recno = recno * 10 + *ptr++ - '0';
4700    
4701            if (*ptr != ')')            if (*ptr != terminator)
4702              {              {
4703              *errorcodeptr = ERR29;              *errorcodeptr = ERR29;
4704              goto FAILED;              goto FAILED;
# Line 5062  we set the flag only if there is a liter Line 5094  we set the flag only if there is a liter
5094      back references and those types that consume a character may be repeated.      back references and those types that consume a character may be repeated.
5095      We can test for values between ESC_b and ESC_Z for the latter; this may      We can test for values between ESC_b and ESC_Z for the latter; this may
5096      have to change if any new ones are ever created. */      have to change if any new ones are ever created. */
5097    
5098      case '\\':      case '\\':
5099      tempptr = ptr;      tempptr = ptr;
5100      c = check_escape(&ptr, errorcodeptr, cd->bracount, options, FALSE);      c = check_escape(&ptr, errorcodeptr, cd->bracount, options, FALSE);
# Line 5089  we set the flag only if there is a liter Line 5121  we set the flag only if there is a liter
5121    
5122        zerofirstbyte = firstbyte;        zerofirstbyte = firstbyte;
5123        zeroreqbyte = reqbyte;        zeroreqbyte = reqbyte;
5124    
5125          /* \g<name> or \g'name' is a subroutine call by name and \g<n> or \g'n'
5126          is a subroutine call by number (Oniguruma syntax). In fact, the value
5127          -ESC_g is returned only for these cases. So we don't need to check for <
5128          or ' if the value is -ESC_g. For the Perl syntax \g{n} the value is
5129          -ESC_REF+n, and for the Perl syntax \g{name} the result is -ESC_k (as
5130          that is a synonym). */
5131    
5132          if (-c == ESC_g)
5133            {
5134            const uschar *p;
5135            terminator = (*(++ptr) == '<')? '>' : '\'';
5136    
5137            /* These two statements stop the compiler for warning about possibly
5138            unset variables caused by the jump to HANDLE_NUMERICAL_RECURSION. In
5139            fact, because we actually check for a number below, the paths that
5140            would actually be in error are never taken. */
5141    
5142            skipbytes = 0;
5143            reset_bracount = FALSE;
5144    
5145            /* Test for a name */
5146    
5147            if (ptr[1] != '+' && ptr[1] != '-')
5148              {
5149              BOOL isnumber = TRUE;
5150              for (p = ptr + 1; *p != 0 && *p != terminator; p++)
5151                {
5152                if ((cd->ctypes[*p] & ctype_digit) == 0) isnumber = FALSE;
5153                if ((cd->ctypes[*p] & ctype_word) == 0) break;
5154                }
5155              if (*p != terminator)
5156                {
5157                *errorcodeptr = ERR57;
5158                break;
5159                }
5160              if (isnumber)
5161                {
5162                ptr++;
5163                goto HANDLE_NUMERICAL_RECURSION;
5164                }
5165              is_recurse = TRUE;
5166              goto NAMED_REF_OR_RECURSE;
5167              }
5168    
5169            /* Test a signed number in angle brackets or quotes. */
5170    
5171            p = ptr + 2;
5172            while ((digitab[*p] & ctype_digit) != 0) p++;
5173            if (*p != terminator)
5174              {
5175              *errorcodeptr = ERR57;
5176              break;
5177              }
5178            ptr++;
5179            goto HANDLE_NUMERICAL_RECURSION;
5180            }
5181    
5182        /* \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).
5183        We also support \k{name} (.NET syntax) */        We also support \k{name} (.NET syntax) */

Legend:
Removed from v.332  
changed lines
  Added in v.333

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12