all repos — openbox @ f7df74b9cc9369fe401d5622c097e258a124f742

openbox fork - make it a bit more like ryudo

openbox/parse.y (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
%{
#include <glib.h>
#ifdef HAVE_STDIO_H
#  include <stdio.h>
#endif

%}

%union ParseTokenData {
    float real;
    int integer;
    char *string;
    char *identifier;
    gboolean bool;
    char character;
    GList *list;
}

%{
#define NO_TAB_H
#include "parse.h"
#undef NO_TAB_H

extern int yylex();
extern int yyparse();
void yyerror(char *err);

extern int lineno;
extern FILE *yyin;

static char *path;
static ParseToken t;

/* in parse.c */
void parse_token(ParseToken *token);
void parse_assign(char *name, ParseToken *token);
void parse_set_section(char *section);
%}

%token <real> REAL
%token <integer> INTEGER
%token <string> STRING
%token <identifier> IDENTIFIER
%token <bool> BOOLEAN
%token <character> '('
%token <character> ')'
%token <character> '{'
%token <character> '}'
%token <character> '='
%token <character> ','
%token <character> '\n'
%token INVALID

%type <list> list
%type <list> listtokens

%%

sections:
  | sections '[' IDENTIFIER ']' { parse_set_section($3); } '\n'
    { ++lineno; } lines
  ;

lines:
  | lines tokens { t.type='\n'; t.data.character='\n'; parse_token(&t); } '\n'
    { ++lineno; }
  | lines IDENTIFIER '=' listtoken { parse_assign($2, &t); } '\n'
    { ++lineno; }
  ;

tokens:
    tokens token { parse_token(&t); }
  | token        { parse_token(&t); }
  ;

token:
    REAL       { t.type = TOKEN_REAL; t.data.real = $1; }
  | INTEGER    { t.type = TOKEN_INTEGER; t.data.integer = $1; }
  | STRING     { t.type = TOKEN_STRING; t.data.string = $1; }
  | IDENTIFIER { t.type = TOKEN_IDENTIFIER; t.data.identifier = $1; }
  | BOOLEAN    { t.type = TOKEN_BOOL; t.data.bool = $1; }
  | list       { t.type = TOKEN_LIST; t.data.list = $1; }
  | '{'        { t.type = $1; t.data.character = $1; }
  | '}'        { t.type = $1; t.data.character = $1; }
  | ','        { t.type = $1; t.data.character = $1; }
  ;

list:
    '(' listtokens ')' { $$ = $2; }
  ;

listtokens:
    listtokens listtoken { ParseToken *nt = g_new(ParseToken, 1);
                           nt->type = t.type;
                           nt->data = t.data;
                           $$ = g_list_append($1, nt);
                         }
  | listtoken            { ParseToken *nt = g_new(ParseToken, 1);
                           nt->type = t.type;
                           nt->data = t.data;
                           $$ = g_list_append(NULL, nt);
                         }
  ;

listtoken:
    REAL       { t.type = TOKEN_REAL; t.data.real = $1; }
  | INTEGER    { t.type = TOKEN_INTEGER; t.data.integer = $1; }
  | STRING     { t.type = TOKEN_STRING; t.data.string = $1; }
  | IDENTIFIER { t.type = TOKEN_IDENTIFIER; t.data.identifier = $1; }
  | BOOLEAN    { t.type = TOKEN_BOOL; t.data.bool = $1; }
  | list       { t.type = TOKEN_LIST; t.data.list = $1; }
  | '{'        { t.type = $1; t.data.character = $1; }
  | '}'        { t.type = $1; t.data.character = $1; }
  | ','        { t.type = $1; t.data.character = $1; }
  ;


%%

int lineno;

void yyerror(char *err) {
    g_message("%s:%d: %s", path, lineno, err);
}

void parse_rc()
{
    /* try the user's rc */
    path = g_build_filename(g_get_home_dir(), ".openbox", "rc3", NULL);
    if ((yyin = fopen(path, "r")) == NULL) {
        g_free(path);
        /* try the system wide rc */
        path = g_build_filename(RCDIR, "rc3", NULL);
        if ((yyin = fopen(path, "r")) == NULL) {
            g_warning("No rc2 file found!");
            g_free(path);
            return;
        }
    }

    lineno = 1;

    yyparse();

    g_free(path);
}