/[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 335 by ph10, Sat Apr 12 14:36:14 2008 UTC revision 341 by ph10, Sat Apr 19 16:41:04 2008 UTC
# Line 302  static const char error_texts[] = Line 302  static const char error_texts[] =
302    "(*VERB) not recognized\0"    "(*VERB) not recognized\0"
303    "number is too big\0"    "number is too big\0"
304    "subpattern name expected\0"    "subpattern name expected\0"
305    "digit expected after (?+";    "digit expected after (?+\0"
306      "] is an invalid data character in JavaScript compatibility mode";
307    
308    
309  /* Table to identify digits and hex digits. This is used when compiling  /* Table to identify digits and hex digits. This is used when compiling
# Line 975  be terminated by '>' because that is che Line 976  be terminated by '>' because that is che
976    
977  Arguments:  Arguments:
978    ptr          current position in the pattern    ptr          current position in the pattern
979    count        current count of capturing parens so far encountered    cd           compile background data
980    name         name to seek, or NULL if seeking a numbered subpattern    name         name to seek, or NULL if seeking a numbered subpattern
981    lorn         name length, or subpattern number if name is NULL    lorn         name length, or subpattern number if name is NULL
982    xmode        TRUE if we are in /x mode    xmode        TRUE if we are in /x mode
# Line 984  Returns:       the number of the named s Line 985  Returns:       the number of the named s
985  */  */
986    
987  static int  static int
988  find_parens(const uschar *ptr, int count, const uschar *name, int lorn,  find_parens(const uschar *ptr, compile_data *cd, const uschar *name, int lorn,
989    BOOL xmode)    BOOL xmode)
990  {  {
991  const uschar *thisname;  const uschar *thisname;
992    int count = cd->bracount;
993    
994  for (; *ptr != 0; ptr++)  for (; *ptr != 0; ptr++)
995    {    {
# Line 1007  for (; *ptr != 0; ptr++) Line 1009  for (; *ptr != 0; ptr++)
1009      continue;      continue;
1010      }      }
1011    
1012    /* Skip over character classes */    /* Skip over character classes; this logic must be similar to the way they
1013      are handled for real. If the first character is '^', skip it. Also, if the
1014      first few characters (either before or after ^) are \Q\E or \E we skip them
1015      too. This makes for compatibility with Perl. */
1016    
1017    if (*ptr == '[')    if (*ptr == '[')
1018      {      {
1019        BOOL negate_class = FALSE;
1020        for (;;)
1021          {
1022          int c = *(++ptr);
1023          if (c == '\\')
1024            {
1025            if (ptr[1] == 'E') ptr++;
1026              else if (strncmp((const char *)ptr+1, "Q\\E", 3) == 0) ptr += 3;
1027                else break;
1028            }
1029          else if (!negate_class && c == '^')
1030            negate_class = TRUE;
1031          else break;
1032          }
1033    
1034        /* If the next character is ']', it is a data character that must be
1035        skipped, except in JavaScript compatibility mode. */
1036    
1037        if (ptr[1] == ']' && (cd->external_options & PCRE_JAVASCRIPT_COMPAT) == 0)
1038          ptr++;
1039    
1040      while (*(++ptr) != ']')      while (*(++ptr) != ']')
1041        {        {
1042        if (*ptr == 0) return -1;        if (*ptr == 0) return -1;
# Line 2654  for (;; ptr++) Line 2680  for (;; ptr++)
2680      opcode is compiled. It may optionally have a bit map for characters < 256,      opcode is compiled. It may optionally have a bit map for characters < 256,
2681      but those above are are explicitly listed afterwards. A flag byte tells      but those above are are explicitly listed afterwards. A flag byte tells
2682      whether the bitmap is present, and whether this is a negated class or not.      whether the bitmap is present, and whether this is a negated class or not.
2683      */  
2684        In JavaScript compatibility mode, an isolated ']' causes an error. In
2685        default (Perl) mode, it is treated as a data character. */
2686    
2687        case ']':
2688        if ((cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
2689          {
2690          *errorcodeptr = ERR64;
2691          goto FAILED;
2692          }
2693        goto NORMAL_CHAR;
2694    
2695      case '[':      case '[':
2696      previous = code;      previous = code;
# Line 2687  for (;; ptr++) Line 2723  for (;; ptr++)
2723          negate_class = TRUE;          negate_class = TRUE;
2724        else break;        else break;
2725        }        }
2726    
2727        /* Empty classes are allowed in JavaScript compatibility mode. Otherwise,
2728        an initial ']' is taken as a data character -- the code below handles
2729        that. In JS mode, [] must always fail, so generate OP_FAIL, whereas
2730        [^] must match any character, so generate OP_ALLANY. */
2731    
2732        if (c ==']' && (cd->external_options & PCRE_JAVASCRIPT_COMPAT) != 0)
2733          {
2734          *code++ = negate_class? OP_ALLANY : OP_FAIL;
2735          if (firstbyte == REQ_UNSET) firstbyte = REQ_NONE;
2736          zerofirstbyte = firstbyte;
2737          break;
2738          }
2739    
2740      /* If a class contains a negative special such as \S, we need to flip the      /* If a class contains a negative special such as \S, we need to flip the
2741      negation flag at the end, so that support for characters > 255 works      negation flag at the end, so that support for characters > 255 works
# Line 4068  we set the flag only if there is a liter Line 4117  we set the flag only if there is a liter
4117            }            }
4118          }          }
4119        }        }
4120    
4121        /* If previous is OP_FAIL, it was generated by an empty class [] in
4122        JavaScript mode. The other ways in which OP_FAIL can be generated, that is
4123        by (*FAIL) or (?!) set previous to NULL, which gives a "nothing to repeat"
4124        error above. We can just ignore the repeat in JS case. */
4125    
4126        else if (*previous == OP_FAIL) goto END_REPEAT;
4127    
4128      /* Else there's some kind of shambles */      /* Else there's some kind of shambles */
4129    
# Line 4355  we set the flag only if there is a liter Line 4411  we set the flag only if there is a liter
4411    
4412          /* Search the pattern for a forward reference */          /* Search the pattern for a forward reference */
4413    
4414          else if ((i = find_parens(ptr, cd->bracount, name, namelen,          else if ((i = find_parens(ptr, cd, name, namelen,
4415                          (options & PCRE_EXTENDED) != 0)) > 0)                          (options & PCRE_EXTENDED) != 0)) > 0)
4416            {            {
4417            PUT2(code, 2+LINK_SIZE, i);            PUT2(code, 2+LINK_SIZE, i);
# Line 4652  we set the flag only if there is a liter Line 4708  we set the flag only if there is a liter
4708              recno = GET2(slot, 0);              recno = GET2(slot, 0);
4709              }              }
4710            else if ((recno =                /* Forward back reference */            else if ((recno =                /* Forward back reference */
4711                      find_parens(ptr, cd->bracount, name, namelen,                      find_parens(ptr, cd, name, namelen,
4712                        (options & PCRE_EXTENDED) != 0)) <= 0)                        (options & PCRE_EXTENDED) != 0)) <= 0)
4713              {              {
4714              *errorcodeptr = ERR15;              *errorcodeptr = ERR15;
# Line 4762  we set the flag only if there is a liter Line 4818  we set the flag only if there is a liter
4818    
4819              if (called == NULL)              if (called == NULL)
4820                {                {
4821                if (find_parens(ptr, cd->bracount, NULL, recno,                if (find_parens(ptr, cd, NULL, recno,
4822                     (options & PCRE_EXTENDED) != 0) < 0)                      (options & PCRE_EXTENDED) != 0) < 0)
4823                  {                  {
4824                  *errorcodeptr = ERR15;                  *errorcodeptr = ERR15;
4825                  goto FAILED;                  goto FAILED;

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

  ViewVC Help
Powered by ViewVC 1.1.5