Finish configfile parsing with lexer, implement -l to use the lexer.

Every user is encouraged to use -l to switch to the new lexer and
see if there are any problems.
next
Michael Stapelberg 2009-09-19 19:05:15 +02:00
parent 207ad0a7df
commit ca472559b9
5 changed files with 60 additions and 12 deletions

View File

@ -20,6 +20,7 @@
typedef struct Config Config;
extern Config config;
extern bool config_use_lexer;
/**
* Part of the struct Config. It makes sense to group colors for background,

View File

@ -43,6 +43,7 @@ Mod2 { yylval.number = BIND_MOD2; return MODIFIER; }
Mod3 { yylval.number = BIND_MOD3; return MODIFIER; }
Mod4 { yylval.number = BIND_MOD4; return MODIFIER; }
Mod5 { yylval.number = BIND_MOD5; return MODIFIER; }
Mode_switch { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
control { return TOKCONTROL; }
shift { return TOKSHIFT; }
→ { return TOKARROW; }

View File

@ -152,6 +152,7 @@ void parse_file(const char *f) {
int number;
char *string;
struct Colortriple *color;
struct Assignment *assignment;
}
%token <number>NUMBER
@ -272,13 +273,39 @@ screen:
;
assign:
TOKASSIGN WHITESPACE window_class WHITESPACE optional_arrow NUMBER
TOKASSIGN WHITESPACE window_class WHITESPACE optional_arrow assign_target
{
/* TODO */
printf("assignment of %s to %d\n", $<string>3, $<number>6);
struct Assignment *new = $<assignment>6;
new->windowclass_title = strdup($<string>3);
TAILQ_INSERT_TAIL(&assignments, new, assignments);
}
;
assign_target:
NUMBER
{
struct Assignment *new = scalloc(sizeof(struct Assignment));
new->workspace = $<number>1;
new->floating = ASSIGN_FLOATING_NO;
$<assignment>$ = new;
}
| '~'
{
struct Assignment *new = scalloc(sizeof(struct Assignment));
new->floating = ASSIGN_FLOATING_ONLY;
$<assignment>$ = new;
}
| '~' NUMBER
{
struct Assignment *new = scalloc(sizeof(struct Assignment));
new->workspace = $<number>2;
new->floating = ASSIGN_FLOATING;
$<assignment>$ = new;
}
;
window_class:
QUOTEDSTRING
| STR_NG

View File

@ -28,6 +28,8 @@
Config config;
bool config_use_lexer = false;
/*
* This function resolves ~ in pathnames.
*
@ -226,6 +228,25 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
config.bar.urgent.background = get_colorpixel(conn, "#900000");
config.bar.urgent.text = get_colorpixel(conn, "#ffffff");
if (config_use_lexer) {
/* Yes, this will be cleaned up soon. */
if (override_configpath != NULL) {
parse_file(override_configpath);
} else {
FILE *handle;
char *globbed = glob_path("~/.i3/config");
if ((handle = fopen(globbed, "r")) == NULL) {
if ((handle = fopen("/etc/i3/config", "r")) == NULL) {
die("Neither \"%s\" nor /etc/i3/config could be opened\n", globbed);
} else {
parse_file("/etc/i3/config");
}
} else {
parse_file(globbed);
}
}
} else {
FILE *handle;
if (override_configpath != NULL) {
if ((handle = fopen(override_configpath, "r")) == NULL)
@ -508,9 +529,6 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
grab_all_keys(conn);
fclose(handle);
REQUIRED_OPTION(terminal);
REQUIRED_OPTION(font);
while (!SLIST_EMPTY(&variables)) {
struct Variable *v = SLIST_FIRST(&variables);
SLIST_REMOVE_HEAD(&variables, variables);
@ -518,6 +536,10 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
free(v->value);
free(v);
}
}
REQUIRED_OPTION(terminal);
REQUIRED_OPTION(font);
/* Set an empty name for every workspace which got no name */
for (int i = 0; i < 10; i++) {

View File

@ -165,7 +165,7 @@ int main(int argc, char *argv[], char *env[]) {
start_argv = argv;
while ((opt = getopt_long(argc, argv, "c:vahp", long_options, &option_index)) != -1) {
while ((opt = getopt_long(argc, argv, "c:vahl", long_options, &option_index)) != -1) {
switch (opt) {
case 'a':
LOG("Autostart disabled using -a\n");
@ -177,12 +177,9 @@ int main(int argc, char *argv[], char *env[]) {
case 'v':
printf("i3 version " I3_VERSION " © 2009 Michael Stapelberg and contributors\n");
exit(EXIT_SUCCESS);
case 'p':
{
printf("parsing\n");
parse_file(override_configpath);
exit(0);
}
case 'l':
config_use_lexer = true;
break;
default:
fprintf(stderr, "Usage: %s [-c configfile] [-a] [-v]\n", argv[0]);
fprintf(stderr, "\n");