Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
filter-expr-parser: move operators to have dedicated tokens at the le…
Browse files Browse the repository at this point in the history
…xer level

Previously everything was captured as LL_IDENTIFIER, operators as well,
and then mapped to tokens using the keyword mechanism. Since I'd like
to make the LL_IDENTIFIER pattern stricter, that wouldn't allow
typical operator characters into LL_IDENTIFIERS, so these should be
recognized at the lexer level.

NOTE: this does not include the spelled out operators like "lt" for "<",
those remain LL_IDENTIFIER and are continued to be mapped using the
keyword mechanism.

Signed-off-by: Balazs Scheidler <[email protected]>
  • Loading branch information
bazsi authored and MrAnno committed Jan 9, 2024
1 parent 1a5313b commit eaa8a42
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
10 changes: 10 additions & 0 deletions lib/cfg-grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@
/* this is a placeholder for unit tests, must be the latest & largest */
%token LL_CONTEXT_MAX 23

/* operators in the filter language, the order of this determines precedence */
%right KW_ASSIGN 9000
%left KW_OR 9001
%left KW_AND 9002
%left KW_STR_EQ 9003 KW_STR_NE 9004, KW_TA_EQ 9005, KW_TA_NE 9006, KW_TAV_EQ 9007, KW_TAV_NE 9008
%left KW_STR_LT 9009, KW_STR_LE 9010, KW_STR_GE, 9011 KW_STR_GT, 9012, KW_TA_LT 9013, KW_TA_LE 9014, KW_TA_GE 9015, KW_TA_GT 9016

%left '+' '-'
%left '*' '/'
%left '.' KW_NOT 9017

/* statements */
%token KW_SOURCE 10000
Expand Down
9 changes: 9 additions & 0 deletions lib/cfg-lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ word [^ \#'"\(\)\{\}\[\]\\;\r\n\t,|\.@:]
<INITIAL,filterx>\.\. { return LL_DOTDOT; }
<INITIAL,filterx>\.\.\. { return LL_DOTDOTDOT; }
<INITIAL,filterx>=> { return LL_ARROW; }
<INITIAL,filterx>< { return KW_TA_LT; }
<INITIAL,filterx><= { return KW_TA_LE; }
<INITIAL,filterx>== { return KW_TA_EQ; }
<INITIAL,filterx>!= { return KW_TA_NE; }
<INITIAL,filterx>>= { return KW_TA_GE; }
<INITIAL,filterx>> { return KW_TA_GT; }
<INITIAL,filterx>=== { return KW_TAV_EQ; }
<INITIAL,filterx>!== { return KW_TAV_NE; }
<INITIAL,filterx>(-|\+)?{digit}+\.{digit}+ { yylval->fnum = strtod(yytext, NULL); return LL_FLOAT; }
<INITIAL,filterx>0x{xdigit}+ {
if (!parse_int64_base16(yytext, &yylval->num))
Expand Down
6 changes: 0 additions & 6 deletions lib/filter/filter-expr-grammar.ym
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ _translate_number_literals(CfgLexer *lexer, gint compare_mode, LogTemplate *expr
%token KW_IN_LIST

%left ';'
%left KW_OR
%left KW_AND
%left KW_NOT
%left KW_STR_LT KW_STR_LE KW_STR_EQ KW_STR_NE KW_STR_GE KW_STR_GT
%left KW_TA_LT KW_TA_LE KW_TA_EQ KW_TA_NE KW_TA_GE KW_TA_GT
%left KW_TAV_EQ KW_TAV_NE

%type <node> filter_expr
%type <node> filter_simple_expr
Expand Down
12 changes: 0 additions & 12 deletions lib/filter/filter-expr-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,6 @@ static CfgLexerKeyword filter_expr_keywords[] =
{ "ge", KW_STR_GE },
{ "gt", KW_STR_GT },

/* type aware comparisons */
{ "<", KW_TA_LT },
{ "<=", KW_TA_LE },
{ "==", KW_TA_EQ },
{ "!=", KW_TA_NE },
{ ">=", KW_TA_GE },
{ ">", KW_TA_GT },

/* equal type and value */
{ "===", KW_TAV_EQ },
{ "!==", KW_TAV_NE },

/* filter expressions */
{ "severity", KW_SEVERITY },
{ "level", KW_SEVERITY },
Expand Down

0 comments on commit eaa8a42

Please sign in to comment.