[master] 56f7ff4 New character types for identifiers and variables
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Tue Jun 27 12:03:06 CEST 2017
commit 56f7ff4d67ab9b58206f98888a8da4e08aaee051
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Jun 27 11:26:24 2017 +0200
New character types for identifiers and variables
The name are borrowed from libvcc.
Refs #2354
diff --git a/include/vct.h b/include/vct.h
index 86b30cf..2893e6b 100644
--- a/include/vct.h
+++ b/include/vct.h
@@ -41,6 +41,8 @@
#define VCT_XMLNAMESTART (1<<7)
#define VCT_XMLNAME (1<<8)
#define VCT_TCHAR (1<<9)
+#define VCT_NAME (1<<10)
+#define VCT_VAR (1<<11)
extern const uint16_t vct_typtab[256];
@@ -62,6 +64,9 @@ vct_is(int x, uint16_t y)
#define vct_isalpha(x) vct_is(x, VCT_ALPHA)
#define vct_issep(x) vct_is(x, VCT_SEPARATOR)
#define vct_issepctl(x) vct_is(x, VCT_SEPARATOR | VCT_CTL)
+#define vct_isident1(x) vct_isalpha(x)
+#define vct_isident(x) vct_is(x, VCT_ALPHA | VCT_DIGIT | VCT_NAME)
+#define vct_isvar(x) vct_is(x, VCT_ALPHA | VCT_DIGIT | VCT_NAME | VCT_VAR)
#define vct_isxmlnamestart(x) vct_is(x, VCT_XMLNAMESTART)
#define vct_isxmlname(x) vct_is(x, VCT_XMLNAMESTART | VCT_XMLNAME)
#define vct_istchar(x) vct_is(x, VCT_ALPHA | VCT_DIGIT | VCT_TCHAR)
diff --git a/lib/libvarnish/vct.c b/lib/libvarnish/vct.c
index 5610566..7d82dd3 100644
--- a/lib/libvarnish/vct.c
+++ b/lib/libvarnish/vct.c
@@ -88,8 +88,8 @@ const uint16_t vct_typtab[256] = {
[0x2a] = VCT_TCHAR,
[0x2b] = VCT_TCHAR,
[0x2c] = VCT_SEPARATOR,
- [0x2d] = VCT_XMLNAME | VCT_TCHAR,
- [0x2e] = VCT_XMLNAME | VCT_TCHAR,
+ [0x2d] = VCT_XMLNAME | VCT_TCHAR | VCT_NAME,
+ [0x2e] = VCT_XMLNAME | VCT_TCHAR | VCT_VAR,
[0x2f] = VCT_SEPARATOR,
[0x30] = VCT_DIGIT | VCT_HEX | VCT_XMLNAME,
[0x31] = VCT_DIGIT | VCT_HEX | VCT_XMLNAME,
@@ -138,7 +138,7 @@ const uint16_t vct_typtab[256] = {
[0x5c] = VCT_SEPARATOR,
[0x5d] = VCT_SEPARATOR,
[0x5e] = VCT_TCHAR,
- [0x5f] = VCT_XMLNAMESTART | VCT_TCHAR,
+ [0x5f] = VCT_XMLNAMESTART | VCT_TCHAR | VCT_NAME,
[0x60] = VCT_TCHAR,
[0x61] = VCT_LOALPHA | VCT_HEX | VCT_XMLNAMESTART,
[0x62] = VCT_LOALPHA | VCT_HEX | VCT_XMLNAMESTART,
@@ -245,14 +245,11 @@ VCT_invalid_name(const char *b, const char *e)
e = strchr(b, '\0');
assert(b < e);
- if (!vct_isalpha(*b))
+ if (!vct_isident1(*b))
return (b);
for (; b < e; b++)
- if (!vct_isalpha(*b) &&
- !vct_isdigit(*b) &&
- *b != '_' &&
- *b != '-')
+ if (!vct_isident(*b))
return (b);
return (NULL);
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 5de8a2a..2ab1a66 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -49,9 +49,6 @@ struct vsb;
struct token;
struct sockaddr_storage;
-#define isident1(c) (isalpha(c))
-#define isident(c) (isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-')
-#define isvar(c) (isident(c) || (c) == '.')
unsigned vcl_fixed_token(const char *p, const char **q);
extern const char * const vcl_tnames[256];
void vcl_output_lang_h(struct vsb *sb);
diff --git a/lib/libvcc/vcc_token.c b/lib/libvcc/vcc_token.c
index 3113722..c38ea32 100644
--- a/lib/libvcc/vcc_token.c
+++ b/lib/libvcc/vcc_token.c
@@ -36,6 +36,8 @@
#include "vcc_compile.h"
+#include "vct.h"
+
/*--------------------------------------------------------------------*/
void
@@ -300,6 +302,7 @@ vcc_ExpectCid(struct vcc *tl, const char *what)
ExpectErr(tl, ID);
ERRCHK(tl);
+ /* XXX: too soon to use vct_invalid_name() */
for (q = tl->t->b; q < tl->t->e; q++) {
if (!isalnum(*q) && *q != '_') {
VSB_printf(tl->sb, "Name of %s, ", what);
@@ -488,9 +491,9 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
}
/* Match Identifiers */
- if (isident1(*p)) {
+ if (vct_isident1(*p)) {
for (q = p; q < sp->e; q++)
- if (!isvar(*q))
+ if (!vct_isvar(*q))
break;
vcc_AddToken(tl, ID, p, q);
p = q;
More information about the varnish-commit
mailing list