~eshel/sweep

54e0a5e9262f8c9b70c6e4adddfc3453a6fcae4d — Eshel Yaron 6 months ago 9ea7cd7
Fix fullstop detection in presence of dot character literal

This fixes an issue where the character "0'." in a clause body would
confuse clause boundaries calculation.

* sweeprolog.el (sweeprolog-end-of-top-term): Make sure fullstop have
punctuation syntax class (otherwise it's part of a character literal).
* sweeprolog-tests.el (end-of-top-term-with-dot-char-literal): Test it
2 files changed, 19 insertions(+), 0 deletions(-)

M sweeprolog-tests.el
M sweeprolog.el
M sweeprolog-tests.el => sweeprolog-tests.el +17 -0
@@ 1379,6 1379,23 @@ html_program_section(Section, Dict) -->
  (sweeprolog-end-of-top-term)
  (should (= (point) 466)))

(sweeprolog-deftest end-of-top-term-with-dot-char-literal ()
  "Tests detecting the fullstop in presence of `0\'.'."
  "
full_stop_after(Index, String, [H|T]) :-
    string_code(Index, String, H),
    Index2 is Index+1,
    (   code_type(H, space)
    ->  !, full_stop_after(Index2, String, T)
    ;   H == 0'.
    ->  !, layout_after(Index2, String, T)
    ).
full_stop_after(_, _, []).
"
  (goto-char (point-min))
  (sweeprolog-end-of-top-term)
  (should (= (point) 242)))

(sweeprolog-deftest fullstop-detection ()
  "Tests detecting the fullstop in presence of confusing comments."
  "

M sweeprolog.el => sweeprolog.el +2 -0
@@ 1384,6 1384,7 @@ Prolog buffers."
                    (ppre (sweeprolog-op-prefix-precedence op)))
               (cond
                ((and (string= "." op)
                      (equal 1 (sweeprolog-syntax-class-at obeg))
                      (let ((sa (sweeprolog-syntax-class-at (1+ obeg))))
                        (or (null sa) (member sa '(0 12)))))
                 nil)


@@ 3873,6 3874,7 @@ The command `beginning-of-defun' calls this function in
      (or (re-search-forward (rx "." (or white "\n")) nil t)
          (goto-char (point-max)))
      (while (and (or (nth 8 (syntax-ppss))
                      (equal 0 (sweeprolog-syntax-class-at (point)))
                      (save-excursion
                        (nth 8 (syntax-ppss (max (point-min)
                                                 (1- (point))))))