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