pmacs3/mode_css.py

94 lines
4.1 KiB
Python

import color, mode2
from lex3 import Grammar, PatternRule, NocasePatternRule, RegionRule, NocaseRegionRule
from point2 import Point
class StringGrammar(Grammar):
rules = [
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
]
class KeywordGrammar(Grammar):
rules = [
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
RegionRule('string', "'", StringGrammar, r"'"),
RegionRule('string', '"', StringGrammar, r'"'),
]
class CSSGrammar(Grammar):
rules = [
RegionRule(r'comment', '/\*', Grammar, '\*/'),
RegionRule(r'htmlcomment', '<!--', Grammar, '-->'),
NocasePatternRule(r'dimension', r'[+-]?(?:[0-9]+|[0-9]*\.[0-9]+)[-a-z_][-a-z0-9_]*'),
NocasePatternRule(r'percentage', r'[+-]?(?:[0-9]+|[0-9]*\.[0-9]+)%%'),
NocasePatternRule(r'length', r'[+-]?(?:[0-9]+|[0-9]*\.[0-9]+)(?:em|ex|px|in|cm|mm|pt|pc)'),
NocasePatternRule(r'hash', r'#[-a-z0-9_]+'),
NocasePatternRule(r'real', r'[+-]?[0-9]*\.[0-9]+'),
NocasePatternRule(r'int', r'[+-]?[0-9]+'),
NocasePatternRule(r'rule', r'@(?:page|media|import)'),
NocasePatternRule(r'color', r'(?:aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|#[0-9]{6}|#[0-9]{3})'),
NocasePatternRule(r'keyword', r'(?:url|rgb|counter)'),
NocaseRegionRule(r'keyword', '(?:(?<=url)|(?<=rgb)|(?<=counter))\(', KeywordGrammar, '\)'),
NocasePatternRule(r'label', r"\.?[-a-zA-Z0-9_]+(?= *{)"),
NocasePatternRule(r'ident', r"-?[a-z_][-a-z0-9_]*"),
NocasePatternRule(r'name', r"[-a-z0-9_]+"),
NocasePatternRule(r'delimiter', r'[:;,{}()\[\]]|~=|\|=|='),
RegionRule(r'string', "'", StringGrammar, r"'"),
RegionRule(r'string', '"', StringGrammar, r'"'),
]
class CSS(mode2.Fundamental):
grammar = CSSGrammar
def __init__(self, w):
mode2.Fundamental.__init__(self, w)
self.add_bindings('close-paren', (')',))
self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',))
self.colors = {
'comment': color.build('red', 'default'),
'comment.start': color.build('red', 'default'),
'comment.null': color.build('red', 'default'),
'comment.end': color.build('red', 'default'),
'htmlcomment': color.build('red', 'default'),
'htmlcomment.start': color.build('red', 'default'),
'htmlcomment.null': color.build('red', 'default'),
'htmlcomment.end': color.build('red', 'default'),
'dimension': color.build('magenta', 'default'),
'percentage': color.build('magenta', 'default'),
'length': color.build('magenta', 'default'),
'real': color.build('magenta', 'default'),
'int': color.build('magenta', 'default'),
'color': color.build('magenta', 'default'),
'hash': color.build('cyan', 'default'),
'label': color.build('cyan', 'default'),
'rule': color.build('cyan', 'default'),
'keyword': color.build('cyan', 'default'),
'ident': color.build('default', 'default'),
'name': color.build('default', 'default'),
'delimiter': color.build('default', 'default'),
'keyword': color.build('cyan', 'default'),
'keyword.start': color.build('default', 'default'),
'keyword.null': color.build('cyan', 'default'),
'keyword.octal': color.build('magenta', 'default'),
'keyword.escaped': color.build('magenta', 'default'),
'keyword.end': color.build('default', 'default'),
'string.start': color.build('green', 'default'),
'string.null': color.build('green', 'default'),
'string.octal': color.build('magenta', 'default'),
'string.escaped': color.build('magenta', 'default'),
'string.end': color.build('green', 'default'),
}
def name(self):
return "Javascript"