]> icculus.org git repositories - dana/openbox.git/blob - openbox/parse.y
add the keyboard plugin into the build systems
[dana/openbox.git] / openbox / parse.y
1 %{
2 #include <glib.h>
3 #ifdef HAVE_STDIO_H
4 #  include <stdio.h>
5 #endif
6
7 %}
8
9 %union ParseTokenData {
10     float real;
11     int integer;
12     char *string;
13     char *identifier;
14     gboolean bool;
15     char character;
16     GList *list;
17 }
18
19 %{
20 #include "parse.h"
21
22 extern int yylex();
23 extern int yyparse();
24 void yyerror(char *err);
25
26 extern int yylineno;
27 extern FILE *yyin;
28
29 static char *path;
30 static ParseToken t;
31
32 /* in parse.c */
33 void parse_token(ParseToken *token);
34 void parse_set_section(char *section);
35 %}
36
37 %token <real> REAL
38 %token <integer> INTEGER
39 %token <string> STRING
40 %token <identifier> IDENTIFIER
41 %token <bool> BOOL
42 %token <character> '('
43 %token <character> ')'
44 %token <character> '{'
45 %token <character> '}'
46 %token <character> '='
47 %token <character> ','
48 %token <character> '\n'
49 %token INVALID
50
51 %type <list> list
52 %type <list> listtokens
53
54 %%
55
56 sections:
57   | sections '[' IDENTIFIER ']' { parse_set_section($3); } '\n' lines
58   ;
59
60 lines:
61   | lines tokens '\n' { t.type = $3; t.data.character = $3; parse_token(&t); }
62   ;
63
64 tokens:
65     tokens token
66   | token
67   ;
68
69 token:
70     REAL       { t.type = TOKEN_REAL; t.data.real = $1; parse_token(&t); }
71   | INTEGER    { t.type = TOKEN_INTEGER; t.data.integer = $1;
72                  parse_token(&t); }
73   | STRING     { t.type = TOKEN_STRING; t.data.string = $1; parse_token(&t); }
74   | IDENTIFIER { t.type = TOKEN_IDENTIFIER; t.data.identifier = $1;
75                  parse_token(&t);}
76   | BOOL       { t.type = TOKEN_BOOL; t.data.bool = $1; parse_token(&t); }
77   | list       { t.type = TOKEN_LIST; t.data.list = $1; parse_token(&t); }
78   | '{'        { t.type = $1; t.data.character = $1; parse_token(&t); }
79   | '}'        { t.type = $1; t.data.character = $1; parse_token(&t); }
80   | '='        { t.type = $1; t.data.character = $1; parse_token(&t); }
81   | ','        { t.type = $1; t.data.character = $1; parse_token(&t); }
82   ;
83
84 list:
85     '(' listtokens ')' { $$ = $2; }
86   ;
87
88 listtokens:
89     listtokens listtoken { ParseToken *nt = g_new(ParseToken, 1);
90                            nt->type = t.type;
91                            nt->data = t.data;
92                            $$ = g_list_append($1, nt);
93                          }
94   | listtoken            { ParseToken *nt = g_new(ParseToken, 1);
95                            nt->type = t.type;
96                            nt->data = t.data;
97                            $$ = g_list_append(NULL, nt);
98                          }
99   ;
100
101 listtoken:
102     REAL       { t.type = TOKEN_REAL; t.data.real = $1; }
103   | INTEGER    { t.type = TOKEN_INTEGER; t.data.integer = $1; }
104   | STRING     { t.type = TOKEN_STRING; t.data.string = $1; }
105   | IDENTIFIER { t.type = TOKEN_IDENTIFIER; t.data.identifier = $1; }
106   | BOOL       { t.type = TOKEN_BOOL; t.data.bool = $1; }
107   | list       { t.type = TOKEN_LIST; t.data.list = $1; }
108   | '{'        { t.type = $1; t.data.character = $1; }
109   | '}'        { t.type = $1; t.data.character = $1; }
110   | '='        { t.type = $1; t.data.character = $1; }
111   | ','        { t.type = $1; t.data.character = $1; }
112   ;
113
114
115 %%
116
117 void yyerror(char *err) {
118     g_message("%s:%d: %s", path, yylineno, err);
119 }
120
121 void parse_rc()
122 {
123     /* try the user's rc */
124     path = g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL);
125     if ((yyin = fopen(path, "r")) == NULL) {
126         g_free(path);
127         /* try the system wide rc */
128         path = g_build_filename(RCDIR, "rc3", NULL);
129         if ((yyin = fopen(path, "r")) == NULL) {
130             g_warning("No rc2 file found!");
131             g_free(path);
132             return;
133         }
134     }
135
136     yylineno = 1;
137
138     yyparse();
139
140     g_free(path);
141 }