[master] 433b6b1d1 vcc: New functions to take a peek at tokens

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Tue Jun 1 13:50:07 UTC 2021


commit 433b6b1d120415333bd78033119441c525ceeea5
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue May 25 11:05:07 2021 +0200

    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.

diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index c01e01094..a48d1a902 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -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_Lexer(struct vcc *tl, struct source *sp);
 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,
     unsigned line);
 
diff --git a/lib/libvcc/vcc_token.c b/lib/libvcc/vcc_token.c
index 35cc6421b..f8d14a86e 100644
--- a/lib/libvcc/vcc_token.c
+++ b/lib/libvcc/vcc_token.c
@@ -263,18 +263,37 @@ vcc_ErrWhere(struct vcc *tl, const struct token *t)
 
 /*--------------------------------------------------------------------*/
 
-void
-vcc_NextToken(struct vcc *tl)
+struct token *
+vcc_PeekTokenFrom(struct vcc *tl, const struct token *t)
 {
+	struct token *tn;
 
-	tl->t = VTAILQ_NEXT(tl->t, list);
-	if (tl->t == NULL) {
+	CHECK_OBJ_NOTNULL(tl, VCC_MAGIC);
+	AN(t);
+	tn = VTAILQ_NEXT(t, list);
+	if (tn == NULL) {
 		VSB_cat(tl->sb,
 		    "Ran out of input, something is missing or"
 		    " maybe unbalanced (...) or {...}\n");
 		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


More information about the varnish-commit mailing list