]> git.sur5r.net Git - i3/i3/blob - src/cmdparse.l
Argument for 'kill' for killing a specific window (now default) or the whole client...
[i3/i3] / src / cmdparse.l
1 /*
2  * vim:ts=4:sw=4:expandtab
3  *
4  * i3 - an improved dynamic tiling window manager
5  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
6  *
7  * cmdparse.l: the lexer for commands you send to i3 (or bind on keys)
8  *
9  */
10 %option nounput
11 %option noinput
12 %option noyy_top_state
13 %option stack
14
15 %{
16 #include <stdio.h>
17 #include <string.h>
18 #include "cmdparse.tab.h"
19
20 #include "config.h"
21 #include "util.h"
22
23 int cmdyycolumn = 1;
24
25 #define YY_DECL int yylex (struct context *context)
26
27 #define YY_USER_ACTION { \
28     context->first_column = cmdyycolumn; \
29     context->last_column = cmdyycolumn+yyleng-1; \
30     cmdyycolumn += yyleng; \
31 }
32
33 %}
34
35 EOL (\r?\n)
36
37 /* handle everything up to \n as a string */
38 %s WANT_STRING
39 /* first expect a whitespace, then a string */
40 %s WANT_WS_STRING
41 /* handle a quoted string or everything up to the next whitespace */
42 %s WANT_QSTRING
43
44 %x BUFFER_LINE
45
46 %%
47
48     {
49         /* This is called when a new line is lexed. We only want the
50          * first line to match to go into state BUFFER_LINE */
51         if (context->line_number == 0) {
52             context->line_number = 1;
53             BEGIN(INITIAL);
54             yy_push_state(BUFFER_LINE);
55         }
56     }
57
58 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
59     /* save whole line */
60     context->line_copy = sstrdup(yytext);
61
62     yyless(0);
63     yy_pop_state();
64     yy_set_bol(true);
65     cmdyycolumn = 1;
66 }
67
68 <WANT_WS_STRING>[ \t]*          { BEGIN(WANT_STRING); return WHITESPACE; }
69 <WANT_STRING>\"[^\"]+\"         {
70                                   BEGIN(INITIAL);
71                                   /* strip quotes */
72                                   char *copy = sstrdup(yytext+1);
73                                   copy[strlen(copy)-1] = '\0';
74                                   cmdyylval.string = copy;
75                                   return STR;
76                                  }
77 <WANT_QSTRING>\"[^\"]+\"         {
78                                   BEGIN(INITIAL);
79                                   /* strip quotes */
80                                   char *copy = sstrdup(yytext+1);
81                                   copy[strlen(copy)-1] = '\0';
82                                   cmdyylval.string = copy;
83                                   return STR;
84                                  }
85
86 <WANT_STRING>[^;\n]+             { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
87
88 [ \t]*                          { return WHITESPACE; }
89 attach                          { return TOK_ATTACH; }
90 exec                            { BEGIN(WANT_WS_STRING); return TOK_EXEC; }
91 exit                            { return TOK_EXIT; }
92 reload                          { return TOK_RELOAD; }
93 restart                         { return TOK_RESTART; }
94 kill                            { return TOK_KILL; }
95 window                          { return TOK_WINDOW; }
96 client                          { return TOK_CLIENT; }
97 fullscreen                      { return TOK_FULLSCREEN; }
98 global                          { return TOK_GLOBAL; }
99 layout                          { return TOK_LAYOUT; }
100 default                         { return TOK_DEFAULT; }
101 stacked                         { return TOK_STACKED; }
102 stacking                        { return TOK_STACKED; }
103 tabbed                          { return TOK_TABBED; }
104 border                          { return TOK_BORDER; }
105 normal                          { return TOK_NORMAL; }
106 none                            { return TOK_NONE; }
107 1pixel                          { return TOK_1PIXEL; }
108 mode                            { return TOK_MODE; }
109 tiling                          { return TOK_TILING; }
110 floating                        { return TOK_FLOATING; }
111 toggle                          { return TOK_TOGGLE; }
112 workspace                       { BEGIN(WANT_WS_STRING); return TOK_WORKSPACE; }
113 focus                           { return TOK_FOCUS; }
114 move                            { return TOK_MOVE; }
115 open                            { return TOK_OPEN; }
116 next                            { return TOK_NEXT; }
117 prev                            { return TOK_PREV; }
118 split                           { return TOK_SPLIT; }
119 horizontal                      { return TOK_HORIZONTAL; }
120 vertical                        { return TOK_VERTICAL; }
121 level                           { return TOK_LEVEL; }
122 up                              { return TOK_UP; }
123 down                            { return TOK_DOWN; }
124 left                            { return TOK_LEFT; }
125 right                           { return TOK_RIGHT; }
126 resize                          { return TOK_RESIZE; }
127 shrink                          { return TOK_SHRINK; }
128 grow                            { return TOK_GROW; }
129 px                              { return TOK_PX; }
130 or                              { return TOK_OR; }
131 ppt                             { return TOK_PPT; }
132 nop                             { BEGIN(WANT_WS_STRING); return TOK_NOP; }
133 restore                         { BEGIN(WANT_WS_STRING); return TOK_RESTORE; }
134 mark                            { BEGIN(WANT_WS_STRING); return TOK_MARK; }
135
136 class                           { BEGIN(WANT_QSTRING); return TOK_CLASS; }
137 id                              { BEGIN(WANT_QSTRING); return TOK_ID; }
138 con_id                          { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
139 con_mark                        { BEGIN(WANT_QSTRING); return TOK_MARK; }
140
141 [0-9]+                          { cmdyylval.number = atoi(yytext); return NUMBER; }
142
143 .                               { return (int)yytext[0]; }
144
145 <<EOF>> {
146     while (yy_start_stack_ptr > 0)
147         yy_pop_state();
148     yyterminate();
149 }
150
151 %%