2010-04-14 14:26:56 -04:00
|
|
|
/*
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
*
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
2011-05-13 14:41:03 -04:00
|
|
|
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
|
2010-04-14 14:26:56 -04:00
|
|
|
*
|
|
|
|
* cmdparse.l: the lexer for commands you send to i3 (or bind on keys)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
%option nounput
|
|
|
|
%option noinput
|
|
|
|
%option noyy_top_state
|
|
|
|
%option stack
|
|
|
|
|
|
|
|
%{
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "cmdparse.tab.h"
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
int cmdyycolumn = 1;
|
|
|
|
|
|
|
|
#define YY_DECL int yylex (struct context *context)
|
|
|
|
|
|
|
|
#define YY_USER_ACTION { \
|
|
|
|
context->first_column = cmdyycolumn; \
|
|
|
|
context->last_column = cmdyycolumn+yyleng-1; \
|
|
|
|
cmdyycolumn += yyleng; \
|
|
|
|
}
|
|
|
|
|
2011-05-22 15:26:50 -04:00
|
|
|
/* macro to first eat whitespace, then expect a string */
|
|
|
|
#define WS_STRING do { \
|
|
|
|
yy_push_state(WANT_STRING); \
|
|
|
|
yy_push_state(EAT_WHITESPACE); \
|
|
|
|
} while (0)
|
|
|
|
|
2010-04-14 14:26:56 -04:00
|
|
|
%}
|
|
|
|
|
|
|
|
EOL (\r?\n)
|
|
|
|
|
|
|
|
/* handle everything up to \n as a string */
|
|
|
|
%s WANT_STRING
|
2011-05-22 15:26:50 -04:00
|
|
|
/* eat a whitespace, then go to the next state on the stack */
|
|
|
|
%s EAT_WHITESPACE
|
2010-04-14 14:26:56 -04:00
|
|
|
/* handle a quoted string or everything up to the next whitespace */
|
|
|
|
%s WANT_QSTRING
|
|
|
|
|
|
|
|
%x BUFFER_LINE
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
{
|
|
|
|
/* This is called when a new line is lexed. We only want the
|
|
|
|
* first line to match to go into state BUFFER_LINE */
|
|
|
|
if (context->line_number == 0) {
|
|
|
|
context->line_number = 1;
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
yy_push_state(BUFFER_LINE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
<BUFFER_LINE>^[^\r\n]*/{EOL}? {
|
|
|
|
/* save whole line */
|
|
|
|
context->line_copy = sstrdup(yytext);
|
|
|
|
|
|
|
|
yyless(0);
|
|
|
|
yy_pop_state();
|
|
|
|
yy_set_bol(true);
|
|
|
|
cmdyycolumn = 1;
|
|
|
|
}
|
|
|
|
|
2011-06-10 10:03:59 -04:00
|
|
|
/* the next/prev tokens are here to recognize them *before* handling
|
|
|
|
* strings ('workspace' command) */
|
|
|
|
next { return TOK_NEXT; }
|
|
|
|
prev { return TOK_PREV; }
|
|
|
|
|
2011-05-12 01:09:06 -04:00
|
|
|
<WANT_STRING>\"[^\"]+\" {
|
2010-04-14 14:26:56 -04:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
/* strip quotes */
|
|
|
|
char *copy = sstrdup(yytext+1);
|
|
|
|
copy[strlen(copy)-1] = '\0';
|
|
|
|
cmdyylval.string = copy;
|
|
|
|
return STR;
|
2011-05-22 15:26:50 -04:00
|
|
|
}
|
|
|
|
<WANT_QSTRING>\"[^\"]+\" {
|
2011-05-13 11:03:15 -04:00
|
|
|
BEGIN(INITIAL);
|
|
|
|
/* strip quotes */
|
|
|
|
char *copy = sstrdup(yytext+1);
|
|
|
|
copy[strlen(copy)-1] = '\0';
|
|
|
|
cmdyylval.string = copy;
|
|
|
|
return STR;
|
2011-05-22 15:26:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
<WANT_STRING>[^;\n]+ { BEGIN(INITIAL); cmdyylval.string = sstrdup(yytext); return STR; }
|
2011-05-13 11:03:15 -04:00
|
|
|
|
2011-05-22 15:26:50 -04:00
|
|
|
<EAT_WHITESPACE>[;\n] { BEGIN(INITIAL); return ';'; }
|
|
|
|
<EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
|
2010-04-14 14:26:56 -04:00
|
|
|
|
2011-05-22 15:26:50 -04:00
|
|
|
[ \t]* { /* ignore whitespace */ ; }
|
|
|
|
exec { WS_STRING; return TOK_EXEC; }
|
2010-04-14 14:26:56 -04:00
|
|
|
exit { return TOK_EXIT; }
|
|
|
|
reload { return TOK_RELOAD; }
|
|
|
|
restart { return TOK_RESTART; }
|
|
|
|
kill { return TOK_KILL; }
|
2011-05-13 14:41:03 -04:00
|
|
|
window { return TOK_WINDOW; }
|
|
|
|
client { return TOK_CLIENT; }
|
2010-04-14 14:26:56 -04:00
|
|
|
fullscreen { return TOK_FULLSCREEN; }
|
|
|
|
global { return TOK_GLOBAL; }
|
|
|
|
layout { return TOK_LAYOUT; }
|
|
|
|
default { return TOK_DEFAULT; }
|
|
|
|
stacked { return TOK_STACKED; }
|
2010-06-01 17:20:57 -04:00
|
|
|
stacking { return TOK_STACKED; }
|
2010-04-14 14:26:56 -04:00
|
|
|
tabbed { return TOK_TABBED; }
|
|
|
|
border { return TOK_BORDER; }
|
2010-11-12 12:41:54 -05:00
|
|
|
normal { return TOK_NORMAL; }
|
2010-04-14 14:26:56 -04:00
|
|
|
none { return TOK_NONE; }
|
|
|
|
1pixel { return TOK_1PIXEL; }
|
2011-06-09 20:38:07 -04:00
|
|
|
mode { BEGIN(WANT_QSTRING); return TOK_MODE; }
|
2010-04-14 14:26:56 -04:00
|
|
|
tiling { return TOK_TILING; }
|
|
|
|
floating { return TOK_FLOATING; }
|
2010-05-31 16:48:28 -04:00
|
|
|
toggle { return TOK_TOGGLE; }
|
2011-07-04 11:09:52 -04:00
|
|
|
mode_toggle { return TOK_MODE_TOGGLE; }
|
2011-05-22 15:26:50 -04:00
|
|
|
workspace { WS_STRING; return TOK_WORKSPACE; }
|
2010-04-14 14:26:56 -04:00
|
|
|
focus { return TOK_FOCUS; }
|
|
|
|
move { return TOK_MOVE; }
|
2010-04-16 09:30:07 -04:00
|
|
|
open { return TOK_OPEN; }
|
2010-05-10 03:33:10 -04:00
|
|
|
split { return TOK_SPLIT; }
|
2010-05-10 03:08:31 -04:00
|
|
|
horizontal { return TOK_HORIZONTAL; }
|
|
|
|
vertical { return TOK_VERTICAL; }
|
2010-05-10 04:12:35 -04:00
|
|
|
up { return TOK_UP; }
|
|
|
|
down { return TOK_DOWN; }
|
2010-06-30 13:47:23 -04:00
|
|
|
left { return TOK_LEFT; }
|
|
|
|
right { return TOK_RIGHT; }
|
2011-06-09 19:36:33 -04:00
|
|
|
parent { return TOK_PARENT; }
|
|
|
|
child { return TOK_CHILD; }
|
2010-06-30 13:47:23 -04:00
|
|
|
resize { return TOK_RESIZE; }
|
|
|
|
shrink { return TOK_SHRINK; }
|
|
|
|
grow { return TOK_GROW; }
|
|
|
|
px { return TOK_PX; }
|
|
|
|
or { return TOK_OR; }
|
|
|
|
ppt { return TOK_PPT; }
|
2011-05-22 15:26:50 -04:00
|
|
|
nop { WS_STRING; return TOK_NOP; }
|
2011-06-09 20:15:31 -04:00
|
|
|
append_layout { WS_STRING; return TOK_APPEND_LAYOUT; }
|
2011-05-22 15:26:50 -04:00
|
|
|
mark { WS_STRING; return TOK_MARK; }
|
2010-04-14 14:26:56 -04:00
|
|
|
|
2011-06-09 20:06:47 -04:00
|
|
|
enable { return TOK_ENABLE; }
|
|
|
|
true { return TOK_ENABLE; }
|
|
|
|
yes { return TOK_ENABLE; }
|
|
|
|
disable { return TOK_DISABLE; }
|
|
|
|
false { return TOK_DISABLE; }
|
|
|
|
no { return TOK_DISABLE; }
|
|
|
|
|
2010-04-14 14:26:56 -04:00
|
|
|
class { BEGIN(WANT_QSTRING); return TOK_CLASS; }
|
2011-08-04 11:12:54 -04:00
|
|
|
instance { BEGIN(WANT_QSTRING); return TOK_INSTANCE; }
|
2010-04-16 09:30:07 -04:00
|
|
|
id { BEGIN(WANT_QSTRING); return TOK_ID; }
|
|
|
|
con_id { BEGIN(WANT_QSTRING); return TOK_CON_ID; }
|
2010-06-02 17:32:05 -04:00
|
|
|
con_mark { BEGIN(WANT_QSTRING); return TOK_MARK; }
|
2011-06-08 17:34:08 -04:00
|
|
|
title { BEGIN(WANT_QSTRING); return TOK_TITLE; }
|
2010-04-14 14:26:56 -04:00
|
|
|
|
2010-06-30 13:47:23 -04:00
|
|
|
[0-9]+ { cmdyylval.number = atoi(yytext); return NUMBER; }
|
|
|
|
|
2010-04-14 14:26:56 -04:00
|
|
|
. { return (int)yytext[0]; }
|
|
|
|
|
|
|
|
<<EOF>> {
|
|
|
|
while (yy_start_stack_ptr > 0)
|
|
|
|
yy_pop_state();
|
|
|
|
yyterminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
%%
|