Commit 433b6b1d authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

vcc: New functions to take a peek at tokens

Without advancing to the next token, and leaving the door open to
synthetic tokens that would otherwise interfere with direct access.
parent 3a214e62
...@@ -418,6 +418,8 @@ int vcc_IdIs(const struct token *t, const char *p); ...@@ -418,6 +418,8 @@ int vcc_IdIs(const struct token *t, const char *p);
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);
struct token * vcc_PeekToken(struct vcc *tl);
struct token * vcc_PeekTokenFrom(struct vcc *tl, const struct token *t);
void vcc__ErrInternal(struct vcc *tl, const char *func, void vcc__ErrInternal(struct vcc *tl, const char *func,
unsigned line); unsigned line);
......
...@@ -263,18 +263,37 @@ vcc_ErrWhere(struct vcc *tl, const struct token *t) ...@@ -263,18 +263,37 @@ vcc_ErrWhere(struct vcc *tl, const struct token *t)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
void struct token *
vcc_NextToken(struct vcc *tl) vcc_PeekTokenFrom(struct vcc *tl, const struct token *t)
{ {
struct token *tn;
tl->t = VTAILQ_NEXT(tl->t, list); CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
if (tl->t == NULL) { AN(t);
tn = VTAILQ_NEXT(t, list);
if (tn == NULL) {
VSB_cat(tl->sb, VSB_cat(tl->sb,
"Ran out of input, something is missing or" "Ran out of input, something is missing or"
" maybe unbalanced (...) or {...}\n"); " maybe unbalanced (...) or {...}\n");
tl->err = 1; tl->err = 1;
return;
} }
return (tn);
}
struct token *
vcc_PeekToken(struct vcc *tl)
{
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
return (vcc_PeekTokenFrom(tl, tl->t));
}
void
vcc_NextToken(struct vcc *tl)
{
CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
tl->t = vcc_PeekTokenFrom(tl, tl->t);
} }
void void
......
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