diff options
Diffstat (limited to 'src/syntax.c')
| -rw-r--r-- | src/syntax.c | 117 |
1 files changed, 62 insertions, 55 deletions
diff --git a/src/syntax.c b/src/syntax.c index 84147a2dc15..0ee1c746ec3 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -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. */ | ||
| 3099 | static bool | ||
| 3100 | in_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; |
| @@ -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: |