comparison src/syntax.c @ 88389:39b2b971cdb3

Include "character.h" instead of "charset.h". (syntax_parent_lookup): Deleted. (Fmodify_syntax_entry): Accept a cons as CHAR. (skip_chars): Adjusted for the new multibyte form. (init_syntax_once): Call char_table_set_range instead of directly accessing the structure of a char table.
author Kenichi Handa <handa@m17n.org>
date Fri, 01 Mar 2002 01:47:11 +0000
parents e8e16616217d
children 49128e8e5ebb
comparison
equal deleted inserted replaced
88388:e9a23b7c1feb 88389:39b2b971cdb3
22 #include <config.h> 22 #include <config.h>
23 #include <ctype.h> 23 #include <ctype.h>
24 #include "lisp.h" 24 #include "lisp.h"
25 #include "commands.h" 25 #include "commands.h"
26 #include "buffer.h" 26 #include "buffer.h"
27 #include "charset.h" 27 #include "character.h"
28 #include "keymap.h" 28 #include "keymap.h"
29 29
30 /* Make syntax table lookup grant data in gl_state. */ 30 /* Make syntax table lookup grant data in gl_state. */
31 #define SYNTAX_ENTRY_VIA_PROPERTY 31 #define SYNTAX_ENTRY_VIA_PROPERTY
32 32
833 sharing objects, the function `describe-syntax' can give a more 833 sharing objects, the function `describe-syntax' can give a more
834 compact listing. */ 834 compact listing. */
835 static Lisp_Object Vsyntax_code_object; 835 static Lisp_Object Vsyntax_code_object;
836 836
837 837
838 /* Look up the value for CHARACTER in syntax table TABLE's parent
839 and its parents. SYNTAX_ENTRY calls this, when TABLE itself has nil
840 for CHARACTER. It's actually used only when not compiled with GCC. */
841
842 Lisp_Object
843 syntax_parent_lookup (table, character)
844 Lisp_Object table;
845 int character;
846 {
847 Lisp_Object value;
848
849 while (1)
850 {
851 table = XCHAR_TABLE (table)->parent;
852 if (NILP (table))
853 return Qnil;
854
855 value = XCHAR_TABLE (table)->contents[character];
856 if (!NILP (value))
857 return value;
858 }
859 }
860
861 DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 1, 0, 838 DEFUN ("char-syntax", Fchar_syntax, Schar_syntax, 1, 1, 0,
862 doc: /* Return the syntax code of CHARACTER, described by a character. 839 doc: /* Return the syntax code of CHARACTER, described by a character.
863 For example, if CHARACTER is a word constituent, 840 For example, if CHARACTER is a word constituent,
864 the character `w' is returned. 841 the character `w' is returned.
865 The characters that correspond to various syntax codes 842 The characters that correspond to various syntax codes
974 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry, Smodify_syntax_entry, 2, 3, 951 DEFUN ("modify-syntax-entry", Fmodify_syntax_entry, Smodify_syntax_entry, 2, 3,
975 "cSet syntax for character: \nsSet syntax for %s to: ", 952 "cSet syntax for character: \nsSet syntax for %s to: ",
976 doc: /* Set syntax for character CHAR according to string NEWENTRY. 953 doc: /* Set syntax for character CHAR according to string NEWENTRY.
977 The syntax is changed only for table SYNTAX_TABLE, which defaults to 954 The syntax is changed only for table SYNTAX_TABLE, which defaults to
978 the current buffer's syntax table. 955 the current buffer's syntax table.
956 CHAR may be a cons (MIN . MAX), in which case, syntaxes of all characters
957 in the range MIN and MAX are changed.
979 The first character of NEWENTRY should be one of the following: 958 The first character of NEWENTRY should be one of the following:
980 Space or - whitespace syntax. w word constituent. 959 Space or - whitespace syntax. w word constituent.
981 _ symbol constituent. . punctuation. 960 _ symbol constituent. . punctuation.
982 ( open-parenthesis. ) close-parenthesis. 961 ( open-parenthesis. ) close-parenthesis.
983 " string quote. \\ escape. 962 " string quote. \\ escape.
1010 between expressions. 989 between expressions.
1011 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */) 990 usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
1012 (c, newentry, syntax_table) 991 (c, newentry, syntax_table)
1013 Lisp_Object c, newentry, syntax_table; 992 Lisp_Object c, newentry, syntax_table;
1014 { 993 {
1015 CHECK_NUMBER (c); 994 if (CONSP (c))
995 {
996 CHECK_CHARACTER (XCAR (c));
997 CHECK_CHARACTER (XCDR (c));
998 }
999 else
1000 CHECK_CHARACTER (c);
1016 1001
1017 if (NILP (syntax_table)) 1002 if (NILP (syntax_table))
1018 syntax_table = current_buffer->syntax_table; 1003 syntax_table = current_buffer->syntax_table;
1019 else 1004 else
1020 check_syntax_table (syntax_table); 1005 check_syntax_table (syntax_table);
1021 1006
1022 SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), Fstring_to_syntax (newentry)); 1007 newentry = Fstring_to_syntax (newentry);
1008 if (CONSP (c))
1009 SET_RAW_SYNTAX_ENTRY_RANGE (syntax_table, c, newentry);
1010 else
1011 SET_RAW_SYNTAX_ENTRY (syntax_table, XINT (c), newentry);
1023 return Qnil; 1012 return Qnil;
1024 } 1013 }
1025 1014
1026 /* Dump syntax table to buffer in human-readable format */ 1015 /* Dump syntax table to buffer in human-readable format */
1027 1016
1416 1405
1417 /* Find the characters specified and set their elements of fastmap. 1406 /* Find the characters specified and set their elements of fastmap.
1418 If syntaxp, each character counts as itself. 1407 If syntaxp, each character counts as itself.
1419 Otherwise, handle backslashes and ranges specially. */ 1408 Otherwise, handle backslashes and ranges specially. */
1420 1409
1421 while (i_byte < size_byte) 1410 if (size_byte == XSTRING (string)->size)
1422 { 1411 while (i_byte < size_byte)
1423 c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte - i_byte, len); 1412 {
1424 i_byte += len; 1413 c = str[i_byte++];
1425 1414
1426 if (syntaxp) 1415 if (syntaxp)
1427 fastmap[syntax_spec_code[c & 0377]] = 1; 1416 fastmap[syntax_spec_code[c]] = 1;
1428 else 1417 else
1429 { 1418 {
1430 if (c == '\\') 1419 if (c == '\\')
1431 { 1420 {
1432 if (i_byte == size_byte) 1421 if (i_byte == size_byte)
1433 break; 1422 break;
1434 1423
1435 c = STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); 1424 c = str[i_byte++];
1436 i_byte += len;
1437 } 1425 }
1438 if (i_byte < size_byte 1426 if (i_byte < size_byte
1439 && str[i_byte] == '-') 1427 && str[i_byte] == '-')
1440 { 1428 {
1441 unsigned int c2; 1429 unsigned int c2;
1445 1433
1446 if (i_byte == size_byte) 1434 if (i_byte == size_byte)
1447 break; 1435 break;
1448 1436
1449 /* Get the end of the range. */ 1437 /* Get the end of the range. */
1450 c2 =STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len); 1438 c2 = str[i_byte++];
1451 i_byte += len; 1439 while (c <= c2)
1452 1440 fastmap[c++] = 1;
1453 if (SINGLE_BYTE_CHAR_P (c))
1454 {
1455 if (! SINGLE_BYTE_CHAR_P (c2))
1456 {
1457 /* Handle a range starting with a character of
1458 less than 256, and ending with a character of
1459 not less than 256. Split that into two
1460 ranges, the low one ending at 0377, and the
1461 high one starting at the smallest character
1462 in the charset of C2 and ending at C2. */
1463 int charset = CHAR_CHARSET (c2);
1464 int c1 = MAKE_CHAR (charset, 0, 0);
1465
1466 char_ranges[n_char_ranges++] = c1;
1467 char_ranges[n_char_ranges++] = c2;
1468 c2 = 0377;
1469 }
1470 while (c <= c2)
1471 {
1472 fastmap[c] = 1;
1473 c++;
1474 }
1475 }
1476 else if (c <= c2) /* Both C and C2 are multibyte char. */
1477 {
1478 char_ranges[n_char_ranges++] = c;
1479 char_ranges[n_char_ranges++] = c2;
1480 }
1481 } 1441 }
1482 else 1442 else
1483 { 1443 fastmap[c] = 1;
1484 if (SINGLE_BYTE_CHAR_P (c)) 1444 }
1485 fastmap[c] = 1; 1445 }
1486 else 1446 else
1487 { 1447 while (i_byte < size_byte)
1488 char_ranges[n_char_ranges++] = c; 1448 {
1489 char_ranges[n_char_ranges++] = c; 1449 c = STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len);
1490 } 1450 i_byte += len;
1491 } 1451
1492 } 1452 if (syntaxp)
1493 } 1453 fastmap[syntax_spec_code[c & 0377]] = 1;
1454 else
1455 {
1456 if (c == '\\')
1457 {
1458 if (i_byte == size_byte)
1459 break;
1460
1461 c = STRING_CHAR_AND_LENGTH (str+i_byte, size_byte-i_byte, len);
1462 i_byte += len;
1463 }
1464 if (i_byte < size_byte
1465 && str[i_byte] == '-')
1466 {
1467 unsigned int c2;
1468
1469 /* Skip over the dash. */
1470 i_byte++;
1471
1472 if (i_byte == size_byte)
1473 break;
1474
1475 /* Get the end of the range. */
1476 c2 =STRING_CHAR_AND_LENGTH (str + i_byte, size_byte-i_byte, len);
1477 i_byte += len;
1478
1479 if (ASCII_CHAR_P (c))
1480 while (c <= c2 && c < 0x80)
1481 fastmap[c++] = 1;
1482 if (c <= c2)
1483 {
1484 char_ranges[n_char_ranges++] = c;
1485 char_ranges[n_char_ranges++] = c2;
1486 }
1487 }
1488 else
1489 {
1490 if (ASCII_CHAR_P (c))
1491 fastmap[c] = 1;
1492 else
1493 {
1494 char_ranges[n_char_ranges++] = c;
1495 char_ranges[n_char_ranges++] = c;
1496 }
1497 }
1498 }
1499 }
1494 1500
1495 /* If ^ was the first character, complement the fastmap. */ 1501 /* If ^ was the first character, complement the fastmap. */
1496 if (negate) 1502 if (negate)
1497 for (i = 0; i < sizeof fastmap; i++) 1503 for (i = 0; i < sizeof fastmap; i++)
1498 fastmap[i] ^= 1; 1504 fastmap[i] ^= 1;
1571 { 1577 {
1572 if (multibyte) 1578 if (multibyte)
1573 while (pos < XINT (lim)) 1579 while (pos < XINT (lim))
1574 { 1580 {
1575 c = FETCH_MULTIBYTE_CHAR (pos_byte); 1581 c = FETCH_MULTIBYTE_CHAR (pos_byte);
1576 if (SINGLE_BYTE_CHAR_P (c)) 1582 if (ASCII_CHAR_P (c))
1577 { 1583 {
1578 if (!fastmap[c]) 1584 if (!fastmap[c])
1579 break; 1585 break;
1580 } 1586 }
1581 else 1587 else
1630 else 1636 else
1631 while (pos > XINT (lim) && fastmap[FETCH_BYTE (pos - 1)]) 1637 while (pos > XINT (lim) && fastmap[FETCH_BYTE (pos - 1)])
1632 pos--; 1638 pos--;
1633 } 1639 }
1634 } 1640 }
1635
1636 #if 0 /* Not needed now that a position in mid-character
1637 cannot be specified in Lisp. */
1638 if (multibyte
1639 /* INC_POS or DEC_POS might have moved POS over LIM. */
1640 && (forwardp ? (pos > XINT (lim)) : (pos < XINT (lim))))
1641 pos = XINT (lim);
1642 #endif
1643 1641
1644 if (! multibyte) 1642 if (! multibyte)
1645 pos_byte = pos; 1643 pos_byte = pos;
1646 1644
1647 SET_PT_BOTH (pos, pos_byte); 1645 SET_PT_BOTH (pos, pos_byte);
2943 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, c, temp); 2941 SET_RAW_SYNTAX_ENTRY (Vstandard_syntax_table, c, temp);
2944 } 2942 }
2945 2943
2946 /* All multibyte characters have syntax `word' by default. */ 2944 /* All multibyte characters have syntax `word' by default. */
2947 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword]; 2945 temp = XVECTOR (Vsyntax_code_object)->contents[(int) Sword];
2948 for (i = CHAR_TABLE_SINGLE_BYTE_SLOTS; i < CHAR_TABLE_ORDINARY_SLOTS; i++) 2946 char_table_set_range (Vstandard_syntax_table, 0x80, MAX_CHAR, temp);
2949 XCHAR_TABLE (Vstandard_syntax_table)->contents[i] = temp;
2950 } 2947 }
2951 2948
2952 void 2949 void
2953 syms_of_syntax () 2950 syms_of_syntax ()
2954 { 2951 {