2011-05-22 22:15:43 +02:00
|
|
|
/*
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
*
|
|
|
|
*/
|
2009-09-29 22:47:37 +02:00
|
|
|
%option nounput
|
|
|
|
%option noinput
|
2010-02-13 19:42:54 +01:00
|
|
|
%option noyy_top_state
|
|
|
|
%option stack
|
2009-09-29 22:47:37 +02:00
|
|
|
|
2009-09-13 14:16:39 +02:00
|
|
|
%{
|
|
|
|
#include <stdio.h>
|
2009-09-26 13:30:32 +02:00
|
|
|
#include <string.h>
|
2010-11-12 23:04:30 +01:00
|
|
|
#include <stdint.h>
|
2009-09-13 14:16:39 +02:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
|
2011-10-23 23:37:11 +02:00
|
|
|
#include "log.h"
|
2009-09-13 14:54:27 +02:00
|
|
|
#include "data.h"
|
2009-09-13 18:40:35 +02:00
|
|
|
#include "config.h"
|
2010-02-13 19:42:54 +01:00
|
|
|
#include "util.h"
|
2011-10-02 19:08:49 +02:00
|
|
|
#include "libi3.h"
|
2010-02-13 19:42:54 +01:00
|
|
|
|
2011-05-02 23:29:26 +02:00
|
|
|
#include "cfgparse.tab.h"
|
|
|
|
|
2010-02-13 19:42:54 +01:00
|
|
|
int yycolumn = 1;
|
|
|
|
|
|
|
|
#define YY_DECL int yylex (struct context *context)
|
|
|
|
|
|
|
|
#define YY_USER_ACTION { \
|
2011-05-22 22:15:43 +02:00
|
|
|
context->first_column = yycolumn; \
|
|
|
|
context->last_column = yycolumn+yyleng-1; \
|
|
|
|
yycolumn += yyleng; \
|
2010-02-13 19:42:54 +01:00
|
|
|
}
|
|
|
|
|
2011-05-22 22:08:40 +02: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)
|
|
|
|
|
2011-10-18 23:16:04 +02:00
|
|
|
#define BAR_DOUBLE_COLOR do { \
|
|
|
|
yy_push_state(BAR_COLOR); \
|
|
|
|
yy_push_state(BAR_COLOR); \
|
|
|
|
} while (0)
|
|
|
|
|
2009-09-13 14:16:39 +02:00
|
|
|
%}
|
|
|
|
|
2011-05-22 22:15:43 +02:00
|
|
|
EOL (\r?\n)
|
2010-02-13 19:42:54 +01:00
|
|
|
|
2011-05-22 22:08:40 +02:00
|
|
|
%s WANT_STRING
|
|
|
|
%s WANT_QSTRING
|
2010-02-13 19:42:54 +01:00
|
|
|
%s BINDSYM_COND
|
|
|
|
%s ASSIGN_COND
|
2011-05-23 18:41:17 +02:00
|
|
|
%s ASSIGN_TARGET_COND
|
2010-02-13 19:42:54 +01:00
|
|
|
%s COLOR_COND
|
2010-03-02 13:35:43 +01:00
|
|
|
%s OUTPUT_COND
|
2011-05-15 20:10:25 +02:00
|
|
|
%s FOR_WINDOW_COND
|
2011-05-22 22:08:40 +02:00
|
|
|
%s EAT_WHITESPACE
|
2011-10-18 23:16:04 +02:00
|
|
|
|
2010-02-13 19:42:54 +01:00
|
|
|
%x BUFFER_LINE
|
2011-10-18 23:16:04 +02:00
|
|
|
%x BAR
|
|
|
|
%x BAR_MODE
|
|
|
|
%x BAR_POSITION
|
|
|
|
%x BAR_COLORS
|
|
|
|
%x BAR_COLOR
|
2009-09-13 14:16:39 +02:00
|
|
|
|
2011-11-11 01:28:04 +01:00
|
|
|
%x EXEC
|
|
|
|
|
2009-09-13 14:16:39 +02:00
|
|
|
%%
|
2010-02-13 19:42:54 +01:00
|
|
|
|
2011-05-22 22:15:43 +02:00
|
|
|
{
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
2010-02-13 19:42:54 +01:00
|
|
|
|
|
|
|
<BUFFER_LINE>^[^\r\n]*/{EOL}? {
|
2011-05-22 22:15:43 +02:00
|
|
|
/* save whole line */
|
|
|
|
context->line_copy = sstrdup(yytext);
|
2010-02-13 19:42:54 +01:00
|
|
|
|
2011-05-22 22:15:43 +02:00
|
|
|
yyless(0);
|
|
|
|
yy_pop_state();
|
|
|
|
yy_set_bol(true);
|
|
|
|
yycolumn = 1;
|
2010-02-13 19:42:54 +01:00
|
|
|
}
|
|
|
|
|
2011-10-18 23:16:04 +02:00
|
|
|
/* This part of the lexer handles the bar {} blocks */
|
|
|
|
<BAR,BAR_MODE,BAR_POSITION,BAR_COLORS,BAR_COLOR>[ \t]+ { /* ignore whitespace */ ; }
|
|
|
|
<BAR>"{" { return '{'; }
|
|
|
|
<BAR>"}" { yy_pop_state(); return '}'; }
|
|
|
|
<BAR>^[ \t]*#[^\n]* { return TOKCOMMENT; }
|
|
|
|
<BAR>output { WS_STRING; return TOK_BAR_OUTPUT; }
|
|
|
|
<BAR>tray_output { WS_STRING; return TOK_BAR_TRAY_OUTPUT; }
|
|
|
|
<BAR>socket_path { WS_STRING; return TOK_BAR_SOCKET_PATH; }
|
|
|
|
<BAR>mode { yy_push_state(BAR_MODE); return TOK_BAR_MODE; }
|
|
|
|
<BAR_MODE>hide { yy_pop_state(); return TOK_BAR_HIDE; }
|
|
|
|
<BAR_MODE>dock { yy_pop_state(); return TOK_BAR_DOCK; }
|
|
|
|
<BAR>position { yy_push_state(BAR_POSITION); return TOK_BAR_POSITION; }
|
|
|
|
<BAR_POSITION>bottom { yy_pop_state(); return TOK_BAR_BOTTOM; }
|
|
|
|
<BAR_POSITION>top { yy_pop_state(); return TOK_BAR_TOP; }
|
|
|
|
<BAR>status_command { WS_STRING; return TOK_BAR_STATUS_COMMAND; }
|
|
|
|
<BAR>font { WS_STRING; return TOK_BAR_FONT; }
|
|
|
|
<BAR>workspace_buttons { return TOK_BAR_WORKSPACE_BUTTONS; }
|
|
|
|
<BAR>verbose { return TOK_BAR_VERBOSE; }
|
|
|
|
<BAR>colors { yy_push_state(BAR_COLORS); return TOK_BAR_COLORS; }
|
|
|
|
<BAR_COLORS>"{" { return '{'; }
|
|
|
|
<BAR_COLORS>"}" { yy_pop_state(); return '}'; }
|
2011-10-25 23:31:57 +02:00
|
|
|
<BAR_COLORS>^[ \t]*#[^\n]* { return TOKCOMMENT; }
|
2011-10-18 23:16:04 +02:00
|
|
|
<BAR_COLORS>background { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_BACKGROUND; }
|
|
|
|
<BAR_COLORS>statusline { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_STATUSLINE; }
|
|
|
|
<BAR_COLORS>focused_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_FOCUSED_WORKSPACE; }
|
|
|
|
<BAR_COLORS>active_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_ACTIVE_WORKSPACE; }
|
|
|
|
<BAR_COLORS>inactive_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_INACTIVE_WORKSPACE; }
|
|
|
|
<BAR_COLORS>urgent_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_URGENT_WORKSPACE; }
|
2011-10-23 18:48:44 +02:00
|
|
|
<BAR_COLOR>#[0-9a-fA-F]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
|
2011-10-18 23:16:04 +02:00
|
|
|
<BAR,BAR_COLORS,BAR_MODE,BAR_POSITION>[a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
|
|
|
|
|
|
|
|
|
2010-02-13 19:42:54 +01:00
|
|
|
|
2011-05-22 22:08:40 +02:00
|
|
|
<FOR_WINDOW_COND>"]" { yy_pop_state(); return ']'; }
|
2011-09-11 22:54:13 +02:00
|
|
|
<ASSIGN_COND>"[" {
|
|
|
|
/* this is the case for the new assign syntax
|
|
|
|
* that uses criteria */
|
|
|
|
yy_pop_state();
|
|
|
|
yy_push_state(FOR_WINDOW_COND);
|
|
|
|
/* afterwards we will be in ASSIGN_TARGET_COND */
|
|
|
|
return '[';
|
|
|
|
}
|
2011-05-22 22:08:40 +02:00
|
|
|
<EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
|
|
|
|
<WANT_QSTRING>\"[^\"]+\" {
|
2011-05-15 20:10:25 +02:00
|
|
|
yy_pop_state();
|
|
|
|
/* strip quotes */
|
|
|
|
char *copy = sstrdup(yytext+1);
|
|
|
|
copy[strlen(copy)-1] = '\0';
|
|
|
|
yylval.string = copy;
|
|
|
|
return STR;
|
2011-05-22 22:08:40 +02:00
|
|
|
}
|
2011-10-18 23:16:04 +02:00
|
|
|
<WANT_STRING>[^\n]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return STR; }
|
2011-10-20 23:38:46 +02:00
|
|
|
<OUTPUT_COND>[a-zA-Z0-9_-]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return OUTPUT; }
|
2009-09-27 17:00:37 +02:00
|
|
|
^[ \t]*#[^\n]* { return TOKCOMMENT; }
|
2011-10-22 00:22:48 +02:00
|
|
|
<COLOR_COND>#[0-9a-fA-F]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
|
2011-05-23 18:41:17 +02:00
|
|
|
<ASSIGN_TARGET_COND>[ \t]*→[ \t]* { BEGIN(WANT_STRING); }
|
|
|
|
<ASSIGN_TARGET_COND>[ \t]+ { BEGIN(WANT_STRING); }
|
2011-11-11 01:28:04 +01:00
|
|
|
<EXEC>--no-startup-id { printf("no startup id\n"); yy_pop_state(); return TOK_NO_STARTUP_ID; }
|
|
|
|
<EXEC>. { printf("anything else: *%s*\n", yytext); yyless(0); yy_pop_state(); yy_pop_state(); }
|
2009-09-19 19:34:02 +02:00
|
|
|
[0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
|
2011-10-18 23:16:04 +02:00
|
|
|
bar { yy_push_state(BAR); return TOK_BAR; }
|
2009-09-27 17:02:13 +02:00
|
|
|
mode { return TOKMODE; }
|
2011-05-22 22:08:40 +02:00
|
|
|
bind { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
|
|
|
|
bindcode { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
|
|
|
|
bindsym { yy_push_state(BINDSYM_COND); yy_push_state(EAT_WHITESPACE); return TOKBINDSYM; }
|
2011-10-20 23:38:46 +02:00
|
|
|
floating_modifier { return TOKFLOATING_MODIFIER; }
|
|
|
|
workspace { return TOKWORKSPACE; }
|
2011-05-22 22:08:40 +02:00
|
|
|
output { yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE); return TOKOUTPUT; }
|
|
|
|
terminal { WS_STRING; return TOKTERMINAL; }
|
|
|
|
font { WS_STRING; return TOKFONT; }
|
2011-05-23 18:41:17 +02:00
|
|
|
assign { yy_push_state(ASSIGN_TARGET_COND); yy_push_state(ASSIGN_COND); return TOKASSIGN; }
|
2009-09-13 21:32:58 +02:00
|
|
|
set[^\n]* { return TOKCOMMENT; }
|
2011-05-22 22:08:40 +02:00
|
|
|
ipc-socket { WS_STRING; return TOKIPCSOCKET; }
|
|
|
|
ipc_socket { WS_STRING; return TOKIPCSOCKET; }
|
|
|
|
restart_state { WS_STRING; return TOKRESTARTSTATE; }
|
2011-03-17 17:55:53 +01:00
|
|
|
default_orientation { return TOK_ORIENTATION; }
|
2011-03-16 11:56:51 +01:00
|
|
|
horizontal { return TOK_HORIZ; }
|
|
|
|
vertical { return TOK_VERT; }
|
|
|
|
auto { return TOK_AUTO; }
|
2011-04-02 21:49:35 +02:00
|
|
|
workspace_layout { return TOK_WORKSPACE_LAYOUT; }
|
2009-11-08 12:43:01 +01:00
|
|
|
new_window { return TOKNEWWINDOW; }
|
2011-08-08 21:51:21 +02:00
|
|
|
new_float { return TOKNEWFLOAT; }
|
2010-12-08 00:32:04 +01:00
|
|
|
normal { return TOK_NORMAL; }
|
|
|
|
none { return TOK_NONE; }
|
|
|
|
1pixel { return TOK_1PIXEL; }
|
2010-01-26 12:10:48 +01:00
|
|
|
focus_follows_mouse { return TOKFOCUSFOLLOWSMOUSE; }
|
2011-06-11 19:15:16 +02:00
|
|
|
force_focus_wrapping { return TOK_FORCE_FOCUS_WRAPPING; }
|
2011-09-19 22:43:25 +02:00
|
|
|
force_xinerama { return TOK_FORCE_XINERAMA; }
|
2011-10-18 00:17:56 +02:00
|
|
|
workspace_auto_back_and_forth { return TOK_WORKSPACE_AUTO_BAF; }
|
2010-03-13 19:15:28 +01:00
|
|
|
workspace_bar { return TOKWORKSPACEBAR; }
|
2011-03-06 15:45:42 +01:00
|
|
|
popup_during_fullscreen { return TOK_POPUP_DURING_FULLSCREEN; }
|
|
|
|
ignore { return TOK_IGNORE; }
|
|
|
|
leave_fullscreen { return TOK_LEAVE_FULLSCREEN; }
|
2011-05-15 20:10:25 +02:00
|
|
|
for_window {
|
|
|
|
/* Example: for_window [class="urxvt"] border none
|
|
|
|
*
|
|
|
|
* First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
|
2011-05-22 22:08:40 +02:00
|
|
|
* Then, we require a whitespace (EAT_WHITESPACE)
|
2011-05-15 20:10:25 +02:00
|
|
|
* And the rest of the line is parsed as a string
|
|
|
|
*/
|
2011-05-22 22:08:40 +02:00
|
|
|
yy_push_state(WANT_STRING);
|
|
|
|
yy_push_state(EAT_WHITESPACE);
|
2011-05-15 20:10:25 +02:00
|
|
|
yy_push_state(FOR_WINDOW_COND);
|
|
|
|
return TOK_FOR_WINDOW;
|
|
|
|
}
|
2011-03-23 16:11:46 +01:00
|
|
|
default { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
|
|
|
|
stacking { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
|
|
|
|
stacked { return TOK_STACKING; }
|
|
|
|
tabbed { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
|
2009-09-27 23:08:27 +02:00
|
|
|
stack-limit { return TOKSTACKLIMIT; }
|
2010-03-27 15:25:51 +01:00
|
|
|
cols { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
|
|
|
|
rows { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
|
2011-11-11 01:28:04 +01:00
|
|
|
exec { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOKEXEC; }
|
|
|
|
exec_always { WS_STRING; yy_push_state(EXEC); yy_push_state(EAT_WHITESPACE); return TOKEXEC_ALWAYS; }
|
2011-10-21 23:58:53 +02:00
|
|
|
client.background { yy_push_state(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
|
|
|
|
client.focused { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
|
|
|
|
client.focused_inactive { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
|
|
|
|
client.unfocused { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
|
|
|
|
client.urgent { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
|
|
|
|
bar.focused { yy_push_state(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
|
|
|
|
bar.unfocused { yy_push_state(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
|
|
|
|
bar.urgent { yy_push_state(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
|
2009-09-13 18:40:35 +02:00
|
|
|
Mod1 { yylval.number = BIND_MOD1; return MODIFIER; }
|
|
|
|
Mod2 { yylval.number = BIND_MOD2; return MODIFIER; }
|
|
|
|
Mod3 { yylval.number = BIND_MOD3; return MODIFIER; }
|
|
|
|
Mod4 { yylval.number = BIND_MOD4; return MODIFIER; }
|
|
|
|
Mod5 { yylval.number = BIND_MOD5; return MODIFIER; }
|
2009-09-19 19:05:15 +02:00
|
|
|
Mode_switch { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
|
2009-09-13 18:40:35 +02:00
|
|
|
control { return TOKCONTROL; }
|
2009-11-12 20:28:09 +01:00
|
|
|
ctrl { return TOKCONTROL; }
|
2009-09-13 18:40:35 +02:00
|
|
|
shift { return TOKSHIFT; }
|
2011-05-15 20:10:25 +02:00
|
|
|
|
|
|
|
class { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
|
2011-08-04 17:12:54 +02:00
|
|
|
instance { yy_push_state(WANT_QSTRING); return TOK_INSTANCE; }
|
2011-09-18 17:05:10 +02:00
|
|
|
window_role { yy_push_state(WANT_QSTRING); return TOK_WINDOW_ROLE; }
|
2011-05-15 20:10:25 +02:00
|
|
|
id { yy_push_state(WANT_QSTRING); return TOK_ID; }
|
|
|
|
con_id { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
|
|
|
|
con_mark { yy_push_state(WANT_QSTRING); return TOK_MARK; }
|
|
|
|
title { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
|
|
|
|
|
2011-10-18 23:16:04 +02:00
|
|
|
<*>{EOL} {
|
2010-02-13 19:42:54 +01:00
|
|
|
FREE(context->line_copy);
|
|
|
|
context->line_number++;
|
|
|
|
yy_push_state(BUFFER_LINE);
|
|
|
|
}
|
2011-10-21 23:58:53 +02:00
|
|
|
<BINDSYM_COND>[ \t]+ { yy_pop_state(); yy_push_state(WANT_STRING); }
|
|
|
|
<OUTPUT_COND>[ \t]+ { yy_pop_state(); yy_push_state(WANT_STRING); }
|
2011-05-22 21:48:25 +02:00
|
|
|
[ \t]+ { /* ignore whitespace */ ; }
|
2009-09-13 18:40:35 +02:00
|
|
|
\"[^\"]+\" {
|
|
|
|
/* if ASSIGN_COND then */
|
2011-05-23 18:41:17 +02:00
|
|
|
if (yy_start_stack_ptr > 0)
|
|
|
|
yy_pop_state();
|
2009-09-13 18:40:35 +02:00
|
|
|
/* yylval will be the string, but without quotes */
|
2011-05-22 22:08:40 +02:00
|
|
|
char *copy = sstrdup(yytext+1);
|
2009-09-13 18:40:35 +02:00
|
|
|
copy[strlen(copy)-1] = '\0';
|
|
|
|
yylval.string = copy;
|
|
|
|
return QUOTEDSTRING;
|
|
|
|
}
|
2011-09-11 22:54:13 +02:00
|
|
|
<ASSIGN_COND>[^ \t\"\[]+ { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
|
2011-05-22 22:15:43 +02:00
|
|
|
<BINDSYM_COND>[a-zA-Z0-9_]+ { yylval.string = sstrdup(yytext); return WORD; }
|
2011-05-22 22:08:40 +02:00
|
|
|
[a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
|
2009-09-13 18:40:35 +02:00
|
|
|
. { return (int)yytext[0]; }
|
2010-02-13 19:42:54 +01:00
|
|
|
|
|
|
|
<<EOF>> {
|
2011-05-22 22:15:43 +02:00
|
|
|
while (yy_start_stack_ptr > 0)
|
|
|
|
yy_pop_state();
|
|
|
|
yyterminate();
|
2010-02-13 19:42:54 +01:00
|
|
|
}
|
|
|
|
|
2009-09-13 14:16:39 +02:00
|
|
|
%%
|