aboutsummaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authorAnna “CyberTailor” <cyber@sysrq.in>2021-07-13 16:30:54 +0500
committerOmar Polo <op@omarpolo.com>2021-07-13 13:38:42 +0200
commitf3966209e5941ee3139425c5e375d373c1026923 (patch)
treeab6d6ecc6d5eb5fa42fd1a45527deaec6a24f322 /parse.y
parenta556718a24d003523b7fb0406061e7f89291b14e (diff)
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".
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y33
1 files changed, 23 insertions, 10 deletions
diff --git a/parse.y b/parse.y
index 35a918a..bf95d40 100644
--- a/parse.y
+++ b/parse.y
@@ -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) {