/[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 333 by ph10, Thu Apr 10 19:55:57 2008 UTC revision 335 by ph10, Sat Apr 12 14:36:14 2008 UTC
# Line 1567  for (code = first_significant_code(code Line 1567  for (code = first_significant_code(code
1567    
1568    /* Groups with zero repeats can of course be empty; skip them. */    /* Groups with zero repeats can of course be empty; skip them. */
1569    
1570    if (c == OP_BRAZERO || c == OP_BRAMINZERO)    if (c == OP_BRAZERO || c == OP_BRAMINZERO || c == OP_SKIPZERO)
1571      {      {
1572      code += _pcre_OP_lengths[c];      code += _pcre_OP_lengths[c];
1573      do code += GET(code, 1); while (*code == OP_ALT);      do code += GET(code, 1); while (*code == OP_ALT);
# Line 1847  return -1; Line 1847  return -1;
1847  that is referenced. This means that groups can be replicated for fixed  that is referenced. This means that groups can be replicated for fixed
1848  repetition simply by copying (because the recursion is allowed to refer to  repetition simply by copying (because the recursion is allowed to refer to
1849  earlier groups that are outside the current group). However, when a group is  earlier groups that are outside the current group). However, when a group is
1850  optional (i.e. the minimum quantifier is zero), OP_BRAZERO is inserted before  optional (i.e. the minimum quantifier is zero), OP_BRAZERO or OP_SKIPZERO is
1851  it, after it has been compiled. This means that any OP_RECURSE items within it  inserted before it, after it has been compiled. This means that any OP_RECURSE
1852  that refer to the group itself or any contained groups have to have their  items within it that refer to the group itself or any contained groups have to
1853  offsets adjusted. That one of the jobs of this function. Before it is called,  have their offsets adjusted. That one of the jobs of this function. Before it
1854  the partially compiled regex must be temporarily terminated with OP_END.  is called, the partially compiled regex must be temporarily terminated with
1855    OP_END.
1856    
1857  This function has been extended with the possibility of forward references for  This function has been extended with the possibility of forward references for
1858  recursions and subroutine calls. It must also check the list of such references  recursions and subroutine calls. It must also check the list of such references
# Line 1882  while ((ptr = (uschar *)find_recurse(ptr Line 1883  while ((ptr = (uschar *)find_recurse(ptr
1883    
1884    /* See if this recursion is on the forward reference list. If so, adjust the    /* See if this recursion is on the forward reference list. If so, adjust the
1885    reference. */    reference. */
1886    
1887    for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)    for (hc = save_hwm; hc < cd->hwm; hc += LINK_SIZE)
1888      {      {
1889      offset = GET(hc, 0);      offset = GET(hc, 0);
# Line 2458  for (;; ptr++) Line 2459  for (;; ptr++)
2459    /* Get next byte in the pattern */    /* Get next byte in the pattern */
2460    
2461    c = *ptr;    c = *ptr;
2462    
2463    /* If we are in the pre-compile phase, accumulate the length used for the    /* If we are in the pre-compile phase, accumulate the length used for the
2464    previous cycle of this loop. */    previous cycle of this loop. */
2465    
# Line 3842  we set the flag only if there is a liter Line 3843  we set the flag only if there is a liter
3843    
3844        if (repeat_min == 0)        if (repeat_min == 0)
3845          {          {
3846          /* If the maximum is also zero, we just omit the group from the output          /* If the maximum is also zero, we used to just omit the group from the
3847          altogether. */          output altogether, like this:
   
         if (repeat_max == 0)  
           {  
           code = previous;  
           goto END_REPEAT;  
           }  
3848    
3849          /* If the maximum is 1 or unlimited, we just have to stick in the          ** if (repeat_max == 0)
3850          BRAZERO and do no more at this point. However, we do need to adjust          **   {
3851          any OP_RECURSE calls inside the group that refer to the group itself or          **   code = previous;
3852          any internal or forward referenced group, because the offset is from          **   goto END_REPEAT;
3853          the start of the whole regex. Temporarily terminate the pattern while          **   }
3854          doing this. */  
3855            However, that fails when a group is referenced as a subroutine from
3856            elsewhere in the pattern, so now we stick in OP_SKIPZERO in front of it
3857            so that it is skipped on execution. As we don't have a list of which
3858            groups are referenced, we cannot do this selectively.
3859    
3860            If the maximum is 1 or unlimited, we just have to stick in the BRAZERO
3861            and do no more at this point. However, we do need to adjust any
3862            OP_RECURSE calls inside the group that refer to the group itself or any
3863            internal or forward referenced group, because the offset is from the
3864            start of the whole regex. Temporarily terminate the pattern while doing
3865            this. */
3866    
3867          if (repeat_max <= 1)          if (repeat_max <= 1)    /* Covers 0, 1, and unlimited */
3868            {            {
3869            *code = OP_END;            *code = OP_END;
3870            adjust_recurse(previous, 1, utf8, cd, save_hwm);            adjust_recurse(previous, 1, utf8, cd, save_hwm);
3871            memmove(previous+1, previous, len);            memmove(previous+1, previous, len);
3872            code++;            code++;
3873              if (repeat_max == 0)
3874                {
3875                *previous++ = OP_SKIPZERO;
3876                goto END_REPEAT;
3877                }
3878            *previous++ = OP_BRAZERO + repeat_type;            *previous++ = OP_BRAZERO + repeat_type;
3879            }            }
3880    
# Line 4138  we set the flag only if there is a liter Line 4149  we set the flag only if there is a liter
4149      bravalue = OP_CBRA;      bravalue = OP_CBRA;
4150      save_hwm = cd->hwm;      save_hwm = cd->hwm;
4151      reset_bracount = FALSE;      reset_bracount = FALSE;
4152    
4153      /* First deal with various "verbs" that can be introduced by '*'. */      /* First deal with various "verbs" that can be introduced by '*'. */
4154    
4155      if (*(++ptr) == '*' && (cd->ctypes[ptr[1]] & ctype_letter) != 0)      if (*(++ptr) == '*' && (cd->ctypes[ptr[1]] & ctype_letter) != 0)
# Line 5127  we set the flag only if there is a liter Line 5138  we set the flag only if there is a liter
5138        -ESC_g is returned only for these cases. So we don't need to check for <        -ESC_g is returned only for these cases. So we don't need to check for <
5139        or ' if the value is -ESC_g. For the Perl syntax \g{n} the value is        or ' if the value is -ESC_g. For the Perl syntax \g{n} the value is
5140        -ESC_REF+n, and for the Perl syntax \g{name} the result is -ESC_k (as        -ESC_REF+n, and for the Perl syntax \g{name} the result is -ESC_k (as
5141        that is a synonym). */        that is a synonym for a named back reference). */
5142    
5143        if (-c == ESC_g)        if (-c == ESC_g)
5144          {          {
5145          const uschar *p;          const uschar *p;
5146            save_hwm = cd->hwm;   /* Normally this is set when '(' is read */
5147          terminator = (*(++ptr) == '<')? '>' : '\'';          terminator = (*(++ptr) == '<')? '>' : '\'';
5148    
5149          /* These two statements stop the compiler for warning about possibly          /* These two statements stop the compiler for warning about possibly
# Line 6197  while (errorcode == 0 && cd->hwm > cwork Line 6209  while (errorcode == 0 && cd->hwm > cwork
6209    if (groupptr == NULL) errorcode = ERR53;    if (groupptr == NULL) errorcode = ERR53;
6210      else PUT(((uschar *)codestart), offset, groupptr - codestart);      else PUT(((uschar *)codestart), offset, groupptr - codestart);
6211    }    }
6212    
6213  /* Give an error if there's back reference to a non-existent capturing  /* Give an error if there's back reference to a non-existent capturing
6214  subpattern. */  subpattern. */
6215    

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

  ViewVC Help
Powered by ViewVC 1.1.5