aboutsummaryrefslogtreecommitdiffstats
path: root/src/syntax.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax.c')
-rw-r--r--src/syntax.c76
1 files changed, 40 insertions, 36 deletions
diff --git a/src/syntax.c b/src/syntax.c
index 2f47d73d695..82103cfa3d4 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -19,7 +19,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19 19
20 20
21#include <config.h> 21#include <config.h>
22
22#include <ctype.h> 23#include <ctype.h>
24#include <sys/types.h>
23#include <setjmp.h> 25#include <setjmp.h>
24#include "lisp.h" 26#include "lisp.h"
25#include "commands.h" 27#include "commands.h"
@@ -95,12 +97,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
95#define ST_COMMENT_STYLE (256 + 1) 97#define ST_COMMENT_STYLE (256 + 1)
96#define ST_STRING_STYLE (256 + 2) 98#define ST_STRING_STYLE (256 + 2)
97 99
98Lisp_Object Qsyntax_table_p, Qsyntax_table, Qscan_error; 100static Lisp_Object Qsyntax_table_p;
101static Lisp_Object Qsyntax_table, Qscan_error;
99 102
103#ifndef __GNUC__
100/* Used as a temporary in SYNTAX_ENTRY and other macros in syntax.h, 104/* Used as a temporary in SYNTAX_ENTRY and other macros in syntax.h,
101 if not compiled with GCC. No need to mark it, since it is used 105 if not compiled with GCC. No need to mark it, since it is used
102 only very temporarily. */ 106 only very temporarily. */
103Lisp_Object syntax_temp; 107Lisp_Object syntax_temp;
108#endif
104 109
105/* This is the internal form of the parse state used in parse-partial-sexp. */ 110/* This is the internal form of the parse state used in parse-partial-sexp. */
106 111
@@ -138,6 +143,7 @@ static EMACS_INT find_start_begv;
138static int find_start_modiff; 143static int find_start_modiff;
139 144
140 145
146static Lisp_Object Fsyntax_table_p (Lisp_Object);
141static Lisp_Object skip_chars (int, Lisp_Object, Lisp_Object, int); 147static Lisp_Object skip_chars (int, Lisp_Object, Lisp_Object, int);
142static Lisp_Object skip_syntaxes (int, Lisp_Object, Lisp_Object); 148static Lisp_Object skip_syntaxes (int, Lisp_Object, Lisp_Object);
143static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, int); 149static Lisp_Object scan_lists (EMACS_INT, EMACS_INT, EMACS_INT, int);
@@ -171,11 +177,12 @@ struct gl_state_s gl_state; /* Global state of syntax parser. */
171 start/end of OBJECT. */ 177 start/end of OBJECT. */
172 178
173void 179void
174update_syntax_table (EMACS_INT charpos, int count, int init, 180update_syntax_table (EMACS_INT charpos, EMACS_INT count, int init,
175 Lisp_Object object) 181 Lisp_Object object)
176{ 182{
177 Lisp_Object tmp_table; 183 Lisp_Object tmp_table;
178 int cnt = 0, invalidate = 1; 184 unsigned cnt = 0;
185 int invalidate = 1;
179 INTERVAL i; 186 INTERVAL i;
180 187
181 if (init) 188 if (init)
@@ -277,7 +284,7 @@ update_syntax_table (EMACS_INT charpos, int count, int init,
277 else 284 else
278 { 285 {
279 gl_state.use_global = 0; 286 gl_state.use_global = 0;
280 gl_state.current_syntax_table = current_buffer->syntax_table; 287 gl_state.current_syntax_table = BVAR (current_buffer, syntax_table);
281 } 288 }
282 } 289 }
283 290
@@ -360,10 +367,10 @@ char_quoted (EMACS_INT charpos, EMACS_INT bytepos)
360/* Return the bytepos one character before BYTEPOS. 367/* Return the bytepos one character before BYTEPOS.
361 We assume that BYTEPOS is not at the start of the buffer. */ 368 We assume that BYTEPOS is not at the start of the buffer. */
362 369
363static INLINE EMACS_INT 370static inline EMACS_INT
364dec_bytepos (EMACS_INT bytepos) 371dec_bytepos (EMACS_INT bytepos)
365{ 372{
366 if (NILP (current_buffer->enable_multibyte_characters)) 373 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
367 return bytepos - 1; 374 return bytepos - 1;
368 375
369 DEC_POS (bytepos); 376 DEC_POS (bytepos);
@@ -513,7 +520,7 @@ back_comment (EMACS_INT from, EMACS_INT from_byte, EMACS_INT stop, int comnested
513 EMACS_INT comment_end = from; 520 EMACS_INT comment_end = from;
514 EMACS_INT comment_end_byte = from_byte; 521 EMACS_INT comment_end_byte = from_byte;
515 EMACS_INT comstart_pos = 0; 522 EMACS_INT comstart_pos = 0;
516 EMACS_INT comstart_byte; 523 EMACS_INT comstart_byte IF_LINT (= 0);
517 /* Place where the containing defun starts, 524 /* Place where the containing defun starts,
518 or 0 if we didn't come across it yet. */ 525 or 0 if we didn't come across it yet. */
519 EMACS_INT defun_start = 0; 526 EMACS_INT defun_start = 0;
@@ -554,7 +561,7 @@ back_comment (EMACS_INT from, EMACS_INT from_byte, EMACS_INT stop, int comnested
554 com2end = (SYNTAX_FLAGS_COMEND_FIRST (syntax) 561 com2end = (SYNTAX_FLAGS_COMEND_FIRST (syntax)
555 && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax)); 562 && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax));
556 comstart = (com2start || code == Scomment); 563 comstart = (com2start || code == Scomment);
557 564
558 /* Nasty cases with overlapping 2-char comment markers: 565 /* Nasty cases with overlapping 2-char comment markers:
559 - snmp-mode: -- c -- foo -- c -- 566 - snmp-mode: -- c -- foo -- c --
560 --- c -- 567 --- c --
@@ -779,7 +786,7 @@ DEFUN ("syntax-table", Fsyntax_table, Ssyntax_table, 0, 0, 0,
779This is the one specified by the current buffer. */) 786This is the one specified by the current buffer. */)
780 (void) 787 (void)
781{ 788{
782 return current_buffer->syntax_table; 789 return BVAR (current_buffer, syntax_table);
783} 790}
784 791
785DEFUN ("standard-syntax-table", Fstandard_syntax_table, 792DEFUN ("standard-syntax-table", Fstandard_syntax_table,
@@ -824,7 +831,7 @@ One argument, a syntax table. */)
824{ 831{
825 int idx; 832 int idx;
826 check_syntax_table (table); 833 check_syntax_table (table);
827 current_buffer->syntax_table = table; 834 BVAR (current_buffer, syntax_table) = table;
828 /* Indicate that this buffer now has a specified syntax table. */ 835 /* Indicate that this buffer now has a specified syntax table. */
829 idx = PER_BUFFER_VAR_IDX (syntax_table); 836 idx = PER_BUFFER_VAR_IDX (syntax_table);
830 SET_PER_BUFFER_VALUE_P (current_buffer, idx, 1); 837 SET_PER_BUFFER_VALUE_P (current_buffer, idx, 1);
@@ -974,7 +981,7 @@ text property. */)
974 break; 981 break;
975 } 982 }
976 983
977 if (val < XVECTOR (Vsyntax_code_object)->size && NILP (match)) 984 if (val < ASIZE (Vsyntax_code_object) && NILP (match))
978 return XVECTOR (Vsyntax_code_object)->contents[val]; 985 return XVECTOR (Vsyntax_code_object)->contents[val];
979 else 986 else
980 /* Since we can't use a shared object, let's make a new one. */ 987 /* Since we can't use a shared object, let's make a new one. */
@@ -1035,7 +1042,7 @@ usage: (modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE) */)
1035 CHECK_CHARACTER (c); 1042 CHECK_CHARACTER (c);
1036 1043
1037 if (NILP (syntax_table)) 1044 if (NILP (syntax_table))
1038 syntax_table = current_buffer->syntax_table; 1045 syntax_table = BVAR (current_buffer, syntax_table);
1039 else 1046 else
1040 check_syntax_table (syntax_table); 1047 check_syntax_table (syntax_table);
1041 1048
@@ -1219,7 +1226,7 @@ scan_words (register EMACS_INT from, register EMACS_INT count)
1219 register EMACS_INT from_byte = CHAR_TO_BYTE (from); 1226 register EMACS_INT from_byte = CHAR_TO_BYTE (from);
1220 register enum syntaxcode code; 1227 register enum syntaxcode code;
1221 int ch0, ch1; 1228 int ch0, ch1;
1222 Lisp_Object func, script, pos; 1229 Lisp_Object func, pos;
1223 1230
1224 immediate_quit = 1; 1231 immediate_quit = 1;
1225 QUIT; 1232 QUIT;
@@ -1259,7 +1266,6 @@ scan_words (register EMACS_INT from, register EMACS_INT count)
1259 } 1266 }
1260 else 1267 else
1261 { 1268 {
1262 script = CHAR_TABLE_REF (Vchar_script_table, ch0);
1263 while (1) 1269 while (1)
1264 { 1270 {
1265 if (from == end) break; 1271 if (from == end) break;
@@ -1310,7 +1316,6 @@ scan_words (register EMACS_INT from, register EMACS_INT count)
1310 } 1316 }
1311 else 1317 else
1312 { 1318 {
1313 script = CHAR_TABLE_REF (Vchar_script_table, ch1);
1314 while (1) 1319 while (1)
1315 { 1320 {
1316 if (from == beg) 1321 if (from == beg)
@@ -1367,8 +1372,6 @@ and the function returns nil. Field boundaries are not noticed if
1367 return val == orig_val ? Qt : Qnil; 1372 return val == orig_val ? Qt : Qnil;
1368} 1373}
1369 1374
1370Lisp_Object skip_chars (int, Lisp_Object, Lisp_Object, int);
1371
1372DEFUN ("skip-chars-forward", Fskip_chars_forward, Sskip_chars_forward, 1, 2, 0, 1375DEFUN ("skip-chars-forward", Fskip_chars_forward, Sskip_chars_forward, 1, 2, 0,
1373 doc: /* Move point forward, stopping before a char not in STRING, or at pos LIM. 1376 doc: /* Move point forward, stopping before a char not in STRING, or at pos LIM.
1374STRING is like the inside of a `[...]' in a regular expression 1377STRING is like the inside of a `[...]' in a regular expression
@@ -1421,7 +1424,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl
1421 register unsigned int c; 1424 register unsigned int c;
1422 unsigned char fastmap[0400]; 1425 unsigned char fastmap[0400];
1423 /* Store the ranges of non-ASCII characters. */ 1426 /* Store the ranges of non-ASCII characters. */
1424 int *char_ranges; 1427 int *char_ranges IF_LINT (= NULL);
1425 int n_char_ranges = 0; 1428 int n_char_ranges = 0;
1426 int negate = 0; 1429 int negate = 0;
1427 register EMACS_INT i, i_byte; 1430 register EMACS_INT i, i_byte;
@@ -1450,7 +1453,7 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl
1450 if (XINT (lim) < BEGV) 1453 if (XINT (lim) < BEGV)
1451 XSETFASTINT (lim, BEGV); 1454 XSETFASTINT (lim, BEGV);
1452 1455
1453 multibyte = (!NILP (current_buffer->enable_multibyte_characters) 1456 multibyte = (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1454 && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE)); 1457 && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE));
1455 string_multibyte = SBYTES (string) > SCHARS (string); 1458 string_multibyte = SBYTES (string) > SCHARS (string);
1456 1459
@@ -1542,7 +1545,8 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl
1542 1545
1543 if (c <= c2) 1546 if (c <= c2)
1544 { 1547 {
1545 while (c <= c2) 1548 unsigned lim2 = c2 + 1;
1549 while (c < lim2)
1546 fastmap[c++] = 1; 1550 fastmap[c++] = 1;
1547 if (! ASCII_CHAR_P (c2)) 1551 if (! ASCII_CHAR_P (c2))
1548 string_has_eight_bit = 1; 1552 string_has_eight_bit = 1;
@@ -1682,7 +1686,8 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl
1682 } 1686 }
1683 if (! ASCII_CHAR_P (c)) 1687 if (! ASCII_CHAR_P (c))
1684 { 1688 {
1685 while (leading_code <= leading_code2) 1689 unsigned lim2 = leading_code2 + 1;
1690 while (leading_code < lim2)
1686 fastmap[leading_code++] = 1; 1691 fastmap[leading_code++] = 1;
1687 if (c <= c2) 1692 if (c <= c2)
1688 { 1693 {
@@ -1714,9 +1719,9 @@ skip_chars (int forwardp, Lisp_Object string, Lisp_Object lim, int handle_iso_cl
1714 for (i = 0; i < n_char_ranges; i += 2) 1719 for (i = 0; i < n_char_ranges; i += 2)
1715 { 1720 {
1716 int c1 = char_ranges[i]; 1721 int c1 = char_ranges[i];
1717 int c2 = char_ranges[i + 1]; 1722 unsigned lim2 = char_ranges[i + 1] + 1;
1718 1723
1719 for (; c1 <= c2; c1++) 1724 for (; c1 < lim2; c1++)
1720 { 1725 {
1721 int b = CHAR_TO_BYTE_SAFE (c1); 1726 int b = CHAR_TO_BYTE_SAFE (c1);
1722 if (b >= 0) 1727 if (b >= 0)
@@ -1936,7 +1941,7 @@ skip_syntaxes (int forwardp, Lisp_Object string, Lisp_Object lim)
1936 if (forwardp ? (PT >= XFASTINT (lim)) : (PT <= XFASTINT (lim))) 1941 if (forwardp ? (PT >= XFASTINT (lim)) : (PT <= XFASTINT (lim)))
1937 return make_number (0); 1942 return make_number (0);
1938 1943
1939 multibyte = (!NILP (current_buffer->enable_multibyte_characters) 1944 multibyte = (!NILP (BVAR (current_buffer, enable_multibyte_characters))
1940 && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE)); 1945 && (XINT (lim) - PT != CHAR_TO_BYTE (XINT (lim)) - PT_BYTE));
1941 1946
1942 memset (fastmap, 0, sizeof fastmap); 1947 memset (fastmap, 0, sizeof fastmap);
@@ -2363,7 +2368,7 @@ between them, return t; otherwise return nil. */)
2363 if (code == Scomment_fence) 2368 if (code == Scomment_fence)
2364 { 2369 {
2365 /* Skip until first preceding unquoted comment_fence. */ 2370 /* Skip until first preceding unquoted comment_fence. */
2366 int found = 0; 2371 int fence_found = 0;
2367 EMACS_INT ini = from, ini_byte = from_byte; 2372 EMACS_INT ini = from, ini_byte = from_byte;
2368 2373
2369 while (1) 2374 while (1)
@@ -2374,13 +2379,13 @@ between them, return t; otherwise return nil. */)
2374 if (SYNTAX (c) == Scomment_fence 2379 if (SYNTAX (c) == Scomment_fence
2375 && !char_quoted (from, from_byte)) 2380 && !char_quoted (from, from_byte))
2376 { 2381 {
2377 found = 1; 2382 fence_found = 1;
2378 break; 2383 break;
2379 } 2384 }
2380 else if (from == stop) 2385 else if (from == stop)
2381 break; 2386 break;
2382 } 2387 }
2383 if (found == 0) 2388 if (fence_found == 0)
2384 { 2389 {
2385 from = ini; /* Set point to ini + 1. */ 2390 from = ini; /* Set point to ini + 1. */
2386 from_byte = ini_byte; 2391 from_byte = ini_byte;
@@ -2669,12 +2674,12 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf
2669 /* We must record the comment style encountered so that 2674 /* We must record the comment style encountered so that
2670 later, we can match only the proper comment begin 2675 later, we can match only the proper comment begin
2671 sequence of the same style. */ 2676 sequence of the same style. */
2672 int c1, other_syntax; 2677 int c2, other_syntax;
2673 DEC_BOTH (from, from_byte); 2678 DEC_BOTH (from, from_byte);
2674 UPDATE_SYNTAX_TABLE_BACKWARD (from); 2679 UPDATE_SYNTAX_TABLE_BACKWARD (from);
2675 code = Sendcomment; 2680 code = Sendcomment;
2676 c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte); 2681 c2 = FETCH_CHAR_AS_MULTIBYTE (from_byte);
2677 other_syntax = SYNTAX_WITH_FLAGS (c1); 2682 other_syntax = SYNTAX_WITH_FLAGS (c2);
2678 comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax); 2683 comstyle = SYNTAX_FLAGS_COMMENT_STYLE (other_syntax, syntax);
2679 comnested 2684 comnested
2680 = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax); 2685 = comnested || SYNTAX_FLAGS_COMMENT_NESTED (other_syntax);
@@ -2703,7 +2708,7 @@ scan_lists (register EMACS_INT from, EMACS_INT count, EMACS_INT depth, int sexpf
2703 while (from > stop) 2708 while (from > stop)
2704 { 2709 {
2705 temp_pos = from_byte; 2710 temp_pos = from_byte;
2706 if (! NILP (current_buffer->enable_multibyte_characters)) 2711 if (! NILP (BVAR (current_buffer, enable_multibyte_characters)))
2707 DEC_POS (temp_pos); 2712 DEC_POS (temp_pos);
2708 else 2713 else
2709 temp_pos--; 2714 temp_pos--;
@@ -3265,9 +3270,9 @@ do { prev_from = from; \
3265 = (curlevel == levelstart) ? -1 : (curlevel - 1)->last; 3270 = (curlevel == levelstart) ? -1 : (curlevel - 1)->last;
3266 state.location = from; 3271 state.location = from;
3267 state.levelstarts = Qnil; 3272 state.levelstarts = Qnil;
3268 while (--curlevel >= levelstart) 3273 while (curlevel > levelstart)
3269 state.levelstarts = Fcons (make_number (curlevel->last), 3274 state.levelstarts = Fcons (make_number ((--curlevel)->last),
3270 state.levelstarts); 3275 state.levelstarts);
3271 immediate_quit = 0; 3276 immediate_quit = 0;
3272 3277
3273 *stateptr = state; 3278 *stateptr = state;
@@ -3367,7 +3372,7 @@ init_syntax_once (void)
3367 3372
3368 /* Create objects which can be shared among syntax tables. */ 3373 /* Create objects which can be shared among syntax tables. */
3369 Vsyntax_code_object = Fmake_vector (make_number (Smax), Qnil); 3374 Vsyntax_code_object = Fmake_vector (make_number (Smax), Qnil);
3370 for (i = 0; i < XVECTOR (Vsyntax_code_object)->size; i++) 3375 for (i = 0; i < ASIZE (Vsyntax_code_object); i++)
3371 XVECTOR (Vsyntax_code_object)->contents[i] 3376 XVECTOR (Vsyntax_code_object)->contents[i]
3372 = Fcons (make_number (i), Qnil); 3377 = Fcons (make_number (i), Qnil);
3373 3378
@@ -3528,4 +3533,3 @@ In both cases, LIMIT bounds the search. */);
3528 defsubr (&Sbackward_prefix_chars); 3533 defsubr (&Sbackward_prefix_chars);
3529 defsubr (&Sparse_partial_sexp); 3534 defsubr (&Sparse_partial_sexp);
3530} 3535}
3531