5 """CSS Lexical Grammar rules.
7 CSS lexical grammar from http://www.w3.org/TR/CSS21/grammar.html
10 __author__ = [
'elsigh@google.com (Lindsey Simon)',
11 'msamuel@google.com (Mike Samuel)']
14 __all__ = [
"NEWLINE",
"HEX",
"NON_ASCII",
"UNICODE",
"ESCAPE",
"NMSTART",
"NMCHAR",
"STRING1",
"STRING2",
"IDENT",
"NAME",
"HASH",
"NUM",
"STRING",
"URL",
"SPACE",
"WHITESPACE",
"COMMENT",
"QUANTITY",
"PUNC" ]
22 KEYWORD =
r'(?:\@(?:import|page|media|charset))'
25 NEWLINE =
r'\n|\r\n|\r|\f'
31 NON_ASCII =
r'[\200-\377]'
34 UNICODE =
r'(?:(?:\\' + HEX +
r'{1,6})(?:\r\n|[ \t\r\n\f])?)'
37 ESCAPE =
r'(?:' + UNICODE +
r'|\\[^\r\n\f0-9a-f])'
40 NMSTART =
r'(?:[_a-z]|' + NON_ASCII +
r'|' + ESCAPE +
r')'
43 NMCHAR =
r'(?:[_a-z0-9-]|' + NON_ASCII +
r'|' + ESCAPE +
r')'
46 IDENT =
r'-?' + NMSTART + NMCHAR +
'*'
55 STRING1 =
r'"(?:[^\"\\]|\\.)*"'
58 STRING2 =
r"'(?:[^\'\\]|\\.)*'"
61 STRING =
'(?:' + STRING1 +
r'|' + STRING2 +
')'
64 NUM =
r'(?:[0-9]*\.[0-9]+|[0-9]+)'
67 SPACE =
r'[ \t\r\n\f]'
70 WHITESPACE =
'(?:' + SPACE +
r'*)'
73 URL_SPECIAL_CHARS =
r'[!#$%&*-~]'
76 URL_CHARS =
r'(?:%s|%s|%s)*' % (URL_SPECIAL_CHARS, NON_ASCII, ESCAPE)
79 URL =
r'url\(%s(%s|%s)%s\)' % (WHITESPACE, STRING, URL_CHARS, WHITESPACE)
83 COMMENT =
r'/\*[^*]*\*+([^/*][^*]*\*+)*/'
101 UNIT =
r'(?:em|ex|px|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|%)'
104 QUANTITY =
'%s(?:%s%s|%s)?' % (NUM, WHITESPACE, UNIT, IDENT)
114 PUNC =
r'<!--|-->|~=|\|=|[\{\+>,:;]'