2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2010 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; \
37 /* handle everything up to \n as a string */
39 /* first expect a whitespace, then a string */
41 /* handle a quoted string or everything up to the next whitespace */
49 /* This is called when a new line is lexed. We only want the
50 * first line to match to go into state BUFFER_LINE */
51 if (context->line_number == 0) {
52 context->line_number = 1;
54 yy_push_state(BUFFER_LINE);
58 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
60 context->line_copy = sstrdup(yytext);
68 <WANT_STRING>[^\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
69 <WANT_WS_STRING>[ \t]* { BEGIN(WANT_STRING); return WHITESPACE; }
70 <WANT_QSTRING>\"[^\"]+\" {
73 char *copy = sstrdup(yytext+1);
74 copy[strlen(copy)-1] = '\0';
75 cmdyylval.string = copy;
79 [ \t]* { return WHITESPACE; }
80 attach { return TOK_ATTACH; }
81 exec { BEGIN(WANT_WS_STRING); return TOK_EXEC; }
82 exit { return TOK_EXIT; }
83 reload { return TOK_RELOAD; }
84 restart { return TOK_RESTART; }
85 kill { return TOK_KILL; }
86 fullscreen { return TOK_FULLSCREEN; }
87 global { return TOK_GLOBAL; }
88 layout { return TOK_LAYOUT; }
89 default { return TOK_DEFAULT; }
90 stacked { return TOK_STACKED; }
91 stacking { return TOK_STACKED; }
92 tabbed { return TOK_TABBED; }
93 border { return TOK_BORDER; }
94 normal { return TOK_NORMAL; }
95 none { return TOK_NONE; }
96 1pixel { return TOK_1PIXEL; }
97 mode { return TOK_MODE; }
98 tiling { return TOK_TILING; }
99 floating { return TOK_FLOATING; }
100 toggle { return TOK_TOGGLE; }
101 workspace { BEGIN(WANT_WS_STRING); return TOK_WORKSPACE; }
102 focus { return TOK_FOCUS; }
103 move { return TOK_MOVE; }
104 open { return TOK_OPEN; }
105 next { return TOK_NEXT; }
106 prev { return TOK_PREV; }
107 split { return TOK_SPLIT; }
108 horizontal { return TOK_HORIZONTAL; }
109 vertical { return TOK_VERTICAL; }
110 level { return TOK_LEVEL; }
111 up { return TOK_UP; }
112 down { return TOK_DOWN; }
113 left { return TOK_LEFT; }
114 right { return TOK_RIGHT; }
115 resize { return TOK_RESIZE; }
116 shrink { return TOK_SHRINK; }
117 grow { return TOK_GROW; }
118 px { return TOK_PX; }
119 or { return TOK_OR; }
120 ppt { return TOK_PPT; }
121 nop { BEGIN(WANT_WS_STRING); return TOK_NOP; }
122 restore { BEGIN(WANT_WS_STRING); return TOK_RESTORE; }
123 mark { BEGIN(WANT_WS_STRING); return TOK_MARK; }
125 class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
126 id { BEGIN(WANT_QSTRING); return TOK_ID; }
127 con_id { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
128 con_mark { BEGIN(WANT_QSTRING); return TOK_MARK; }
130 [0-9]+ { cmdyylval.number = atoi(yytext); return NUMBER; }
132 . { return (int)yytext[0]; }
135 while (yy_start_stack_ptr > 0)