From: Michael Stapelberg Date: Sun, 27 Sep 2009 15:02:13 +0000 (+0200) Subject: parser: Implement parsing mode sections X-Git-Tag: 3.d~71 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d916e075c3188b25e54a771f9bfcad9f84739ea4;p=i3%2Fi3 parser: Implement parsing mode sections Wait for further commits before they are actually used. --- diff --git a/src/cfgparse.l b/src/cfgparse.l index 20e36235..3bbedd66 100644 --- a/src/cfgparse.l +++ b/src/cfgparse.l @@ -25,6 +25,7 @@ ^[ \t]*#[^\n]* { return TOKCOMMENT; } [0-9a-fA-F]+ { yylval.string = strdup(yytext); return HEX; } [0-9]+ { yylval.number = atoi(yytext); return NUMBER; } +mode { return TOKMODE; } bind { BEGIN(BIND_COND); return TOKBIND; } bindsym { BEGIN(BIND_COND); return TOKBINDSYM; } floating_modifier { return TOKFLOATING_MODIFIER; } diff --git a/src/cfgparse.y b/src/cfgparse.y index 3fba5057..15f0df8b 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -25,6 +25,8 @@ extern int yylex(void); extern FILE *yyin; +static struct bindings_head *current_bindings; + int yydebug = 1; void yyerror(const char *str) { @@ -158,7 +160,8 @@ void parse_file(const char *f) { int number; char *string; struct Colortriple *color; - struct Assignment *assignment; + struct Assignment *assignment; + struct Binding *binding; } %token NUMBER @@ -185,6 +188,7 @@ void parse_file(const char *f) { %token TOKEXEC %token TOKCOLOR %token TOKARROW +%token TOKMODE %% @@ -194,8 +198,8 @@ lines: /* empty */ ; line: - bind - | bindsym + bindline + | mode | floating_modifier | workspace | assign @@ -215,31 +219,70 @@ command: STR ; +bindline: + binding + { + TAILQ_INSERT_TAIL(&bindings, $1, bindings); + } + ; + +binding: + TOKBIND WHITESPACE bind { $$ = $3; } + | TOKBINDSYM WHITESPACE bindsym { $$ = $3; } + ; + bind: - TOKBIND WHITESPACE binding_modifiers NUMBER WHITESPACE command + binding_modifiers NUMBER WHITESPACE command { - printf("\tFound binding mod%d with key %d and command %s\n", $3, $4, $6); + printf("\tFound binding mod%d with key %d and command %s\n", $1, $2, $4); Binding *new = scalloc(sizeof(Binding)); - new->keycode = $4; - new->mods = $3; - new->command = sstrdup($6); + new->keycode = $2; + new->mods = $1; + new->command = sstrdup($4); - TAILQ_INSERT_TAIL(&bindings, new, bindings); + $$ = new; } ; bindsym: - TOKBINDSYM WHITESPACE binding_modifiers WORD WHITESPACE command + binding_modifiers WORD WHITESPACE command { - printf("\tFound symbolic mod%d with key %s and command %s\n", $3, $4, $6); + printf("\tFound symbolic mod%d with key %s and command %s\n", $1, $2, $4); Binding *new = scalloc(sizeof(Binding)); - new->symbol = sstrdup($4); - new->mods = $3; - new->command = sstrdup($6); + new->symbol = sstrdup($2); + new->mods = $1; + new->command = sstrdup($4); + + $$ = new; + } + ; + +mode: + TOKMODE WHITESPACE QUOTEDSTRING WHITESPACE '{' modelines '}' + { + printf("\t now in mode %s\n", $3); + printf("\t current bindings = %p\n", current_bindings); + } + ; + +modelines: + /* empty */ + | modelines WHITESPACE modeline + | modelines modeline + ; + +modeline: + comment + | binding + { + if (current_bindings == NULL) { + current_bindings = scalloc(sizeof(struct bindings_head)); + TAILQ_INIT(current_bindings); + } - TAILQ_INSERT_TAIL(&bindings, new, bindings); + TAILQ_INSERT_TAIL(current_bindings, $1, bindings); } ;