From: Ondrej Zajicek Date: Fri, 9 May 2025 12:53:58 +0000 (+0200) Subject: Conf: Improve parsing of config datatypes X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=36b2092213347a00021c9ae04ad5ccc75baef947;p=thirdparty%2Fbird.git 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. --- 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