]> icculus.org git repositories - mikachu/openbox.git/blob - openbox/parse.l
rm the generated files on clean
[mikachu/openbox.git] / openbox / parse.l
1 %{
2 #include <glib.h>
3 #include "y.tab.h"
4 #ifdef HAVE_STDLIB_H
5 #  include <stdlib.h>
6 #endif
7
8 extern void yyerror(char *err);
9
10 int yylineno = 1;
11 %}
12
13 real [-0-9][0-9]*\.[0-9]+
14 integer [-0-9][0-9]*
15 string \"[^"\n]*\"
16 identifier [a-zA-Z][.a-zA-Z0-9]*
17 bool ([tT][rR][uU][eE]|[fF][aA][lL][sS][eE]|[yY][eE][sS]|[nN][oO]|[oO][nN]|[oO][fF][fF])
18
19 %%
20
21 ^[ \t]*#.*\n /* comment */ { ++yylineno; }
22 ^[ \t]*#.*   /* comment */
23 ^[ \t]*\n    /* empty lines */ { ++yylineno; }
24 [ \t]        /* whitespace */
25 {real}       { yylval.real = atof(yytext); return REAL; }
26 {integer}    { yylval.integer = atoi(yytext); return INTEGER; }
27 {string}     { yylval.string = g_strdup(yytext+1); /* drop the left quote */
28                if (yylval.string[yyleng-2] != '"')
29                    yyerror("improperly terminated string on line %d");
30                else
31                    yylval.string[yyleng-2] = '\0';
32                return STRING;
33              }
34 {bool}       { yylval.bool = (!g_ascii_strcasecmp("true", yytext) ||
35                               !g_ascii_strcasecmp("yes", yytext) ||
36                               !g_ascii_strcasecmp("on", yytext));
37                return BOOL;
38              }
39 {identifier} { yylval.identifier = g_strdup(yytext); return IDENTIFIER; }
40 [{}()\[\]=,] { yylval.character = *yytext; return *yytext; }
41 \n           { yylval.character = *yytext; ++yylineno; return *yytext; }
42 .            { return INVALID; }
43
44 %%
45
46 int yywrap() {
47     return 1;
48 }