Commit 02010917 authored by Stefan Monnier's avatar Stefan Monnier

(back_comment): Use one switch rather than a few `if's.

Obey open_paren_in_column_0_is_defun_start.
When reverting to the `slow' method, try to nicely handle the case
of nested comments by checking that the comment-starter we found
does indeed match the comment-ender.
(scan_sexps_forward, scan_sexps_forward):
Ignore excessive opening parenthesis rather than throwing an error.
parent d76c03ea
2000-07-11 Stefan Monnier <monnier@cs.yale.edu>
* syntax.c (back_comment): Use one switch rather than a few `if's.
Obey open_paren_in_column_0_is_defun_start.
When reverting to the `slow' method, try to nicely handle the case
of nested comments by checking that the comment-starter we found
does indeed match the comment-ender.
(scan_sexps_forward, scan_sexps_forward):
Ignore excessive opening parenthesis rather than throwing an error.
2000-07-11 Gerd Moellmann <gerd@gnu.org> 2000-07-11 Gerd Moellmann <gerd@gnu.org>
* doc.c (Fsubstitute_command_keys): Handle case that a GC * doc.c (Fsubstitute_command_keys): Handle case that a GC
......
...@@ -527,7 +527,6 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p ...@@ -527,7 +527,6 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
if (code != Sendcomment && char_quoted (from, from_byte)) if (code != Sendcomment && char_quoted (from, from_byte))
continue; continue;
/* Track parity of quotes. */
switch (code) switch (code)
{ {
case Sstring_fence: case Sstring_fence:
...@@ -568,31 +567,33 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p ...@@ -568,31 +567,33 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
comstart_byte = from_byte; comstart_byte = from_byte;
break; break;
default: case Sendcomment:
; if (SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte)) == comstyle)
} /* This is the same style of comment ender as ours. */
{
/* If we find another earlier comment-ender, if (comnested)
any comment-starts earlier than that don't count nesting++;
(because they go with the earlier comment-ender). */ else
if (code == Sendcomment /* Anything before that can't count because it would match
&& SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte)) == comstyle) this comment-ender rather than ours. */
{ from = stop; /* Break out of the loop. */
if (comnested) }
nesting++; break;
else
break;
}
/* Assume a defun-start point is outside of strings. */ case Sopen:
if (code == Sopen /* Assume a defun-start point is outside of strings. */
&& (from == stop if (open_paren_in_column_0_is_defun_start
|| (temp_byte = dec_bytepos (from_byte), && (from == stop
FETCH_CHAR (temp_byte) == '\n'))) || (temp_byte = dec_bytepos (from_byte),
{ FETCH_CHAR (temp_byte) == '\n')))
defun_start = from; {
defun_start_byte = from_byte; defun_start = from;
defun_start_byte = from_byte;
from = stop; /* Break out of the loop. */
}
break; break;
default:
} }
} }
...@@ -619,7 +620,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p ...@@ -619,7 +620,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
lossage: lossage:
/* We had two kinds of string delimiters mixed up /* We had two kinds of string delimiters mixed up
together. Decode this going forwards. together. Decode this going forwards.
Scan fwd from the previous comment ender Scan fwd from a known safe place (beginning-of-defun)
to the one in question; this records where we to the one in question; this records where we
last passed a comment starter. */ last passed a comment starter. */
/* If we did not already find the defun start, find it now. */ /* If we did not already find the defun start, find it now. */
...@@ -628,20 +629,30 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p ...@@ -628,20 +629,30 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
defun_start = find_defun_start (comment_end, comment_end_byte); defun_start = find_defun_start (comment_end, comment_end_byte);
defun_start_byte = find_start_value_byte; defun_start_byte = find_start_value_byte;
} }
scan_sexps_forward (&state, do
defun_start, defun_start_byte,
comment_end - 1, -10000, 0, Qnil, 0);
if (state.incomment)
{
/* scan_sexps_forward changed the direction of search in
global variables, so we need to update it completely. */
from = state.comstr_start;
}
else
{ {
from = comment_end; scan_sexps_forward (&state,
} defun_start, defun_start_byte,
comment_end, -10000, 0, Qnil, 0);
defun_start = comment_end;
if (state.incomment == (comnested ? 1 : -1)
&& state.comstyle == comstyle)
from = state.comstr_start;
else
{
from = comment_end;
if (state.incomment)
/* If comment_end is inside some other comment, maybe ours
is nested, so we need to try again from within the
surrounding comment. Example: { a (* " *) */
{
/* FIXME: We should advance by one or two chars. */
defun_start = state.comstr_start + 2;
defun_start_byte = CHAR_TO_BYTE (defun_start);
}
}
} while (defun_start < comment_end);
from_byte = CHAR_TO_BYTE (from); from_byte = CHAR_TO_BYTE (from);
UPDATE_SYNTAX_TABLE_FORWARD (from - 1); UPDATE_SYNTAX_TABLE_FORWARD (from - 1);
} }
...@@ -2525,7 +2536,7 @@ do { prev_from = from; \ ...@@ -2525,7 +2536,7 @@ do { prev_from = from; \
/* curlevel++->last ran into compiler bug on Apollo */ /* curlevel++->last ran into compiler bug on Apollo */
curlevel->last = XINT (Fcar (tem)); curlevel->last = XINT (Fcar (tem));
if (++curlevel == endlevel) if (++curlevel == endlevel)
error ("Nesting too deep for parser"); curlevel--; /* error ("Nesting too deep for parser"); */
curlevel->prev = -1; curlevel->prev = -1;
curlevel->last = -1; curlevel->last = -1;
tem = Fcdr (tem); tem = Fcdr (tem);
...@@ -2673,7 +2684,7 @@ do { prev_from = from; \ ...@@ -2673,7 +2684,7 @@ do { prev_from = from; \
/* curlevel++->last ran into compiler bug on Apollo */ /* curlevel++->last ran into compiler bug on Apollo */
curlevel->last = prev_from; curlevel->last = prev_from;
if (++curlevel == endlevel) if (++curlevel == endlevel)
error ("Nesting too deep for parser"); curlevel--; /* error ("Nesting too deep for parser"); */
curlevel->prev = -1; curlevel->prev = -1;
curlevel->last = -1; curlevel->last = -1;
if (targetdepth == depth) goto done; if (targetdepth == depth) goto done;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment