Mercurial > emacs
comparison src/syntax.c @ 32086:73d18e25e303
(forw_comment): Match nestedness of ender/starter.
(Fforward_comment): Treat an unmatched \n comment-ender as whitespace.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 02 Oct 2000 21:59:00 +0000 |
parents | 05763e780521 |
children | 83ecc6bc4bc2 |
comparison
equal
deleted
inserted
replaced
32085:56bb657c0878 | 32086:73d18e25e303 |
---|---|
1694 c = FETCH_CHAR (from_byte); | 1694 c = FETCH_CHAR (from_byte); |
1695 syntax = SYNTAX_WITH_FLAGS (c); | 1695 syntax = SYNTAX_WITH_FLAGS (c); |
1696 code = syntax & 0xff; | 1696 code = syntax & 0xff; |
1697 if (code == Sendcomment | 1697 if (code == Sendcomment |
1698 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style | 1698 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style |
1699 && --nesting <= 0) | 1699 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ? |
1700 (nesting > 0 && --nesting == 0) : nesting < 0)) | |
1700 /* we have encountered a comment end of the same style | 1701 /* we have encountered a comment end of the same style |
1701 as the comment sequence which began this comment | 1702 as the comment sequence which began this comment |
1702 section */ | 1703 section */ |
1703 break; | 1704 break; |
1704 if (code == Scomment_fence | 1705 if (code == Scomment_fence |
1707 as the comment sequence which began this comment | 1708 as the comment sequence which began this comment |
1708 section. */ | 1709 section. */ |
1709 break; | 1710 break; |
1710 if (nesting > 0 | 1711 if (nesting > 0 |
1711 && code == Scomment | 1712 && code == Scomment |
1713 && SYNTAX_FLAGS_COMMENT_NESTED (syntax) | |
1712 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style) | 1714 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style) |
1713 /* we have encountered a nested comment of the same style | 1715 /* we have encountered a nested comment of the same style |
1714 as the comment sequence which began this comment section */ | 1716 as the comment sequence which began this comment section */ |
1715 nesting++; | 1717 nesting++; |
1716 INC_BOTH (from, from_byte); | 1718 INC_BOTH (from, from_byte); |
1718 | 1720 |
1719 forw_incomment: | 1721 forw_incomment: |
1720 if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax) | 1722 if (from < stop && SYNTAX_FLAGS_COMEND_FIRST (syntax) |
1721 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style | 1723 && SYNTAX_FLAGS_COMMENT_STYLE (syntax) == style |
1722 && (c1 = FETCH_CHAR (from_byte), | 1724 && (c1 = FETCH_CHAR (from_byte), |
1723 SYNTAX_COMEND_SECOND (c1))) | 1725 SYNTAX_COMEND_SECOND (c1)) |
1726 && ((SYNTAX_FLAGS_COMMENT_NESTED (syntax) || | |
1727 SYNTAX_COMMENT_NESTED (c1)) ? nesting > 0 : nesting < 0)) | |
1724 { | 1728 { |
1725 if (--nesting <= 0) | 1729 if (--nesting <= 0) |
1726 /* we have encountered a comment end of the same style | 1730 /* we have encountered a comment end of the same style |
1727 as the comment sequence which began this comment | 1731 as the comment sequence which began this comment |
1728 section */ | 1732 section */ |
1736 if (nesting > 0 | 1740 if (nesting > 0 |
1737 && from < stop | 1741 && from < stop |
1738 && SYNTAX_FLAGS_COMSTART_FIRST (syntax) | 1742 && SYNTAX_FLAGS_COMSTART_FIRST (syntax) |
1739 && (c1 = FETCH_CHAR (from_byte), | 1743 && (c1 = FETCH_CHAR (from_byte), |
1740 SYNTAX_COMMENT_STYLE (c1) == style | 1744 SYNTAX_COMMENT_STYLE (c1) == style |
1741 && SYNTAX_COMSTART_SECOND (c1))) | 1745 && SYNTAX_COMSTART_SECOND (c1)) |
1746 && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) || | |
1747 SYNTAX_COMMENT_NESTED (c1))) | |
1742 /* we have encountered a nested comment of the same style | 1748 /* we have encountered a nested comment of the same style |
1743 as the comment sequence which began this comment | 1749 as the comment sequence which began this comment |
1744 section */ | 1750 section */ |
1745 { | 1751 { |
1746 INC_BOTH (from, from_byte); | 1752 INC_BOTH (from, from_byte); |
1817 comstyle = SYNTAX_COMMENT_STYLE (c1); | 1823 comstyle = SYNTAX_COMMENT_STYLE (c1); |
1818 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); | 1824 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); |
1819 INC_BOTH (from, from_byte); | 1825 INC_BOTH (from, from_byte); |
1820 UPDATE_SYNTAX_TABLE_FORWARD (from); | 1826 UPDATE_SYNTAX_TABLE_FORWARD (from); |
1821 } | 1827 } |
1822 /* FIXME: here we ignore 2-char endcomments while we don't | 1828 } |
1823 when going backwards. */ | 1829 while (code == Swhitespace || (code == Sendcomment && c == '\n')); |
1824 } | |
1825 while (code == Swhitespace || code == Sendcomment); | |
1826 | 1830 |
1827 if (code == Scomment_fence) | 1831 if (code == Scomment_fence) |
1828 comstyle = ST_COMMENT_STYLE; | 1832 comstyle = ST_COMMENT_STYLE; |
1829 else if (code != Scomment) | 1833 else if (code != Scomment) |
1830 { | 1834 { |
1874 code = SYNTAX (c); | 1878 code = SYNTAX (c); |
1875 comstyle = 0; | 1879 comstyle = 0; |
1876 comnested = SYNTAX_COMMENT_NESTED (c); | 1880 comnested = SYNTAX_COMMENT_NESTED (c); |
1877 if (code == Sendcomment) | 1881 if (code == Sendcomment) |
1878 comstyle = SYNTAX_COMMENT_STYLE (c); | 1882 comstyle = SYNTAX_COMMENT_STYLE (c); |
1879 comstart_second = SYNTAX_COMSTART_SECOND (c); | |
1880 if (from > stop && SYNTAX_COMEND_SECOND (c) | 1883 if (from > stop && SYNTAX_COMEND_SECOND (c) |
1881 && prev_char_comend_first (from, from_byte) | 1884 && prev_char_comend_first (from, from_byte) |
1882 && !char_quoted (from - 1, dec_bytepos (from_byte))) | 1885 && !char_quoted (from - 1, dec_bytepos (from_byte))) |
1883 { | 1886 { |
1884 /* We must record the comment style encountered so that | 1887 /* We must record the comment style encountered so that |
1889 /* Calling char_quoted, above, set up global syntax position | 1892 /* Calling char_quoted, above, set up global syntax position |
1890 at the new value of FROM. */ | 1893 at the new value of FROM. */ |
1891 c1 = FETCH_CHAR (from_byte); | 1894 c1 = FETCH_CHAR (from_byte); |
1892 comstyle = SYNTAX_COMMENT_STYLE (c1); | 1895 comstyle = SYNTAX_COMMENT_STYLE (c1); |
1893 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); | 1896 comnested = comnested || SYNTAX_COMMENT_NESTED (c1); |
1894 } | |
1895 if (from > stop && comstart_second | |
1896 && prev_char_comstart_first (from, from_byte) | |
1897 && !char_quoted (from - 1, dec_bytepos (from_byte))) | |
1898 { | |
1899 code = Scomment; | |
1900 DEC_BOTH (from, from_byte); | |
1901 } | 1897 } |
1902 | 1898 |
1903 if (code == Scomment_fence) | 1899 if (code == Scomment_fence) |
1904 { | 1900 { |
1905 /* Skip until first preceding unquoted comment_fence. */ | 1901 /* Skip until first preceding unquoted comment_fence. */ |
1930 { | 1926 { |
1931 found = back_comment (from, from_byte, stop, comnested, comstyle, | 1927 found = back_comment (from, from_byte, stop, comnested, comstyle, |
1932 &out_charpos, &out_bytepos); | 1928 &out_charpos, &out_bytepos); |
1933 if (found == -1) | 1929 if (found == -1) |
1934 { | 1930 { |
1935 #if 0 /* cc-mode (and maybe others) relies on the bogus behavior. */ | 1931 if (c == '\n') |
1936 /* Failure: we should go back to the end of this | 1932 /* This end-of-line is not an end-of-comment. |
1937 not-quite-endcomment. */ | 1933 Treat it like a whitespace. |
1938 if (SYNTAX(c) != code) | 1934 CC-mode (and maybe others) relies on this behavior. */ |
1939 /* It was a two-char Sendcomment. */ | 1935 ; |
1940 INC_BOTH (from, from_byte); | 1936 else |
1941 goto leave; | 1937 { |
1942 #endif | 1938 /* Failure: we should go back to the end of this |
1939 not-quite-endcomment. */ | |
1940 if (SYNTAX(c) != code) | |
1941 /* It was a two-char Sendcomment. */ | |
1942 INC_BOTH (from, from_byte); | |
1943 goto leave; | |
1944 } | |
1943 } | 1945 } |
1944 else | 1946 else |
1945 /* We have skipped one comment. */ | 1947 { |
1946 from = out_charpos, from_byte = out_bytepos; | 1948 /* We have skipped one comment. */ |
1947 break; | 1949 from = out_charpos, from_byte = out_bytepos; |
1950 break; | |
1951 } | |
1948 } | 1952 } |
1949 else if (code != Swhitespace && code != Scomment) | 1953 else if (code != Swhitespace) |
1950 { | 1954 { |
1951 leave: | 1955 leave: |
1952 immediate_quit = 0; | 1956 immediate_quit = 0; |
1953 INC_BOTH (from, from_byte); | 1957 INC_BOTH (from, from_byte); |
1954 SET_PT_BOTH (from, from_byte); | 1958 SET_PT_BOTH (from, from_byte); |