ECC-1860: Definition language: Add 'isnot' operator for strings

This commit is contained in:
shahramn 2024-07-04 15:54:59 +01:00
parent 7280121094
commit 53e202a2ee
9 changed files with 2083 additions and 2036 deletions

View File

@ -757,7 +757,7 @@ grib_expression* new_is_in_dict_expression(grib_context* c, const char* name, co
grib_expression* new_true_expression(grib_context* c);
/* grib_expression_class_string_compare.cc */
grib_expression* new_string_compare_expression(grib_context* c, grib_expression* left, grib_expression* right);
grib_expression* new_string_compare_expression(grib_context* c, grib_expression* left, grib_expression* right, int eq);
/* grib_expression_class_unop.cc */
grib_expression* new_unop_expression(grib_context* c, grib_unop_long_proc long_func, grib_unop_double_proc double_func, grib_expression* exp);

View File

@ -22,7 +22,8 @@
IMPLEMENTS = print
IMPLEMENTS = add_dependency
MEMBERS = grib_expression *left
MEMBERS = grib_expression *right
MEMBERS = grib_expression *right
MEMBERS = int eq
END_CLASS_DEF
*/
@ -50,6 +51,7 @@ typedef struct grib_expression_string_compare{
/* Members defined in string_compare */
grib_expression *left;
grib_expression *right;
int eq;
} grib_expression_string_compare;
@ -110,7 +112,11 @@ static int evaluate_long(grib_expression* g, grib_handle* h, long* lres)
return ret;
}
*lres = (grib_inline_strcmp(v1, v2) == 0);
if (e->eq) // IS operator
*lres = (grib_inline_strcmp(v1, v2) == 0);
else // ISNOT operator
*lres = (grib_inline_strcmp(v1, v2) != 0);
return GRIB_SUCCESS;
}
@ -147,12 +153,13 @@ static void add_dependency(grib_expression* g, grib_accessor* observer)
}
grib_expression* new_string_compare_expression(grib_context* c,
grib_expression* left, grib_expression* right)
grib_expression* left, grib_expression* right, int eq)
{
grib_expression_string_compare* e = (grib_expression_string_compare*)grib_context_malloc_clear_persistent(c, sizeof(grib_expression_string_compare));
e->base.cclass = grib_expression_class_string_compare;
e->left = left;
e->right = right;
e->base.cclass = grib_expression_class_string_compare;
e->left = left;
e->right = right;
e->eq = eq;
return (grib_expression*)e;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -174,10 +174,11 @@ extern int grib_yydebug;
OR = 375, /* OR */
NOT = 376, /* NOT */
IS = 377, /* IS */
IDENT = 378, /* IDENT */
STRING = 379, /* STRING */
INTEGER = 380, /* INTEGER */
FLOAT = 381 /* FLOAT */
ISNOT = 378, /* ISNOT */
IDENT = 379, /* IDENT */
STRING = 380, /* STRING */
INTEGER = 381, /* INTEGER */
FLOAT = 382 /* FLOAT */
};
typedef enum grib_yytokentype grib_yytoken_kind_t;
#endif
@ -306,10 +307,11 @@ extern int grib_yydebug;
#define OR 375
#define NOT 376
#define IS 377
#define IDENT 378
#define STRING 379
#define INTEGER 380
#define FLOAT 381
#define ISNOT 378
#define IDENT 379
#define STRING 380
#define INTEGER 381
#define FLOAT 382
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
@ -333,7 +335,7 @@ union YYSTYPE
grib_rule *rules;
grib_rule_entry *rule_entry;
#line 337 "y.tab.h"
#line 339 "y.tab.h"
};
typedef union YYSTYPE YYSTYPE;

View File

