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"
25 #define YY_DECL int yylex (struct context *context)
27 #define YY_USER_ACTION { \
28 context->first_column = cmdyycolumn; \
29 context->last_column = cmdyycolumn+yyleng-1; \
30 cmdyycolumn += yyleng; \
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); \
43 /* handle everything up to \n as a string */
45 /* eat a whitespace, then go to the next state on the stack */
47 /* handle a quoted string or everything up to the next whitespace */
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;
60 yy_push_state(BUFFER_LINE);
64 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
66 context->line_copy = sstrdup(yytext);
74 <WANT_STRING>\"[^\"]+\" {
77 char *copy = sstrdup(yytext+1);
78 copy[strlen(copy)-1] = '\0';
79 cmdyylval.string = copy;
82 <WANT_QSTRING>\"[^\"]+\" {
85 char *copy = sstrdup(yytext+1);
86 copy[strlen(copy)-1] = '\0';
87 cmdyylval.string = copy;
91 <WANT_STRING>[^;\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
93 <EAT_WHITESPACE>[;\n] { BEGIN(INITIAL); return ';'; }
94 <EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
96 [ \t]* { /* ignore whitespace */ ; }
97 attach { return TOK_ATTACH; }
98 exec { WS_STRING; return TOK_EXEC; }
99 exit { return TOK_EXIT; }
100 reload { return TOK_RELOAD; }
101 restart { return TOK_RESTART; }
102 kill { return TOK_KILL; }
103 window { return TOK_WINDOW; }
104 client { return TOK_CLIENT; }
105 fullscreen { return TOK_FULLSCREEN; }
106 global { return TOK_GLOBAL; }
107 layout { return TOK_LAYOUT; }
108 default { return TOK_DEFAULT; }
109 stacked { return TOK_STACKED; }
110 stacking { return TOK_STACKED; }
111 tabbed { return TOK_TABBED; }
112 border { return TOK_BORDER; }
113 normal { return TOK_NORMAL; }
114 none { return TOK_NONE; }
115 1pixel { return TOK_1PIXEL; }
116 mode { return TOK_MODE; }
117 tiling { return TOK_TILING; }
118 floating { return TOK_FLOATING; }
119 toggle { return TOK_TOGGLE; }
120 workspace { WS_STRING; return TOK_WORKSPACE; }
121 focus { return TOK_FOCUS; }
122 move { return TOK_MOVE; }
123 open { return TOK_OPEN; }
124 next { return TOK_NEXT; }
125 prev { return TOK_PREV; }
126 split { return TOK_SPLIT; }
127 horizontal { return TOK_HORIZONTAL; }
128 vertical { return TOK_VERTICAL; }
129 level { return TOK_LEVEL; }
130 up { return TOK_UP; }
131 down { return TOK_DOWN; }
132 left { return TOK_LEFT; }
133 right { return TOK_RIGHT; }
134 resize { return TOK_RESIZE; }
135 shrink { return TOK_SHRINK; }
136 grow { return TOK_GROW; }
137 px { return TOK_PX; }
138 or { return TOK_OR; }
139 ppt { return TOK_PPT; }
140 nop { WS_STRING; return TOK_NOP; }
141 restore { WS_STRING; return TOK_RESTORE; }
142 mark { WS_STRING; return TOK_MARK; }
144 class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
145 id { BEGIN(WANT_QSTRING); return TOK_ID; }
146 con_id { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
147 con_mark { BEGIN(WANT_QSTRING); return TOK_MARK; }
149 [0-9]+ { cmdyylval.number = atoi(yytext); return NUMBER; }
151 . { return (int)yytext[0]; }
154 while (yy_start_stack_ptr > 0)