aboutsummaryrefslogtreecommitdiffstats
path: root/src/syntax.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax.c')
-rw-r--r--src/syntax.c167
1 files changed, 87 insertions, 80 deletions
diff --git a/src/syntax.c b/src/syntax.c
index 84147a2dc15..f9e4093765c 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -1426,8 +1426,8 @@ scan_words (register ptrdiff_t from, register EMACS_INT count)
1426 int ch0, ch1; 1426 int ch0, ch1;
1427 Lisp_Object func, pos; 1427 Lisp_Object func, pos;
1428 1428
1429 immediate_quit = 1; 1429 immediate_quit = true;
1430 QUIT; 1430 maybe_quit ();
1431 1431
1432 SETUP_SYNTAX_TABLE (from, count); 1432 SETUP_SYNTAX_TABLE (from, count);
1433 1433
@@ -1437,7 +1437,7 @@ scan_words (register ptrdiff_t from, register EMACS_INT count)
1437 { 1437 {
1438 if (from == end) 1438 if (from == end)
1439 { 1439 {
1440 immediate_quit = 0; 1440 immediate_quit = false;
1441 return 0; 1441 return 0;
1442 } 1442 }
1443 UPDATE_SYNTAX_TABLE_FORWARD (from); 1443 UPDATE_SYNTAX_TABLE_FORWARD (from);
@@ -1487,7 +1487,7 @@ scan_words (register ptrdiff_t from, register EMACS_INT count)
1487 { 1487 {
1488 if (from == beg) 1488 if (from == beg)
1489 { 1489 {
1490 immediate_quit = 0; 1490 immediate_quit = false;
1491 return 0; 1491 return 0;
1492 } 1492 }
1493 DEC_BOTH (from, from_byte); 1493 DEC_BOTH (from, from_byte);
@@ -1536,7 +1536,7 @@ scan_words (register ptrdiff_t from, register EMACS_INT count)
1536 count++; 1536 count++;
1537 } 1537 }
1538 1538
1539 immediate_quit = 0; 1539 immediate_quit = false;
1540 1540
1541 return from; 1541 return from;
1542} 1542}
@@ -1921,7 +1921,7 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim,
1921 stop = (pos >= GPT && GPT > XINT (lim)) ? GAP_END_ADDR : endp; 1921 stop = (pos >= GPT && GPT > XINT (lim)) ? GAP_END_ADDR : endp;
1922 } 1922 }
1923 1923
1924 immediate_quit = 1; 1924 immediate_quit = true;
1925 /* This code may look up syntax tables using functions that rely on the 1925 /* This code may look up syntax tables using functions that rely on the
1926 gl_state object. To make sure this object is not out of date, 1926 gl_state object. To make sure this object is not out of date,
1927 let's initialize it manually. 1927 let's initialize it manually.
@@ -2064,7 +2064,7 @@ skip_chars (bool forwardp, Lisp_Object string, Lisp_Object lim,
2064 } 2064 }
2065 2065
2066 SET_PT_BOTH (pos, pos_byte); 2066 SET_PT_BOTH (pos, pos_byte);
2067 immediate_quit = 0; 2067 immediate_quit = false;
2068 2068
2069 SAFE_FREE (); 2069 SAFE_FREE ();
2070 return make_number (PT - start_point); 2070 return make_number (PT - start_point);
@@ -2138,7 +2138,7 @@ skip_syntaxes (bool forwardp, Lisp_Object string, Lisp_Object lim)
2138 ptrdiff_t pos_byte = PT_BYTE; 2138 ptrdiff_t pos_byte = PT_BYTE;
2139 unsigned char *p, *endp, *stop; 2139 unsigned char *p, *endp, *stop;
2140 2140
2141 immediate_quit = 1; 2141 immediate_quit = true;
2142 SETUP_SYNTAX_TABLE (pos, forwardp ? 1 : -1); 2142 SETUP_SYNTAX_TABLE (pos, forwardp ? 1 : -1);
2143 2143
2144 if (forwardp) 2144 if (forwardp)
@@ -2224,7 +2224,7 @@ skip_syntaxes (bool forwardp, Lisp_Object string, Lisp_Object lim)
2224 2224
2225 done: 2225 done:
2226 SET_PT_BOTH (pos, pos_byte); 2226 SET_PT_BOTH (pos, pos_byte);
2227 immediate_quit = 0; 2227 immediate_quit = false;
2228 2228
2229 return make_number (PT - start_point); 2229 return make_number (PT - start_point);
2230 } 2230 }
@@ -2412,8 +2412,8 @@ between them, return t; otherwise return nil. */)
2412 count1 = XINT (count); 2412 count1 = XINT (count);
2413 stop = count1 > 0 ? ZV : BEGV; 2413 stop = count1 > 0 ? ZV : BEGV;
2414 2414
2415 immediate_quit = 1; 2415 immediate_quit = true;
2416 QUIT; 2416 maybe_quit ();
2417 2417
2418 from = PT; 2418 from = PT;
2419 from_byte = PT_BYTE; 2419 from_byte = PT_BYTE;
@@ -2429,7 +2429,7 @@ between them, return t; otherwise return nil. */)
2429 if (from == stop) 2429 if (from == stop)
2430 { 2430 {
2431 SET_PT_BOTH (from, from_byte); 2431 SET_PT_BOTH (from, from_byte);
2432 immediate_quit = 0; 2432 immediate_quit = false;
2433 return Qnil; 2433 return Qnil;
2434 } 2434 }
2435 c = FETCH_CHAR_AS_MULTIBYTE (from_byte); 2435 c = FETCH_CHAR_AS_MULTIBYTE (from_byte);
@@ -2463,7 +2463,7 @@ between them, return t; otherwise return nil. */)
2463 comstyle = ST_COMMENT_STYLE; 2463 comstyle = ST_COMMENT_STYLE;
2464 else if (code != Scomment) 2464 else if (code != Scomment)
2465 { 2465 {
2466 immediate_quit = 0; 2466 immediate_quit = false;
2467 DEC_BOTH (from, from_byte); 2467 DEC_BOTH (from, from_byte);
2468 SET_PT_BOTH (from, from_byte); 2468 SET_PT_BOTH (from, from_byte);
2469 return Qnil; 2469 return Qnil;
@@ -2474,7 +2474,7 @@ between them, return t; otherwise return nil. */)
2474 from = out_charpos; from_byte = out_bytepos; 2474 from = out_charpos; from_byte = out_bytepos;
2475 if (!found) 2475 if (!found)
2476 { 2476 {
2477 immediate_quit = 0; 2477 immediate_quit = false;
2478 SET_PT_BOTH (from, from_byte); 2478 SET_PT_BOTH (from, from_byte);
2479 return Qnil; 2479 return Qnil;
2480 } 2480 }
@@ -2494,7 +2494,7 @@ between them, return t; otherwise return nil. */)
2494 if (from <= stop) 2494 if (from <= stop)
2495 { 2495 {
2496 SET_PT_BOTH (BEGV, BEGV_BYTE); 2496 SET_PT_BOTH (BEGV, BEGV_BYTE);
2497 immediate_quit = 0; 2497 immediate_quit = false;
2498 return Qnil; 2498 return Qnil;
2499 } 2499 }
2500 2500
@@ -2587,7 +2587,7 @@ between them, return t; otherwise return nil. */)
2587 else if (code != Swhitespace || quoted) 2587 else if (code != Swhitespace || quoted)
2588 { 2588 {
2589 leave: 2589 leave:
2590 immediate_quit = 0; 2590 immediate_quit = false;
2591 INC_BOTH (from, from_byte); 2591 INC_BOTH (from, from_byte);
2592 SET_PT_BOTH (from, from_byte); 2592 SET_PT_BOTH (from, from_byte);
2593 return Qnil; 2593 return Qnil;
@@ -2598,7 +2598,7 @@ between them, return t; otherwise return nil. */)
2598 } 2598 }
2599 2599
2600 SET_PT_BOTH (from, from_byte); 2600 SET_PT_BOTH (from, from_byte);
2601 immediate_quit = 0; 2601 immediate_quit = false;
2602 return Qt; 2602 return Qt;
2603} 2603}
2604 2604
@@ -2640,8 +2640,8 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
2640 2640
2641 from_byte = CHAR_TO_BYTE (from); 2641 from_byte = CHAR_TO_BYTE (from);
2642 2642
2643 immediate_quit = 1; 2643 immediate_quit = true;
2644 QUIT; 2644 maybe_quit ();
2645 2645
2646 SETUP_SYNTAX_TABLE (from, count); 2646 SETUP_SYNTAX_TABLE (from, count);
2647 while (count > 0) 2647 while (count > 0)
@@ -2801,7 +2801,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
2801 if (depth) 2801 if (depth)
2802 goto lose; 2802 goto lose;
2803 2803
2804 immediate_quit = 0; 2804 immediate_quit = false;
2805 return Qnil; 2805 return Qnil;
2806 2806
2807 /* End of object reached */ 2807 /* End of object reached */
@@ -2984,7 +2984,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
2984 if (depth) 2984 if (depth)
2985 goto lose; 2985 goto lose;
2986 2986
2987 immediate_quit = 0; 2987 immediate_quit = false;
2988 return Qnil; 2988 return Qnil;
2989 2989
2990 done2: 2990 done2:
@@ -2992,7 +2992,7 @@ scan_lists (EMACS_INT from, EMACS_INT count, EMACS_INT depth, bool sexpflag)
2992 } 2992 }
2993 2993
2994 2994
2995 immediate_quit = 0; 2995 immediate_quit = false;
2996 XSETFASTINT (val, from); 2996 XSETFASTINT (val, from);
2997 return val; 2997 return val;
2998 2998
@@ -3092,6 +3092,36 @@ the prefix syntax flag (p). */)
3092 return Qnil; 3092 return Qnil;
3093} 3093}
3094 3094
3095
3096/* If the character at FROM_BYTE is the second part of a 2-character
3097 comment opener based on PREV_FROM_SYNTAX, update STATE and return
3098 true. */
3099static bool
3100in_2char_comment_start (struct lisp_parse_state *state,
3101 int prev_from_syntax,
3102 ptrdiff_t prev_from,
3103 ptrdiff_t from_byte)
3104{
3105 int c1, syntax;
3106 if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax)
3107 && (c1 = FETCH_CHAR_AS_MULTIBYTE (from_byte),
3108 syntax = SYNTAX_WITH_FLAGS (c1),
3109 SYNTAX_FLAGS_COMSTART_SECOND (syntax)))
3110 {
3111 /* Record the comment style we have entered so that only
3112 the comment-end sequence of the same style actually
3113 terminates the comment section. */
3114 state->comstyle
3115 = SYNTAX_FLAGS_COMMENT_STYLE (syntax, prev_from_syntax);
3116 bool comnested = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax)
3117 | SYNTAX_FLAGS_COMMENT_NESTED (syntax));
3118 state->incomment = comnested ? 1 : -1;
3119 state->comstr_start = prev_from;
3120 return true;
3121 }
3122 return false;
3123}
3124
3095/* Parse forward from FROM / FROM_BYTE to END, 3125/* Parse forward from FROM / FROM_BYTE to END,
3096 assuming that FROM has state STATE, 3126 assuming that FROM has state STATE,
3097 and return a description of the state of the parse at END. 3127 and return a description of the state of the parse at END.
@@ -3107,8 +3137,6 @@ scan_sexps_forward (struct lisp_parse_state *state,
3107 int commentstop) 3137 int commentstop)
3108{ 3138{
3109 enum syntaxcode code; 3139 enum syntaxcode code;
3110 int c1;
3111 bool comnested;
3112 struct level { ptrdiff_t last, prev; }; 3140 struct level { ptrdiff_t last, prev; };
3113 struct level levelstart[100]; 3141 struct level levelstart[100];
3114 struct level *curlevel = levelstart; 3142 struct level *curlevel = levelstart;
@@ -3122,7 +3150,6 @@ scan_sexps_forward (struct lisp_parse_state *state,
3122 ptrdiff_t prev_from; /* Keep one character before FROM. */ 3150 ptrdiff_t prev_from; /* Keep one character before FROM. */
3123 ptrdiff_t prev_from_byte; 3151 ptrdiff_t prev_from_byte;
3124 int prev_from_syntax, prev_prev_from_syntax; 3152 int prev_from_syntax, prev_prev_from_syntax;
3125 int syntax;
3126 bool boundary_stop = commentstop == -1; 3153 bool boundary_stop = commentstop == -1;
3127 bool nofence; 3154 bool nofence;
3128 bool found; 3155 bool found;
@@ -3146,8 +3173,8 @@ do { prev_from = from; \
3146 UPDATE_SYNTAX_TABLE_FORWARD (from); \ 3173 UPDATE_SYNTAX_TABLE_FORWARD (from); \
3147 } while (0) 3174 } while (0)
3148 3175
3149 immediate_quit = 1; 3176 immediate_quit = true;
3150 QUIT; 3177 maybe_quit ();
3151 3178
3152 depth = state->depth; 3179 depth = state->depth;
3153 start_quoted = state->quoted; 3180 start_quoted = state->quoted;
@@ -3187,53 +3214,31 @@ do { prev_from = from; \
3187 } 3214 }
3188 else if (start_quoted) 3215 else if (start_quoted)
3189 goto startquoted; 3216 goto startquoted;
3217 else if ((from < end)
3218 && (in_2char_comment_start (state, prev_from_syntax,
3219 prev_from, from_byte)))
3220 {
3221 INC_FROM;
3222 prev_from_syntax = Smax; /* the syntax has already been "used up". */
3223 goto atcomment;
3224 }
3190 3225
3191 while (from < end) 3226 while (from < end)
3192 { 3227 {
3193 if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax) 3228 INC_FROM;
3194 && (c1 = FETCH_CHAR (from_byte), 3229
3195 syntax = SYNTAX_WITH_FLAGS (c1), 3230 if ((from < end)
3196 SYNTAX_FLAGS_COMSTART_SECOND (syntax))) 3231 && (in_2char_comment_start (state, prev_from_syntax,
3197 { 3232 prev_from, from_byte)))
3198 /* Record the comment style we have entered so that only
3199 the comment-end sequence of the same style actually
3200 terminates the comment section. */
3201 state->comstyle
3202 = SYNTAX_FLAGS_COMMENT_STYLE (syntax, prev_from_syntax);
3203 comnested = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax)
3204 | SYNTAX_FLAGS_COMMENT_NESTED (syntax));
3205 state->incomment = comnested ? 1 : -1;
3206 state->comstr_start = prev_from;
3207 INC_FROM;
3208 prev_from_syntax = Smax; /* the syntax has already been
3209 "used up". */
3210 code = Scomment;
3211 }
3212 else
3213 { 3233 {
3214 INC_FROM; 3234 INC_FROM;
3215 code = prev_from_syntax & 0xff; 3235 prev_from_syntax = Smax; /* the syntax has already been "used up". */
3216 if (code == Scomment_fence) 3236 goto atcomment;
3217 {
3218 /* Record the comment style we have entered so that only
3219 the comment-end sequence of the same style actually
3220 terminates the comment section. */
3221 state->comstyle = ST_COMMENT_STYLE;
3222 state->incomment = -1;
3223 state->comstr_start = prev_from;
3224 code = Scomment;
3225 }
3226 else if (code == Scomment)
3227 {
3228 state->comstyle = SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax, 0);
3229 state->incomment = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax) ?
3230 1 : -1);
3231 state->comstr_start = prev_from;
3232 }
3233 } 3237 }
3234 3238
3235 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax)) 3239 if (SYNTAX_FLAGS_PREFIX (prev_from_syntax))
3236 continue; 3240 continue;
3241 code = prev_from_syntax & 0xff;
3237 switch (code) 3242 switch (code)
3238 { 3243 {
3239 case Sescape: 3244 case Sescape:
@@ -3252,24 +3257,15 @@ do { prev_from = from; \
3252 symstarted: 3257 symstarted:
3253 while (from < end) 3258 while (from < end)
3254 { 3259 {
3255 int symchar = FETCH_CHAR_AS_MULTIBYTE (from_byte); 3260 if (in_2char_comment_start (state, prev_from_syntax,
3256 3261 prev_from, from_byte))
3257 if (SYNTAX_FLAGS_COMSTART_FIRST (prev_from_syntax)
3258 && (syntax = SYNTAX_WITH_FLAGS (symchar),
3259 SYNTAX_FLAGS_COMSTART_SECOND (syntax)))
3260 { 3262 {
3261 state->comstyle
3262 = SYNTAX_FLAGS_COMMENT_STYLE (syntax, prev_from_syntax);
3263 comnested = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax)
3264 | SYNTAX_FLAGS_COMMENT_NESTED (syntax));
3265 state->incomment = comnested ? 1 : -1;
3266 state->comstr_start = prev_from;
3267 INC_FROM; 3263 INC_FROM;
3268 prev_from_syntax = Smax; 3264 prev_from_syntax = Smax; /* the syntax has already been "used up". */
3269 code = Scomment;
3270 goto atcomment; 3265 goto atcomment;
3271 } 3266 }
3272 3267
3268 int symchar = FETCH_CHAR_AS_MULTIBYTE (from_byte);
3273 switch (SYNTAX (symchar)) 3269 switch (SYNTAX (symchar))
3274 { 3270 {
3275 case Scharquote: 3271 case Scharquote:
@@ -3290,8 +3286,19 @@ do { prev_from = from; \
3290 curlevel->prev = curlevel->last; 3286 curlevel->prev = curlevel->last;
3291 break; 3287 break;
3292 3288
3293 case Scomment_fence: /* Can't happen because it's handled above. */ 3289 case Scomment_fence:
3290 /* Record the comment style we have entered so that only
3291 the comment-end sequence of the same style actually
3292 terminates the comment section. */
3293 state->comstyle = ST_COMMENT_STYLE;
3294 state->incomment = -1;
3295 state->comstr_start = prev_from;
3296 goto atcomment;
3294 case Scomment: 3297 case Scomment:
3298 state->comstyle = SYNTAX_FLAGS_COMMENT_STYLE (prev_from_syntax, 0);
3299 state->incomment = (SYNTAX_FLAGS_COMMENT_NESTED (prev_from_syntax) ?
3300 1 : -1);
3301 state->comstr_start = prev_from;
3295 atcomment: 3302 atcomment:
3296 if (commentstop || boundary_stop) goto done; 3303 if (commentstop || boundary_stop) goto done;
3297 startincomment: 3304 startincomment:
@@ -3425,7 +3432,7 @@ do { prev_from = from; \
3425 state->levelstarts); 3432 state->levelstarts);
3426 state->prev_syntax = (SYNTAX_FLAGS_COMSTARTEND_FIRST (prev_from_syntax) 3433 state->prev_syntax = (SYNTAX_FLAGS_COMSTARTEND_FIRST (prev_from_syntax)
3427 || state->quoted) ? prev_from_syntax : Smax; 3434 || state->quoted) ? prev_from_syntax : Smax;
3428 immediate_quit = 0; 3435 immediate_quit = false;
3429} 3436}
3430 3437
3431/* Convert a (lisp) parse state to the internal form used in 3438/* Convert a (lisp) parse state to the internal form used in