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 back_and_forth { BEGIN(INITIAL); return TOK_BACK_AND_FORTH; }
83 <WANT_STRING>\"[^\"]+\" {
86 char *copy = sstrdup(yytext+1);
87 copy[strlen(copy)-1] = '\0';
88 cmdyylval.string = copy;
91 <WANT_QSTRING>\"[^\"]+\" {
94 char *copy = sstrdup(yytext+1);
95 copy[strlen(copy)-1] = '\0';
96 cmdyylval.string = copy;
100 <WANT_STRING>[^;\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
102 <EAT_WHITESPACE>[;\n] { BEGIN(INITIAL); return ';'; }
103 <EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
105 [ \t]* { /* ignore whitespace */ ; }
106 <EXEC>--no-startup-id { printf("no startup id\n"); yy_pop_state(); return TOK_NO_STARTUP_ID; }
107 <EXEC>. { printf("anything else: *%s*\n", yytext); yyless(0); yy_pop_state(); yy_pop_state(); }
108 exec { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOK_EXEC; }
109 exit { return TOK_EXIT; }
110 reload { return TOK_RELOAD; }
111 restart { return TOK_RESTART; }
112 kill { return TOK_KILL; }
113 window { return TOK_WINDOW; }
114 client { return TOK_CLIENT; }
115 fullscreen { return TOK_FULLSCREEN; }
116 global { return TOK_GLOBAL; }
117 layout { return TOK_LAYOUT; }
118 default { return TOK_DEFAULT; }
119 stacked { return TOK_STACKED; }
120 stacking { return TOK_STACKED; }
121 tabbed { return TOK_TABBED; }
122 border { return TOK_BORDER; }
123 normal { return TOK_NORMAL; }
124 none { return TOK_NONE; }
125 1pixel { return TOK_1PIXEL; }
126 mode { BEGIN(WANT_QSTRING); return TOK_MODE; }
127 tiling { return TOK_TILING; }
128 floating { return TOK_FLOATING; }
129 toggle { return TOK_TOGGLE; }
130 mode_toggle { return TOK_MODE_TOGGLE; }
131 workspace { WS_STRING; return TOK_WORKSPACE; }
132 output { WS_STRING; return TOK_OUTPUT; }
133 focus { return TOK_FOCUS; }
134 move { return TOK_MOVE; }
135 open { return TOK_OPEN; }
136 split { return TOK_SPLIT; }
137 horizontal { return TOK_HORIZONTAL; }
138 vertical { return TOK_VERTICAL; }
139 up { return TOK_UP; }
140 down { return TOK_DOWN; }
141 left { return TOK_LEFT; }
142 right { return TOK_RIGHT; }
143 parent { return TOK_PARENT; }
144 child { return TOK_CHILD; }
145 resize { return TOK_RESIZE; }
146 shrink { return TOK_SHRINK; }
147 grow { return TOK_GROW; }
148 px { return TOK_PX; }
149 or { return TOK_OR; }
150 ppt { return TOK_PPT; }
151 nop { WS_STRING; return TOK_NOP; }
152 append_layout { WS_STRING; return TOK_APPEND_LAYOUT; }
153 mark { WS_STRING; return TOK_MARK; }
155 enable { return TOK_ENABLE; }
156 true { return TOK_ENABLE; }
157 yes { return TOK_ENABLE; }
158 disable { return TOK_DISABLE; }
159 false { return TOK_DISABLE; }
160 no { return TOK_DISABLE; }
162 class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
163 instance { BEGIN(WANT_QSTRING); return TOK_INSTANCE; }
164 window_role { BEGIN(WANT_QSTRING); return TOK_WINDOW_ROLE; }
165 id { BEGIN(WANT_QSTRING); return TOK_ID; }
166 con_id { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
167 con_mark { BEGIN(WANT_QSTRING); return TOK_MARK; }
168 title { BEGIN(WANT_QSTRING); return TOK_TITLE; }
170 [0-9]+ { cmdyylval.number = atoi(yytext); return NUMBER; }
172 . { return (int)yytext[0]; }
175 while (yy_start_stack_ptr > 0)