Mercurial > emacs
comparison src/syntax.h @ 17465:8a008f65c8d4
(enum syntaxcode): New members Scomment_fence, Sstring_fence.
(SYNTAX_ENTRY): Depending on the value of SYNTAX_ENTRY_VIA_PROPERTY
may do a lookup for syntax table in gl_state.
(UPDATE_SYNTAX_TABLE_FORWARD, UPDATE_SYNTAX_TABLE_BACKWARD,
UPDATE_SYNTAX_TABLE, SETUP_SYNTAX_TABLE,
SETUP_SYNTAX_TABLE_FOR_OBJECT): New macros.
(struct gl_state_s): New struct.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 15 Apr 1997 04:56:10 +0000 |
parents | 156896ccc86e |
children | 614b916ff5bf |
comparison
equal
deleted
inserted
replaced
17464:36483a1ada24 | 17465:8a008f65c8d4 |
---|---|
1 /* Declarations having to do with GNU Emacs syntax tables. | 1 /* Declarations having to do with GNU Emacs syntax tables. |
2 Copyright (C) 1985, 1993, 1994 Free Software Foundation, Inc. | 2 Copyright (C) 1985, 1993, 1994, 1997 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GNU Emacs. | 4 This file is part of GNU Emacs. |
5 | 5 |
6 GNU Emacs is free software; you can redistribute it and/or modify | 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 | 7 it under the terms of the GNU General Public License as published by |
19 Boston, MA 02111-1307, USA. */ | 19 Boston, MA 02111-1307, USA. */ |
20 | 20 |
21 | 21 |
22 extern Lisp_Object Qsyntax_table_p; | 22 extern Lisp_Object Qsyntax_table_p; |
23 extern Lisp_Object Fsyntax_table_p (), Fsyntax_table (), Fset_syntax_table (); | 23 extern Lisp_Object Fsyntax_table_p (), Fsyntax_table (), Fset_syntax_table (); |
24 extern void update_syntax_table (); | |
24 | 25 |
25 /* The standard syntax table is stored where it will automatically | 26 /* The standard syntax table is stored where it will automatically |
26 be used in all new buffers. */ | 27 be used in all new buffers. */ |
27 #define Vstandard_syntax_table buffer_defaults.syntax_table | 28 #define Vstandard_syntax_table buffer_defaults.syntax_table |
28 | 29 |
40 Ssymbol, /* symbol constituent but not word constituent */ | 41 Ssymbol, /* symbol constituent but not word constituent */ |
41 Sopen, /* for a beginning delimiter */ | 42 Sopen, /* for a beginning delimiter */ |
42 Sclose, /* for an ending delimiter */ | 43 Sclose, /* for an ending delimiter */ |
43 Squote, /* for a prefix character like Lisp ' */ | 44 Squote, /* for a prefix character like Lisp ' */ |
44 Sstring, /* for a string-grouping character like Lisp " */ | 45 Sstring, /* for a string-grouping character like Lisp " */ |
45 Smath, /* for delimiters like $ in Tex. */ | 46 Smath, /* for delimiters like $ in Tex. */ |
46 Sescape, /* for a character that begins a C-style escape */ | 47 Sescape, /* for a character that begins a C-style escape */ |
47 Scharquote, /* for a character that quotes the following character */ | 48 Scharquote, /* for a character that quotes the following character */ |
48 Scomment, /* for a comment-starting character */ | 49 Scomment, /* for a comment-starting character */ |
49 Sendcomment, /* for a comment-ending character */ | 50 Sendcomment, /* for a comment-ending character */ |
50 Sinherit, /* use the standard syntax table for this character */ | 51 Sinherit, /* use the standard syntax table for this character */ |
52 Scomment_fence, /* Starts/ends comment which is delimited on the | |
53 other side by a char with the same syntaxcode. */ | |
54 Sstring_fence, /* Starts/ends string which is delimited on the | |
55 other side by a char with the same syntaxcode. */ | |
51 Smax /* Upper bound on codes that are meaningful */ | 56 Smax /* Upper bound on codes that are meaningful */ |
52 }; | 57 }; |
53 | 58 |
54 /* Set the syntax entry VAL for char C in table TABLE. */ | 59 /* Set the syntax entry VAL for char C in table TABLE. */ |
55 | 60 |
83 (NILP (syntax_temp) \ | 88 (NILP (syntax_temp) \ |
84 ? syntax_parent_lookup (table, (c)) \ | 89 ? syntax_parent_lookup (table, (c)) \ |
85 : syntax_temp)) | 90 : syntax_temp)) |
86 #endif | 91 #endif |
87 | 92 |
88 /* Fetch the syntax entry for char C in the current syntax table. | 93 /* SYNTAX_ENTRY fetches the information from the entry for character C |
89 This returns the whole entry (normally a cons cell). | 94 in syntax table TABLE, or from globally kept data (gl_state). |
90 Do Inheritance. */ | 95 Does inheritance. */ |
91 | 96 /* CURRENT_SYNTAX_TABLE gives the syntax table valid for current |
92 #define SYNTAX_ENTRY(c) \ | 97 position, it is either the buffer's syntax table, or syntax table |
98 found in text properties. */ | |
99 | |
100 #ifdef SYNTAX_ENTRY_VIA_PROPERTY | |
101 # define SYNTAX_ENTRY(c) \ | |
102 (gl_state.use_global ? gl_state.global_code : SYNTAX_ENTRY_INT (c)) | |
103 # define CURRENT_SYNTAX_TABLE gl_state.current_syntax_table | |
104 #else | |
105 # define SYNTAX_ENTRY SYNTAX_ENTRY_INT | |
106 # define CURRENT_SYNTAX_TABLE current_buffer->syntax_table | |
107 #endif | |
108 | |
109 #define SYNTAX_ENTRY_INT(c) \ | |
93 ((c) < CHAR_TABLE_SINGLE_BYTE_SLOTS \ | 110 ((c) < CHAR_TABLE_SINGLE_BYTE_SLOTS \ |
94 ? SYNTAX_ENTRY_FOLLOW_PARENT (current_buffer->syntax_table, \ | 111 ? SYNTAX_ENTRY_FOLLOW_PARENT (CURRENT_SYNTAX_TABLE, \ |
95 (unsigned char) (c)) \ | 112 (unsigned char) (c)) \ |
96 : Faref (current_buffer->syntax_table, make_number ((c)))) | 113 : Faref (CURRENT_SYNTAX_TABLE, make_number ((c)))) |
97 | |
98 | 114 |
99 /* Extract the information from the entry for character C | 115 /* Extract the information from the entry for character C |
100 in the current syntax table. */ | 116 in the current syntax table. */ |
101 | 117 |
102 #ifdef __GNUC__ | 118 #ifdef __GNUC__ |
150 and whose second character has flag 2 will be interpreted as a comment start. | 166 and whose second character has flag 2 will be interpreted as a comment start. |
151 | 167 |
152 bit 6 is used to discriminate between two different comment styles. | 168 bit 6 is used to discriminate between two different comment styles. |
153 Languages such as C++ allow two orthogonal syntax start/end pairs | 169 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 | 170 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. | 171 ends style a or b. Comment start sequences can start style a or b. |
156 Style a is always the default. | 172 Style a is always the default. |
157 */ | 173 */ |
158 | 174 |
159 #define SYNTAX_COMSTART_FIRST(c) ((SYNTAX_WITH_FLAGS (c) >> 16) & 1) | 175 #define SYNTAX_COMSTART_FIRST(c) ((SYNTAX_WITH_FLAGS (c) >> 16) & 1) |
160 | 176 |
169 /* extract the comment style bit from the syntax table entry */ | 185 /* extract the comment style bit from the syntax table entry */ |
170 #define SYNTAX_COMMENT_STYLE(c) ((SYNTAX_WITH_FLAGS (c) >> 21) & 1) | 186 #define SYNTAX_COMMENT_STYLE(c) ((SYNTAX_WITH_FLAGS (c) >> 21) & 1) |
171 | 187 |
172 /* This array, indexed by a character, contains the syntax code which that | 188 /* This array, indexed by a character, contains the syntax code which that |
173 character signifies (as a char). For example, | 189 character signifies (as a char). For example, |
174 (enum syntaxcode) syntax_spec_code['w'] is Sword. */ | 190 (enum syntaxcode) syntax_spec_code['w'] is Sword. */ |
175 | 191 |
176 extern unsigned char syntax_spec_code[0400]; | 192 extern unsigned char syntax_spec_code[0400]; |
177 | 193 |
178 /* Indexed by syntax code, give the letter that describes it. */ | 194 /* Indexed by syntax code, give the letter that describes it. */ |
179 | 195 |
180 extern char syntax_code_spec[14]; | 196 extern char syntax_code_spec[16]; |
197 | |
198 /* Make syntax table state (gl_state) good for POS, assuming it is | |
199 currently good for a position before POS. */ | |
200 #define UPDATE_SYNTAX_TABLE_FORWARD(pos) \ | |
201 ((pos) >= gl_state.e_property ? \ | |
202 ( update_syntax_table ((pos), 1, 0), 1 ) : 0) | |
203 | |
204 | |
205 /* Make syntax table state (gl_state) good for POS, assuming it is | |
206 currently good for a position after POS. */ | |
207 #define UPDATE_SYNTAX_TABLE_BACKWARD(pos) \ | |
208 ((pos) <= gl_state.b_property ? \ | |
209 ( update_syntax_table ((pos), -1, 0), 1 ) : 0) | |
210 | |
211 /* Make syntax table good for POS. */ | |
212 #define UPDATE_SYNTAX_TABLE(pos) \ | |
213 ((pos) <= gl_state.b_property ? \ | |
214 ( update_syntax_table ((pos), -1, 0), 1 ) : \ | |
215 ( (pos) >= gl_state.e_property ? \ | |
216 ( update_syntax_table ((pos), 1, 0), 1 ) : 0)) | |
217 | |
218 /* This macro should be called with FROM at the start of forward | |
219 search, or after the last position of the backward search. It | |
220 makes sure that the first char is picked up with correct table, so | |
221 one does not need to call UPDATE_SYNTAX_TABLE immediately after the | |
222 call. | |
223 Sign of COUNT gives the direction of the search. | |
224 */ | |
225 | |
226 #define SETUP_SYNTAX_TABLE(from,count) \ | |
227 gl_state.b_property = BEGV - 1; \ | |
228 gl_state.e_property = ZV + 1; \ | |
229 gl_state.use_global = 0; \ | |
230 gl_state.current_syntax_table = current_buffer->syntax_table; \ | |
231 if (parse_sexp_lookup_properties) \ | |
232 update_syntax_table ((count) > 0 ? (from) : (from) - 1, (count), 1, Qnil); | |
233 | |
234 /* Same as above, but in OBJECT. If OBJECT is nil, use current buffer. | |
235 If it is t, ignore properties altogether. */ | |
236 | |
237 #define SETUP_SYNTAX_TABLE_FOR_OBJECT(object, from, count) \ | |
238 if (BUFFERP (object)) \ | |
239 { \ | |
240 gl_state.b_property = BEGV - 1; \ | |
241 gl_state.e_property = ZV; \ | |
242 } \ | |
243 else if (EQ (object, Qt)) \ | |
244 { \ | |
245 gl_state.b_property = - 1; \ | |
246 gl_state.e_property = 1500000000; \ | |
247 } \ | |
248 else \ | |
249 { \ | |
250 gl_state.b_property = -1; \ | |
251 gl_state.e_property = 1 + XSTRING (object)->size; \ | |
252 } \ | |
253 gl_state.use_global = 0; \ | |
254 gl_state.current_syntax_table = current_buffer->syntax_table; \ | |
255 if (parse_sexp_lookup_properties) \ | |
256 update_syntax_table (count > 0 ? (from) : (from) - 1, count, 1, object); | |
257 | |
258 struct gl_state_s | |
259 { | |
260 int start; /* Where to stop. */ | |
261 int stop; /* Where to stop. */ | |
262 int use_global; /* Whether to use global_code | |
263 or c_s_t. */ | |
264 Lisp_Object global_code; /* Syntax code of current char. */ | |
265 Lisp_Object current_syntax_table; /* Syntax table for current pos. */ | |
266 Lisp_Object old_prop; /* Syntax-table prop at prev pos. */ | |
267 int b_property; /* Last index where c_s_t is | |
268 not valid. */ | |
269 int e_property; /* First index where c_s_t is | |
270 not valid. */ | |
271 INTERVAL forward_i; /* Where to start lookup on forward */ | |
272 INTERVAL backward_i; /* or backward movement. The | |
273 data in c_s_t is valid | |
274 between these intervals, | |
275 and possibly at the | |
276 intervals too, depending | |
277 on: */ | |
278 char left_ok; | |
279 char right_ok; | |
280 }; | |
281 | |
282 extern struct gl_state_s gl_state; | |
283 extern int parse_sexp_lookup_properties; | |
284 extern INTERVAL interval_of(); |