forked from ALSchwalm/flycheck-nim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flycheck-nim.el
115 lines (95 loc) · 4.46 KB
/
flycheck-nim.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
;;; flycheck-nim.el --- Defines a flycheck syntax checker for nim
;; Copyright (c) 2015 Adam Schwalm
;; Author: Adam Schwalm <[email protected]>
;; Version: 0.2.1
;; URL: https://github.com/ALSchwalm/flycheck-nim
;; Package-Requires: ((dash "2.4.0") (flycheck "0.20"))
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Adds Nim support to flycheck
;;; Code:
(require 'flycheck)
(require 'dash)
(flycheck-def-args-var flycheck-nim-args nim)
(flycheck-def-option-var flycheck-nim-experimental nil nim
"Whether to enable experimental features in the nim compiler.
When non-nil, enables experimental features, via `--experimental'."
:type 'boolean
:safe #'booleanp)
(flycheck-def-option-var flycheck-nim-threads t nim
"Whether to enable threads.
When non-nil, enables threads, via `--threads:on'."
:type 'boolean
:safe #'booleanp)
(flycheck-def-option-var flycheck-nim-hints "on" nim
"Whether to enable compiler hints.
Enables or disables all hints via `--hints'."
:type '(choice (const :tag "Off" "off")
(const :tag "On" "on"))
:safe #'stringp)
(flycheck-def-option-var flycheck-nim-warnings "on" nim
"Whether to enable compiler warnings.
Enables or disables all warnings via `--warnings'."
:type '(choice (const :tag "Off" "off")
(const :tag "On" "on"))
:safe #'stringp)
(flycheck-def-option-var flycheck-nim-specific-hints nil nim
"Settings for specific hints from the compiler.
Enables or disables specific hints via `--hint[x]'"
:type '(choice (const :tag "No specific hint settings" nil)
(repeat :tag "Specific hint settings"
(group (string :tag "Hint name")
(choice (const :tag "Off" "off")
(const :tag "On" "on")))))
:safe (lambda (l) (-all? #'flycheck-string-list-p l)))
(flycheck-def-option-var flycheck-nim-specific-warnings nil nim
"Settings for specific warnings from the compiler.
Enables or disables specific warnings via `--warning[x]'"
:type '(choice (const :tag "No specific warning settings" nil)
(repeat :tag "Specific warning settings"
(group (string :tag "Warning name")
(choice (const :tag "Off" "off")
(const :tag "On" "on")))))
:safe (lambda (l) (-all? #'flycheck-string-list-p l)))
(flycheck-define-checker nim
"A syntax checker for the nim programming language.
See http://nim-lang.org"
:command ("nim" "check"
(option-flag "--experimental" flycheck-nim-experimental)
(option-flag "--threads:on" flycheck-nim-threads)
(option "--hints:" flycheck-nim-hints concat)
(option "--warnings:" flycheck-nim-warnings concat)
(eval (--map (format "--hint[%s]:%s" (car it) (cadr it))
flycheck-nim-specific-hints))
(eval (--map (format "--warning[%s]:%s" (car it) (cadr it))
flycheck-nim-specific-warnings))
(eval flycheck-nim-args)
;; Must use source-inplace so relative imports and
;; qualified references to local variables resolve correctly
source-inplace)
:error-patterns
((error line-start (file-name) "(" line ", "
column ") Error:"
(message (one-or-more not-newline)
(optional
(and "\nbut expected one of:"
(minimal-match (one-or-more anything)) "\n\n"))))
(warning line-start (file-name) "(" line ", "
column ") " (or "Hint:" "Warning:") (message) line-end))
:error-filter
(lambda (errors)
(flycheck-sanitize-errors (flycheck-increment-error-columns errors)))
:modes (nim-mode nimrod-mode)
:predicate (lambda () (not org-src-mode)))
(add-to-list 'flycheck-checkers 'nim)
(provide 'flycheck-nim)
;;; flycheck-nim.el ends here