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-04-08 00:21:29 -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+'),
|
|
|
|
NocasePatternRule(r'css.rule', r'@(?:page|media|import)'),
|
|
|
|
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
|
|
|
|
2011-12-09 16:57:17 -05:00
|
|
|
NocasePatternRule(r'css.keyword', r'(?:url|rgba|rgb|counter)'),
|
|
|
|
NocaseRegionRule(r'css.keyword', '(?:(?<=url)|(?<=rgba)|(?<=rgb)|(?<=counter))\(', KeywordGrammar, '\)'),
|
2007-07-21 11:40:53 -04:00
|
|
|
|
2009-04-08 00:21:29 -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'[:;,{}()\[\]]|~=|\|=|='),
|
2009-04-08 00:21:29 -04:00
|
|
|
RegionRule(r'css.string', "'", StringGrammar1, r"'"),
|
|
|
|
RegionRule(r'css.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 = {
|
2009-04-08 00:21:29 -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'),
|
|
|
|
'css.hash': ('cyan', 'default', 'bold'),
|
|
|
|
'css.rule': ('cyan', 'default', 'bold'),
|
|
|
|
'css.label': ('cyan', 'default', 'bold'),
|
|
|
|
'css.keyword': ('cyan', 'default', 'bold'),
|
|
|
|
'css.ident': ('default', 'default'),
|
|
|
|
'css.name': ('default', 'default'),
|
|
|
|
'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
|