-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbconf.l
66 lines (58 loc) · 956 Bytes
/
bconf.l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* SPDX-License-Identifier: BSD-3-Clause */
%{
#include "mkconf.h"
#include "y.tab.h"
static char *
strdupesc(char *esc, size_t esclen) {
char buf[esclen + 1];
char *src = esc;
char *dst = buf;
while (*++src != '"') {
if (*src == '\\') {
switch (*++src) {
case '\n':
continue;
case 't':
*dst = '\t';
break;
case 'r':
*dst = '\r';
break;
case 'n':
*dst = '\n';
break;
default:
*dst = *src;
break;
}
} else {
*dst = *src;
}
dst++;
}
*dst = '\0';
return strdup(buf);
}
%}
%%
"config" return T_CONFIG;
"defaults" return T_DEFAULTS;
[A-Z][A-Z0-9_]* {
yylval.string = strdup(yytext);
return T_NAME;
}
\".*\" {
yylval.string = strdupesc(yytext, yyleng);
return T_STRING;
}
\n { yylineno++; }
[ \t\r]+
%%
int
yywrap(void) {
return feof(yyin);
}
void
yyerror(struct mkconf *mkconf, const char *message) {
mkconf_err(mkconf, "%d: %s near '%s'", yylineno, message, yytext);
}