| 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 1, 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 | |
| 21 | extern Lisp_Object Qsyntax_table_p; |
| 22 | extern Lisp_Object Fsyntax_table_p (), Fsyntax_table (), Fset_syntax_table (); |
| 23 | |
| 24 | /* The standard syntax table is stored where it will automatically |
| 25 | be used in all new buffers. */ |
| 26 | #define Vstandard_syntax_table buffer_defaults.syntax_table |
| 27 | |
| 28 | /* A syntax table is a Lisp vector of length 0400, whose elements are integers. |
| 29 | |
| 30 | The low 8 bits of the integer is a code, as follows: |
| 31 | */ |
| 32 | |
| 33 | enum syntaxcode |
| 34 | { |
| 35 | Swhitespace, /* for a whitespace character */ |
| 36 | Spunct, /* for random punctuation characters */ |
| 37 | Sword, /* for a word constituent */ |
| 38 | Ssymbol, /* symbol constituent but not word constituent */ |
| 39 | Sopen, /* for a beginning delimiter */ |
| 40 | Sclose, /* for an ending delimiter */ |
| 41 | Squote, /* for a prefix character like Lisp ' */ |
| 42 | Sstring, /* for a string-grouping character like Lisp " */ |
| 43 | Smath, /* for delimiters like $ in Tex. */ |
| 44 | Sescape, /* for a character that begins a C-style escape */ |
| 45 | Scharquote, /* for a character that quotes the following character */ |
| 46 | Scomment, /* for a comment-starting character */ |
| 47 | Sendcomment, /* for a comment-ending character */ |
| 48 | Sinherit, /* use the standard syntax table for this character */ |
| 49 | Smax /* Upper bound on codes that are meaningful */ |
| 50 | }; |
| 51 | |
| 52 | #define RAW_SYNTAX(table, c) \ |
| 53 | ((enum syntaxcode) (XINT (XVECTOR (table)->contents[(unsigned char) (c)]) & 0377)) |
| 54 | |
| 55 | #ifdef __GNUC__ |
| 56 | #define SYNTAX(c) \ |
| 57 | ({ unsigned char character = c; \ |
| 58 | enum syntaxcode syntax \ |
| 59 | = RAW_SYNTAX (current_buffer->syntax_table, character); \ |
| 60 | if (syntax == Sinherit) \ |
| 61 | syntax = RAW_SYNTAX (Vstandard_syntax_table, character); \ |
| 62 | syntax; }) |
| 63 | #else |
| 64 | #define SYNTAX(c) \ |
| 65 | (RAW_SYNTAX (current_buffer->syntax_table, c) == Sinherit \ |
| 66 | ? RAW_SYNTAX (Vstandard_syntax_table, c) \ |
| 67 | : RAW_SYNTAX (current_buffer->syntax_table, c)) |
| 68 | #endif |
| 69 | |
| 70 | /* The next 8 bits of the number is a character, |
| 71 | the matching delimiter in the case of Sopen or Sclose. */ |
| 72 | |
| 73 | #define RAW_SYNTAX_MATCH(table, c) \ |
| 74 | ((XINT (XVECTOR (table)->contents[(unsigned char) (c)]) >> 8) & 0377) |
| 75 | |
| 76 | #ifdef __GNUC__ |
| 77 | #define SYNTAX_MATCH(c) \ |
| 78 | ({ unsigned char character = c; \ |
| 79 | enum syntaxcode syntax \ |
| 80 | = RAW_SYNTAX (current_buffer->syntax_table, character); \ |
| 81 | int matcher; \ |
| 82 | if (syntax == Sinherit) \ |
| 83 | matcher = RAW_SYNTAX_MATCH (Vstandard_syntax_table, character); \ |
| 84 | else \ |
| 85 | matcher = RAW_SYNTAX_MATCH (current_buffer->syntax_table, character); \ |
| 86 | syntax; }) |
| 87 | #else |
| 88 | #define SYNTAX_MATCH(c) \ |
| 89 | (RAW_SYNTAX (current_buffer->syntax_table, c) == Sinherit \ |
| 90 | ? RAW_SYNTAX_MATCH (Vstandard_syntax_table, c) \ |
| 91 | : RAW_SYNTAX_MATCH (current_buffer->syntax_table, c)) |
| 92 | #endif |
| 93 | |
| 94 | /* Then there are six single-bit flags that have the following meanings: |
| 95 | 1. This character is the first of a two-character comment-start sequence. |
| 96 | 2. This character is the second of a two-character comment-start sequence. |
| 97 | 3. This character is the first of a two-character comment-end sequence. |
| 98 | 4. This character is the second of a two-character comment-end sequence. |
| 99 | 5. This character is a prefix, for backward-prefix-chars. |
| 100 | Note that any two-character sequence whose first character has flag 1 |
| 101 | and whose second character has flag 2 will be interpreted as a comment start. |
| 102 | |
| 103 | bit 6 is used to discriminate between two different comment styles. |
| 104 | Languages such as C++ allow two orthogonal syntax start/end pairs |
| 105 | and bit 6 is used to determine whether a comment-end or Scommentend |
| 106 | ends style a or b. Comment start sequences can start style a or b. |
| 107 | Style a is always the default. |
| 108 | */ |
| 109 | |
| 110 | #define SYNTAX_CHOOSE_TABLE(c) \ |
| 111 | (RAW_SYNTAX (current_buffer->syntax_table, c) == Sinherit \ |
| 112 | ? Vstandard_syntax_table : current_buffer->syntax_table) |
| 113 | |
| 114 | #ifdef __GNUC__ |
| 115 | |
| 116 | #define SYNTAX_COMSTART_FIRST(c) \ |
| 117 | ({ unsigned char ch = c; \ |
| 118 | Lisp_Object table = SYNTAX_CHOOSE_TABLE (ch); \ |
| 119 | (XINT (XVECTOR (table)->contents[ch]) >> 16) & 1; \ |
| 120 | }) |
| 121 | |
| 122 | #define SYNTAX_COMSTART_SECOND(c) \ |
| 123 | ({ unsigned char ch = c; \ |
| 124 | Lisp_Object table = SYNTAX_CHOOSE_TABLE (ch); \ |
| 125 | (XINT (XVECTOR (table)->contents[ch]) >> 17) & 1; \ |
| 126 | }) |
| 127 | |
| 128 | #define SYNTAX_COMEND_FIRST(c) \ |
| 129 | ({ unsigned char ch = c; \ |
| 130 | Lisp_Object table = SYNTAX_CHOOSE_TABLE (ch); \ |
| 131 | (XINT (XVECTOR (table)->contents[ch]) >> 18) & 1; \ |
| 132 | }) |
| 133 | |
| 134 | #define SYNTAX_COMEND_SECOND(c) \ |
| 135 | ({ unsigned char ch = c; \ |
| 136 | Lisp_Object table = SYNTAX_CHOOSE_TABLE (ch); \ |
| 137 | (XINT (XVECTOR (table)->contents[ch]) >> 19) & 1; \ |
| 138 | }) |
| 139 | |
| 140 | #define SYNTAX_PREFIX(c) \ |
| 141 | ({ unsigned char ch = c; \ |
| 142 | Lisp_Object table = SYNTAX_CHOOSE_TABLE (ch); \ |
| 143 | (XINT (XVECTOR (table)->contents[ch]) >> 20) & 1; \ |
| 144 | }) |
| 145 | |
| 146 | /* extract the comment style bit from the syntax table entry */ |
| 147 | #define SYNTAX_COMMENT_STYLE(c) \ |
| 148 | ({ unsigned char ch = c; \ |
| 149 | Lisp_Object table = SYNTAX_CHOOSE_TABLE (ch); \ |
| 150 | (XINT (XVECTOR (table)->contents[ch]) >> 21) & 1; \ |
| 151 | }) |
| 152 | |
| 153 | #else |
| 154 | |
| 155 | #define SYNTAX_COMSTART_FIRST(c) \ |
| 156 | ((XINT (XVECTOR (SYNTAX_CHOOSE_TABLE (c))->contents[(unsigned char) (c)]) >> 16) & 1) |
| 157 | |
| 158 | #define SYNTAX_COMSTART_SECOND(c) \ |
| 159 | ((XINT (XVECTOR (SYNTAX_CHOOSE_TABLE (c))->contents[(unsigned char) (c)]) >> 17) & 1) |
| 160 | |
| 161 | #define SYNTAX_COMEND_FIRST(c) \ |
| 162 | ((XINT (XVECTOR (SYNTAX_CHOOSE_TABLE (c))->contents[(unsigned char) (c)]) >> 18) & 1) |
| 163 | |
| 164 | #define SYNTAX_COMEND_SECOND(c) \ |
| 165 | ((XINT (XVECTOR (SYNTAX_CHOOSE_TABLE (c))->contents[(unsigned char) (c)]) >> 19) & 1) |
| 166 | |
| 167 | #define SYNTAX_PREFIX(c) \ |
| 168 | ((XINT (XVECTOR (SYNTAX_CHOOSE_TABLE (c))->contents[(unsigned char) (c)]) >> 20) & 1) |
| 169 | |
| 170 | /* extract the comment style bit from the syntax table entry */ |
| 171 | #define SYNTAX_COMMENT_STYLE(c) \ |
| 172 | ((XINT (XVECTOR (SYNTAX_CHOOSE_TABLE (c))->contents[(unsigned char) (c)]) >> 21) & 1) |
| 173 | |
| 174 | #endif |
| 175 | |
| 176 | /* This array, indexed by a character, contains the syntax code which that |
| 177 | character signifies (as a char). For example, |
| 178 | (enum syntaxcode) syntax_spec_code['w'] is Sword. */ |
| 179 | |
| 180 | extern unsigned char syntax_spec_code[0400]; |
| 181 | |
| 182 | /* Indexed by syntax code, give the letter that describes it. */ |
| 183 | |
| 184 | extern char syntax_code_spec[14]; |