]> code.delx.au - gnu-emacs/blob - src/syntax.h
Adjusted for the change of MAX_CHARSET.
[gnu-emacs] / src / syntax.h
1 /* Declarations having to do with GNU Emacs syntax tables.
2 Copyright (C) 1985, 1993, 1994 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
20
21
22 extern Lisp_Object Qsyntax_table_p;
23 extern Lisp_Object Fsyntax_table_p (), Fsyntax_table (), Fset_syntax_table ();
24
25 /* The standard syntax table is stored where it will automatically
26 be used in all new buffers. */
27 #define Vstandard_syntax_table buffer_defaults.syntax_table
28
29 /* A syntax table is a chartable whose elements are cons cells
30 (CODE+FLAGS . MATCHING-CHAR). MATCHING-CHAR can be nil if the char
31 is not a kind of parenthesis.
32
33 The low 8 bits of CODE+FLAGS is a code, as follows: */
34
35 enum syntaxcode
36 {
37 Swhitespace, /* for a whitespace character */
38 Spunct, /* for random punctuation characters */
39 Sword, /* for a word constituent */
40 Ssymbol, /* symbol constituent but not word constituent */
41 Sopen, /* for a beginning delimiter */
42 Sclose, /* for an ending delimiter */
43 Squote, /* for a prefix character like Lisp ' */
44 Sstring, /* for a string-grouping character like Lisp " */
45 Smath, /* for delimiters like $ in Tex. */
46 Sescape, /* for a character that begins a C-style escape */
47 Scharquote, /* for a character that quotes the following character */
48 Scomment, /* for a comment-starting character */
49 Sendcomment, /* for a comment-ending character */
50 Sinherit, /* use the standard syntax table for this character */
51 Smax /* Upper bound on codes that are meaningful */
52 };
53
54 /* Set the syntax entry VAL for char C in table TABLE. */
55
56 #define SET_RAW_SYNTAX_ENTRY(table, c, val) \
57 ((c) < CHAR_TABLE_SINGLE_BYTE_SLOTS \
58 ? (XCHAR_TABLE (table)->contents[(unsigned char) (c)] = (val)) \
59 : Faset ((table), make_number (c), (val)))
60
61 /* Fetch the syntax entry for char C in syntax table TABLE.
62 This macro is called only when C is less than CHAR_TABLE_ORDINARY_SLOTS.
63 Do inheritance. */
64
65 #ifdef __GNUC__
66 #define SYNTAX_ENTRY_FOLLOW_PARENT(table, c) \
67 ({ Lisp_Object tbl = table; \
68 Lisp_Object temp = XCHAR_TABLE (tbl)->contents[(c)]; \
69 while (NILP (temp)) \
70 { \
71 tbl = XCHAR_TABLE (tbl)->parent; \
72 if (NILP (tbl)) \
73 break; \
74 temp = XCHAR_TABLE (tbl)->contents[(c)]; \
75 } \
76 temp; })
77 #else
78 extern Lisp_Object syntax_temp;
79 extern Lisp_Object syntax_parent_lookup ();
80
81 #define SYNTAX_ENTRY_FOLLOW_PARENT(table, c) \
82 (syntax_temp = XCHAR_TABLE (table)->contents[(c)], \
83 (NILP (syntax_temp) \
84 ? syntax_parent_lookup (table, (c)) \
85 : syntax_temp))
86 #endif
87
88 /* Fetch the syntax entry for char C in the current syntax table.
89 This returns the whole entry (normally a cons cell).
90 Do Inheritance. */
91
92 #define SYNTAX_ENTRY(c) \
93 ((c) < CHAR_TABLE_SINGLE_BYTE_SLOTS \
94 ? SYNTAX_ENTRY_FOLLOW_PARENT (current_buffer->syntax_table, \
95 (unsigned char) (c)) \
96 : Faref (current_buffer->syntax_table, make_number ((c))))
97
98
99 /* Extract the information from the entry for character C
100 in the current syntax table. */
101
102 #ifdef __GNUC__
103 #define SYNTAX(c) \
104 ({ Lisp_Object temp; \
105 temp = SYNTAX_ENTRY (c); \
106 (CONSP (temp) \
107 ? (enum syntaxcode) (XINT (XCONS (temp)->car) & 0xff) \
108 : Swhitespace); })
109
110 #define SYNTAX_WITH_FLAGS(c) \
111 ({ Lisp_Object temp; \
112 temp = SYNTAX_ENTRY (c); \
113 (CONSP (temp) \
114 ? XINT (XCONS (temp)->car) \
115 : (int) Swhitespace); })
116
117 #define SYNTAX_MATCH(c) \
118 ({ Lisp_Object temp; \
119 temp = SYNTAX_ENTRY (c); \
120 (CONSP (temp) \
121 ? XINT (XCONS (temp)->cdr) \
122 : Qnil); })
123 #else
124 #define SYNTAX(c) \
125 (syntax_temp = SYNTAX_ENTRY ((c)), \
126 (CONSP (syntax_temp) \
127 ? (enum syntaxcode) (XINT (XCONS (syntax_temp)->car) & 0xff) \
128 : Swhitespace))
129
130 #define SYNTAX_WITH_FLAGS(c) \
131 (syntax_temp = SYNTAX_ENTRY ((c)), \
132 (CONSP (syntax_temp) \
133 ? XINT (XCONS (syntax_temp)->car) \
134 : (int) Swhitespace))
135
136 #define SYNTAX_MATCH(c) \
137 (syntax_temp = SYNTAX_ENTRY ((c)), \
138 (CONSP (syntax_temp) \
139 ? XINT (XCONS (syntax_temp)->cdr) \
140 : Qnil))
141 #endif
142
143 /* Then there are six single-bit flags that have the following meanings:
144 1. This character is the first of a two-character comment-start sequence.
145 2. This character is the second of a two-character comment-start sequence.
146 3. This character is the first of a two-character comment-end sequence.
147 4. This character is the second of a two-character comment-end sequence.
148 5. This character is a prefix, for backward-prefix-chars.
149 Note that any two-character sequence whose first character has flag 1
150 and whose second character has flag 2 will be interpreted as a comment start.
151
152 bit 6 is used to discriminate between two different comment styles.
153 Languages such as C++ allow two orthogonal syntax start/end pairs
154 and bit 6 is used to determine whether a comment-end or Scommentend
155 ends style a or b. Comment start sequences can start style a or b.
156 Style a is always the default.
157 */
158
159 #define SYNTAX_COMSTART_FIRST(c) ((SYNTAX_WITH_FLAGS (c) >> 16) & 1)
160
161 #define SYNTAX_COMSTART_SECOND(c) ((SYNTAX_WITH_FLAGS (c) >> 17) & 1)
162
163 #define SYNTAX_COMEND_FIRST(c) ((SYNTAX_WITH_FLAGS (c) >> 18) & 1)
164
165 #define SYNTAX_COMEND_SECOND(c) ((SYNTAX_WITH_FLAGS (c) >> 19) & 1)
166
167 #define SYNTAX_PREFIX(c) ((SYNTAX_WITH_FLAGS (c) >> 20) & 1)
168
169 /* extract the comment style bit from the syntax table entry */
170 #define SYNTAX_COMMENT_STYLE(c) ((SYNTAX_WITH_FLAGS (c) >> 21) & 1)
171
172 /* This array, indexed by a character, contains the syntax code which that
173 character signifies (as a char). For example,
174 (enum syntaxcode) syntax_spec_code['w'] is Sword. */
175
176 extern unsigned char syntax_spec_code[0400];
177
178 /* Indexed by syntax code, give the letter that describes it. */
179
180 extern char syntax_code_spec[14];