>From 9bf08b916f9b6148cf3b61d4a7b6b25fc3dc4add Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Fri, 23 Dec 2016 17:53:03 +0100 Subject: [nft PATCH] implement boolean as simple alias for relational EQ/NEQ 0 Signed-off-by: Phil Sutter --- src/parser_bison.y | 13 +++++++++++++ src/scanner.l | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/src/parser_bison.y b/src/parser_bison.y index deaaf06fa1c6c..438f3d81a8fbb 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -424,6 +424,9 @@ static void location_update(struct location *loc, struct location *rhs, int n) %token NOTRACK "notrack" +%token BOOLEAN_TRUE "boolean true" +%token BOOLEAN_FALSE "boolean false" + %type identifier type_identifier string comment_spec %destructor { xfree($$); } identifier type_identifier string comment_spec @@ -2298,6 +2301,16 @@ relational_expr : expr /* implicit */ rhs_expr { $$ = relational_expr_alloc(&@2, $2, $1, $4); } + | expr BOOLEAN_TRUE + { + $$ = relational_expr_alloc(&@$, OP_NEQ, $1, + symbol_expr_alloc(&@$, SYMBOL_VALUE, current_scope(state), "0")); + } + | expr BOOLEAN_FALSE + { + $$ = relational_expr_alloc(&@$, OP_EQ, $1, + symbol_expr_alloc(&@$, SYMBOL_VALUE, current_scope(state), "0")); + } ; list_rhs_expr : basic_rhs_expr COMMA basic_rhs_expr diff --git a/src/scanner.l b/src/scanner.l index 625023f5257c1..e34730a74fad4 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -475,6 +475,13 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "xml" { return XML; } "json" { return JSON; } +"true" { return BOOLEAN_TRUE; } +"false" { return BOOLEAN_FALSE; } +"yes" { return BOOLEAN_TRUE; } +"no" { return BOOLEAN_FALSE; } +"exists" { return BOOLEAN_TRUE; } +"missing" { return BOOLEAN_FALSE; } + {addrstring} { yylval->string = xstrdup(yytext); return STRING; -- 2.11.0