import color, mode from lex import Grammar, PatternRule, RegionRule class StringGrammar(Grammar): rules = [ PatternRule(r'cheetah_placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'), PatternRule(r'cheetah_placeholder', r'\$[a-zA-Z0-9_.\[\]]+'), PatternRule(r'octal', r'\\[0-7]{3}'), PatternRule(r'escaped', r'\\.'), PatternRule(r'data', r'[^\$\\]+'), ] class TagGrammar(Grammar): rules = [ PatternRule(r'cheetah_placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'), PatternRule(r'cheetah_placeholder', r'\$[a-zA-Z0-9_.\[\]]+'), RegionRule(r'string', r'"', StringGrammar, r'"'), RegionRule(r'string', r"'", StringGrammar, r"'"), PatternRule(r'namespace', r'[a-zA-Z_]+:'), PatternRule(r'attrname', r'[^ =>\n]+(?==)'), PatternRule(r'name', r'[^\[\] =>\n]+'), ] class TemplateGrammar(Grammar): rules = [ RegionRule(r'comment', r'#\*', Grammar, r'\*#'), PatternRule(r'comment', r'##.*\n'), PatternRule(r'cheetah_placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'), PatternRule(r'cheetah_placeholder', r'\$[a-zA-Z0-9_.\[\]]+'), PatternRule(r'cheetah_directive', r'#.*?[#\n]'), RegionRule(r'cheetah_tag', r''), ] class Template(mode.Fundamental): modename = 'Cheetah' extensions = ['.tmpl'] grammar = TemplateGrammar commentc = '##' colors = { 'cheetah_directive': ('magenta', 'default', 'bold'), 'cheetah_placeholder': ('magenta', 'default', 'bold'), 'cheetah_tag.start': ('default', 'default', 'bold'), 'cheetah_tag.namespace': ('magenta', 'default', 'bold'), 'cheetah_tag.name': ('blue', 'default', 'bold'), 'cheetah_tag.attrname': ('cyan', 'default', 'bold'), 'cheetah_tag.string.start': ('green', 'default', 'bold'), 'cheetah_tag.string.null': ('green', 'default', 'bold'), 'cheetah_tag.string.end': ('green', 'default', 'bold'), 'cheetah_tag.end': ('default', 'default', 'bold'), } _bindings = { 'close-paren': (')',), 'close-brace': ('}',), 'close-bracket': (']',), } install = Template.install