-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_lexer.l
62 lines (51 loc) · 1.34 KB
/
config_lexer.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
%{
#include "parser.h"
%}
%option noyywrap
%option nounput
%option noinput
%option nodefault
%option warn
EOL (\r|\n|\n\r|\r\n)
STRING [a-zA-Z_][a-zA-Z0-9_]*
NUMBER [0-9]+
LBRACE \{
RBRACE \}
LPAREN \(
RPAREN \)
COMA ,
EQ =
COMMENT \/\/.*
%%
button {return TOKEN_BUTTON;}
axis {return TOKEN_AXIS;}
new_axis {return TOKEN_NEW_AXIS;}
if {return TOKEN_IF;}
device {return TOKEN_DEVICE;}
grab {return TOKEN_GRAB;}
avoid {return TOKEN_AVOID;}
{EQ} {return TOKEN_EQ;}
{LPAREN} {return TOKEN_LPAREN;}
{RPAREN} {return TOKEN_RPAREN;}
{LBRACE} {return TOKEN_LBRACE;}
{RBRACE} {return TOKEN_RBRACE;}
{COMA} {return TOKEN_COMA;}
{EOL} {++edslineno;}
[[:blank:]]+ /*eat whitespaces*/
{NUMBER} {
edslval.num = atoi(yytext);
return TOKEN_NUMBER;
}
{STRING} {
edslval.str = strdup(yytext);
return TOKEN_STRING;
}
["][^"]*["] {
size_t len = strlen(yytext);
//skip the first and leave out the last
edslval.str = strndup(yytext + 1, len - 2);
return TOKEN_STRING;
}
{COMMENT}
. {printf("Unmatched character '%s' at line %d.\n", edstext, edslineno);}
%%