perfect insertion of guessed type.

This commit is contained in:
Kazu Yamamoto 2011-01-14 13:38:12 +09:00
parent 2f804f5de1
commit 7e9d992def

View File

@ -74,16 +74,30 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun ghc-extract-type (str)
(with-temp-buffer
(insert str)
(goto-char (point-min))
(when (re-search-forward "Inferred type: " nil t)
(delete-region (point-min) (point)))
(when (re-search-forward "forall [^.]+\\. " nil t)
(replace-match ""))
(while (re-search-forward "\0 +" nil t)
(replace-match " "))
(goto-char (point-min))
(while (re-search-forward "\\[Char\\]" nil t)
(replace-match "String"))
(re-search-forward "\0" nil t)
(buffer-substring-no-properties (point-min) (1- (point)))))
(defun ghc-flymake-insert-from-warning () (defun ghc-flymake-insert-from-warning ()
(interactive) (interactive)
(dolist (data (ghc-flymake-err-list)) (dolist (data (ghc-flymake-err-list))
(save-excursion (save-excursion
(cond (cond
((string-match "Inferred type: \\([^:]+ :: \\)\\(forall [^.]+\\.\\( \\|\0 +\\)\\)?\\([^\0]*\\)" data) ((string-match "Inferred type: " data)
(beginning-of-line) (beginning-of-line)
(insert (match-string 1 data) (insert (ghc-extract-type data) "\n"))
(replace-regexp-in-string "\\[Char\\]" "String" (match-string 4 data))
"\n"))
((string-match "lacks an accompanying binding" data) ((string-match "lacks an accompanying binding" data)
(beginning-of-line) (beginning-of-line)
(when (looking-at "^\\([^ ]+\\) *::") (when (looking-at "^\\([^ ]+\\) *::")