Fixes for Mac OS x.
[liboconfig.git] / src / scanner.l
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  */
18
19 %{
20 #include <stdlib.h>
21 #include "oconfig.h"
22 #include "aux_types.h"
23 #include "parser.h"
24 %}
25 %option yylineno
26 WHITE_SPACE [\ \t\b]
27 QUOTED_STRING \"([^\\"]+|\\.)*\"
28 UNQUOTED_STRING [0-9A-Za-z_]+
29 HEX_NUMBER 0[xX][0-9a-fA-F]+
30 OCT_NUMBER 0[0-7]+
31 DEC_NUMBER [\+\-]?[0-9]+
32 FLOAT_NUMBER [\+\-]?[0-9]*\.[0-9]+([eE][\+\-][0-9]+)?
33 NUMBER ({FLOAT_NUMBER}|{HEX_NUMBER}|{OCT_NUMBER}|{DEC_NUMBER})
34 BOOL_TRUE (true|yes|on)
35 BOOL_FALSE (false|no|off)
36 COMMENT #.*
37 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]?)
38 IP_BYTE (2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])
39 IPV4_ADDR {IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}(:{PORT})?
40
41 %%
42 {WHITE_SPACE}           |
43 {COMMENT}               {/* ignore */}
44
45 \n                      {return (EOL);}
46 "/"                     {return (SLASH);}
47 "<"                     {return (OPENBRAC);}
48 ">"                     {return (CLOSEBRAC);}
49 {BOOL_TRUE}             {yylval.boolean = 1; return (TRUE);}
50 {BOOL_FALSE}            {yylval.boolean = 0; return (FALSE);}
51
52 {IPV4_ADDR}             {yylval.string = yytext; return (UNQUOTED_STRING);}
53
54 {NUMBER}                {yylval.number = strtod (yytext, NULL); return (NUMBER);}
55
56 {QUOTED_STRING}         {yylval.string = yytext; return (QUOTED_STRING);}
57 {UNQUOTED_STRING}       {yylval.string = yytext; return (UNQUOTED_STRING);}
58 %%