Fix some parsing problems, retab!

This commit is contained in:
Michael Stapelberg 2009-09-13 18:40:35 +02:00
parent 268bf71222
commit 2986636e03
3 changed files with 174 additions and 145 deletions

View File

@ -27,7 +27,7 @@ src/cfgparse.yy.o: src/cfgparse.l
src/cfgparse.y.o: src/cfgparse.y
echo "YACC $<"
yacc -b $(basename $< .y) -d $<
yacc --debug --verbose -b $(basename $< .y) -d $<
$(CC) $(CFLAGS) -c -o $@ $(<:.y=.tab.c)
install: all

View File

@ -4,49 +4,71 @@
#include <xcb/xcb.h>
#include "data.h"
#include "config.h"
%}
%Start BIND_COND BIND_AWS_COND BIND_A2WS_COND ASSIGN_COND COLOR_COND
%Start BIND_COND
%Start BIND_AWS_COND
%Start BIND_A2WS_COND
%Start ASSIGN_COND
%Start COLOR_COND
%Start SET_COND
%Start SET_AWS_COND
%Start SCREEN_COND
%Start SCREEN_AWS_COND
%%
<BIND_A2WS_COND>[^\n]+ { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR; }
#[^\n]* return TOKCOMMENT;
[0-9]+ yylval.number = atoi(yytext); return NUMBER;
^#[^\n]* { return TOKCOMMENT; }
[0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
<COLOR_COND>[0-9a-fA-F]+ { yylval.string = strdup(yytext); return HEX; }
bind { BEGIN(BIND_COND); return TOKBIND; }
bindsym { BEGIN(BIND_COND); return TOKBINDSYM; }
floating_modifier return TOKFLOATING_MODIFIER;
workspace return TOKWORKSPACE;
screen return TOKSCREEN;
floating_modifier { return TOKFLOATING_MODIFIER; }
workspace { BEGIN(INITIAL); return TOKWORKSPACE; }
screen { BEGIN(SCREEN_COND); return TOKSCREEN; }
terminal { BEGIN(BIND_AWS_COND); return TOKTERMINAL; }
font { BEGIN(BIND_AWS_COND); return TOKFONT; }
assign { BEGIN(ASSIGN_COND); return TOKASSIGN; }
set { BEGIN(BIND_COND); return TOKSET; }
set { BEGIN(SET_COND); return TOKSET; }
ipc-socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
exec { BEGIN(BIND_AWS_COND); return TOKEXEC; }
client.focused { BEGIN(COLOR_COND); /* TODO: lval pointer */ return TOKCOLOR; }
Mod1 yylval.number = BIND_MOD1; return MODIFIER;
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;
control return TOKCONTROL;
shift return TOKSHIFT;
→ return TOKARROW;
client.focused { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
client.focused_inactive { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
client.unfocused { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
client.urgent { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
bar.focused { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
bar.unfocused { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
bar.urgent { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
Mod1 { yylval.number = BIND_MOD1; return MODIFIER; }
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; }
control { return TOKCONTROL; }
shift { return TOKSHIFT; }
→ { return TOKARROW; }
\n /* ignore end of line */;
<SCREEN_AWS_COND>x { return (int)yytext[0]; }
<BIND_COND>[ \t]+ { BEGIN(BIND_AWS_COND); return WHITESPACE; }
<SET_COND>[ \t]+ { BEGIN(SET_AWS_COND); return WHITESPACE; }
<BIND_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
[ \t]+ return WHITESPACE;
<ASSIGN_COND>[^ \t]+ { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR_NG; }
[a-zA-Z]+ yylval.string = strdup(yytext); return WORD;
[a-zA-Z0-9_-]+ yylval.string = strdup(yytext); return VARNAME;
<SET_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
<SCREEN_COND>[ \t]+ { BEGIN(SCREEN_AWS_COND); return WHITESPACE; }
<SCREEN_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
[ \t]+ { return WHITESPACE; }
\"[^\"]+\" {
/* if ASSIGN_COND then */
BEGIN(INITIAL);
/* yylval will be the string, but without quotes */
char *copy = strdup(yytext+1);
copy[strlen(copy)-1] = '\0';
yylval.string = copy;
return QUOTEDSTRING;
}
. return (int) yytext[0];
<ASSIGN_COND>[^ \t]+ { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR_NG; }
[a-zA-Z]+ { yylval.string = strdup(yytext); return WORD; }
<SET_AWS_COND>[a-zA-Z0-9_-]+ { yylval.string = strdup(yytext); return VARNAME; }
. { return (int)yytext[0]; }
%%

View File

@ -4,6 +4,7 @@
#include <xcb/xcb.h>
#include "data.h"
#include "config.h"
extern int yylex(void);
extern FILE *yyin;
@ -44,6 +45,7 @@ main()
%union {
int number;
char *string;
struct Colortriple *color;
}
%token <number>NUMBER
@ -103,16 +105,16 @@ command:
;
bind:
TOKBIND WHITESPACE binding_modifiers '+' NUMBER WHITESPACE command
TOKBIND WHITESPACE binding_modifiers NUMBER WHITESPACE command
{
printf("\tFound binding mod%d with key %d and command %s\n", $<number>3, $5, $<string>7);
printf("\tFound binding mod%d with key %d and command %s\n", $<number>3, $4, $<string>6);
}
;
bindsym:
TOKBINDSYM WHITESPACE binding_modifiers '+' WORD WHITESPACE command
TOKBINDSYM WHITESPACE binding_modifiers WORD WHITESPACE command
{
printf("\tFound symbolic mod%d with key %s and command %s\n", $<number>3, $5, $<string>7);
printf("\tFound symbolic mod%d with key %s and command %s\n", $<number>3, $4, $<string>6);
}
;
@ -126,18 +128,25 @@ floating_modifier:
workspace:
TOKWORKSPACE WHITESPACE NUMBER WHITESPACE TOKSCREEN WHITESPACE screen
{
printf("\t workspace %d to screen %d\n", $<number>3, $<number>7);
printf("\t workspace %d to screen %s\n", $<number>3, $<string>7);
}
| TOKWORKSPACE WHITESPACE NUMBER WHITESPACE TOKSCREEN WHITESPACE screen WHITESPACE QUOTEDSTRING
| TOKWORKSPACE WHITESPACE NUMBER WHITESPACE TOKSCREEN WHITESPACE screen WHITESPACE workspace_name
{
printf("\t quoted: %s\n", $<string>9);
}
;
screen:
NUMBER
workspace_name:
QUOTEDSTRING
| STR
;
screen:
NUMBER { asprintf(&$<string>$, "%d", $<number>1); }
| NUMBER 'x' { asprintf(&$<string>$, "%d", $<number>1); }
| NUMBER 'x' NUMBER { asprintf(&$<string>$, "%dx%d", $<number>1, $<number>3); }
| 'x' NUMBER { asprintf(&$<string>$, "x%d", $<number>2); }
;
assign:
TOKASSIGN WHITESPACE window_class WHITESPACE optional_arrow NUMBER
@ -198,20 +207,18 @@ font:
color:
TOKCOLOR WHITESPACE '#' HEX
TOKCOLOR WHITESPACE '#' HEX WHITESPACE '#' HEX WHITESPACE '#' HEX
{
printf("color %s\n", $<string>4);
printf("color %p, %s and %s and %s\n", $<color>1, $<string>4, $<string>7, $<string>10);
}
;
binding_modifiers:
binding_modifier
|
binding_modifiers '+' binding_modifier
{
$<number>$ = $<number>1 | $<number>3;
}
/* NULL */ { $<number>$ = 0; }
| binding_modifier
| binding_modifiers '+' binding_modifier { $<number>$ = $<number>1 | $<number>3; }
| binding_modifiers '+' { $<number>$ = $<number>1; }
;
binding_modifier: