comparison src/syntax.h @ 13143:ba670977cceb

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.
author Richard M. Stallman <rms@gnu.org>
date Sat, 07 Oct 1995 21:55:20 +0000
parents ac7375e60931
children 94a4b6e9d310
comparison
equal deleted inserted replaced
13142:297a0e21501a 13143:ba670977cceb
23 23
24 /* The standard syntax table is stored where it will automatically 24 /* The standard syntax table is stored where it will automatically
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 {
35 Swhitespace, /* for a whitespace character */ 36 Swhitespace, /* for a whitespace character */
36 Spunct, /* for random punctuation characters */ 37 Spunct, /* for random punctuation characters */
47 Sendcomment, /* for a comment-ending character */ 48 Sendcomment, /* for a comment-ending character */
48 Sinherit, /* use the standard syntax table for this character */ 49 Sinherit, /* use the standard syntax table for this character */
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. */
56
57 #if 1
58 #define RAW_SYNTAX_ENTRY(table, c) \
59 (XCHAR_TABLE (table)->contents[(unsigned char) (c)])
60
61 #define SET_RAW_SYNTAX_ENTRY(table, c, val) \
62 (XCHAR_TABLE (table)->contents[(unsigned char) (c)] = (val))
63 #else
64 #define RAW_SYNTAX_ENTRY(table, c) \
65 ((c) >= 128 \
66 ? raw_syntax_table_lookup (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))
73 #endif
74
75 /* Extract the information from the entry for character C
76 in syntax table TABLE. Do inheritance. */
54 77
55 #ifdef __GNUC__ 78 #ifdef __GNUC__
56 #define SYNTAX(c) \ 79 #define SYNTAX_ENTRY(c) \
57 ({ unsigned char character = c; \ 80 ({ Lisp_Object temp, table; \
58 enum syntaxcode syntax \ 81 unsigned char cc = (c); \
59 = RAW_SYNTAX (current_buffer->syntax_table, character); \ 82 table = current_buffer->syntax_table; \
60 if (syntax == Sinherit) \ 83 while (!NILP (table)) \
61 syntax = RAW_SYNTAX (Vstandard_syntax_table, character); \ 84 { \
62 syntax; }) 85 temp = RAW_SYNTAX_ENTRY (table, cc); \
86 if (!NILP (temp)) \
87 break; \
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)); })
63 #else 112 #else
64 #define SYNTAX(c) \ 113 extern Lisp_Object syntax_temp;
65 (RAW_SYNTAX (current_buffer->syntax_table, c) == Sinherit \ 114 extern Lisp_Object syntax_parent_lookup ();
66 ? RAW_SYNTAX (Vstandard_syntax_table, c) \
67 : RAW_SYNTAX (current_buffer->syntax_table, c))
68 #endif
69 115
70 /* The next 8 bits of the number is a character, 116 #define SYNTAX_ENTRY(c) \
71 the matching delimiter in the case of Sopen or Sclose. */ 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))
72 123
73 #define RAW_SYNTAX_MATCH(table, c) \ 124 #define SYNTAX(c) \
74 ((XINT (XVECTOR (table)->contents[(unsigned char) (c)]) >> 8) & 0377) 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)) })
75 130
76 #ifdef __GNUC__ 131 #define SYNTAX_WITH_FLAGS(c) \
77 #define SYNTAX_MATCH(c) \ 132 (syntax_temp \
78 ({ unsigned char character = c; \ 133 = SYNTAX_ENTRY (current_buffer->syntax_table, (c)), \
79 enum syntaxcode syntax \ 134 (CONSP (syntax_temp) \
80 = RAW_SYNTAX (current_buffer->syntax_table, character); \ 135 ? XINT (XCONS (syntax_temp)->car) \
81 int matcher; \ 136 : wrong_type_argument (Qconsp, syntax_temp)) })
82 if (syntax == Sinherit) \ 137
83 matcher = RAW_SYNTAX_MATCH (Vstandard_syntax_table, character); \ 138 #define SYNTAX_MATCH(c) \
84 else \ 139 (syntax_temp \
85 matcher = RAW_SYNTAX_MATCH (current_buffer->syntax_table, character); \ 140 = SYNTAX_ENTRY (current_buffer->syntax_table, (c)), \
86 matcher; }) 141 (CONSP (syntax_temp) \
87 #else 142 ? XINT (XCONS (syntax_temp)->cdr) \
88 #define SYNTAX_MATCH(c) \ 143 : wrong_type_argument (Qconsp, syntax_temp)) })
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 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:
95 1. This character is the first of a two-character comment-start sequence. 147 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. 148 2. This character is the second of a two-character comment-start sequence.
105 and bit 6 is used to determine whether a comment-end or Scommentend 157 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. 158 ends style a or b. Comment start sequences can start style a or b.
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 167
122 #define SYNTAX_COMSTART_SECOND(c) \ 168 #define SYNTAX_COMEND_SECOND(c) ((SYNTAX_WITH_FLAGS (c) >> 19) & 1)
123 ({ unsigned char ch = c; \
124 Lisp_Object table = SYNTAX_CHOOSE_TABLE (ch); \
125 (XINT (XVECTOR (table)->contents[ch]) >> 17) & 1; \
126 })
127 169
128 #define SYNTAX_COMEND_FIRST(c) \ 170 #define SYNTAX_PREFIX(c) ((SYNTAX_WITH_FLAGS (c) >> 20) & 1)
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 171
146 /* extract the comment style bit from the syntax table entry */ 172 /* extract the comment style bit from the syntax table entry */
147 #define SYNTAX_COMMENT_STYLE(c) \ 173 #define SYNTAX_COMMENT_STYLE(c) ((SYNTAX_WITH_FLAGS (c) >> 21) & 1)
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 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,
178 (enum syntaxcode) syntax_spec_code['w'] is Sword. */ 177 (enum syntaxcode) syntax_spec_code['w'] is Sword. */
179 178