1 /****************************************************************************
3 ** Copyright (c) 2020 SoftAtHome
5 ** Redistribution and use in source and binary forms, with or
6 ** without modification, are permitted provided that the following
9 ** 1. Redistributions of source code must retain the above copyright
10 ** notice, this list of conditions and the following disclaimer.
12 ** 2. Redistributions in binary form must reproduce the above
13 ** copyright notice, this list of conditions and the following
14 ** disclaimer in the documentation and/or other materials provided
15 ** with the distribution.
17 ** Subject to the terms and conditions of this license, each
18 ** copyright holder and contributor hereby grants to those receiving
19 ** rights under this license a perpetual, worldwide, non-exclusive,
20 ** no-charge, royalty-free, irrevocable (except for failure to
21 ** satisfy the conditions of this license) patent license to make,
22 ** have made, use, offer to sell, sell, import, and otherwise
23 ** transfer this software, where such license applies only to those
24 ** patent claims, already acquired or hereafter acquired, licensable
25 ** by such copyright holder or contributor that are necessarily
28 ** (a) their Contribution(s) (the licensed copyrights of copyright
29 ** holders and non-copyrightable additions of contributors, in
30 ** source or binary form) alone; or
32 ** (b) combination of their Contribution(s) with the work of
33 ** authorship to which such Contribution(s) was added by such
34 ** copyright holder or contributor, if, at the time the Contribution
35 ** is added, such addition causes such combination to be necessarily
36 ** infringed. The patent license shall not apply to any other
37 ** combinations which include the Contribution.
39 ** Except as expressly stated above, no rights or licenses from any
40 ** copyright holder or contributor is granted under this license,
41 ** whether expressly, by implication, estoppel or otherwise.
45 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
46 ** CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
47 ** INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
48 ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
49 ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
50 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
53 ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
54 ** AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
56 ** ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57 ** POSSIBILITY OF SUCH DAMAGE.
59 ****************************************************************************/
60 %option reentrant bison-bridge
61 %option never-interactive
65 %option bison-locations
72 #include <sys/types.h>
75 #include <amxc/amxc.h>
77 #include "amxp_expr_priv.h"
78 #include "amxp_expr.tab.h"
80 #if __SIZE_WIDTH__ == 64
81 #define ssize_t_abs(x) labs(x)
83 #define ssize_t_abs(x) abs(x)
86 #define YY_EXTRA_TYPE amxp_expr_t*
87 #define YY_INPUT(buf,result,max_size) { \
88 ssize_t read_result = 0; \
89 read_result = yyextra->reader(yyextra, buf, max_size); \
90 if (read_result == -1) { \
91 YY_FATAL_ERROR( "input in flex scanner failed" ); \
93 result = read_result > 0? ssize_t_abs(read_result):0; \
97 (YYSTYPE * yylval_param , YYLTYPE* yylloc_param, yyscan_t yyscanner);
99 #define UNUSED __attribute__((unused))
100 #define YY_DECL int yylex \
101 (YYSTYPE * yylval_param , UNUSED YYLTYPE* yylloc_param, yyscan_t yyscanner)
104 %x MULTI_LINE_COMMENT SINGLE_LINE_COMMENT LONG_TEXT LONG_TEXT_SQ FIELD_PATH
110 "/*" { BEGIN( MULTI_LINE_COMMENT ); }
111 <MULTI_LINE_COMMENT>{
113 [^*\n]+ { yymore(); }
114 [^*\n]*{NEWLINE} { yymore(); }
115 "*/" { yylval->cptr.txt = yytext;
116 yylval->cptr.length = yyleng - 2;
121 "//" { BEGIN( SINGLE_LINE_COMMENT ); }
122 <SINGLE_LINE_COMMENT>{NEWLINE} { BEGIN(INITIAL); }
123 <SINGLE_LINE_COMMENT>"*" { }
124 <SINGLE_LINE_COMMENT>[^*\n]+ { }
126 "'" { BEGIN(LONG_TEXT_SQ); }
129 {NEWLINE} { yymore(); }
130 [^\\']+ { yymore(); }
132 "'" { yylval->cptr.txt = yytext;
133 yylval->cptr.length = yyleng - 1;
141 "\"" { BEGIN(LONG_TEXT); }
144 {NEWLINE} { yymore(); }
145 [^\\"]+ { yymore(); }
147 "\"" { yylval->cptr.txt = yytext;
148 yylval->cptr.length = yyleng - 1;
155 "{" { BEGIN(FIELD_PATH); }
158 "}" { yylval->cptr.txt = yytext;
159 yylval->cptr.length = yyleng - 1;
169 <<EOF>> { yylval->integer = token_eof;
176 "&&" { return LAND; }
181 "==" { yylval->comp = amxp_expr_comp_equal;
184 "!=" { yylval->comp = amxp_expr_comp_not_equal;
187 "<" { yylval->comp = amxp_expr_comp_lesser;
190 ">" { yylval->comp = amxp_expr_comp_bigger;
193 "<=" { yylval->comp = amxp_expr_comp_lesser_equal;
196 ">=" { yylval->comp = amxp_expr_comp_bigger_equal;
199 matches { yylval->comp = amxp_expr_comp_matches;
202 starts[ \t]{1,}with { yylval->comp = amxp_expr_comp_starts_with;
205 ends[ \t]{1,}with { yylval->comp = amxp_expr_comp_ends_with;
208 in { yylval->comp = amxp_expr_comp_in;
211 "~=" { yylval->comp = amxp_expr_comp_contains;
214 "^=" { yylval->comp = amxp_expr_comp_equals_ignorecase;
217 (?i:true) { yylval->boolean = true;
220 (?i:false) { yylval->boolean = false;
224 [[:digit:]]+ { char *endptr = NULL;
225 yylval->integer = strtoll(yytext, &endptr, 0);
228 -[[:digit:]]+ { char *endptr = NULL;
229 yylval->integer = strtoll(yytext, &endptr, 0);
233 [a-zA-Z0-9\-_@]+ { yylval->cptr.txt = yytext;
234 yylval->cptr.length = yyleng;
238 \n|. { return yytext[0]; }
242 void amxp_expr_create_lex(amxp_expr_t *expr) {
243 yylex_init(&expr->scanner);
244 yyset_extra(expr, expr->scanner);
247 void amxp_expr_destroy_lex(amxp_expr_t *expr) {
248 yylex_destroy(expr->scanner);