2 * vim:ts=4:sw=4:expandtab
21 #include "cfgparse.tab.h"
25 #define YY_DECL int yylex (struct context *context)
27 #define YY_USER_ACTION { \
28 context->first_column = yycolumn; \
29 context->last_column = yycolumn+yyleng-1; \
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); \
57 /* This is called when a new line is lexed. We only want the
58 * first line to match to go into state BUFFER_LINE */
59 if (context->line_number == 0) {
60 context->line_number = 1;
62 yy_push_state(BUFFER_LINE);
66 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
68 context->line_copy = sstrdup(yytext);
77 <FOR_WINDOW_COND>"]" { yy_pop_state(); return ']'; }
79 /* this is the case for the new assign syntax
80 * that uses criteria */
82 yy_push_state(FOR_WINDOW_COND);
83 /* afterwards we will be in ASSIGN_TARGET_COND */
86 <EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
87 <WANT_QSTRING>\"[^\"]+\" {
90 char *copy = sstrdup(yytext+1);
91 copy[strlen(copy)-1] = '\0';
95 <WANT_STRING>[^\n]+ { BEGIN(INITIAL); yylval.string = sstrdup(yytext); return STR; }
96 <OUTPUT_COND>[a-zA-Z0-9_-]+ { yylval.string = sstrdup(yytext); return OUTPUT; }
97 ^[ \t]*#[^\n]* { return TOKCOMMENT; }
98 <COLOR_COND>[0-9a-fA-F]+ { yylval.string = sstrdup(yytext); return HEX; }
99 <ASSIGN_TARGET_COND>[ \t]*→[ \t]* { BEGIN(WANT_STRING); }
100 <ASSIGN_TARGET_COND>[ \t]+ { BEGIN(WANT_STRING); }
101 [0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
102 mode { return TOKMODE; }
103 bind { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
104 bindcode { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
105 bindsym { yy_push_state(BINDSYM_COND); yy_push_state(EAT_WHITESPACE); return TOKBINDSYM; }
106 floating_modifier { BEGIN(INITIAL); return TOKFLOATING_MODIFIER; }
107 workspace { BEGIN(INITIAL); return TOKWORKSPACE; }
108 output { yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE); return TOKOUTPUT; }
109 terminal { WS_STRING; return TOKTERMINAL; }
110 font { WS_STRING; return TOKFONT; }
111 assign { yy_push_state(ASSIGN_TARGET_COND); yy_push_state(ASSIGN_COND); return TOKASSIGN; }
112 set[^\n]* { return TOKCOMMENT; }
113 ipc-socket { WS_STRING; return TOKIPCSOCKET; }
114 ipc_socket { WS_STRING; return TOKIPCSOCKET; }
115 restart_state { WS_STRING; return TOKRESTARTSTATE; }
116 default_orientation { return TOK_ORIENTATION; }
117 horizontal { return TOK_HORIZ; }
118 vertical { return TOK_VERT; }
119 auto { return TOK_AUTO; }
120 workspace_layout { return TOK_WORKSPACE_LAYOUT; }
121 new_window { return TOKNEWWINDOW; }
122 new_float { return TOKNEWFLOAT; }
123 normal { return TOK_NORMAL; }
124 none { return TOK_NONE; }
125 1pixel { return TOK_1PIXEL; }
126 focus_follows_mouse { return TOKFOCUSFOLLOWSMOUSE; }
127 force_focus_wrapping { return TOK_FORCE_FOCUS_WRAPPING; }
128 force_xinerama { return TOK_FORCE_XINERAMA; }
129 workspace_bar { return TOKWORKSPACEBAR; }
130 popup_during_fullscreen { return TOK_POPUP_DURING_FULLSCREEN; }
131 ignore { return TOK_IGNORE; }
132 leave_fullscreen { return TOK_LEAVE_FULLSCREEN; }
134 /* Example: for_window [class="urxvt"] border none
136 * First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
137 * Then, we require a whitespace (EAT_WHITESPACE)
138 * And the rest of the line is parsed as a string
140 yy_push_state(WANT_STRING);
141 yy_push_state(EAT_WHITESPACE);
142 yy_push_state(FOR_WINDOW_COND);
143 return TOK_FOR_WINDOW;
145 default { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
146 stacking { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
147 stacked { return TOK_STACKING; }
148 tabbed { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
149 stack-limit { return TOKSTACKLIMIT; }
150 cols { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
151 rows { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
152 exec { WS_STRING; return TOKEXEC; }
153 exec_always { WS_STRING; return TOKEXEC_ALWAYS; }
154 client.background { BEGIN(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
155 client.focused { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
156 client.focused_inactive { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
157 client.unfocused { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
158 client.urgent { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
159 bar.focused { BEGIN(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
160 bar.unfocused { BEGIN(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
161 bar.urgent { BEGIN(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
162 Mod1 { yylval.number = BIND_MOD1; return MODIFIER; }
163 Mod2 { yylval.number = BIND_MOD2; return MODIFIER; }
164 Mod3 { yylval.number = BIND_MOD3; return MODIFIER; }
165 Mod4 { yylval.number = BIND_MOD4; return MODIFIER; }
166 Mod5 { yylval.number = BIND_MOD5; return MODIFIER; }
167 Mode_switch { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
168 control { return TOKCONTROL; }
169 ctrl { return TOKCONTROL; }
170 shift { return TOKSHIFT; }
172 class { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
173 instance { yy_push_state(WANT_QSTRING); return TOK_INSTANCE; }
174 window_role { yy_push_state(WANT_QSTRING); return TOK_WINDOW_ROLE; }
175 id { yy_push_state(WANT_QSTRING); return TOK_ID; }
176 con_id { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
177 con_mark { yy_push_state(WANT_QSTRING); return TOK_MARK; }
178 title { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
181 FREE(context->line_copy);
182 context->line_number++;
184 yy_push_state(BUFFER_LINE);
186 <BINDSYM_COND>[ \t]+ { BEGIN(WANT_STRING); }
187 <OUTPUT_COND>[ \t]+ { BEGIN(WANT_STRING); }
188 [ \t]+ { /* ignore whitespace */ ; }
190 /* if ASSIGN_COND then */
191 if (yy_start_stack_ptr > 0)
194 /* yylval will be the string, but without quotes */
195 char *copy = sstrdup(yytext+1);
196 copy[strlen(copy)-1] = '\0';
197 yylval.string = copy;
200 <ASSIGN_COND>[^ \t\"\[]+ { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
201 <BINDSYM_COND>[a-zA-Z0-9_]+ { yylval.string = sstrdup(yytext); return WORD; }
202 [a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
203 . { return (int)yytext[0]; }
206 while (yy_start_stack_ptr > 0)