Commit baa7e69d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Improve the error messages for 'vcl N.N;'

Some specialcasing is warranted to get sensible messages.

Fixes #2532
parent 79ed4fce
......@@ -15,3 +15,13 @@ varnish v1 -syntax 4.0 -errvcl "9.9 higher than the top level version" {
vcl 9.9;
backend b1 { .host = "127.0.0.1:8080"; }
}
varnish v1 -cliexpect {Don't play silly buggers with VCL version numbers} \
{vcl.inline t0 "vcl 4.00 ; backend b { .host = \"localhost\";} "}
varnish v1 -cliexpect {Don't play silly buggers with VCL version numbers} \
{vcl.inline t1 "vcl 04.0 ; backend b { .host = \"localhost\";} "}
varnish v1 -cliexpect {Expected 'vcl N.N;' found no semi-colon} \
{vcl.inline t2 "vcl 4.0 backend b { .host = \"localhost\";} "}
......@@ -310,7 +310,6 @@ void Resolve_Sockaddr(struct vcc *tl, const char *host, const char *defport,
double vcc_TimeUnit(struct vcc *);
void vcc_ByteVal(struct vcc *, double *);
void vcc_NumVal(struct vcc *, double *, int *);
double vcc_DoubleVal(struct vcc *tl);
void vcc_Duration(struct vcc *tl, double *);
unsigned vcc_UintVal(struct vcc *tl);
......
......@@ -274,29 +274,50 @@ vcc_ParseFunction(struct vcc *tl)
static void
vcc_ParseVcl(struct vcc *tl)
{
struct token *tok;
struct token *tok0, *tok1, *tok2;
assert(vcc_IdIs(tl->t, "vcl"));
tok0 = tl->t;
vcc_NextToken(tl);
tok = tl->t;
tok->src->syntax = vcc_DoubleVal(tl);
ERRCHK(tl);
if (tl->t->e - tok->b > 4) {
tok1 = tl->t;
Expect(tl, CNUM);
tok1->src->syntax = *tl->t->b - '0';
vcc_NextToken(tl);
Expect(tl, '.');
vcc_NextToken(tl);
Expect(tl, CNUM);
tok2 = tl->t;
tok1->src->syntax += .1 * (*tl->t->b - '0');
vcc_NextToken(tl);
if (tok1->e - tok1->b != 1 || tok2->e - tok2->b != 1) {
VSB_printf(tl->sb,
"Don't play silly buggers with VCL version numbers\n");
vcc_ErrWhere2(tl, tok, tl->t);
vcc_ErrWhere2(tl, tok0, tl->t);
ERRCHK(tl);
}
if (tl->t->tok != ';') {
/* Special handling, because next token might be 'vcl'
* in the built-in VCL, and that would give a very
* confusing error message
*/
VSB_printf(tl->sb,
"Expected 'vcl N.N;' found no semi-colon\n");
vcc_ErrWhere2(tl, tok0, tl->t);
ERRCHK(tl);
}
if (tl->syntax != 0.0 && tok->src->syntax > tl->syntax) {
vcc_NextToken(tl);
if (tl->syntax != 0.0 && tok1->src->syntax > tl->syntax) {
VSB_printf(tl->sb,
"VCL version %.1f higher than"
" the top level version %.1f\n",
tok->src->syntax, tl->syntax);
vcc_ErrWhere2(tl, tok, tl->t);
tok1->src->syntax, tl->syntax);
vcc_ErrWhere2(tl, tok0, tl->t);
ERRCHK(tl);
}
ExpectErr(tl, ';');
vcc_NextToken(tl);
}
/*--------------------------------------------------------------------
......
......@@ -344,7 +344,7 @@ vcc_NumVal(struct vcc *tl, double *d, int *frac)
vcc_NextToken(tl);
}
double
static double
vcc_DoubleVal(struct vcc *tl)
{
double d;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment