Skip to content

Commit

Permalink
Parse class type correctly (ocaml#239)
Browse files Browse the repository at this point in the history
Lex "type" after "class" as "c-type", in analogy with "m-type".
  • Loading branch information
mattiase committed Jun 24, 2021
1 parent 6559b20 commit a30dec9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
19 changes: 19 additions & 0 deletions tuareg-tests.el
Expand Up @@ -230,4 +230,23 @@ Returns the value of the last FORM."
(end-of-defun)
(should (equal (point) p8a)))))

(ert-deftest tuareg-class-type ()
(with-temp-buffer
(tuareg-mode)
(tuareg--lets
(insert "class type my_class_type =\n"
" object\n"
" method meth_1 : int\n"
" method meth_2 : unit\n"
" end;;\n")
(let p1 (point))

(goto-char (point-min))
(end-of-defun)
(should (equal (point) p1))
(beginning-of-defun)
(should (equal (point) (point-min)))
(should (equal (tuareg-discover-phrase (point-min))
(list (point-min) (1- p1) (1- p1)))))))

(provide 'tuareg-tests)
7 changes: 4 additions & 3 deletions tuareg.el
Expand Up @@ -1476,7 +1476,7 @@ For use on `electric-indent-functions'."
(def-in-exp (defs "in" exp))
(def (var "d=" exp) (id "d=" datatype) (id "d=" module))
(idtype (id ":" type))
(var (id) ("m-type" var) ("d-type" var) ("rec" var)
(var (id) ("m-type" var) ("d-type" var) ("c-type" var) ("rec" var)
("private" var) (idtype)
("l-module" var) ("l-class" var))
(exception (id "of" type))
Expand Down Expand Up @@ -1932,12 +1932,13 @@ Return values can be
(tuareg-smie--label-colon-p))))
(if (member nearest '("with" "|" "fun" "function" "functor"))
tok "t->"))))
;; Handle "module type", mod-constraint's "with/and type" and
;; polymorphic syntax.
;; Handle "module type", "class type", mod-constraint's "with/and type"
;; and polymorphic syntax.
((equal tok "type")
(save-excursion
(let ((prev (tuareg-smie--backward-token)))
(cond ((equal prev "module") "m-type")
((equal prev "class") "c-type")
((member prev '("and" "with")) "w-type")
((equal prev ":") "d-type"); ": type a. ..."
(t tok)))))
Expand Down

0 comments on commit a30dec9

Please sign in to comment.