]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_lex.l
Merge pull request #105 from opensourcerouting/cli_merge_step_prep
[mirror_frr.git] / lib / command_lex.l
1 /*
2 * Command format string lexer for CLI backend.
3 *
4 * --
5 * Copyright (C) 2015 Cumulus Networks, Inc.
6 *
7 * This file is part of GNU Zebra.
8 *
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
12 * later version.
13 *
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.
18 *
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
22 * 02111-1307, USA.
23 */
24
25 %{
26 #include "command_parse.h"
27
28 #define YY_USER_ACTION yylloc->last_column += yyleng;
29 #define LOC_STEP do { if (yylloc) { \
30 yylloc->first_column = yylloc->last_column; \
31 yylloc->first_line = yylloc->last_line; \
32 } } while(0)
33 %}
34
35 WORD (\-|\+)?[a-z0-9\*][-+_a-zA-Z0-9\*]*
36 IPV4 A\.B\.C\.D
37 IPV4_PREFIX A\.B\.C\.D\/M
38 IPV6 X:X::X:X
39 IPV6_PREFIX X:X::X:X\/M
40 VARIABLE [A-Z][-_a-zA-Z:0-9]+
41 NUMBER (\-|\+)?[0-9]{1,20}
42 RANGE \({NUMBER}[ ]?\-[ ]?{NUMBER}\)
43
44 /* yytext shall be a pointer */
45 %pointer
46 %option noyywrap
47 %option nounput
48 %option noinput
49 %option outfile="command_lex.c"
50 %option header-file="command_lex.h"
51 %option prefix="cmd_yy"
52 %option reentrant
53 %option bison-bridge
54 %option bison-locations
55
56 %%
57 %{
58 LOC_STEP;
59 %}
60
61 [ \t]+ LOC_STEP /* ignore whitespace */;
62 {WORD} {yylval->string = XSTRDUP(MTYPE_TMP, yytext); return WORD;}
63 {IPV4} {yylval->string = XSTRDUP(MTYPE_TMP, yytext); return IPV4;}
64 {IPV4_PREFIX} {yylval->string = XSTRDUP(MTYPE_TMP, yytext); return IPV4_PREFIX;}
65 {IPV6} {yylval->string = XSTRDUP(MTYPE_TMP, yytext); return IPV6;}
66 {IPV6_PREFIX} {yylval->string = XSTRDUP(MTYPE_TMP, yytext); return IPV6_PREFIX;}
67 {VARIABLE} {yylval->string = XSTRDUP(MTYPE_TMP, yytext); return VARIABLE;}
68 {RANGE} {yylval->string = XSTRDUP(MTYPE_TMP, yytext); return RANGE;}
69 . {return yytext[0];}
70 %%
71
72 YY_BUFFER_STATE buffer;
73
74 void set_lexer_string (yyscan_t *scn, const char *string)
75 {
76 *scn = NULL;
77 yylex_init(scn);
78 buffer = yy_scan_string (string, *scn);
79 }
80
81 void cleanup_lexer (yyscan_t *scn)
82 {
83 // yy_delete_buffer (buffer, *scn);
84 yylex_destroy(*scn);
85 }