Adjustments of the language, added copyright notice and license information, ...
[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 WHITE_SPACE [\ \t\b]
26 QUOTED_STRING \"([^\\"]+|\\.)*\"
27 UNQUOTED_STRING [0-9A-Za-z_]+
28 HEX_NUMBER 0[xX][0-9a-fA-F]+
29 OCT_NUMBER 0[0-7]+
30 DEC_NUMBER [\+\-]?[0-9]+
31 FLOAT_NUMBER [\+\-]?[0-9]*\.[0-9]+([eE][\+\-][0-9]+)?
32 NUMBER ({FLOAT_NUMBER}|{HEX_NUMBER}|{OCT_NUMBER}|{DEC_NUMBER})
33 BOOL_TRUE (true|yes|on)
34 BOOL_FALSE (false|no|off)
35 COMMENT #.*
36 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]?)
37 IP_BYTE (2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])
38 IPV4_ADDR {IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}\.{IP_BYTE}(:{PORT})?
39
40 %%
41 {WHITE_SPACE}           |
42 {COMMENT}               {/* ignore */}
43
44 \n                      {return (EOL);}
45 "/"                     {return (SLASH);}
46 "<"                     {return (OPENBRAC);}
47 ">"                     {return (CLOSEBRAC);}
48 {BOOL_TRUE}             {yylval.boolean = 1; return (TRUE);}
49 {BOOL_FALSE}            {yylval.boolean = 0; return (FALSE);}
50
51 {IPV4_ADDR}             {yylval.string = yytext; return (UNQUOTED_STRING);}
52
53 {NUMBER}                {yylval.number = strtod (yytext, NULL); return (NUMBER);}
54
55 {QUOTED_STRING}         {yylval.string = yytext; return (QUOTED_STRING);}
56 {UNQUOTED_STRING}       {yylval.string = yytext; return (UNQUOTED_STRING);}
57 %%