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 workspace_bar { return TOKWORKSPACEBAR; }
129 popup_during_fullscreen { return TOK_POPUP_DURING_FULLSCREEN; }
130 ignore { return TOK_IGNORE; }
131 leave_fullscreen { return TOK_LEAVE_FULLSCREEN; }
133 /* Example: for_window [class="urxvt"] border none
135 * First, we wait for the ']' that finishes a match (FOR_WINDOW_COND)
136 * Then, we require a whitespace (EAT_WHITESPACE)
137 * And the rest of the line is parsed as a string
139 yy_push_state(WANT_STRING);
140 yy_push_state(EAT_WHITESPACE);
141 yy_push_state(FOR_WINDOW_COND);
142 return TOK_FOR_WINDOW;
144 default { /* yylval.number = MODE_DEFAULT; */return TOK_DEFAULT; }
145 stacking { /* yylval.number = MODE_STACK; */return TOK_STACKING; }
146 stacked { return TOK_STACKING; }
147 tabbed { /* yylval.number = MODE_TABBED; */return TOK_TABBED; }
148 stack-limit { return TOKSTACKLIMIT; }
149 cols { /* yylval.number = STACK_LIMIT_COLS; */return TOKSTACKLIMIT; }
150 rows { /* yylval.number = STACK_LIMIT_ROWS; */return TOKSTACKLIMIT; }
151 exec { WS_STRING; return TOKEXEC; }
152 exec_always { WS_STRING; return TOKEXEC_ALWAYS; }
153 client.background { BEGIN(COLOR_COND); yylval.single_color = &config.client.background; return TOKSINGLECOLOR; }
154 client.focused { BEGIN(COLOR_COND); yylval.color = &config.client.focused; return TOKCOLOR; }
155 client.focused_inactive { BEGIN(COLOR_COND); yylval.color = &config.client.focused_inactive; return TOKCOLOR; }
156 client.unfocused { BEGIN(COLOR_COND); yylval.color = &config.client.unfocused; return TOKCOLOR; }
157 client.urgent { BEGIN(COLOR_COND); yylval.color = &config.client.urgent; return TOKCOLOR; }
158 bar.focused { BEGIN(COLOR_COND); yylval.color = &config.bar.focused; return TOKCOLOR; }
159 bar.unfocused { BEGIN(COLOR_COND); yylval.color = &config.bar.unfocused; return TOKCOLOR; }
160 bar.urgent { BEGIN(COLOR_COND); yylval.color = &config.bar.urgent; return TOKCOLOR; }
161 Mod1 { yylval.number = BIND_MOD1; return MODIFIER; }
162 Mod2 { yylval.number = BIND_MOD2; return MODIFIER; }
163 Mod3 { yylval.number = BIND_MOD3; return MODIFIER; }
164 Mod4 { yylval.number = BIND_MOD4; return MODIFIER; }
165 Mod5 { yylval.number = BIND_MOD5; return MODIFIER; }
166 Mode_switch { yylval.number = BIND_MODE_SWITCH; return MODIFIER; }
167 control { return TOKCONTROL; }
168 ctrl { return TOKCONTROL; }
169 shift { return TOKSHIFT; }
171 class { yy_push_state(WANT_QSTRING); return TOK_CLASS; }
172 instance { yy_push_state(WANT_QSTRING); return TOK_INSTANCE; }
173 id { yy_push_state(WANT_QSTRING); return TOK_ID; }
174 con_id { yy_push_state(WANT_QSTRING); return TOK_CON_ID; }
175 con_mark { yy_push_state(WANT_QSTRING); return TOK_MARK; }
176 title { yy_push_state(WANT_QSTRING); return TOK_TITLE; }
179 FREE(context->line_copy);
180 context->line_number++;
182 yy_push_state(BUFFER_LINE);
184 <BINDSYM_COND>[ \t]+ { BEGIN(WANT_STRING); }
185 <OUTPUT_COND>[ \t]+ { BEGIN(WANT_STRING); }
186 [ \t]+ { /* ignore whitespace */ ; }
188 /* if ASSIGN_COND then */
189 if (yy_start_stack_ptr > 0)
192 /* yylval will be the string, but without quotes */
193 char *copy = sstrdup(yytext+1);
194 copy[strlen(copy)-1] = '\0';
195 yylval.string = copy;
198 <ASSIGN_COND>[^ \t\"\[]+ { BEGIN(ASSIGN_TARGET_COND); yylval.string = sstrdup(yytext); return STR_NG; }
199 <BINDSYM_COND>[a-zA-Z0-9_]+ { yylval.string = sstrdup(yytext); return WORD; }
200 [a-zA-Z]+ { yylval.string = sstrdup(yytext); return WORD; }
201 . { return (int)yytext[0]; }
204 while (yy_start_stack_ptr > 0)