Mercurial > hg > xemacs-beta
comparison src/syntax.h @ 460:223736d75acb r21-2-45
Import from CVS: tag r21-2-45
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:43:24 +0200 |
parents | abe6d1db359e |
children | fdefd0186b75 |
comparison
equal
deleted
inserted
replaced
459:9d4fd877b885 | 460:223736d75acb |
---|---|
59 Sescape, /* a character that begins a C-style escape */ | 59 Sescape, /* a character that begins a C-style escape */ |
60 Scharquote, /* a character that quotes the following character */ | 60 Scharquote, /* a character that quotes the following character */ |
61 Scomment, /* a comment-starting character */ | 61 Scomment, /* a comment-starting character */ |
62 Sendcomment, /* a comment-ending character */ | 62 Sendcomment, /* a comment-ending character */ |
63 Sinherit, /* use the standard syntax table for this character */ | 63 Sinherit, /* use the standard syntax table for this character */ |
64 Scomment_fence, /* Starts/ends comment which is delimited on the | |
65 other side by a char with the same syntaxcode. */ | |
66 Sstring_fence, /* Starts/ends string which is delimited on the | |
67 other side by a char with the same syntaxcode. */ | |
64 Smax /* Upper bound on codes that are meaningful */ | 68 Smax /* Upper bound on codes that are meaningful */ |
65 }; | 69 }; |
66 | 70 |
67 enum syntaxcode charset_syntax (struct buffer *buf, Lisp_Object charset, | 71 enum syntaxcode charset_syntax (struct buffer *buf, Lisp_Object charset, |
68 int *multi_p_out); | 72 int *multi_p_out); |
252 syntax table itself. */ | 256 syntax table itself. */ |
253 Lisp_Object syntax_match (Lisp_Object table, Emchar ch); | 257 Lisp_Object syntax_match (Lisp_Object table, Emchar ch); |
254 | 258 |
255 extern int no_quit_in_re_search; | 259 extern int no_quit_in_re_search; |
256 extern struct buffer *regex_emacs_buffer; | 260 extern struct buffer *regex_emacs_buffer; |
257 extern int regex_emacs_buffer_p; | 261 |
262 /* This is the string or buffer in which we are matching. It is used | |
263 for looking up syntax properties. */ | |
264 extern Lisp_Object regex_match_object; | |
258 | 265 |
259 void update_syntax_table (Lisp_Char_Table *ct); | 266 void update_syntax_table (Lisp_Char_Table *ct); |
260 | 267 |
268 #ifdef emacs | |
269 | |
270 extern int lookup_syntax_properties; | |
271 | |
272 struct syntax_cache | |
273 { | |
274 int use_code; /* Whether to use syntax_code | |
275 or current_syntax_table. */ | |
276 struct buffer* buffer; /* The buffer the current syntax cache | |
277 applies to. */ | |
278 Lisp_Object object; /* The buffer or string the current | |
279 syntax cache applies to. */ | |
280 int syntax_code; /* Syntax code of current char. */ | |
281 Lisp_Object current_syntax_table; /* Syntax table for current pos. */ | |
282 Lisp_Object old_prop; /* Syntax-table prop at prev pos. */ | |
283 | |
284 Bufpos next_change; /* Position of the next extent | |
285 change. */ | |
286 Bufpos prev_change; /* Position of the previous | |
287 extent change. */ | |
288 }; | |
289 extern struct syntax_cache syntax_cache; | |
290 | |
291 void update_syntax_cache (int pos, int count, int init); | |
292 | |
293 /* Make syntax cache state good for CHARPOS, assuming it is | |
294 currently good for a position before CHARPOS. */ | |
295 #define UPDATE_SYNTAX_CACHE_FORWARD(pos) \ | |
296 (lookup_syntax_properties \ | |
297 ? (update_syntax_cache ((pos), 1, 0), 1) \ | |
298 : 0) | |
299 | |
300 /* Make syntax cache state good for CHARPOS, assuming it is | |
301 currently good for a position after CHARPOS. */ | |
302 #define UPDATE_SYNTAX_CACHE_BACKWARD(pos) \ | |
303 (lookup_syntax_properties \ | |
304 ? (update_syntax_cache ((pos), -1, 0), 1) \ | |
305 : 0) | |
306 | |
307 /* Make syntax cache state good for CHARPOS */ | |
308 #define UPDATE_SYNTAX_CACHE(pos) \ | |
309 (lookup_syntax_properties \ | |
310 ? (update_syntax_cache ((pos), 0, 0), 1) \ | |
311 : 0) | |
312 | |
313 #define SYNTAX_FROM_CACHE(table, c) \ | |
314 SYNTAX_FROM_CODE (SYNTAX_CODE_FROM_CACHE (table, c)) | |
315 | |
316 #define SYNTAX_CODE_FROM_CACHE(table, c) \ | |
317 ( syntax_cache.use_code \ | |
318 ? syntax_cache.syntax_code \ | |
319 : SYNTAX_CODE (XCHAR_TABLE (syntax_cache.current_syntax_table), \ | |
320 c) \ | |
321 ) | |
322 | |
323 /* Convert the byte offset BYTEPOS into a character position, | |
324 for the object recorded in syntax_cache with SETUP_SYNTAX_TABLE_FOR_OBJECT. | |
325 | |
326 The value is meant for use in the UPDATE_SYNTAX_TABLE... macros. | |
327 These macros do nothing when parse_sexp_lookup_properties is 0, | |
328 so we return 0 in that case, for speed. */ | |
329 #define SYNTAX_CACHE_BYTE_TO_CHAR(bytepos) \ | |
330 (! lookup_syntax_properties \ | |
331 ? 0 \ | |
332 : STRINGP (syntax_cache.object) \ | |
333 ? bytecount_to_charcount (XSTRING_DATA (syntax_cache.object), bytepos) \ | |
334 : (BUFFERP (syntax_cache.object) || NILP (syntax_cache.object)) \ | |
335 ? bytind_to_bufpos (syntax_cache.buffer, \ | |
336 bytepos + BI_BUF_BEGV (syntax_cache.buffer)) \ | |
337 : (bytepos)) | |
338 | |
339 #define SYNTAX_CACHE_OBJECT_BYTE_TO_CHAR(obj, buf, bytepos) \ | |
340 (! lookup_syntax_properties \ | |
341 ? 0 \ | |
342 : STRINGP (obj) \ | |
343 ? bytecount_to_charcount (XSTRING_DATA (obj), bytepos) \ | |
344 : (BUFFERP (obj) || NILP (obj)) \ | |
345 ? bytind_to_bufpos (buf, bytepos + BI_BUF_BEGV (buf)) \ | |
346 : (bytepos)) | |
347 | |
348 #else /* not emacs */ | |
349 | |
350 #define update_syntax_cache(pos, count, init) | |
351 #define UPDATE_SYNTAX_CACHE_FORWARD(pos) | |
352 #define UPDATE_SYNTAX_CACHE_BACKWARD(pos) | |
353 #define UPDATE_SYNTAX_CACHE(pos) | |
354 #define SYNTAX_FROM_CACHE SYNTAX | |
355 #define SYNTAX_CODE_FROM_CACHE SYNTAX_CODE | |
356 | |
357 #endif /* emacs */ | |
358 | |
359 #define SETUP_SYNTAX_CACHE(FROM, COUNT) \ | |
360 do { \ | |
361 syntax_cache.buffer = current_buffer; \ | |
362 syntax_cache.object = Qnil; \ | |
363 syntax_cache.current_syntax_table \ | |
364 = current_buffer->mirror_syntax_table; \ | |
365 syntax_cache.use_code = 0; \ | |
366 if (lookup_syntax_properties) \ | |
367 update_syntax_cache ((COUNT) > 0 ? (FROM) : (FROM) - 1, \ | |
368 (COUNT), 1); \ | |
369 } while (0) | |
370 | |
371 #define SETUP_SYNTAX_CACHE_FOR_BUFFER(BUFFER, FROM, COUNT) \ | |
372 do { \ | |
373 syntax_cache.buffer = (BUFFER); \ | |
374 syntax_cache.object = Qnil; \ | |
375 syntax_cache.current_syntax_table = \ | |
376 syntax_cache.buffer->mirror_syntax_table; \ | |
377 syntax_cache.use_code = 0; \ | |
378 if (lookup_syntax_properties) \ | |
379 update_syntax_cache ((FROM) + ((COUNT) > 0 ? 0 : -1), \ | |
380 (COUNT), 1); \ | |
381 } while (0) | |
382 | |
383 #define SETUP_SYNTAX_CACHE_FOR_OBJECT(OBJECT, BUFFER, FROM, COUNT) \ | |
384 do { \ | |
385 syntax_cache.buffer = (BUFFER); \ | |
386 syntax_cache.object = (OBJECT); \ | |
387 if (NILP (syntax_cache.object)) \ | |
388 { \ | |
389 /* do nothing */; \ | |
390 } \ | |
391 else if (EQ (syntax_cache.object, Qt)) \ | |
392 { \ | |
393 /* do nothing */; \ | |
394 } \ | |
395 else if (STRINGP (syntax_cache.object)) \ | |
396 { \ | |
397 /* do nothing */; \ | |
398 } \ | |
399 else if (BUFFERP (syntax_cache.object)) \ | |
400 { \ | |
401 syntax_cache.buffer = XBUFFER (syntax_cache.object); \ | |
402 } \ | |
403 else \ | |
404 { \ | |
405 /* OBJECT must be buffer/string/t/nil */ \ | |
406 assert(0); \ | |
407 } \ | |
408 syntax_cache.current_syntax_table \ | |
409 = syntax_cache.buffer->mirror_syntax_table; \ | |
410 syntax_cache.use_code = 0; \ | |
411 if (lookup_syntax_properties) \ | |
412 update_syntax_cache ((FROM) + ((COUNT) > 0 ? 0 : -1), \ | |
413 (COUNT), 1); \ | |
414 } while (0) | |
415 | |
416 #define SYNTAX_CODE_PREFIX(c) \ | |
417 ((c >> 7) & 1) | |
418 | |
419 #define SYNTAX_CODE_COMMENT_BITS(c) \ | |
420 ((c >> 16) &0xff) | |
421 | |
422 #define SYNTAX_CODES_START_P(a, b) \ | |
423 (((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START) >> 2) \ | |
424 & (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_START)) | |
425 | |
426 #define SYNTAX_CODES_END_P(a, b) \ | |
427 (((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END) >> 2) \ | |
428 & (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_END)) | |
429 | |
430 #define SYNTAX_CODES_COMMENT_MASK_START(a, b) \ | |
431 (SYNTAX_CODES_MATCH_START_P (a, b, SYNTAX_COMMENT_STYLE_A) \ | |
432 ? SYNTAX_COMMENT_STYLE_A \ | |
433 : (SYNTAX_CODES_MATCH_START_P (a, b, SYNTAX_COMMENT_STYLE_B) \ | |
434 ? SYNTAX_COMMENT_STYLE_B \ | |
435 : 0)) | |
436 #define SYNTAX_CODES_COMMENT_MASK_END(a, b) \ | |
437 (SYNTAX_CODES_MATCH_END_P (a, b, SYNTAX_COMMENT_STYLE_A) \ | |
438 ? SYNTAX_COMMENT_STYLE_A \ | |
439 : (SYNTAX_CODES_MATCH_END_P (a, b, SYNTAX_COMMENT_STYLE_B) \ | |
440 ? SYNTAX_COMMENT_STYLE_B \ | |
441 : 0)) | |
442 | |
443 #define SYNTAX_CODE_START_FIRST_P(a) \ | |
444 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START) | |
445 | |
446 #define SYNTAX_CODE_START_SECOND_P(a) \ | |
447 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_SECOND_CHAR_START) | |
448 | |
449 #define SYNTAX_CODE_END_FIRST_P(a) \ | |
450 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END) | |
451 | |
452 #define SYNTAX_CODE_END_SECOND_P(a) \ | |
453 (SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_SECOND_CHAR_END) | |
454 | |
455 | |
456 #define SYNTAX_CODES_MATCH_START_P(a, b, mask) \ | |
457 ((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_START & (mask)) \ | |
458 && (SYNTAX_CODE_COMMENT_BITS (b) \ | |
459 & SYNTAX_SECOND_CHAR_START & (mask))) | |
460 | |
461 #define SYNTAX_CODES_MATCH_END_P(a, b, mask) \ | |
462 ((SYNTAX_CODE_COMMENT_BITS (a) & SYNTAX_FIRST_CHAR_END & (mask)) \ | |
463 && (SYNTAX_CODE_COMMENT_BITS (b) & SYNTAX_SECOND_CHAR_END & (mask))) | |
464 | |
465 #define SYNTAX_CODE_MATCHES_1CHAR_P(a, mask) \ | |
466 ((SYNTAX_CODE_COMMENT_BITS (a) & (mask))) | |
467 | |
468 #define SYNTAX_CODE_COMMENT_1CHAR_MASK(a) \ | |
469 ((SYNTAX_CODE_MATCHES_1CHAR_P (a, SYNTAX_COMMENT_STYLE_A) \ | |
470 ? SYNTAX_COMMENT_STYLE_A \ | |
471 : (SYNTAX_CODE_MATCHES_1CHAR_P (a, SYNTAX_COMMENT_STYLE_B) \ | |
472 ? SYNTAX_COMMENT_STYLE_B \ | |
473 : 0))) | |
474 | |
475 | |
261 #endif /* INCLUDED_syntax_h_ */ | 476 #endif /* INCLUDED_syntax_h_ */ |