]> Dogcows Code - chaz/openbox/blob - openbox/parse.y
put focus_cycle into focus.c, use it there in the action. improved it as well to...
[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 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_assign(char *name, ParseToken *token);
35 void parse_set_section(char *section);
36 %}
37
38 %token <real> REAL
39 %token <integer> INTEGER
40 %token <string> STRING
41 %token <identifier> IDENTIFIER
42 %token <bool> BOOL
43 %token <character> '('
44 %token <character> ')'
45 %token <character> '{'
46 %token <character> '}'
47 %token <character> '='
48 %token <character> ','
49 %token <character> '\n'
50 %token INVALID
51
52 %type <list> list
53 %type <list> listtokens
54
55 %%
56
57 sections:
58 | sections '[' IDENTIFIER ']' { parse_set_section($3); } '\n'
59 { ++yylineno; } lines
60 ;
61
62 lines:
63 | lines tokens { t.type='\n'; t.data.character='\n'; parse_token(&t); } '\n'
64 { ++yylineno; }
65 | lines IDENTIFIER '=' listtoken { parse_assign($2, &t); } '\n'
66 { ++yylineno; }
67 ;
68
69 tokens:
70 tokens token { parse_token(&t); }
71 | token { parse_token(&t); }
72 ;
73
74 token:
75 REAL { t.type = TOKEN_REAL; t.data.real = $1; }
76 | INTEGER { t.type = TOKEN_INTEGER; t.data.integer = $1; }
77 | STRING { t.type = TOKEN_STRING; t.data.string = $1; }
78 | IDENTIFIER { t.type = TOKEN_IDENTIFIER; t.data.identifier = $1; }
79 | BOOL { t.type = TOKEN_BOOL; t.data.bool = $1; }
80 | list { t.type = TOKEN_LIST; t.data.list = $1; }
81 | '{' { t.type = $1; t.data.character = $1; }
82 | '}' { t.type = $1; t.data.character = $1; }
83 | ',' { t.type = $1; t.data.character = $1; }
84 ;
85
86 list:
87 '(' listtokens ')' { $$ = $2; }
88 ;
89
90 listtokens:
91 listtokens listtoken { ParseToken *nt = g_new(ParseToken, 1);
92 nt->type = t.type;
93 nt->data = t.data;
94 $$ = g_list_append($1, nt);
95 }
96 | listtoken { ParseToken *nt = g_new(ParseToken, 1);
97 nt->type = t.type;
98 nt->data = t.data;
99 $$ = g_list_append(NULL, nt);
100 }
101 ;
102
103 listtoken:
104 REAL { t.type = TOKEN_REAL; t.data.real = $1; }
105 | INTEGER { t.type = TOKEN_INTEGER; t.data.integer = $1; }
106 | STRING { t.type = TOKEN_STRING; t.data.string = $1; }
107 | IDENTIFIER { t.type = TOKEN_IDENTIFIER; t.data.identifier = $1; }
108 | BOOL { t.type = TOKEN_BOOL; t.data.bool = $1; }
109 | list { t.type = TOKEN_LIST; t.data.list = $1; }
110 | '{' { t.type = $1; t.data.character = $1; }
111 | '}' { t.type = $1; t.data.character = $1; }
112 | ',' { t.type = $1; t.data.character = $1; }
113 ;
114
115
116 %%
117
118 void yyerror(char *err) {
119 g_message("%s:%d: %s", path, yylineno, err);
120 }
121
122 void parse_rc()
123 {
124 /* try the user's rc */
125 path = g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL);
126 if ((yyin = fopen(path, "r")) == NULL) {
127 g_free(path);
128 /* try the system wide rc */
129 path = g_build_filename(RCDIR, "rc3", NULL);
130 if ((yyin = fopen(path, "r")) == NULL) {
131 g_warning("No rc2 file found!");
132 g_free(path);
133 return;
134 }
135 }
136
137 yylineno = 1;
138
139 yyparse();
140
141 g_free(path);
142 }
This page took 0.03815 seconds and 4 git commands to generate.