diff options
| author | Po Lu | 2023-05-10 08:51:27 +0800 |
|---|---|---|
| committer | Po Lu | 2023-05-10 08:51:27 +0800 |
| commit | 4fbaf6d9fe1923d03c971a970ad4d2eef075aef3 (patch) | |
| tree | 40fc3779e0de2c16d6ed0377bfc935ba48119881 /src | |
| parent | 1230521f7130a3ad8fe4033817f6d936675742c1 (diff) | |
| parent | 7791907c3852e6ec197352e1c3d3dd8487cc04f5 (diff) | |
| download | emacs-4fbaf6d9fe1923d03c971a970ad4d2eef075aef3.tar.gz emacs-4fbaf6d9fe1923d03c971a970ad4d2eef075aef3.zip | |
Merge remote-tracking branch 'origin/master' into feature/android
Diffstat (limited to 'src')
| -rw-r--r-- | src/regex-emacs.h | 3 | ||||
| -rw-r--r-- | src/syntax.c | 87 |
2 files changed, 38 insertions, 52 deletions
diff --git a/src/regex-emacs.h b/src/regex-emacs.h index 1bc973363e9..bc357633135 100644 --- a/src/regex-emacs.h +++ b/src/regex-emacs.h | |||
| @@ -187,7 +187,8 @@ typedef enum { RECC_ERROR = 0, | |||
| 187 | RECC_DIGIT, RECC_XDIGIT, | 187 | RECC_DIGIT, RECC_XDIGIT, |
| 188 | RECC_BLANK, RECC_SPACE, | 188 | RECC_BLANK, RECC_SPACE, |
| 189 | RECC_MULTIBYTE, RECC_NONASCII, | 189 | RECC_MULTIBYTE, RECC_NONASCII, |
| 190 | RECC_ASCII, RECC_UNIBYTE | 190 | RECC_ASCII, RECC_UNIBYTE, |
| 191 | RECC_NUM_CLASSES = RECC_UNIBYTE | ||
| 191 | } re_wctype_t; | 192 | } re_wctype_t; |
| 192 | 193 | ||
| 193 | extern bool re_iswctype (int ch, re_wctype_t cc); | 194 | extern bool re_iswctype (int ch, re_wctype_t cc); |
diff --git a/src/syntax.c b/src/syntax.c index e9e04e2d638..839ab36bb2f 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -178,14 +178,14 @@ static ptrdiff_t find_start_begv; | |||
| 178 | static modiff_count find_start_modiff; | 178 | static modiff_count find_start_modiff; |
| 179 | 179 | ||
| 180 | 180 | ||
| 181 | static Lisp_Object skip_chars (bool, Lisp_Object, Lisp_Object, bool); | 181 | static Lisp_Object skip_chars (bool, Lisp_Object, Lisp_Object); |
| 182 | static Lisp_Object skip_syntaxes (bool, Lisp_Object, Lisp_Object); | 182 | static Lisp_Object skip_syntaxes (bool, Lisp_Object, Lisp_Object); |
| 183 | static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, bool); | 183 | static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, bool); |
| 184 | static void scan_sexps_forward (struct lisp_parse_state *, | 184 | static void scan_sexps_forward (struct lisp_parse_state *, |
| 185 | ptrdiff_t, ptrdiff_t, ptrdiff_t, EMACS_INT, | 185 | ptrdiff_t, ptrdiff_t, ptrdiff_t, EMACS_INT, |
| 186 | bool, int); | 186 | bool, int); |
| 187 | static void internalize_parse_state (Lisp_Object, struct lisp_parse_state *); | 187 | static void internalize_parse_state (Lisp_Object, struct lisp_parse_state *); |
| 188 | static bool in_classes (int, Lisp_Object); | 188 | static bool in_classes (int c, int num_classes, const unsigned char *classes); |
| 189 | static void parse_sexp_propertize (ptrdiff_t charpos); | 189 | static void parse_sexp_propertize (ptrdiff_t charpos); |
| 190 | 190 | ||
| 191 | /* This setter is used only in this file, so it can be private. */ | 191 | /* This setter is used only in this file, so it can be private. */ |
| @@ -1607,7 +1607,7 @@ Char classes, e.g. `[:alpha:]', are supported. | |||
| 1607 | Returns the distance traveled, either zero or positive. */) | 1607 | Returns the distance traveled, either zero or positive. */) |
| 1608 | (Lisp_Object string, Lisp_Object lim) | 1608 | (Lisp_Object string, Lisp_Object lim) |
| 1609 | { | 1609 | { |
| 1610 | return skip_chars (1, string, lim, 1); | 1610 | return skip_chars (1, string, lim); |
| 1611 | } | 1611 | } |
| 1612 | 1612 | ||
| 1613 | DEFUN ("skip-chars-backward", Fskip_chars_backward, Sskip_chars_backward, 1, 2, 0, | 1613 | DEFUN ("skip-chars-backward", Fskip_chars_backward, Sskip_chars_backward, 1, 2, 0, |
| @@ -1616,7 +1616,7 @@ See `skip-chars-forward' for details. | |||
| 1616 | Returns the distance traveled, either zero or negative. */) | 1616 | Returns the distance traveled, either zero or negative. */) |
| 1617 | (Lisp_Object string, Lisp_Object lim) | 1617 | (Lisp_Object string, Lisp_Object lim) |
| 1618 | { | 1618 | { |
| 1619 | return skip_chars (0, string, lim, 1); | 1619 | return skip_chars (0, string, lim); |
| 1620 | } | 1620 | } |
| 1621 | 1621 | ||
| 1622 | DEFUN ("skip-syntax-forward", Fskip_syntax_forward, Sskip_syntax_forward, 1, 2, 0, | 1622 | DEFUN ("skip-syntax-forward", Fskip_syntax_forward, Sskip_syntax_forward, 1, 2, 0, |
| @@ -1643,8 +1643,7 @@ of this is the distance traveled. */) | |||
| 1643 | } | 1643 | } |
| 1644 | 1644 | ||
| 1645 | static Lisp_Object | 1645 | static Lisp_Object |
| 1646 | skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, | 1646 | skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim) |
| 1647 | bool handle_iso_classes) | ||
| 1648 | { | 1647 | { |
| 1649 | int c; | 1648 | int c; |
| 1650 | char fastmap[0400]; | 1649 | char fastmap[0400]; |
| @@ -1661,11 +1660,9 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, | |||
| 1661 | ptrdiff_t size_byte; | 1660 | ptrdiff_t size_byte; |
| 1662 | const unsigned char *str; | 1661 | const unsigned char *str; |
| 1663 | int len; | 1662 | int len; |
| 1664 | Lisp_Object iso_classes; | ||
| 1665 | USE_SAFE_ALLOCA; | 1663 | USE_SAFE_ALLOCA; |
| 1666 | 1664 | ||
| 1667 | CHECK_STRING (string); | 1665 | CHECK_STRING (string); |
| 1668 | iso_classes = Qnil; | ||
| 1669 | 1666 | ||
| 1670 | if (NILP (lim)) | 1667 | if (NILP (lim)) |
| 1671 | XSETINT (lim, forwardp ? ZV : BEGV); | 1668 | XSETINT (lim, forwardp ? ZV : BEGV); |
| @@ -1700,6 +1697,8 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, | |||
| 1700 | If STRING contains non-ASCII characters, setup char_ranges for | 1697 | If STRING contains non-ASCII characters, setup char_ranges for |
| 1701 | them and use fastmap only for their leading codes. */ | 1698 | them and use fastmap only for their leading codes. */ |
| 1702 | 1699 | ||
| 1700 | int nclasses = 0; | ||
| 1701 | unsigned char classes[RECC_NUM_CLASSES]; | ||
| 1703 | if (! string_multibyte) | 1702 | if (! string_multibyte) |
| 1704 | { | 1703 | { |
| 1705 | bool string_has_eight_bit = 0; | 1704 | bool string_has_eight_bit = 0; |
| @@ -1707,18 +1706,16 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, | |||
| 1707 | /* At first setup fastmap. */ | 1706 | /* At first setup fastmap. */ |
| 1708 | while (i_byte < size_byte) | 1707 | while (i_byte < size_byte) |
| 1709 | { | 1708 | { |
| 1710 | if (handle_iso_classes) | 1709 | const unsigned char *ch = str + i_byte; |
| 1710 | re_wctype_t cc = re_wctype_parse (&ch, size_byte - i_byte); | ||
| 1711 | if (cc == 0) | ||
| 1712 | error ("Invalid ISO C character class"); | ||
| 1713 | if (cc != -1) | ||
| 1711 | { | 1714 | { |
| 1712 | const unsigned char *ch = str + i_byte; | 1715 | if (!(nclasses && memchr (classes, cc, nclasses))) |
| 1713 | re_wctype_t cc = re_wctype_parse (&ch, size_byte - i_byte); | 1716 | classes[nclasses++] = cc; |
| 1714 | if (cc == 0) | 1717 | i_byte = ch - str; |
| 1715 | error ("Invalid ISO C character class"); | 1718 | continue; |
| 1716 | if (cc != -1) | ||
| 1717 | { | ||
| 1718 | iso_classes = Fcons (make_fixnum (cc), iso_classes); | ||
| 1719 | i_byte = ch - str; | ||
| 1720 | continue; | ||
| 1721 | } | ||
| 1722 | } | 1719 | } |
| 1723 | 1720 | ||
| 1724 | c = str[i_byte++]; | 1721 | c = str[i_byte++]; |
| @@ -1803,18 +1800,16 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, | |||
| 1803 | { | 1800 | { |
| 1804 | int leading_code = str[i_byte]; | 1801 | int leading_code = str[i_byte]; |
| 1805 | 1802 | ||
| 1806 | if (handle_iso_classes) | 1803 | const unsigned char *ch = str + i_byte; |
| 1804 | re_wctype_t cc = re_wctype_parse (&ch, size_byte - i_byte); | ||
| 1805 | if (cc == 0) | ||
| 1806 | error ("Invalid ISO C character class"); | ||
| 1807 | if (cc != -1) | ||
| 1807 | { | 1808 | { |
| 1808 | const unsigned char *ch = str + i_byte; | 1809 | if (!(nclasses && memchr (classes, cc, nclasses))) |
| 1809 | re_wctype_t cc = re_wctype_parse (&ch, size_byte - i_byte); | 1810 | classes[nclasses++] = cc; |
| 1810 | if (cc == 0) | 1811 | i_byte = ch - str; |
| 1811 | error ("Invalid ISO C character class"); | 1812 | continue; |
| 1812 | if (cc != -1) | ||
| 1813 | { | ||
| 1814 | iso_classes = Fcons (make_fixnum (cc), iso_classes); | ||
| 1815 | i_byte = ch - str; | ||
| 1816 | continue; | ||
| 1817 | } | ||
| 1818 | } | 1813 | } |
| 1819 | 1814 | ||
| 1820 | if (leading_code== '\\') | 1815 | if (leading_code== '\\') |
| @@ -1960,7 +1955,7 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, | |||
| 1960 | stop = endp; | 1955 | stop = endp; |
| 1961 | } | 1956 | } |
| 1962 | c = string_char_and_length (p, &nbytes); | 1957 | c = string_char_and_length (p, &nbytes); |
| 1963 | if (! NILP (iso_classes) && in_classes (c, iso_classes)) | 1958 | if (nclasses && in_classes (c, nclasses, classes)) |
| 1964 | { | 1959 | { |
| 1965 | if (negate) | 1960 | if (negate) |
| 1966 | break; | 1961 | break; |
| @@ -2001,7 +1996,7 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, | |||
| 2001 | stop = endp; | 1996 | stop = endp; |
| 2002 | } | 1997 | } |
| 2003 | 1998 | ||
| 2004 | if (!NILP (iso_classes) && in_classes (*p, iso_classes)) | 1999 | if (nclasses && in_classes (*p, nclasses, classes)) |
| 2005 | { | 2000 | { |
| 2006 | if (negate) | 2001 | if (negate) |
| 2007 | break; | 2002 | break; |
| @@ -2035,7 +2030,7 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, | |||
| 2035 | 2030 | ||
| 2036 | c = STRING_CHAR (p); | 2031 | c = STRING_CHAR (p); |
| 2037 | 2032 | ||
| 2038 | if (! NILP (iso_classes) && in_classes (c, iso_classes)) | 2033 | if (nclasses && in_classes (c, nclasses, classes)) |
| 2039 | { | 2034 | { |
| 2040 | if (negate) | 2035 | if (negate) |
| 2041 | break; | 2036 | break; |
| @@ -2069,7 +2064,7 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim, | |||
| 2069 | stop = endp; | 2064 | stop = endp; |
| 2070 | } | 2065 | } |
| 2071 | 2066 | ||
| 2072 | if (! NILP (iso_classes) && in_classes (p[-1], iso_classes)) | 2067 | if (nclasses && in_classes (p[-1], nclasses, classes)) |
| 2073 | { | 2068 | { |
| 2074 | if (negate) | 2069 | if (negate) |
| 2075 | break; | 2070 | break; |
| @@ -2253,26 +2248,16 @@ skip_syntaxes (bool forwardp, Lisp_Object string, Lisp_Object lim) | |||
| 2253 | } | 2248 | } |
| 2254 | } | 2249 | } |
| 2255 | 2250 | ||
| 2256 | /* Return true if character C belongs to one of the ISO classes | 2251 | /* Return true if character C belongs to one of the ISO classes in the |
| 2257 | in the list ISO_CLASSES. Each class is represented by an | 2252 | array. */ |
| 2258 | integer which is its type according to re_wctype. */ | ||
| 2259 | 2253 | ||
| 2260 | static bool | 2254 | static bool |
| 2261 | in_classes (int c, Lisp_Object iso_classes) | 2255 | in_classes (int c, int nclasses, const unsigned char *classes) |
| 2262 | { | 2256 | { |
| 2263 | bool fits_class = 0; | 2257 | for (int i = 0; i < nclasses; i++) |
| 2264 | 2258 | if (re_iswctype (c, classes[i])) | |
| 2265 | while (CONSP (iso_classes)) | 2259 | return true; |
| 2266 | { | 2260 | return false; |
| 2267 | Lisp_Object elt; | ||
| 2268 | elt = XCAR (iso_classes); | ||
| 2269 | iso_classes = XCDR (iso_classes); | ||
| 2270 | |||
| 2271 | if (re_iswctype (c, XFIXNAT (elt))) | ||
| 2272 | fits_class = 1; | ||
| 2273 | } | ||
| 2274 | |||
| 2275 | return fits_class; | ||
| 2276 | } | 2261 | } |
| 2277 | 2262 | ||
| 2278 | /* Jump over a comment, assuming we are at the beginning of one. | 2263 | /* Jump over a comment, assuming we are at the beginning of one. |