0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Birdtest: Add function format in grammar for stringify expression

This commit is contained in:
Pavel Tvrdik 2016-11-16 12:15:43 +01:00
parent bb721f0d6d
commit 4b135d0958
2 changed files with 17 additions and 1 deletions

View File

@ -406,7 +406,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
PREPEND, FIRST, LAST, LAST_NONAGGREGATED, MATCH, PREPEND, FIRST, LAST, LAST_NONAGGREGATED, MATCH,
EMPTY, EMPTY,
FILTER, WHERE, EVAL, FILTER, WHERE, EVAL,
BT_ASSERT, BT_TEST_SUITE) BT_ASSERT, BT_TEST_SUITE, FORMAT)
%nonassoc THEN %nonassoc THEN
%nonassoc ELSE %nonassoc ELSE
@ -916,6 +916,7 @@ term:
| ROA_CHECK '(' rtable ')' { $$ = f_generate_roa_check($3, NULL, NULL); } | ROA_CHECK '(' rtable ')' { $$ = f_generate_roa_check($3, NULL, NULL); }
| ROA_CHECK '(' rtable ',' term ',' term ')' { $$ = f_generate_roa_check($3, $5, $7); } | ROA_CHECK '(' rtable ',' term ',' term ')' { $$ = f_generate_roa_check($3, $5, $7); }
| FORMAT '(' term ')' { $$ = f_new_inst(); $$->code = P('f','m'); $$->a1.p = $3; }
/* | term '.' LEN { $$->code = P('P','l'); } */ /* | term '.' LEN { $$->code = P('P','l'); } */

View File

@ -563,6 +563,14 @@ f_rta_cow(void)
(*f_rte)->attrs = rta_do_cow((*f_rte)->attrs, f_pool); (*f_rte)->attrs = rta_do_cow((*f_rte)->attrs, f_pool);
} }
static char *
val_format_str(struct f_val v) {
buffer b;
LOG_BUFFER_INIT(b);
val_format(v, &b);
return lp_strdup(f_pool, b.start);
}
static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS; static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS;
#define runtime(fmt, ...) do { \ #define runtime(fmt, ...) do { \
@ -1477,6 +1485,13 @@ interpret(struct f_inst *what)
break; break;
case P('f','m'): /* Format */
ONEARG;
res.type = T_STRING;
res.val.s = val_format_str(v1);
break;
case P('a','s'): /* Birdtest Assert */ case P('a','s'): /* Birdtest Assert */
ONEARG; ONEARG;