2009-03-29 20:50:27 -04:00
|
|
|
from mode import Fundamental
|
2007-10-21 20:52:48 -04:00
|
|
|
from lex import Grammar, PatternRule, NocasePatternRule, RegionRule, NocaseRegionRule
|
2009-03-29 20:50:27 -04:00
|
|
|
from mode.python import StringGrammar1, StringGrammar2
|
2007-07-21 11:40:53 -04:00
|
|
|
|
2008-10-07 23:39:22 -04:00
|
|
|
class CommentGrammar1(Grammar):
|
|
|
|
rules = [PatternRule(r'data', r'(?:[^*]|\*(?!/))+')]
|
|
|
|
class CommentGrammar2(Grammar):
|
|
|
|
rules = [PatternRule(r'data', r'(?:[^-]|-(?!-)|--(?!>))+')]
|
|
|
|
|
2007-07-21 11:40:53 -04:00
|
|
|
class KeywordGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'octal', r'\\[0-7]{3}'),
|
|
|
|
PatternRule(r'escaped', r'\\.'),
|
2008-10-07 23:39:22 -04:00
|
|
|
RegionRule(r'string', "'", StringGrammar1, r"'"),
|
|
|
|
RegionRule(r'string', '"', StringGrammar2, r'"'),
|
2007-07-21 11:40:53 -04:00
|
|
|
]
|
|
|
|
|
2009-03-29 20:50:27 -04:00
|
|
|
chr2 = '[-a-z0-9_]'
|
|
|
|
|
2007-07-21 11:40:53 -04:00
|
|
|
class CSSGrammar(Grammar):
|
|
|
|
rules = [
|
2008-10-07 23:39:22 -04:00
|
|
|
RegionRule(r'comment', '/\*', CommentGrammar1, '\*/'),
|
|
|
|
RegionRule(r'comment', '<!--', CommentGrammar2, '-->'),
|
2009-03-29 20:50:27 -04:00
|
|
|
NocasePatternRule(r'css_dimension', r'[+-]?(?:\d+|\d*\.\d+)[-a-z_][-a-z0-9_]*'),
|
|
|
|
NocasePatternRule(r'css_percentage', r'[+-]?(?:\d+|\d*\.\d+)%%'),
|
|
|
|
NocasePatternRule(r'css_length', r'[+-]?(?:\d+|\d*\.\d+)(?:em|ex|px|in|cm|mm|pt|pc)'),
|
|
|
|
NocasePatternRule(r'css_hash', r'#' + chr2 + '+'),
|
|
|
|
NocasePatternRule(r'css_real', r'[+-]?\d*\.\d+'),
|
|
|
|
NocasePatternRule(r'css_int', r'[+-]?\d+'),
|
2008-03-16 10:53:35 -04:00
|
|
|
NocasePatternRule(r'css_rule', r'@(?:page|media|import)'),
|
2009-03-29 20:50:27 -04:00
|
|
|
NocasePatternRule(r'css_color', r'(?:aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|#\d{6}|#\d{3})(?!' + chr2 + ')'),
|
2007-07-21 11:40:53 -04:00
|
|
|
|
2008-03-16 01:23:14 -04:00
|
|
|
NocasePatternRule(r'css_keyword', r'(?:url|rgb|counter)'),
|
|
|
|
NocaseRegionRule(r'css_keyword', '(?:(?<=url)|(?<=rgb)|(?<=counter))\(', KeywordGrammar, '\)'),
|
2007-07-21 11:40:53 -04:00
|
|
|
|
2009-03-29 20:50:27 -04:00
|
|
|
NocasePatternRule(r'css_label', r"\.?" + chr2 + "+(?= *{)"),
|
|
|
|
NocasePatternRule(r'css_ident', r"-?[a-z_]" + chr2 + "*"),
|
|
|
|
NocasePatternRule(r'css_name', chr2 + "+"),
|
2007-07-21 11:40:53 -04:00
|
|
|
NocasePatternRule(r'delimiter', r'[:;,{}()\[\]]|~=|\|=|='),
|
2008-10-07 23:39:22 -04:00
|
|
|
RegionRule(r'string', "'", StringGrammar1, r"'"),
|
|
|
|
RegionRule(r'string', '"', StringGrammar2, r'"'),
|
2007-07-21 11:40:53 -04:00
|
|
|
]
|
|
|
|
|
2009-03-29 20:50:27 -04:00
|
|
|
class CSS(Fundamental):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'CSS'
|
|
|
|
extensions = ['.css']
|
|
|
|
grammar = CSSGrammar
|
2007-10-21 00:51:45 -04:00
|
|
|
opentokens = ('delimiter',)
|
|
|
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
|
|
|
closetokens = ('delimiter',)
|
|
|
|
closetags = {')': '(', ']': '[', '}': '{'}
|
2009-03-17 15:24:10 -04:00
|
|
|
colors = {
|
2008-10-07 23:39:22 -04:00
|
|
|
'css_dimension': ('magenta', 'default', 'bold'),
|
|
|
|
'css_percentage': ('magenta', 'default', 'bold'),
|
|
|
|
'css_length': ('magenta', 'default', 'bold'),
|
|
|
|
'css_real': ('magenta', 'default', 'bold'),
|
|
|
|
'css_int': ('magenta', 'default', 'bold'),
|
|
|
|
'css_color': ('magenta', 'default', 'bold'),
|
2008-05-03 13:31:30 -04:00
|
|
|
'css_hash': ('cyan', 'default', 'bold'),
|
|
|
|
'css_rule': ('cyan', 'default', 'bold'),
|
|
|
|
'css_label': ('cyan', 'default', 'bold'),
|
|
|
|
'css_keyword': ('cyan', 'default', 'bold'),
|
2009-03-29 20:50:27 -04:00
|
|
|
'css_ident': ('default', 'default'),
|
|
|
|
'css_name': ('default', 'default'),
|
2008-05-03 13:31:30 -04:00
|
|
|
'css_keyword': ('cyan', 'default', 'bold'),
|
|
|
|
'css_keyword.start': ('default', 'default', 'bold'),
|
|
|
|
'css_keyword.null': ('cyan', 'default', 'bold'),
|
|
|
|
'css_keyword.octal': ('magenta', 'default', 'bold'),
|
|
|
|
'css_keyword.escaped': ('magenta', 'default', 'bold'),
|
|
|
|
'css_keyword.end': ('default', 'default', 'bold'),
|
2007-07-21 11:40:53 -04:00
|
|
|
}
|
2009-02-15 12:06:35 -05:00
|
|
|
_bindings = {
|
|
|
|
'close-paren': (')',),
|
|
|
|
'close-brace': ('}',),
|
|
|
|
'close-bracket': (']',),
|
|
|
|
}
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = CSS.install
|