contrib/vim: add Syntastic integration

Error and warning messages are prefixed with "error: " and "warning: "
correspondingly to ease integration with automated tooling.

`yywarn' function added. Off-by-one line numbers in warnings are fixed.

Two error messages are reworded to avoid repeating like
"error: error in server directive" or "error: syntax error".
This commit is contained in:
Anna “CyberTailor” 2021-07-13 16:30:54 +05:00 committed by Omar Polo
parent a556718a24
commit f3966209e5
4 changed files with 67 additions and 11 deletions

3
.gitignore vendored
View File

@ -1,9 +1,11 @@
*~
*.pem
TAGS
gmid
!contrib/gmid
gg
*.o
*.swp
compat/*.o
docs
y.tab.*
@ -14,6 +16,7 @@ config.h.old
config.log
config.log.old
configure.local
!contrib/vim/syntax_checkers/gmid
regress/testdata
regress/*.pem
regress/*.key

View File

@ -16,4 +16,8 @@ gmid.service
vim
Syntax highlighting of gmid configuration for vim, to be
placed into ~/.vim/ or /usr/share/vim/vimfiles.
placed into ~/.vim/ or /usr/share/vim/vimfiles/.
To enable Syntastic checker, put this line in your vimrc:
let g:syntastic_gmid_checkers = ['gmid']

View File

@ -0,0 +1,36 @@
" Syntax checking plugin for syntastic
" Language: gmid(1) configuration file
" Licence: ISC
if exists('g:loaded_syntastic_gmid_gmid_checker')
finish
endif
let g:loaded_syntastic_gmid_gmid_checker = 1
let s:save_cpo = &cpo
set cpo&vim
function! SyntaxCheckers_gmid_gmid_GetLocList() dict
let makeprg = self.makeprgBuild({ 'args': '-nc' })
let errorformat =
\ '%-Gconfig OK,' .
\ '%f:%l %tarning: %m,' .
\ '%f:%l %trror: %m'
return SyntasticMake({
\ 'makeprg': makeprg,
\ 'errorformat': errorformat,
\ 'defaults': {'type': 'E'},
\ 'returns': [0, 1] })
endfunction
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'gmid',
\ 'name': 'gmid',
\ 'exec': 'gmid'})
let &cpo = s:save_cpo
unlet s:save_cpo
" vim: set sw=4 sts=4 et fdm=marker:

33
parse.y
View File

@ -52,6 +52,9 @@ int yylex(void);
void yyerror(const char *, ...)
__attribute__((__format__ (printf, 1, 2)))
__attribute__((__nonnull__ (1)));
void yywarn(const char *, ...)
__attribute__((__format__ (printf, 1, 2)))
__attribute__((__nonnull__ (1)));
int kw_cmp(const void *, const void *);
int lookup(char *);
int igetc(void);
@ -183,10 +186,9 @@ varset : STRING '=' string {
option : TCHROOT string { conf.chroot = $2; }
| TIPV6 bool { conf.ipv6 = $2; }
| TMIME STRING string {
fprintf(stderr, "%s:%d: `mime MIME EXT' is deprecated and "
"will be removed in a future version, "
"please use the new syntax: `map MIME to-ext EXT'\n",
config_path, yylval.lineno+1);
yywarn("`mime MIME EXT' is deprecated and will be "
"removed in a future version, please use the new "
"syntax: `map MIME to-ext EXT'");
add_mime(&conf.mime, $2, $3);
}
| TMAP string TTOEXT string { add_mime(&conf.mime, $2, $4); }
@ -210,15 +212,14 @@ vhost : TSERVER string {
host->domain = $2;
if (strstr($2, "xn--") != NULL) {
warnx("%s:%d \"%s\" looks like punycode: "
"you should use the decoded hostname.",
config_path, yylval.lineno+1, $2);
yywarn("\"%s\" looks like punycode: you "
"should use the decoded hostname", $2);
}
} '{' optnl servopts locations '}' {
if (host->cert == NULL || host->key == NULL)
yyerror("invalid vhost definition: %s", $2);
}
| error '}' { yyerror("error in server directive"); }
| error '}' { yyerror("bad server directive"); }
;
servopts : /* empty */
@ -411,7 +412,19 @@ yyerror(const char *msg, ...)
file->errors++;
va_start(ap, msg);
fprintf(stderr, "%s:%d: ", config_path, yylval.lineno);
fprintf(stderr, "%s:%d error: ", config_path, yylval.lineno);
vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
va_end(ap);
}
void
yywarn(const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
fprintf(stderr, "%s:%d warning: ", config_path, yylval.lineno);
vfprintf(stderr, msg, ap);
fprintf(stderr, "\n");
va_end(ap);
@ -640,7 +653,7 @@ top:
*p = '\0';
break;
} else if (c == '\0') {
yyerror("syntax error");
yyerror("invalid syntax");
return findeol();
}
if (p + 1 >= buf + sizeof(buf) - 1) {