Revert "Prepared for diff."
[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 /* flex generated code wants a declaration of isatty... */
30 #ifdef _WIN32
31 #include <io.h>
32 #else
33 #include <unistd.h>
34
35 #include "lc_parser_t.h"
36 #include "lc_config_parser.h"
37
38 #define YY_NO_UNISTD_H
39 #define YY_NO_INPUT
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 static int _lc_opt_wrap(void);
45 #ifdef __cplusplus
46 }
47 #endif
48
49 %}
50
51 num             [0-9]+
52 hexnum          0x[0-9a-fA-F]+
53 idcharsbegin    [a-zA-Z$_]
54 idchars         ({idcharsbegin}|[0-9])
55 ident           {idcharsbegin}{idchars}*
56 ws              [\t ]*
57 nl              \n
58
59 %x LINE_COMMENT
60 %x BIG_COMMENT
61 %x DAT
62 %x DAT_CONT
63 %x STR
64
65
66 %%
67
68 "/*"                { BEGIN(BIG_COMMENT); }
69 <BIG_COMMENT>"*/"   { BEGIN(INITIAL); }
70 <BIG_COMMENT>\n     PMANGLE(linenr)++;
71 <BIG_COMMENT>.      ;
72
73 ("#"|"//")          { BEGIN(LINE_COMMENT); }
74 <LINE_COMMENT>\n    { BEGIN(INITIAL); PMANGLE(linenr)++; }
75 <LINE_COMMENT>.     ;
76
77
78 <INITIAL>[=:]{ws}   { BEGIN(DAT); }
79 <DAT>\"             { BEGIN(STR); }
80 <DAT>\\             { BEGIN(DAT_CONT); }
81 <DAT>.              { _lc_opt_add_to_data_char(PMANGLE(text)[0]); }
82 <DAT>\n             {
83                                                 BEGIN(INITIAL);
84                                                 PMANGLE(linenr)++;
85                                                 _lc_opt_add_to_data_char('\0');
86                                                 return DATA;
87                                         }
88 <DAT_CONT>\n        { BEGIN(DAT); PMANGLE(linenr)++; }
89 <DAT_CONT>.         ;
90
91
92 <STR>\"             {
93                                                 BEGIN(INITIAL);
94                                                 _lc_opt_add_to_data_char('\0');
95                                                 return DATA;
96                                         }
97
98 <STR>\\n            _lc_opt_add_to_data_char('\n');
99 <STR>\\r            _lc_opt_add_to_data_char('\r');
100 <STR>\\t            _lc_opt_add_to_data_char('\t');
101 <STR>\\b            _lc_opt_add_to_data_char('\b');
102 <STR>\\f            _lc_opt_add_to_data_char('\f');
103 <STR>\\.            _lc_opt_add_to_data_char(yytext[1]);
104 <STR>[^\"]          _lc_opt_add_to_data_char(yytext[0]);
105
106 {ident}                         {
107                                                 PMANGLE(lval).text.str = PMANGLE(text);
108                                                 PMANGLE(lval).text.len = PMANGLE(leng);
109                                                 return IDENT;
110                                         }
111 [/.]                { return SEP; }
112
113 {ws}                ;
114 {nl}                PMANGLE(linenr)++;
115
116 .                   return yytext[0];
117
118 %%
119
120 static int _lc_opt_wrap(void)
121 {
122         /* avoid warning */
123         (void) yyunput;
124         return 1;
125 }