-
Notifications
You must be signed in to change notification settings - Fork 0
/
css_extended.py~
53 lines (46 loc) · 950 Bytes
/
css_extended.py~
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
#!/usr/bin/python
# ------------------------------------------------------------
# css_base.py
#
# tokenizer for css
# ------------------------------------------------------------
import ply.lex as lex
# List of token names.
tokens=(
'COMMENT',
'PROPERTY',
'REPLACE_PROPERTY',
'ID',
'DOLLAR',
'EQUALS',
'RCURL',
'LCURL',
'STRING'
)
def t_COMMENT(t):
'/\*(.|\n)*\*/'
pass
t_LCURL=r'\{'
t_RCURL=r'\}'
t_EQUALS=r'='
t_ignore = ' \t\r\n;'
t_DOLLAR=r'[$]'
def t_REPLACE_PROPERTY(t):
r'.*?:[$].*;'
return t
def t_PROPERTY(t):
r'.*?:.*;'
return t
t_ID=r'[A-Za-z]+[A-Za-z0-9_]*'
#t_SELECTOR=r'([A-Za-z_]*(.|\#)?[A-Za-z0-9_]* > )*([A-Za-z_]*(.|\#)?[A-Za-z0-9_]*(:[A-Za-z_]*))'
t_STRING=r'([A-Za-z0-9 ]|[,_>.@#"]|[-]|\'|[[]|[]])+;'
# Error handling rule
def t_error(t):
print "Illegal character '%s'" % t.value[0]
t.lexer.skip(1)
lexer = lex.lex()
while True:
data=raw_input()
lexer.input(data)
for tok in lexer:
print tok