2008-01-27 15:10:13 -05:00
|
|
|
import color, mode
|
|
|
|
from lex import Grammar, PatternRule, RegionRule
|
2008-04-18 10:12:30 -04:00
|
|
|
|
|
|
|
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'\\.'),
|
2008-10-07 23:39:22 -04:00
|
|
|
PatternRule(r'data', r'[^\$\\]+'),
|
2008-04-18 10:12:30 -04:00
|
|
|
]
|
|
|
|
|
2008-01-27 15:10:13 -05:00
|
|
|
|
|
|
|
class TagGrammar(Grammar):
|
|
|
|
rules = [
|
2008-04-18 10:12:30 -04:00
|
|
|
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"'"),
|
2008-01-27 15:10:13 -05:00
|
|
|
PatternRule(r'namespace', r'[a-zA-Z_]+:'),
|
|
|
|
PatternRule(r'attrname', r'[^ =>\n]+(?==)'),
|
|
|
|
PatternRule(r'name', r'[^\[\] =>\n]+'),
|
|
|
|
]
|
|
|
|
|
|
|
|
class TemplateGrammar(Grammar):
|
|
|
|
rules = [
|
2008-01-27 17:05:49 -05:00
|
|
|
RegionRule(r'comment', r'#\*', Grammar, r'\*#'),
|
2008-01-27 15:10:13 -05:00
|
|
|
PatternRule(r'comment', r'##.*\n'),
|
2008-04-18 10:12:30 -04:00
|
|
|
PatternRule(r'cheetah_placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'),
|
|
|
|
PatternRule(r'cheetah_placeholder', r'\$[a-zA-Z0-9_.\[\]]+'),
|
2008-03-16 11:39:17 -04:00
|
|
|
PatternRule(r'cheetah_directive', r'#.*?[#\n]'),
|
2008-03-16 01:23:14 -04:00
|
|
|
RegionRule(r'cheetah_tag', r'</?', TagGrammar, r'/?>'),
|
2008-01-27 15:10:13 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
class Template(mode.Fundamental):
|
|
|
|
modename = 'Cheetah'
|
|
|
|
extensions = ['.tmpl']
|
|
|
|
grammar = TemplateGrammar
|
2009-02-15 12:06:35 -05:00
|
|
|
commentc = '##'
|
2008-01-27 15:10:13 -05:00
|
|
|
colors = {
|
2008-05-03 13:31:30 -04:00
|
|
|
'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'),
|
2008-01-27 15:10:13 -05:00
|
|
|
}
|
2009-02-15 12:06:35 -05:00
|
|
|
_bindings = {
|
|
|
|
'close-paren': (')',),
|
|
|
|
'close-brace': ('}',),
|
|
|
|
'close-bracket': (']',),
|
|
|
|
}
|
2008-01-27 15:10:13 -05:00
|
|
|
|
|
|
|
install = Template.install
|