2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
7 * cmdparse.l: the lexer for commands you send to i3 (or bind on keys)
12 %option noyy_top_state
18 #include "cmdparse.tab.h"
26 #define YY_DECL int yylex (struct context *context)
28 #define YY_USER_ACTION { \
29 context->first_column = cmdyycolumn; \
30 context->last_column = cmdyycolumn+yyleng-1; \
31 cmdyycolumn += yyleng; \
34 /* macro to first eat whitespace, then expect a string */
35 #define WS_STRING do { \
36 yy_push_state(WANT_STRING); \
37 yy_push_state(EAT_WHITESPACE); \
44 /* handle everything up to \n as a string */
46 /* eat a whitespace, then go to the next state on the stack */
48 /* handle a quoted string or everything up to the next whitespace */
58 /* This is called when a new line is lexed. We only want the
59 * first line to match to go into state BUFFER_LINE */
60 if (context->line_number == 0) {
61 context->line_number = 1;
63 yy_push_state(BUFFER_LINE);
67 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
69 context->line_copy = sstrdup(yytext);
77 /* the next/prev/back_and_forth tokens are here to recognize them *before*
78 * handling strings ('workspace' command) */
79 next { BEGIN(INITIAL); return TOK_NEXT; }
80 prev { BEGIN(INITIAL); return TOK_PREV; }
81 next_on_output { BEGIN(INITIAL); return TOK_NEXT_ON_OUTPUT; }
82 prev_on_output { BEGIN(INITIAL); return TOK_PREV_ON_OUTPUT; }
83 back_and_forth { BEGIN(INITIAL); return TOK_BACK_AND_FORTH; }
85 <WANT_STRING>\"[^\"]+\" {
88 char *copy = sstrdup(yytext+1);
89 copy[strlen(copy)-1] = '\0';
90 cmdyylval.string = copy;
93 <WANT_QSTRING>\"[^\"]+\" {
96 char *copy = sstrdup(yytext+1);
97 copy[strlen(copy)-1] = '\0';
98 cmdyylval.string = copy;
102 <WANT_STRING>[^;\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
104 <EAT_WHITESPACE>[;\n] { BEGIN(INITIAL); return ';'; }
105 <EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
107 [ \t]* { /* ignore whitespace */ ; }
108 <EXEC>--no-startup-id { printf("no startup id\n"); yy_pop_state(); return TOK_NO_STARTUP_ID; }
109 <EXEC>. { printf("anything else: *%s*\n", yytext); yyless(0); yy_pop_state(); yy_pop_state(); }
110 exec { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOK_EXEC; }
111 exit { return TOK_EXIT; }
112 reload { return TOK_RELOAD; }
113 restart { return TOK_RESTART; }
114 kill { return TOK_KILL; }
115 window { return TOK_WINDOW; }
116 client { return TOK_CLIENT; }
117 fullscreen { return TOK_FULLSCREEN; }
118 global { return TOK_GLOBAL; }
119 layout { return TOK_LAYOUT; }
120 default { return TOK_DEFAULT; }
121 stacked { return TOK_STACKED; }
122 stacking { return TOK_STACKED; }
123 tabbed { return TOK_TABBED; }
124 border { return TOK_BORDER; }
125 normal { return TOK_NORMAL; }
126 none { return TOK_NONE; }
127 1pixel { return TOK_1PIXEL; }
128 mode { BEGIN(WANT_QSTRING); return TOK_MODE; }
129 tiling { return TOK_TILING; }
130 floating { return TOK_FLOATING; }
131 toggle { return TOK_TOGGLE; }
132 mode_toggle { return TOK_MODE_TOGGLE; }
133 workspace { WS_STRING; return TOK_WORKSPACE; }
134 output { WS_STRING; return TOK_OUTPUT; }
135 focus { return TOK_FOCUS; }
136 move { return TOK_MOVE; }
137 open { return TOK_OPEN; }
138 scratchpad { return TOK_SCRATCHPAD; }
139 show { return TOK_SHOW; }
140 split { return TOK_SPLIT; }
141 horizontal { return TOK_HORIZONTAL; }
142 vertical { return TOK_VERTICAL; }
143 up { return TOK_UP; }
144 down { return TOK_DOWN; }
145 left { return TOK_LEFT; }
146 right { return TOK_RIGHT; }
147 parent { return TOK_PARENT; }
148 child { return TOK_CHILD; }
149 resize { return TOK_RESIZE; }
150 shrink { return TOK_SHRINK; }
151 grow { return TOK_GROW; }
152 px { return TOK_PX; }
153 or { return TOK_OR; }
154 ppt { return TOK_PPT; }
155 nop { WS_STRING; return TOK_NOP; }
156 append_layout { WS_STRING; return TOK_APPEND_LAYOUT; }
157 mark { WS_STRING; return TOK_MARK; }
159 enable { return TOK_ENABLE; }
160 true { return TOK_ENABLE; }
161 yes { return TOK_ENABLE; }
162 disable { return TOK_DISABLE; }
163 false { return TOK_DISABLE; }
164 no { return TOK_DISABLE; }
166 class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
167 instance { BEGIN(WANT_QSTRING); return TOK_INSTANCE; }
168 window_role { BEGIN(WANT_QSTRING); return TOK_WINDOW_ROLE; }
169 id { BEGIN(WANT_QSTRING); return TOK_ID; }
170 con_id { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
171 con_mark { BEGIN(WANT_QSTRING); return TOK_MARK; }
172 title { BEGIN(WANT_QSTRING); return TOK_TITLE; }
174 [0-9]+ { cmdyylval.number = atoi(yytext); return NUMBER; }
176 . { return (int)yytext[0]; }
179 while (yy_start_stack_ptr > 0)