]> code.delx.au - gnu-emacs/blobdiff - src/syntax.c
(archive-l-e): New optional argument `float' means generate a float value.
[gnu-emacs] / src / syntax.c
index 62612620f03fd5bde55a71185e0dcc8bee5a1737..1c8d0debbf32f307020d4736c18f549c8b18989a 100644 (file)
@@ -1,5 +1,6 @@
 /* GNU Emacs routines to deal with syntax tables; also word and list parsing.
-   Copyright (C) 1985, 87, 93, 94, 95, 97, 1998, 1999, 2004 Free Software Foundation, Inc.
+   Copyright (C) 1985, 1987, 1993, 1994, 1995, 1997, 1998, 1999, 2002,
+                 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -15,8 +16,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 
 #include <config.h>
@@ -132,7 +133,7 @@ update_syntax_table (charpos, count, init, object)
 {
   Lisp_Object tmp_table;
   int cnt = 0, invalidate = 1;
-  INTERVAL i, oldi;
+  INTERVAL i;
 
   if (init)
     {
@@ -163,7 +164,7 @@ update_syntax_table (charpos, count, init, object)
       gl_state.e_property = INTERVAL_LAST_POS (i) - gl_state.offset;
       goto update;
     }
-  oldi = i = count > 0 ? gl_state.forward_i : gl_state.backward_i;
+  i = count > 0 ? gl_state.forward_i : gl_state.backward_i;
 
   /* We are guaranteed to be called with CHARPOS either in i,
      or further off.  */
@@ -248,7 +249,8 @@ update_syntax_table (charpos, count, init, object)
            }
          else
            {
-             gl_state.b_property = i->position + LENGTH (i) - gl_state.offset;
+             gl_state.b_property
+               = i->position + LENGTH (i) - gl_state.offset;
              gl_state.backward_i = i;
            }
          return;
@@ -257,7 +259,12 @@ update_syntax_table (charpos, count, init, object)
        {
          if (count > 0)
            {
-             gl_state.e_property = i->position + LENGTH (i) - gl_state.offset;
+             gl_state.e_property
+               = i->position + LENGTH (i) - gl_state.offset
+               /* e_property at EOB is not set to ZV but to ZV+1, so that
+                  we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without
+                  having to check eob between the two.  */
+               + (NULL_INTERVAL_P (next_interval (i)) ? 1 : 0);
              gl_state.forward_i = i;
            }
          else
@@ -292,7 +299,7 @@ char_quoted (charpos, bytepos)
 
   DEC_BOTH (charpos, bytepos);
 
-  while (bytepos >= beg)
+  while (charpos >= beg)
     {
       int c;
 
@@ -673,7 +680,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
     {
       from = comstart_pos;
       from_byte = comstart_byte;
-      /* Globals are correct now.  */
+      UPDATE_SYNTAX_TABLE_FORWARD (from - 1);
     }
   else
     {
@@ -923,7 +930,7 @@ text property.  */)
   p = SDATA (string);
   code = (enum syntaxcode) syntax_spec_code[*p++];
   if (((int) code & 0377) == 0377)
-    error ("invalid syntax description letter: %c", p[-1]);
+    error ("Invalid syntax description letter: %c", p[-1]);
 
   if (code == Sinherit)
     return Qnil;
@@ -1295,6 +1302,7 @@ and the function returns nil.  Field boundaries are not noticed if
      (arg)
      Lisp_Object arg;
 {
+  Lisp_Object tmp;
   int orig_val, val;
 
   if (NILP (arg))
@@ -1307,8 +1315,9 @@ and the function returns nil.  Field boundaries are not noticed if
     val = XINT (arg) > 0 ? ZV : BEGV;
 
   /* Avoid jumping out of an input field.  */
-  val = XFASTINT (Fconstrain_to_field (make_number (val), make_number (PT),
-                                      Qt, Qnil, Qnil));
+  tmp = Fconstrain_to_field (make_number (val), make_number (PT),
+                            Qt, Qnil, Qnil);
+  val = XFASTINT (tmp);
 
   SET_PT (val);
   return val == orig_val ? Qt : Qnil;
@@ -1455,7 +1464,7 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes)
            {
              const unsigned char *class_beg = str + i_byte + 1;
              const unsigned char *class_end = class_beg;
-             const unsigned char *class_limit = str + size_byte;
+             const unsigned char *class_limit = str + size_byte - 2;
              /* Leave room for the null.        */
              unsigned char class_name[CHAR_CLASS_MAX_LENGTH + 1];
              re_wctype_t cc;
@@ -1463,17 +1472,13 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes)
              if (class_limit - class_beg > CHAR_CLASS_MAX_LENGTH)
                class_limit = class_beg + CHAR_CLASS_MAX_LENGTH;
 
-             while (class_end != class_limit
-                    && ! (*class_end >= 0200
-                          || *class_end <= 040
-                          || (*class_end == ':'
-                              && class_end[1] == ']')))
+             while (class_end < class_limit
+                    && *class_end >= 'a' && *class_end <= 'z')
                class_end++;
 
-             if (class_end == class_limit
-                 || *class_end >= 0200
-                 || *class_end <= 040)
-               error ("Invalid ISO C character class");
+             if (class_end == class_beg
+                 || *class_end != ':' || class_end[1] != ']')
+               goto not_a_class_name;
 
              bcopy (class_beg, class_name, class_end - class_beg);
              class_name[class_end - class_beg] = 0;
@@ -1488,6 +1493,7 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes)
              continue;
            }
 
+       not_a_class_name:
          if (c == '\\')
            {
              if (i_byte == size_byte)
@@ -1731,12 +1737,11 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes)
                      if (negate)
                        break;
                      else
-                       goto fwd_ok;
+                       goto fwd_unibyte_ok;
                    }
 
                  if (!fastmap[*p])
                    break;
-
                fwd_unibyte_ok:
                  p++, pos++;
                }
@@ -1805,12 +1810,11 @@ skip_chars (forwardp, syntaxp, string, lim, handle_iso_classes)
                      if (negate)
                        break;
                      else
-                       goto fwd_ok;
+                       goto back_unibyte_ok;
                    }
 
                  if (!fastmap[p[-1]])
                    break;
-
                back_unibyte_ok:
                  p--, pos--;
                }
@@ -2119,8 +2123,6 @@ between them, return t; otherwise return nil.  */)
              while (1)
                {
                  DEC_BOTH (from, from_byte);
-                 if (from == stop)
-                   break;
                  UPDATE_SYNTAX_TABLE_BACKWARD (from);
                  c = FETCH_CHAR (from_byte);
                  if (SYNTAX (c) == Scomment_fence
@@ -2129,6 +2131,8 @@ between them, return t; otherwise return nil.  */)
                      found = 1;
                      break;
                    }
+                 else if (from == stop)
+                   break;
                }
              if (found == 0)
                {
@@ -2136,6 +2140,9 @@ between them, return t; otherwise return nil.  */)
                  from_byte = ini_byte;
                  goto leave;
                }
+             else
+               /* We have skipped one comment.  */
+               break;
            }
          else if (code == Sendcomment)
            {
@@ -2804,12 +2811,23 @@ do { prev_from = from;                          \
       INC_FROM;
       code = prev_from_syntax & 0xff;
 
-      if (code == Scomment)
+      if (from < end
+         && SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax)
+         && (c1 = FETCH_CHAR (from_byte),
+             SYNTAX_COMSTART_SECOND (c1)))
+       /* Duplicate code to avoid a complex if-expression
+          which causes trouble for the SGI compiler.  */
        {
-         state.comstyle = SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax);
-         state.incomment = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax) ?
-                            1 : -1);
+         /* Record the comment style we have entered so that only
+            the comment-end sequence of the same style actually
+            terminates the comment section.  */
+         state.comstyle = SYNTAX_COMMENT_STYLE (c1);
+         comnested = SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax);
+         comnested = comnested || SYNTAX_COMMENT_NESTED (c1);
+         state.incomment = comnested ? 1 : -1;
          state.comstr_start = prev_from;
+         INC_FROM;
+         code = Scomment;
        }
       else if (code == Scomment_fence)
        {
@@ -2821,24 +2839,13 @@ do { prev_from = from;                          \
          state.comstr_start = prev_from;
          code = Scomment;
        }
-     else if (from < end)
-       if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax))
-         if (c1 = FETCH_CHAR (from_byte),
-             SYNTAX_COMSTART_SECOND (c1))
-           /* Duplicate code to avoid a complex if-expression
-              which causes trouble for the SGI compiler.  */
-           {
-             /* Record the comment style we have entered so that only
-                the comment-end sequence of the same style actually
-                terminates the comment section.  */
-             state.comstyle = SYNTAX_COMMENT_STYLE (c1);
-             comnested = SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax);
-             comnested = comnested || SYNTAX_COMMENT_NESTED (c1);
-             state.incomment = comnested ? 1 : -1;
-             state.comstr_start = prev_from;
-             INC_FROM;
-             code = Scomment;
-           }
+      else if (code == Scomment)
+       {
+         state.comstyle = SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax);
+         state.incomment = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax) ?
+                            1 : -1);
+         state.comstr_start = prev_from;
+       }
 
       if (SYNTAX_FLAGS_PREFIX (prev_from_syntax))
        continue;
@@ -3016,7 +3023,7 @@ Parsing stops at TO or when certain criteria are met;
  point is set to where parsing stops.
 If fifth arg OLDSTATE is omitted or nil,
  parsing assumes that FROM is the beginning of a function.
-Value is a list of ten elements describing final state of parsing:
+Value is a list of elements describing final state of parsing:
  0. depth in parens.
  1. character address of start of innermost containing list; nil if none.
  2. character address of start of last complete sexp terminated.
@@ -3035,7 +3042,7 @@ If third arg TARGETDEPTH is non-nil, parsing stops if the depth
 in parentheses becomes equal to TARGETDEPTH.
 Fourth arg STOPBEFORE non-nil means stop when come to
  any character that starts a sexp.
-Fifth arg OLDSTATE is a nine-element list like what this function returns.
+Fifth arg OLDSTATE is a list like what this function returns.
  It is used to initialize the state of the parse.  Elements number 1, 2, 6
  and 8 are ignored; you can leave off element 8 (the last) entirely.
 Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
@@ -3171,6 +3178,14 @@ syms_of_syntax ()
 
   staticpro (&Vsyntax_code_object);
 
+  staticpro (&gl_state.object);
+  staticpro (&gl_state.global_code);
+  staticpro (&gl_state.current_syntax_table);
+  staticpro (&gl_state.old_prop);
+
+  /* Defined in regex.c */
+  staticpro (&re_match_object);
+
   Qscan_error = intern ("scan-error");
   staticpro (&Qscan_error);
   Fput (Qscan_error, Qerror_conditions,