summaryrefslogtreecommitdiff
path: root/ale_linters/sml/smlnj.vim
blob: b15995210a749d12899d4701207a92f1eaa3af8d (plain)
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
" Author: Paulo Alem    <paulo.alem@gmail.com>
" Description: Rudimentary SML checking with smlnj compiler

if exists('g:loaded_ale_sml_smlnj_checker')
    finish
endif

let g:loaded_ale_sml_smlnj_checker = 1

function! ale_linters#sml#smlnj#Handle(buffer, lines) abort
    " Try to match basic sml errors

    let l:out = []
    let l:pattern = '^.*\:\([0-9\.]\+\)\ \(\w\+\)\:\ \(.*\)'
    let l:pattern2 = '^.*\:\([0-9]\+\)\.\?\([0-9]\+\).* \(\(Warning\|Error\): .*\)'

    for l:line in a:lines
        let l:match2 = matchlist(l:line, l:pattern2)

        if len(l:match2) != 0
          call add(l:out, {
          \   'bufnr': a:buffer,
          \   'lnum': l:match2[1] + 0,
          \   'col' : l:match2[2] - 1,
          \   'text': l:match2[3],
          \   'type': l:match2[3] =~# '^Warning' ? 'W' : 'E',
          \})
          continue
        endif

        let l:match = matchlist(l:line, l:pattern)

        if len(l:match) != 0
          call add(l:out, {
          \   'bufnr': a:buffer,
          \   'lnum': l:match[1] + 0,
          \   'text': l:match[2] . ': ' . l:match[3],
          \   'type': l:match[2] ==# 'error' ? 'E' : 'W',
          \})
          continue
        endif

    endfor

    return l:out
endfunction

call g:ale#linter#Define('sml', {
\   'name': 'smlnj',
\   'executable': 'sml',
\   'command': 'sml',
\   'callback': 'ale_linters#sml#smlnj#Handle',
\})