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 src/cfgparse.y.o: src/cfgparse.y
echo "YACC $<" echo "YACC $<"
yacc -b $(basename $< .y) -d $< yacc --debug --verbose -b $(basename $< .y) -d $<
$(CC) $(CFLAGS) -c -o $@ $(<:.y=.tab.c) $(CC) $(CFLAGS) -c -o $@ $(<:.y=.tab.c)
install: all install: all

View File

@ -4,49 +4,71 @@
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include "data.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; } <BIND_A2WS_COND>[^\n]+ { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR; }
#[^\n]* return TOKCOMMENT; ^#[^\n]* { return TOKCOMMENT; }
[0-9]+ yylval.number = atoi(yytext); return NUMBER; [0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
<COLOR_COND>[0-9a-fA-F]+ { yylval.string = strdup(yytext); return HEX; } <COLOR_COND>[0-9a-fA-F]+ { yylval.string = strdup(yytext); return HEX; }
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; }
workspace return TOKWORKSPACE; workspace { BEGIN(INITIAL); return TOKWORKSPACE; }
screen return TOKSCREEN; screen { BEGIN(SCREEN_COND); return TOKSCREEN; }
terminal { BEGIN(BIND_AWS_COND); return TOKTERMINAL; } terminal { BEGIN(BIND_AWS_COND); return TOKTERMINAL; }
font { BEGIN(BIND_AWS_COND); return TOKFONT; } font { BEGIN(BIND_AWS_COND); return TOKFONT; }
assign { BEGIN(ASSIGN_COND); return TOKASSIGN; } 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; } ipc-socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
exec { BEGIN(BIND_AWS_COND); return TOKEXEC; } exec { BEGIN(BIND_AWS_COND); return TOKEXEC; }
client.focused { BEGIN(COLOR_COND); /* TODO: lval pointer */ return TOKCOLOR; } client.focused { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
Mod1 yylval.number = BIND_MOD1; return MODIFIER; client.focused_inactive { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
Mod2 yylval.number = BIND_MOD2; return MODIFIER; client.unfocused { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
Mod3 yylval.number = BIND_MOD3; return MODIFIER; client.urgent { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
Mod4 yylval.number = BIND_MOD4; return MODIFIER; bar.focused { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
Mod5 yylval.number = BIND_MOD5; return MODIFIER; bar.unfocused { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
control return TOKCONTROL; bar.urgent { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
shift return TOKSHIFT; Mod1 { yylval.number = BIND_MOD1; return MODIFIER; }
→ return TOKARROW; Mod2 { yylval.number = BIND_MOD2; return MODIFIER; }
\n /* ignore end of line */; Mod3 { yylval.number = BIND_MOD3; return MODIFIER; }
<BIND_COND>[ \t]+ { BEGIN(BIND_AWS_COND); return WHITESPACE; } Mod4 { yylval.number = BIND_MOD4; return MODIFIER; }
<BIND_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); return WHITESPACE; } Mod5 { yylval.number = BIND_MOD5; return MODIFIER; }
[ \t]+ return WHITESPACE; control { return TOKCONTROL; }
<ASSIGN_COND>[^ \t]+ { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR_NG; } shift { return TOKSHIFT; }
[a-zA-Z]+ yylval.string = strdup(yytext); return WORD; → { return TOKARROW; }
[a-zA-Z0-9_-]+ yylval.string = strdup(yytext); return VARNAME; \n /* ignore end of line */;
\"[^\"]+\" { <SCREEN_AWS_COND>x { return (int)yytext[0]; }
/* yylval will be the string, but without quotes */ <BIND_COND>[ \t]+ { BEGIN(BIND_AWS_COND); return WHITESPACE; }
char *copy = strdup(yytext+1); <SET_COND>[ \t]+ { BEGIN(SET_AWS_COND); return WHITESPACE; }
copy[strlen(copy)-1] = '\0'; <BIND_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
yylval.string = copy; <SET_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
return QUOTEDSTRING; <SCREEN_COND>[ \t]+ { BEGIN(SCREEN_AWS_COND); return WHITESPACE; }
} <SCREEN_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
. return (int) yytext[0]; [ \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 <xcb/xcb.h>
#include "data.h" #include "data.h"
#include "config.h"
extern int yylex(void); extern int yylex(void);
extern FILE *yyin; extern FILE *yyin;
@ -19,31 +20,32 @@ int yywrap() {
} }
void parse_file(const char *f) { void parse_file(const char *f) {
printf("opening %s\n", f); printf("opening %s\n", f);
if ((yyin = fopen(f, "r")) == NULL) { if ((yyin = fopen(f, "r")) == NULL) {
perror("fopen"); perror("fopen");
exit(1); exit(1);
} }
if (yyparse() != 0) { if (yyparse() != 0) {
fprintf(stderr, "Could not parse configfile\n"); fprintf(stderr, "Could not parse configfile\n");
exit(1); exit(1);
} }
fclose(yyin); fclose(yyin);
} }
#if 0 #if 0
main() main()
{ {
yyparse(); yyparse();
printf("parsing done\n"); printf("parsing done\n");
} }
#endif #endif
%} %}
%union { %union {
int number; int number;
char *string; char *string;
struct Colortriple *color;
} }
%token <number>NUMBER %token <number>NUMBER
@ -76,146 +78,151 @@ main()
lines: /* empty */ lines: /* empty */
| lines WHITESPACE line | lines WHITESPACE line
| lines line | lines line
; ;
line: line:
bind bind
| bindsym | bindsym
| floating_modifier | floating_modifier
| workspace | workspace
| assign | assign
| set | set
| ipcsocket | ipcsocket
| exec | exec
| color | color
| terminal | terminal
| font | font
| comment | comment
; ;
comment: comment:
TOKCOMMENT TOKCOMMENT
; ;
command: command:
STR STR
; ;
bind: 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: 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: floating_modifier:
TOKFLOATING_MODIFIER WHITESPACE binding_modifiers TOKFLOATING_MODIFIER WHITESPACE binding_modifiers
{ {
printf("\tfloating modifier %d\n", $<number>3); printf("\tfloating modifier %d\n", $<number>3);
} }
; ;
workspace: workspace:
TOKWORKSPACE WHITESPACE NUMBER WHITESPACE TOKSCREEN WHITESPACE screen 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); printf("\t quoted: %s\n", $<string>9);
} }
; ;
workspace_name:
QUOTEDSTRING
| STR
;
screen: 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: assign:
TOKASSIGN WHITESPACE window_class WHITESPACE optional_arrow NUMBER TOKASSIGN WHITESPACE window_class WHITESPACE optional_arrow NUMBER
{ {
printf("assignment of %s to %d\n", $<string>3, $<number>6); printf("assignment of %s to %d\n", $<string>3, $<number>6);
} }
; ;
window_class: window_class:
QUOTEDSTRING QUOTEDSTRING
| STR_NG | STR_NG
; ;
optional_arrow: optional_arrow:
/* NULL */ /* NULL */
| TOKARROW WHITESPACE | TOKARROW WHITESPACE
; ;
set: set:
TOKSET WHITESPACE variable WHITESPACE STR TOKSET WHITESPACE variable WHITESPACE STR
{ {
printf("set %s to %s\n", $<string>3, $<string>5); printf("set %s to %s\n", $<string>3, $<string>5);
} }
; ;
variable: variable:
'$' WORD { asprintf(&$<string>$, "$%s", $<string>2); } '$' WORD { asprintf(&$<string>$, "$%s", $<string>2); }
| '$' VARNAME { asprintf(&$<string>$, "$%s", $<string>2); } | '$' VARNAME { asprintf(&$<string>$, "$%s", $<string>2); }
; ;
ipcsocket: ipcsocket:
TOKIPCSOCKET WHITESPACE STR TOKIPCSOCKET WHITESPACE STR
{ {
printf("ipc %s\n", $<string>3); printf("ipc %s\n", $<string>3);
} }
; ;
exec: exec:
TOKEXEC WHITESPACE STR TOKEXEC WHITESPACE STR
{ {
printf("exec %s\n", $<string>3); printf("exec %s\n", $<string>3);
} }
; ;
terminal: terminal:
TOKTERMINAL WHITESPACE STR TOKTERMINAL WHITESPACE STR
{ {
printf("terminal %s\n", $<string>3); printf("terminal %s\n", $<string>3);
} }
; ;
font: font:
TOKFONT WHITESPACE STR TOKFONT WHITESPACE STR
{ {
printf("font %s\n", $<string>3); printf("font %s\n", $<string>3);
} }
; ;
color: 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_modifiers:
binding_modifier /* NULL */ { $<number>$ = 0; }
| | binding_modifier
binding_modifiers '+' binding_modifier | binding_modifiers '+' binding_modifier { $<number>$ = $<number>1 | $<number>3; }
{ | binding_modifiers '+' { $<number>$ = $<number>1; }
$<number>$ = $<number>1 | $<number>3; ;
}
;
binding_modifier: binding_modifier:
MODIFIER { $<number>$ = $<number>1; } MODIFIER { $<number>$ = $<number>1; }
| TOKCONTROL { $<number>$ = BIND_CONTROL; } | TOKCONTROL { $<number>$ = BIND_CONTROL; }
| TOKSHIFT { $<number>$ = BIND_SHIFT; } | TOKSHIFT { $<number>$ = BIND_SHIFT; }
; ;