Commit | Line | Data |
---|---|---|
9889c728 | 1 | /* Declarations having to do with GNU Emacs syntax tables. |
95df8112 | 2 | |
ab422c4d PE |
3 | Copyright (C) 1985, 1993-1994, 1997-1998, 2001-2013 Free Software |
4 | Foundation, Inc. | |
9889c728 JB |
5 | |
6 | This file is part of GNU Emacs. | |
7 | ||
b9b1cc14 | 8 | GNU Emacs is free software: you can redistribute it and/or modify |
9889c728 | 9 | it under the terms of the GNU General Public License as published by |
b9b1cc14 GM |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
9889c728 JB |
12 | |
13 | GNU Emacs is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
b9b1cc14 | 19 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
9889c728 | 20 | |
45b683a1 | 21 | INLINE_HEADER_BEGIN |
9889c728 | 22 | |
1fc71008 | 23 | extern void update_syntax_table (ptrdiff_t, EMACS_INT, bool, Lisp_Object); |
9889c728 JB |
24 | |
25 | /* The standard syntax table is stored where it will automatically | |
26 | be used in all new buffers. */ | |
4b4deea2 | 27 | #define Vstandard_syntax_table BVAR (&buffer_defaults, syntax_table) |
9889c728 | 28 | |
e46c910e RS |
29 | /* A syntax table is a chartable whose elements are cons cells |
30 | (CODE+FLAGS . MATCHING-CHAR). MATCHING-CHAR can be nil if the char | |
31 | is not a kind of parenthesis. | |
9889c728 | 32 | |
e46c910e | 33 | The low 8 bits of CODE+FLAGS is a code, as follows: */ |
9889c728 JB |
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 " */ | |
5eea1c5a | 45 | Smath, /* for delimiters like $ in Tex. */ |
9889c728 JB |
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 */ | |
c8cdcb16 | 50 | Sinherit, /* use the standard syntax table for this character */ |
5eea1c5a | 51 | Scomment_fence, /* Starts/ends comment which is delimited on the |
47ab3db5 | 52 | other side by any char with the same syntaxcode. */ |
5eea1c5a | 53 | Sstring_fence, /* Starts/ends string which is delimited on the |
47ab3db5 | 54 | other side by any char with the same syntaxcode. */ |
9889c728 JB |
55 | Smax /* Upper bound on codes that are meaningful */ |
56 | }; | |
57 | ||
e0b8ff93 | 58 | |
45b683a1 PE |
59 | struct gl_state_s |
60 | { | |
61 | Lisp_Object object; /* The object we are scanning. */ | |
62 | ptrdiff_t start; /* Where to stop. */ | |
63 | ptrdiff_t stop; /* Where to stop. */ | |
64 | bool use_global; /* Whether to use global_code | |
65 | or c_s_t. */ | |
66 | Lisp_Object global_code; /* Syntax code of current char. */ | |
67 | Lisp_Object current_syntax_table; /* Syntax table for current pos. */ | |
68 | Lisp_Object old_prop; /* Syntax-table prop at prev pos. */ | |
69 | ptrdiff_t b_property; /* First index where c_s_t is valid. */ | |
70 | ptrdiff_t e_property; /* First index where c_s_t is | |
71 | not valid. */ | |
72 | INTERVAL forward_i; /* Where to start lookup on forward */ | |
73 | INTERVAL backward_i; /* or backward movement. The | |
74 | data in c_s_t is valid | |
75 | between these intervals, | |
76 | and possibly at the | |
77 | intervals too, depending | |
78 | on: */ | |
79 | /* Offset for positions specified to UPDATE_SYNTAX_TABLE. */ | |
80 | ptrdiff_t offset; | |
81 | }; | |
e0b8ff93 | 82 | |
45b683a1 | 83 | extern struct gl_state_s gl_state; |
9889c728 | 84 | |
45b683a1 | 85 | /* Fetch the information from the entry for character C |
c6cfd910 PE |
86 | in the current buffer's syntax table, |
87 | or (if VIA_PROPERTY) from globally kept data (gl_state). | |
5eea1c5a | 88 | Does inheritance. */ |
5eea1c5a | 89 | |
00382e8b | 90 | INLINE Lisp_Object |
c6cfd910 | 91 | syntax_property_entry (int c, bool via_property) |
45b683a1 | 92 | { |
c6cfd910 PE |
93 | if (via_property) |
94 | return (gl_state.use_global | |
95 | ? gl_state.global_code | |
96 | : CHAR_TABLE_REF (gl_state.current_syntax_table, c)); | |
45b683a1 | 97 | return CHAR_TABLE_REF (BVAR (current_buffer, syntax_table), c); |
c6cfd910 PE |
98 | } |
99 | INLINE Lisp_Object | |
100 | SYNTAX_ENTRY (int c) | |
101 | { | |
102 | return syntax_property_entry (c, 0); | |
45b683a1 | 103 | } |
e0b8ff93 | 104 | |
e46c910e | 105 | /* Extract the information from the entry for character C |
e0b8ff93 | 106 | in the current syntax table. */ |
c8cdcb16 | 107 | |
00382e8b | 108 | INLINE int |
c6cfd910 | 109 | syntax_property_with_flags (int c, bool via_property) |
45b683a1 | 110 | { |
c6cfd910 | 111 | Lisp_Object ent = syntax_property_entry (c, via_property); |
45b683a1 PE |
112 | return CONSP (ent) ? XINT (XCAR (ent)) : Swhitespace; |
113 | } | |
c6cfd910 PE |
114 | INLINE int |
115 | SYNTAX_WITH_FLAGS (int c) | |
116 | { | |
117 | return syntax_property_with_flags (c, 0); | |
118 | } | |
45b683a1 | 119 | |
c6cfd910 PE |
120 | INLINE enum syntaxcode |
121 | syntax_property (int c, bool via_property) | |
122 | { | |
123 | return syntax_property_with_flags (c, via_property) & 0xff; | |
124 | } | |
00382e8b | 125 | INLINE enum syntaxcode |
45b683a1 PE |
126 | SYNTAX (int c) |
127 | { | |
c6cfd910 | 128 | return syntax_property (c, 0); |
45b683a1 | 129 | } |
9889c728 | 130 | |
a306d6f1 | 131 | |
c5683ceb | 132 | /* Whether the syntax of the character C has the prefix flag set. */ |
1fc71008 | 133 | extern bool syntax_prefix_flag_p (int c); |
c0364919 | 134 | |
1fc71008 PE |
135 | /* This array, indexed by a character less than 256, contains the |
136 | syntax code which that character signifies (as an unsigned char). | |
137 | For example, syntax_spec_code['w'] == Sword. */ | |
9889c728 | 138 | |
1fc71008 | 139 | extern unsigned char const syntax_spec_code[0400]; |
9889c728 | 140 | |
5eea1c5a RS |
141 | /* Indexed by syntax code, give the letter that describes it. */ |
142 | ||
1fc71008 | 143 | extern char const syntax_code_spec[16]; |
5eea1c5a | 144 | |
c292db29 | 145 | /* Convert the byte offset BYTEPOS into a character position, |
2f16e7fd RS |
146 | for the object recorded in gl_state with SETUP_SYNTAX_TABLE_FOR_OBJECT. |
147 | ||
45b683a1 PE |
148 | The value is meant for use in code that does nothing when |
149 | parse_sexp_lookup_properties is 0, so return 0 in that case, for speed. */ | |
150 | ||
00382e8b | 151 | INLINE ptrdiff_t |
45b683a1 PE |
152 | SYNTAX_TABLE_BYTE_TO_CHAR (ptrdiff_t bytepos) |
153 | { | |
154 | return (! parse_sexp_lookup_properties | |
155 | ? 0 | |
156 | : STRINGP (gl_state.object) | |
157 | ? string_byte_to_char (gl_state.object, bytepos) | |
158 | : BUFFERP (gl_state.object) | |
159 | ? ((buf_bytepos_to_charpos | |
160 | (XBUFFER (gl_state.object), | |
161 | (bytepos + BUF_BEGV_BYTE (XBUFFER (gl_state.object)) - 1))) | |
162 | - BUF_BEGV (XBUFFER (gl_state.object)) + 1) | |
163 | : NILP (gl_state.object) | |
164 | ? BYTE_TO_CHAR (bytepos + BEGV_BYTE - 1) - BEGV + 1 | |
165 | : bytepos); | |
166 | } | |
c292db29 | 167 | |
f79b4b7e KH |
168 | /* Make syntax table state (gl_state) good for CHARPOS, assuming it is |
169 | currently good for a position before CHARPOS. */ | |
5eea1c5a | 170 | |
00382e8b | 171 | INLINE void |
45b683a1 PE |
172 | UPDATE_SYNTAX_TABLE_FORWARD (ptrdiff_t charpos) |
173 | { | |
174 | if (parse_sexp_lookup_properties && charpos >= gl_state.e_property) | |
175 | update_syntax_table (charpos + gl_state.offset, 1, 0, gl_state.object); | |
176 | } | |
5eea1c5a | 177 | |
f79b4b7e KH |
178 | /* Make syntax table state (gl_state) good for CHARPOS, assuming it is |
179 | currently good for a position after CHARPOS. */ | |
5eea1c5a | 180 | |
00382e8b | 181 | INLINE void |
45b683a1 PE |
182 | UPDATE_SYNTAX_TABLE_BACKWARD (ptrdiff_t charpos) |
183 | { | |
184 | if (parse_sexp_lookup_properties && charpos < gl_state.b_property) | |
185 | update_syntax_table (charpos + gl_state.offset, -1, 0, gl_state.object); | |
186 | } | |
e2d8d746 | 187 | |
f79b4b7e | 188 | /* Make syntax table good for CHARPOS. */ |
e2d8d746 | 189 | |
00382e8b | 190 | INLINE void |
45b683a1 PE |
191 | UPDATE_SYNTAX_TABLE (ptrdiff_t charpos) |
192 | { | |
193 | UPDATE_SYNTAX_TABLE_BACKWARD (charpos); | |
194 | UPDATE_SYNTAX_TABLE_FORWARD (charpos); | |
195 | } | |
196 | ||
197 | /* Set up the buffer-global syntax table. */ | |
5eea1c5a | 198 | |
00382e8b | 199 | INLINE void |
45b683a1 | 200 | SETUP_BUFFER_SYNTAX_TABLE (void) |
5eea1c5a | 201 | { |
45b683a1 PE |
202 | gl_state.use_global = 0; |
203 | gl_state.current_syntax_table = BVAR (current_buffer, syntax_table); | |
204 | } | |
5eea1c5a | 205 | |
d311d28c | 206 | extern ptrdiff_t scan_words (ptrdiff_t, EMACS_INT); |
45b683a1 PE |
207 | extern void SETUP_SYNTAX_TABLE_FOR_OBJECT (Lisp_Object, ptrdiff_t, ptrdiff_t); |
208 | ||
209 | INLINE_HEADER_END |