pmacs3/mode/css.py

79 lines
3.5 KiB
Python
Raw Permalink Normal View History

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
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'\\.'),
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 = [
RegionRule(r'comment', '/\*', CommentGrammar1, '\*/'),
RegionRule(r'comment', '<!--', CommentGrammar2, '-->'),
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
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
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'[:;,{}()\[\]]|~=|\|=|='),
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):
name = 'CSS'
extensions = ['.css']
grammar = CSSGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
'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