/vim/bundle/syntastic/syntax_checkers/ocaml/camlp4o.vim

https://bitbucket.org/omairabdullah/config · Vim Script · 149 lines · 77 code · 19 blank · 53 comment · 17 complexity · 1dc47eb25d4bed68fc4130907a7bb1d3 MD5 · raw file

  1. "============================================================================
  2. "File: ocaml.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Török Edwin <edwintorok at gmail dot com>
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. "============================================================================
  12. "
  13. " The more reliable way to check for a single .ml file is to use ocamlc.
  14. " You can do that setting this in your .vimrc:
  15. "
  16. " let g:syntastic_ocaml_use_ocamlc = 1
  17. " It's possible to use ocamlc in conjuction with Jane Street's Core. In order
  18. " to do that, you have to specify this in your .vimrc:
  19. "
  20. " let g:syntastic_ocaml_use_janestreet_core = 1
  21. " let g:syntastic_ocaml_janestreet_core_dir = <path>
  22. "
  23. " Where path is the path to your core installation (usually a collection of
  24. " .cmx and .cmxa files).
  25. "
  26. "
  27. " By default the camlp4o preprocessor is used to check the syntax of .ml, and .mli files,
  28. " ocamllex is used to check .mll files and menhir is used to check .mly files.
  29. " The output is all redirected to /dev/null, nothing is written to the disk.
  30. "
  31. " If your source code needs camlp4r then you can define this in your .vimrc:
  32. "
  33. " let g:syntastic_ocaml_camlp4r = 1
  34. "
  35. " If you used some syntax extensions, or you want to also typecheck the source
  36. " code, then you can define this:
  37. "
  38. " let g:syntastic_ocaml_use_ocamlbuild = 1
  39. "
  40. " This will run ocamlbuild <name>.inferred.mli, so it will write to your _build
  41. " directory (and possibly rebuild your myocamlbuild.ml plugin), only enable this
  42. " if you are ok with that.
  43. "
  44. " If you are using syntax extensions / external libraries and have a properly
  45. " set up _tags (and myocamlbuild.ml file) then it should just work
  46. " to enable this flag and get syntax / type checks through syntastic.
  47. "
  48. " For best results your current directory should be the project root
  49. " (same situation if you want useful output from :make).
  50. if exists("g:loaded_syntastic_ocaml_camlp4o_checker")
  51. finish
  52. endif
  53. let g:loaded_syntastic_ocaml_camlp4o_checker=1
  54. if exists('g:syntastic_ocaml_camlp4r') &&
  55. \ g:syntastic_ocaml_camlp4r != 0
  56. let s:ocamlpp="camlp4r"
  57. else
  58. let s:ocamlpp="camlp4o"
  59. endif
  60. function! SyntaxCheckers_ocaml_camlp4o_IsAvailable()
  61. return executable(s:ocamlpp)
  62. endfunction
  63. if !exists('g:syntastic_ocaml_use_ocamlc') || !executable('ocamlc')
  64. let g:syntastic_ocaml_use_ocamlc = 0
  65. endif
  66. if !exists('g:syntastic_ocaml_use_janestreet_core')
  67. let g:syntastic_ocaml_use_ocamlc = 0
  68. endif
  69. if !exists('g:syntastic_ocaml_use_ocamlbuild') || !executable("ocamlbuild")
  70. let g:syntastic_ocaml_use_ocamlbuild = 0
  71. endif
  72. function! SyntaxCheckers_ocaml_camlp4o_GetLocList()
  73. let makeprg = s:GetMakeprg()
  74. if makeprg == ""
  75. return []
  76. endif
  77. let errorformat =
  78. \ '%AFile "%f"\, line %l\, characters %c-%*\d:,'.
  79. \ '%AFile "%f"\, line %l\, characters %c-%*\d (end at line %*\d\, character %*\d):,'.
  80. \ '%AFile "%f"\, line %l\, character %c:,'.
  81. \ '%AFile "%f"\, line %l\, character %c:%m,'.
  82. \ '%-GPreprocessing error %.%#,'.
  83. \ '%-GCommand exited %.%#,'.
  84. \ '%C%tarning %n: %m,'.
  85. \ '%C%m,'.
  86. \ '%-G+%.%#'
  87. return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat })
  88. endfunction
  89. function! s:GetMakeprg()
  90. if g:syntastic_ocaml_use_ocamlc
  91. return s:GetOcamlcMakeprg()
  92. endif
  93. if g:syntastic_ocaml_use_ocamlbuild && isdirectory('_build')
  94. return s:GetOcamlBuildMakeprg()
  95. endif
  96. return s:GetOtherMakeprg()
  97. endfunction
  98. function! s:GetOcamlcMakeprg()
  99. if g:syntastic_ocaml_use_janestreet_core
  100. let build_cmd = "ocamlc -I "
  101. let build_cmd .= expand(g:syntastic_ocaml_janestreet_core_dir)
  102. let build_cmd .= " -c " . syntastic#util#shexpand('%')
  103. return build_cmd
  104. else
  105. return "ocamlc -c " . syntastic#util#shexpand('%')
  106. endif
  107. endfunction
  108. function! s:GetOcamlBuildMakeprg()
  109. return "ocamlbuild -quiet -no-log -tag annot," . s:ocamlpp . " -no-links -no-hygiene -no-sanitize " .
  110. \ syntastic#util#shexpand('%:r') . ".cmi"
  111. endfunction
  112. function! s:GetOtherMakeprg()
  113. "TODO: give this function a better name?
  114. "
  115. "TODO: should use throw/catch instead of returning an empty makeprg
  116. let extension = expand('%:e')
  117. let makeprg = ""
  118. if match(extension, 'mly') >= 0 && executable("menhir")
  119. " ocamlyacc output can't be redirected, so use menhir
  120. let makeprg = "menhir --only-preprocess " . syntastic#util#shexpand('%') . " >" . syntastic#util#DevNull()
  121. elseif match(extension,'mll') >= 0 && executable("ocamllex")
  122. let makeprg = "ocamllex -q " . syntastic#c#NullOutput() . " " . syntastic#util#shexpand('%')
  123. else
  124. let makeprg = "camlp4o " . syntastic#c#NullOutput() . " " . syntastic#util#shexpand('%')
  125. endif
  126. return makeprg
  127. endfunction
  128. call g:SyntasticRegistry.CreateAndRegisterChecker({
  129. \ 'filetype': 'ocaml',
  130. \ 'name': 'camlp4o'})