New checker "perl6" for Perl 6.

This commit is contained in:
Claudio Ramirez 2017-09-18 20:25:13 +03:00 committed by LCD 47
parent 2ac540a103
commit 026e09fbdf
7 changed files with 226 additions and 11 deletions

View File

@ -61,10 +61,10 @@ Source Language, ActionScript, Ada, Ansible configurations, API Blueprint,
AppleScript, AsciiDoc, Assembly languages, BEMHTML, Bro, Bourne shell, C, C++,
C#, Cabal, Chef, CMake, CoffeeScript, Coco, Coq, CSS, Cucumber, CUDA, D, Dart,
DocBook, Dockerfile, Dust, Elixir, Erlang, eRuby, Fortran, Gentoo metadata,
GLSL, Go, Haml, Haskell, Haxe, Handlebars, HSS, HTML, Java, JavaScript,
JSON, JSX, Julia, LESS, Lex, Limbo, LISP, LLVM intermediate language, Lua,
Markdown, MATLAB, Mercury, NASM, Nix, Objective-C, Objective-C++, OCaml, Perl,
Perl POD, PHP, gettext Portable Object, OS X and iOS property lists, Pug
GLSL, Go, Haml, Haskell, Haxe, Handlebars, HSS, HTML, Java, JavaScript, JSON,
JSX, Julia, LESS, Lex, Limbo, LISP, LLVM intermediate language, Lua, Markdown,
MATLAB, Mercury, NASM, Nix, Objective-C, Objective-C++, OCaml, Perl, Perl
6, Perl POD, PHP, gettext Portable Object, OS X and iOS property lists, Pug
(formerly Jade), Puppet, Python, QML, R, Racket, RDF TriG, RDF Turtle, Relax
NG, reStructuredText, RPM spec, Ruby, SASS/SCSS, Scala, Slim, SML, Solidity,
Sphinx, SQL, Stylus, Tcl, TeX, Texinfo, Twig, TypeScript, Vala, Verilog, VHDL,

View File

@ -65,6 +65,17 @@ function! syntastic#postprocess#guards(errors) abort " {{{2
return a:errors
endfunction " }}}2
" convert error messages from UTF-8 to the current encoding
function! syntastic#postprocess#iconv(errors) abort " {{{2
if has('iconv') && &encoding !=# '' && &encoding !=# 'utf-8'
for e in a:errors
let e['text'] = iconv(e['text'], "utf-8", &encoding)
endfor
endif
return a:errors
endfunction " }}}2
" }}}1
let &cpo = s:save_cpo

View File

@ -264,6 +264,43 @@ function! syntastic#preprocess#perl(errors) abort " {{{2
return syntastic#util#unique(out)
endfunction " }}}2
function! syntastic#preprocess#perl6(errors) abort " {{{2
if a:errors[0] ==# 'Syntax OK'
return []
endif
let errs = s:_decode_JSON(join(a:errors, ''))
let out = []
if type(errs) == type({})
try
for val in values(errs)
let line = get(val, 'line', 0)
let pos = get(val, 'pos', 0)
if pos && has('byte_offset')
let line_pos = byte2line(pos + 1)
let column = line_pos > 0 ? pos - line2byte(line_pos) + 2 : 0
else
let column = 0
endif
call add(out, join([
\ get(val, 'filename', ''),
\ line,
\ column,
\ get(val, 'message', '') ], ':'))
endfor
catch /\m^Vim\%((\a\+)\)\=:E716/
call syntastic#log#warn('checker perl6/perl6: unrecognized error item ' . string(val))
let out = []
endtry
else
call syntastic#log#warn('checker perl6/perl6: unrecognized error format')
endif
return out
endfunction " }}}2
function! syntastic#preprocess#prospector(errors) abort " {{{2
let errs = join(a:errors, '')
if errs ==# ''

View File

