changeset 27698:9c61956399b2

(back_comment): Make sure we only consider comment-starters of the relevant style and return -1 in case of a failure to find the beginning of the comment. (Fforward_comment): If back_comment fails, go back to the position just after the comment-end. (scan_lists): Add comment describing a very minor bug.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 15 Feb 2000 06:21:26 +0000
parents 409a708c27b3
children 30ad7bc10779
files src/ChangeLog src/syntax.c
diffstat 2 files changed, 23 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
Binary file src/ChangeLog has changed
--- a/src/syntax.c	Mon Feb 14 23:36:15 2000 +0000
+++ b/src/syntax.c	Tue Feb 15 06:21:26 2000 +0000
@@ -508,6 +508,9 @@
 	    code = Scomment;
 	  UPDATE_SYNTAX_TABLE_BACKWARD (from);
 	}
+      else if (code == Scomment && comstyle != SYNTAX_COMMENT_STYLE (c))
+	/* Ignore comment starters of a different style.  */
+	continue;
 
       /* Ignore escaped characters, except comment-enders.  */
       if (code != Sendcomment && char_quoted (from, from_byte))
@@ -539,8 +542,7 @@
 	}
 
       if (code == Scomment)
-	/* FIXME: we should also check that the comstyle is correct
-	   if the Scomment is a single-char. */
+	/* We've already checked that it is the relevant comstyle.  */
 	{
 	  if (comnested && --nesting <= 0 && parity == 0 && !string_lossage)
 	    /* nested comments have to be balanced, so we don't need to
@@ -634,7 +636,7 @@
   *charpos_ptr = from;
   *bytepos_ptr = from_byte;
 
-  return from;
+  return (from == comment_end) ? -1 : from;
 }
 
 DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0,
@@ -1795,6 +1797,8 @@
 	      INC_BOTH (from, from_byte);
 	      UPDATE_SYNTAX_TABLE_FORWARD (from);
 	    }
+	  /* FIXME: here we ignore 2-char endcomments while we don't
+	     when going backwards.  */
 	}
       while (code == Swhitespace || code == Sendcomment);
 
@@ -1904,10 +1908,17 @@
 	    {
 	      found = back_comment (from, from_byte, stop, comnested, comstyle,
 				    &out_charpos, &out_bytepos);
-	      if (found != -1)
-		from = out_charpos, from_byte = out_bytepos;
+	      if (found == -1)
+		{
+		  /* Failure: we have to skip the one or two chars of the
+		     not-quite-endcomment.  */
+		  if (SYNTAX(c) != code)
+		    /* It was a two-char Sendcomment.  */
+		    INC_BOTH (from, from_byte);
+		  goto leave;
+		}
 	      /* We have skipped one comment.  */
-	      break;
+	      from = out_charpos, from_byte = out_bytepos;
 	    }
 	  else if (code != Swhitespace && code != Scomment)
 	    {
@@ -2227,6 +2238,12 @@
 		break;
 	      found = back_comment (from, from_byte, stop, comnested, comstyle,
 				    &out_charpos, &out_bytepos);
+	      /* FIXME:  if found == -1, then it really wasn't a comment-end.
+		 For single-char Sendcomment, we can't do much about it apart
+		 from skipping the char.
+		 For 2-char endcomments, we could try again, taking both
+		 chars as separate entities, but it's a lot of trouble
+		 for very little gain, so we don't bother either.  -sm */
 	      if (found != -1)
 		from = out_charpos, from_byte = out_bytepos;
 	      break;