diff options
| author | Stefan Monnier | 2000-10-02 22:15:27 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-10-02 22:15:27 +0000 |
| commit | 3f679f55a2d12837a39ad52613e3b4760f761969 (patch) | |
| tree | ea163a498389e775427df873f80be8004d43c0e8 /src/syntax.c | |
| parent | abf8a9ffcc978497c75a9c32984acf7c8583967d (diff) | |
| download | emacs-3f679f55a2d12837a39ad52613e3b4760f761969.tar.gz emacs-3f679f55a2d12837a39ad52613e3b4760f761969.zip | |
(prev_char_comstart_first): Remove.
(back_comment): Check two-char comment markers more carefully
to better handle overlapping cases like *//* or /* */* */ ...
Match nestedness of ender/starter.
Diffstat (limited to 'src/syntax.c')
| -rw-r--r-- | src/syntax.c | 115 |
1 files changed, 77 insertions, 38 deletions
diff --git a/src/syntax.c b/src/syntax.c index bb552d9ea05..a3b96c44475 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -425,19 +425,19 @@ prev_char_comend_first (pos, pos_byte) | |||
| 425 | 425 | ||
| 426 | /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */ | 426 | /* Return the SYNTAX_COMSTART_FIRST of the character before POS, POS_BYTE. */ |
| 427 | 427 | ||
| 428 | static int | 428 | /* static int |
| 429 | prev_char_comstart_first (pos, pos_byte) | 429 | * prev_char_comstart_first (pos, pos_byte) |
| 430 | int pos, pos_byte; | 430 | * int pos, pos_byte; |
| 431 | { | 431 | * { |
| 432 | int c, val; | 432 | * int c, val; |
| 433 | 433 | * | |
| 434 | DEC_BOTH (pos, pos_byte); | 434 | * DEC_BOTH (pos, pos_byte); |
| 435 | UPDATE_SYNTAX_TABLE_BACKWARD (pos); | 435 | * UPDATE_SYNTAX_TABLE_BACKWARD (pos); |
| 436 | c = FETCH_CHAR (pos_byte); | 436 | * c = FETCH_CHAR (pos_byte); |
| 437 | val = SYNTAX_COMSTART_FIRST (c); | 437 | * val = SYNTAX_COMSTART_FIRST (c); |
| 438 | UPDATE_SYNTAX_TABLE_FORWARD (pos + 1); | 438 | * UPDATE_SYNTAX_TABLE_FORWARD (pos + 1); |
| 439 | return val; | 439 | * return val; |
| 440 | } | 440 | * } */ |
| 441 | 441 | ||
| 442 | /* Checks whether charpos FROM is at the end of a comment. | 442 | /* Checks whether charpos FROM is at the end of a comment. |
| 443 | FROM_BYTE is the bytepos corresponding to FROM. | 443 | FROM_BYTE is the bytepos corresponding to FROM. |
| @@ -479,7 +479,6 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p | |||
| 479 | int comment_end_byte = from_byte; | 479 | int comment_end_byte = from_byte; |
| 480 | int comstart_pos = 0; | 480 | int comstart_pos = 0; |
| 481 | int comstart_byte; | 481 | int comstart_byte; |
| 482 | int scanstart = from - 1; | ||
| 483 | /* Place where the containing defun starts, | 482 | /* Place where the containing defun starts, |
| 484 | or 0 if we didn't come across it yet. */ | 483 | or 0 if we didn't come across it yet. */ |
| 485 | int defun_start = 0; | 484 | int defun_start = 0; |
| @@ -487,44 +486,82 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p | |||
| 487 | register enum syntaxcode code; | 486 | register enum syntaxcode code; |
| 488 | int nesting = 1; /* current comment nesting */ | 487 | int nesting = 1; /* current comment nesting */ |
| 489 | int c; | 488 | int c; |
| 489 | int syntax = 0; | ||
| 490 | |||
| 491 | /* FIXME: A }} comment-ender style leads to incorrect behavior | ||
| 492 | in the case of {{ c }}} because we ignore the last two chars which are | ||
| 493 | assumed to be comment-enders although they aren't. */ | ||
| 490 | 494 | ||
| 491 | /* At beginning of range to scan, we're outside of strings; | 495 | /* At beginning of range to scan, we're outside of strings; |
| 492 | that determines quote parity to the comment-end. */ | 496 | that determines quote parity to the comment-end. */ |
| 493 | while (from != stop) | 497 | while (from != stop) |
| 494 | { | 498 | { |
| 495 | int temp_byte; | 499 | int temp_byte, prev_syntax; |
| 500 | int com2start, com2end; | ||
| 496 | 501 | ||
| 497 | /* Move back and examine a character. */ | 502 | /* Move back and examine a character. */ |
| 498 | DEC_BOTH (from, from_byte); | 503 | DEC_BOTH (from, from_byte); |
| 499 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 504 | UPDATE_SYNTAX_TABLE_BACKWARD (from); |
| 500 | 505 | ||
| 506 | prev_syntax = syntax; | ||
| 501 | c = FETCH_CHAR (from_byte); | 507 | c = FETCH_CHAR (from_byte); |
| 508 | syntax = SYNTAX_WITH_FLAGS (c); | ||
| 502 | code = SYNTAX (c); | 509 | code = SYNTAX (c); |
| 503 | 510 | ||
| 504 | /* If this char is the second of a 2-char comment end sequence, | 511 | /* Check for 2-char comment markers. */ |
| 505 | back up and give the pair the appropriate syntax. */ | 512 | com2start = (SYNTAX_FLAGS_COMSTART_FIRST (syntax) |
| 506 | if (from > stop && SYNTAX_COMEND_SECOND (c) | 513 | && SYNTAX_FLAGS_COMSTART_SECOND (prev_syntax) |
| 507 | && prev_char_comend_first (from, from_byte)) | 514 | && comstyle == SYNTAX_FLAGS_COMMENT_STYLE (prev_syntax) |
| 508 | { | 515 | && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax) |
| 509 | code = Sendcomment; | 516 | || SYNTAX_FLAGS_COMMENT_NESTED (syntax)) == comnested); |
| 510 | DEC_BOTH (from, from_byte); | 517 | com2end = (SYNTAX_FLAGS_COMEND_FIRST (syntax) |
| 511 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 518 | && SYNTAX_FLAGS_COMEND_SECOND (prev_syntax)); |
| 512 | c = FETCH_CHAR (from_byte); | 519 | |
| 513 | } | 520 | /* Nasty cases with overlapping 2-char comment markers: |
| 514 | 521 | - snmp-mode: -- c -- foo -- c -- | |
| 515 | /* If this char starts a 2-char comment start sequence, | 522 | --- c -- |
| 516 | treat it like a 1-char comment starter. */ | 523 | ------ c -- |
| 517 | if (from < scanstart && SYNTAX_COMSTART_FIRST (c)) | 524 | - c-mode: *||* |
| 525 | |* *|* *| | ||
| 526 | |*| |* |*| | ||
| 527 | /// */ | ||
| 528 | |||
| 529 | /* If a 2-char comment sequence partly overlaps with another, | ||
| 530 | we don't try to be clever. */ | ||
| 531 | if (from > stop && (com2end || com2start)) | ||
| 518 | { | 532 | { |
| 519 | temp_byte = inc_bytepos (from_byte); | 533 | int next = from, next_byte = from_byte, next_c, next_syntax; |
| 520 | UPDATE_SYNTAX_TABLE_FORWARD (from + 1); | 534 | DEC_BOTH (next, next_byte); |
| 521 | if (SYNTAX_COMSTART_SECOND (FETCH_CHAR (temp_byte)) | 535 | UPDATE_SYNTAX_TABLE_BACKWARD (next); |
| 522 | && comstyle == SYNTAX_COMMENT_STYLE (FETCH_CHAR (temp_byte))) | 536 | next_c = FETCH_CHAR (next_byte); |
| 523 | code = Scomment; | 537 | next_syntax = SYNTAX_WITH_FLAGS (next_c); |
| 524 | UPDATE_SYNTAX_TABLE_BACKWARD (from); | 538 | if (((com2start || comnested) |
| 539 | && SYNTAX_FLAGS_COMEND_SECOND (syntax) | ||
| 540 | && SYNTAX_FLAGS_COMEND_FIRST (next_syntax)) | ||
| 541 | || ((com2end || comnested) | ||
| 542 | && SYNTAX_FLAGS_COMSTART_SECOND (syntax) | ||
| 543 | && comstyle == SYNTAX_FLAGS_COMMENT_STYLE (syntax) | ||
| 544 | && SYNTAX_FLAGS_COMSTART_FIRST (next_syntax))) | ||
| 545 | goto lossage; | ||
| 546 | /* UPDATE_SYNTAX_TABLE_FORWARD (next + 1); */ | ||
| 525 | } | 547 | } |
| 526 | else if (code == Scomment && comstyle != SYNTAX_COMMENT_STYLE (c)) | 548 | |
| 527 | /* Ignore comment starters of a different style. */ | 549 | if (com2start && comstart_pos == 0) |
| 550 | /* We're looking at a comment starter. But it might be a comment | ||
| 551 | ender as well (see snmp-mode). The first time we see one, we | ||
| 552 | need to consider it as a comment starter, | ||
| 553 | and the subsequent times as a comment ender. */ | ||
| 554 | com2end = 0; | ||
| 555 | |||
| 556 | /* Turn a 2-char comment sequences into the appropriate syntax. */ | ||
| 557 | if (com2end) | ||
| 558 | code = Sendcomment; | ||
| 559 | else if (com2start) | ||
| 560 | code = Scomment; | ||
| 561 | /* Ignore comment starters of a different style. */ | ||
| 562 | else if (code == Scomment | ||
| 563 | && (comstyle != SYNTAX_FLAGS_COMMENT_STYLE (syntax) | ||
| 564 | || SYNTAX_FLAGS_COMMENT_NESTED (syntax) != comnested)) | ||
| 528 | continue; | 565 | continue; |
| 529 | 566 | ||
| 530 | /* Ignore escaped characters, except comment-enders. */ | 567 | /* Ignore escaped characters, except comment-enders. */ |
| @@ -573,7 +610,9 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p | |||
| 573 | break; | 610 | break; |
| 574 | 611 | ||
| 575 | case Sendcomment: | 612 | case Sendcomment: |
| 576 | if (SYNTAX_COMMENT_STYLE (FETCH_CHAR (from_byte)) == comstyle) | 613 | if (SYNTAX_FLAGS_COMMENT_STYLE (syntax) == comstyle |
| 614 | && (SYNTAX_FLAGS_COMMENT_NESTED (prev_syntax) | ||
| 615 | || SYNTAX_FLAGS_COMMENT_NESTED (syntax)) == comnested) | ||
| 577 | /* This is the same style of comment ender as ours. */ | 616 | /* This is the same style of comment ender as ours. */ |
| 578 | { | 617 | { |
| 579 | if (comnested) | 618 | if (comnested) |