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
69 #include "amxo_parser_priv.h"
70 #include "amxo_parser_hooks_priv.h"
71 #include "amxo_parser.tab.h"
73 #if __SIZE_WIDTH__ == 64
74 #define ssize_t_abs(x) labs(x)
76 #define ssize_t_abs(x) abs(x)
79 #define YY_EXTRA_TYPE amxo_parser_t*
80 #define YY_INPUT(buf,result,max_size) { \
81 ssize_t read_result = 0; \
82 read_result = yyextra->reader(yyextra, buf, max_size); \
83 if (read_result == -1) { \
84 YY_FATAL_ERROR( "input in flex scanner failed" ); \
86 result = read_result > 0? ssize_t_abs(read_result):0; \
90 (YYSTYPE * yylval_param , YYLTYPE* yylloc_param, yyscan_t yyscanner);
92 #define UNUSED __attribute__((unused))
93 #define YY_DECL int yylex \
94 (YYSTYPE * yylval_param , UNUSED YYLTYPE* yylloc_param, yyscan_t yyscanner)
100 #define YY_USER_ACTION { \
101 yylloc->first_line = yylineno; \
102 yyextra->line = yylineno; \
106 %x MULTI_LINE_COMMENT SINGLE_LINE_COMMENT LONG_TEXT LONG_TEXT_SQ FUNC_RESOLVER
112 "/*" { BEGIN( MULTI_LINE_COMMENT ); }
113 <MULTI_LINE_COMMENT>{
115 [^*\n]+ { yymore(); }
116 [^*\n]*{NEWLINE} { yymore(); }
117 "*/" { yylval->cptr.txt = yytext;
118 yylval->cptr.length = yyleng - 2;
119 amxo_hooks_comment(yyextra, yylval->cptr.txt, yylval->cptr.length);
124 "#" { BEGIN( SINGLE_LINE_COMMENT ); }
125 "//" { BEGIN( SINGLE_LINE_COMMENT ); }
126 <SINGLE_LINE_COMMENT>{NEWLINE} { BEGIN(INITIAL); }
127 <SINGLE_LINE_COMMENT>"*" { }
128 <SINGLE_LINE_COMMENT>[^*\n]+ { yylval->cptr.txt = yytext;
129 yylval->cptr.length = yyleng;
130 amxo_hooks_comment(yyextra, yylval->cptr.txt, yylval->cptr.length);
133 "'" { BEGIN(LONG_TEXT_SQ); }
136 {NEWLINE} { yymore(); }
137 [^\\']+ { yymore(); }
139 "'" { yylval->cptr.txt = yytext;
140 yylval->cptr.length = yyleng - 1;
148 "\"" { BEGIN(LONG_TEXT); }
151 {NEWLINE} { yymore(); }
152 [^\\"]+ { yymore(); }
154 "\"" { yylval->cptr.txt = yytext;
155 yylval->cptr.length = yyleng - 1;
162 "<!" { BEGIN( FUNC_RESOLVER ); }
164 {NEWLINE} { yymore(); }
165 "!>" { if (yyleng - 2 == 0) {
166 yylval->cptr.txt = NULL;
167 yylval->cptr.length = 0;
169 yylval->cptr.txt = yytext;
170 yylval->cptr.length = yyleng - 2;
181 <<EOF>> { yylval->integer = token_eof;
186 %config { yylval->integer = token_config;
187 amxo_hooks_start_section(yyextra, 0);
190 %define { yylval->integer = token_define;
191 amxo_hooks_start_section(yyextra, 1);
194 %populate { yylval->integer = token_populate;
195 amxo_hooks_start_section(yyextra, 2);
198 object { yylval->integer = token_object;
201 select { yylval->integer = token_object;
204 mib { yylval->integer = token_mib;
207 parameter { yylval->integer = token_keyword;
210 &include { yylval->integer = token_post_include;
213 #include { yylval->integer = token_optional_include;
216 \?include { yylval->integer = token_conditional_include;
219 include { yylval->integer = token_include;
222 requires { yylval->integer = token_requires;
225 import { yylval->integer = token_import;
228 using { yylval->integer = token_import;
231 as { yylval->integer = token_keyword;
234 instance { yylval->integer = token_keyword;
237 of { yylval->integer = token_keyword;
240 add { yylval->integer = token_keyword;
243 extend { yylval->integer = token_keyword;
247 %read-only { yylval->integer = 1 << attr_readonly;
248 return SET_ATTRIBUTE;
250 %persistent { yylval->integer = 1 << attr_persistent;
251 return SET_ATTRIBUTE;
253 %private { yylval->integer = 1 << attr_private;
254 return SET_ATTRIBUTE;
256 %protected { yylval->integer = 1 << attr_protected;
257 return SET_ATTRIBUTE;
259 %template { yylval->integer = 1 << attr_template;
260 return SET_ATTRIBUTE;
262 %instance { yylval->integer = 1 << attr_instance;
263 return SET_ATTRIBUTE;
265 %volatile { yylval->integer = 1 << attr_variable;
266 return SET_ATTRIBUTE;
268 volatile { yylval->integer = 1 << attr_variable;
269 return SET_ATTRIBUTE;
271 %async { yylval->integer = 1 << attr_asynchronous;
272 return SET_ATTRIBUTE;
274 %in { yylval->integer = 1 << attr_in;
275 return SET_ATTRIBUTE;
277 %out { yylval->integer = 1 << attr_out;
278 return SET_ATTRIBUTE;
280 in { yylval->integer = 1 << attr_in;
281 return SET_ATTRIBUTE;
283 out { yylval->integer = 1 << attr_out;
284 return SET_ATTRIBUTE;
286 %mandatory { yylval->integer = 1 << attr_mandatory;
287 return SET_ATTRIBUTE;
289 %strict { yylval->integer = 1 << attr_strict;
290 return SET_ATTRIBUTE;
292 %key { yylval->integer = 1 << attr_key;
293 return SET_ATTRIBUTE;
295 %unique { yylval->integer = 1 << attr_unique;
296 return SET_ATTRIBUTE;
298 %mutable { yylval->integer = 1 << attr_mutable;
299 return SET_ATTRIBUTE;
301 %global { yylval->integer = token_keyword;
304 !read-only { yylval->integer = 1 << attr_readonly;
305 return UNSET_ATTRIBUTE;
307 !persistent { yylval->integer = 1 << attr_persistent;
308 return UNSET_ATTRIBUTE;
310 !private { yylval->integer = 1 << attr_private;
311 return UNSET_ATTRIBUTE;
313 !protected { yylval->integer = 1 << attr_protected;
314 return UNSET_ATTRIBUTE;
316 !volatile { yylval->integer = 1 << attr_variable;
317 return UNSET_ATTRIBUTE;
319 void { yylval->integer = AMXC_VAR_ID_NULL;
322 string { yylval->integer = AMXC_VAR_ID_CSTRING;
325 csv_string { yylval->integer = AMXC_VAR_ID_CSV_STRING;
328 ssv_string { yylval->integer = AMXC_VAR_ID_SSV_STRING;
331 int8 { yylval->integer = AMXC_VAR_ID_INT8;
334 int16 { yylval->integer = AMXC_VAR_ID_INT16;
337 int32 { yylval->integer = AMXC_VAR_ID_INT32;
340 int64 { yylval->integer = AMXC_VAR_ID_INT64;
343 uint8 { yylval->integer = AMXC_VAR_ID_UINT8;
346 uint16 { yylval->integer = AMXC_VAR_ID_UINT16;
349 uint32 { yylval->integer = AMXC_VAR_ID_UINT32;
352 uint64 { yylval->integer = AMXC_VAR_ID_UINT64;
355 bool { yylval->integer = AMXC_VAR_ID_BOOL;
358 list { yylval->integer = AMXC_VAR_ID_LIST;
361 htable { yylval->integer = AMXC_VAR_ID_HTABLE;
364 fd { yylval->integer = AMXC_VAR_ID_FD;
367 variant { yylval->integer = AMXC_VAR_ID_ANY;
370 double { yylval->integer = AMXC_VAR_ID_DOUBLE;
373 datetime { yylval->integer = AMXC_VAR_ID_TIMESTAMP;
377 true { yylval->boolean = true;
380 false { yylval->boolean = false;
384 RTLD_NOW { yylval->integer = RTLD_NOW;
388 RTLD_GLOBAL { yylval->integer = RTLD_GLOBAL;
392 RTLD_NODELETE { yylval->integer = RTLD_NODELETE;
396 entry-point { yylval->integer = token_keyword;
400 with { yylval->integer = token_keyword;
403 counted { yylval->integer = token_keyword;
406 on { yylval->integer = token_keyword;
409 default { yylval->integer = token_keyword;
413 action { yylval->integer = token_keyword;
416 event { yylval->integer = token_keyword;
419 filter { yylval->integer = token_keyword;
422 call { yylval->integer = token_keyword;
425 regexp { yylval->integer = token_keyword;
428 userflags { yylval->integer = token_keyword;
431 print { yylval->integer = token_keyword;
434 synchronize { yylval->integer = token_keyword;
437 %batch { yylval->integer = AMXS_SYNC_PARAM_BATCH;
438 return SYNC_ATTRIBUTE;
440 "->" { yylval->integer = AMXS_SYNC_ONLY_A_TO_B;
443 "<-" { yylval->integer = AMXS_SYNC_ONLY_B_TO_A;
446 "<->" { yylval->integer = AMXS_SYNC_DEFAULT;
449 (-|\+){0,1}[[:digit:]]+ { char *endptr = NULL;
450 yylval->integer = strtoll(yytext, &endptr, 0);
453 (-|\+){0,1}0x[A-Fa-f0-9]+ { char *endptr = NULL;
454 yylval->integer = strtoll(yytext, &endptr, 16);
457 (-|\+){0,1}0b[0-1]+ { char *endptr = NULL;
458 yylval->integer = strtoll(yytext + 2, &endptr, 2);
461 [a-zA-Z0-9\-_]+ { yylval->cptr.txt = yytext;
462 yylval->cptr.length = yyleng;
466 \n|. { return yytext[0]; }
470 void amxo_parser_create_lex(amxo_parser_t *parser) {
471 yylex_init(&parser->scanner);
472 yyset_extra(parser, parser->scanner);
475 void amxo_parser_destroy_lex(amxo_parser_t *parser) {
476 yylex_destroy(parser->scanner);