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;
<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;
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; }
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;
\n /* ignore end of line */;
<BIND_COND>[ \t]+ { BEGIN(BIND_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;
\"[^\"]+\" {
/* 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];
<BIND_A2WS_COND>[^\n]+ { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR; }
^#[^\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 { 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(SET_COND); return TOKSET; }
ipc-socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
exec { BEGIN(BIND_AWS_COND); return TOKEXEC; }
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; }
<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;
}
<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;
@ -19,31 +20,32 @@ int yywrap() {
}
void parse_file(const char *f) {
printf("opening %s\n", f);
printf("opening %s\n", f);
if ((yyin = fopen(f, "r")) == NULL) {
perror("fopen");
exit(1);
}
if (yyparse() != 0) {
fprintf(stderr, "Could not parse configfile\n");
exit(1);
}
fclose(yyin);
perror("fopen");
exit(1);
}
if (yyparse() != 0) {
fprintf(stderr, "Could not parse configfile\n");
exit(1);
}
fclose(yyin);
}
#if 0
main()
{
yyparse();
printf("parsing done\n");
printf("parsing done\n");
}
#endif
%}
%union {
int number;
char *string;
int number;
char *string;
struct Colortriple *color;
}
%token <number>NUMBER
@ -76,146 +78,151 @@ main()
lines: /* empty */
| lines WHITESPACE line
| lines line
| lines line
;
line:
bind
| bindsym
| floating_modifier
| workspace
| assign
| set
| ipcsocket
| exec
| color
| terminal
| font
| comment
| bindsym
| floating_modifier
| workspace
| assign
| set
| ipcsocket
| exec
| color
| terminal
| font
| comment
;
comment:
TOKCOMMENT
;
TOKCOMMENT
;
command:
STR
;
STR
;
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);
}
;
floating_modifier:
TOKFLOATING_MODIFIER WHITESPACE binding_modifiers
{
printf("\tfloating modifier %d\n", $<number>3);
}
;
TOKFLOATING_MODIFIER WHITESPACE binding_modifiers
{
printf("\tfloating modifier %d\n", $<number>3);
}
;
workspace:
TOKWORKSPACE WHITESPACE NUMBER WHITESPACE TOKSCREEN WHITESPACE screen
{
printf("\t workspace %d to screen %d\n", $<number>3, $<number>7);
}
| TOKWORKSPACE WHITESPACE NUMBER WHITESPACE TOKSCREEN WHITESPACE screen WHITESPACE QUOTEDSTRING
{
printf("\t quoted: %s\n", $<string>9);
}
;
TOKWORKSPACE WHITESPACE NUMBER WHITESPACE TOKSCREEN WHITESPACE screen
{
printf("\t workspace %d to screen %s\n", $<number>3, $<string>7);
}
| TOKWORKSPACE WHITESPACE NUMBER WHITESPACE TOKSCREEN WHITESPACE screen WHITESPACE workspace_name
{
printf("\t quoted: %s\n", $<string>9);
}
;
workspace_name:
QUOTEDSTRING
| STR
;
screen:
NUMBER
;
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
{
printf("assignment of %s to %d\n", $<string>3, $<number>6);
}
;
TOKASSIGN WHITESPACE window_class WHITESPACE optional_arrow NUMBER
{
printf("assignment of %s to %d\n", $<string>3, $<number>6);
}
;
window_class:
QUOTEDSTRING
| STR_NG
;
QUOTEDSTRING
| STR_NG
;
optional_arrow:
/* NULL */
| TOKARROW WHITESPACE
;
/* NULL */
| TOKARROW WHITESPACE
;
set:
TOKSET WHITESPACE variable WHITESPACE STR
{
printf("set %s to %s\n", $<string>3, $<string>5);
}
;
TOKSET WHITESPACE variable WHITESPACE STR
{
printf("set %s to %s\n", $<string>3, $<string>5);
}
;
variable:
'$' WORD { asprintf(&$<string>$, "$%s", $<string>2); }
| '$' VARNAME { asprintf(&$<string>$, "$%s", $<string>2); }
;
'$' WORD { asprintf(&$<string>$, "$%s", $<string>2); }
| '$' VARNAME { asprintf(&$<string>$, "$%s", $<string>2); }
;
ipcsocket:
TOKIPCSOCKET WHITESPACE STR
{
printf("ipc %s\n", $<string>3);
}
;
TOKIPCSOCKET WHITESPACE STR
{
printf("ipc %s\n", $<string>3);
}
;
exec:
TOKEXEC WHITESPACE STR
{
printf("exec %s\n", $<string>3);
}
;
TOKEXEC WHITESPACE STR
{
printf("exec %s\n", $<string>3);
}
;
terminal:
TOKTERMINAL WHITESPACE STR
{
printf("terminal %s\n", $<string>3);
}
;
TOKTERMINAL WHITESPACE STR
{
printf("terminal %s\n", $<string>3);
}
;
font:
TOKFONT WHITESPACE STR
{
printf("font %s\n", $<string>3);
}
;
TOKFONT WHITESPACE STR
{
printf("font %s\n", $<string>3);
}
;
color:
TOKCOLOR WHITESPACE '#' HEX
{
printf("color %s\n", $<string>4);
}
;
TOKCOLOR WHITESPACE '#' HEX WHITESPACE '#' HEX WHITESPACE '#' HEX
{
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:
MODIFIER { $<number>$ = $<number>1; }
| TOKCONTROL { $<number>$ = BIND_CONTROL; }
| TOKSHIFT { $<number>$ = BIND_SHIFT; }
;
MODIFIER { $<number>$ = $<number>1; }
| TOKCONTROL { $<number>$ = BIND_CONTROL; }
| TOKSHIFT { $<number>$ = BIND_SHIFT; }
;