changeset 16992:ff7346c31184

(scan_lists): Signal errors using scan-error. (syms_of_syntax): Set up Qscan_error.
author Richard M. Stallman <rms@gnu.org>
date Mon, 10 Feb 1997 09:47:12 +0000
parents b33fd17a2873
children 6a9b49bc5161
files src/syntax.c
diffstat 1 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/syntax.c	Mon Feb 10 09:46:16 1997 +0000
+++ b/src/syntax.c	Mon Feb 10 09:47:12 1997 +0000
@@ -26,7 +26,7 @@
 #include "buffer.h"
 #include "syntax.h"
 
-Lisp_Object Qsyntax_table_p, Qsyntax_table;
+Lisp_Object Qsyntax_table_p, Qsyntax_table, Qscan_error;
 
 static void scan_sexps_forward ();
 static int char_quoted ();
@@ -943,6 +943,7 @@
   register enum syntaxcode code;
   int min_depth = depth;    /* Err out if depth gets less than this. */
   int comstyle = 0;	    /* style of comment encountered */
+  int last_good = from;
 
   if (depth > 0) min_depth = 0;
 
@@ -956,6 +957,8 @@
 	{
 	  c = FETCH_CHAR (from);
 	  code = SYNTAX (c);
+	  if (depth == min_depth)
+	    last_good = from;
 	  from++;
 	  if (from < stop && SYNTAX_COMSTART_FIRST (c)
 	      && SYNTAX_COMSTART_SECOND (FETCH_CHAR (from))
@@ -1053,7 +1056,10 @@
 	    close1:
 	      if (!--depth) goto done;
 	      if (depth < min_depth)
-		error ("Containing expression ends prematurely");
+		Fsignal (Qscan_error,
+			 Fcons (build_string ("Containing expression ends prematurely"),
+				Fcons (make_number (last_good),
+				       Fcons (make_number (from), Qnil))));
 	      break;
 
 	    case Sstring:
@@ -1097,6 +1103,8 @@
 	    from--;
 	  c = FETCH_CHAR (from);
 	  code = SYNTAX (c);
+	  if (depth == min_depth)
+	    last_good = from;
 	  comstyle = 0;
 	  if (code == Sendcomment)
 	    comstyle = SYNTAX_COMMENT_STYLE (c);
@@ -1155,7 +1163,10 @@
 	    open2:
 	      if (!--depth) goto done2;
 	      if (depth < min_depth)
-		error ("Containing expression ends prematurely");
+		Fsignal (Qscan_error,
+			 Fcons (build_string ("Containing expression ends prematurely"),
+				Fcons (make_number (last_good),
+				       Fcons (make_number (from), Qnil))));
 	      break;
 
 	    case Sendcomment:
@@ -1331,7 +1342,11 @@
   return val;
 
  lose:
-  error ("Unbalanced parentheses");
+  Fsignal (Qscan_error,
+	   Fcons (build_string ("Unbalanced parentheses"),
+		  Fcons (make_number (last_good),
+			 Fcons (make_number (from), Qnil))));
+
   /* NOTREACHED */
 }
 
@@ -1796,6 +1811,13 @@
   Qsyntax_table_p = intern ("syntax-table-p");
   staticpro (&Qsyntax_table_p);
 
+  Qscan_error = intern ("scan-error");
+  staticpro (&Qscan_error);
+  Fput (Qscan_error, Qerror_conditions,
+	Fcons (Qerror, Qnil));
+  Fput (Qscan_error, Qerror_message,
+	build_string ("Scan error"));
+
   DEFVAR_BOOL ("parse-sexp-ignore-comments", &parse_sexp_ignore_comments,
     "Non-nil means `forward-sexp', etc., should treat comments as whitespace.");