Mercurial > hg > xemacs-beta
comparison src/syntax.h @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | ac2d302a0011 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
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 | |
26 /* The standard syntax table is stored where it will automatically | |
27 be used in all new buffers. */ | |
28 extern Lisp_Object Vstandard_syntax_table; | |
29 | |
30 /* A syntax table is a Lisp vector of length 0400, whose elements are integers. | |
31 | |
32 The low 7 bits of the integer is a code, as follows. The 8th bit is | |
33 used as the prefix bit flag (see below). | |
34 */ | |
35 | |
36 enum syntaxcode | |
37 { | |
38 Swhitespace, /* for a whitespace character */ | |
39 Spunct, /* for random punctuation characters */ | |
40 Sword, /* for a word constituent */ | |
41 Ssymbol, /* symbol constituent but not word constituent */ | |
42 Sopen, /* for a beginning delimiter */ | |
43 Sclose, /* for an ending delimiter */ | |
44 Squote, /* for a prefix character like Lisp ' */ | |
45 Sstring, /* for a string-grouping character like Lisp " */ | |
46 Smath, /* for delimiters like $ in Tex. */ | |
47 Sescape, /* for a character that begins a C-style escape */ | |
48 Scharquote, /* for a character that quotes the following character */ | |
49 Scomment, /* for a comment-starting character */ | |
50 Sendcomment, /* for a comment-ending character */ | |
51 Sinherit, /* use the standard syntax table for this character */ | |
52 Sextword, /* extended word; works mostly like a word constituent. | |
53 See the comment in syntax.c. */ | |
54 Smax /* Upper bound on codes that are meaningful */ | |
55 }; | |
56 | |
57 extern Lisp_Object Qsyntax_table_p; | |
58 Lisp_Object Fsyntax_table_p (Lisp_Object); | |
59 Lisp_Object Fsyntax_table (Lisp_Object); | |
60 Lisp_Object Fset_syntax_table (Lisp_Object, Lisp_Object); | |
61 | |
62 /* Return the raw syntax code for a particular character and table */ | |
63 #define RAW_SYNTAX_CODE_UNSAFE(table, c) \ | |
64 (XINT (vector_data (XVECTOR (table))[(unsigned char) (c)])) | |
65 | |
66 /* Return the syntax code for a particular character and table, taking | |
67 into account inheritance. */ | |
68 | |
69 /* Unfortunately, we cannot write SYNTAX_CODE() as a safe macro in | |
70 general. I tried just using an inline function but that causes | |
71 significant slowdown (esp. in regex routines) because this macro | |
72 is called so many millions of times. So instead we resort to | |
73 SYNTAX_CODE_UNSAFE(), which is used most of the time. Under | |
74 GCC we can actually write this as a safe macro, and we do because | |
75 it's likely to lead to speedups. */ | |
76 | |
77 #ifdef __GNUC__ | |
78 #define SYNTAX_CODE_UNSAFE(table, c) \ | |
79 ({ Emchar _ch_ = (c); \ | |
80 int _rawcode_ = RAW_SYNTAX_CODE_UNSAFE (table, _ch_); \ | |
81 if ((enum syntaxcode) (_rawcode_ & 0177) == Sinherit) \ | |
82 _rawcode_ = RAW_SYNTAX_CODE_UNSAFE (Vstandard_syntax_table, _ch_); \ | |
83 _rawcode_; }) | |
84 #else | |
85 #define SYNTAX_CODE_UNSAFE(table, c) \ | |
86 (RAW_SYNTAX_CODE_UNSAFE (table, c) == Sinherit \ | |
87 ? RAW_SYNTAX_CODE_UNSAFE (Vstandard_syntax_table, c) \ | |
88 : RAW_SYNTAX_CODE_UNSAFE (table, c)) | |
89 #endif | |
90 | |
91 INLINE int SYNTAX_CODE (Lisp_Object table, Emchar c); | |
92 INLINE int | |
93 SYNTAX_CODE (Lisp_Object table, Emchar c) | |
94 { | |
95 return SYNTAX_CODE_UNSAFE (table, c); | |
96 } | |
97 | |
98 #define SYNTAX_UNSAFE(table, c) \ | |
99 ((enum syntaxcode) (SYNTAX_CODE_UNSAFE (table, c) & 0177)) | |
100 | |
101 #define SYNTAX_FROM_CODE(code) ((enum syntaxcode) ((code) & 0177)) | |
102 #define SYNTAX(table, c) SYNTAX_FROM_CODE (SYNTAX_CODE (table, c)) | |
103 | |
104 INLINE int WORD_SYNTAX_P (Lisp_Object table, Emchar c); | |
105 INLINE int | |
106 WORD_SYNTAX_P (Lisp_Object table, Emchar c) | |
107 { | |
108 int syncode = SYNTAX (table, c); | |
109 return syncode == Sword || syncode == Sextword; | |
110 } | |
111 | |
112 /* The prefix flag bit for backward-prefix-chars is now put into bit 7. */ | |
113 | |
114 #define SYNTAX_PREFIX_UNSAFE(table, c) \ | |
115 ((SYNTAX_CODE_UNSAFE (table, c) >> 7) & 1) | |
116 #define SYNTAX_PREFIX(table, c) \ | |
117 ((SYNTAX_CODE (table, c) >> 7) & 1) | |
118 | |
119 /* The next 8 bits of the number is a character, | |
120 the matching delimiter in the case of Sopen or Sclose. */ | |
121 | |
122 #define SYNTAX_MATCH(table, c) \ | |
123 ((SYNTAX_CODE (table, c) >> 8) & 0377) | |
124 | |
125 /* The next 8 bits are used to implement up to two comment styles | |
126 in a single buffer. They have the following meanings: | |
127 | |
128 1. first of a one or two character comment-start sequence of style a. | |
129 2. first of a one or two character comment-start sequence of style b. | |
130 3. second of a two-character comment-start sequence of style a. | |
131 4. second of a two-character comment-start sequence of style b. | |
132 5. first of a one or two character comment-end sequence of style a. | |
133 6. first of a one or two character comment-end sequence of style b. | |
134 7. second of a two-character comment-end sequence of style a. | |
135 8. second of a two-character comment-end sequence of style b. | |
136 */ | |
137 | |
138 #define SYNTAX_COMMENT_BITS(table, c) \ | |
139 ((SYNTAX_CODE (table, c) >> 16) &0xff) | |
140 | |
141 #define SYNTAX_FIRST_OF_START_A 0x80 | |
142 #define SYNTAX_FIRST_OF_START_B 0x40 | |
143 #define SYNTAX_SECOND_OF_START_A 0x20 | |
144 #define SYNTAX_SECOND_OF_START_B 0x10 | |
145 #define SYNTAX_FIRST_OF_END_A 0x08 | |
146 #define SYNTAX_FIRST_OF_END_B 0x04 | |
147 #define SYNTAX_SECOND_OF_END_A 0x02 | |
148 #define SYNTAX_SECOND_OF_END_B 0x01 | |
149 | |
150 #define SYNTAX_COMMENT_STYLE_A 0xaa | |
151 #define SYNTAX_COMMENT_STYLE_B 0x55 | |
152 #define SYNTAX_FIRST_CHAR_START 0xc0 | |
153 #define SYNTAX_FIRST_CHAR_END 0x0c | |
154 #define SYNTAX_FIRST_CHAR 0xcc | |
155 #define SYNTAX_SECOND_CHAR_START 0x30 | |
156 #define SYNTAX_SECOND_CHAR_END 0x03 | |
157 #define SYNTAX_SECOND_CHAR 0x33 | |
158 | |
159 #define SYNTAX_START_P(table, a, b) \ | |
160 ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_START) \ | |
161 && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_START)) | |
162 | |
163 #define SYNTAX_END_P(table, a, b) \ | |
164 ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_END) \ | |
165 && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_END)) | |
166 | |
167 #define SYNTAX_STYLES_MATCH_START_P(table, a, b, mask) \ | |
168 ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_START & (mask)) \ | |
169 && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_START & (mask))) | |
170 | |
171 #define SYNTAX_STYLES_MATCH_END_P(table, a, b, mask) \ | |
172 ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_END & (mask)) \ | |
173 && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_END & (mask))) | |
174 | |
175 #define SYNTAX_STYLES_MATCH_1CHAR_P(table, a, mask) \ | |
176 ((SYNTAX_COMMENT_BITS (table, a) & (mask))) | |
177 | |
178 #define STYLE_FOUND_P(table, a, b, startp, style) \ | |
179 ((SYNTAX_COMMENT_BITS (table, a) & \ | |
180 ((startp) ? SYNTAX_FIRST_CHAR_START : \ | |
181 SYNTAX_FIRST_CHAR_END) & (style)) \ | |
182 && (SYNTAX_COMMENT_BITS (table, b) & \ | |
183 ((startp) ? SYNTAX_SECOND_CHAR_START : \ | |
184 SYNTAX_SECOND_CHAR_END) & (style))) | |
185 | |
186 #define SYNTAX_COMMENT_MASK_START(table, a, b) \ | |
187 ((STYLE_FOUND_P (table, a, b, 1, SYNTAX_COMMENT_STYLE_A) \ | |
188 ? SYNTAX_COMMENT_STYLE_A \ | |
189 : (STYLE_FOUND_P (table, a, b, 1, SYNTAX_COMMENT_STYLE_B) \ | |
190 ? SYNTAX_COMMENT_STYLE_B \ | |
191 : 0))) | |
192 | |
193 #define SYNTAX_COMMENT_MASK_END(table, a, b) \ | |
194 ((STYLE_FOUND_P (table, a, b, 0, SYNTAX_COMMENT_STYLE_A) \ | |
195 ? SYNTAX_COMMENT_STYLE_A \ | |
196 : (STYLE_FOUND_P (table, a, b, 0, SYNTAX_COMMENT_STYLE_B) \ | |
197 ? SYNTAX_COMMENT_STYLE_B \ | |
198 : 0))) | |
199 | |
200 #define STYLE_FOUND_1CHAR_P(table, a, style) \ | |
201 ((SYNTAX_COMMENT_BITS (table, a) & (style))) | |
202 | |
203 #define SYNTAX_COMMENT_1CHAR_MASK(table, a) \ | |
204 ((STYLE_FOUND_1CHAR_P (table, a, SYNTAX_COMMENT_STYLE_A) \ | |
205 ? SYNTAX_COMMENT_STYLE_A \ | |
206 : (STYLE_FOUND_1CHAR_P (table, a, SYNTAX_COMMENT_STYLE_B) \ | |
207 ? SYNTAX_COMMENT_STYLE_B \ | |
208 : 0))) | |
209 | |
210 /* This array, indexed by a character, contains the syntax code which that | |
211 character signifies (as a char). For example, | |
212 (enum syntaxcode) syntax_spec_code['w'] is Sword. */ | |
213 | |
214 extern CONST unsigned char syntax_spec_code[0400]; | |
215 | |
216 /* Indexed by syntax code, give the letter that describes it. */ | |
217 | |
218 extern CONST unsigned char syntax_code_spec[]; | |
219 | |
220 Lisp_Object scan_lists (struct buffer *buf, int from, int count, | |
221 int depth, int sexpflag, int no_error); | |
222 int char_quoted (struct buffer *buf, int pos); | |
223 | |
224 /* NOTE: This does not refer to the mirror table, but to the | |
225 syntax table itself. */ | |
226 Lisp_Object syntax_match (Lisp_Object table, Emchar ch); | |
227 | |
228 extern int no_quit_in_re_search; | |
229 extern struct buffer *regex_emacs_buffer; | |
230 | |
231 #endif /* _XEMACS_SYNTAX_H_ */ |