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