0
|
1 /* Declarations having to do with XEmacs syntax tables.
|
|
2 Copyright (C) 1985, 1992, 1993 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; 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 /* Synched up with: FSF 19.28. */
|
|
22
|
|
23 #ifndef _XEMACS_SYNTAX_H_
|
|
24 #define _XEMACS_SYNTAX_H_
|
|
25
|
70
|
26 #include "chartab.h"
|
|
27
|
0
|
28 /* The standard syntax table is stored where it will automatically
|
|
29 be used in all new buffers. */
|
|
30 extern Lisp_Object Vstandard_syntax_table;
|
|
31
|
70
|
32 /* A syntax table is a type of char table.
|
0
|
33
|
|
34 The low 7 bits of the integer is a code, as follows. The 8th bit is
|
|
35 used as the prefix bit flag (see below).
|
70
|
36
|
|
37 The values in a syntax table are either integers or conses of
|
|
38 integers and chars. The lowest 7 bits of the integer are the syntax
|
|
39 class. If this is Sinherit, then the actual syntax value needs to
|
|
40 be retrieved from the standard syntax table.
|
|
41
|
|
42 Since the logic involved in finding the actual integer isn't very
|
|
43 complex, you'd think the time required to retrieve it is not a
|
|
44 factor. If you thought that, however, you'd be wrong, due to the
|
|
45 high number of times (many per character) that the syntax value is
|
|
46 accessed in functions such as scan_lists(). To speed this up,
|
|
47 we maintain a mirror syntax table that contains the actual
|
|
48 integers. We can do this successfully because syntax tables are
|
|
49 now an abstract type, where we control all access.
|
0
|
50 */
|
|
51
|
|
52 enum syntaxcode
|
2
|
53 {
|
|
54 Swhitespace, /* whitespace character */
|
|
55 Spunct, /* random punctuation character */
|
|
56 Sword, /* word constituent */
|
|
57 Ssymbol, /* symbol constituent but not word constituent */
|
|
58 Sopen, /* a beginning delimiter */
|
|
59 Sclose, /* an ending delimiter */
|
|
60 Squote, /* a prefix character like Lisp ' */
|
|
61 Sstring, /* a string-grouping character like Lisp " */
|
|
62 Smath, /* delimiters like $ in TeX. */
|
|
63 Sescape, /* a character that begins a C-style escape */
|
|
64 Scharquote, /* a character that quotes the following character */
|
|
65 Scomment, /* a comment-starting character */
|
|
66 Sendcomment, /* a comment-ending character */
|
|
67 Sinherit, /* use the standard syntax table for this character */
|
|
68 Smax /* Upper bound on codes that are meaningful */
|
|
69 };
|
0
|
70
|
|
71 extern Lisp_Object Qsyntax_table_p;
|
|
72 Lisp_Object Fsyntax_table_p (Lisp_Object);
|
2
|
73 Lisp_Object Fsyntax_table (Lisp_Object);
|
0
|
74 Lisp_Object Fset_syntax_table (Lisp_Object, Lisp_Object);
|
70
|
75 enum syntaxcode charset_syntax (struct buffer *buf, Lisp_Object charset,
|
|
76 int *multi_p_out);
|
0
|
77
|
70
|
78 /* Return the syntax code for a particular character and mirror table. */
|
0
|
79
|
70
|
80 #define SYNTAX_CODE_UNSAFE(table, c) \
|
|
81 XINT (CHAR_TABLE_VALUE_UNSAFE (table, c))
|
0
|
82
|
70
|
83 INLINE int SYNTAX_CODE (struct Lisp_Char_Table *table, Emchar c);
|
0
|
84 INLINE int
|
70
|
85 SYNTAX_CODE (struct Lisp_Char_Table *table, Emchar c)
|
0
|
86 {
|
|
87 return SYNTAX_CODE_UNSAFE (table, c);
|
|
88 }
|
|
89
|
|
90 #define SYNTAX_UNSAFE(table, c) \
|
|
91 ((enum syntaxcode) (SYNTAX_CODE_UNSAFE (table, c) & 0177))
|
|
92
|
|
93 #define SYNTAX_FROM_CODE(code) ((enum syntaxcode) ((code) & 0177))
|
|
94 #define SYNTAX(table, c) SYNTAX_FROM_CODE (SYNTAX_CODE (table, c))
|
|
95
|
70
|
96 INLINE int WORD_SYNTAX_P (struct Lisp_Char_Table *table, Emchar c);
|
0
|
97 INLINE int
|
70
|
98 WORD_SYNTAX_P (struct Lisp_Char_Table *table, Emchar c)
|
0
|
99 {
|
|
100 int syncode = SYNTAX (table, c);
|
70
|
101 return syncode == Sword;
|
0
|
102 }
|
|
103
|
70
|
104 /* OK, here's a graphic diagram of the format of the syntax values:
|
|
105
|
|
106 Bit number:
|
|
107
|
|
108 [ 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 ]
|
|
109 [ 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 ]
|
|
110
|
|
111 <-----> <-----> <-------------> <-------------> ^ <----------->
|
|
112 ELisp unused |comment bits | unused | syntax code
|
|
113 tag | | | | | | | | |
|
|
114 stuff | | | | | | | | |
|
|
115 | | | | | | | | |
|
|
116 | | | | | | | | `--> prefix flag
|
|
117 | | | | | | | |
|
|
118 | | | | | | | `--> comment end style B, second char
|
|
119 | | | | | | `----> comment end style A, second char
|
|
120 | | | | | `------> comment end style B, first char
|
|
121 | | | | `--------> comment end style A, first char
|
|
122 | | | `----------> comment start style B, second char
|
|
123 | | `------------> comment start style A, second char
|
|
124 | `--------------> comment start style B, first char
|
|
125 `----------------> comment start style A, first char
|
|
126
|
|
127 In a 64-bit integer, there would be 32 more unused bits between
|
|
128 the tag and the comment bits.
|
|
129
|
|
130 Clearly, such a scheme will not work for Mule, because the matching
|
|
131 paren could be any character and as such requires 19 bits, which
|
|
132 we don't got.
|
|
133
|
|
134 Remember that under Mule we use char tables instead of vectors.
|
|
135 So what we do is use another char table for the matching paren
|
|
136 and store a pointer to it in the first char table. (This frees
|
|
137 code from having to worry about passing two tables around.)
|
|
138 */
|
|
139
|
|
140
|
0
|
141 /* The prefix flag bit for backward-prefix-chars is now put into bit 7. */
|
|
142
|
|
143 #define SYNTAX_PREFIX_UNSAFE(table, c) \
|
|
144 ((SYNTAX_CODE_UNSAFE (table, c) >> 7) & 1)
|
|
145 #define SYNTAX_PREFIX(table, c) \
|
|
146 ((SYNTAX_CODE (table, c) >> 7) & 1)
|
|
147
|
70
|
148 /* Bits 23-16 are used to implement up to two comment styles
|
0
|
149 in a single buffer. They have the following meanings:
|
|
150
|
|
151 1. first of a one or two character comment-start sequence of style a.
|
|
152 2. first of a one or two character comment-start sequence of style b.
|
|
153 3. second of a two-character comment-start sequence of style a.
|
|
154 4. second of a two-character comment-start sequence of style b.
|
|
155 5. first of a one or two character comment-end sequence of style a.
|
|
156 6. first of a one or two character comment-end sequence of style b.
|
|
157 7. second of a two-character comment-end sequence of style a.
|
|
158 8. second of a two-character comment-end sequence of style b.
|
|
159 */
|
|
160
|
|
161 #define SYNTAX_COMMENT_BITS(table, c) \
|
|
162 ((SYNTAX_CODE (table, c) >> 16) &0xff)
|
|
163
|
|
164 #define SYNTAX_FIRST_OF_START_A 0x80
|
|
165 #define SYNTAX_FIRST_OF_START_B 0x40
|
|
166 #define SYNTAX_SECOND_OF_START_A 0x20
|
|
167 #define SYNTAX_SECOND_OF_START_B 0x10
|
|
168 #define SYNTAX_FIRST_OF_END_A 0x08
|
|
169 #define SYNTAX_FIRST_OF_END_B 0x04
|
|
170 #define SYNTAX_SECOND_OF_END_A 0x02
|
|
171 #define SYNTAX_SECOND_OF_END_B 0x01
|
|
172
|
|
173 #define SYNTAX_COMMENT_STYLE_A 0xaa
|
|
174 #define SYNTAX_COMMENT_STYLE_B 0x55
|
|
175 #define SYNTAX_FIRST_CHAR_START 0xc0
|
|
176 #define SYNTAX_FIRST_CHAR_END 0x0c
|
|
177 #define SYNTAX_FIRST_CHAR 0xcc
|
|
178 #define SYNTAX_SECOND_CHAR_START 0x30
|
|
179 #define SYNTAX_SECOND_CHAR_END 0x03
|
|
180 #define SYNTAX_SECOND_CHAR 0x33
|
|
181
|
|
182 #define SYNTAX_START_P(table, a, b) \
|
|
183 ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_START) \
|
|
184 && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_START))
|
|
185
|
|
186 #define SYNTAX_END_P(table, a, b) \
|
|
187 ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_END) \
|
|
188 && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_END))
|
|
189
|
|
190 #define SYNTAX_STYLES_MATCH_START_P(table, a, b, mask) \
|
|
191 ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_START & (mask)) \
|
|
192 && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_START & (mask)))
|
|
193
|
|
194 #define SYNTAX_STYLES_MATCH_END_P(table, a, b, mask) \
|
|
195 ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_END & (mask)) \
|
|
196 && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_END & (mask)))
|
|
197
|
|
198 #define SYNTAX_STYLES_MATCH_1CHAR_P(table, a, mask) \
|
|
199 ((SYNTAX_COMMENT_BITS (table, a) & (mask)))
|
|
200
|
|
201 #define STYLE_FOUND_P(table, a, b, startp, style) \
|
|
202 ((SYNTAX_COMMENT_BITS (table, a) & \
|
|
203 ((startp) ? SYNTAX_FIRST_CHAR_START : \
|
|
204 SYNTAX_FIRST_CHAR_END) & (style)) \
|
|
205 && (SYNTAX_COMMENT_BITS (table, b) & \
|
|
206 ((startp) ? SYNTAX_SECOND_CHAR_START : \
|
|
207 SYNTAX_SECOND_CHAR_END) & (style)))
|
|
208
|
|
209 #define SYNTAX_COMMENT_MASK_START(table, a, b) \
|
|
210 ((STYLE_FOUND_P (table, a, b, 1, SYNTAX_COMMENT_STYLE_A) \
|
|
211 ? SYNTAX_COMMENT_STYLE_A \
|
|
212 : (STYLE_FOUND_P (table, a, b, 1, SYNTAX_COMMENT_STYLE_B) \
|
|
213 ? SYNTAX_COMMENT_STYLE_B \
|
|
214 : 0)))
|
|
215
|
|
216 #define SYNTAX_COMMENT_MASK_END(table, a, b) \
|
|
217 ((STYLE_FOUND_P (table, a, b, 0, SYNTAX_COMMENT_STYLE_A) \
|
|
218 ? SYNTAX_COMMENT_STYLE_A \
|
|
219 : (STYLE_FOUND_P (table, a, b, 0, SYNTAX_COMMENT_STYLE_B) \
|
|
220 ? SYNTAX_COMMENT_STYLE_B \
|
|
221 : 0)))
|
|
222
|
|
223 #define STYLE_FOUND_1CHAR_P(table, a, style) \
|
|
224 ((SYNTAX_COMMENT_BITS (table, a) & (style)))
|
|
225
|
|
226 #define SYNTAX_COMMENT_1CHAR_MASK(table, a) \
|
|
227 ((STYLE_FOUND_1CHAR_P (table, a, SYNTAX_COMMENT_STYLE_A) \
|
|
228 ? SYNTAX_COMMENT_STYLE_A \
|
|
229 : (STYLE_FOUND_1CHAR_P (table, a, SYNTAX_COMMENT_STYLE_B) \
|
|
230 ? SYNTAX_COMMENT_STYLE_B \
|
|
231 : 0)))
|
|
232
|
2
|
233 /* This array, indexed by a character, contains the syntax code which
|
|
234 that character signifies (as a char).
|
|
235 For example, (enum syntaxcode) syntax_spec_code['w'] is Sword. */
|
0
|
236
|
|
237 extern CONST unsigned char syntax_spec_code[0400];
|
|
238
|
|
239 /* Indexed by syntax code, give the letter that describes it. */
|
|
240
|
|
241 extern CONST unsigned char syntax_code_spec[];
|
|
242
|
|
243 Lisp_Object scan_lists (struct buffer *buf, int from, int count,
|
|
244 int depth, int sexpflag, int no_error);
|
|
245 int char_quoted (struct buffer *buf, int pos);
|
|
246
|
|
247 /* NOTE: This does not refer to the mirror table, but to the
|
|
248 syntax table itself. */
|
|
249 Lisp_Object syntax_match (Lisp_Object table, Emchar ch);
|
|
250
|
|
251 extern int no_quit_in_re_search;
|
|
252 extern struct buffer *regex_emacs_buffer;
|
|
253
|
70
|
254 void update_syntax_table (struct Lisp_Char_Table *ct);
|
|
255
|
0
|
256 #endif /* _XEMACS_SYNTAX_H_ */
|