2009-09-29 16:47:37 -04:00
|
|
|
%option nounput
|
|
|
|
%option noinput
|
2010-02-13 13:42:54 -05:00
|
|
|
%option noyy_top_state
|
|
|
|
%option stack
|
2009-09-29 16:47:37 -04:00
|
|
|
|
2009-09-13 08:16:39 -04:00
|
|
|
%{
|
2009-09-27 11:01:06 -04:00
|
|
|
/*
|
|
|
|
* vim:ts=8:expandtab
|
|
|
|
*
|
|
|
|
*/
|
2009-09-13 08:16:39 -04:00
|
|
|
#include <stdio.h>
|
2009-09-26 07:30:32 -04:00
|
|
|
#include <string.h>
|
2010-11-12 17:04:30 -05:00
|
|
|
#include <stdint.h>
|
2009-09-13 08:16:39 -04:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
|
2009-09-13 08:54:27 -04:00
|
|
|
#include "data.h"
|
2009-09-13 12:40:35 -04:00
|
|
|
#include "config.h"
|
2010-02-13 13:42:54 -05:00
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2011-05-02 17:29:26 -04:00
|
|
|
#include "cfgparse.tab.h"
|
|
|
|
|
2010-02-13 13:42:54 -05:00
|
|
|
int yycolumn = 1;
|
|
|
|
|
|
|
|
#define YY_DECL int yylex (struct context *context)
|
|
|
|
|
|
|
|
#define YY_USER_ACTION { \
|
|
|
|
context->first_column = yycolumn; \
|
|
|
|
context->last_column = yycolumn+yyleng-1; \
|
|
|
|
yycolumn += yyleng; \
|
|
|
|
}
|
|
|
|
|
2009-09-13 08:16:39 -04:00
|
|
|
%}
|
|
|
|
|
2010-02-13 13:42:54 -05:00
|
|
|
EOL (\r?\n)
|
|
|
|
|
2011-04-18 17:06:32 -04:00
|
|
|
%s BINDCODE_COND
|
2010-02-13 13:42:54 -05:00
|
|
|
%s BINDSYM_COND
|
|
|
|
%s BIND_AWS_COND
|
|
|
|
%s BINDSYM_AWS_COND
|
|
|
|
%s BIND_A2WS_COND
|
|
|
|
%s ASSIGN_COND
|
|
|
|
%s COLOR_COND
|
2010-03-02 07:35:43 -05:00
|
|
|
%s OUTPUT_COND
|
|
|
|
%s OUTPUT_AWS_COND
|
2011-05-15 14:10:25 -04:00
|
|
|
%s WANT_QSTRING
|
|
|
|
%s FOR_WINDOW_COND
|
|
|
|
%s REQUIRE_WS
|
2010-02-13 13:42:54 -05:00
|
|
|
%x BUFFER_LINE
|
2009-09-13 08:16:39 -04:00
|
|
|
|
|
|
|
%%
|
2010-02-13 13:42:54 -05: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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
<BUFFER_LINE>^[^\r\n]*/{EOL}? {
|
|
|
|
/* save whole line */
|
|
|
|
context->line_copy = strdup(yytext);
|
|
|
|
|
|
|
|
yyless(0);
|
|
|
|
yy_pop_state();
|
|
|
|
yy_set_bol(true);
|
|
|
|
yycolumn = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-15 14:10:25 -04:00
|
|
|
<FOR_WINDOW_COND>"]" { yy_pop_state(); return ']'; }
|
2011-05-22 15:48:25 -04:00
|
|
|
<REQUIRE_WS>[ \t]* { yy_pop_state(); }
|
2011-05-15 14:10:25 -04:00
|
|
|
<WANT_QSTRING>\"[^\"]+\" {
|
|
|
|
yy_pop_state();
|
|
|
|
/* strip quotes */
|
|
|
|
char *copy = sstrdup(yytext+1);
|
|
|
|
copy[strlen(copy)-1] = '\0';
|
|
|
|
yylval.string = copy;
|
|
|
|
return STR;
|
|
|
|
}
|
2009-09-13 12:40:35 -04:00
|
|
|
<BIND_A2WS_COND>[^\n]+ { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR; }
|
2010-03-22 10:10:26 -04:00
|
|
|
<OUTPUT_AWS_COND>[a-zA-Z0-9_-]+ { yylval.string = strdup(yytext); return OUTPUT; }
|
2009-09-27 11:00:37 -04:00
|
|
|
^[ \t]*#[^\n]* { return TOKCOMMENT; }
|
2009-09-13 12:40:35 -04:00
|
|
|
<COLOR_COND>[0-9a-fA-F]+ { yylval.string = strdup(yytext); return HEX; }
|
2009-09-19 13:34:02 -04:00
|
|
|
[0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
|
2009-09-27 11:02:13 -04:00
|
|
|
mode { return TOKMODE; }
|
2011-04-18 17:06:32 -04:00
|
|
|
bind { BEGIN(BINDCODE_COND); return TOKBINDCODE; }
|
|
|
|
bindcode { BEGIN(BINDCODE_COND); return TOKBINDCODE; }
|
2009-09-29 05:32:57 -04:00
|
|
|
bindsym { BEGIN(BINDSYM_COND); return TOKBINDSYM; }
|
2010-01-08 12:56:01 -05:00
|
|
|
floating_modifier { BEGIN(INITIAL); return TOKFLOATING_MODIFIER; }
|
2009-09-13 12:40:35 -04:00
|
|
|
workspace { BEGIN(INITIAL); return TOKWORKSPACE; }
|
2010-03-02 07:35:43 -05:00
|
|
|
output { BEGIN(OUTPUT_COND); return TOKOUTPUT; }
|
|
|
|
screen {
|
|
|
|
/* for compatibility until v3.φ */
|
|
|
|
ELOG("Assignments to screens are DEPRECATED and will not work. " \
|
|
|
|
"Please replace them with assignments to outputs.\n");
|
|
|
|
BEGIN(OUTPUT_COND);
|
|
|
|
return TOKOUTPUT;
|
|
|
|
}
|
2009-09-13 12:40:35 -04:00
|
|
|
terminal { BEGIN(BIND_AWS_COND); return TOKTERMINAL; }
|
|
|
|
font { BEGIN(BIND_AWS_COND); return TOKFONT; }
|
|
|
|
assign { BEGIN(ASSIGN_COND); return TOKASSIGN; }
|
2009-09-13 15:32:58 -04:00
|
|
|
set[^\n]* { return TOKCOMMENT; }
|
2009-09-13 12:40:35 -04:00
|
|
|
ipc-socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
|
2009-09-27 14:44:24 -04:00
|
|
|
ipc_socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
|
2010-11-26 19:27:38 -05:00
|
|
|
restart_state { BEGIN(BIND_AWS_COND); return TOKRESTARTSTATE; }
|
2011-03-17 12:55:53 -04:00
|
|
|
default_orientation { return TOK_ORIENTATION; }
|
2011-03-16 06:56:51 -04:00
|
|
|
horizontal { return TOK_HORIZ; }
|
|
|
|
vertical { return TOK_VERT; }
|
|
|
|
auto { return TOK_AUTO; }
|
2011-04-02 15:49:35 -04:00
|
|
|
workspace_layout { return TOK_WORKSPACE_LAYOUT; }
|
2009-11-08 06:43:01 -05:00
|
|
|
new_window { return TOKNEWWINDOW; }
|
2010-12-07 18:32:04 -05:00
|
|
|
normal { return TOK_NORMAL; }
|
|
|
|
none { return TOK_NONE; }
|
|
|
|
1pixel { return TOK_1PIXEL; }
|
2010-01-26 06:10:48 -05:00
|
|
|
focus_follows_mouse { return TOKFOCUSFOLLOWSMOUSE; }
|
2010-03-13 13:15:28 -05:00
|
|
|
workspace_bar { return TOKWORKSPACEBAR; }
|
2011-03-06 09:45:42 -05:00
|
|
|
popup_during_fullscreen { return TOK_POPUP_DURING_FULLSCREEN; }
|
|
|
|
ignore { return TOK_IGNORE; }
|
|
|
|
leave_fullscreen { return TOK_LEAVE_FULLSCREEN; }
|
2011-05-15 14:10:25 -04:00
|
|
|
for_window {
|
|
|
|
/* Example: for_window [class="urxvt"] border none
|
|
|
|
*
|
|
|
|
* First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
|
|
|
|
* Then, we require a whitespace (REQUIRE_WS)
|
|
|
|
* And the rest of the line is parsed as a string
|
|
|
|
*/
|
|
|
|
yy_push_state(BIND_A2WS_COND);
|
|
|
|
yy_push_state(REQUIRE_WS);
|
|
|
|
yy_push_state(FOR_WINDOW_COND);
|
|
|
|
return TOK_FOR_WINDOW;
|
|
|
|
}
|
2011-03-23 11:11:46 -04: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 17:08:27 -04:00
|
|
|
stack-limit { return TOKSTACKLIMIT; }
|
2010-03-27 10:25:51 -04:00
|
|
|
cols { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
|
|
|
|
rows { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
|
2009-09-13 12:40:35 -04:00
|
|
|
exec { BEGIN(BIND_AWS_COND); return TOKEXEC; }
|
2010-11-13 14:07:49 -05:00
|
|
|
client.background { BEGIN(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
|
2009-09-13 12:40:35 -04:00
|
|
|
client.focused { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
|
|
|
|
client.focused_inactive { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
|
|
|
|
client.unfocused { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
|
|
|
|
client.urgent { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
|
2009-10-23 17:13:38 -04:00
|
|
|
bar.focused { BEGIN(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
|
|
|
|
bar.unfocused { BEGIN(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
|
|
|
|
bar.urgent { BEGIN(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
|
2009-09-13 12:40:35 -04: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 13:05:15 -04:00
|
|
|
Mode_switch { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
|
2009-09-13 12:40:35 -04:00
|
|
|
control { return TOKCONTROL; }
|
2009-11-12 14:28:09 -05:00
|
|
|
ctrl { return TOKCONTROL; }
|
2009-09-13 12:40:35 -04:00
|
|
|
shift { return TOKSHIFT; }
|
|
|
|
→ { return TOKARROW; }
|
2011-05-15 14:10:25 -04:00
|
|
|
|
|
|
|
class { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
|
|
|
|
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; }
|
|
|
|
|
2010-02-13 13:42:54 -05:00
|
|
|
{EOL} {
|
|
|
|
FREE(context->line_copy);
|
|
|
|
context->line_number++;
|
2010-03-02 07:35:43 -05:00
|
|
|
BEGIN(INITIAL);
|
2010-02-13 13:42:54 -05:00
|
|
|
yy_push_state(BUFFER_LINE);
|
|
|
|
}
|
2011-05-22 15:48:25 -04:00
|
|
|
<BINDCODE_COND>[ \t]+ { BEGIN(BIND_AWS_COND); }
|
|
|
|
<BINDSYM_COND>[ \t]+ { BEGIN(BINDSYM_AWS_COND); }
|
|
|
|
<BIND_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); }
|
|
|
|
<BINDSYM_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); }
|
|
|
|
<OUTPUT_COND>[ \t]+ { BEGIN(OUTPUT_AWS_COND); }
|
|
|
|
<OUTPUT_AWS_COND>[ \t]+ { BEGIN(BIND_A2WS_COND); }
|
|
|
|
[ \t]+ { /* ignore whitespace */ ; }
|
2009-09-13 12:40:35 -04:00
|
|
|
\"[^\"]+\" {
|
|
|
|
/* if ASSIGN_COND then */
|
|
|
|
BEGIN(INITIAL);
|
|
|
|
/* yylval will be the string, but without quotes */
|
|
|
|
char *copy = strdup(yytext+1);
|
|
|
|
copy[strlen(copy)-1] = '\0';
|
|
|
|
yylval.string = copy;
|
|
|
|
return QUOTEDSTRING;
|
|
|
|
}
|
|
|
|
<ASSIGN_COND>[^ \t]+ { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR_NG; }
|
2009-11-20 09:33:38 -05:00
|
|
|
<BINDSYM_AWS_COND>[a-zA-Z0-9_]+ { yylval.string = strdup(yytext); return WORD; }
|
2009-09-13 12:40:35 -04:00
|
|
|
[a-zA-Z]+ { yylval.string = strdup(yytext); return WORD; }
|
|
|
|
. { return (int)yytext[0]; }
|
2010-02-13 13:42:54 -05:00
|
|
|
|
|
|
|
<<EOF>> {
|
|
|
|
while (yy_start_stack_ptr > 0)
|
|
|
|
yy_pop_state();
|
|
|
|
yyterminate();
|
|
|
|
}
|
|
|
|
|
2009-09-13 08:16:39 -04:00
|
|
|
%%
|