Package cssutils :: Module css3productions
[hide private]
[frames] | no frames]

Source Code for Module cssutils.css3productions

 1  """productions for CSS 3 
 2   
 3  CSS3_MACROS and CSS3_PRODUCTIONS are from http://www.w3.org/TR/css3-syntax 
 4  """ 
 5  __all__ = ['CSSProductions', 'MACROS', 'PRODUCTIONS'] 
 6  __docformat__ = 'restructuredtext' 
 7  __author__ = '$LastChangedBy: cthedot $' 
 8  __date__ = '$LastChangedDate: 2007-09-01 15:55:42 +0200 (Sa, 01 Sep 2007) $' 
 9  __version__ = '$LastChangedRevision: 300 $' 
10   
11  # a complete list of css3 macros 
12  MACROS = { 
13      'ident': r'[-]?{nmstart}{nmchar}*', 
14      'name': r'{nmchar}+', 
15      'nmstart': r'[_a-zA-Z]|{nonascii}|{escape}', 
16      'nonascii': r'[^\0-\177]', 
17      'unicode': r'\\[0-9a-f]{1,6}{wc}?', 
18      'escape': r'{unicode}|\\[ -~\200-\777]', 
19      #   'escape': r'{unicode}|\\[ -~\200-\4177777]', 
20      'nmchar': r'[-_a-zA-Z0-9]|{nonascii}|{escape}', 
21   
22      # CHANGED TO SPEC: added "-?" 
23      'num': r'-?[0-9]*\.[0-9]+|[0-9]+', #r'[-]?\d+|[-]?\d*\.\d+', 
24      'string':  r'''\'({stringchar}|\")*\'|\"({stringchar}|\')*\"''', 
25      'stringchar':  r'{urlchar}| |\\{nl}', 
26      'urlchar':  r'[\x09\x21\x23-\x26\x27-\x7E]|{nonascii}|{escape}', 
27      # what if \r\n, \n matches first? 
28      'nl': r'\n|\r\n|\r|\f', 
29      'w': r'{wc}*', 
30      'wc': r'\t|\r|\n|\f|\x20' 
31      } 
32   
33  # The following productions are the complete list of tokens in CSS3, the productions are **ordered**: 
34  PRODUCTIONS = [ 
35      ('BOM', r'\xFEFF'), 
36      ('URI', r'url\({w}({string}|{urlchar}*){w}\)'), 
37      ('FUNCTION', r'{ident}\('), 
38      ('ATKEYWORD', r'\@{ident}'), 
39      ('IDENT', r'{ident}'), 
40      ('STRING', r'{string}'), 
41      ('HASH', r'\#{name}'), 
42      ('PERCENTAGE', r'{num}\%'), 
43      ('DIMENSION', r'{num}{ident}'), 
44      ('NUMBER', r'{num}'), 
45      #??? 
46      ('UNICODE-RANGE', ur'[0-9A-F?]{1,6}(\-[0-9A-F]{1,6})?'), 
47      ('CDO', r'\<\!\-\-'), 
48      ('CDC', r'\-\-\>'), 
49      ('S', r'{wc}+'), 
50      ('INCLUDES', '\~\='), 
51      ('DASHMATCH', r'\|\='), 
52      ('PREFIXMATCH', r'\^\='), 
53      ('SUFFIXMATCH', r'\$\='), 
54      ('SUBSTRINGMATCH', r'\*\='), 
55      ('COMMENT', r'\/\*[^*]*\*+([^/][^*]*\*+)*\/'), 
56      ('CHAR', r'[^"\']'), 
57      ] 
58   
59 -class CSSProductions(object):
60 "has attributes for all PRODUCTIONS" 61 pass
62 63 for i, t in enumerate(PRODUCTIONS): 64 setattr(CSSProductions, t[0].replace('-', '_'), t[0]) 65