diff options
| author | Richard M. Stallman | 1992-09-05 05:34:24 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1992-09-05 05:34:24 +0000 |
| commit | e5d4f4dc541c0177c62baf13cd75e9c7c83da502 (patch) | |
| tree | 289f05aa2d037067cd1f0946c938b4056edb309d /src/syntax.c | |
| parent | a4d4c8197b1208e68a9552fdb95dddfe90cdfaad (diff) | |
| download | emacs-e5d4f4dc541c0177c62baf13cd75e9c7c83da502.tar.gz emacs-e5d4f4dc541c0177c62baf13cd75e9c7c83da502.zip | |
(scan_lists): Improve smarts for backwards scan of comments.
Don't modify comstyle inside that loop.
If string quotes don't match up, don't take value from OFROM;
instead, parse forward using scan_sexps_forward.
(scan_sexps_forward): Return value via a pointer passed in.
New element in state contains char addr of last comment-starter seen.
(Fparse_partial_sexp): Change call to scan_sexps_forward.
Diffstat (limited to 'src/syntax.c')
| -rw-r--r-- | src/syntax.c | 230 |
1 files changed, 174 insertions, 56 deletions
diff --git a/src/syntax.c b/src/syntax.c index 21e0d5bfebb..aa40547ba5a 100644 --- a/src/syntax.c +++ b/src/syntax.c | |||
| @@ -29,6 +29,22 @@ Lisp_Object Qsyntax_table_p; | |||
| 29 | 29 | ||
| 30 | int words_include_escapes; | 30 | int words_include_escapes; |
| 31 | 31 | ||
| 32 | /* This is the internal form of the parse state used in parse-partial-sexp. */ | ||
| 33 | |||
| 34 | struct lisp_parse_state | ||
| 35 | { | ||
| 36 | int depth; /* Depth at end of parsing */ | ||
| 37 | int instring; /* -1 if not within string, else desired terminator. */ | ||
| 38 | int incomment; /* Nonzero if within a comment at end of parsing */ | ||
| 39 | int comstyle; /* comment style a=0, or b=1 */ | ||
| 40 | int quoted; /* Nonzero if just after an escape char at end of parsing */ | ||
| 41 | int thislevelstart; /* Char number of most recent start-of-expression at current level */ | ||
| 42 | int prevlevelstart; /* Char number of start of containing expression */ | ||
| 43 | int location; /* Char number at which parsing stopped. */ | ||
| 44 | int mindepth; /* Minimum depth seen while scanning. */ | ||
| 45 | int comstart; /* Position just after last comment starter. */ | ||
| 46 | }; | ||
| 47 | |||
| 32 | DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0, | 48 | DEFUN ("syntax-table-p", Fsyntax_table_p, Ssyntax_table_p, 1, 1, 0, |
| 33 | "Return t if ARG is a syntax table.\n\ | 49 | "Return t if ARG is a syntax table.\n\ |
| 34 | Any vector of 256 elements will do.") | 50 | Any vector of 256 elements will do.") |
| @@ -170,13 +186,21 @@ Two-character sequences are represented as described below.\n\ | |||
| 170 | The second character of S is the matching parenthesis,\n\ | 186 | The second character of S is the matching parenthesis,\n\ |
| 171 | used only if the first character is `(' or `)'.\n\ | 187 | used only if the first character is `(' or `)'.\n\ |
| 172 | Any additional characters are flags.\n\ | 188 | Any additional characters are flags.\n\ |
| 173 | Defined flags are the characters 1, 2, 3, 4, and p.\n\ | 189 | Defined flags are the characters 1, 2, 3, 4, b, and p.\n\ |
| 174 | 1 means C is the start of a two-char comment start sequence.\n\ | 190 | 1 means C is the start of a two-char comment start sequence.\n\ |
| 175 | 2 means C is the second character of such a sequence.\n\ | 191 | 2 means C is the second character of such a sequence.\n\ |
| 176 | 3 means C is the start of a two-char comment end sequence.\n\ | 192 | 3 means C is the start of a two-char comment end sequence.\n\ |
| 177 | 4 means C is the second character of such a sequence.\n\ | 193 | 4 means C is the second character of such a sequence.\n\ |
| 178 | p means C is a prefix character for `backward-prefix-chars'; | 194 | \n\ |
| 179 | such characters are treated as whitespace when they occur | 195 | There can be up to two orthogonal comment sequences. This is to support\n\ |
| 196 | language modes such as C++. By default, all comment sequences are of style\n\ | ||
| 197 | a, but you can set the comment sequence style to b (on the second character of a\n\ | ||
| 198 | comment-start, or the first character of a comment-end sequence) by using\n\ | ||
| 199 | this flag:\n\ | ||
| 200 | b means C is part of comment sequence b.\n\ | ||
| 201 | \n\ | ||
| 202 | p means C is a prefix character for `backward-prefix-chars';\n\ | ||
| 203 | such characters are treated as whitespace when they occur\n\ | ||
| 180 | between expressions.") | 204 | between expressions.") |
| 181 | 205 | ||
| 182 | */ | 206 | */ |
| @@ -233,6 +257,10 @@ DEFUN ("modify-syntax-entry", Fmodify_syntax_entry, Smodify_syntax_entry, 2, 3, | |||
| 233 | case 'p': | 257 | case 'p': |
| 234 | XFASTINT (val) |= 1 << 20; | 258 | XFASTINT (val) |= 1 << 20; |
| 235 | break; | 259 | break; |
| 260 | |||
| 261 | case 'b': | ||
| 262 | XFASTINT (val) |= 1 << 21; | ||
| 263 | break; | ||
| 236 | } | 264 | } |
| 237 | 265 | ||
| 238 | XVECTOR (syntax_table)->contents[0xFF & XINT (c)] = val; | 266 | XVECTOR (syntax_table)->contents[0xFF & XINT (c)] = val; |
| @@ -246,7 +274,7 @@ describe_syntax (value) | |||
| 246 | Lisp_Object value; | 274 | Lisp_Object value; |
| 247 | { | 275 | { |
| 248 | register enum syntaxcode code; | 276 | register enum syntaxcode code; |
| 249 | char desc, match, start1, start2, end1, end2, prefix; | 277 | char desc, match, start1, start2, end1, end2, prefix, comstyle; |
| 250 | char str[2]; | 278 | char str[2]; |
| 251 | 279 | ||
| 252 | Findent_to (make_number (16), make_number (1)); | 280 | Findent_to (make_number (16), make_number (1)); |
| @@ -264,6 +292,7 @@ describe_syntax (value) | |||
| 264 | end1 = (XINT (value) >> 18) & 1; | 292 | end1 = (XINT (value) >> 18) & 1; |
| 265 | end2 = (XINT (value) >> 19) & 1; | 293 | end2 = (XINT (value) >> 19) & 1; |
| 266 | prefix = (XINT (value) >> 20) & 1; | 294 | prefix = (XINT (value) >> 20) & 1; |
| 295 | comstyle = (XINT (value) >> 21) & 1; | ||
| 267 | 296 | ||
| 268 | if ((int) code < 0 || (int) code >= (int) Smax) | 297 | if ((int) code < 0 || (int) code >= (int) Smax) |
| 269 | { | 298 | { |
| @@ -291,6 +320,8 @@ describe_syntax (value) | |||
| 291 | 320 | ||
| 292 | if (prefix) | 321 | if (prefix) |
| 293 | insert ("p", 1); | 322 | insert ("p", 1); |
| 323 | if (comstyle) | ||
| 324 | insert ("b", 1); | ||
| 294 | 325 | ||
| 295 | insert_string ("\twhich means: "); | 326 | insert_string ("\twhich means: "); |
| 296 | 327 | ||
| @@ -348,6 +379,9 @@ describe_syntax (value) | |||
| 348 | insert_string (",\n\t is the first character of a comment-end sequence"); | 379 | insert_string (",\n\t is the first character of a comment-end sequence"); |
| 349 | if (end2) | 380 | if (end2) |
| 350 | insert_string (",\n\t is the second character of a comment-end sequence"); | 381 | insert_string (",\n\t is the second character of a comment-end sequence"); |
| 382 | if (comstyle) | ||
| 383 | insert_string (" (comment style b)"); | ||
| 384 | |||
| 351 | if (prefix) | 385 | if (prefix) |
| 352 | insert_string (",\n\t is a prefix character for `backward-prefix-chars'"); | 386 | insert_string (",\n\t is a prefix character for `backward-prefix-chars'"); |
| 353 | 387 | ||
| @@ -489,6 +523,7 @@ scan_lists (from, count, depth, sexpflag) | |||
| 489 | int mathexit = 0; | 523 | int mathexit = 0; |
| 490 | register enum syntaxcode code; | 524 | register enum syntaxcode code; |
| 491 | int min_depth = depth; /* Err out if depth gets less than this. */ | 525 | int min_depth = depth; /* Err out if depth gets less than this. */ |
| 526 | int comstyle = 0; /* style of comment encountered */ | ||
| 492 | 527 | ||
| 493 | if (depth > 0) min_depth = 0; | 528 | if (depth > 0) min_depth = 0; |
| 494 | 529 | ||
| @@ -501,12 +536,22 @@ scan_lists (from, count, depth, sexpflag) | |||
| 501 | while (from < stop) | 536 | while (from < stop) |
| 502 | { | 537 | { |
| 503 | c = FETCH_CHAR (from); | 538 | c = FETCH_CHAR (from); |
| 504 | code = SYNTAX(c); | 539 | code = SYNTAX (c); |
| 505 | from++; | 540 | from++; |
| 506 | if (from < stop && SYNTAX_COMSTART_FIRST (c) | 541 | if (from < stop && SYNTAX_COMSTART_FIRST (c) |
| 507 | && SYNTAX_COMSTART_SECOND (FETCH_CHAR (from)) | 542 | && SYNTAX_COMSTART_SECOND (FETCH_CHAR (from)) |
| 508 | && parse_sexp_ignore_comments) | 543 | && parse_sexp_ignore_comments) |
| 509 | code = Scomment, from++; | 544 | { |
| 545 | /* we have encountered a comment start sequence and we | ||
| 546 | are ignoring all text inside comments. we must record | ||
| 547 | the comment style this sequence begins so that later, | ||
| 548 | only a comment end of the same style actually ends | ||
| 549 | the comment section */ | ||
| 550 | code = Scomment; | ||
| 551 | comstyle = SYNTAX_COMMENT_STYLE (FETCH_CHAR (from)); | ||
| 552 | from++; | ||
| 553 | } | ||
| 554 | |||
| 510 | if (SYNTAX_PREFIX (c)) | 555 | if (SYNTAX_PREFIX (c)) |
| 511 | continue; | 556 | continue; |
| 512 | 557 | ||
| @@ -528,9 +573,9 @@ scan_lists (from, count, depth, sexpflag) | |||
| 528 | while (from < stop) | 573 | while (from < stop) |
| 529 | { | 574 | { |
| 530 | #ifdef SWITCH_ENUM_BUG | 575 | #ifdef SWITCH_ENUM_BUG |
| 531 | switch ((int) SYNTAX(FETCH_CHAR (from))) | 576 | switch ((int) SYNTAX (FETCH_CHAR (from))) |
| 532 | #else | 577 | #else |
| 533 | switch (SYNTAX(FETCH_CHAR (from))) | 578 | switch (SYNTAX (FETCH_CHAR (from))) |
| 534 | #endif | 579 | #endif |
| 535 | { | 580 | { |
| 536 | case Scharquote: | 581 | case Scharquote: |
| @@ -554,11 +599,20 @@ scan_lists (from, count, depth, sexpflag) | |||
| 554 | while (1) | 599 | while (1) |
| 555 | { | 600 | { |
| 556 | if (from == stop) goto done; | 601 | if (from == stop) goto done; |
| 557 | if (SYNTAX (c = FETCH_CHAR (from)) == Sendcomment) | 602 | c = FETCH_CHAR (from); |
| 603 | if (SYNTAX (c) == Sendcomment | ||
| 604 | && SYNTAX_COMMENT_STYLE (c) == comstyle) | ||
| 605 | /* we have encountered a comment end of the same style | ||
| 606 | as the comment sequence which began this comment | ||
| 607 | section */ | ||
| 558 | break; | 608 | break; |
| 559 | from++; | 609 | from++; |
| 560 | if (from < stop && SYNTAX_COMEND_FIRST (c) | 610 | if (from < stop && SYNTAX_COMEND_FIRST (c) |
| 561 | && SYNTAX_COMEND_SECOND (FETCH_CHAR (from))) | 611 | && SYNTAX_COMEND_SECOND (FETCH_CHAR (from)) |
| 612 | && SYNTAX_COMMENT_STYLE (c) == comstyle) | ||
| 613 | /* we have encountered a comment end of the same style | ||
| 614 | as the comment sequence which began this comment | ||
| 615 | section */ | ||
| 562 | { from++; break; } | 616 | { from++; break; } |
| 563 | } | 617 | } |
| 564 | break; | 618 | break; |
| @@ -593,9 +647,9 @@ scan_lists (from, count, depth, sexpflag) | |||
| 593 | if (from >= stop) goto lose; | 647 | if (from >= stop) goto lose; |
| 594 | if (FETCH_CHAR (from) == stringterm) break; | 648 | if (FETCH_CHAR (from) == stringterm) break; |
| 595 | #ifdef SWITCH_ENUM_BUG | 649 | #ifdef SWITCH_ENUM_BUG |
| 596 | switch ((int) SYNTAX(FETCH_CHAR (from))) | 650 | switch ((int) SYNTAX (FETCH_CHAR (from))) |
| 597 | #else | 651 | #else |
| 598 | switch (SYNTAX(FETCH_CHAR (from))) | 652 | switch (SYNTAX (FETCH_CHAR (from))) |
| 599 | #endif | 653 | #endif |
| 600 | { | 654 | { |
| 601 | case Scharquote: | 655 | case Scharquote: |
| @@ -635,7 +689,15 @@ scan_lists (from, count, depth, sexpflag) | |||
| 635 | && SYNTAX_COMEND_FIRST (FETCH_CHAR (from - 1)) | 689 | && SYNTAX_COMEND_FIRST (FETCH_CHAR (from - 1)) |
| 636 | && !char_quoted (from - 1) | 690 | && !char_quoted (from - 1) |
| 637 | && parse_sexp_ignore_comments) | 691 | && parse_sexp_ignore_comments) |
| 638 | code = Sendcomment, from--; | 692 | { |
| 693 | /* we must record the comment style encountered so that | ||
| 694 | later, we can match only the proper comment begin | ||
| 695 | sequence of the same style */ | ||
| 696 | code = Sendcomment; | ||
| 697 | comstyle = SYNTAX_COMMENT_STYLE (FETCH_CHAR (from - 1)); | ||
| 698 | from--; | ||
| 699 | } | ||
| 700 | |||
| 639 | if (SYNTAX_PREFIX (c)) | 701 | if (SYNTAX_PREFIX (c)) |
| 640 | continue; | 702 | continue; |
| 641 | 703 | ||
| @@ -654,9 +716,9 @@ scan_lists (from, count, depth, sexpflag) | |||
| 654 | quoted = char_quoted (from - 1); | 716 | quoted = char_quoted (from - 1); |
| 655 | if (quoted) | 717 | if (quoted) |
| 656 | from--; | 718 | from--; |
| 657 | if (! (quoted || SYNTAX(FETCH_CHAR (from - 1)) == Sword | 719 | if (! (quoted || SYNTAX (FETCH_CHAR (from - 1)) == Sword |
| 658 | || SYNTAX(FETCH_CHAR (from - 1)) == Ssymbol | 720 | || SYNTAX (FETCH_CHAR (from - 1)) == Ssymbol |
| 659 | || SYNTAX(FETCH_CHAR (from - 1)) == Squote)) | 721 | || SYNTAX (FETCH_CHAR (from - 1)) == Squote)) |
| 660 | goto done2; | 722 | goto done2; |
| 661 | from--; | 723 | from--; |
| 662 | } | 724 | } |
| @@ -700,6 +762,9 @@ scan_lists (from, count, depth, sexpflag) | |||
| 700 | { | 762 | { |
| 701 | int ofrom[2]; | 763 | int ofrom[2]; |
| 702 | int parity = 0; | 764 | int parity = 0; |
| 765 | char my_stringend = 0; | ||
| 766 | int string_lossage = 0; | ||
| 767 | int comment_end = from; | ||
| 703 | 768 | ||
| 704 | ofrom[0] = ofrom[1] = from; | 769 | ofrom[0] = ofrom[1] = from; |
| 705 | 770 | ||
| @@ -717,10 +782,18 @@ scan_lists (from, count, depth, sexpflag) | |||
| 717 | back up and give the pair the appropriate syntax. */ | 782 | back up and give the pair the appropriate syntax. */ |
| 718 | if (from > stop && SYNTAX_COMEND_SECOND (c) | 783 | if (from > stop && SYNTAX_COMEND_SECOND (c) |
| 719 | && SYNTAX_COMEND_FIRST (FETCH_CHAR (from - 1))) | 784 | && SYNTAX_COMEND_FIRST (FETCH_CHAR (from - 1))) |
| 720 | code = Sendcomment, from--; | 785 | { |
| 786 | code = Sendcomment; | ||
| 787 | from--; | ||
| 788 | } | ||
| 789 | |||
| 721 | else if (from > stop && SYNTAX_COMSTART_SECOND (c) | 790 | else if (from > stop && SYNTAX_COMSTART_SECOND (c) |
| 722 | && SYNTAX_COMSTART_FIRST (FETCH_CHAR (from - 1))) | 791 | && SYNTAX_COMSTART_FIRST (FETCH_CHAR (from - 1)) |
| 723 | code = Scomment, from--; | 792 | && comstyle == SYNTAX_COMMENT_STYLE (c)) |
| 793 | { | ||
| 794 | code = Scomment; | ||
| 795 | from--; | ||
| 796 | } | ||
| 724 | 797 | ||
| 725 | /* Ignore escaped characters. */ | 798 | /* Ignore escaped characters. */ |
| 726 | if (char_quoted (from)) | 799 | if (char_quoted (from)) |
| @@ -728,7 +801,15 @@ scan_lists (from, count, depth, sexpflag) | |||
| 728 | 801 | ||
| 729 | /* Track parity of quotes between here and comment-end. */ | 802 | /* Track parity of quotes between here and comment-end. */ |
| 730 | if (code == Sstring) | 803 | if (code == Sstring) |
| 731 | parity ^= 1; | 804 | { |
| 805 | parity ^= 1; | ||
| 806 | if (my_stringend == 0) | ||
| 807 | my_stringend = c; | ||
| 808 | /* We have two kinds of string delimiters. | ||
| 809 | There's no way to grok this scanning backwards. */ | ||
| 810 | else if (my_stringend != c) | ||
| 811 | string_lossage = 1; | ||
| 812 | } | ||
| 732 | 813 | ||
| 733 | /* Record comment-starters according to that | 814 | /* Record comment-starters according to that |
| 734 | quote-parity to the comment-end. */ | 815 | quote-parity to the comment-end. */ |
| @@ -737,11 +818,31 @@ scan_lists (from, count, depth, sexpflag) | |||
| 737 | 818 | ||
| 738 | /* If we come to another comment-end, | 819 | /* If we come to another comment-end, |
| 739 | assume it's not inside a string. | 820 | assume it's not inside a string. |
| 740 | That determines the quote parity to the comment-end. */ | 821 | That determines the quote parity to the comment-end. |
| 741 | if (code == Sendcomment) | 822 | Note that the comment style this character ends must |
| 823 | match the style that we have begun */ | ||
| 824 | if (code == Sendcomment | ||
| 825 | && SYNTAX_COMMENT_STYLE (FETCH_CHAR (from)) == comstyle) | ||
| 742 | break; | 826 | break; |
| 743 | } | 827 | } |
| 744 | from = ofrom[parity]; | 828 | if (string_lossage) |
| 829 | { | ||
| 830 | /* We had two kinds of string delimiters mixed up | ||
| 831 | together. Decode this going forwards. | ||
| 832 | Scan fwd from the previous comment ender | ||
| 833 | to the one in question; this records where we | ||
| 834 | last passed a comment starter. */ | ||
| 835 | struct lisp_parse_state state; | ||
| 836 | scan_sexps_forward (&state, from + 1, comment_end - 1, | ||
| 837 | -10000, 0, Qnil); | ||
| 838 | if (state.incomment) | ||
| 839 | from = state.comstart; | ||
| 840 | else | ||
| 841 | /* We can't grok this as a comment; scan it normally. */ | ||
| 842 | from = comment_end; | ||
| 843 | } | ||
| 844 | else | ||
| 845 | from = ofrom[parity]; | ||
| 745 | } | 846 | } |
| 746 | break; | 847 | break; |
| 747 | 848 | ||
| @@ -858,26 +959,13 @@ This includes chars with \"quote\" or \"prefix\" syntax (' or p).") | |||
| 858 | return Qnil; | 959 | return Qnil; |
| 859 | } | 960 | } |
| 860 | 961 | ||
| 861 | struct lisp_parse_state | ||
| 862 | { | ||
| 863 | int depth; /* Depth at end of parsing */ | ||
| 864 | int instring; /* -1 if not within string, else desired terminator. */ | ||
| 865 | int incomment; /* Nonzero if within a comment at end of parsing */ | ||
| 866 | int quoted; /* Nonzero if just after an escape char at end of parsing */ | ||
| 867 | int thislevelstart; /* Char number of most recent start-of-expression at current level */ | ||
| 868 | int prevlevelstart; /* Char number of start of containing expression */ | ||
| 869 | int location; /* Char number at which parsing stopped. */ | ||
| 870 | int mindepth; /* Minimum depth seen while scanning. */ | ||
| 871 | }; | ||
| 872 | |||
| 873 | /* Parse forward from FROM to END, | 962 | /* Parse forward from FROM to END, |
| 874 | assuming that FROM is the start of a function, | 963 | assuming that FROM has state OLDSTATE (nil means FROM is start of function), |
| 875 | and return a description of the state of the parse at END. */ | 964 | and return a description of the state of the parse at END. |
| 876 | 965 | If STOPBEFORE is nonzero, stop at the start of an atom. */ | |
| 877 | struct lisp_parse_state val_scan_sexps_forward; | ||
| 878 | 966 | ||
| 879 | struct lisp_parse_state * | 967 | scan_sexps_forward (stateptr, from, end, targetdepth, stopbefore, oldstate) |
| 880 | scan_sexps_forward (from, end, targetdepth, stopbefore, oldstate) | 968 | struct lisp_parse_state *stateptr; |
| 881 | register int from; | 969 | register int from; |
| 882 | int end, targetdepth, stopbefore; | 970 | int end, targetdepth, stopbefore; |
| 883 | Lisp_Object oldstate; | 971 | Lisp_Object oldstate; |
| @@ -905,6 +993,7 @@ scan_sexps_forward (from, end, targetdepth, stopbefore, oldstate) | |||
| 905 | depth = 0; | 993 | depth = 0; |
| 906 | state.instring = -1; | 994 | state.instring = -1; |
| 907 | state.incomment = 0; | 995 | state.incomment = 0; |
| 996 | state.comstyle = 0; /* comment style a by default */ | ||
| 908 | } | 997 | } |
| 909 | else | 998 | else |
| 910 | { | 999 | { |
| @@ -927,6 +1016,14 @@ scan_sexps_forward (from, end, targetdepth, stopbefore, oldstate) | |||
| 927 | oldstate = Fcdr (oldstate); | 1016 | oldstate = Fcdr (oldstate); |
| 928 | tem = Fcar (oldstate); | 1017 | tem = Fcar (oldstate); |
| 929 | start_quoted = !NILP (tem); | 1018 | start_quoted = !NILP (tem); |
| 1019 | |||
| 1020 | /* if the eight element of the list is nil, we are in comment | ||
| 1021 | style a. if it is non-nil, we are in comment style b */ | ||
| 1022 | oldstate = Fcdr (oldstate); | ||
| 1023 | oldstate = Fcdr (oldstate); | ||
| 1024 | oldstate = Fcdr (oldstate); | ||
| 1025 | tem = Fcar (oldstate); | ||
| 1026 | state.comstyle = !NILP (tem); | ||
| 930 | } | 1027 | } |
| 931 | state.quoted = 0; | 1028 | state.quoted = 0; |
| 932 | mindepth = depth; | 1029 | mindepth = depth; |
| @@ -946,11 +1043,19 @@ scan_sexps_forward (from, end, targetdepth, stopbefore, oldstate) | |||
| 946 | 1043 | ||
| 947 | while (from < end) | 1044 | while (from < end) |
| 948 | { | 1045 | { |
| 949 | code = SYNTAX(FETCH_CHAR (from)); | 1046 | code = SYNTAX (FETCH_CHAR (from)); |
| 950 | from++; | 1047 | from++; |
| 951 | if (from < end && SYNTAX_COMSTART_FIRST (FETCH_CHAR (from - 1)) | 1048 | if (from < end && SYNTAX_COMSTART_FIRST (FETCH_CHAR (from - 1)) |
| 952 | && SYNTAX_COMSTART_SECOND (FETCH_CHAR (from))) | 1049 | && SYNTAX_COMSTART_SECOND (FETCH_CHAR (from))) |
| 953 | code = Scomment, from++; | 1050 | { |
| 1051 | /* Record the comment style we have entered so that only | ||
| 1052 | the comment-end sequence of the same style actually | ||
| 1053 | terminates the comment section. */ | ||
| 1054 | code = Scomment; | ||
| 1055 | state.comstyle = SYNTAX_COMMENT_STYLE (FETCH_CHAR (from)); | ||
| 1056 | from++; | ||
| 1057 | } | ||
| 1058 | |||
| 954 | if (SYNTAX_PREFIX (FETCH_CHAR (from - 1))) | 1059 | if (SYNTAX_PREFIX (FETCH_CHAR (from - 1))) |
| 955 | continue; | 1060 | continue; |
| 956 | #ifdef SWITCH_ENUM_BUG | 1061 | #ifdef SWITCH_ENUM_BUG |
| @@ -976,9 +1081,9 @@ scan_sexps_forward (from, end, targetdepth, stopbefore, oldstate) | |||
| 976 | while (from < end) | 1081 | while (from < end) |
| 977 | { | 1082 | { |
| 978 | #ifdef SWITCH_ENUM_BUG | 1083 | #ifdef SWITCH_ENUM_BUG |
| 979 | switch ((int) SYNTAX(FETCH_CHAR (from))) | 1084 | switch ((int) SYNTAX (FETCH_CHAR (from))) |
| 980 | #else | 1085 | #else |
| 981 | switch (SYNTAX(FETCH_CHAR (from))) | 1086 | switch (SYNTAX (FETCH_CHAR (from))) |
| 982 | #endif | 1087 | #endif |
| 983 | { | 1088 | { |
| 984 | case Scharquote: | 1089 | case Scharquote: |
| @@ -1001,18 +1106,29 @@ scan_sexps_forward (from, end, targetdepth, stopbefore, oldstate) | |||
| 1001 | 1106 | ||
| 1002 | case Scomment: | 1107 | case Scomment: |
| 1003 | state.incomment = 1; | 1108 | state.incomment = 1; |
| 1109 | state.comstart = from; | ||
| 1004 | startincomment: | 1110 | startincomment: |
| 1005 | while (1) | 1111 | while (1) |
| 1006 | { | 1112 | { |
| 1007 | if (from == end) goto done; | 1113 | if (from == end) goto done; |
| 1008 | if (SYNTAX (prev = FETCH_CHAR (from)) == Sendcomment) | 1114 | prev = FETCH_CHAR (from); |
| 1115 | if (SYNTAX (prev) == Sendcomment | ||
| 1116 | && SYNTAX_COMMENT_STYLE (prev) == state.comstyle) | ||
| 1117 | /* Only terminate the comment section if the endcomment | ||
| 1118 | of the same style as the start sequence has been | ||
| 1119 | encountered. */ | ||
| 1009 | break; | 1120 | break; |
| 1010 | from++; | 1121 | from++; |
| 1011 | if (from < end && SYNTAX_COMEND_FIRST (prev) | 1122 | if (from < end && SYNTAX_COMEND_FIRST (prev) |
| 1012 | && SYNTAX_COMEND_SECOND (FETCH_CHAR (from))) | 1123 | && SYNTAX_COMEND_SECOND (FETCH_CHAR (from)) |
| 1124 | && SYNTAX_COMMENT_STYLE (prev) == state.comstyle) | ||
| 1125 | /* Only terminate the comment section if the end-comment | ||
| 1126 | sequence of the same style as the start sequence has | ||
| 1127 | been encountered. */ | ||
| 1013 | { from++; break; } | 1128 | { from++; break; } |
| 1014 | } | 1129 | } |
| 1015 | state.incomment = 0; | 1130 | state.incomment = 0; |
| 1131 | state.comstyle = 0; /* reset the comment style */ | ||
| 1016 | break; | 1132 | break; |
| 1017 | 1133 | ||
| 1018 | case Sopen: | 1134 | case Sopen: |
| @@ -1047,9 +1163,9 @@ scan_sexps_forward (from, end, targetdepth, stopbefore, oldstate) | |||
| 1047 | if (from >= end) goto done; | 1163 | if (from >= end) goto done; |
| 1048 | if (FETCH_CHAR (from) == state.instring) break; | 1164 | if (FETCH_CHAR (from) == state.instring) break; |
| 1049 | #ifdef SWITCH_ENUM_BUG | 1165 | #ifdef SWITCH_ENUM_BUG |
| 1050 | switch ((int) SYNTAX(FETCH_CHAR (from))) | 1166 | switch ((int) SYNTAX (FETCH_CHAR (from))) |
| 1051 | #else | 1167 | #else |
| 1052 | switch (SYNTAX(FETCH_CHAR (from))) | 1168 | switch (SYNTAX (FETCH_CHAR (from))) |
| 1053 | #endif | 1169 | #endif |
| 1054 | { | 1170 | { |
| 1055 | case Scharquote: | 1171 | case Scharquote: |
| @@ -1086,8 +1202,7 @@ scan_sexps_forward (from, end, targetdepth, stopbefore, oldstate) | |||
| 1086 | state.location = from; | 1202 | state.location = from; |
| 1087 | immediate_quit = 0; | 1203 | immediate_quit = 0; |
| 1088 | 1204 | ||
| 1089 | val_scan_sexps_forward = state; | 1205 | *stateptr = state; |
| 1090 | return &val_scan_sexps_forward; | ||
| 1091 | } | 1206 | } |
| 1092 | 1207 | ||
| 1093 | /* This comment supplies the doc string for parse-partial-sexp, | 1208 | /* This comment supplies the doc string for parse-partial-sexp, |
| @@ -1100,7 +1215,7 @@ Parsing stops at TO or when certain criteria are met;\n\ | |||
| 1100 | point is set to where parsing stops.\n\ | 1215 | point is set to where parsing stops.\n\ |
| 1101 | If fifth arg STATE is omitted or nil,\n\ | 1216 | If fifth arg STATE is omitted or nil,\n\ |
| 1102 | parsing assumes that FROM is the beginning of a function.\n\ | 1217 | parsing assumes that FROM is the beginning of a function.\n\ |
| 1103 | Value is a list of seven elements describing final state of parsing:\n\ | 1218 | Value is a list of eight elements describing final state of parsing:\n\ |
| 1104 | 1. depth in parens.\n\ | 1219 | 1. depth in parens.\n\ |
| 1105 | 2. character address of start of innermost containing list; nil if none.\n\ | 1220 | 2. character address of start of innermost containing list; nil if none.\n\ |
| 1106 | 3. character address of start of last complete sexp terminated.\n\ | 1221 | 3. character address of start of last complete sexp terminated.\n\ |
| @@ -1109,6 +1224,7 @@ Value is a list of seven elements describing final state of parsing:\n\ | |||
| 1109 | 5. t if inside a comment.\n\ | 1224 | 5. t if inside a comment.\n\ |
| 1110 | 6. t if following a quote character.\n\ | 1225 | 6. t if following a quote character.\n\ |
| 1111 | 7. the minimum paren-depth encountered during this scan.\n\ | 1226 | 7. the minimum paren-depth encountered during this scan.\n\ |
| 1227 | 8. t if in a comment of style `b'.\n\ | ||
| 1112 | If third arg TARGETDEPTH is non-nil, parsing stops if the depth\n\ | 1228 | If third arg TARGETDEPTH is non-nil, parsing stops if the depth\n\ |
| 1113 | in parentheses becomes equal to TARGETDEPTH.\n\ | 1229 | in parentheses becomes equal to TARGETDEPTH.\n\ |
| 1114 | Fourth arg STOPBEFORE non-nil means stop when come to\n\ | 1230 | Fourth arg STOPBEFORE non-nil means stop when come to\n\ |
| @@ -1136,8 +1252,8 @@ DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 5, 0, | |||
| 1136 | target = -100000; /* We won't reach this depth */ | 1252 | target = -100000; /* We won't reach this depth */ |
| 1137 | 1253 | ||
| 1138 | validate_region (&from, &to); | 1254 | validate_region (&from, &to); |
| 1139 | state = *scan_sexps_forward (XINT (from), XINT (to), | 1255 | scan_sexps_forward (&state, XINT (from), XINT (to), |
| 1140 | target, !NILP (stopbefore), oldstate); | 1256 | target, !NILP (stopbefore), oldstate); |
| 1141 | 1257 | ||
| 1142 | SET_PT (state.location); | 1258 | SET_PT (state.location); |
| 1143 | 1259 | ||
| @@ -1147,7 +1263,9 @@ DEFUN ("parse-partial-sexp", Fparse_partial_sexp, Sparse_partial_sexp, 2, 5, 0, | |||
| 1147 | Fcons (state.instring >= 0 ? make_number (state.instring) : Qnil, | 1263 | Fcons (state.instring >= 0 ? make_number (state.instring) : Qnil, |
| 1148 | Fcons (state.incomment ? Qt : Qnil, | 1264 | Fcons (state.incomment ? Qt : Qnil, |
| 1149 | Fcons (state.quoted ? Qt : Qnil, | 1265 | Fcons (state.quoted ? Qt : Qnil, |
| 1150 | Fcons (make_number (state.mindepth), Qnil))))))); | 1266 | Fcons (make_number (state.mindepth), |
| 1267 | Fcons (state.comstyle ? Qt : Qnil, | ||
| 1268 | Qnil)))))))); | ||
| 1151 | } | 1269 | } |
| 1152 | 1270 | ||
| 1153 | init_syntax_once () | 1271 | init_syntax_once () |