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