Merge r21-4-7-utf-2000-5.
[chise/xemacs-chise.git] / src / syntax.h
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
4
5 This file is part of XEmacs.
6
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
10 later version.
11
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
15 for more details.
16
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.  */
21
22 /* Synched up with: FSF 19.28. */
23
24 #ifndef INCLUDED_syntax_h_
25 #define INCLUDED_syntax_h_
26
27 #include "chartab.h"
28
29 /* A syntax table is a type of char table.
30
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).
33
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.
38
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.
47 */
48
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;
52
53 enum syntaxcode
54 {
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   Scomment_fence, /* Starts/ends comment which is delimited on the
70                      other side by a char with the same syntaxcode.  */
71   Sstring_fence,  /* Starts/ends string which is delimited on the
72                      other side by a char with the same syntaxcode.  */
73   Smax   /* Upper bound on codes that are meaningful */
74 };
75
76 enum syntaxcode charset_syntax (struct buffer *buf, Lisp_Object charset,
77                                 int *multi_p_out);
78
79 /* Return the syntax code for a particular character and mirror table. */
80
81 #ifdef UTF2000
82 INLINE_HEADER int SYNTAX_CODE_UNSAFE (Lisp_Char_Table *table, Emchar c);
83 INLINE_HEADER int
84 SYNTAX_CODE_UNSAFE (Lisp_Char_Table *table, Emchar c)
85 {
86   int code = CHAR_TABLE_VALUE_UNSAFE (table, c);
87   int ret = Spunct;
88
89   if (CONSP (code))
90     code = XCAR (code);
91   ret = XINT (code);
92
93   if (ret == Sinherit)
94     {
95       code = CHAR_TABLE_VALUE_UNSAFE (XCHAR_TABLE
96                                       (Vstandard_syntax_table), c);
97       if (CONSP (code))
98         code = XCAR (code);
99       return XINT (code);
100     }
101   else
102     return ret;
103 }
104 #else
105 #define SYNTAX_CODE_UNSAFE(table, c) \
106    XINT (CHAR_TABLE_VALUE_UNSAFE (table, c))
107 #endif
108
109 INLINE_HEADER int SYNTAX_CODE (Lisp_Char_Table *table, Emchar c);
110 INLINE_HEADER int
111 SYNTAX_CODE (Lisp_Char_Table *table, Emchar c)
112 {
113   return SYNTAX_CODE_UNSAFE (table, c);
114 }
115
116 #define SYNTAX_UNSAFE(table, c) \
117   ((enum syntaxcode) (SYNTAX_CODE_UNSAFE (table, c) & 0177))
118
119 #define SYNTAX_FROM_CODE(code) ((enum syntaxcode) ((code) & 0177))
120 #define SYNTAX(table, c) SYNTAX_FROM_CODE (SYNTAX_CODE (table, c))
121
122 INLINE_HEADER int WORD_SYNTAX_P (Lisp_Char_Table *table, Emchar c);
123 INLINE_HEADER int
124 WORD_SYNTAX_P (Lisp_Char_Table *table, Emchar c)
125 {
126   return SYNTAX (table, c) == Sword;
127 }
128
129 /* OK, here's a graphic diagram of the format of the syntax values:
130
131    Bit number:
132
133  [ 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 ]
134  [ 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 ]
135
136    <-----> <-----> <-------------> <-------------> ^  <----------->
137     ELisp  unused  |comment bits |     unused      |   syntax code
138      tag           | | | | | | | |                 |
139     stuff          | | | | | | | |                 |
140                    | | | | | | | |                 |
141                    | | | | | | | |                 `--> prefix flag
142                    | | | | | | | |
143                    | | | | | | | `--> comment end style B, second char
144                    | | | | | | `----> comment end style A, second char
145                    | | | | | `------> comment end style B, first char
146                    | | | | `--------> comment end style A, first char
147                    | | | `----------> comment start style B, second char
148                    | | `------------> comment start style A, second char
149                    | `--------------> comment start style B, first char
150                    `----------------> comment start style A, first char
151
152   In a 64-bit integer, there would be 32 more unused bits between
153   the tag and the comment bits.
154
155   Clearly, such a scheme will not work for Mule, because the matching
156   paren could be any character and as such requires 19 bits, which
157   we don't got.
158
159   Remember that under Mule we use char tables instead of vectors.
160   So what we do is use another char table for the matching paren
161   and store a pointer to it in the first char table. (This frees
162   code from having to worry about passing two tables around.)
163 */
164
165
166 /* The prefix flag bit for backward-prefix-chars is now put into bit 7. */
167
168 #define SYNTAX_PREFIX_UNSAFE(table, c) \
169   ((SYNTAX_CODE_UNSAFE (table, c) >> 7) & 1)
170 #define SYNTAX_PREFIX(table, c) \
171   ((SYNTAX_CODE (table, c) >> 7) & 1)
172
173 /* Bits 23-16 are used to implement up to two comment styles
174    in a single buffer. They have the following meanings:
175
176   1. first of a one or two character comment-start sequence of style a.
177   2. first of a one or two character comment-start sequence of style b.
178   3. second of a two-character comment-start sequence of style a.
179   4. second of a two-character comment-start sequence of style b.
180   5. first of a one or two character comment-end sequence of style a.
181   6. first of a one or two character comment-end sequence of style b.
182   7. second of a two-character comment-end sequence of style a.
183   8. second of a two-character comment-end sequence of style b.
184  */
185
186 #define SYNTAX_COMMENT_BITS(table, c) \
187   ((SYNTAX_CODE (table, c) >> 16) &0xff)
188
189 #define SYNTAX_FIRST_OF_START_A  0x80
190 #define SYNTAX_FIRST_OF_START_B  0x40
191 #define SYNTAX_SECOND_OF_START_A 0x20
192 #define SYNTAX_SECOND_OF_START_B 0x10
193 #define SYNTAX_FIRST_OF_END_A    0x08
194 #define SYNTAX_FIRST_OF_END_B    0x04
195 #define SYNTAX_SECOND_OF_END_A   0x02
196 #define SYNTAX_SECOND_OF_END_B   0x01
197
198 #define SYNTAX_COMMENT_STYLE_A   0xaa
199 #define SYNTAX_COMMENT_STYLE_B   0x55
200 #define SYNTAX_FIRST_CHAR_START  0xc0
201 #define SYNTAX_FIRST_CHAR_END    0x0c
202 #define SYNTAX_FIRST_CHAR        0xcc
203 #define SYNTAX_SECOND_CHAR_START 0x30
204 #define SYNTAX_SECOND_CHAR_END   0x03
205 #define SYNTAX_SECOND_CHAR       0x33
206
207
208 /* #### These are now more or less equivalent to
209    SYNTAX_COMMENT_MATCH_START ...*/
210 /* a and b must be first and second start chars for a common type */
211 #define SYNTAX_START_P(table, a, b)                                     \
212   (((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_START) >> 2)    \
213    & (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_START))
214
215 /* ... and  SYNTAX_COMMENT_MATCH_END */
216 /* a and b must be first and second end chars for a common type */
217 #define SYNTAX_END_P(table, a, b)                                       \
218   (((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_END) >> 2)      \
219    & (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_END))
220
221 #define SYNTAX_STYLES_MATCH_START_P(table, a, b, mask)                      \
222   ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_START & (mask))      \
223    && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_START & (mask)))
224
225 #define SYNTAX_STYLES_MATCH_END_P(table, a, b, mask)                      \
226   ((SYNTAX_COMMENT_BITS (table, a) & SYNTAX_FIRST_CHAR_END & (mask))      \
227    && (SYNTAX_COMMENT_BITS (table, b) & SYNTAX_SECOND_CHAR_END & (mask)))
228
229 #define SYNTAX_STYLES_MATCH_1CHAR_P(table, a, mask)     \
230   ((SYNTAX_COMMENT_BITS (table, a) & (mask)))
231
232 #define STYLE_FOUND_P(table, a, b, startp, style)       \
233   ((SYNTAX_COMMENT_BITS (table, a) &                    \
234     ((startp) ? SYNTAX_FIRST_CHAR_START :               \
235      SYNTAX_FIRST_CHAR_END) & (style))                  \
236    && (SYNTAX_COMMENT_BITS (table, b) &                 \
237     ((startp) ? SYNTAX_SECOND_CHAR_START :              \
238      SYNTAX_SECOND_CHAR_END) & (style)))
239
240 #define SYNTAX_COMMENT_MASK_START(table, a, b)                  \
241   ((STYLE_FOUND_P (table, a, b, 1, SYNTAX_COMMENT_STYLE_A)      \
242     ? SYNTAX_COMMENT_STYLE_A                                    \
243     : (STYLE_FOUND_P (table, a, b, 1, SYNTAX_COMMENT_STYLE_B)   \
244          ? SYNTAX_COMMENT_STYLE_B                               \
245          : 0)))
246
247 #define SYNTAX_COMMENT_MASK_END(table, a, b)                    \
248   ((STYLE_FOUND_P (table, a, b, 0, SYNTAX_COMMENT_STYLE_A)      \
249    ? SYNTAX_COMMENT_STYLE_A                                     \
250    : (STYLE_FOUND_P (table, a, b, 0, SYNTAX_COMMENT_STYLE_B)    \
251       ? SYNTAX_COMMENT_STYLE_B                                  \
252       : 0)))
253
254 #define STYLE_FOUND_1CHAR_P(table, a, style)    \
255   ((SYNTAX_COMMENT_BITS (table, a) & (style)))
256
257 #define SYNTAX_COMMENT_1CHAR_MASK(table, a)                     \
258   ((STYLE_FOUND_1CHAR_P (table, a, SYNTAX_COMMENT_STYLE_A)      \
259    ? SYNTAX_COMMENT_STYLE_A                                     \
260    : (STYLE_FOUND_1CHAR_P (table, a, SYNTAX_COMMENT_STYLE_B)    \
261       ? SYNTAX_COMMENT_STYLE_B                                  \
262          : 0)))
263
264 EXFUN (Fchar_syntax, 2);
265 EXFUN (Fforward_word, 2);
266
267 /* This array, indexed by a character, contains the syntax code which
268    that character signifies (as a char).
269    For example, (enum syntaxcode) syntax_spec_code['w'] is Sword. */
270
271 extern const unsigned char syntax_spec_code[0400];
272
273 /* Indexed by syntax code, give the letter that describes it. */
274
275 extern const unsigned char syntax_code_spec[];
276
277 Lisp_Object scan_lists (struct buffer *buf, Bufpos from, int count,
278                         int depth, int sexpflag, int no_error);
279 int char_quoted (struct buffer *buf, Bufpos pos);
280
281 /* NOTE: This does not refer to the mirror table, but to the
282    syntax table itself. */
283 Lisp_Object syntax_match (Lisp_Object table, Emchar ch);
284
285 extern int no_quit_in_re_search;
286 extern struct buffer *regex_emacs_buffer;
287
288 /* This is the string or buffer in which we are matching.  It is used
289    for looking up syntax properties.  */
290 extern Lisp_Object regex_match_object;
291
292 #ifndef UTF2000
293 void update_syntax_table (Lisp_Char_Table *ct);
294 #endif
295
296 #ifdef emacs
297
298 extern int lookup_syntax_properties;
299
300 struct syntax_cache
301 {
302   int use_code;                         /* Whether to use syntax_code
303                                            or current_syntax_table. */
304   struct buffer* buffer;                /* The buffer the current syntax cache
305                                            applies to. */
306   Lisp_Object object;                   /* The buffer or string the current
307                                            syntax cache applies to. */
308   int syntax_code;                      /* Syntax code of current char. */
309   Lisp_Object current_syntax_table;     /* Syntax table for current pos. */
310   Lisp_Object old_prop;                 /* Syntax-table prop at prev pos. */
311
312   Bufpos next_change;                   /* Position of the next extent
313                                            change. */
314   Bufpos prev_change;                   /* Position of the previous
315                                            extent change. */
316 };
317 extern struct syntax_cache syntax_cache;
318
319 void update_syntax_cache (int pos, int count, int init);
320
321 /* Make syntax cache state good for CHARPOS, assuming it is
322    currently good for a position before CHARPOS.  */
323 #define UPDATE_SYNTAX_CACHE_FORWARD(pos)        \
324    (lookup_syntax_properties                    \
325     ? (update_syntax_cache ((pos), 1, 0), 1)    \
326     : 0)
327
328 /* Make syntax cache state good for CHARPOS, assuming it is
329    currently good for a position after CHARPOS.  */
330 #define UPDATE_SYNTAX_CACHE_BACKWARD(pos)       \
331    (lookup_syntax_properties                    \
332     ? (update_syntax_cache ((pos), -1, 0), 1)   \
333     : 0)
334
335 /* Make syntax cache state good for CHARPOS */
336 #define UPDATE_SYNTAX_CACHE(pos)                \
337    (lookup_syntax_properties                    \
338     ? (update_syntax_cache ((pos), 0, 0), 1)    \
339     : 0)
340
341 #define SYNTAX_FROM_CACHE(table, c)                     \
342    SYNTAX_FROM_CODE (SYNTAX_CODE_FROM_CACHE (table, c))
343
344 #define SYNTAX_CODE_FROM_CACHE(table, c)                                \
345   ( syntax_cache.use_code                                               \
346       ? syntax_cache.syntax_code                                        \
347       : SYNTAX_CODE (XCHAR_TABLE (syntax_cache.current_syntax_table),   \
348                      c)                                                 \
349  )
350
351 /* Convert the byte offset BYTEPOS into a character position,
352    for the object recorded in syntax_cache with SETUP_SYNTAX_TABLE_FOR_OBJECT.
353
354    The value is meant for use in the UPDATE_SYNTAX_TABLE... macros.
355    These macros do nothing when parse_sexp_lookup_properties is 0,
356    so we return 0 in that case, for speed.  */
357 #define SYNTAX_CACHE_BYTE_TO_CHAR(bytepos)                                      \
358   (! lookup_syntax_properties                                                   \
359    ? 0                                                                          \
360    : STRINGP (syntax_cache.object)                                              \
361    ? bytecount_to_charcount (XSTRING_DATA (syntax_cache.object), bytepos)       \
362    : (BUFFERP (syntax_cache.object) || NILP (syntax_cache.object))              \
363    ? bytind_to_bufpos (syntax_cache.buffer,                                     \
364                        bytepos + BI_BUF_BEGV (syntax_cache.buffer))             \
365    : (bytepos))
366
367 #define SYNTAX_CACHE_OBJECT_BYTE_TO_CHAR(obj, buf, bytepos)     \
368   (! lookup_syntax_properties                                   \
369    ? 0                                                          \
370    : STRINGP (obj)                                              \
371    ? bytecount_to_charcount (XSTRING_DATA (obj), bytepos)       \
372    : (BUFFERP (obj) || NILP (obj))                              \
373    ? bytind_to_bufpos (buf, bytepos + BI_BUF_BEGV (buf))        \
374    : (bytepos))
375
376 #else  /* not emacs */
377
378 #define update_syntax_cache(pos, count, init)
379 #define UPDATE_SYNTAX_CACHE_FORWARD(pos)
380 #define UPDATE_SYNTAX_CACHE_BACKWARD(pos)
381 #define UPDATE_SYNTAX_CACHE(pos)
382 #define SYNTAX_FROM_CACHE SYNTAX
383 #define SYNTAX_CODE_FROM_CACHE SYNTAX_CODE
384
385 #endif /* emacs */
386
387 #ifdef UTF2000
388 #define SETUP_SYNTAX_CACHE(FROM, COUNT)                         \
389   do {                                                          \
390     syntax_cache.buffer = current_buffer;                       \
391     syntax_cache.object = Qnil;                                 \
392     syntax_cache.current_syntax_table                           \
393       = current_buffer->syntax_table;                           \
394     syntax_cache.use_code = 0;                                  \
395     if (lookup_syntax_properties)                               \
396       update_syntax_cache ((COUNT) > 0 ? (FROM) : (FROM) - 1,   \
397                            (COUNT), 1);                         \
398   } while (0)
399 #else
400 #define SETUP_SYNTAX_CACHE(FROM, COUNT)                         \
401   do {                                                          \
402     syntax_cache.buffer = current_buffer;                       \
403     syntax_cache.object = Qnil;                                 \
404     syntax_cache.current_syntax_table                           \
405       = current_buffer->mirror_syntax_table;                    \
406     syntax_cache.use_code = 0;                                  \
407     if (lookup_syntax_properties)                               \
408       update_syntax_cache ((COUNT) > 0 ? (FROM) : (FROM) - 1,   \
409                            (COUNT), 1);                         \
410   } while (0)
411 #endif
412
413 #ifdef UTF2000
414 #define SETUP_SYNTAX_CACHE_FOR_BUFFER(BUFFER, FROM, COUNT)      \
415   do {                                                          \
416     syntax_cache.buffer = (BUFFER);                             \
417     syntax_cache.object = Qnil;                                 \
418     syntax_cache.current_syntax_table =                         \
419       syntax_cache.buffer->syntax_table;                        \
420     syntax_cache.use_code = 0;                                  \
421     if (lookup_syntax_properties)                               \
422       update_syntax_cache ((FROM) + ((COUNT) > 0 ? 0 : -1),     \
423                            (COUNT), 1);                         \
424   } while (0)
425 #else
426 #define SETUP_SYNTAX_CACHE_FOR_BUFFER(BUFFER, FROM, COUNT)      \
427   do {                                                          \
428     syntax_cache.buffer = (BUFFER);                             \
429     syntax_cache.object = Qnil;                                 \
430     syntax_cache.current_syntax_table =                         \
431       syntax_cache.buffer->mirror_syntax_table;                 \
432     syntax_cache.use_code = 0;                                  \
433     if (lookup_syntax_properties)                               \
434       update_syntax_cache ((FROM) + ((COUNT) > 0 ? 0 : -1),     \
435                            (COUNT), 1);                         \
436   } while (0)
437 #endif
438
439 #ifdef UTF2000
440 #define SETUP_SYNTAX_CACHE_FOR_OBJECT(OBJECT, BUFFER, FROM, COUNT)      \
441   do {                                                                  \
442     syntax_cache.buffer = (BUFFER);                                     \
443     syntax_cache.object = (OBJECT);                                     \
444     if (NILP (syntax_cache.object))                                     \
445       {                                                                 \
446         /* do nothing */;                                               \
447       }                                                                 \
448     else if (EQ (syntax_cache.object, Qt))                              \
449       {                                                                 \
450         /* do nothing */;                                               \
451       }                                                                 \
452     else if (STRINGP (syntax_cache.object))                             \
453       {                                                                 \
454         /* do nothing */;                                               \
455       }                                                                 \
456     else if (BUFFERP (syntax_cache.object))                             \
457       {                                                                 \
458         syntax_cache.buffer = XBUFFER (syntax_cache.object);            \
459       }                                                                 \
460     else                                                                \
461       {                                                                 \
462         /* OBJECT must be buffer/string/t/nil */                        \
463         assert(0);                                                      \
464       }                                                                 \
465     syntax_cache.current_syntax_table                                   \
466       = syntax_cache.buffer->syntax_table;                              \
467     syntax_cache.use_code = 0;                                          \
468     if (lookup_syntax_properties)                                       \
469       update_syntax_cache ((FROM) + ((COUNT) > 0 ? 0 : -1),             \
470                            (COUNT), 1);                                 \
471   } while (0)
472 #else
473 #define SETUP_SYNTAX_CACHE_FOR_OBJECT(OBJECT, BUFFER, FROM, COUNT)      \
474   do {                                                                  \
475     syntax_cache.buffer = (BUFFER);                                     \
476     syntax_cache.object = (OBJECT);                                     \
477     if (NILP (syntax_cache.object))                                     \
478       {                                                                 \
479         /* do nothing */;                                               \
480       }                                                                 \
481     else if (EQ (syntax_cache.object, Qt))                              \
482       {                                                                 \
483         /* do nothing */;                                               \
484       }                                                                 \
485     else if (STRINGP (syntax_cache.object))                             \
486       {                                                                 \
487         /* do nothing */;                                               \
488       }                                                                 \
489     else if (BUFFERP (syntax_cache.object))                             \
490       {                                                                 \
491         syntax_cache.buffer = XBUFFER (syntax_cache.object);            \
492       }                                                                 \
493     else                                                                \
494       {                                                                 \
495         /* OBJECT must be buffer/string/t/nil */                        \
496         assert(0);                                                      \
497       }                                                                 \
498     syntax_cache.current_syntax_table                                   \
499       = syntax_cache.buffer->mirror_syntax_table;                       \
500     syntax_cache.use_code = 0;                                          \
501     if (lookup_syntax_properties)                                       \
502       update_syntax_cache ((FROM) + ((COUNT) > 0 ? 0 : -1),             \
503                            (COUNT), 1);                                 \
504   } while (0)
505 #endif
506
507 #define SYNTAX_CODE_PREFIX(c) \
508   ((c >> 7) & 1)
509
510 #define SYNTAX_CODE_COMMENT_BITS(c) \
511   ((c >> 16) &0xff)
512
513 #define SYNTAX_CODES_START_P(a, b)                                    \
514   (((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START) >> 2)    \
515    & (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_START))
516
517 #define SYNTAX_CODES_END_P(a, b)                                    \
518   (((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END) >> 2)    \
519    & (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_END))
520
521 #define SYNTAX_CODES_COMMENT_MASK_START(a, b)                   \
522   (SYNTAX_CODES_MATCH_START_P (a, b, SYNTAX_COMMENT_STYLE_A)    \
523    ? SYNTAX_COMMENT_STYLE_A                                     \
524    : (SYNTAX_CODES_MATCH_START_P (a, b, SYNTAX_COMMENT_STYLE_B) \
525       ? SYNTAX_COMMENT_STYLE_B                                  \
526       : 0))
527 #define SYNTAX_CODES_COMMENT_MASK_END(a, b)                     \
528   (SYNTAX_CODES_MATCH_END_P (a, b, SYNTAX_COMMENT_STYLE_A)      \
529    ? SYNTAX_COMMENT_STYLE_A                                     \
530    : (SYNTAX_CODES_MATCH_END_P (a, b, SYNTAX_COMMENT_STYLE_B)   \
531       ? SYNTAX_COMMENT_STYLE_B                                  \
532       : 0))
533
534 #define SYNTAX_CODE_START_FIRST_P(a) \
535   (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START)
536
537 #define SYNTAX_CODE_START_SECOND_P(a) \
538   (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_SECOND_CHAR_START)
539
540 #define SYNTAX_CODE_END_FIRST_P(a) \
541   (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END)
542
543 #define SYNTAX_CODE_END_SECOND_P(a) \
544   (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_SECOND_CHAR_END)
545
546
547 #define SYNTAX_CODES_MATCH_START_P(a, b, mask)                          \
548   ((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START & (mask))    \
549    && (SYNTAX_CODE_COMMENT_BITS (b)                                     \
550        & SYNTAX_SECOND_CHAR_START & (mask)))
551
552 #define SYNTAX_CODES_MATCH_END_P(a, b, mask)                            \
553   ((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END & (mask))      \
554    && (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_END & (mask)))
555
556 #define SYNTAX_CODE_MATCHES_1CHAR_P(a, mask)    \
557   ((SYNTAX_CODE_COMMENT_BITS (a) & (mask)))
558
559 #define SYNTAX_CODE_COMMENT_1CHAR_MASK(a)                       \
560   ((SYNTAX_CODE_MATCHES_1CHAR_P (a, SYNTAX_COMMENT_STYLE_A)     \
561     ? SYNTAX_COMMENT_STYLE_A                                    \
562     : (SYNTAX_CODE_MATCHES_1CHAR_P (a, SYNTAX_COMMENT_STYLE_B)  \
563        ? SYNTAX_COMMENT_STYLE_B                                 \
564        : 0)))
565
566
567 #endif /* INCLUDED_syntax_h_ */