cmdyycolumn += yyleng; \
}
+/* macro to first eat whitespace, then expect a string */
+#define WS_STRING do { \
+ yy_push_state(WANT_STRING); \
+ yy_push_state(EAT_WHITESPACE); \
+} while (0)
+
%}
EOL (\r?\n)
/* handle everything up to \n as a string */
%s WANT_STRING
-/* first expect a whitespace, then a string */
-%s WANT_WS_STRING
+/* eat a whitespace, then go to the next state on the stack */
+%s EAT_WHITESPACE
/* handle a quoted string or everything up to the next whitespace */
%s WANT_QSTRING
cmdyycolumn = 1;
}
-<WANT_WS_STRING>[ \t]* { BEGIN(WANT_STRING); return WHITESPACE; }
<WANT_STRING>\"[^\"]+\" {
BEGIN(INITIAL);
/* strip quotes */
copy[strlen(copy)-1] = '\0';
cmdyylval.string = copy;
return STR;
- }
-<WANT_QSTRING>\"[^\"]+\" {
+ }
+<WANT_QSTRING>\"[^\"]+\" {
BEGIN(INITIAL);
/* strip quotes */
char *copy = sstrdup(yytext+1);
copy[strlen(copy)-1] = '\0';
cmdyylval.string = copy;
return STR;
- }
+ }
+
+<WANT_STRING>[^;\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
-<WANT_STRING>[^;\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
+<EAT_WHITESPACE>[;\n] { BEGIN(INITIAL); return ';'; }
+<EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
-[ \t]* { return WHITESPACE; }
+[ \t]* { /* ignore whitespace */ ; }
attach { return TOK_ATTACH; }
-exec { BEGIN(WANT_WS_STRING); return TOK_EXEC; }
+exec { WS_STRING; return TOK_EXEC; }
exit { return TOK_EXIT; }
reload { return TOK_RELOAD; }
restart { return TOK_RESTART; }
tiling { return TOK_TILING; }
floating { return TOK_FLOATING; }
toggle { return TOK_TOGGLE; }
-workspace { BEGIN(WANT_WS_STRING); return TOK_WORKSPACE; }
+workspace { WS_STRING; return TOK_WORKSPACE; }
focus { return TOK_FOCUS; }
move { return TOK_MOVE; }
open { return TOK_OPEN; }
px { return TOK_PX; }
or { return TOK_OR; }
ppt { return TOK_PPT; }
-nop { BEGIN(WANT_WS_STRING); return TOK_NOP; }
-restore { BEGIN(WANT_WS_STRING); return TOK_RESTORE; }
-mark { BEGIN(WANT_WS_STRING); return TOK_MARK; }
+nop { WS_STRING; return TOK_NOP; }
+restore { WS_STRING; return TOK_RESTORE; }
+mark { WS_STRING; return TOK_MARK; }
class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
id { BEGIN(WANT_QSTRING); return TOK_ID; }
%}
-%expect 5
%error-verbose
%lex-param { struct context *context }
int number;
}
-%token TOK_ATTACH "attach"
%token TOK_EXEC "exec"
%token TOK_EXIT "exit"
%token TOK_RELOAD "reload"
%token TOK_ID "id"
%token TOK_CON_ID "con_id"
-%token WHITESPACE "<whitespace>"
%token <string> STR "<string>"
%token <number> NUMBER "<number>"
%%
commands:
- commands optwhitespace ';' optwhitespace command
+ commands ';' command
| command
{
owindow *current;
}
;
-optwhitespace:
- | WHITESPACE
- ;
-
command:
- match optwhitespace operations
+ match operations
;
match:
- | matchstart optwhitespace criteria optwhitespace matchend
+ | matchstart criteria matchend
{
printf("match parsed\n");
}
;
operations:
- operation optwhitespace
- | operations ',' optwhitespace operation
+ operation
+ | operations ',' operation
;
operation:
| restore
| move
| workspace
- | attach
| focus
| kill
| open
;
exec:
- TOK_EXEC WHITESPACE STR
+ TOK_EXEC STR
{
- printf("should execute %s\n", $3);
- start_application($3);
- free($3);
+ printf("should execute %s\n", $2);
+ start_application($2);
+ free($2);
}
;
}
;
-attach:
- TOK_ATTACH
- {
- printf("should attach\n");
- }
- ;
-
focus:
TOK_FOCUS
{
optional_kill_mode:
/* empty */ { $$ = KILL_WINDOW; }
- | WHITESPACE { $$ = KILL_WINDOW; }
- | WHITESPACE TOK_WINDOW { $$ = KILL_WINDOW; }
- | WHITESPACE TOK_CLIENT { $$ = KILL_CLIENT; }
+ | TOK_WINDOW { $$ = KILL_WINDOW; }
+ | TOK_CLIENT { $$ = KILL_CLIENT; }
;
workspace:
- TOK_WORKSPACE WHITESPACE STR
+ TOK_WORKSPACE STR
{
- printf("should switch to workspace %s\n", $3);
- workspace_show($3);
- free($3);
+ printf("should switch to workspace %s\n", $2);
+ workspace_show($2);
+ free($2);
}
;
;
next:
- TOK_NEXT WHITESPACE direction
+ TOK_NEXT direction
{
/* TODO: use matches */
- printf("should select next window in direction %c\n", $3);
- tree_next('n', ($3 == 'v' ? VERT : HORIZ));
+ printf("should select next window in direction %c\n", $2);
+ tree_next('n', ($2 == 'v' ? VERT : HORIZ));
}
;
prev:
- TOK_PREV WHITESPACE direction
+ TOK_PREV direction
{
/* TODO: use matches */
- printf("should select prev window in direction %c\n", $3);
- tree_next('p', ($3 == 'v' ? VERT : HORIZ));
+ printf("should select prev window in direction %c\n", $2);
+ tree_next('p', ($2 == 'v' ? VERT : HORIZ));
}
;
split:
- TOK_SPLIT WHITESPACE direction
+ TOK_SPLIT direction
{
/* TODO: use matches */
- printf("splitting in direction %c\n", $3);
- tree_split(focused, ($3 == 'v' ? VERT : HORIZ));
+ printf("splitting in direction %c\n", $2);
+ tree_split(focused, ($2 == 'v' ? VERT : HORIZ));
}
;
;
mode:
- TOK_MODE WHITESPACE window_mode
+ TOK_MODE window_mode
{
HANDLE_EMPTY_MATCH;
owindow *current;
TAILQ_FOREACH(current, &owindows, owindows) {
printf("matching: %p / %s\n", current->con, current->con->name);
- if ($3 == TOK_TOGGLE) {
+ if ($2 == TOK_TOGGLE) {
printf("should toggle mode\n");
toggle_floating_mode(current->con, false);
} else {
- printf("should switch mode to %s\n", ($3 == TOK_FLOATING ? "floating" : "tiling"));
- if ($3 == TOK_FLOATING) {
+ printf("should switch mode to %s\n", ($2 == TOK_FLOATING ? "floating" : "tiling"));
+ if ($2 == TOK_FLOATING) {
floating_enable(current->con, false);
} else {
floating_disable(current->con, false);
;
border:
- TOK_BORDER WHITESPACE border_style
+ TOK_BORDER border_style
{
- printf("border style should be changed to %d\n", $3);
+ printf("border style should be changed to %d\n", $2);
owindow *current;
HANDLE_EMPTY_MATCH;
TAILQ_FOREACH(current, &owindows, owindows) {
printf("matching: %p / %s\n", current->con, current->con->name);
- current->con->border_style = $3;
+ current->con->border_style = $2;
}
}
;
level:
- TOK_LEVEL WHITESPACE level_direction
+ TOK_LEVEL level_direction
{
- printf("level %c\n", $3);
- if ($3 == 'u')
+ printf("level %c\n", $2);
+ if ($2 == 'u')
level_up();
else level_down();
}
;
move:
- TOK_MOVE WHITESPACE direction
+ TOK_MOVE direction
{
- printf("moving in direction %d\n", $3);
- tree_move($3);
+ printf("moving in direction %d\n", $2);
+ tree_move($2);
}
- | TOK_MOVE WHITESPACE TOK_WORKSPACE WHITESPACE STR
+ | TOK_MOVE TOK_WORKSPACE STR
{
owindow *current;
- printf("should move window to workspace %s\n", $5);
+ printf("should move window to workspace %s\n", $3);
/* get the workspace */
- Con *ws = workspace_get($5, NULL);
- free($5);
+ Con *ws = workspace_get($3, NULL);
+ free($3);
HANDLE_EMPTY_MATCH;
;
restore:
- TOK_RESTORE WHITESPACE STR
+ TOK_RESTORE STR
{
- printf("restoring \"%s\"\n", $3);
- tree_append_json($3);
- free($3);
+ printf("restoring \"%s\"\n", $2);
+ tree_append_json($2);
+ free($2);
}
;
layout:
- TOK_LAYOUT WHITESPACE layout_mode
+ TOK_LAYOUT layout_mode
{
- printf("changing layout to %d\n", $3);
+ printf("changing layout to %d\n", $2);
owindow *current;
/* check if the match is empty, not if the result is empty */
if (match_is_empty(¤t_match))
- con_set_layout(focused->parent, $3);
+ con_set_layout(focused->parent, $2);
else {
TAILQ_FOREACH(current, &owindows, owindows) {
printf("matching: %p / %s\n", current->con, current->con->name);
- con_set_layout(current->con, $3);
+ con_set_layout(current->con, $2);
}
}
}
;
mark:
- TOK_MARK WHITESPACE STR
+ TOK_MARK STR
{
- printf("marking window with str %s\n", $3);
+ printf("marking window with str %s\n", $2);
owindow *current;
HANDLE_EMPTY_MATCH;
TAILQ_FOREACH(current, &owindows, owindows) {
printf("matching: %p / %s\n", current->con, current->con->name);
- current->con->mark = sstrdup($3);
+ current->con->mark = sstrdup($2);
}
- free($<string>3);
+ free($<string>2);
}
;
nop:
- TOK_NOP WHITESPACE STR
+ TOK_NOP STR
{
printf("-------------------------------------------------\n");
- printf(" NOP: %s\n", $3);
+ printf(" NOP: %s\n", $2);
printf("-------------------------------------------------\n");
- free($3);
+ free($2);
}
;
resize:
- TOK_RESIZE WHITESPACE resize_way WHITESPACE direction resize_px resize_tiling
+ TOK_RESIZE resize_way direction resize_px resize_tiling
{
/* resize <grow|shrink> <direction> [<px> px] [or <ppt> ppt] */
- printf("resizing in way %d, direction %d, px %d or ppt %d\n", $3, $5, $6, $7);
- int direction = $5;
- int px = $6;
- int ppt = $7;
- if ($3 == TOK_SHRINK) {
+ printf("resizing in way %d, direction %d, px %d or ppt %d\n", $2, $3, $4, $5);
+ int direction = $3;
+ int px = $4;
+ int ppt = $5;
+ if ($2 == TOK_SHRINK) {
px *= -1;
ppt *= -1;
}
{
$$ = 10;
}
- | WHITESPACE NUMBER WHITESPACE TOK_PX
+ | NUMBER TOK_PX
{
- $$ = $2;
+ $$ = $1;
}
;
{
$$ = 10;
}
- | WHITESPACE TOK_OR WHITESPACE NUMBER WHITESPACE TOK_PPT
+ | TOK_OR NUMBER TOK_PPT
{
- $$ = $4;
+ $$ = $2;
}
;