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 */
56 /* This is called when a new line is lexed. We only want the
57 * first line to match to go into state BUFFER_LINE */
58 if (context->line_number == 0) {
59 context->line_number = 1;
61 yy_push_state(BUFFER_LINE);
65 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
67 context->line_copy = sstrdup(yytext);
75 /* the next/prev tokens are here to recognize them *before* handling
76 * strings ('workspace' command) */
77 next { return TOK_NEXT; }
78 prev { return TOK_PREV; }
80 <WANT_STRING>\"[^\"]+\" {
83 char *copy = sstrdup(yytext+1);
84 copy[strlen(copy)-1] = '\0';
85 cmdyylval.string = copy;
88 <WANT_QSTRING>\"[^\"]+\" {
91 char *copy = sstrdup(yytext+1);
92 copy[strlen(copy)-1] = '\0';
93 cmdyylval.string = copy;
97 <WANT_STRING>[^;\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
99 <EAT_WHITESPACE>[;\n] { BEGIN(INITIAL); return ';'; }
100 <EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
102 [ \t]* { /* ignore whitespace */ ; }
103 exec { WS_STRING; return TOK_EXEC; }
104 exit { return TOK_EXIT; }
105 reload { return TOK_RELOAD; }
106 restart { return TOK_RESTART; }
107 kill { return TOK_KILL; }
108 window { return TOK_WINDOW; }
109 client { return TOK_CLIENT; }
110 fullscreen { return TOK_FULLSCREEN; }
111 global { return TOK_GLOBAL; }
112 layout { return TOK_LAYOUT; }
113 default { return TOK_DEFAULT; }
114 stacked { return TOK_STACKED; }
115 stacking { return TOK_STACKED; }
116 tabbed { return TOK_TABBED; }
117 border { return TOK_BORDER; }
118 normal { return TOK_NORMAL; }
119 none { return TOK_NONE; }
120 1pixel { return TOK_1PIXEL; }
121 mode { BEGIN(WANT_QSTRING); return TOK_MODE; }
122 tiling { return TOK_TILING; }
123 floating { return TOK_FLOATING; }
124 toggle { return TOK_TOGGLE; }
125 mode_toggle { return TOK_MODE_TOGGLE; }
126 workspace { WS_STRING; return TOK_WORKSPACE; }
127 output { WS_STRING; return TOK_OUTPUT; }
128 focus { return TOK_FOCUS; }
129 move { return TOK_MOVE; }
130 open { return TOK_OPEN; }
131 split { return TOK_SPLIT; }
132 horizontal { return TOK_HORIZONTAL; }
133 vertical { return TOK_VERTICAL; }
134 up { return TOK_UP; }
135 down { return TOK_DOWN; }
136 left { return TOK_LEFT; }
137 right { return TOK_RIGHT; }
138 parent { return TOK_PARENT; }
139 child { return TOK_CHILD; }
140 resize { return TOK_RESIZE; }
141 shrink { return TOK_SHRINK; }
142 grow { return TOK_GROW; }
143 px { return TOK_PX; }
144 or { return TOK_OR; }
145 ppt { return TOK_PPT; }
146 nop { WS_STRING; return TOK_NOP; }
147 append_layout { WS_STRING; return TOK_APPEND_LAYOUT; }
148 mark { WS_STRING; return TOK_MARK; }
150 enable { return TOK_ENABLE; }
151 true { return TOK_ENABLE; }
152 yes { return TOK_ENABLE; }
153 disable { return TOK_DISABLE; }
154 false { return TOK_DISABLE; }
155 no { return TOK_DISABLE; }
157 class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
158 instance { BEGIN(WANT_QSTRING); return TOK_INSTANCE; }
159 window_role { BEGIN(WANT_QSTRING); return TOK_WINDOW_ROLE; }
160 id { BEGIN(WANT_QSTRING); return TOK_ID; }
161 con_id { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
162 con_mark { BEGIN(WANT_QSTRING); return TOK_MARK; }
163 title { BEGIN(WANT_QSTRING); return TOK_TITLE; }
165 [0-9]+ { cmdyylval.number = atoi(yytext); return NUMBER; }
167 . { return (int)yytext[0]; }
170 while (yy_start_stack_ptr > 0)