]> git.sur5r.net Git - i3/i3/blob - src/cmdparse.l
Merge branch 'master' into next
[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 /* macro to first eat whitespace, then expect a string */
34 #define WS_STRING do { \
35     yy_push_state(WANT_STRING); \
36     yy_push_state(EAT_WHITESPACE); \
37 } while (0)
38
39 %}
40
41 EOL (\r?\n)
42
43 /* handle everything up to \n as a string */
44 %s WANT_STRING
45 /* eat a whitespace, then go to the next state on the stack */
46 %s EAT_WHITESPACE
47 /* handle a quoted string or everything up to the next whitespace */
48 %s WANT_QSTRING
49
50 %x BUFFER_LINE
51
52 %%
53
54     {
55         /* This is called when a new line is lexed. We only want the
56          * first line to match to go into state BUFFER_LINE */
57         if (context->line_number == 0) {
58             context->line_number = 1;
59             BEGIN(INITIAL);
60             yy_push_state(BUFFER_LINE);
61         }
62     }
63
64 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
65     /* save whole line */
66     context->line_copy = sstrdup(yytext);
67
68     yyless(0);
69     yy_pop_state();
70     yy_set_bol(true);
71     cmdyycolumn = 1;
72 }
73
74     /* the next/prev tokens are here to recognize them *before* handling
75      * strings ('workspace' command) */
76 next                            { return TOK_NEXT; }
77 prev                            { return TOK_PREV; }
78
79 <WANT_STRING>\"[^\"]+\"         {
80                                   BEGIN(INITIAL);
81                                   /* strip quotes */
82                                   char *copy = sstrdup(yytext+1);
83                                   copy[strlen(copy)-1] = '\0';
84                                   cmdyylval.string = copy;
85                                   return STR;
86                                 }
87 <WANT_QSTRING>\"[^\"]+\"        {
88                                   BEGIN(INITIAL);
89                                   /* strip quotes */
90                                   char *copy = sstrdup(yytext+1);
91                                   copy[strlen(copy)-1] = '\0';
92                                   cmdyylval.string = copy;
93                                   return STR;
94                                 }
95
96 <WANT_STRING>[^;\n]+            { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
97
98 <EAT_WHITESPACE>[;\n]           { BEGIN(INITIAL); return ';'; }
99 <EAT_WHITESPACE>[ \t]*          { yy_pop_state(); }
100
101 [ \t]*                          { /* ignore whitespace */ ; }
102 exec                            { WS_STRING; return TOK_EXEC; }
103 exit                            { return TOK_EXIT; }
104 reload                          { return TOK_RELOAD; }
105 restart                         { return TOK_RESTART; }
106 kill                            { return TOK_KILL; }
107 window                          { return TOK_WINDOW; }
108 client                          { return TOK_CLIENT; }
109 fullscreen                      { return TOK_FULLSCREEN; }
110 global                          { return TOK_GLOBAL; }
111 layout                          { return TOK_LAYOUT; }
112 default                         { return TOK_DEFAULT; }
113 stacked                         { return TOK_STACKED; }
114 stacking                        { return TOK_STACKED; }
115 tabbed                          { return TOK_TABBED; }
116 border                          { return TOK_BORDER; }
117 normal                          { return TOK_NORMAL; }
118 none                            { return TOK_NONE; }
119 1pixel                          { return TOK_1PIXEL; }
120 mode                            { BEGIN(WANT_QSTRING); return TOK_MODE; }
121 tiling                          { return TOK_TILING; }
122 floating                        { return TOK_FLOATING; }
123 toggle                          { return TOK_TOGGLE; }
124 mode_toggle                     { return TOK_MODE_TOGGLE; }
125 workspace                       { WS_STRING; return TOK_WORKSPACE; }
126 output                          { WS_STRING; return TOK_OUTPUT; }
127 focus                           { return TOK_FOCUS; }
128 move                            { return TOK_MOVE; }
129 open                            { return TOK_OPEN; }
130 split                           { return TOK_SPLIT; }
131 horizontal                      { return TOK_HORIZONTAL; }
132 vertical                        { return TOK_VERTICAL; }
133 up                              { return TOK_UP; }
134 down                            { return TOK_DOWN; }
135 left                            { return TOK_LEFT; }
136 right                           { return TOK_RIGHT; }
137 parent                          { return TOK_PARENT; }
138 child                           { return TOK_CHILD; }
139 resize                          { return TOK_RESIZE; }
140 shrink                          { return TOK_SHRINK; }
141 grow                            { return TOK_GROW; }
142 px                              { return TOK_PX; }
143 or                              { return TOK_OR; }
144 ppt                             { return TOK_PPT; }
145 nop                             { WS_STRING; return TOK_NOP; }
146 append_layout                   { WS_STRING; return TOK_APPEND_LAYOUT; }
147 mark                            { WS_STRING; return TOK_MARK; }
148
149 enable                          { return TOK_ENABLE; }
150 true                            { return TOK_ENABLE; }
151 yes                             { return TOK_ENABLE; }
152 disable                         { return TOK_DISABLE; }
153 false                           { return TOK_DISABLE; }
154 no                              { return TOK_DISABLE; }
155
156 class                           { BEGIN(WANT_QSTRING); return TOK_CLASS; }
157 instance                        { BEGIN(WANT_QSTRING); return TOK_INSTANCE; }
158 window_role                     { BEGIN(WANT_QSTRING); return TOK_WINDOW_ROLE; }
159 id                              { BEGIN(WANT_QSTRING); return TOK_ID; }
160 con_id                          { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
161 con_mark                        { BEGIN(WANT_QSTRING); return TOK_MARK; }
162 title                           { BEGIN(WANT_QSTRING); return TOK_TITLE; }
163
164 [0-9]+                          { cmdyylval.number = atoi(yytext); return NUMBER; }
165
166 .                               { return (int)yytext[0]; }
167
168 <<EOF>> {
169     while (yy_start_stack_ptr > 0)
170         yy_pop_state();
171     yyterminate();
172 }
173
174 %%