4d9fc3de811bce2f7b79da20b566e65171d9baa0
1 /**
2 * oconfig - src/scanner.l
3 * Copyright (C) 2007 Florian octo Forster <octo at verplant.org>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
19 %{
20 #include <stdlib.h>
21 #include "oconfig.h"
22 #include "aux_types.h"
23 #include "parser.h"
24 %}
25 %option yylineno
26 %option noyywrap
27 WHITE_SPACE [\ \t\b]
28 QUOTED_STRING \"([^\\"]+|\\.)*\"
29 UNQUOTED_STRING [0-9A-Za-z_]+
30 HEX_NUMBER 0[xX][0-9a-fA-F]+
31 OCT_NUMBER 0[0-7]+
32 DEC_NUMBER [\+\-]?[0-9]+
33 FLOAT_NUMBER [\+\-]?[0-9]*\.[0-9]+([eE][\+\-][0-9]+)?
34 NUMBER ({FLOAT_NUMBER}|{HEX_NUMBER}|{OCT_NUMBER}|{DEC_NUMBER})
35 BOOL_TRUE (true|yes|on)
36 BOOL_FALSE (false|no|off)
37 COMMENT #.*
38 PORT (6(5(5(3[0-5]|[0-2][0-9])|[0-4][0-9][0-9])|[0-4][0-9][0-9][0-9])|[1-5][0-9][0-9][0-9][0-9]|[1-9][0-9]?[0-9]?[0-9]?)
39 IP_BYTE (2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])
40 IPV4_ADDR {IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}(:{PORT})?
42 %%
43 {WHITE_SPACE} |
44 {COMMENT} {/* ignore */}
46 \n {return (EOL);}
47 "/" {return (SLASH);}
48 "<" {return (OPENBRAC);}
49 ">" {return (CLOSEBRAC);}
50 {BOOL_TRUE} {yylval.boolean = 1; return (TRUE);}
51 {BOOL_FALSE} {yylval.boolean = 0; return (FALSE);}
53 {IPV4_ADDR} {yylval.string = yytext; return (UNQUOTED_STRING);}
55 {NUMBER} {yylval.number = strtod (yytext, NULL); return (NUMBER);}
57 {QUOTED_STRING} {yylval.string = yytext; return (QUOTED_STRING);}
58 {UNQUOTED_STRING} {yylval.string = yytext; return (UNQUOTED_STRING);}
59 %%