]> git.sur5r.net Git - i3/i3/blob - i3-config-wizard/cfgparse.l
wizard: actually write the output config
[i3/i3] / i3-config-wizard / cfgparse.l
1 %option nounput
2 %option noinput
3 %option noyy_top_state
4 %option stack
5
6 %{
7 /*
8  * vim:ts=8:expandtab
9  *
10  */
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdint.h>
14 #include <stdbool.h>
15 #include "cfgparse.tab.h"
16
17 int yycolumn = 1;
18
19 struct context {
20         int line_number;
21         char *line_copy;
22
23         char *compact_error;
24
25         /* These are the same as in YYLTYPE */
26         int first_column;
27         int last_column;
28 };
29
30
31 #define YY_DECL int yylex (struct context *context)
32
33 #define YY_USER_ACTION { \
34         context->first_column = yycolumn; \
35         context->last_column = yycolumn+yyleng-1; \
36         yycolumn += yyleng; \
37 }
38
39 %}
40
41 EOL     (\r?\n)
42
43 %s BINDCODE_COND
44 %s BIND_AWS_COND
45 %s BIND_A2WS_COND
46 %x BUFFER_LINE
47
48 %%
49
50         {
51                 /* This is called when a new line is lexed. We only want the
52                  * first line to match to go into state BUFFER_LINE */
53                 if (context->line_number == 0) {
54                         context->line_number = 1;
55                         BEGIN(INITIAL);
56                         yy_push_state(BUFFER_LINE);
57                 }
58         }
59
60 <BUFFER_LINE>^[^\r\n]*/{EOL}? {
61         /* save whole line */
62         context->line_copy = strdup(yytext);
63
64         yyless(0);
65         yy_pop_state();
66         yy_set_bol(true);
67         yycolumn = 1;
68 }
69
70
71 <BIND_A2WS_COND>[^\n]+          { BEGIN(INITIAL); yylval.string = strdup(yytext); return STR; }
72 [0-9]+                          { yylval.number = atoi(yytext); return NUMBER; }
73 bind                            { BEGIN(BINDCODE_COND); return TOKBINDCODE; }
74 bindcode                        { BEGIN(BINDCODE_COND); return TOKBINDCODE; }
75 Mod1                            { yylval.number = (1 << 3); return MODIFIER; }
76 Mod2                            { yylval.number = (1 << 4); return MODIFIER; }
77 Mod3                            { yylval.number = (1 << 5); return MODIFIER; }
78 Mod4                            { yylval.number = (1 << 6); return MODIFIER; }
79 Mod5                            { yylval.number = (1 << 7); return MODIFIER; }
80 Mode_switch                     { yylval.number = (1 << 8); return MODIFIER; }
81 $mod                            { yylval.number = (1 << 9); return TOKMODVAR; }
82 control                         { return TOKCONTROL; }
83 ctrl                            { return TOKCONTROL; }
84 shift                           { return TOKSHIFT; }
85 {EOL}                           {
86                                   if (context->line_copy) {
87                                     free(context->line_copy);
88                                     context->line_copy = NULL;
89                                   }
90                                   context->line_number++;
91                                   BEGIN(INITIAL);
92                                   yy_push_state(BUFFER_LINE);
93                                 }
94 <BINDCODE_COND>[ \t]+           { BEGIN(BIND_AWS_COND); return WHITESPACE; }
95 <BIND_AWS_COND>[ \t]+           { BEGIN(BIND_A2WS_COND); return WHITESPACE; }
96 [ \t]+                          { return WHITESPACE; }
97 .                               { return (int)yytext[0]; }
98
99 <<EOF>> {
100         while (yy_start_stack_ptr > 0)
101                 yy_pop_state();
102         yyterminate();
103 }
104
105 %%