From 36b2092213347a00021c9ae04ad5ccc75baef947 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Fri, 9 May 2025 14:53:58 +0200 Subject: [PATCH] Conf: Improve parsing of config datatypes Parser rules for configuration datatypes were inconsistent about whether they accept literals, constants, or expressions. We should accept each of these three everywhere. The patch also simplifies the grammar, makes it more uniform, and adds some documentation about that. --- conf/confbase.Y | 216 +++++++++++++++++++++++++++++---------------- doc/bird.sgml | 6 ++ nest/config.Y | 19 +--- proto/bgp/config.Y | 4 +- 4 files changed, 151 insertions(+), 94 deletions(-) diff --git a/conf/confbase.Y b/conf/confbase.Y index 857689707..b1d0625f1 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -51,6 +51,31 @@ static inline void cf_assert_symbol(const struct symbol *sym, uint class) { } } +static inline const char * +cf_type_name(enum f_type type) +{ + /* There is already f_type_name(), but this uses names more suited + to configuration error messages */ + switch (type) + { + case T_INT: return "Number"; + case T_BOOL: return "Boolean"; + case T_IP: return "IP address"; + case T_NET: return "Network"; + case T_STRING: return "String"; + case T_BYTESTRING: return "Bytestring"; + default: return "???"; + } +} + +static inline void +cf_assert_type(const struct f_val val, enum f_type type) +{ + if (val.type != type) + cf_error("%s expected", cf_type_name(type)); +} + + CF_DECLS %union { @@ -117,6 +142,7 @@ CF_DECLS %type ipa_scope %type expr bool pxlen4 +%type idval %type