]> git.sur5r.net Git - i3/i3/blob - src/cmdparse.y
add i3-nagbar. tells you about config file errors (for example)
[i3/i3] / src / cmdparse.y
1 %{
2 /*
3  * vim:ts=4:sw=4:expandtab
4  *
5  * i3 - an improved dynamic tiling window manager
6  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
7  *
8  * cmdparse.y: the parser for commands you send to i3 (or bind on keys)
9  *
10
11  */
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 #include <fcntl.h>
16 #include <limits.h>
17
18 #include "all.h"
19
20 /** When the command did not include match criteria (!), we use the currently
21  * focused command. Do not confuse this case with a command which included
22  * criteria but which did not match any windows. This macro has to be called in
23  * every command.
24  */
25 #define HANDLE_EMPTY_MATCH do { \
26     if (match_is_empty(&current_match)) { \
27         owindow *ow = smalloc(sizeof(owindow)); \
28         ow->con = focused; \
29         TAILQ_INIT(&owindows); \
30         TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
31     } \
32 } while (0)
33
34 typedef struct yy_buffer_state *YY_BUFFER_STATE;
35 extern int cmdyylex(struct context *context);
36 extern int cmdyyparse(void);
37 extern FILE *cmdyyin;
38 YY_BUFFER_STATE cmdyy_scan_string(const char *);
39
40 static struct context *context;
41 static Match current_match;
42
43 /*
44  * Helper data structure for an operation window (window on which the operation
45  * will be performed). Used to build the TAILQ owindows.
46  *
47  */
48 typedef struct owindow {
49     Con *con;
50     TAILQ_ENTRY(owindow) owindows;
51 } owindow;
52 static TAILQ_HEAD(owindows_head, owindow) owindows;
53
54 /* Holds the JSON which will be returned via IPC or NULL for the default return
55  * message */
56 static char *json_output;
57
58 /* We don’t need yydebug for now, as we got decent error messages using
59  * yyerror(). Should you ever want to extend the parser, it might be handy
60  * to just comment it in again, so it stays here. */
61 //int cmdyydebug = 1;
62
63 void cmdyyerror(const char *error_message) {
64     ELOG("\n");
65     ELOG("CMD: %s\n", error_message);
66     ELOG("CMD: in command:\n");
67     ELOG("CMD:   %s\n", context->line_copy);
68     ELOG("CMD:   ");
69     for (int c = 1; c <= context->last_column; c++)
70         if (c >= context->first_column)
71                 printf("^");
72         else printf(" ");
73     printf("\n");
74     ELOG("\n");
75     context->compact_error = sstrdup(error_message);
76 }
77
78 int cmdyywrap() {
79     return 1;
80 }
81
82 char *parse_cmd(const char *new) {
83     LOG("COMMAND: *%s*\n", new);
84     cmdyy_scan_string(new);
85
86     match_init(&current_match);
87     context = scalloc(sizeof(struct context));
88     context->filename = "cmd";
89     FREE(json_output);
90     if (cmdyyparse() != 0) {
91         fprintf(stderr, "Could not parse command\n");
92         asprintf(&json_output, "{\"success\":false, \"error\":\"%s at position %d\"}",
93                  context->compact_error, context->first_column);
94         FREE(context->line_copy);
95         FREE(context->compact_error);
96         free(context);
97         return json_output;
98     }
99     printf("done, json output = %s\n", json_output);
100
101     FREE(context->line_copy);
102     FREE(context->compact_error);
103     free(context);
104     return json_output;
105 }
106
107 %}
108
109 %error-verbose
110 %lex-param { struct context *context }
111
112 %union {
113     char *string;
114     char chr;
115     int number;
116 }
117
118 %token              TOK_EXEC            "exec"
119 %token              TOK_EXIT            "exit"
120 %token              TOK_RELOAD          "reload"
121 %token              TOK_RESTART         "restart"
122 %token              TOK_KILL            "kill"
123 %token              TOK_WINDOW          "window"
124 %token              TOK_CLIENT          "client"
125 %token              TOK_FULLSCREEN      "fullscreen"
126 %token              TOK_GLOBAL          "global"
127 %token              TOK_LAYOUT          "layout"
128 %token              TOK_DEFAULT         "default"
129 %token              TOK_STACKED         "stacked"
130 %token              TOK_TABBED          "tabbed"
131 %token              TOK_BORDER          "border"
132 %token              TOK_NORMAL          "normal"
133 %token              TOK_NONE            "none"
134 %token              TOK_1PIXEL          "1pixel"
135 %token              TOK_MODE            "mode"
136 %token              TOK_TILING          "tiling"
137 %token              TOK_FLOATING        "floating"
138 %token              TOK_MODE_TOGGLE     "mode_toggle"
139 %token              TOK_ENABLE          "enable"
140 %token              TOK_DISABLE         "disable"
141 %token              TOK_WORKSPACE       "workspace"
142 %token              TOK_TOGGLE          "toggle"
143 %token              TOK_FOCUS           "focus"
144 %token              TOK_MOVE            "move"
145 %token              TOK_OPEN            "open"
146 %token              TOK_NEXT            "next"
147 %token              TOK_PREV            "prev"
148 %token              TOK_SPLIT           "split"
149 %token              TOK_HORIZONTAL      "horizontal"
150 %token              TOK_VERTICAL        "vertical"
151 %token              TOK_UP              "up"
152 %token              TOK_DOWN            "down"
153 %token              TOK_LEFT            "left"
154 %token              TOK_RIGHT           "right"
155 %token              TOK_PARENT          "parent"
156 %token              TOK_CHILD           "child"
157 %token              TOK_APPEND_LAYOUT   "append_layout"
158 %token              TOK_MARK            "mark"
159 %token              TOK_RESIZE          "resize"
160 %token              TOK_GROW            "grow"
161 %token              TOK_SHRINK          "shrink"
162 %token              TOK_PX              "px"
163 %token              TOK_OR              "or"
164 %token              TOK_PPT             "ppt"
165 %token              TOK_NOP             "nop"
166
167 %token              TOK_CLASS           "class"
168 %token              TOK_ID              "id"
169 %token              TOK_CON_ID          "con_id"
170 %token              TOK_TITLE           "title"
171
172 %token  <string>    STR                 "<string>"
173 %token  <number>    NUMBER              "<number>"
174
175 %type   <number>    direction
176 %type   <number>    split_direction
177 %type   <number>    fullscreen_mode
178 %type   <number>    level
179 %type   <number>    window_mode
180 %type   <number>    boolean
181 %type   <number>    border_style
182 %type   <number>    layout_mode
183 %type   <number>    resize_px
184 %type   <number>    resize_way
185 %type   <number>    resize_tiling
186 %type   <number>    optional_kill_mode
187
188 %%
189
190 commands:
191     commands ';' command
192     | command
193     {
194         owindow *current;
195
196         printf("single command completely parsed, dropping state...\n");
197         while (!TAILQ_EMPTY(&owindows)) {
198             current = TAILQ_FIRST(&owindows);
199             TAILQ_REMOVE(&owindows, current, owindows);
200             free(current);
201         }
202         match_init(&current_match);
203     }
204     ;
205
206 command:
207     match operations
208     ;
209
210 match:
211     | matchstart criteria matchend
212     {
213         printf("match parsed\n");
214     }
215     ;
216
217 matchstart:
218     '['
219     {
220         printf("start\n");
221         match_init(&current_match);
222         TAILQ_INIT(&owindows);
223         /* copy all_cons */
224         Con *con;
225         TAILQ_FOREACH(con, &all_cons, all_cons) {
226             owindow *ow = smalloc(sizeof(owindow));
227             ow->con = con;
228             TAILQ_INSERT_TAIL(&owindows, ow, owindows);
229         }
230     }
231     ;
232
233 matchend:
234     ']'
235     {
236         owindow *next, *current;
237
238         printf("match specification finished, matching...\n");
239         /* copy the old list head to iterate through it and start with a fresh
240          * list which will contain only matching windows */
241         struct owindows_head old = owindows;
242         TAILQ_INIT(&owindows);
243         for (next = TAILQ_FIRST(&old); next != TAILQ_END(&old);) {
244             /* make a copy of the next pointer and advance the pointer to the
245              * next element as we are going to invalidate the element’s
246              * next/prev pointers by calling TAILQ_INSERT_TAIL later */
247             current = next;
248             next = TAILQ_NEXT(next, owindows);
249
250             printf("checking if con %p / %s matches\n", current->con, current->con->name);
251             if (current_match.con_id != NULL) {
252                 if (current_match.con_id == current->con) {
253                     printf("matches container!\n");
254                     TAILQ_INSERT_TAIL(&owindows, current, owindows);
255
256                 }
257             } else if (current_match.mark != NULL && current->con->mark != NULL &&
258                     strcasecmp(current_match.mark, current->con->mark) == 0) {
259                 printf("match by mark\n");
260                     TAILQ_INSERT_TAIL(&owindows, current, owindows);
261
262             } else {
263                 if (current->con->window == NULL)
264                     continue;
265                 if (match_matches_window(&current_match, current->con->window)) {
266                     printf("matches window!\n");
267                     TAILQ_INSERT_TAIL(&owindows, current, owindows);
268                 } else {
269                     printf("doesnt match\n");
270                     free(current);
271                 }
272             }
273         }
274
275         TAILQ_FOREACH(current, &owindows, owindows) {
276             printf("matching: %p / %s\n", current->con, current->con->name);
277         }
278
279     }
280     ;
281
282 criteria:
283     criteria criterion
284     | criterion
285     ;
286
287 criterion:
288     TOK_CLASS '=' STR
289     {
290         printf("criteria: class = %s\n", $3);
291         current_match.class = $3;
292     }
293     | TOK_CON_ID '=' STR
294     {
295         printf("criteria: id = %s\n", $3);
296         char *end;
297         long parsed = strtol($3, &end, 10);
298         if (parsed == LONG_MIN ||
299             parsed == LONG_MAX ||
300             parsed < 0 ||
301             (end && *end != '\0')) {
302             ELOG("Could not parse con id \"%s\"\n", $3);
303         } else {
304             current_match.con_id = (Con*)parsed;
305             printf("id as int = %p\n", current_match.con_id);
306         }
307     }
308     | TOK_ID '=' STR
309     {
310         printf("criteria: window id = %s\n", $3);
311         char *end;
312         long parsed = strtol($3, &end, 10);
313         if (parsed == LONG_MIN ||
314             parsed == LONG_MAX ||
315             parsed < 0 ||
316             (end && *end != '\0')) {
317             ELOG("Could not parse window id \"%s\"\n", $3);
318         } else {
319             current_match.id = parsed;
320             printf("window id as int = %d\n", current_match.id);
321         }
322     }
323     | TOK_MARK '=' STR
324     {
325         printf("criteria: mark = %s\n", $3);
326         current_match.mark = $3;
327     }
328     | TOK_TITLE '=' STR
329     {
330         printf("criteria: title = %s\n", $3);
331         current_match.title = $3;
332     }
333     ;
334
335 operations:
336     operation
337     | operations ',' operation
338     ;
339
340 operation:
341     exec
342     | exit
343     | restart
344     | reload
345     | border
346     | layout
347     | append_layout
348     | move
349     | workspace
350     | focus
351     | kill
352     | open
353     | fullscreen
354     | split
355     | floating
356     | mark
357     | resize
358     | nop
359     | mode
360     ;
361
362 exec:
363     TOK_EXEC STR
364     {
365         printf("should execute %s\n", $2);
366         start_application($2);
367         free($2);
368     }
369     ;
370
371 exit:
372     TOK_EXIT
373     {
374         printf("exit, bye bye\n");
375         exit(0);
376     }
377     ;
378
379 reload:
380     TOK_RELOAD
381     {
382         printf("reloading\n");
383         kill_configerror_nagbar(false);
384         load_configuration(conn, NULL, true);
385         x_set_i3_atoms();
386         /* Send an IPC event just in case the ws names have changed */
387         ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"reload\"}");
388     }
389     ;
390
391 restart:
392     TOK_RESTART
393     {
394         printf("restarting i3\n");
395         i3_restart(false);
396     }
397     ;
398
399 focus:
400     TOK_FOCUS
401     {
402         owindow *current;
403
404         if (match_is_empty(&current_match)) {
405             ELOG("You have to specify which window/container should be focused.\n");
406             ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
407
408             asprintf(&json_output, "{\"success\":false, \"error\":\"You have to "
409                      "specify which window/container should be focused\"}");
410             break;
411         }
412
413         int count = 0;
414         TAILQ_FOREACH(current, &owindows, owindows) {
415             LOG("focusing %p / %s\n", current->con, current->con->name);
416             con_focus(current->con);
417             count++;
418         }
419
420         if (count > 1)
421             LOG("WARNING: Your criteria for the focus command matches %d containers, "
422                 "while only exactly one container can be focused at a time.\n", count);
423
424         tree_render();
425     }
426     | TOK_FOCUS direction
427     {
428         int direction = $2;
429         switch (direction) {
430             case TOK_LEFT:
431                 LOG("Focusing left\n");
432                 tree_next('p', HORIZ);
433                 break;
434             case TOK_RIGHT:
435                 LOG("Focusing right\n");
436                 tree_next('n', HORIZ);
437                 break;
438             case TOK_UP:
439                 LOG("Focusing up\n");
440                 tree_next('p', VERT);
441                 break;
442             case TOK_DOWN:
443                 LOG("Focusing down\n");
444                 tree_next('n', VERT);
445                 break;
446             default:
447                 ELOG("Invalid focus direction (%d)\n", direction);
448                 break;
449         }
450
451         tree_render();
452     }
453     | TOK_FOCUS window_mode
454     {
455         printf("should focus: ");
456
457         if ($2 == TOK_TILING)
458             printf("tiling\n");
459         else if ($2 == TOK_FLOATING)
460             printf("floating\n");
461         else printf("mode toggle\n");
462
463         Con *ws = con_get_workspace(focused);
464         Con *current;
465         if (ws != NULL) {
466             int to_focus = $2;
467             if ($2 == TOK_MODE_TOGGLE) {
468                 current = TAILQ_FIRST(&(ws->focus_head));
469                 if (current->type == CT_FLOATING_CON)
470                     to_focus = TOK_TILING;
471                 else to_focus = TOK_FLOATING;
472             }
473             TAILQ_FOREACH(current, &(ws->focus_head), focused) {
474                 if ((to_focus == TOK_FLOATING && current->type != CT_FLOATING_CON) ||
475                     (to_focus == TOK_TILING && current->type == CT_FLOATING_CON))
476                     continue;
477
478                 con_focus(con_descend_focused(current));
479                 break;
480             }
481         }
482
483         tree_render();
484     }
485     | TOK_FOCUS level
486     {
487         if ($2 == TOK_PARENT)
488             level_up();
489         else level_down();
490
491         tree_render();
492     }
493     ;
494
495 window_mode:
496     TOK_TILING        { $$ = TOK_TILING; }
497     | TOK_FLOATING    { $$ = TOK_FLOATING; }
498     | TOK_MODE_TOGGLE { $$ = TOK_MODE_TOGGLE; }
499     ;
500
501 level:
502     TOK_PARENT  { $$ = TOK_PARENT; }
503     | TOK_CHILD { $$ = TOK_CHILD;  }
504     ;
505
506 kill:
507     TOK_KILL optional_kill_mode
508     {
509         owindow *current;
510
511         printf("killing!\n");
512         /* check if the match is empty, not if the result is empty */
513         if (match_is_empty(&current_match))
514             tree_close_con($2);
515         else {
516             TAILQ_FOREACH(current, &owindows, owindows) {
517                 printf("matching: %p / %s\n", current->con, current->con->name);
518                 tree_close(current->con, $2, false);
519             }
520         }
521
522         tree_render();
523     }
524     ;
525
526 optional_kill_mode:
527     /* empty */             { $$ = KILL_WINDOW; }
528     | TOK_WINDOW { $$ = KILL_WINDOW; }
529     | TOK_CLIENT { $$ = KILL_CLIENT; }
530     ;
531
532 workspace:
533     TOK_WORKSPACE TOK_NEXT
534     {
535         workspace_next();
536         tree_render();
537     }
538     | TOK_WORKSPACE TOK_PREV
539     {
540         workspace_prev();
541         tree_render();
542     }
543     | TOK_WORKSPACE STR
544     {
545         printf("should switch to workspace %s\n", $2);
546         workspace_show($2);
547         free($2);
548
549         tree_render();
550     }
551     ;
552
553 open:
554     TOK_OPEN
555     {
556         printf("opening new container\n");
557         Con *con = tree_open_con(NULL, NULL);
558         con_focus(con);
559         asprintf(&json_output, "{\"success\":true, \"id\":%ld}", (long int)con);
560
561         tree_render();
562     }
563     ;
564
565 fullscreen:
566     TOK_FULLSCREEN fullscreen_mode
567     {
568         printf("toggling fullscreen, mode = %s\n", ($2 == CF_OUTPUT ? "normal" : "global"));
569         owindow *current;
570
571         HANDLE_EMPTY_MATCH;
572
573         TAILQ_FOREACH(current, &owindows, owindows) {
574             printf("matching: %p / %s\n", current->con, current->con->name);
575             con_toggle_fullscreen(current->con, $2);
576         }
577
578         tree_render();
579     }
580     ;
581
582 fullscreen_mode:
583     /* empty */  { $$ = CF_OUTPUT; }
584     | TOK_GLOBAL { $$ = CF_GLOBAL; }
585     ;
586
587 split:
588     TOK_SPLIT split_direction
589     {
590         /* TODO: use matches */
591         printf("splitting in direction %c\n", $2);
592         tree_split(focused, ($2 == 'v' ? VERT : HORIZ));
593
594         tree_render();
595     }
596     ;
597
598 split_direction:
599     TOK_HORIZONTAL  { $$ = 'h'; }
600     | 'h'           { $$ = 'h'; }
601     | TOK_VERTICAL  { $$ = 'v'; }
602     | 'v'           { $$ = 'v'; }
603     ;
604
605 floating:
606     TOK_FLOATING boolean
607     {
608         HANDLE_EMPTY_MATCH;
609
610         owindow *current;
611         TAILQ_FOREACH(current, &owindows, owindows) {
612             printf("matching: %p / %s\n", current->con, current->con->name);
613             if ($2 == TOK_TOGGLE) {
614                 printf("should toggle mode\n");
615                 toggle_floating_mode(current->con, false);
616             } else {
617                 printf("should switch mode to %s\n", ($2 == TOK_FLOATING ? "floating" : "tiling"));
618                 if ($2 == TOK_ENABLE) {
619                     floating_enable(current->con, false);
620                 } else {
621                     floating_disable(current->con, false);
622                 }
623             }
624         }
625
626         tree_render();
627     }
628     ;
629
630 boolean:
631     TOK_ENABLE    { $$ = TOK_ENABLE; }
632     | TOK_DISABLE { $$ = TOK_DISABLE; }
633     | TOK_TOGGLE  { $$ = TOK_TOGGLE; }
634     ;
635
636 border:
637     TOK_BORDER border_style
638     {
639         printf("border style should be changed to %d\n", $2);
640         owindow *current;
641
642         HANDLE_EMPTY_MATCH;
643
644         TAILQ_FOREACH(current, &owindows, owindows) {
645             printf("matching: %p / %s\n", current->con, current->con->name);
646             if ($2 == TOK_TOGGLE) {
647                 current->con->border_style++;
648                 current->con->border_style %= 3;
649             } else current->con->border_style = $2;
650         }
651
652         tree_render();
653     }
654     ;
655
656 border_style:
657     TOK_NORMAL      { $$ = BS_NORMAL; }
658     | TOK_NONE      { $$ = BS_NONE; }
659     | TOK_1PIXEL    { $$ = BS_1PIXEL; }
660     | TOK_TOGGLE    { $$ = TOK_TOGGLE; }
661     ;
662
663 move:
664     TOK_MOVE direction
665     {
666         printf("moving in direction %d\n", $2);
667         tree_move($2);
668
669         tree_render();
670     }
671     | TOK_MOVE TOK_WORKSPACE STR
672     {
673         owindow *current;
674
675         printf("should move window to workspace %s\n", $3);
676         /* get the workspace */
677         Con *ws = workspace_get($3, NULL);
678         free($3);
679
680         HANDLE_EMPTY_MATCH;
681
682         TAILQ_FOREACH(current, &owindows, owindows) {
683             printf("matching: %p / %s\n", current->con, current->con->name);
684             con_move_to_workspace(current->con, ws);
685         }
686
687         tree_render();
688     }
689     ;
690
691 append_layout:
692     TOK_APPEND_LAYOUT STR
693     {
694         printf("restoring \"%s\"\n", $2);
695         tree_append_json($2);
696         free($2);
697         tree_render();
698     }
699     ;
700
701 layout:
702     TOK_LAYOUT layout_mode
703     {
704         printf("changing layout to %d\n", $2);
705         owindow *current;
706
707         /* check if the match is empty, not if the result is empty */
708         if (match_is_empty(&current_match))
709             con_set_layout(focused->parent, $2);
710         else {
711             TAILQ_FOREACH(current, &owindows, owindows) {
712                 printf("matching: %p / %s\n", current->con, current->con->name);
713                 con_set_layout(current->con, $2);
714             }
715         }
716
717         tree_render();
718     }
719     ;
720
721 layout_mode:
722     TOK_DEFAULT   { $$ = L_DEFAULT; }
723     | TOK_STACKED { $$ = L_STACKED; }
724     | TOK_TABBED  { $$ = L_TABBED; }
725     ;
726
727 mark:
728     TOK_MARK STR
729     {
730         printf("marking window with str %s\n", $2);
731         owindow *current;
732
733         HANDLE_EMPTY_MATCH;
734
735         TAILQ_FOREACH(current, &owindows, owindows) {
736             printf("matching: %p / %s\n", current->con, current->con->name);
737             current->con->mark = sstrdup($2);
738         }
739
740         free($<string>2);
741
742         tree_render();
743     }
744     ;
745
746 nop:
747     TOK_NOP STR
748     {
749         printf("-------------------------------------------------\n");
750         printf("  NOP: %s\n", $2);
751         printf("-------------------------------------------------\n");
752         free($2);
753     }
754     ;
755
756 resize:
757     TOK_RESIZE resize_way direction resize_px resize_tiling
758     {
759         /* resize <grow|shrink> <direction> [<px> px] [or <ppt> ppt] */
760         printf("resizing in way %d, direction %d, px %d or ppt %d\n", $2, $3, $4, $5);
761         int direction = $3;
762         int px = $4;
763         int ppt = $5;
764         if ($2 == TOK_SHRINK) {
765             px *= -1;
766             ppt *= -1;
767         }
768
769         if (con_is_floating(focused)) {
770             printf("floating resize\n");
771             if (direction == TOK_UP) {
772                 focused->parent->rect.y -= px;
773                 focused->parent->rect.height += px;
774             } else if (direction == TOK_DOWN) {
775                 focused->rect.height += px;
776             } else if (direction == TOK_LEFT) {
777                 focused->rect.x -= px;
778                 focused->rect.width += px;
779             } else {
780                 focused->rect.width += px;
781             }
782         } else {
783             LOG("tiling resize\n");
784             /* get the default percentage */
785             int children = con_num_children(focused->parent);
786             Con *other;
787             LOG("ins. %d children\n", children);
788             double percentage = 1.0 / children;
789             LOG("default percentage = %f\n", percentage);
790
791             if (direction == TOK_UP || direction == TOK_LEFT) {
792                 other = TAILQ_PREV(focused, nodes_head, nodes);
793             } else {
794                 other = TAILQ_NEXT(focused, nodes);
795             }
796             if (other == TAILQ_END(workspaces)) {
797                 LOG("No other container in this direction found, cannot resize.\n");
798                 return 0;
799             }
800             LOG("other->percent = %f\n", other->percent);
801             LOG("focused->percent before = %f\n", focused->percent);
802             if (focused->percent == 0.0)
803                 focused->percent = percentage;
804             if (other->percent == 0.0)
805                 other->percent = percentage;
806             focused->percent += ((double)ppt / 100.0);
807             other->percent -= ((double)ppt / 100.0);
808             LOG("focused->percent after = %f\n", focused->percent);
809             LOG("other->percent after = %f\n", other->percent);
810         }
811
812         tree_render();
813     }
814     ;
815
816 resize_px:
817     /* empty */
818     {
819         $$ = 10;
820     }
821     | NUMBER TOK_PX
822     {
823         $$ = $1;
824     }
825     ;
826
827 resize_tiling:
828     /* empty */
829     {
830         $$ = 10;
831     }
832     | TOK_OR NUMBER TOK_PPT
833     {
834         $$ = $2;
835     }
836     ;
837
838 resize_way:
839     TOK_GROW        { $$ = TOK_GROW; }
840     | TOK_SHRINK    { $$ = TOK_SHRINK; }
841     ;
842
843 direction:
844     TOK_UP          { $$ = TOK_UP; }
845     | TOK_DOWN      { $$ = TOK_DOWN; }
846     | TOK_LEFT      { $$ = TOK_LEFT; }
847     | TOK_RIGHT     { $$ = TOK_RIGHT; }
848     ;
849
850 mode:
851     TOK_MODE STR
852     {
853         switch_mode($2);
854     }
855     ;