aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2000-06-21 14:57:11 +0000
committerStefan Monnier2000-06-21 14:57:11 +0000
commit3ee5041cf5cc5db6a870d0e624ced221665c4e0c (patch)
treee88a1bdbcf2b6a4a1b904942dea88577059393e2 /src
parent4c34300137624a85499f90873fa16f4b7056713a (diff)
downloademacs-3ee5041cf5cc5db6a870d0e624ced221665c4e0c.tar.gz
emacs-3ee5041cf5cc5db6a870d0e624ced221665c4e0c.zip
(back_comment): Simplify string-parity counting (with
the added benefit of handling multiple string-styles as long as they are not nested). Jump to the slow code as soon as a comment starter is found in a "string_lossage" position. Fixes the case: " /* " /* " */.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/syntax.c63
2 files changed, 40 insertions, 31 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index cc1d6659a3e..2bd068d6742 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
12000-06-21 Stefan Monnier <monnier@cs.yale.edu>
2
3 * syntax.c (back_comment): Simplify string-parity counting (with
4 the added benefit of handling multiple string-styles as long as
5 they are not intertwined).
6 Jump to the slow code as soon as a comment starter is found in
7 a "string_lossage" position. Fixes the case: " /* " /* " */.
8
12000-06-21 Dave Love <fx@gnu.org> 92000-06-21 Dave Love <fx@gnu.org>
2 10
3 * Makefile.in: Use GETLOADAVG_LIBS. 11 * Makefile.in: Use GETLOADAVG_LIBS.
diff --git a/src/syntax.c b/src/syntax.c
index 656d567b1a5..fcc6dc6b4da 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -467,8 +467,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
467 OFROM[I] is position of the earliest comment-starter seen 467 OFROM[I] is position of the earliest comment-starter seen
468 which is I+2X quotes from the comment-end. 468 which is I+2X quotes from the comment-end.
469 PARITY is current parity of quotes from the comment end. */ 469 PARITY is current parity of quotes from the comment end. */
470 int parity = 0; 470 int string_style = -1; /* Presumed outside of any string. */
471 int my_stringend = 0;
472 int string_lossage = 0; 471 int string_lossage = 0;
473 int comment_end = from; 472 int comment_end = from;
474 int comment_end_byte = from_byte; 473 int comment_end_byte = from_byte;
@@ -476,7 +475,6 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
476 int comstart_byte; 475 int comstart_byte;
477 /* Value that PARITY had, when we reached the position 476 /* Value that PARITY had, when we reached the position
478 in COMSTART_POS. */ 477 in COMSTART_POS. */
479 int comstart_parity = 0;
480 int scanstart = from - 1; 478 int scanstart = from - 1;
481 /* Place where the containing defun starts, 479 /* Place where the containing defun starts,
482 or 0 if we didn't come across it yet. */ 480 or 0 if we didn't come across it yet. */
@@ -530,34 +528,33 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
530 continue; 528 continue;
531 529
532 /* Track parity of quotes. */ 530 /* Track parity of quotes. */
533 if (code == Sstring) 531 switch (code)
534 { 532 {
535 parity ^= 1; 533 case Sstring_fence:
536 if (my_stringend == 0) 534 case Scomment_fence:
537 my_stringend = c; 535 c = (code == Sstring_fence ? ST_STRING_STYLE : ST_COMMENT_STYLE);
538 /* If we have two kinds of string delimiters. 536 case Sstring:
539 There's no way to grok this scanning backwards. */ 537 /* Track parity of quotes. */
540 else if (my_stringend != c) 538 if (string_style == -1)
541 string_lossage = 1; 539 /* Entering a string. */
542 } 540 string_style = c;
543 541 else if (string_style == c)
544 if (code == Sstring_fence || code == Scomment_fence) 542 /* Leaving the string. */
545 { 543 string_style = -1;
546 parity ^= 1; 544 else
547 if (my_stringend == 0) 545 /* If we have two kinds of string delimiters.
548 my_stringend 546 There's no way to grok this scanning backwards. */
549 = code == Sstring_fence ? ST_STRING_STYLE : ST_COMMENT_STYLE;
550 /* If we have two kinds of string delimiters.
551 There's no way to grok this scanning backwards. */
552 else if (my_stringend != (code == Sstring_fence
553 ? ST_STRING_STYLE : ST_COMMENT_STYLE))
554 string_lossage = 1; 547 string_lossage = 1;
555 } 548 break;
549
550 case Scomment:
551 /* We've already checked that it is the relevant comstyle. */
552 if (string_style != -1 || string_lossage)
553 /* There are odd string quotes involved, so let's be careful.
554 Test case in Pascal: " { " a { " } */
555 goto lossage;
556 556
557 if (code == Scomment) 557 if (comnested && --nesting <= 0)
558 /* We've already checked that it is the relevant comstyle. */
559 {
560 if (comnested && --nesting <= 0 && parity == 0 && !string_lossage)
561 /* nested comments have to be balanced, so we don't need to 558 /* nested comments have to be balanced, so we don't need to
562 keep looking for earlier ones. We use here the same (slightly 559 keep looking for earlier ones. We use here the same (slightly
563 incorrect) reasoning as below: since it is followed by uniform 560 incorrect) reasoning as below: since it is followed by uniform
@@ -567,9 +564,12 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
567 564
568 /* Record comment-starters according to that 565 /* Record comment-starters according to that
569 quote-parity to the comment-end. */ 566 quote-parity to the comment-end. */
570 comstart_parity = parity;
571 comstart_pos = from; 567 comstart_pos = from;
572 comstart_byte = from_byte; 568 comstart_byte = from_byte;
569 break;
570
571 default:
572 ;
573 } 573 }
574 574
575 /* If we find another earlier comment-ender, 575 /* If we find another earlier comment-ender,
@@ -607,7 +607,7 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
607 we know it can't be inside a string 607 we know it can't be inside a string
608 since if it were then the comment ender would be inside one. 608 since if it were then the comment ender would be inside one.
609 So it does start a comment. Skip back to it. */ 609 So it does start a comment. Skip back to it. */
610 else if (!comnested && comstart_parity == 0 && !string_lossage) 610 else if (!comnested)
611 { 611 {
612 from = comstart_pos; 612 from = comstart_pos;
613 from_byte = comstart_byte; 613 from_byte = comstart_byte;
@@ -615,12 +615,13 @@ back_comment (from, from_byte, stop, comnested, comstyle, charpos_ptr, bytepos_p
615 } 615 }
616 else 616 else
617 { 617 {
618 struct lisp_parse_state state;
619 lossage:
618 /* We had two kinds of string delimiters mixed up 620 /* We had two kinds of string delimiters mixed up
619 together. Decode this going forwards. 621 together. Decode this going forwards.
620 Scan fwd from the previous comment ender 622 Scan fwd from the previous comment ender
621 to the one in question; this records where we 623 to the one in question; this records where we
622 last passed a comment starter. */ 624 last passed a comment starter. */
623 struct lisp_parse_state state;
624 /* If we did not already find the defun start, find it now. */ 625 /* If we did not already find the defun start, find it now. */
625 if (defun_start == 0) 626 if (defun_start == 0)
626 { 627 {