1 /* Declarations having to do with XEmacs syntax tables.
2 Copyright (C) 1985, 1992, 1993 Free Software Foundation, Inc.
3 Copyright (C) 2001 MORIOKA Tomohiko
5 This file is part of XEmacs.
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Synched up with: FSF 19.28. */
24 #ifndef INCLUDED_syntax_h_
25 #define INCLUDED_syntax_h_
29 /* A syntax table is a type of char table.
31 The low 7 bits of the integer is a code, as follows. The 8th bit is
32 used as the prefix bit flag (see below).
34 The values in a syntax table are either integers or conses of
35 integers and chars. The lowest 7 bits of the integer are the syntax
36 class. If this is Sinherit, then the actual syntax value needs to
37 be retrieved from the standard syntax table.
39 Since the logic involved in finding the actual integer isn't very
40 complex, you'd think the time required to retrieve it is not a
41 factor. If you thought that, however, you'd be wrong, due to the
42 high number of times (many per character) that the syntax value is
43 accessed in functions such as scan_lists(). To speed this up,
44 we maintain a mirror syntax table that contains the actual
45 integers. We can do this successfully because syntax tables are
46 now an abstract type, where we control all access.
49 /* The standard syntax table is stored where it will automatically
50 be used in all new buffers. */
51 extern Lisp_Object Vstandard_syntax_table;
55 Swhitespace, /* whitespace character */
56 Spunct, /* random punctuation character */
57 Sword, /* word constituent */
58 Ssymbol, /* symbol constituent but not word constituent */
59 Sopen, /* a beginning delimiter */
60 Sclose, /* an ending delimiter */
61 Squote, /* a prefix character like Lisp ' */
62 Sstring, /* a string-grouping character like Lisp " */
63 Smath, /* delimiters like $ in TeX. */
64 Sescape, /* a character that begins a C-style escape */
65 Scharquote, /* a character that quotes the following character */
66 Scomment, /* a comment-starting character */
67 Sendcomment, /* a comment-ending character */
68 Sinherit, /* use the standard syntax table for this character */
69 Smax /* Upper bound on codes that are meaningful */
72 enum syntaxcode charset_syntax (struct buffer *buf, Lisp_Object charset,
75 /* Return the syntax code for a particular character and mirror table. */
78 INLINE_HEADER int SYNTAX_CODE_UNSAFE (Lisp_Char_Table *table, Emchar c);
80 SYNTAX_CODE_UNSAFE (Lisp_Char_Table *table, Emchar c)
82 int code = CHAR_TABLE_VALUE_UNSAFE (table, c);
91 code = CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE
92 (Vstandard_syntax_table), c);
101 #define SYNTAX_CODE_UNSAFE(table, c) \
102 XINT (CHAR_TABLE_VALUE_UNSAFE (table, c))
105 INLINE_HEADER int SYNTAX_CODE (Lisp_Char_Table *table, Emchar c);
107 SYNTAX_CODE (Lisp_Char_Table *table, Emchar c)
109 return SYNTAX_CODE_UNSAFE (table, c);
112 #define SYNTAX_UNSAFE(table, c) \
113 ((enum syntaxcode) (SYNTAX_CODE_UNSAFE (table, c) & 0177))
115 #define SYNTAX_FROM_CODE(code) ((enum syntaxcode) ((code) & 0177))
116 #define SYNTAX(table, c) SYNTAX_FROM_CODE (SYNTAX_CODE (table, c))
118 INLINE_HEADER int WORD_SYNTAX_P (Lisp_Char_Table *table, Emchar c);
120 WORD_SYNTAX_P (Lisp_Char_Table *table, Emchar c)
122 return SYNTAX (table, c) == Sword;
125 /* OK, here's a graphic diagram of the format of the syntax values:
129 [ 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 ]
130 [ 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 ]
132 <-----> <-----> <-------------> <-------------> ^ <----------->
133 ELisp unused |comment bits | unused | syntax code
134 tag | | | | | | | | |
135 stuff | | | | | | | | |
137 | | | | | | | | `--> prefix flag
139 | | | | | | | `--> comment end style B, second char
140 | | | | | | `----> comment end style A, second char
141 | | | | | `------> comment end style B, first char
142 | | | | `--------> comment end style A, first char
143 | | | `----------> comment start style B, second char
144 | | `------------> comment start style A, second char
145 | `--------------> comment start style B, first char
146 `----------------> comment start style A, first char
148 In a 64-bit integer, there would be 32 more unused bits between
149 the tag and the comment bits.
151 Clearly, such a scheme will not work for Mule, because the matching
152 paren could be any character and as such requires 19 bits, which
155 Remember that under Mule we use char tables instead of vectors.
156 So what we do is use another char table for the matching paren
157 and store a pointer to it in the first char table. (This frees
158 code from having to worry about passing two tables around.)
162 /* The prefix flag bit for backward-prefix-chars is now put into bit 7. */
164 #define SYNTAX_PREFIX_UNSAFE(table, c) \
165 ((SYNTAX_CODE_UNSAFE (table, c) >> 7) & 1)
166 #define SYNTAX_PREFIX(table, c) \
167 ((SYNTAX_CODE (table, c) >> 7) & 1)
169 /* Bits 23-16 are used to implement up to two comment styles
170 in a single buffer. They have the following meanings:
172 1. first of a one or two character comment-start sequence of style a.
173 2. first of a one or two character comment-start sequence of style b.
174 3. second of a two-character comment-start sequence of style a.
175 4. second of a two-character comment-start sequence of style b.
176 5. first of a one or two character comment-end sequence of style a.
177 6. first of a one or two character comment-end sequence of style b.
178 7. second of a two-character comment-end sequence of style a.
179 8. second of a two-character comment-end sequence of style b.
182 #define SYNTAX_COMMENT_BITS(table, c) \
183 ((SYNTAX_CODE (table, c) >> 16) &0xff)
185 #define SYNTAX_FIRST_OF_START_A 0x80
186 #define SYNTAX_FIRST_OF_START_B 0x40
187 #define SYNTAX_SECOND_OF_START_A 0x20
188 #define SYNTAX_SECOND_OF_START_B 0x10
189 #define SYNTAX_FIRST_OF_END_A 0x08
190 #define SYNTAX_FIRST_OF_END_B 0x04
191 #define SYNTAX_SECOND_OF_END_A 0x02
192 #define SYNTAX_SECOND_OF_END_B 0x01
194 #define SYNTAX_COMMENT_STYLE_A 0xaa
195 #define SYNTAX_COMMENT_STYLE_B 0x55
196 #define SYNTAX_FIRST_CHAR_START 0xc0
197 #define SYNTAX_FIRST_CHAR_END 0x0c
198 #define SYNTAX_FIRST_CHAR 0xcc
199 #define SYNTAX_SECOND_CHAR_START 0x30
200 #define SYNTAX_SECOND_CHAR_END 0x03
201 #define SYNTAX_SECOND_CHAR 0x33
204 /* #### These are now more or less equivalent to
205 SYNTAX_COMMENT_MATCH_START ...*/
206 /* a and b must be first and second start chars for a common type */
207 #define SYNTAX_START_P(table, a, b) \
208 (((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_START) >> 2) \
209 & (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_START))
211 /* ... and SYNTAX_COMMENT_MATCH_END */
212 /* a and b must be first and second end chars for a common type */
213 #define SYNTAX_END_P(table, a, b) \
214 (((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_END) >> 2) \
215 & (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_END))
217 #define SYNTAX_STYLES_MATCH_START_P(table, a, b, mask) \
218 ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_START & (mask)) \
219 && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_START & (mask)))
221 #define SYNTAX_STYLES_MATCH_END_P(table, a, b, mask) \
222 ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_END & (mask)) \
223 && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_END & (mask)))
225 #define SYNTAX_STYLES_MATCH_1CHAR_P(table, a, mask) \
226 ((SYNTAX_COMMENT_BITS (table, a) & (mask)))
228 #define STYLE_FOUND_P(table, a, b, startp, style) \
229 ((SYNTAX_COMMENT_BITS (table, a) & \
230 ((startp) ? SYNTAX_FIRST_CHAR_START : \
231 SYNTAX_FIRST_CHAR_END) & (style)) \
232 && (SYNTAX_COMMENT_BITS (table, b) & \
233 ((startp) ? SYNTAX_SECOND_CHAR_START : \
234 SYNTAX_SECOND_CHAR_END) & (style)))
236 #define SYNTAX_COMMENT_MASK_START(table, a, b) \
237 ((STYLE_FOUND_P (table, a, b, 1, SYNTAX_COMMENT_STYLE_A) \
238 ? SYNTAX_COMMENT_STYLE_A \
239 : (STYLE_FOUND_P (table, a, b, 1, SYNTAX_COMMENT_STYLE_B) \
240 ? SYNTAX_COMMENT_STYLE_B \
243 #define SYNTAX_COMMENT_MASK_END(table, a, b) \
244 ((STYLE_FOUND_P (table, a, b, 0, SYNTAX_COMMENT_STYLE_A) \
245 ? SYNTAX_COMMENT_STYLE_A \
246 : (STYLE_FOUND_P (table, a, b, 0, SYNTAX_COMMENT_STYLE_B) \
247 ? SYNTAX_COMMENT_STYLE_B \
250 #define STYLE_FOUND_1CHAR_P(table, a, style) \
251 ((SYNTAX_COMMENT_BITS (table, a) & (style)))
253 #define SYNTAX_COMMENT_1CHAR_MASK(table, a) \
254 ((STYLE_FOUND_1CHAR_P (table, a, SYNTAX_COMMENT_STYLE_A) \
255 ? SYNTAX_COMMENT_STYLE_A \
256 : (STYLE_FOUND_1CHAR_P (table, a, SYNTAX_COMMENT_STYLE_B) \
257 ? SYNTAX_COMMENT_STYLE_B \
260 EXFUN (Fchar_syntax, 2);
261 EXFUN (Fforward_word, 2);
263 /* This array, indexed by a character, contains the syntax code which
264 that character signifies (as a char).
265 For example, (enum syntaxcode) syntax_spec_code['w'] is Sword. */
267 extern const unsigned char syntax_spec_code[0400];
269 /* Indexed by syntax code, give the letter that describes it. */
271 extern const unsigned char syntax_code_spec[];
273 Lisp_Object scan_lists (struct buffer *buf, Bufpos from, int count,
274 int depth, int sexpflag, int no_error);
275 int char_quoted (struct buffer *buf, Bufpos pos);
277 /* NOTE: This does not refer to the mirror table, but to the
278 syntax table itself. */
279 Lisp_Object syntax_match (Lisp_Object table, Emchar ch);
281 extern int no_quit_in_re_search;
282 extern struct buffer *regex_emacs_buffer;
283 extern int regex_emacs_buffer_p;
286 void update_syntax_table (Lisp_Char_Table *ct);
289 #endif /* INCLUDED_syntax_h_ */