From f7c436c1c8538b9b593f7d7040bcbee2b0ad79d0 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 27 Aug 2000 17:44:59 +0000 Subject: [PATCH] (back_comment): Detect cases where a comment-starter is actually inside another comment as in: /* a // b */ c // d \n. Make it clear that `comstart_pos' is unused for nested comments. --- src/ChangeLog | 18 ++++++++++++++++++ src/syntax.c | 43 +++++++++++++++++++++++++++---------------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6b847d3f35d..b9fcac51fc4 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,21 @@ +2000-08-27 Stefan Monnier + + * syntax.c (back_comment): Detect cases where a comment-starter is + actually inside another comment as in: /* a // b */ c // d \n. + Make it clear that `comstart_pos' is unused for nested comments. + + * keymap.c (store_in_keymap, fix_submap_inheritance): New prototypes. + (KEYMAPP): New macro. + (Fkeymap_parent, Fset_keymap_parent): Use it. + (fix_submap_inheritance): Mark it static. + (define_as_prefix, describe_buffer_bindings, describe_command) + (describe_translation, describe_map): Complete prototypes. + + * lisp.h (store_in_keymap, fix_submap_inheritance): Remove. + + * keyboard.c (menu_bar_item): Detect duplicate entries for all items + to better match the key-lookup behavior. + 2000-08-27 Gerd Moellmann * xfaces.c (lface_fully_specified_p): Handle :inherit. diff --git a/src/syntax.c b/src/syntax.c index 9e5247064ef..189e50d0963 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -469,12 +469,16 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p PARITY is current parity of quotes from the comment end. */ int string_style = -1; /* Presumed outside of any string. */ int string_lossage = 0; + /* Not a real lossage: indicates that we have passed a matching comment + starter plus an non-matching comment-ender, meaning that any matching + comment-starter we might see later could be a false positive (hidden + inside another comment). + Test case: { a (* b } c (* d *) */ + int comment_lossage = 0; int comment_end = from; int comment_end_byte = from_byte; int comstart_pos = 0; int comstart_byte; - /* Value that PARITY had, when we reached the position - in COMSTART_POS. */ int scanstart = from - 1; /* Place where the containing defun starts, or 0 if we didn't come across it yet. */ @@ -548,23 +552,24 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p case Scomment: /* We've already checked that it is the relevant comstyle. */ - if (string_style != -1 || string_lossage) + if (string_style != -1 || comment_lossage || string_lossage) /* There are odd string quotes involved, so let's be careful. Test case in Pascal: " { " a { " } */ goto lossage; - if (comnested && --nesting <= 0) + if (!comnested) + { + /* Record best comment-starter so far. */ + comstart_pos = from; + comstart_byte = from_byte; + } + else if (--nesting <= 0) /* nested comments have to be balanced, so we don't need to keep looking for earlier ones. We use here the same (slightly incorrect) reasoning as below: since it is followed by uniform paired string quotes, this comment-start has to be outside of strings, else the comment-end itself would be inside a string. */ goto done; - - /* Record comment-starters according to that - quote-parity to the comment-end. */ - comstart_pos = from; - comstart_byte = from_byte; break; case Sendcomment: @@ -578,6 +583,15 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p this comment-ender rather than ours. */ from = stop; /* Break out of the loop. */ } + else if (comstart_pos != 0 || c != '\n') + /* We're mixing comment styles here, so we'd better be careful. + The (comstart_pos != 0 || c != '\n') check is not quite correct + (we should just always set comment_lossage), but removing it + would imply that any multiline comment in C would go through + lossage, which seems overkill. + The failure should only happen in the rare cases such as + { (* } *) */ + comment_lossage = 1; break; case Sopen: @@ -594,7 +608,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p break; default: - continue; + break; } } @@ -604,12 +618,9 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p from_byte = comment_end_byte; UPDATE_SYNTAX_TABLE_FORWARD (comment_end - 1); } - /* If the earliest comment starter - is followed by uniform paired string quotes or none, - we know it can't be inside a string - since if it were then the comment ender would be inside one. - So it does start a comment. Skip back to it. */ - else if (!comnested) + /* If comstart_pos is set and we get here (ie. didn't jump to `lossage' + or `done'), then we've found the beginning of the non-nested comment. */ + else if (1) /* !comnested */ { from = comstart_pos; from_byte = comstart_byte; -- 2.39.2