diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2022-12-13 19:31:46 +0100 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2023-08-25 23:50:44 +0200 |
commit | f5140d1027f514bc59d46ab8aa09181f5870afbd (patch) | |
tree | 0af416202ebde1828b3d0c2684061d600234142b /conf | |
parent | cce48c6cdd9484c606879ea76d4c633fce12ba36 (diff) |
Conf: Allow keywords to be redefined by user symbols
Most syntactic constructs in BIRD configuration (e.g. protocol options)
are defined as keywords, which are distinct from symbols (user-defined
names for protocols, variables, ...). That may cause backwards
compatibility issue when a new feature is added, as it may collide with
existing user names.
We can allow keywords to be shadowed by symbols in almost all cases to
avoid this issue.
This replaces the previous mechanism, where shadowable symbols have to be
explictly added to kw_syms.
Diffstat (limited to 'conf')
-rw-r--r-- | conf/confbase.Y | 3 | ||||
-rw-r--r-- | conf/gen_keywords.m4 | 1 | ||||
-rw-r--r-- | conf/gen_parser.m4 | 12 |
3 files changed, 13 insertions, 3 deletions
diff --git a/conf/confbase.Y b/conf/confbase.Y index a6b4b1ee..a43a8cca 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -119,7 +119,6 @@ CF_DECLS %type <t> text opttext %type <bs> bytestring %type <s> symbol -%type <kw> kw_sym %type <v> bytestring_text text_or_ipa %type <x> bytestring_expr @@ -178,7 +177,7 @@ expr_us: | expr US { $$ = $1 US_; } ; -symbol: CF_SYM_UNDEFINED | CF_SYM_KNOWN | kw_sym { $$ = cf_symbol_from_keyword($1); } ; +symbol: CF_SYM_UNDEFINED | CF_SYM_KNOWN | KEYWORD { $$ = cf_symbol_from_keyword($1); } ; /* Switches */ diff --git a/conf/gen_keywords.m4 b/conf/gen_keywords.m4 index 0c1dc545..3206c186 100644 --- a/conf/gen_keywords.m4 +++ b/conf/gen_keywords.m4 @@ -28,6 +28,7 @@ m4_divert(-1)') m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)CF_handle_kw($1)]])') m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token[[]]CF_toks )DNL') +m4_define(CF_KEYWORDS_EXCLUSIVE, `CF_KEYWORDS($@)') # CLI commands generate keywords as well m4_define(CF_CLI, `CF_KEYWORDS(m4_translit($1, [[ ]], [[,]])) diff --git a/conf/gen_parser.m4 b/conf/gen_parser.m4 index 7a2a9de4..a26af851 100644 --- a/conf/gen_parser.m4 +++ b/conf/gen_parser.m4 @@ -29,11 +29,17 @@ m4_define(CF_END, `m4_divert(-1)') m4_define(CF_itera, `m4_ifelse($#, 1, [[CF_iter($1)]], [[CF_iter($1)[[]]CF_itera(m4_shift($@))]])') m4_define(CF_iterate, `m4_define([[CF_iter]], m4_defn([[$1]]))CF_itera($2)') +m4_define(CF_append, `m4_define([[$1]], m4_ifdef([[$1]], m4_defn([[$1]])[[$3]])[[$2]])') + # Keywords act as %token<kw> -m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)m4_define([[CF_toks]],CF_toks $1)]])') +m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)CF_append([[CF_kw_rule]],$1,[[ | ]])m4_define([[CF_toks]],CF_toks $1)]])') m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token<kw>[[]]CF_toks )DNL') +m4_define(CF_keywd2, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)m4_define([[CF_toks]],CF_toks $1)]])') +m4_define(CF_KEYWORDS_EXCLUSIVE, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd2]], [[$@]])m4_ifelse(CF_toks,,,%token<kw>[[]]CF_toks +)DNL') + # CLI commands m4_define(CF_CLI, `m4_define([[CF_cmd]], cmd_[[]]m4_translit($1, [[ ]], _))DNL m4_divert(2)CF_KEYWORDS(m4_translit($1, [[ ]], [[,]])) @@ -55,7 +61,11 @@ m4_undivert(1)DNL m4_undivert(2)DNL +%type <kw> KEYWORD + %% +KEYWORD: CF_kw_rule; + m4_undivert(3)DNL %% |