Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / src / syntax.h
CommitLineData
9889c728 1/* Declarations having to do with GNU Emacs syntax tables.
73b0cd50 2 Copyright (C) 1985, 1993-1994, 1997-1998, 2001-2011 Free Software Foundation, Inc.
9889c728
JB
3
4This file is part of GNU Emacs.
5
b9b1cc14 6GNU Emacs is free software: you can redistribute it and/or modify
9889c728 7it under the terms of the GNU General Public License as published by
b9b1cc14
GM
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
9889c728
JB
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
b9b1cc14 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
9889c728
JB
18
19
20extern Lisp_Object Qsyntax_table_p;
4f3a2f8d 21extern void update_syntax_table (EMACS_INT, int, int, Lisp_Object);
9889c728
JB
22
23/* The standard syntax table is stored where it will automatically
24 be used in all new buffers. */
25#define Vstandard_syntax_table buffer_defaults.syntax_table
26
e46c910e
RS
27/* A syntax table is a chartable whose elements are cons cells
28 (CODE+FLAGS . MATCHING-CHAR). MATCHING-CHAR can be nil if the char
29 is not a kind of parenthesis.
9889c728 30
e46c910e 31 The low 8 bits of CODE+FLAGS is a code, as follows: */
9889c728
JB
32
33enum 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 " */
5eea1c5a 43 Smath, /* for delimiters like $ in Tex. */
9889c728
JB
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 */
c8cdcb16 48 Sinherit, /* use the standard syntax table for this character */
5eea1c5a 49 Scomment_fence, /* Starts/ends comment which is delimited on the
47ab3db5 50 other side by any char with the same syntaxcode. */
5eea1c5a 51 Sstring_fence, /* Starts/ends string which is delimited on the
47ab3db5 52 other side by any char with the same syntaxcode. */
9889c728
JB
53 Smax /* Upper bound on codes that are meaningful */
54 };
55
e0b8ff93 56/* Set the syntax entry VAL for char C in table TABLE. */
e46c910e 57
f4926ee8 58#define SET_RAW_SYNTAX_ENTRY(table, c, val) \
dcb82a5e 59 CHAR_TABLE_SET ((table), c, (val))
e0b8ff93 60
f4926ee8
KH
61/* Set the syntax entry VAL for char-range RANGE in table TABLE.
62 RANGE is a cons (FROM . TO) specifying the range of characters. */
e0b8ff93 63
f4926ee8
KH
64#define SET_RAW_SYNTAX_ENTRY_RANGE(table, range, val) \
65 Fset_char_table_range ((table), (range), (val))
9889c728 66
5eea1c5a 67/* SYNTAX_ENTRY fetches the information from the entry for character C
177c0ea7 68 in syntax table TABLE, or from globally kept data (gl_state).
5eea1c5a
RS
69 Does inheritance. */
70/* CURRENT_SYNTAX_TABLE gives the syntax table valid for current
71 position, it is either the buffer's syntax table, or syntax table
72 found in text properties. */
73
74#ifdef SYNTAX_ENTRY_VIA_PROPERTY
75# define SYNTAX_ENTRY(c) \
76 (gl_state.use_global ? gl_state.global_code : SYNTAX_ENTRY_INT (c))
77# define CURRENT_SYNTAX_TABLE gl_state.current_syntax_table
78#else
79# define SYNTAX_ENTRY SYNTAX_ENTRY_INT
80# define CURRENT_SYNTAX_TABLE current_buffer->syntax_table
81#endif
e0b8ff93 82
501d7ac6 83#define SYNTAX_ENTRY_INT(c) CHAR_TABLE_REF (CURRENT_SYNTAX_TABLE, (c))
e0b8ff93 84
e46c910e 85/* Extract the information from the entry for character C
e0b8ff93 86 in the current syntax table. */
c8cdcb16
RS
87
88#ifdef __GNUC__
e46c910e 89#define SYNTAX(c) \
874757e8
AS
90 ({ Lisp_Object _syntax_temp; \
91 _syntax_temp = SYNTAX_ENTRY (c); \
92 (CONSP (_syntax_temp) \
93 ? (enum syntaxcode) (XINT (XCAR (_syntax_temp)) & 0xff) \
e0b8ff93 94 : Swhitespace); })
e46c910e
RS
95
96#define SYNTAX_WITH_FLAGS(c) \
874757e8
AS
97 ({ Lisp_Object _syntax_temp; \
98 _syntax_temp = SYNTAX_ENTRY (c); \
99 (CONSP (_syntax_temp) \
100 ? XINT (XCAR (_syntax_temp)) \
e0b8ff93 101 : (int) Swhitespace); })
e46c910e
RS
102
103#define SYNTAX_MATCH(c) \
874757e8
AS
104 ({ Lisp_Object _syntax_temp; \
105 _syntax_temp = SYNTAX_ENTRY (c); \
106 (CONSP (_syntax_temp) \
107 ? XCDR (_syntax_temp) \
e0b8ff93 108 : Qnil); })
c8cdcb16 109#else
3d7db6f1 110extern Lisp_Object syntax_temp;
e46c910e 111#define SYNTAX(c) \
9d40ebd2 112 (syntax_temp = SYNTAX_ENTRY ((c)), \
e46c910e 113 (CONSP (syntax_temp) \
3331fb06 114 ? (enum syntaxcode) (XINT (XCAR (syntax_temp)) & 0xff) \
e0b8ff93 115 : Swhitespace))
e46c910e
RS
116
117#define SYNTAX_WITH_FLAGS(c) \
9d40ebd2 118 (syntax_temp = SYNTAX_ENTRY ((c)), \
e46c910e 119 (CONSP (syntax_temp) \
3331fb06 120 ? XINT (XCAR (syntax_temp)) \
e0b8ff93 121 : (int) Swhitespace))
e46c910e
RS
122
123#define SYNTAX_MATCH(c) \
9d40ebd2 124 (syntax_temp = SYNTAX_ENTRY ((c)), \
e46c910e 125 (CONSP (syntax_temp) \
3331fb06 126 ? XCDR (syntax_temp) \
e0b8ff93 127 : Qnil))
c8cdcb16 128#endif
9889c728 129
a306d6f1 130
c5683ceb
SM
131/* Whether the syntax of the character C has the prefix flag set. */
132extern int syntax_prefix_flag_p (int c);
c0364919 133
9889c728
JB
134/* This array, indexed by a character, contains the syntax code which that
135 character signifies (as a char). For example,
5eea1c5a 136 (enum syntaxcode) syntax_spec_code['w'] is Sword. */
9889c728
JB
137
138extern unsigned char syntax_spec_code[0400];
139
5eea1c5a
RS
140/* Indexed by syntax code, give the letter that describes it. */
141
142extern char syntax_code_spec[16];
143
c292db29 144/* Convert the byte offset BYTEPOS into a character position,
2f16e7fd
RS
145 for the object recorded in gl_state with SETUP_SYNTAX_TABLE_FOR_OBJECT.
146
147 The value is meant for use in the UPDATE_SYNTAX_TABLE... macros.
148 These macros do nothing when parse_sexp_lookup_properties is 0,
149 so we return 0 in that case, for speed. */
c292db29
RS
150
151#define SYNTAX_TABLE_BYTE_TO_CHAR(bytepos) \
2f16e7fd
RS
152 (! parse_sexp_lookup_properties \
153 ? 0 \
154 : STRINGP (gl_state.object) \
c292db29
RS
155 ? string_byte_to_char (gl_state.object, (bytepos)) \
156 : BUFFERP (gl_state.object) \
f79b4b7e
KH
157 ? buf_bytepos_to_charpos (XBUFFER (gl_state.object), \
158 (bytepos) + BUF_BEGV_BYTE (XBUFFER (gl_state.object)) - 1) - BUF_BEGV (XBUFFER (gl_state.object)) + 1 \
c292db29 159 : NILP (gl_state.object) \
f79b4b7e 160 ? BYTE_TO_CHAR ((bytepos) + BEGV_BYTE - 1) - BEGV + 1 \
c292db29
RS
161 : (bytepos))
162
f79b4b7e
KH
163/* Make syntax table state (gl_state) good for CHARPOS, assuming it is
164 currently good for a position before CHARPOS. */
5eea1c5a 165
f79b4b7e 166#define UPDATE_SYNTAX_TABLE_FORWARD(charpos) \
2f16e7fd 167 (parse_sexp_lookup_properties \
f79b4b7e
KH
168 && (charpos) >= gl_state.e_property \
169 ? (update_syntax_table ((charpos) + gl_state.offset, 1, 0, \
c292db29
RS
170 gl_state.object), \
171 1) \
172 : 0)
5eea1c5a 173
f79b4b7e
KH
174/* Make syntax table state (gl_state) good for CHARPOS, assuming it is
175 currently good for a position after CHARPOS. */
5eea1c5a 176
f79b4b7e 177#define UPDATE_SYNTAX_TABLE_BACKWARD(charpos) \
2f16e7fd 178 (parse_sexp_lookup_properties \
4948e1f2 179 && (charpos) < gl_state.b_property \
f79b4b7e 180 ? (update_syntax_table ((charpos) + gl_state.offset, -1, 0, \
c292db29
RS
181 gl_state.object), \
182 1) \
183 : 0)
e2d8d746 184
f79b4b7e 185/* Make syntax table good for CHARPOS. */
e2d8d746 186
f79b4b7e 187#define UPDATE_SYNTAX_TABLE(charpos) \
2f16e7fd 188 (parse_sexp_lookup_properties \
4948e1f2 189 && (charpos) < gl_state.b_property \
f79b4b7e 190 ? (update_syntax_table ((charpos) + gl_state.offset, -1, 0, \
c292db29
RS
191 gl_state.object), \
192 1) \
2f16e7fd 193 : (parse_sexp_lookup_properties \
f79b4b7e
KH
194 && (charpos) >= gl_state.e_property \
195 ? (update_syntax_table ((charpos) + gl_state.offset, 1, 0,\
c292db29
RS
196 gl_state.object), \
197 1) \
198 : 0))
5eea1c5a 199
d48cd3f4
SM
200/* This macro sets up the buffer-global syntax table. */
201#define SETUP_BUFFER_SYNTAX_TABLE() \
202do \
203 { \
204 gl_state.use_global = 0; \
205 gl_state.current_syntax_table = current_buffer->syntax_table; \
206 } while (0)
207
5eea1c5a
RS
208/* This macro should be called with FROM at the start of forward
209 search, or after the last position of the backward search. It
210 makes sure that the first char is picked up with correct table, so
211 one does not need to call UPDATE_SYNTAX_TABLE immediately after the
177c0ea7 212 call.
5eea1c5a
RS
213 Sign of COUNT gives the direction of the search.
214 */
215
c292db29 216#define SETUP_SYNTAX_TABLE(FROM, COUNT) \
92413ef3 217do \
2f16e7fd 218 { \
d48cd3f4 219 SETUP_BUFFER_SYNTAX_TABLE (); \
4948e1f2 220 gl_state.b_property = BEGV; \
2f16e7fd
RS
221 gl_state.e_property = ZV + 1; \
222 gl_state.object = Qnil; \
2f16e7fd 223 gl_state.offset = 0; \
2f16e7fd 224 if (parse_sexp_lookup_properties) \
9b9794f0
RS
225 if ((COUNT) > 0 || (FROM) > BEGV) \
226 update_syntax_table ((COUNT) > 0 ? (FROM) : (FROM) - 1, (COUNT),\
227 1, Qnil); \
2f16e7fd 228 } \
92413ef3 229while (0)
5eea1c5a
RS
230
231/* Same as above, but in OBJECT. If OBJECT is nil, use current buffer.
e2d8d746
RS
232 If it is t, ignore properties altogether.
233
234 This is meant for regex.c to use. For buffers, regex.c passes arguments
235 to the UPDATE_SYNTAX_TABLE macros which are relative to BEGV.
4bbd5bc3 236 So if it is a buffer, we set the offset field to BEGV. */
5eea1c5a 237
c292db29 238#define SETUP_SYNTAX_TABLE_FOR_OBJECT(OBJECT, FROM, COUNT) \
92413ef3 239do \
4bbd5bc3 240 { \
d48cd3f4 241 SETUP_BUFFER_SYNTAX_TABLE (); \
c292db29
RS
242 gl_state.object = (OBJECT); \
243 if (BUFFERP (gl_state.object)) \
244 { \
245 struct buffer *buf = XBUFFER (gl_state.object); \
4948e1f2 246 gl_state.b_property = 1; \
1d1293dd 247 gl_state.e_property = BUF_ZV (buf) - BUF_BEGV (buf) + 1; \
c292db29
RS
248 gl_state.offset = BUF_BEGV (buf) - 1; \
249 } \
250 else if (NILP (gl_state.object)) \
4bbd5bc3 251 { \
4948e1f2 252 gl_state.b_property = 1; \
1d1293dd 253 gl_state.e_property = ZV - BEGV + 1; \
4bbd5bc3
RS
254 gl_state.offset = BEGV - 1; \
255 } \
c292db29 256 else if (EQ (gl_state.object, Qt)) \
4bbd5bc3 257 { \
4948e1f2 258 gl_state.b_property = 0; \
4bbd5bc3
RS
259 gl_state.e_property = 1500000000; \
260 gl_state.offset = 0; \
261 } \
262 else \
263 { \
4948e1f2 264 gl_state.b_property = 0; \
d5db4077 265 gl_state.e_property = 1 + SCHARS (gl_state.object); \
4bbd5bc3
RS
266 gl_state.offset = 0; \
267 } \
4bbd5bc3 268 if (parse_sexp_lookup_properties) \
f79b4b7e 269 update_syntax_table (((FROM) + gl_state.offset \
c292db29
RS
270 + (COUNT > 0 ? 0 : -1)), \
271 COUNT, 1, gl_state.object); \
4bbd5bc3 272 } \
92413ef3 273while (0)
5eea1c5a
RS
274
275struct gl_state_s
276{
c292db29 277 Lisp_Object object; /* The object we are scanning. */
5eea1c5a
RS
278 int start; /* Where to stop. */
279 int stop; /* Where to stop. */
280 int use_global; /* Whether to use global_code
281 or c_s_t. */
282 Lisp_Object global_code; /* Syntax code of current char. */
283 Lisp_Object current_syntax_table; /* Syntax table for current pos. */
284 Lisp_Object old_prop; /* Syntax-table prop at prev pos. */
4948e1f2 285 int b_property; /* First index where c_s_t is valid. */
5eea1c5a
RS
286 int e_property; /* First index where c_s_t is
287 not valid. */
288 INTERVAL forward_i; /* Where to start lookup on forward */
289 INTERVAL backward_i; /* or backward movement. The
290 data in c_s_t is valid
291 between these intervals,
292 and possibly at the
293 intervals too, depending
294 on: */
e2d8d746
RS
295 /* Offset for positions specified to UPDATE_SYNTAX_TABLE. */
296 int offset;
5eea1c5a
RS
297};
298
299extern struct gl_state_s gl_state;
4f3a2f8d 300extern EMACS_INT scan_words (EMACS_INT, EMACS_INT);
839966f3 301