fdf998f8503558d5fe62dc15ec490216dcbfd57a
[libfirm] / ir / libcore / lc_config_lexer.l
1
2 %option prefix="_lc_opt_"
3
4 %{
5
6 /*
7   libcore: library for basic data structures and algorithms.
8   Copyright (C) 2005  IPD Goos, Universit"at Karlsruhe, Germany
9
10   This library is free software; you can redistribute it and/or
11   modify it under the terms of the GNU Lesser General Public
12   License as published by the Free Software Foundation; either
13   version 2.1 of the License, or (at your option) any later version.
14
15   This library is distributed in the hope that it will be useful,
16   but WITHOUT ANY WARRANTY; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18   Lesser General Public License for more details.
19
20   You should have received a copy of the GNU Lesser General Public
21   License along with this library; if not, write to the Free Software
22   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 */
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <stdio.h>
29 #include <unistd.h>  /* flex generated code wants a declaration of isatty... */
30
31 #include "lc_parser_t.h"
32 #include "lc_config_parser.h"
33
34 #define YY_NO_UNISTD_H
35 #define YY_NO_INPUT
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 static int _lc_opt_wrap(void);
41 #ifdef __cplusplus
42 }
43 #endif
44
45 %}
46
47 num             [0-9]+
48 hexnum          0x[0-9a-fA-F]+
49 idcharsbegin    [a-zA-Z$_]
50 idchars         ({idcharsbegin}|[0-9])
51 ident           {idcharsbegin}{idchars}*
52 ws              [\t ]*
53 nl              \n
54
55 %x LINE_COMMENT
56 %x BIG_COMMENT
57 %x DAT
58 %x DAT_CONT
59 %x STR
60
61
62 %%
63
64 "/*"                { BEGIN(BIG_COMMENT); }
65 <BIG_COMMENT>"*/"   { BEGIN(INITIAL); }
66 <BIG_COMMENT>\n     PMANGLE(linenr)++;
67 <BIG_COMMENT>.      ;
68
69 ("#"|"//")          { BEGIN(LINE_COMMENT); }
70 <LINE_COMMENT>\n    { BEGIN(INITIAL); PMANGLE(linenr)++; }
71 <LINE_COMMENT>.     ;
72
73
74 <INITIAL>[=:]{ws}   { BEGIN(DAT); }
75 <DAT>\"             { BEGIN(STR); }
76 <DAT>\\             { BEGIN(DAT_CONT); }
77 <DAT>.              { _lc_opt_add_to_data_char(PMANGLE(text)[0]); }
78 <DAT>\n             {
79                                                 BEGIN(INITIAL);
80                                                 PMANGLE(linenr)++;
81                                                 _lc_opt_add_to_data_char('\0');
82                                                 return DATA;
83                                         }
84 <DAT_CONT>\n        { BEGIN(DAT); PMANGLE(linenr)++; }
85 <DAT_CONT>.         ;
86
87
88 <STR>\"             {
89                                                 BEGIN(INITIAL);
90                                                 _lc_opt_add_to_data_char('\0');
91                                                 return DATA;
92                                         }
93
94 <STR>\\n            _lc_opt_add_to_data_char('\n');
95 <STR>\\r            _lc_opt_add_to_data_char('\r');
96 <STR>\\t            _lc_opt_add_to_data_char('\t');
97 <STR>\\b            _lc_opt_add_to_data_char('\b');
98 <STR>\\f            _lc_opt_add_to_data_char('\f');
99 <STR>\\.            _lc_opt_add_to_data_char(yytext[1]);
100 <STR>[^\"]          _lc_opt_add_to_data_char(yytext[0]);
101
102 {ident}                         {
103                                                 PMANGLE(lval).text.str = PMANGLE(text);
104                                                 PMANGLE(lval).text.len = PMANGLE(leng);
105                                                 return IDENT;
106                                         }
107 [/.]                { return SEP; }
108
109 {ws}                ;
110 {nl}                PMANGLE(linenr)++;
111
112 .                   return yytext[0];
113
114 %%
115
116 static int _lc_opt_wrap(void)
117 {
118         /* avoid warning */
119         (void) yyunput;
120         return 1;
121 }