File: css_lex.l

package info (click to toggle)
htmlcxx 0.87-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,412 kB
  • sloc: sh: 4,380; cpp: 4,355; yacc: 526; ansic: 205; lex: 159; makefile: 47; perl: 27
file content (159 lines) | stat: -rw-r--r-- 3,859 bytes parent folder | download | duplicates (8)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
%{

#include <string.h>
#include "css_syntax.h"

#define YY_DECL int yylex(YYSTYPE *lvalp)

%}

%option noyywrap

unicode		\\[0-9a-f]{1,4}
latin1		[-]
escape		{unicode}|\\[ -~-]
stringchar	{escape}|{latin1}|[ !#$%&(-~]
nmstrt		[a-z]|{latin1}|{escape}
nmchar		[-a-z0-9]|{latin1}|{escape}
ident		{nmstrt}{nmchar}*
name		{nmchar}+
d		[0-9]
notnm		[^-a-z0-9\\]|{latin1}
w		[ \t\r\n]*
num		{d}+|{d}*\.{d}+
string		\"({stringchar}|\')*\"|\'({stringchar}|\")*\'

%x COMMENT
%s AFTER_IDENT

%%

"/*"				{BEGIN(COMMENT);}
<COMMENT>[^*]*		/* eat anything that's not a '*' */
<COMMENT>"*"+[^*/]*	/* eat up '*'s not followed by '/'s */
<COMMENT>"*"+"/"        BEGIN(0);
@import				{BEGIN(0); return IMPORT_SYM;}
"!"{w}important			{BEGIN(0); return IMPORTANT_SYM;}
{ident}				{
						BEGIN(AFTER_IDENT);
						lvalp->lexeme = strdup(yytext);
						return IDENT;
					}
{string}			{
						BEGIN(0); 
						lvalp->lexeme = strdup(yytext);
						return STRING;
					}

{num}				{
						BEGIN(0); 
						lvalp->lexeme = strdup(yytext);
						return NUMBER;
					}
{num}"%"			{
						BEGIN(0);
						lvalp->lexeme = strdup(yytext);
						return PERCENTAGE;
					}
{num}pt/{notnm}			{
							BEGIN(0); 
							lvalp->lexeme = strdup(yytext);
							return LENGTH;
						}
{num}mm/{notnm}			{
							BEGIN(0); 
							lvalp->lexeme = strdup(yytext);
							return LENGTH;
						}
{num}cm/{notnm}			{
							BEGIN(0); 
							lvalp->lexeme = strdup(yytext);
							return LENGTH;
						}
{num}pc/{notnm}			{
							BEGIN(0); 
							lvalp->lexeme = strdup(yytext);
							return LENGTH;
						}
{num}in/{notnm}			{
							BEGIN(0); 
							lvalp->lexeme = strdup(yytext);
							return LENGTH;
						}
{num}px/{notnm}			{
							BEGIN(0); 
							lvalp->lexeme = strdup(yytext);
							return LENGTH;
						}
{num}em/{notnm}			{
							BEGIN(0); 
							lvalp->lexeme = strdup(yytext);
							return EMS;
						}
{num}ex/{notnm}			{
							BEGIN(0); 
							lvalp->lexeme = strdup(yytext);
							return EXS;
						}

<AFTER_IDENT>":"link		{return LINK_PSCLASS_AFTER_IDENT;}
<AFTER_IDENT>":"visited	{return VISITED_PSCLASS_AFTER_IDENT;}
<AFTER_IDENT>":"active	{return ACTIVE_PSCLASS_AFTER_IDENT;}
<AFTER_IDENT>":"first-line	{return FIRST_LINE_AFTER_IDENT;}
<AFTER_IDENT>":"first-letter	{return FIRST_LETTER_AFTER_IDENT;}
<AFTER_IDENT>"#"{name}		{
								lvalp->lexeme = strdup(yytext+1);
								return HASH_AFTER_IDENT;
							}
<AFTER_IDENT>"."{name}		{
								lvalp->lexeme = strdup(yytext+1);
								return CLASS_AFTER_IDENT;
							}

":"link				{BEGIN(AFTER_IDENT); return LINK_PSCLASS;}
":"visited			{BEGIN(AFTER_IDENT); return VISITED_PSCLASS;}
":"active			{BEGIN(AFTER_IDENT); return ACTIVE_PSCLASS;}
":"first-line		{BEGIN(AFTER_IDENT); return FIRST_LINE;}
":"first-letter		{BEGIN(AFTER_IDENT); return FIRST_LETTER;}
"#"{name}			{
						BEGIN(AFTER_IDENT);
						lvalp->lexeme = strdup(yytext+1);
						return HASH;
					}
"."{name}			{
						BEGIN(AFTER_IDENT);
						lvalp->lexeme = strdup(yytext+1);
						return CLASS;
					}

url\({w}{string}{w}\)					|
url\({w}([^ \r\n\'\")]|\\\ |\\\'|\\\"|\\\))+{w}\)		{
														BEGIN(0); 
														lvalp->lexeme = 
															strdup(yytext);
														return URL;
													}
rgb\({w}{num}%?{w}\,{w}{num}%?{w}\,{w}{num}%?{w}\)	{
														BEGIN(0);
														lvalp->lexeme = 
															strdup(yytext);
														return RGB;
													}

[-/+{};,#:]			{BEGIN(0); return *yytext;}
[ \t\r]+				{BEGIN(0); /* ignore whitespace */}
\n				{BEGIN(0); /* ignore whitespace */}
\<\!\-\-			{BEGIN(0); return CDO;}
\-\-\>				{BEGIN(0); return CDC;}
\/\/				{BEGIN(0); return CSL;}
.				{fprintf(stderr, "Illegal character (%d)\n", *yytext);}

%%

int init_yylex(const char *buffer, int buf_len) {
	yy_scan_bytes(buffer, buf_len);
}

int end_yylex() {
	yy_delete_buffer(YY_CURRENT_BUFFER);
}