@ -71,23 +71,24 @@ IDENT {IDENT1}|{IDENT2}|{IDENT3}|{IDENT4}|{IDENT5}
%%
"==" return EQ ;
">=" return GE ;
">" return GT ;
"<=" return LE ;
"<" return LT ;
"!=" return NE ;
"<>" return NE ;
"bit" return BIT ;
"notbit" return BITOFF ;
"==" return EQ ;
">=" return GE ;
">" return GT ;
"<=" return LE ;
"<" return LT ;
"!=" return NE ;
"<>" return NE ;
"bit" return BIT ;
"notbit" return BITOFF ;
"is" return IS ;
"not" return NOT ;
"!" return NOT ;
"and" return AND ;
"&&" return AND ;
"or" return OR ;
"||" return OR ;
"isnot" return ISNOT ;
"not" return NOT ;
"!" return NOT ;
"and" return AND ;
"&&" return AND ;
"or" return OR ;
"||" return OR ;
"null" return NIL ;
"~" return DUMMY ;
@ -97,7 +98,7 @@ IDENT {IDENT1}|{IDENT2}|{IDENT3}|{IDENT4}|{IDENT5}
"length" return LENGTH ;
"lowercase" return LOWERCASE;
"if" return IF ;
"_if" return IF_TRANSIENT ;
"_if" return IF_TRANSIENT ;
"else" return ELSE ;
"unsigned" return UNSIGNED ;
"ascii" return ASCII ;

View File

@ -191,6 +191,7 @@ static grib_hash_array_value *_reverse_hash_array(grib_hash_array_value *r,grib_
%token NOT
%token IS
%token ISNOT
%token <str>IDENT
%token <str>STRING
@ -819,7 +820,8 @@ condition: condition GT term { $$ = new_binop_expression(grib_parser_context,
| condition GE term { $$ = new_binop_expression(grib_parser_context,&grib_op_ge,&grib_op_ge_d,$1,$3); }
| condition LE term { $$ = new_binop_expression(grib_parser_context,&grib_op_le,&grib_op_le_d,$1,$3); }
| condition NE term { $$ = new_binop_expression(grib_parser_context,&grib_op_ne,&grib_op_ne_d,$1,$3); }
| string_or_ident IS string_or_ident { $$ = new_string_compare_expression(grib_parser_context,$1,$3); }
| string_or_ident IS string_or_ident { $$ = new_string_compare_expression(grib_parser_context,$1,$3,1); }
| string_or_ident ISNOT string_or_ident { $$ = new_string_compare_expression(grib_parser_context,$1,$3,0); }
/*
| condition IN term { $$ = new_binop_expression(grib_parser_context,grib_op_pow,$1,$3); }
| condition MATCH term { $$ = new_binop_expression(grib_parser_context,grib_op_pow,$1,$3); }

View File

@ -2,6 +2,8 @@ set -xe
export LEX=flex
export LEX_OUT=gribl.cc
$LEX -o gribl.cc gribl.l
sed 's/yy/grib_yy/g' < $LEX_OUT | sed 's/static void grib_yyunput/void grib_yyunput/' > grib_lex1.cc
sed 's/fgetc/getc/g' < grib_lex1.cc > grib_lex.cc
@ -18,11 +20,16 @@ sed 's/yy/grib_yy/g' < y.tab.h > grib_yacc.h
rm -f y.tab.c y.tab.h
set +x
$LEX --version
yacc --version
echo "---------------------------------------------"
# We use flex and bison
echo "Did you use the latest YACC and FLEX modules?"
echo " module avail bison"
echo " module avail flex"
echo
echo ALL OK

View File

@ -385,7 +385,11 @@ grep "MISSING" $tempOut
cat >$tempFilt <<EOF
if (rubbish is "ppp") { print "yes"; } else { print "rubbish must fail"; }
if ("ppp" is garbage) { print "yes"; } else { print "garbage must fail"; }
assert ( identifier isnot "rubbish" );
assert ( "a" isnot "A" );
assert ( identifier is "GRIB" );
EOF
cat $tempFilt
${tools_dir}/grib_filter $tempFilt $ECCODES_SAMPLES_PATH/GRIB2.tmpl > $tempOut 2>&1
cat $tempOut
grep "rubbish must fail" $tempOut