scrooloose/syntastic — Issue #140: ocaml syntaxchecker
Author: edwintorok
Created: 2012-01-13 11:35:23+00:00
State: open

There is no syntax checker for OCaml. Here is one (supports .ml, .mli, .mll and .mly):

if exists("loaded_ocaml_syntax_checker")
finish
endif
let loaded_ocaml_syntax_checker = 1

"bail if the user doesnt have camlp4o installed
if !executable("camlp4o")
finish
endif

function! SyntaxCheckers_ocaml_GetLocList()
let extension = expand('%:e')
if match(extension, 'mly') >= 0
" ocamlyacc output can't be redirected, so use menhir
if !executable("menhir")
return []
endif
let makeprg = "menhir --only-preprocess ".shellescape(expand('%')) . " >/dev/null"
elseif match(extension,'mll') >= 0
if !executable("ocamllex")
return []
endif
let makeprg = "ocamllex -q -o /dev/null ".shellescape(expand('%'))
else
let makeprg = "camlp4o -o /dev/null ".shellescape(expand('%'))
endif
let errorformat = '%EFile "%f"\, line %l\, characters %c-%*\d:,'.
\ '%EFile "%f"\, line %l\, characters %c-%*\d (end at line %*\d\, character %*\d):,'.
\ '%EFile "%f"\, line %l\, character %c:,'.
\ '%EFile "%f"\, line %l\, character %c:%m,'.
\ '%C%m'

return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
endfunction

function! SyntaxCheckers_locaml_GetLocList()
return SyntaxCheckers_ocaml_GetLocList()
endfunction