2 * Command format string lexer for CLI backend.
5 * Copyright (C) 2015 Cumulus Networks, Inc.
7 * This file is part of GNU Zebra.
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 /* ignore flex generated code in static analyzer */
27 #ifndef __clang_analyzer__
29 /* ignore harmless bugs in old versions of flex */
30 #pragma GCC diagnostic ignored "-Wsign-compare"
31 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
33 #include "command_parse.h"
35 #define YY_USER_ACTION yylloc->last_column += yyleng;
36 #define LOC_STEP do { if (yylloc) { \
37 yylloc->first_column = yylloc->last_column; \
38 yylloc->first_line = yylloc->last_line; \
43 IPV4_PREFIX A\.B\.C\.D\/M
45 IPV6_PREFIX X:X::X:X\/M
48 VARIABLE [A-Z][-_A-Z:0-9]+
49 WORD (\-|\+)?[a-zA-Z0-9\*][-+_a-zA-Z0-9\*]*
50 NUMBER (\-|\+)?[0-9]{1,20}
51 RANGE \({NUMBER}[ ]?\-[ ]?{NUMBER}\)
53 /* yytext shall be a pointer */
58 %option outfile="lib/command_lex.c"
59 %option header-file="lib/command_lex.h"
60 %option prefix="cmd_yy"
63 %option bison-locations
70 [ \t]+ LOC_STEP /* ignore whitespace */;
71 {IPV4} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return IPV4;}
72 {IPV4_PREFIX} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return IPV4_PREFIX;}
73 {IPV6} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return IPV6;}
74 {IPV6_PREFIX} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return IPV6_PREFIX;}
75 {MAC} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return MAC;}
76 {MAC_PREFIX} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return MAC_PREFIX;}
77 {VARIABLE} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return VARIABLE;}
78 {WORD} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return WORD;}
79 {RANGE} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return RANGE;}
83 YY_BUFFER_STATE buffer;
85 void set_lexer_string (yyscan_t *scn, const char *string)
89 buffer = yy_scan_string (string, *scn);
92 void cleanup_lexer (yyscan_t *scn)
94 // yy_delete_buffer (buffer, *scn);
98 #endif /* __clang_analyzer__ */