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 /* the next/prev tokens are here to recognize them *before* handling
75 * strings ('workspace' command) */
76 next { return TOK_NEXT; }
77 prev { return TOK_PREV; }
79 <WANT_STRING>\"[^\"]+\" {
82 char *copy = sstrdup(yytext+1);
83 copy[strlen(copy)-1] = '\0';
84 cmdyylval.string = copy;
87 <WANT_QSTRING>\"[^\"]+\" {
90 char *copy = sstrdup(yytext+1);
91 copy[strlen(copy)-1] = '\0';
92 cmdyylval.string = copy;
96 <WANT_STRING>[^;\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
98 <EAT_WHITESPACE>[;\n] { BEGIN(INITIAL); return ';'; }
99 <EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
101 [ \t]* { /* ignore whitespace */ ; }
102 exec { WS_STRING; return TOK_EXEC; }
103 exit { return TOK_EXIT; }
104 reload { return TOK_RELOAD; }
105 restart { return TOK_RESTART; }
106 kill { return TOK_KILL; }
107 window { return TOK_WINDOW; }
108 client { return TOK_CLIENT; }
109 fullscreen { return TOK_FULLSCREEN; }
110 global { return TOK_GLOBAL; }
111 layout { return TOK_LAYOUT; }
112 default { return TOK_DEFAULT; }
113 stacked { return TOK_STACKED; }
114 stacking { return TOK_STACKED; }
115 tabbed { return TOK_TABBED; }
116 border { return TOK_BORDER; }
117 normal { return TOK_NORMAL; }
118 none { return TOK_NONE; }
119 1pixel { return TOK_1PIXEL; }
120 mode { BEGIN(WANT_QSTRING); return TOK_MODE; }
121 tiling { return TOK_TILING; }
122 floating { return TOK_FLOATING; }
123 toggle { return TOK_TOGGLE; }
124 mode_toggle { return TOK_MODE_TOGGLE; }
125 workspace { WS_STRING; return TOK_WORKSPACE; }
126 focus { return TOK_FOCUS; }
127 move { return TOK_MOVE; }
128 open { return TOK_OPEN; }
129 split { return TOK_SPLIT; }
130 horizontal { return TOK_HORIZONTAL; }
131 vertical { return TOK_VERTICAL; }
132 up { return TOK_UP; }
133 down { return TOK_DOWN; }
134 left { return TOK_LEFT; }
135 right { return TOK_RIGHT; }
136 parent { return TOK_PARENT; }
137 child { return TOK_CHILD; }
138 resize { return TOK_RESIZE; }
139 shrink { return TOK_SHRINK; }
140 grow { return TOK_GROW; }
141 px { return TOK_PX; }
142 or { return TOK_OR; }
143 ppt { return TOK_PPT; }
144 nop { WS_STRING; return TOK_NOP; }
145 append_layout { WS_STRING; return TOK_APPEND_LAYOUT; }
146 mark { WS_STRING; return TOK_MARK; }
148 enable { return TOK_ENABLE; }
149 true { return TOK_ENABLE; }
150 yes { return TOK_ENABLE; }
151 disable { return TOK_DISABLE; }
152 false { return TOK_DISABLE; }
153 no { return TOK_DISABLE; }
155 class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
156 id { BEGIN(WANT_QSTRING); return TOK_ID; }
157 con_id { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
158 con_mark { BEGIN(WANT_QSTRING); return TOK_MARK; }
159 title { BEGIN(WANT_QSTRING); return TOK_TITLE; }
161 [0-9]+ { cmdyylval.number = atoi(yytext); return NUMBER; }
163 . { return (int)yytext[0]; }
166 while (yy_start_stack_ptr > 0)