2007-07-08 15:01:55 -04:00
|
|
|
import color, mode2
|
2007-07-15 09:44:20 -04:00
|
|
|
from lex3 import Grammar, PatternRule, NocasePatternRule, RegionRule, NocaseRegionRule
|
2007-07-08 15:01:55 -04:00
|
|
|
from point2 import Point
|
|
|
|
|
|
|
|
class StringGrammar(Grammar):
|
|
|
|
rules = [
|
2007-07-15 15:07:36 -04:00
|
|
|
PatternRule(r'octal', r'\\[0-7]{3}'),
|
|
|
|
PatternRule(r'escaped', r'\\.'),
|
2007-07-08 15:01:55 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
class KeywordGrammar(Grammar):
|
|
|
|
rules = [
|
2007-07-15 15:07:36 -04:00
|
|
|
PatternRule(r'octal', r'\\[0-7]{3}'),
|
|
|
|
PatternRule(r'escaped', r'\\.'),
|
|
|
|
RegionRule('string', "'", StringGrammar, r"'"),
|
|
|
|
RegionRule('string', '"', StringGrammar, r'"'),
|
2007-07-08 15:01:55 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
class CSSGrammar(Grammar):
|
|
|
|
rules = [
|
2007-07-15 15:07:36 -04:00
|
|
|
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})'),
|
2007-07-08 15:01:55 -04:00
|
|
|
|
2007-07-15 15:07:36 -04:00
|
|
|
NocasePatternRule(r'keyword', r'(?:url|rgb|counter)'),
|
|
|
|
NocaseRegionRule(r'keyword', '(?:(?<=url)|(?<=rgb)|(?<=counter))\(', KeywordGrammar, '\)'),
|
2007-07-08 15:01:55 -04:00
|
|
|
|
2007-07-15 15:07:36 -04:00
|
|
|
NocasePatternRule(r'label', r"\.?[-a-zA-Z0-9_]+(?= *{)"),
|
2007-07-08 15:01:55 -04:00
|
|
|
|
2007-07-15 15:07:36 -04:00
|
|
|
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'"'),
|
2007-07-08 15:01:55 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
class CSS(mode2.Fundamental):
|
2007-07-15 15:07:36 -04:00
|
|
|
grammar = CSSGrammar
|
2007-07-18 07:22:12 -04:00
|
|
|
colors = {
|
|
|
|
'comment': ('red', 'default'),
|
|
|
|
'comment.start': ('red', 'default'),
|
|
|
|
'comment.null': ('red', 'default'),
|
|
|
|
'comment.end': ('red', 'default'),
|
2007-07-08 15:01:55 -04:00
|
|
|
|
2007-07-18 07:22:12 -04:00
|
|
|
'htmlcomment': ('red', 'default'),
|
|
|
|
'htmlcomment.start': ('red', 'default'),
|
|
|
|
'htmlcomment.null': ('red', 'default'),
|
|
|
|
'htmlcomment.end': ('red', 'default'),
|
2007-07-08 15:01:55 -04:00
|
|
|
|
2007-07-18 07:22:12 -04:00
|
|
|
'dimension': ('magenta', 'default'),
|
|
|
|
'percentage': ('magenta', 'default'),
|
|
|
|
'length': ('magenta', 'default'),
|
|
|
|
'real': ('magenta', 'default'),
|
|
|
|
'int': ('magenta', 'default'),
|
|
|
|
'color': ('magenta', 'default'),
|
2007-07-08 15:01:55 -04:00
|
|
|
|
2007-07-18 07:22:12 -04:00
|
|
|
'hash': ('cyan', 'default'),
|
|
|
|
'label': ('cyan', 'default'),
|
|
|
|
'rule': ('cyan', 'default'),
|
|
|
|
'keyword': ('cyan', 'default'),
|
2007-07-08 15:01:55 -04:00
|
|
|
|
2007-07-18 07:22:12 -04:00
|
|
|
'ident': ('default', 'default'),
|
|
|
|
'name': ('default', 'default'),
|
2007-07-08 15:01:55 -04:00
|
|
|
|
2007-07-18 07:22:12 -04:00
|
|
|
'delimiter': ('default', 'default'),
|
2007-07-08 15:01:55 -04:00
|
|
|
|
2007-07-18 07:22:12 -04:00
|
|
|
'keyword': ('cyan', 'default'),
|
|
|
|
'keyword.start': ('default', 'default'),
|
|
|
|
'keyword.null': ('cyan', 'default'),
|
|
|
|
'keyword.octal': ('magenta', 'default'),
|
|
|
|
'keyword.escaped': ('magenta', 'default'),
|
|
|
|
'keyword.end': ('default', 'default'),
|
2007-07-08 15:01:55 -04:00
|
|
|
|
2007-07-18 07:22:12 -04:00
|
|
|
'string.start': ('green', 'default'),
|
|
|
|
'string.null': ('green', 'default'),
|
|
|
|
'string.octal': ('magenta', 'default'),
|
|
|
|
'string.escaped': ('magenta', 'default'),
|
|
|
|
'string.end': ('green', 'default'),
|
|
|
|
}
|
|
|
|
def __init__(self, w):
|
|
|
|
mode2.Fundamental.__init__(self, w)
|
|
|
|
self.add_bindings('close-paren', (')',))
|
|
|
|
self.add_bindings('close-brace', ('}',))
|
|
|
|
self.add_bindings('close-bracket', (']',))
|
2007-07-08 15:01:55 -04:00
|
|
|
def name(self):
|
|
|
|
return "Javascript"
|