Mercurial > emacs
comparison src/syntax.c @ 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 | b1afaefff576 |
children | 73926d5a4d9f |
comparison
equal
deleted
inserted
replaced
27697:409a708c27b3 | 27698:9c61956399b2 |
---|---|
506 if (SYNTAX_COMSTART_SECOND (FETCH_CHAR (temp_byte)) | 506 if (SYNTAX_COMSTART_SECOND (FETCH_CHAR (temp_byte)) |
507 && comstyle == SYNTAX_COMMENT_STYLE (FETCH_CHAR (temp_byte))) | 507 && comstyle == SYNTAX_COMMENT_STYLE (FETCH_CHAR (temp_byte))) |
508 code = Scomment; | 508 code = Scomment; |
509 UPDATE_SYNTAX_TABLE_BACKWARD (from); | 509 UPDATE_SYNTAX_TABLE_BACKWARD (from); |
510 } | 510 } |
511 else if (code == Scomment && comstyle != SYNTAX_COMMENT_STYLE (c)) | |
512 /* Ignore comment starters of a different style. */ | |
513 continue; | |
511 | 514 |
512 /* Ignore escaped characters, except comment-enders. */ | 515 /* Ignore escaped characters, except comment-enders. */ |
513 if (code != Sendcomment && char_quoted (from, from_byte)) | 516 if (code != Sendcomment && char_quoted (from, from_byte)) |
514 continue; | 517 continue; |
515 | 518 |
537 ? ST_STRING_STYLE : ST_COMMENT_STYLE)) | 540 ? ST_STRING_STYLE : ST_COMMENT_STYLE)) |
538 string_lossage = 1; | 541 string_lossage = 1; |
539 } | 542 } |
540 | 543 |
541 if (code == Scomment) | 544 if (code == Scomment) |
542 /* FIXME: we should also check that the comstyle is correct | 545 /* We've already checked that it is the relevant comstyle. */ |
543 if the Scomment is a single-char. */ | |
544 { | 546 { |
545 if (comnested && --nesting <= 0 && parity == 0 && !string_lossage) | 547 if (comnested && --nesting <= 0 && parity == 0 && !string_lossage) |
546 /* nested comments have to be balanced, so we don't need to | 548 /* nested comments have to be balanced, so we don't need to |
547 keep looking for earlier ones. We use here the same (slightly | 549 keep looking for earlier ones. We use here the same (slightly |
548 incorrect) reasoning as below: since it is followed by uniform | 550 incorrect) reasoning as below: since it is followed by uniform |
632 | 634 |
633 done: | 635 done: |
634 *charpos_ptr = from; | 636 *charpos_ptr = from; |
635 *bytepos_ptr = from_byte; | 637 *bytepos_ptr = from_byte; |
636 | 638 |
637 return from; | 639 return (from == comment_end) ? -1 : from; |
638 } | 640 } |
639 | 641 |
640 DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0, | 642 DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0, |
641 "Return t if OBJECT is a syntax table.\n\ | 643 "Return t if OBJECT is a syntax table.\n\ |
642 Currently, any char-table counts as a syntax table.") | 644 Currently, any char-table counts as a syntax table.") |
1793 comstyle = SYNTAX_COMMENT_STYLE (c1); | 1795 comstyle = SYNTAX_COMMENT_STYLE (c1); |
1794 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); | 1796 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); |
1795 INC_BOTH (from, from_byte); | 1797 INC_BOTH (from, from_byte); |
1796 UPDATE_SYNTAX_TABLE_FORWARD (from); | 1798 UPDATE_SYNTAX_TABLE_FORWARD (from); |
1797 } | 1799 } |
1800 /* FIXME: here we ignore 2-char endcomments while we don't | |
1801 when going backwards. */ | |
1798 } | 1802 } |
1799 while (code == Swhitespace || code == Sendcomment); | 1803 while (code == Swhitespace || code == Sendcomment); |
1800 | 1804 |
1801 if (code == Scomment_fence) | 1805 if (code == Scomment_fence) |
1802 comstyle = ST_COMMENT_STYLE; | 1806 comstyle = ST_COMMENT_STYLE; |
1902 } | 1906 } |
1903 else if (code == Sendcomment) | 1907 else if (code == Sendcomment) |
1904 { | 1908 { |
1905 found = back_comment (from, from_byte, stop, comnested, comstyle, | 1909 found = back_comment (from, from_byte, stop, comnested, comstyle, |
1906 &out_charpos, &out_bytepos); | 1910 &out_charpos, &out_bytepos); |
1907 if (found != -1) | 1911 if (found == -1) |
1908 from = out_charpos, from_byte = out_bytepos; | 1912 { |
1913 /* Failure: we have to skip the one or two chars of the | |
1914 not-quite-endcomment. */ | |
1915 if (SYNTAX(c) != code) | |
1916 /* It was a two-char Sendcomment. */ | |
1917 INC_BOTH (from, from_byte); | |
1918 goto leave; | |
1919 } | |
1909 /* We have skipped one comment. */ | 1920 /* We have skipped one comment. */ |
1910 break; | 1921 from = out_charpos, from_byte = out_bytepos; |
1911 } | 1922 } |
1912 else if (code != Swhitespace && code != Scomment) | 1923 else if (code != Swhitespace && code != Scomment) |
1913 { | 1924 { |
1914 leave: | 1925 leave: |
1915 immediate_quit = 0; | 1926 immediate_quit = 0; |
2225 case Sendcomment: | 2236 case Sendcomment: |
2226 if (!parse_sexp_ignore_comments) | 2237 if (!parse_sexp_ignore_comments) |
2227 break; | 2238 break; |
2228 found = back_comment (from, from_byte, stop, comnested, comstyle, | 2239 found = back_comment (from, from_byte, stop, comnested, comstyle, |
2229 &out_charpos, &out_bytepos); | 2240 &out_charpos, &out_bytepos); |
2241 /* FIXME: if found == -1, then it really wasn't a comment-end. | |
2242 For single-char Sendcomment, we can't do much about it apart | |
2243 from skipping the char. | |
2244 For 2-char endcomments, we could try again, taking both | |
2245 chars as separate entities, but it's a lot of trouble | |
2246 for very little gain, so we don't bother either. -sm */ | |
2230 if (found != -1) | 2247 if (found != -1) |
2231 from = out_charpos, from_byte = out_bytepos; | 2248 from = out_charpos, from_byte = out_bytepos; |
2232 break; | 2249 break; |
2233 | 2250 |
2234 case Scomment_fence: | 2251 case Scomment_fence: |