2 * vim:ts=4:sw=4:expandtab
22 #include "cfgparse.tab.h"
26 #define YY_DECL int yylex (struct context *context)
28 #define YY_USER_ACTION { \
29 context->first_column = yycolumn; \
30 context->last_column = yycolumn+yyleng-1; \
34 /* macro to first eat whitespace, then expect a string */
35 #define WS_STRING do { \
36 yy_push_state(WANT_STRING); \
37 yy_push_state(EAT_WHITESPACE); \
40 #define BAR_DOUBLE_COLOR do { \
41 yy_push_state(BAR_COLOR); \
42 yy_push_state(BAR_COLOR); \
69 /* This is called when a new line is lexed. We only want the
70 * first line to match to go into state BUFFER_LINE */
71 if (context->line_number == 0) {
72 context->line_number = 1;
74 yy_push_state(BUFFER_LINE);
78 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
80 context->line_copy = sstrdup(yytext);
88 /* This part of the lexer handles the bar {} blocks */
89 <BAR,BAR_MODE,BAR_POSITION,BAR_COLORS,BAR_COLOR>[ \t]+ { /* ignore whitespace */ ; }
90 <BAR>"{" { return '{'; }
91 <BAR>"}" { yy_pop_state(); return '}'; }
92 <BAR>^[ \t]*#[^\n]* { return TOKCOMMENT; }
93 <BAR>output { WS_STRING; return TOK_BAR_OUTPUT; }
94 <BAR>tray_output { WS_STRING; return TOK_BAR_TRAY_OUTPUT; }
95 <BAR>socket_path { WS_STRING; return TOK_BAR_SOCKET_PATH; }
96 <BAR>mode { yy_push_state(BAR_MODE); return TOK_BAR_MODE; }
97 <BAR_MODE>hide { yy_pop_state(); return TOK_BAR_HIDE; }
98 <BAR_MODE>dock { yy_pop_state(); return TOK_BAR_DOCK; }
99 <BAR>position { yy_push_state(BAR_POSITION); return TOK_BAR_POSITION; }
100 <BAR_POSITION>bottom { yy_pop_state(); return TOK_BAR_BOTTOM; }
101 <BAR_POSITION>top { yy_pop_state(); return TOK_BAR_TOP; }
102 <BAR>status_command { WS_STRING; return TOK_BAR_STATUS_COMMAND; }
103 <BAR>font { WS_STRING; return TOK_BAR_FONT; }
104 <BAR>workspace_buttons { return TOK_BAR_WORKSPACE_BUTTONS; }
105 <BAR>verbose { return TOK_BAR_VERBOSE; }
106 <BAR>colors { yy_push_state(BAR_COLORS); return TOK_BAR_COLORS; }
107 <BAR_COLORS>"{" { return '{'; }
108 <BAR_COLORS>"}" { yy_pop_state(); return '}'; }
109 <BAR_COLORS>^[ \t]*#[^\n]* { return TOKCOMMENT; }
110 <BAR_COLORS>background { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_BACKGROUND; }
111 <BAR_COLORS>statusline { yy_push_state(BAR_COLOR); return TOK_BAR_COLOR_STATUSLINE; }
112 <BAR_COLORS>focused_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_FOCUSED_WORKSPACE; }
113 <BAR_COLORS>active_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_ACTIVE_WORKSPACE; }
114 <BAR_COLORS>inactive_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_INACTIVE_WORKSPACE; }
115 <BAR_COLORS>urgent_workspace { BAR_DOUBLE_COLOR; return TOK_BAR_COLOR_URGENT_WORKSPACE; }
116 <BAR_COLOR>#[0-9a-fA-F]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
117 <BAR,BAR_COLORS,BAR_MODE,BAR_POSITION>[a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
121 <FOR_WINDOW_COND>"]" { yy_pop_state(); return ']'; }
123 /* this is the case for the new assign syntax
124 * that uses criteria */
126 yy_push_state(FOR_WINDOW_COND);
127 /* afterwards we will be in ASSIGN_TARGET_COND */
130 <EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
131 <WANT_QSTRING>\"[^\"]+\" {
134 char *copy = sstrdup(yytext+1);
135 copy[strlen(copy)-1] = '\0';
136 yylval.string = copy;
139 <WANT_STRING>[^\n]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return STR; }
140 <OUTPUT_COND>[a-zA-Z0-9_-]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return OUTPUT; }
141 ^[ \t]*#[^\n]* { return TOKCOMMENT; }
142 <COLOR_COND>#[0-9a-fA-F]+ { yy_pop_state(); yylval.string = sstrdup(yytext); return HEXCOLOR; }
143 <ASSIGN_TARGET_COND>[ \t]*→[ \t]* { BEGIN(WANT_STRING); }
144 <ASSIGN_TARGET_COND>[ \t]+ { BEGIN(WANT_STRING); }
145 [0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
146 bar { yy_push_state(BAR); return TOK_BAR; }
147 mode { return TOKMODE; }
148 bind { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
149 bindcode { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
150 bindsym { yy_push_state(BINDSYM_COND); yy_push_state(EAT_WHITESPACE); return TOKBINDSYM; }
151 floating_modifier { return TOKFLOATING_MODIFIER; }
152 workspace { return TOKWORKSPACE; }
153 output { yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE); return TOKOUTPUT; }
154 terminal { WS_STRING; return TOKTERMINAL; }
155 font { WS_STRING; return TOKFONT; }
156 assign { yy_push_state(ASSIGN_TARGET_COND); yy_push_state(ASSIGN_COND); return TOKASSIGN; }
157 set[^\n]* { return TOKCOMMENT; }
158 ipc-socket { WS_STRING; return TOKIPCSOCKET; }
159 ipc_socket { WS_STRING; return TOKIPCSOCKET; }
160 restart_state { WS_STRING; return TOKRESTARTSTATE; }
161 default_orientation { return TOK_ORIENTATION; }
162 horizontal { return TOK_HORIZ; }
163 vertical { return TOK_VERT; }
164 auto { return TOK_AUTO; }
165 workspace_layout { return TOK_WORKSPACE_LAYOUT; }
166 new_window { return TOKNEWWINDOW; }
167 new_float { return TOKNEWFLOAT; }
168 normal { return TOK_NORMAL; }
169 none { return TOK_NONE; }
170 1pixel { return TOK_1PIXEL; }
171 focus_follows_mouse { return TOKFOCUSFOLLOWSMOUSE; }
172 force_focus_wrapping { return TOK_FORCE_FOCUS_WRAPPING; }
173 force_xinerama { return TOK_FORCE_XINERAMA; }
174 workspace_auto_back_and_forth { return TOK_WORKSPACE_AUTO_BAF; }
175 workspace_bar { return TOKWORKSPACEBAR; }
176 popup_during_fullscreen { return TOK_POPUP_DURING_FULLSCREEN; }
177 ignore { return TOK_IGNORE; }
178 leave_fullscreen { return TOK_LEAVE_FULLSCREEN; }
180 /* Example: for_window [class="urxvt"] border none
182 * First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
183 * Then, we require a whitespace (EAT_WHITESPACE)
184 * And the rest of the line is parsed as a string
186 yy_push_state(WANT_STRING);
187 yy_push_state(EAT_WHITESPACE);
188 yy_push_state(FOR_WINDOW_COND);
189 return TOK_FOR_WINDOW;
191 default { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
192 stacking { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
193 stacked { return TOK_STACKING; }
194 tabbed { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
195 stack-limit { return TOKSTACKLIMIT; }
196 cols { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
197 rows { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
198 exec { WS_STRING; return TOKEXEC; }
199 exec_always { WS_STRING; return TOKEXEC_ALWAYS; }
200 client.background { yy_push_state(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
201 client.focused { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
202 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; }
203 client.unfocused { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
204 client.urgent { yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yy_push_state(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
205 bar.focused { yy_push_state(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
206 bar.unfocused { yy_push_state(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
207 bar.urgent { yy_push_state(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
208 Mod1 { yylval.number = BIND_MOD1; return MODIFIER; }
209 Mod2 { yylval.number = BIND_MOD2; return MODIFIER; }
210 Mod3 { yylval.number = BIND_MOD3; return MODIFIER; }
211 Mod4 { yylval.number = BIND_MOD4; return MODIFIER; }
212 Mod5 { yylval.number = BIND_MOD5; return MODIFIER; }
213 Mode_switch { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
214 control { return TOKCONTROL; }
215 ctrl { return TOKCONTROL; }
216 shift { return TOKSHIFT; }
218 class { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
219 instance { yy_push_state(WANT_QSTRING); return TOK_INSTANCE; }
220 window_role { yy_push_state(WANT_QSTRING); return TOK_WINDOW_ROLE; }
221 id { yy_push_state(WANT_QSTRING); return TOK_ID; }
222 con_id { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
223 con_mark { yy_push_state(WANT_QSTRING); return TOK_MARK; }
224 title { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
227 FREE(context->line_copy);
228 context->line_number++;
229 yy_push_state(BUFFER_LINE);
231 <BINDSYM_COND>[ \t]+ { yy_pop_state(); yy_push_state(WANT_STRING); }
232 <OUTPUT_COND>[ \t]+ { yy_pop_state(); yy_push_state(WANT_STRING); }
233 [ \t]+ { /* ignore whitespace */ ; }
235 /* if ASSIGN_COND then */
236 if (yy_start_stack_ptr > 0)
238 /* yylval will be the string, but without quotes */
239 char *copy = sstrdup(yytext+1);
240 copy[strlen(copy)-1] = '\0';
241 yylval.string = copy;
244 <ASSIGN_COND>[^ \t\"\[]+ { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
245 <BINDSYM_COND>[a-zA-Z0-9_]+ { yylval.string = sstrdup(yytext); return WORD; }
246 [a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
247 . { return (int)yytext[0]; }
250 while (yy_start_stack_ptr > 0)