import color, mode2 from lex2 import Grammar, PatternRule, NocasePatternRule, RegionRule, NocaseRegionRule from point2 import Point class StringGrammar(Grammar): rules = [ PatternRule(name=r'octal', pattern=r'\\[0-7]{3}'), PatternRule(name=r'escaped', pattern=r'\\.'), ] class KeywordGrammar(Grammar): rules = [ PatternRule(name=r'octal', pattern=r'\\[0-7]{3}'), PatternRule(name=r'escaped', pattern=r'\\.'), RegionRule(name='string', start="'", grammar=StringGrammar(), end="'"), RegionRule(name='string', start='"', grammar=StringGrammar(), end='"'), ] class CSSGrammar(Grammar): rules = [ RegionRule(name=r'comment', start='/\*', grammar=Grammar(), end='\*/'), RegionRule(name=r'htmlcomment', start=''), NocasePatternRule(name=r'dimension', pattern=r'[+-]?(?:[0-9]+|[0-9]*\.[0-9]+)[-a-z_][-a-z0-9_]*'), NocasePatternRule(name=r'percentage', pattern=r'[+-]?(?:[0-9]+|[0-9]*\.[0-9]+)%%'), NocasePatternRule(name=r'length', pattern=r'[+-]?(?:[0-9]+|[0-9]*\.[0-9]+)(?:em|ex|px|in|cm|mm|pt|pc)'), NocasePatternRule(name=r'hash', pattern=r'#[-a-z0-9_]+'), NocasePatternRule(name=r'real', pattern=r'[+-]?[0-9]*\.[0-9]+'), NocasePatternRule(name=r'int', pattern=r'[+-]?[0-9]+'), NocasePatternRule(name=r'rule', pattern=r'@(?:page|media|import)'), NocasePatternRule(name=r'color', pattern=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(name=r'keyword', pattern=r'(?:url|rgb|counter)'), NocaseRegionRule(name=r'keyword', start='(?:(?<=url)|(?<=rgb)|(?<=counter))\(', grammar=KeywordGrammar(), end='\)'), NocasePatternRule(name=r'label', pattern=r"\.?[-a-zA-Z0-9_]+(?= *{)"), NocasePatternRule(name=r'ident', pattern=r"-?[a-z_][-a-z0-9_]*"), NocasePatternRule(name=r'name', pattern=r"[-a-z0-9_]+"), NocasePatternRule(name=r'delimiter', pattern=r'[:;,{}()\[\]]|~=|\|=|='), RegionRule(name='string', start="'", grammar=StringGrammar(), end="'"), RegionRule(name='string', start='"', grammar=StringGrammar(), end='"'), ] 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"