]> icculus.org git repositories - dana/openbox.git/blob - openbox/parse.yacc
don't include the y.tab.h inside the yacc file
[dana/openbox.git] / openbox / parse.yacc
1 %{
2 #define NO_Y_H
3 #include "parse.h"
4 #undef NO_Y_H
5
6 #ifdef HAVE_STDIO_H
7 #  include <stdio.h>
8 #endif
9
10 extern int yylex();
11
12 extern int yylineno;
13 extern FILE *yyin;
14
15 static char *path;
16 static union ParseToken t;
17
18 /* in parse.c */
19 void parse_token(ParseTokenType type, union ParseToken token);
20 void parse_set_section(char *section);
21 %}
22
23 %union ParseToken {
24     float real;
25     int integer;
26     char *string;
27     char *identifier;
28     gboolean bool;
29     char character;
30 }
31
32 %token <real> REAL
33 %token <integer> INTEGER
34 %token <string> STRING
35 %token <identifier> IDENTIFIER
36 %token <bool> BOOL
37 %token <character> '('
38 %token <character> ')'
39 %token <character> '{'
40 %token <character> '}'
41 %token <character> '='
42 %token <character> ','
43 %token <character> '\n'
44 %token INVALID
45
46 %%
47
48 sections:
49   | sections '[' IDENTIFIER ']' { parse_set_section($3); } '\n' lines
50   ;
51
52 lines:
53   | lines tokens '\n' { t.character = $3; parse_token(TOKEN_NEWLINE, t); }
54   ;
55
56 tokens:
57     tokens token
58   | token
59   ;
60
61 token:
62     REAL       { t.real = $1; parse_token(TOKEN_REAL, t); }
63   | INTEGER    { t.integer = $1; parse_token(TOKEN_INTEGER, t); }
64   | STRING     { t.string = $1; parse_token(TOKEN_STRING, t); }
65   | IDENTIFIER { t.identifier = $1; parse_token(TOKEN_IDENTIFIER, t); }
66   | BOOL       { t.bool = $1; parse_token(TOKEN_BOOL, t); }
67   | '('        { t.character = $1; parse_token(TOKEN_LBRACKET, t); }
68   | ')'        { t.character = $1; parse_token(TOKEN_RBRACKET, t); }
69   | '{'        { t.character = $1; parse_token(TOKEN_LBRACE, t); }
70   | '}'        { t.character = $1; parse_token(TOKEN_RBRACE, t); }
71   | '='        { t.character = $1; parse_token(TOKEN_EQUALS, t); }
72   | ','        { t.character = $1; parse_token(TOKEN_COMMA, t); }
73   ;
74
75 %%
76
77 void yyerror(char *err) {
78     g_message("%s:%d: %s", path, yylineno, err);
79 }
80
81 void parse_rc()
82 {
83     /* try the user's rc */
84     path = g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL);
85     if ((yyin = fopen(path, "r")) == NULL) {
86         g_free(path);
87         /* try the system wide rc */
88         path = g_build_filename(RCDIR, "rc3", NULL);
89         if ((yyin = fopen(path, "r")) == NULL) {
90             g_warning("No rc2 file found!");
91             g_free(path);
92             return;
93         }
94     }
95
96     yylineno = 1;
97
98     yyparse();
99
100     g_free(path);
101 }