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