This repository has been archived by the owner on Jun 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnetmap_scan.l
77 lines (63 loc) · 2.47 KB
/
netmap_scan.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* This file is part of iouyap, a program to bridge IOU with
* network interfaces.
*
* Copyright (C) 2013, 2014 James E. Carpenter
*
* iouyap is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iouyap is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
%{
#include <stdio.h>
#include "iouyap.h"
#include "y.tab.h"
int comment_line = -1;
unsigned int got_node = 0;
%}
%option noyywrap nodefault yylineno noinput nounput
%x COMMENT
%x NODE
%x JUNK
INT [[:digit:]]+
ADDRESS [[:alnum:].-]+
%%
[ \t]+ /* Ignore whitespace except for newline *if* we have something good */
\n { if (got_node) {got_node = 0; return ENDSEG;} }
{INT}:{INT} { BEGIN NODE; yyless(0); }
<NODE>{INT} { yylval.ival = atoi(yytext); return INT; }
<NODE>{ADDRESS} { yylval.sval = strdup(yytext); return ADDRESS; }
<NODE>[:/@] { return yytext[0]; }
<NODE>"/*"|.|\n { BEGIN INITIAL; yyless(0); got_node = 1; return ENDNODE; }
/* C-style comments (like this) are allowed in NETMAP */
"/*" { BEGIN COMMENT; comment_line = yylineno; }
<COMMENT>"*/" { BEGIN INITIAL; }
<COMMENT>([^*/]|\n)+|. /* match anything but *'s and /'s and ignore it */
<COMMENT>"/*" { log_fmt("NETMAP line %d: nested comment\n", yylineno); }
<COMMENT><<EOF>> { log_fmt("NETMAP line %d: unterminated comment\n", comment_line); yyterminate(); }
"*/" { log_fmt("NETMAP line %d: terminator found outside of comment\n", yylineno); }
. { BEGIN JUNK; yyless(0); }
<JUNK>"/*"|[ \t\n] { BEGIN INITIAL; yyless(0); }
<JUNK>[^/ \t\n]+|. { log_fmt("NETMAP line %d: unknown character(s) found '%s'\n", yylineno, yytext); }
%%
/*
* Editor modelines
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=4 expandtab:
* :indentSize=4:tabSize=4:noTabs=true:
*/