]>
Commit | Line | Data |
---|---|---|
1ab84bf3 QY |
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 | ||
92055a92 | 25 | %{ |
073845da QY |
26 | /* ignore harmless bug in old versions of flex */ |
27 | #pragma GCC diagnostic ignored "-Wsign-compare" | |
28 | ||
2a23ca6e | 29 | #include "command_parse.h" |
8bb647a8 DL |
30 | |
31 | #define YY_USER_ACTION yylloc->last_column += yyleng; | |
14152706 | 32 | #define LOC_STEP do { if (yylloc) { \ |
8bb647a8 | 33 | yylloc->first_column = yylloc->last_column; \ |
14152706 DL |
34 | yylloc->first_line = yylloc->last_line; \ |
35 | } } while(0) | |
92055a92 QY |
36 | %} |
37 | ||
bca1a301 | 38 | WORD (\-|\+)?[a-z0-9\*][-+_a-zA-Z0-9\*]* |
92055a92 QY |
39 | IPV4 A\.B\.C\.D |
40 | IPV4_PREFIX A\.B\.C\.D\/M | |
41 | IPV6 X:X::X:X | |
42 | IPV6_PREFIX X:X::X:X\/M | |
1a8c390d | 43 | VARIABLE [A-Z][-_a-zA-Z:0-9]+ |
b3899769 | 44 | NUMBER (\-|\+)?[0-9]{1,20} |
ef955a80 | 45 | RANGE \({NUMBER}[ ]?\-[ ]?{NUMBER}\) |
92055a92 QY |
46 | |
47 | /* yytext shall be a pointer */ | |
48 | %pointer | |
49 | %option noyywrap | |
2a23ca6e QY |
50 | %option nounput |
51 | %option noinput | |
4a121f99 DL |
52 | %option outfile="lib/command_lex.c" |
53 | %option header-file="lib/command_lex.h" | |
e9484f70 DL |
54 | %option prefix="cmd_yy" |
55 | %option reentrant | |
56 | %option bison-bridge | |
8bb647a8 | 57 | %option bison-locations |
92055a92 QY |
58 | |
59 | %% | |
8bb647a8 DL |
60 | %{ |
61 | LOC_STEP; | |
62 | %} | |
63 | ||
64 | [ \t]+ LOC_STEP /* ignore whitespace */; | |
55b7f20f DL |
65 | {WORD} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return WORD;} |
66 | {IPV4} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return IPV4;} | |
67 | {IPV4_PREFIX} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return IPV4_PREFIX;} | |
68 | {IPV6} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return IPV6;} | |
69 | {IPV6_PREFIX} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return IPV6_PREFIX;} | |
70 | {VARIABLE} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return VARIABLE;} | |
71 | {RANGE} {yylval->string = XSTRDUP(MTYPE_LEX, yytext); return RANGE;} | |
92055a92 QY |
72 | . {return yytext[0];} |
73 | %% | |
2a23ca6e | 74 | |
e9484f70 DL |
75 | YY_BUFFER_STATE buffer; |
76 | ||
77 | void set_lexer_string (yyscan_t *scn, const char *string) | |
2a23ca6e | 78 | { |
e9484f70 DL |
79 | *scn = NULL; |
80 | yylex_init(scn); | |
81 | buffer = yy_scan_string (string, *scn); | |
4427e9b3 QY |
82 | } |
83 | ||
e9484f70 | 84 | void cleanup_lexer (yyscan_t *scn) |
4427e9b3 | 85 | { |
e9484f70 DL |
86 | // yy_delete_buffer (buffer, *scn); |
87 | yylex_destroy(*scn); | |
2a23ca6e | 88 | } |