]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Add hex:XYZ syntax for short hex strings
authorAlexander Zubkov <green@qrator.net>
Fri, 23 Jun 2023 14:47:37 +0000 (16:47 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Fri, 23 Jun 2023 14:47:37 +0000 (16:47 +0200)
Hexadecimal bytestring literals have minimal length to not collide
with IP addresses or regular (hexadecimal) number literals.

Allow to use shorter literals with explicit hex: prefix.

conf/cf-lex.l

index 9555949d430546bce549ec436d86928f7d07905d..9025a84d8259e8c244ef5e693c8d449c5d27cdcc 100644 (file)
@@ -255,12 +255,17 @@ WHITE [ \t]
   return IP4;
 }
 
-{XIGIT}{2}((:{XIGIT}{2}){15,}|({XIGIT}{2}){15,}) {
-  char *s = yytext;
+({XIGIT}{2}){16,}|{XIGIT}{2}(:{XIGIT}{2}){15,}|hex:({XIGIT}{2}(:?{XIGIT}{2})*)? {
+  char *s, *sb = yytext;
   size_t len = 0, i;
   struct bytestring *bytes;
   byte *b;
 
+  /* skip 'hex:' prefix */
+  if (sb[0] == 'h' && sb[1] == 'e' && sb[2] == 'x' && sb[3] == ':')
+    sb += 4;
+
+  s = sb;
   while (*s) {
     len++;
     s += 2;
@@ -271,7 +276,7 @@ WHITE [ \t]
 
   bytes->length = len;
   b = &bytes->data[0];
-  s = yytext;
+  s = sb;
   errno = 0;
   for (i = 0; i < len; i++) {
     *b = bstrtobyte16(s);