Commit 3c02e558 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

vcc: New function to print a series of tokens

The same pattern occurred 3 times while reviewing potential usage for the
new vcc_PeekToken*() functions.
parent 433b6b1d
...@@ -415,6 +415,8 @@ void vcc_Warn(struct vcc *); ...@@ -415,6 +415,8 @@ void vcc_Warn(struct vcc *);
void vcc__Expect(struct vcc *tl, unsigned tok, unsigned line); void vcc__Expect(struct vcc *tl, unsigned tok, unsigned line);
int vcc_IdIs(const struct token *t, const char *p); int vcc_IdIs(const struct token *t, const char *p);
void vcc_PrintTokens(struct vcc *tl, const struct token *tb,
const struct token *te);
void vcc_ExpectVid(struct vcc *tl, const char *what); void vcc_ExpectVid(struct vcc *tl, const char *what);
void vcc_Lexer(struct vcc *tl, struct source *sp); void vcc_Lexer(struct vcc *tl, struct source *sp);
void vcc_NextToken(struct vcc *tl); void vcc_NextToken(struct vcc *tl);
......
...@@ -318,8 +318,7 @@ VCC_SymbolGet(struct vcc *tl, vcc_ns_t ns, vcc_kind_t kind, ...@@ -318,8 +318,7 @@ VCC_SymbolGet(struct vcc *tl, vcc_ns_t ns, vcc_kind_t kind,
tl->t = VTAILQ_NEXT(tn, list); tl->t = VTAILQ_NEXT(tn, list);
if (sym == NULL) { if (sym == NULL) {
VSB_printf(tl->sb, "%s: '", e->name); VSB_printf(tl->sb, "%s: '", e->name);
for (tn1 = t0; tn1 != tl->t; tn1 = VTAILQ_NEXT(tn1, list)) vcc_PrintTokens(tl, t0, tl->t);
VSB_printf(tl->sb, "%.*s", PF(tn1));
VSB_cat(tl->sb, "'"); VSB_cat(tl->sb, "'");
sym = vcc_sym_in_tab(tl, st, kind, VCL_LOW, VCL_HIGH); sym = vcc_sym_in_tab(tl, st, kind, VCL_LOW, VCL_HIGH);
if (sym != NULL && sym->kind != SYM_OBJECT && if (sym != NULL && sym->kind != SYM_OBJECT &&
...@@ -338,8 +337,7 @@ VCC_SymbolGet(struct vcc *tl, vcc_ns_t ns, vcc_kind_t kind, ...@@ -338,8 +337,7 @@ VCC_SymbolGet(struct vcc *tl, vcc_ns_t ns, vcc_kind_t kind,
} }
if (kind != SYM_NONE && kind != sym->kind) { if (kind != SYM_NONE && kind != sym->kind) {
VSB_cat(tl->sb, "Symbol '"); VSB_cat(tl->sb, "Symbol '");
for (tn1 = t0; tn1 != tl->t; tn1 = VTAILQ_NEXT(tn1, list)) vcc_PrintTokens(tl, t0, tl->t);
VSB_printf(tl->sb, "%.*s", PF(tn1));
VSB_printf(tl->sb, "' has wrong type (%s), expected %s:", VSB_printf(tl->sb, "' has wrong type (%s), expected %s:",
sym->kind->name, kind->name); sym->kind->name, kind->name);
VSB_cat(tl->sb, "\nAt: "); VSB_cat(tl->sb, "\nAt: ");
......
...@@ -329,29 +329,45 @@ vcc_IdIs(const struct token *t, const char *p) ...@@ -329,29 +329,45 @@ vcc_IdIs(const struct token *t, const char *p)
* Check that we have a Varnish identifier * Check that we have a Varnish identifier
*/ */
void
vcc_PrintTokens(struct vcc *tl, const struct token *tb, const struct token *te)
{
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
AN(tb);
AN(te);
while (tb != te) {
VSB_printf(tl->sb, "%.*s", PF(tb));
tb = vcc_PeekTokenFrom(tl, tb);
AN(tb);
}
}
void void
vcc_ExpectVid(struct vcc *tl, const char *what) vcc_ExpectVid(struct vcc *tl, const char *what)
{ {
const char *bad = NULL; const char *bad = NULL;
struct token *t2, *t3; struct token *t2;
ExpectErr(tl, ID); ExpectErr(tl, ID);
ERRCHK(tl); ERRCHK(tl);
t2 = VTAILQ_NEXT(tl->t, list); t2 = vcc_PeekToken(tl);
ERRCHK(tl);
while (t2->tok == '.') { while (t2->tok == '.') {
bad = "."; bad = ".";
t2 = VTAILQ_NEXT(t2, list); t2 = vcc_PeekTokenFrom(tl, t2);
ERRCHK(tl);
if (t2->tok != ID) if (t2->tok != ID)
break; break;
t2 = VTAILQ_NEXT(t2, list); t2 = vcc_PeekTokenFrom(tl, t2);
ERRCHK(tl);
} }
if (bad == NULL) if (bad == NULL)
bad = VCT_invalid_name(tl->t->b, tl->t->e); bad = VCT_invalid_name(tl->t->b, tl->t->e);
if (bad != NULL) { if (bad != NULL) {
VSB_printf(tl->sb, "Name of %s, '", what); VSB_printf(tl->sb, "Name of %s, '", what);
for (t3 = tl->t; t3 != t2; t3 = VTAILQ_NEXT(t3, list)) vcc_PrintTokens(tl, tl->t, t2);
VSB_printf(tl->sb, "%.*s", PF(t3));
VSB_printf(tl->sb, VSB_printf(tl->sb,
"', contains illegal character '%c'\n", *bad); "', contains illegal character '%c'\n", *bad);
vcc_ErrWhere2(tl, tl->t, t2); vcc_ErrWhere2(tl, tl->t, t2);
......
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