-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOSStyleLex.l
79 lines (65 loc) · 1.67 KB
/
COSStyleLex.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
67
68
69
70
71
72
73
74
75
76
77
78
79
%{
#include <stdio.h>
#include "COSStyleDefine.h"
#include "COSStyleParser.h"
#define COSSTYLE_COPY_YYTEXT(charpp) \
do { \
*charpp = (char *)malloc((strlen(yytext) + 1) * sizeof(char)); \
strcpy(*charpp, yytext); \
} while (0)
%}
%option noyywrap
%option reentrant
%option case-insensitive
%option prefix="COSStyle"
%option header-file="COSStyleLex.h"
%option noinput
%option nounput
i [0-9]+
h [0-9a-f]
digit [-+]?{i}
float [-+]?({i}\.{i}?|{i}?\.{i})
number {digit}|{float}[fF]?
percentage ({digit}|{float})%
string1 \"[^\n\r\f"]*\"
string2 \'[^\n\r\f']*\'
string {string1}|{string2}
id -?[_a-z][_a-z0-9-]*
hexcolor #{h}+
%%
[ \n\r\t\f]
\/\*[^*]*\*+([^/*][^*]*\*+)*\/
"{" { return COSSTYLE_LBRACE; }
"}" { return COSSTYLE_RBRACE; }
"," { return COSSTYLE_COMMA; }
"." { return COSSTYLE_DOT; }
":" { return COSSTYLE_COLON; }
";" { return COSSTYLE_SEMI; }
"+" { return COSSTYLE_ADD; }
"-" { return COSSTYLE_SUB; }
"*" { return COSSTYLE_MUL; }
"/" { return COSSTYLE_DIV; }
"(" { return COSSTYLE_LPAREN; }
")" { return COSSTYLE_RPAREN; }
{id} {
COSSTYLE_COPY_YYTEXT(token_value);
return COSSTYLE_ID;
}
{number} {
COSSTYLE_COPY_YYTEXT(token_value);
return COSSTYLE_NUMBER;
}
{percentage} {
COSSTYLE_COPY_YYTEXT(token_value);
return COSSTYLE_PERCENTAGE;
}
{string} {
COSSTYLE_COPY_YYTEXT(token_value);
return COSSTYLE_STRING;
}
{hexcolor} {
COSSTYLE_COPY_YYTEXT(token_value);
return COSSTYLE_HEX;
}
. { return COSSTYLE_INVALID; }
%%