@ -81,6 +81,7 @@ SYNTAX CHECKERS BY LANGUAGE *syntastic-checkers-lang*
OCaml....................................|syntastic-checkers-ocaml|
Perl.....................................|syntastic-checkers-perl|
Perl 6...................................|syntastic-checkers-perl6|
PHP......................................|syntastic-checkers-php|
POD......................................|syntastic-checkers-pod|
Pug (formerly Jade)......................|syntastic-checkers-pug|
@ -4562,11 +4563,11 @@ Security~
This checker runs "perl -c" against your files, which in turn executes any
"BEGIN", "UNITCHECK", and "CHECK" blocks, and any "use" statements in your
file (cf. http://perldoc.perl.org/perlrun.html#*-c*). This is probably fine if
you wrote the file yourself, but it can be a problem if you're trying to check
third party files. If you are 100% willing to let Vim run the code in your
file, set 'g:syntastic_enable_perl_checker' to 1 in your vimrc to enable this
checker: >
files (cf. http://perldoc.perl.org/perlrun.html#*-c*). This is probably fine
if you wrote the file yourself, but it can be a problem if you're trying to
check third party files. If you are 100% willing to let Vim run the code in
your files, set 'g:syntastic_enable_perl_checker' to 1 in your vimrc to enable
this checker: >
let g:syntastic_enable_perl_checker = 1
<
There is also a buffer-local version of this variable, that takes precedence
@ -4589,7 +4590,7 @@ Default: "perl"
The perl interpreter to use.
*'g:syntastic_perl_lib_path'*
Type: list os strings
Type: list of strings
Default: []
List of include directories to be added to the perl command line. Example: >
let g:syntastic_perl_lib_path = [ "./lib", "./lib/auto" ]
@ -4651,6 +4652,65 @@ accepts the standard options described at |syntastic-config-makeprg|.
See also: |syntastic-pod-podchecker|.
==============================================================================
SYNTAX CHECKERS FOR PERL 6 *syntastic-checkers-perl6*
The following checkers are available for Perl 6 (filetype "perl6"):
1. perl6....................|syntastic-perl6-perl6|
------------------------------------------------------------------------------
1. perl6 *syntastic-perl6-perl6*
Name: perl6
Maintainers: Claudio Ramirez <pub.claudio@gmail.com>
"perl6" is a checker for Perl 6 files using the "Rakudo" compiler. See the
project's page for details:
http://rakudo.org/
Syntastic requires Rakudo Star release 2017.01 or later.
Security~
This checker runs "perl6 -c" against your files, which executes any "BEGIN"
and "CHECK" blocks (cf. https://docs.perl6.org/programs/00-running). This
is probably fine if you wrote the files yourself, but it can be a problem if
you're trying to check third party files. If you are 100% willing to let Vim
run the code in your files, set 'g:syntastic_enable_perl6_checker' to 1 in
your vimrc to enable this checker: >
let g:syntastic_enable_perl6_checker = 1
<
There is also a buffer-local version of this variable, that takes precedence
over it in the buffers where it is defined.
Please note that setting this variable doesn't automatically enable the
checker, you still need to add it to 'g:syntastic_perl6_checkers' if you plan
to use it.
Checker options~
This checker is initialised using the "makeprgBuild()" function and thus it
accepts the standard options described at syntastic-config-makeprg.
Additionally:
*'g:syntastic_perl6_lib_path'*
Type: list of strings
Default: []
List of include directories to be added to the perl6 command line. Example: >
let g:syntastic_perl6_lib_path = [ "./lib", "./lib/auto" ]
<
You can also set the "PERL6LIB" environment variable to a colon-separated
list of add-hoc include paths. These paths will then be added to the ones
prescribed by |'g:syntastic_perl6_lib_path'|.
Note~
At the time of this writing the support for JSON error output of the "Rakudo"
compiler is still incomplete.
==============================================================================
SYNTAX CHECKERS FOR PHP *syntastic-checkers-php*

View File

@ -19,7 +19,7 @@ if has('reltime')
lockvar! g:_SYNTASTIC_START
endif
let g:_SYNTASTIC_VERSION = '3.8.0-83'
let g:_SYNTASTIC_VERSION = '3.8.0-84'
lockvar g:_SYNTASTIC_VERSION
" Sanity checks {{{1

View File

@ -68,6 +68,7 @@ let s:_DEFAULT_CHECKERS = {
\ 'objcpp': ['gcc'],
\ 'ocaml': ['camlp4o'],
\ 'perl': ['perlcritic'],
\ 'perl6': [],
\ 'php': ['php', 'phpcs', 'phpmd'],
\ 'po': ['msgfmt'],
\ 'pod': ['podchecker'],

View File

@ -0,0 +1,106 @@
"============================================================================
"File: perl6.vim
"Description: Syntax checking plugin for syntastic
"Maintainer: Claudio Ramirez <pub.claudio at gmail dot com>
"License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
"============================================================================
"
" Security:
"
" This checker runs 'perl6 -c' against your file, which in turn executes
" any BEGIN and CHECK blocks in your file. This is probably fine if you
" wrote the file yourself, but it can be a problem if you're trying to
" check third party files. If you are 100% willing to let Vim run the code
" in your file, set g:syntastic_enable_perl6_checker to 1 in your vimrc
" to enable this
" checker:
"
" let g:syntastic_enable_perl6_checker = 1
"
" Reference:
"
" - https://docs.perl6.org/programs/00-running
if exists('g:loaded_syntastic_perl6_perl6_checker')
finish
endif
let g:loaded_syntastic_perl6_perl6_checker = 1
if !exists('g:syntastic_perl6_lib_path')
let g:syntastic_perl6_lib_path = []
endif
if !exists('g:syntastic_perl6_perl6_sort')
let g:syntastic_perl6_perl6_sort = 1
endif
let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_perl6_perl6_IsAvailable() dict " {{{1
" don't call executable() here, to allow things like
" let g:syntastic_perl6_perl6_exec = '/usr/bin/env perl6'
silent! call syntastic#util#system(self.getExecEscaped() . ' -e ' . syntastic#util#shescape('exit(0)'))
return (v:shell_error == 0) && syntastic#util#versionIsAtLeast(self.getVersion(), [2017, 1])
endfunction " }}}1
function! SyntaxCheckers_perl6_perl6_GetHighlightRegex(item) " {{{1
let term = matchstr(a:item['text'], '\m''\zs.\{-}\ze''')
if term !=# ''
return '\V' . escape(term, '\')
endif
let term = matchstr(a:item['text'], '\m^Undeclared .\+:\W\zs\S\+\ze')
if term !=# ''
return '\V' . escape(term, '\')
endif
let term = matchstr(a:item['text'], '\mCould not find \zs.\{-}\ze at')
if term !=# ''
return '\V' . escape(term, '\')
endif
let term = matchstr(a:item['text'], '\mCould not find \zs\S\+$')
return term !=# '' ? '\V' . escape(term, '\') : ''
endfunction " }}}1
function! SyntaxCheckers_perl6_perl6_GetLocList() dict " {{{1
if type(g:syntastic_perl6_lib_path) == type('')
call syntastic#log#oneTimeWarn('variable g:syntastic_perl6_lib_path should be a list')
let includes = split(g:syntastic_perl6_lib_path, ',')
else
let includes = copy(syntastic#util#var('perl6_lib_path', []))
endif
" support for PERL6LIB environment variable
if $PERL6LIB !=# ''
let includes += split($PERL6LIB, ':')
endif
call map(includes, '"-I" . v:val')
let errorformat =
\ '%f:%l:%c:%m,' .
\ ':%l:%c:%m'
let makeprg = self.makeprgBuild({ 'args_before': ['-c'] + includes })
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'env': { 'RAKUDO_EXCEPTIONS_HANDLER': 'JSON' },
\ 'defaults': { 'bufnr': bufnr(''), 'type': 'E' },
\ 'returns': [0, 1],
\ 'preprocess': 'perl6',
\ 'postprocess': ['guards', 'iconv'] })
endfunction " }}}1
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'perl6',
\ 'name': 'perl6',
\ 'enable': 'enable_perl6_checker'})
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set sw=4 sts=4 et fdm=marker: