parser: Implement parsing mode sections

Wait for further commits before they are actually used.
This commit is contained in:
Michael Stapelberg 2009-09-27 17:02:13 +02:00
parent 051caf571d
commit d916e075c3
2 changed files with 60 additions and 16 deletions

View File

@ -25,6 +25,7 @@
^[ \t]*#[^\n]* { return TOKCOMMENT; } ^[ \t]*#[^\n]* { return TOKCOMMENT; }
<COLOR_COND>[0-9a-fA-F]+ { yylval.string = strdup(yytext); return HEX; } <COLOR_COND>[0-9a-fA-F]+ { yylval.string = strdup(yytext); return HEX; }
[0-9]+ { yylval.number = atoi(yytext); return NUMBER; } [0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
mode { return TOKMODE; }
bind { BEGIN(BIND_COND); return TOKBIND; } bind { BEGIN(BIND_COND); return TOKBIND; }
bindsym { BEGIN(BIND_COND); return TOKBINDSYM; } bindsym { BEGIN(BIND_COND); return TOKBINDSYM; }
floating_modifier { return TOKFLOATING_MODIFIER; } floating_modifier { return TOKFLOATING_MODIFIER; }

View File

@ -25,6 +25,8 @@
extern int yylex(void); extern int yylex(void);
extern FILE *yyin; extern FILE *yyin;
static struct bindings_head *current_bindings;
int yydebug = 1; int yydebug = 1;
void yyerror(const char *str) { void yyerror(const char *str) {
@ -158,7 +160,8 @@ void parse_file(const char *f) {
int number; int number;
char *string; char *string;
struct Colortriple *color; struct Colortriple *color;
struct Assignment *assignment; struct Assignment *assignment;
struct Binding *binding;
} }
%token <number>NUMBER %token <number>NUMBER
@ -185,6 +188,7 @@ void parse_file(const char *f) {
%token TOKEXEC %token TOKEXEC
%token TOKCOLOR %token TOKCOLOR
%token TOKARROW %token TOKARROW
%token TOKMODE
%% %%
@ -194,8 +198,8 @@ lines: /* empty */
; ;
line: line:
bind bindline
| bindsym | mode
| floating_modifier | floating_modifier
| workspace | workspace
| assign | assign
@ -215,31 +219,70 @@ command:
STR STR
; ;
bind: bindline:
TOKBIND WHITESPACE binding_modifiers NUMBER WHITESPACE command binding
{ {
printf("\tFound binding mod%d with key %d and command %s\n", $<number>3, $4, $<string>6); TAILQ_INSERT_TAIL(&bindings, $<binding>1, bindings);
}
;
binding:
TOKBIND WHITESPACE bind { $<binding>$ = $<binding>3; }
| TOKBINDSYM WHITESPACE bindsym { $<binding>$ = $<binding>3; }
;
bind:
binding_modifiers NUMBER WHITESPACE command
{
printf("\tFound binding mod%d with key %d and command %s\n", $<number>1, $2, $<string>4);
Binding *new = scalloc(sizeof(Binding)); Binding *new = scalloc(sizeof(Binding));
new->keycode = $<number>4; new->keycode = $<number>2;
new->mods = $<number>3; new->mods = $<number>1;
new->command = sstrdup($<string>6); new->command = sstrdup($<string>4);
TAILQ_INSERT_TAIL(&bindings, new, bindings); $<binding>$ = new;
} }
; ;
bindsym: 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", $<number>3, $4, $<string>6); printf("\tFound symbolic mod%d with key %s and command %s\n", $<number>1, $2, $<string>4);
Binding *new = scalloc(sizeof(Binding)); Binding *new = scalloc(sizeof(Binding));
new->symbol = sstrdup($4); new->symbol = sstrdup($2);
new->mods = $<number>3; new->mods = $<number>1;
new->command = sstrdup($<string>6); new->command = sstrdup($<string>4);
TAILQ_INSERT_TAIL(&bindings, new, bindings); $<binding>$ = new;
}
;
mode:
TOKMODE WHITESPACE QUOTEDSTRING WHITESPACE '{' modelines '}'
{
printf("\t now in mode %s\n", $<string>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(current_bindings, $<binding>1, bindings);
} }
; ;