Revision 9b0a0ba9 filter/config.Y

View differences:

filter/config.Y
323 323
  return rv;
324 324
}
325 325

  
326
/*
327
 * Remove all new lines and doubled whitespaces
328
 * and convert all tabulators to spaces
329
 * and return a copy of string
330
 */
331
char *
332
assert_copy_expr(const char *start, size_t len)
333
{
334
  /* XXX: Allocates maybe a little more memory than we really finally need */
335
  char *str = cfg_alloc(len + 1);
336

  
337
  char *dst = str;
338
  const char *src = start - 1;
339
  const char *end = start + len;
340
  while (++src < end)
341
  {
342
    if (*src == '\n')
343
      continue;
344

  
345
    /* Skip doubled whitespaces */
346
    if (src != start)
347
    {
348
      const char *prev = src - 1;
349
      if ((*src == ' ' || *src == '\t') && (*prev == ' ' || *prev == '\t'))
350
	continue;
351
    }
352

  
353
    if (*src == '\t')
354
      *dst = ' ';
355
    else
356
      *dst = *src;
357

  
358
    dst++;
359
  }
360
  *dst = '\0';
361

  
362
  return str;
363
}
364

  
365
/*
366
 * assert_done - create f_instruction of bt_assert
367
 * @expr: expression in bt_assert()
368
 * @start: pointer to first char of test expression
369
 * @end: pointer to the last char of test expression
370
 */
371
static struct f_inst *
372
assert_done(struct f_inst *expr, const char *start, const char *end)
373
{
374
  struct f_inst *i;
375
  i = f_new_inst();
376
  i->code = P('a','s');
377
  i->a1.p = expr;
378

  
379
  if (end >= start)
380
  {
381
    i->a2.p = assert_copy_expr(start, end - start + 1);
382
  }
383
  else
384
  {
385
    /* this is a break of lexer buffer */
386
    i->a2.p = "???";
387
  }
326 388

  
389
  return i;
390
}
327 391

  
328 392
CF_DECLS
329 393

  
......
341 405
	ADD, DELETE, CONTAINS, RESET,
342 406
	PREPEND, FIRST, LAST, LAST_NONAGGREGATED, MATCH,
343 407
	EMPTY,
344
	FILTER, WHERE, EVAL)
408
	FILTER, WHERE, EVAL,
409
	BT_ASSERT, BT_TEST_SUITE)
345 410

  
346 411
%nonassoc THEN
347 412
%nonassoc ELSE
348 413

  
349
%type <x> term block cmds cmds_int cmd function_body constant constructor print_one print_list var_list var_listn dynamic_attr static_attr function_call symbol bgp_path_expr
414
%type <x> term block cmds cmds_int cmd function_body constant constructor print_one print_list var_list var_listn dynamic_attr static_attr function_call symbol bgp_path_expr bt_assert
350 415
%type <f> filter filter_body where_filter
351 416
%type <i> type break_command ec_kind
352 417
%type <i32> cnum
......
356 421
%type <px> fprefix
357 422
%type <s> decls declsn one_decl function_params
358 423
%type <h> bgp_path bgp_path_tail1 bgp_path_tail2
424
%type <t> get_cf_position
359 425

  
360 426
CF_GRAMMAR
361 427

  
......
375 441
   EVAL term { f_eval_int($2); }
376 442
 ;
377 443

  
444
CF_ADDTO(conf, bt_test_suite)
445
bt_test_suite:
446
 BT_TEST_SUITE '(' SYM ',' text ')' {
447
  if (!($3->class & SYM_FUNCTION))
448
    cf_error("Function expected");
449

  
450
  struct f_bt_test_suite *t = cfg_alloc(sizeof(struct f_bt_test_suite));
451
  t->fn = $3->def;
452
  t->fn_name = $3->name;
453
  t->dsc = $5;
454

  
455
  add_tail(&new_config->tests, &t->n);
456
 }
457
 ;
458

  
378 459
type:
379 460
   INT { $$ = T_INT; }
380 461
 | BOOL { $$ = T_BOOL; }
......
835 916
 | ROA_CHECK '(' rtable ')' { $$ = f_generate_roa_check($3, NULL, NULL); }
836 917
 | ROA_CHECK '(' rtable ',' term ',' term ')' { $$ = f_generate_roa_check($3, $5, $7); }
837 918

  
919
 | bt_assert { $$ = $1; }
920

  
838 921
/* | term '.' LEN { $$->code = P('P','l'); } */
839 922

  
840 923
/* function_call is inlined here */
......
966 1049
      $$->a1.p = $2;
967 1050
      $$->a2.p = build_tree( $4 );
968 1051
   }
1052
 | bt_assert ';' { $$ = $1; }
969 1053

  
970 1054

  
971 1055
 | rtadot dynamic_attr '.' EMPTY ';' { $$ = f_generate_empty($2); }
......
975 1059
 | rtadot dynamic_attr '.' FILTER '(' term ')' ';'    { $$ = f_generate_complex( P('C','a'), 'f', $2, $6 ); }
976 1060
 ;
977 1061

  
1062
 bt_assert:
1063
   BT_ASSERT '(' get_cf_position term get_cf_position ')' { $$ = assert_done($4, $3 + 1, $5 - 1); }
1064
 ;
1065

  
1066
get_cf_position:
1067
{
1068
  $$ = cf_text;
1069
};
1070

  
1071

  
978 1072
CF_END

Also available in: Unified diff