home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / src / syntax.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-26  |  6.8 KB  |  176 lines

  1. /* Declarations having to do with GNU Emacs syntax tables.
  2.    Copyright (C) 1985-1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  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
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #ifndef _EMACS_SYNTAX_H_
  21. #define _EMACS_SYNTAX_H_
  22.  
  23. extern Lisp_Object Qsyntax_table_p;
  24. extern Lisp_Object Fsyntax_table_p (), Fsyntax_table (), Fset_syntax_table ();
  25.  
  26. /* The standard syntax table is stored where it will automatically
  27.    be used in all new buffers.  */
  28. #define Vstandard_syntax_table buffer_defaults.syntax_table
  29.  
  30. /* A syntax table is a Lisp vector of length 0400, whose elements are integers.
  31.  
  32. The low 8 bits of the integer is a code, as follows:
  33. */
  34.  
  35. enum syntaxcode
  36.   {
  37.     Swhitespace, /* for a whitespace character */
  38.     Spunct,     /* for random punctuation characters */
  39.     Sword,     /* for a word constituent */
  40.     Ssymbol,     /* symbol constituent but not word constituent */
  41.     Sopen,     /* for a beginning delimiter */
  42.     Sclose,      /* for an ending delimiter */
  43.     Squote,     /* for a prefix character like Lisp ' */
  44.     Sstring,     /* for a string-grouping character like Lisp " */
  45.     Smath,     /* for delimiters like $ in Tex. */
  46.     Sescape,     /* for a character that begins a C-style escape */
  47.     Scharquote,  /* for a character that quotes the following character */
  48.     Scomment,    /* for a comment-starting character */
  49.     Sendcomment, /* for a comment-ending character */
  50.     Smax     /* Upper bound on codes that are meaningful */
  51.   };
  52.  
  53. #define SYNTAX(c) \
  54.   ((enum syntaxcode) (XINT (XVECTOR (current_buffer->syntax_table)->contents[c]) & 0377))
  55.  
  56. /* The next 8 bits of the number is a character,
  57.  the matching delimiter in the case of Sopen or Sclose. */
  58.  
  59. #define SYNTAX_MATCH(c) \
  60.   ((XINT (XVECTOR (current_buffer->syntax_table)->contents[c]) >> 8) & 0377)
  61.  
  62. /* The following bits have different meanings depending on whether 
  63.  emacs was compiled with the NEW_SYNTAX flag or not.  If so, then
  64.  syntax parsing has been extended to recognize up to two different
  65.  comment styles in a single mode. The next nine single-bit flags
  66.  have the following meanings:
  67.  
  68.   1. first of a one or two character comment-start sequence of style a.
  69.   2. first of a one or two character comment-start sequence of style b.
  70.   3. second of a two-character comment-start sequence of style a.
  71.   4. second of a two-character comment-start sequence of style b.
  72.   5. first of a one or two character comment-end sequence of style a.
  73.   6. first of a one or two character comment-end sequence of style b.
  74.   7. second of a two-character comment-end sequence of style a.
  75.   8. second of a two-character comment-end sequence of style b.
  76.   9. This character is a prefix, for backward-prefix-chars.
  77.  
  78.  Otherwise, If emacs was not compiled with the NEW_SYNTAX flag, only
  79.  the following limited syntax is available. This is compatible with
  80.  old versions of emacs:
  81.  
  82.   1. This character is the first of a two-character comment-start sequence.
  83.   2. This character is the second of a two-character comment-start sequence.
  84.   3. This character is the first of a two-character comment-end sequence.
  85.   4. This character is the second of a two-character comment-end sequence.
  86.   5. This character is a prefix, for backward-prefix-chars.
  87.   6. Comment style flag (see below).
  88.  Note that any two-character sequence whose first character has flag 1
  89.   and whose second character has flag 2 will be interpreted as a comment start.
  90.  
  91.  bit 6 is used to discriminate between two different comment styles.
  92.  Languages such as C++ allow two orthogonal syntax start/end pairs and
  93.  some way of pairing comment starts and ends has to be provided. To
  94.  keep backward compatibility, we simply add bit 6 flag which is
  95.  checked only on the second character of a two-char comment start
  96.  sequence, and the first character of a two-char comment end sequence,
  97.  or a Scommentend class character.
  98.  */
  99.  
  100. #ifndef NEW_SYNTAX /* old way of doing things */
  101.  
  102. #define SYNTAX_COMSTART_FIRST(c) \
  103.   ((XINT (XVECTOR (current_buffer->syntax_table)->contents[c]) >> 16) & 1)
  104.  
  105. #define SYNTAX_COMSTART_SECOND(c) \
  106.   ((XINT (XVECTOR (current_buffer->syntax_table)->contents[c]) >> 17) & 1)
  107.  
  108. #define SYNTAX_COMEND_FIRST(c) \
  109.   ((XINT (XVECTOR (current_buffer->syntax_table)->contents[c]) >> 18) & 1)
  110.  
  111. #define SYNTAX_COMEND_SECOND(c) \
  112.   ((XINT (XVECTOR (current_buffer->syntax_table)->contents[c]) >> 19) & 1)
  113.  
  114. #define SYNTAX_PREFIX(c) \
  115.   ((XINT (XVECTOR (current_buffer->syntax_table)->contents[c]) >> 20) & 1)
  116.  
  117. #else /* NEW_SYNTAX */
  118.  
  119. #define SYNTAX_COMMENT_BITS(c) \
  120.   ((XINT (XVECTOR (current_buffer->syntax_table)->contents[c]) >> 16) &0xff)
  121.  
  122. #define SYNTAX_COMMENT_STYLE_A 0xaa
  123. #define SYNTAX_COMMENT_STYLE_B 0x55
  124. #define SYNTAX_FIRST_CHAR_START 0xc0
  125. #define SYNTAX_SECOND_CHAR_START 0x30
  126. #define SYNTAX_FIRST_CHAR_END 0x0c
  127. #define SYNTAX_SECOND_CHAR_END 0x03
  128.  
  129. #define SYNTAX_FIRST_OF_START_A 0x80
  130. #define SYNTAX_FIRST_OF_START_B 0x40
  131. #define SYNTAX_SECOND_OF_START_A 0x20
  132. #define SYNTAX_SECOND_OF_START_B 0x10
  133. #define SYNTAX_FIRST_OF_END_A 0x08
  134. #define SYNTAX_FIRST_OF_END_B 0x04
  135. #define SYNTAX_SECOND_OF_END_A 0x02
  136. #define SYNTAX_SECOND_OF_END_B 0x01
  137.  
  138. #define SYNTAX_START_SEQUENCE(a,b,style) \
  139. (((SYNTAX_COMMENT_BITS(a)&style)&SYNTAX_FIRST_CHAR_START) && \
  140.  ((SYNTAX_COMMENT_BITS(b)&style)&SYNTAX_SECOND_CHAR_START))
  141.  
  142. #define SYNTAX_END_SEQUENCE(a,b,style) \
  143. (((SYNTAX_COMMENT_BITS(a)&style)&SYNTAX_FIRST_CHAR_END) && \
  144.  ((SYNTAX_COMMENT_BITS(b)&style)&SYNTAX_SECOND_CHAR_END))
  145.  
  146. #define SYNTAX_START(a,b) \
  147. (SYNTAX_START_SEQUENCE(a,b,SYNTAX_COMMENT_STYLE_A) || \
  148.  SYNTAX_START_SEQUENCE(a,b,SYNTAX_COMMENT_STYLE_B))
  149.  
  150. #define SYNTAX_END(a,b) \
  151. (SYNTAX_END_SEQUENCE(a,b,SYNTAX_COMMENT_STYLE_A) || \
  152.  SYNTAX_END_SEQUENCE(a,b,SYNTAX_COMMENT_STYLE_B))
  153.  
  154. #define SYNTAX_SINGLE_CHAR_STYLE_A(c) \
  155. (SYNTAX_COMMENT_BITS(c)&SYNTAX_COMMENT_STYLE_A)
  156.  
  157. #define SYNTAX_SINGLE_CHAR_STYLE_B(c) \
  158. (SYNTAX_COMMENT_BITS(c)&SYNTAX_COMMENT_STYLE_B)
  159.  
  160. #define SYNTAX_PREFIX(c) \
  161.   ((XINT (XVECTOR (current_buffer->syntax_table)->contents[c]) >> 24) & 1)
  162.  
  163. #endif /* NEW_SYNTAX */
  164.  
  165. /* This array, indexed by a character, contains the syntax code which that
  166.  character signifies (as a char).  For example,
  167.  (enum syntaxcode) syntax_spec_code['w'] is Sword. */
  168.  
  169. extern unsigned char syntax_spec_code[0400];
  170.  
  171. /* Indexed by syntax code, give the letter that describes it. */
  172.  
  173. extern unsigned char syntax_code_spec[13];
  174.  
  175. #endif /* _EMACS_SYNTAX_H_ */
  176.