diff --git a/src/cfgparse.y b/src/cfgparse.y index 33b8f774..61b67687 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -196,52 +196,71 @@ void parse_file(const char *f) { struct Binding *binding; } -%token NUMBER "" -%token WORD "" -%token STR "" -%token STR_NG "" -%token HEX "" -%token OUTPUT "" -%token TOKBINDCODE -%token TOKTERMINAL -%token TOKCOMMENT "" -%token TOKFONT "font" -%token TOKBINDSYM "bindsym" -%token MODIFIER "" -%token TOKCONTROL "control" -%token TOKSHIFT "shift" -%token WHITESPACE "" -%token TOKFLOATING_MODIFIER "floating_modifier" -%token QUOTEDSTRING "" -%token TOKWORKSPACE "workspace" -%token TOKOUTPUT "output" -%token TOKASSIGN "assign" -%token TOKSET -%token TOKIPCSOCKET "ipc_socket" -%token TOKRESTARTSTATE "restart_state" -%token TOKEXEC "exec" -%token TOKSINGLECOLOR -%token TOKCOLOR -%token TOKARROW "→" -%token TOKMODE "mode" -%token TOK_ORIENTATION "default_orientation" -%token TOK_HORIZ "horizontal" -%token TOK_VERT "vertical" -%token TOK_AUTO "auto" -%token TOK_WORKSPACE_LAYOUT "workspace_layout" -%token TOKNEWWINDOW "new_window" -%token TOK_NORMAL "normal" -%token TOK_NONE "none" -%token TOK_1PIXEL "1pixel" -%token TOKFOCUSFOLLOWSMOUSE "focus_follows_mouse" -%token TOKWORKSPACEBAR "workspace_bar" -%token TOK_DEFAULT "default" -%token TOK_STACKING "stacking" -%token TOK_TABBED "tabbed" -%token TOKSTACKLIMIT "stack-limit" -%token TOK_POPUP_DURING_FULLSCREEN "popup_during_fullscreen" -%token TOK_IGNORE "ignore" -%token TOK_LEAVE_FULLSCREEN "leave_fullscreen" +%token NUMBER "" +%token WORD "" +%token STR "" +%token STR_NG "" +%token HEX "" +%token OUTPUT "" +%token TOKBINDCODE +%token TOKTERMINAL +%token TOKCOMMENT "" +%token TOKFONT "font" +%token TOKBINDSYM "bindsym" +%token MODIFIER "" +%token TOKCONTROL "control" +%token TOKSHIFT "shift" +%token WHITESPACE "" +%token TOKFLOATING_MODIFIER "floating_modifier" +%token QUOTEDSTRING "" +%token TOKWORKSPACE "workspace" +%token TOKOUTPUT "output" +%token TOKASSIGN "assign" +%token TOKSET +%token TOKIPCSOCKET "ipc_socket" +%token TOKRESTARTSTATE "restart_state" +%token TOKEXEC "exec" +%token TOKSINGLECOLOR +%token TOKCOLOR +%token TOKARROW "→" +%token TOKMODE "mode" +%token TOK_ORIENTATION "default_orientation" +%token TOK_HORIZ "horizontal" +%token TOK_VERT "vertical" +%token TOK_AUTO "auto" +%token TOK_WORKSPACE_LAYOUT "workspace_layout" +%token TOKNEWWINDOW "new_window" +%token TOK_NORMAL "normal" +%token TOK_NONE "none" +%token TOK_1PIXEL "1pixel" +%token TOKFOCUSFOLLOWSMOUSE "focus_follows_mouse" +%token TOKWORKSPACEBAR "workspace_bar" +%token TOK_DEFAULT "default" +%token TOK_STACKING "stacking" +%token TOK_TABBED "tabbed" +%token TOKSTACKLIMIT "stack-limit" +%token TOK_POPUP_DURING_FULLSCREEN "popup_during_fullscreen" +%token TOK_IGNORE "ignore" +%token TOK_LEAVE_FULLSCREEN "leave_fullscreen" + +%type binding +%type bindcode +%type bindsym +%type binding_modifiers +%type binding_modifier +%type direction +%type layout_mode +%type border_style +%type new_window +%type colorpixel +%type bool +%type popup_setting +%type command +%type word_or_number +%type optional_workspace_name +%type workspace_name +%type window_class +%type assign_target %% @@ -284,40 +303,40 @@ command: bindline: binding { - TAILQ_INSERT_TAIL(bindings, $1, bindings); + TAILQ_INSERT_TAIL(bindings, $1, bindings); } ; binding: - TOKBINDCODE WHITESPACE bindcode { $$ = $3; } - | TOKBINDSYM WHITESPACE bindsym { $$ = $3; } + TOKBINDCODE WHITESPACE bindcode { $$ = $3; } + | TOKBINDSYM WHITESPACE bindsym { $$ = $3; } ; bindcode: binding_modifiers NUMBER WHITESPACE command { - printf("\tFound keycode binding mod%d with key %d and command %s\n", $1, $2, $4); + printf("\tFound keycode binding mod%d with key %d and command %s\n", $1, $2, $4); Binding *new = scalloc(sizeof(Binding)); - new->keycode = $2; - new->mods = $1; - new->command = $4; + new->keycode = $2; + new->mods = $1; + new->command = $4; - $$ = new; + $$ = new; } ; bindsym: binding_modifiers word_or_number WHITESPACE command { - printf("\tFound keysym binding mod%d with key %s and command %s\n", $1, $2, $4); + printf("\tFound keysym binding mod%d with key %s and command %s\n", $1, $2, $4); Binding *new = scalloc(sizeof(Binding)); - new->symbol = $2; - new->mods = $1; - new->command = $4; + new->symbol = $2; + new->mods = $1; + new->command = $4; - $$ = new; + $$ = new; } ; @@ -325,18 +344,18 @@ word_or_number: WORD | NUMBER { - asprintf(&$$, "%d", $1); + asprintf(&$$, "%d", $1); } ; mode: TOKMODE WHITESPACE QUOTEDSTRING WHITESPACE '{' modelines '}' { - if (strcasecmp($3, "default") == 0) { + if (strcasecmp($3, "default") == 0) { printf("You cannot use the name \"default\" for your mode\n"); exit(1); } - printf("\t now in mode %s\n", $3); + printf("\t now in mode %s\n", $3); printf("\t current bindings = %p\n", current_bindings); Binding *binding; TAILQ_FOREACH(binding, current_bindings, bindings) { @@ -345,7 +364,7 @@ mode: } struct Mode *mode = scalloc(sizeof(struct Mode)); - mode->name = $3; + mode->name = $3; mode->bindings = current_bindings; current_bindings = NULL; SLIST_INSERT_HEAD(&modes, mode, modes); @@ -368,37 +387,37 @@ modeline: TAILQ_INIT(current_bindings); } - TAILQ_INSERT_TAIL(current_bindings, $1, bindings); + TAILQ_INSERT_TAIL(current_bindings, $1, bindings); } ; floating_modifier: TOKFLOATING_MODIFIER WHITESPACE binding_modifiers { - DLOG("floating modifier = %d\n", $3); - config.floating_modifier = $3; + DLOG("floating modifier = %d\n", $3); + config.floating_modifier = $3; } ; orientation: TOK_ORIENTATION WHITESPACE direction { - DLOG("New containers should start with split direction %d\n", $3); - config.default_orientation = $3; + DLOG("New containers should start with split direction %d\n", $3); + config.default_orientation = $3; } ; direction: - TOK_HORIZ { $$ = HORIZ; } - | TOK_VERT { $$ = VERT; } - | TOK_AUTO { $$ = NO_ORIENTATION; } + TOK_HORIZ { $$ = HORIZ; } + | TOK_VERT { $$ = VERT; } + | TOK_AUTO { $$ = NO_ORIENTATION; } ; workspace_layout: TOK_WORKSPACE_LAYOUT WHITESPACE layout_mode { - DLOG("new containers will be in mode %d\n", $3); - config.default_layout = $3; + DLOG("new containers will be in mode %d\n", $3); + config.default_layout = $3; #if 0 /* We also need to change the layout of the already existing @@ -421,9 +440,9 @@ workspace_layout: } | TOK_WORKSPACE_LAYOUT WHITESPACE TOKSTACKLIMIT WHITESPACE TOKSTACKLIMIT WHITESPACE NUMBER { - DLOG("stack-limit %d with val %d\n", $5, $7); - config.container_stack_limit = $5; - config.container_stack_limit_value = $7; + DLOG("stack-limit %d with val %d\n", $5, $7); + config.container_stack_limit = $5; + config.container_stack_limit_value = $7; #if 0 /* See the comment above */ @@ -440,61 +459,61 @@ workspace_layout: ; layout_mode: - TOK_DEFAULT { $$ = L_DEFAULT; } - | TOK_STACKING { $$ = L_STACKED; } - | TOK_TABBED { $$ = L_TABBED; } + TOK_DEFAULT { $$ = L_DEFAULT; } + | TOK_STACKING { $$ = L_STACKED; } + | TOK_TABBED { $$ = L_TABBED; } ; new_window: TOKNEWWINDOW WHITESPACE border_style { - DLOG("new windows should start with border style %d\n", $3); - config.default_border = $3; + DLOG("new windows should start with border style %d\n", $3); + config.default_border = $3; } ; border_style: - TOK_NORMAL { $$ = BS_NORMAL; } - | TOK_NONE { $$ = BS_NONE; } - | TOK_1PIXEL { $$ = BS_1PIXEL; } + TOK_NORMAL { $$ = BS_NORMAL; } + | TOK_NONE { $$ = BS_NONE; } + | TOK_1PIXEL { $$ = BS_1PIXEL; } ; bool: NUMBER { - $$ = ($1 == 1); + $$ = ($1 == 1); } | WORD { - DLOG("checking word \"%s\"\n", $1); - $$ = (strcasecmp($1, "yes") == 0 || - strcasecmp($1, "true") == 0 || - strcasecmp($1, "on") == 0 || - strcasecmp($1, "enable") == 0 || - strcasecmp($1, "active") == 0); + DLOG("checking word \"%s\"\n", $1); + $$ = (strcasecmp($1, "yes") == 0 || + strcasecmp($1, "true") == 0 || + strcasecmp($1, "on") == 0 || + strcasecmp($1, "enable") == 0 || + strcasecmp($1, "active") == 0); } ; focus_follows_mouse: TOKFOCUSFOLLOWSMOUSE WHITESPACE bool { - DLOG("focus follows mouse = %d\n", $3); - config.disable_focus_follows_mouse = !($3); + DLOG("focus follows mouse = %d\n", $3); + config.disable_focus_follows_mouse = !($3); } ; workspace_bar: TOKWORKSPACEBAR WHITESPACE bool { - DLOG("workspace bar = %d\n", $3); - config.disable_workspace_bar = !($3); + DLOG("workspace bar = %d\n", $3); + config.disable_workspace_bar = !($3); } ; workspace: TOKWORKSPACE WHITESPACE NUMBER WHITESPACE TOKOUTPUT WHITESPACE OUTPUT optional_workspace_name { - int ws_num = $3; + int ws_num = $3; if (ws_num < 1) { DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); } else { @@ -510,11 +529,11 @@ workspace: } | TOKWORKSPACE WHITESPACE NUMBER WHITESPACE workspace_name { - int ws_num = $3; + int ws_num = $3; if (ws_num < 1) { DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); } else { - DLOG("workspace name to: %s\n", $5); + DLOG("workspace name to: %s\n", $5); #if 0 if ($5 != NULL) { workspace_set_name(workspace_get(ws_num - 1), $5); @@ -526,31 +545,31 @@ workspace: ; optional_workspace_name: - /* empty */ { $$ = NULL; } - | WHITESPACE workspace_name { $$ = $2; } + /* empty */ { $$ = NULL; } + | WHITESPACE workspace_name { $$ = $2; } ; workspace_name: - QUOTEDSTRING { $$ = $1; } - | STR { $$ = $1; } - | WORD { $$ = $1; } + QUOTEDSTRING { $$ = $1; } + | STR { $$ = $1; } + | WORD { $$ = $1; } ; assign: TOKASSIGN WHITESPACE window_class WHITESPACE optional_arrow assign_target { - printf("assignment of %s\n", $3); + printf("assignment of %s\n", $3); - struct Match *match = $6; + struct Match *match = $6; char *separator = NULL; - if ((separator = strchr($3, '/')) != NULL) { + if ((separator = strchr($3, '/')) != NULL) { *(separator++) = '\0'; match->title = sstrdup(separator); } - if (*$3 != '\0') - match->class = sstrdup($3); - free($3); + if (*$3 != '\0') + match->class = sstrdup($3); + free($3); printf(" class = %s\n", match->class); printf(" title = %s\n", match->title); @@ -567,8 +586,8 @@ assign_target: Match *match = smalloc(sizeof(Match)); match_init(match); match->insert_where = M_ASSIGN_WS; - asprintf(&(match->target_ws), "%d", $1); - $$ = match; + asprintf(&(match->target_ws), "%d", $1); + $$ = match; } | '~' { @@ -604,14 +623,14 @@ optional_arrow: ipcsocket: TOKIPCSOCKET WHITESPACE STR { - config.ipc_socket_path = $3; + config.ipc_socket_path = $3; } ; restart_state: TOKRESTARTSTATE WHITESPACE STR { - config.restart_state_path = $3; + config.restart_state_path = $3; } ; @@ -619,7 +638,7 @@ exec: TOKEXEC WHITESPACE STR { struct Autostart *new = smalloc(sizeof(struct Autostart)); - new->command = $3; + new->command = $3; TAILQ_INSERT_TAIL(&autostarts, new, autostarts); } ; @@ -635,27 +654,27 @@ terminal: font: TOKFONT WHITESPACE STR { - config.font = load_font($3, true); - printf("font %s\n", $3); + config.font = load_font($3, true); + printf("font %s\n", $3); } ; single_color: TOKSINGLECOLOR WHITESPACE colorpixel { - uint32_t *dest = $1; - *dest = $3; + uint32_t *dest = $1; + *dest = $3; } ; color: TOKCOLOR WHITESPACE colorpixel WHITESPACE colorpixel WHITESPACE colorpixel { - struct Colortriple *dest = $1; + struct Colortriple *dest = $1; - dest->border = $3; - dest->background = $5; - dest->text = $7; + dest->border = $3; + dest->background = $5; + dest->text = $7; } ; @@ -663,36 +682,36 @@ colorpixel: '#' HEX { char *hex; - if (asprintf(&hex, "#%s", $2) == -1) + if (asprintf(&hex, "#%s", $2) == -1) die("asprintf()"); - $$ = get_colorpixel(hex); + $$ = get_colorpixel(hex); free(hex); } ; binding_modifiers: - /* NULL */ { $$ = 0; } + /* NULL */ { $$ = 0; } | binding_modifier - | binding_modifiers '+' binding_modifier { $$ = $1 | $3; } - | binding_modifiers '+' { $$ = $1; } + | binding_modifiers '+' binding_modifier { $$ = $1 | $3; } + | binding_modifiers '+' { $$ = $1; } ; binding_modifier: - MODIFIER { $$ = $1; } - | TOKCONTROL { $$ = BIND_CONTROL; } - | TOKSHIFT { $$ = BIND_SHIFT; } + MODIFIER { $$ = $1; } + | TOKCONTROL { $$ = BIND_CONTROL; } + | TOKSHIFT { $$ = BIND_SHIFT; } ; popup_during_fullscreen: TOK_POPUP_DURING_FULLSCREEN WHITESPACE popup_setting { - DLOG("popup_during_fullscreen setting: %d\n", $3); - config.popup_during_fullscreen = $3; + DLOG("popup_during_fullscreen setting: %d\n", $3); + config.popup_during_fullscreen = $3; } ; popup_setting: - TOK_IGNORE { $$ = PDF_IGNORE; } - | TOK_LEAVE_FULLSCREEN { $$ = PDF_LEAVE_FULLSCREEN; } + TOK_IGNORE { $$ = PDF_IGNORE; } + | TOK_LEAVE_FULLSCREEN { $$ = PDF_LEAVE_FULLSCREEN; } ;