8 * 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); \
56 /* This is called when a new line is lexed. We only want the
57 * first line to match to go into state BUFFER_LINE */
58 if (context->line_number == 0) {
59 context->line_number = 1;
61 yy_push_state(BUFFER_LINE);
65 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
67 context->line_copy = sstrdup(yytext);
76 <FOR_WINDOW_COND>"]" { yy_pop_state(); return ']'; }
77 <EAT_WHITESPACE>[ \t]* { yy_pop_state(); }
78 <WANT_QSTRING>\"[^\"]+\" {
81 char *copy = sstrdup(yytext+1);
82 copy[strlen(copy)-1] = '\0';
86 <WANT_STRING>[^\n]+ { BEGIN(INITIAL); yylval.string = sstrdup(yytext); return STR; }
87 <OUTPUT_COND>[a-zA-Z0-9_-]+ { yylval.string = sstrdup(yytext); return OUTPUT; }
88 ^[ \t]*#[^\n]* { return TOKCOMMENT; }
89 <COLOR_COND>[0-9a-fA-F]+ { yylval.string = sstrdup(yytext); return HEX; }
90 [0-9]+ { yylval.number = atoi(yytext); return NUMBER; }
91 mode { return TOKMODE; }
92 bind { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
93 bindcode { yy_push_state(WANT_STRING); yy_push_state(EAT_WHITESPACE); yy_push_state(EAT_WHITESPACE); return TOKBINDCODE; }
94 bindsym { yy_push_state(BINDSYM_COND); yy_push_state(EAT_WHITESPACE); return TOKBINDSYM; }
95 floating_modifier { BEGIN(INITIAL); return TOKFLOATING_MODIFIER; }
96 workspace { BEGIN(INITIAL); return TOKWORKSPACE; }
97 output { yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE); return TOKOUTPUT; }
99 /* for compatibility until v3.φ */
100 ELOG("Assignments to screens are DEPRECATED and will not work. " \
101 "Please replace them with assignments to outputs.\n");
102 yy_push_state(OUTPUT_COND); yy_push_state(EAT_WHITESPACE);
105 terminal { WS_STRING; return TOKTERMINAL; }
106 font { WS_STRING; return TOKFONT; }
107 assign { BEGIN(ASSIGN_COND); return TOKASSIGN; }
108 set[^\n]* { return TOKCOMMENT; }
109 ipc-socket { WS_STRING; return TOKIPCSOCKET; }
110 ipc_socket { WS_STRING; return TOKIPCSOCKET; }
111 restart_state { WS_STRING; return TOKRESTARTSTATE; }
112 default_orientation { return TOK_ORIENTATION; }
113 horizontal { return TOK_HORIZ; }
114 vertical { return TOK_VERT; }
115 auto { return TOK_AUTO; }
116 workspace_layout { return TOK_WORKSPACE_LAYOUT; }
117 new_window { return TOKNEWWINDOW; }
118 normal { return TOK_NORMAL; }
119 none { return TOK_NONE; }
120 1pixel { return TOK_1PIXEL; }
121 focus_follows_mouse { return TOKFOCUSFOLLOWSMOUSE; }
122 workspace_bar { return TOKWORKSPACEBAR; }
123 popup_during_fullscreen { return TOK_POPUP_DURING_FULLSCREEN; }
124 ignore { return TOK_IGNORE; }
125 leave_fullscreen { return TOK_LEAVE_FULLSCREEN; }
127 /* Example: for_window [class="urxvt"] border none
129 * First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
130 * Then, we require a whitespace (EAT_WHITESPACE)
131 * And the rest of the line is parsed as a string
133 yy_push_state(WANT_STRING);
134 yy_push_state(EAT_WHITESPACE);
135 yy_push_state(FOR_WINDOW_COND);
136 return TOK_FOR_WINDOW;
138 default { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
139 stacking { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
140 stacked { return TOK_STACKING; }
141 tabbed { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
142 stack-limit { return TOKSTACKLIMIT; }
143 cols { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
144 rows { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
145 exec { WS_STRING; return TOKEXEC; }
146 client.background { BEGIN(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
147 client.focused { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
148 client.focused_inactive { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
149 client.unfocused { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
150 client.urgent { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
151 bar.focused { BEGIN(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
152 bar.unfocused { BEGIN(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
153 bar.urgent { BEGIN(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
154 Mod1 { yylval.number = BIND_MOD1; return MODIFIER; }
155 Mod2 { yylval.number = BIND_MOD2; return MODIFIER; }
156 Mod3 { yylval.number = BIND_MOD3; return MODIFIER; }
157 Mod4 { yylval.number = BIND_MOD4; return MODIFIER; }
158 Mod5 { yylval.number = BIND_MOD5; return MODIFIER; }
159 Mode_switch { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
160 control { return TOKCONTROL; }
161 ctrl { return TOKCONTROL; }
162 shift { return TOKSHIFT; }
163 → { return TOKARROW; }
165 class { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
166 id { yy_push_state(WANT_QSTRING); return TOK_ID; }
167 con_id { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
168 con_mark { yy_push_state(WANT_QSTRING); return TOK_MARK; }
169 title { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
172 FREE(context->line_copy);
173 context->line_number++;
175 yy_push_state(BUFFER_LINE);
177 <BINDSYM_COND>[ \t]+ { BEGIN(WANT_STRING); }
178 <OUTPUT_COND>[ \t]+ { BEGIN(WANT_STRING); }
179 [ \t]+ { /* ignore whitespace */ ; }
181 /* if ASSIGN_COND then */
183 /* yylval will be the string, but without quotes */
184 char *copy = sstrdup(yytext+1);
185 copy[strlen(copy)-1] = '\0';
186 yylval.string = copy;
189 <ASSIGN_COND>[^ \t]+ { BEGIN(INITIAL); yylval.string = sstrdup(yytext); return STR_NG; }
190 <BINDSYM_COND>[a-zA-Z0-9_]+ { yylval.string = sstrdup(yytext); return WORD; }
191 [a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
192 . { return (int)yytext[0]; }
195 while (yy_start_stack_ptr > 0)