diff options
| author | Richard M. Stallman | 1995-10-07 21:55:20 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-10-07 21:55:20 +0000 |
| commit | e46c910e4a464d0ec115a66f1810a8dea1f1502b (patch) | |
| tree | cf911bddd719d4f2fa10e5ff130157a9dfc0ef35 /src | |
| parent | df31bc64f96060ad7b15259faafb01206c41cf89 (diff) | |
| download | emacs-e46c910e4a464d0ec115a66f1810a8dea1f1502b.tar.gz emacs-e46c910e4a464d0ec115a66f1810a8dea1f1502b.zip | |
Use char tables as syntax tables.
(RAW_SYNTAX, RAW_SYNTAX_MATCH): Macros deleted.
(RAW_SYNTAX_ENTRY, SET_RAW_SYNTAX_ENTRY): New macros.
(SYNTAX, SYNTAX_MATCH): Rewritten.
(SYNTAX_ENTRY, SYNTAX_WITH_FLAGS): New macros.
(SYNTAX_COMSTART_SECOND, SYNTAX_COMEND_FIRST, SYNTAX_COMEND_SECOND)
(SYNTAX_PREFIX, SYNTAX_COMMENT_STYLE): Use SYNTAX_WITH_FLAGS.
Diffstat (limited to 'src')
| -rw-r--r-- | src/syntax.h | 189 |
1 files changed, 94 insertions, 95 deletions
diff --git a/src/syntax.h b/src/syntax.h index 2cdac9d1809..69a73c2fe9f 100644 --- a/src/syntax.h +++ b/src/syntax.h | |||
| @@ -25,10 +25,11 @@ extern Lisp_Object Fsyntax_table_p (), Fsyntax_table (), Fset_syntax_table (); | |||
| 25 | be used in all new buffers. */ | 25 | be used in all new buffers. */ |
| 26 | #define Vstandard_syntax_table buffer_defaults.syntax_table | 26 | #define Vstandard_syntax_table buffer_defaults.syntax_table |
| 27 | 27 | ||
| 28 | /* A syntax table is a Lisp vector of length 0400, whose elements are integers. | 28 | /* A syntax table is a chartable whose elements are cons cells |
| 29 | (CODE+FLAGS . MATCHING-CHAR). MATCHING-CHAR can be nil if the char | ||
| 30 | is not a kind of parenthesis. | ||
| 29 | 31 | ||
| 30 | The low 8 bits of the integer is a code, as follows: | 32 | The low 8 bits of CODE+FLAGS is a code, as follows: */ |
| 31 | */ | ||
| 32 | 33 | ||
| 33 | enum syntaxcode | 34 | enum syntaxcode |
| 34 | { | 35 | { |
| @@ -49,46 +50,97 @@ enum syntaxcode | |||
| 49 | Smax /* Upper bound on codes that are meaningful */ | 50 | Smax /* Upper bound on codes that are meaningful */ |
| 50 | }; | 51 | }; |
| 51 | 52 | ||
| 52 | #define RAW_SYNTAX(table, c) \ | 53 | /* Fetch the syntax entry for char C from table TABLE. |
| 53 | ((enum syntaxcode) (XINT (XVECTOR (table)->contents[(unsigned char) (c)]) & 0377)) | 54 | This returns the whole entry (normally a cons cell) |
| 55 | and does not do any kind of inheritance. */ | ||
| 54 | 56 | ||
| 55 | #ifdef __GNUC__ | 57 | #if 1 |
| 56 | #define SYNTAX(c) \ | 58 | #define RAW_SYNTAX_ENTRY(table, c) \ |
| 57 | ({ unsigned char character = c; \ | 59 | (XCHAR_TABLE (table)->contents[(unsigned char) (c)]) |
| 58 | enum syntaxcode syntax \ | 60 | |
| 59 | = RAW_SYNTAX (current_buffer->syntax_table, character); \ | 61 | #define SET_RAW_SYNTAX_ENTRY(table, c, val) \ |
| 60 | if (syntax == Sinherit) \ | 62 | (XCHAR_TABLE (table)->contents[(unsigned char) (c)] = (val)) |
| 61 | syntax = RAW_SYNTAX (Vstandard_syntax_table, character); \ | ||
| 62 | syntax; }) | ||
| 63 | #else | 63 | #else |
| 64 | #define SYNTAX(c) \ | 64 | #define RAW_SYNTAX_ENTRY(table, c) \ |
| 65 | (RAW_SYNTAX (current_buffer->syntax_table, c) == Sinherit \ | 65 | ((c) >= 128 \ |
| 66 | ? RAW_SYNTAX (Vstandard_syntax_table, c) \ | 66 | ? raw_syntax_table_lookup (table, c) \ |
| 67 | : RAW_SYNTAX (current_buffer->syntax_table, c)) | 67 | : XCHAR_TABLE (table)->contents[(unsigned char) (c)]) |
| 68 | |||
| 69 | #define SET_RAW_SYNTAX_ENTRY(table, c, val) \ | ||
| 70 | ((c) >= 128 \ | ||
| 71 | ? set_raw_syntax_table_lookup (table, c, (val)) \ | ||
| 72 | : XCHAR_TABLE (table)->contents[(unsigned char) (c)] = (val)) | ||
| 68 | #endif | 73 | #endif |
| 69 | 74 | ||
| 70 | /* The next 8 bits of the number is a character, | 75 | /* Extract the information from the entry for character C |
| 71 | the matching delimiter in the case of Sopen or Sclose. */ | 76 | in syntax table TABLE. Do inheritance. */ |
| 72 | |||
| 73 | #define RAW_SYNTAX_MATCH(table, c) \ | ||
| 74 | ((XINT (XVECTOR (table)->contents[(unsigned char) (c)]) >> 8) & 0377) | ||
| 75 | 77 | ||
| 76 | #ifdef __GNUC__ | 78 | #ifdef __GNUC__ |
| 77 | #define SYNTAX_MATCH(c) \ | 79 | #define SYNTAX_ENTRY(c) \ |
| 78 | ({ unsigned char character = c; \ | 80 | ({ Lisp_Object temp, table; \ |
| 79 | enum syntaxcode syntax \ | 81 | unsigned char cc = (c); \ |
| 80 | = RAW_SYNTAX (current_buffer->syntax_table, character); \ | 82 | table = current_buffer->syntax_table; \ |
| 81 | int matcher; \ | 83 | while (!NILP (table)) \ |
| 82 | if (syntax == Sinherit) \ | 84 | { \ |
| 83 | matcher = RAW_SYNTAX_MATCH (Vstandard_syntax_table, character); \ | 85 | temp = RAW_SYNTAX_ENTRY (table, cc); \ |
| 84 | else \ | 86 | if (!NILP (temp)) \ |
| 85 | matcher = RAW_SYNTAX_MATCH (current_buffer->syntax_table, character); \ | 87 | break; \ |
| 86 | matcher; }) | 88 | table = XCHAR_TABLE (table)->parent; \ |
| 89 | } \ | ||
| 90 | temp; }) | ||
| 91 | |||
| 92 | #define SYNTAX(c) \ | ||
| 93 | ({ Lisp_Object temp; \ | ||
| 94 | temp = SYNTAX_ENTRY (c); \ | ||
| 95 | (CONSP (temp) \ | ||
| 96 | ? (enum syntaxcode) (XINT (XCONS (temp)->car) & 0xff) \ | ||
| 97 | : wrong_type_argument (Qconsp, temp)); }) | ||
| 98 | |||
| 99 | #define SYNTAX_WITH_FLAGS(c) \ | ||
| 100 | ({ Lisp_Object temp; \ | ||
| 101 | temp = SYNTAX_ENTRY (c); \ | ||
| 102 | (CONSP (temp) \ | ||
| 103 | ? XINT (XCONS (temp)->car) \ | ||
| 104 | : wrong_type_argument (Qconsp, temp)); }) | ||
| 105 | |||
| 106 | #define SYNTAX_MATCH(c) \ | ||
| 107 | ({ Lisp_Object temp; \ | ||
| 108 | temp = SYNTAX_ENTRY (c); \ | ||
| 109 | (CONSP (temp) \ | ||
| 110 | ? XINT (XCONS (temp)->cdr) \ | ||
| 111 | : wrong_type_argument (Qconsp, temp)); }) | ||
| 87 | #else | 112 | #else |
| 88 | #define SYNTAX_MATCH(c) \ | 113 | extern Lisp_Object syntax_temp; |
| 89 | (RAW_SYNTAX (current_buffer->syntax_table, c) == Sinherit \ | 114 | extern Lisp_Object syntax_parent_lookup (); |
| 90 | ? RAW_SYNTAX_MATCH (Vstandard_syntax_table, c) \ | 115 | |
| 91 | : RAW_SYNTAX_MATCH (current_buffer->syntax_table, c)) | 116 | #define SYNTAX_ENTRY(c) \ |
| 117 | (syntax_temp \ | ||
| 118 | = RAW_SYNTAX_ENTRY (current_buffer->syntax_table, (c)), \ | ||
| 119 | (NILP (syntax_temp) \ | ||
| 120 | ? (syntax_temp \ | ||
| 121 | = syntax_parent_lookup (current_buffer->syntax_table, (c))) \ | ||
| 122 | : syntax_temp)) | ||
| 123 | |||
| 124 | #define SYNTAX(c) \ | ||
| 125 | (syntax_temp \ | ||
| 126 | = SYNTAX_ENTRY (current_buffer->syntax_table, (c)), \ | ||
| 127 | (CONSP (syntax_temp) \ | ||
| 128 | ? (enum syntaxcode) (XINT (XCONS (syntax_temp)->car) & 0xff) \ | ||
| 129 | : wrong_type_argument (Qconsp, syntax_temp)) }) | ||
| 130 | |||
| 131 | #define SYNTAX_WITH_FLAGS(c) \ | ||
| 132 | (syntax_temp \ | ||
| 133 | = SYNTAX_ENTRY (current_buffer->syntax_table, (c)), \ | ||
| 134 | (CONSP (syntax_temp) \ | ||
| 135 | ? XINT (XCONS (syntax_temp)->car) \ | ||
| 136 | : wrong_type_argument (Qconsp, syntax_temp)) }) | ||
| 137 | |||
| 138 | #define SYNTAX_MATCH(c) \ | ||
| 139 | (syntax_temp \ | ||
| 140 | = SYNTAX_ENTRY (current_buffer->syntax_table, (c)), \ | ||
| 141 | (CONSP (syntax_temp) \ | ||
| 142 | ? XINT (XCONS (syntax_temp)->cdr) \ | ||
| 143 | : wrong_type_argument (Qconsp, syntax_temp)) }) | ||
| 92 | #endif | 144 | #endif |
| 93 | 145 | ||
| 94 | /* Then there are six single-bit flags that have the following meanings: | 146 | /* Then there are six single-bit flags that have the following meanings: |
| @@ -107,71 +159,18 @@ enum syntaxcode | |||
| 107 | Style a is always the default. | 159 | Style a is always the default. |
| 108 | */ | 160 | */ |
| 109 | 161 | ||
| 110 | #define SYNTAX_CHOOSE_TABLE(c) \ | 162 | #define SYNTAX_COMSTART_FIRST(c) ((SYNTAX_WITH_FLAGS (c) >> 16) & 1) |
| 111 | (RAW_SYNTAX (current_buffer->syntax_table, c) == Sinherit \ | ||
| 112 | ? Vstandard_syntax_table : current_buffer->syntax_table) | ||
| 113 | 163 | ||
| 114 | #ifdef __GNUC__ | 164 | #define SYNTAX_COMSTART_SECOND(c) ((SYNTAX_WITH_FLAGS (c) >> 17) & 1) |
| 115 | 165 | ||
| 116 | #define SYNTAX_COMSTART_FIRST(c) \ | 166 | #define SYNTAX_COMEND_FIRST(c) ((SYNTAX_WITH_FLAGS (c) >> 18) & 1) |
| 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 | 167 | ||
| 146 | /* extract the comment style bit from the syntax table entry */ | 168 | #define SYNTAX_COMEND_SECOND(c) ((SYNTAX_WITH_FLAGS (c) >> 19) & 1) |
| 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 | 169 | ||
| 155 | #define SYNTAX_COMSTART_FIRST(c) \ | 170 | #define SYNTAX_PREFIX(c) ((SYNTAX_WITH_FLAGS (c) >> 20) & 1) |
| 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 | 171 | ||
| 170 | /* extract the comment style bit from the syntax table entry */ | 172 | /* extract the comment style bit from the syntax table entry */ |
| 171 | #define SYNTAX_COMMENT_STYLE(c) \ | 173 | #define SYNTAX_COMMENT_STYLE(c) ((SYNTAX_WITH_FLAGS (c) >> 21) & 1) |
| 172 | ((XINT (XVECTOR (SYNTAX_CHOOSE_TABLE (c))->contents[(unsigned char) (c)]) >> 21) & 1) | ||
| 173 | |||
| 174 | #endif | ||
| 175 | 174 | ||
| 176 | /* This array, indexed by a character, contains the syntax code which that | 175 | /* This array, indexed by a character, contains the syntax code which that |
| 177 | character signifies (as a char). For example, | 176 | character signifies (as a char). For example, |