2009-03-29 20:50:27 -04:00
|
|
|
from mode import Fundamental
|
2008-01-27 15:10:13 -05:00
|
|
|
from lex import Grammar, PatternRule, RegionRule
|
2008-04-18 10:12:30 -04:00
|
|
|
|
|
|
|
class StringGrammar(Grammar):
|
|
|
|
rules = [
|
2009-03-29 20:50:27 -04:00
|
|
|
PatternRule('cheetah_placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'),
|
|
|
|
PatternRule('cheetah_placeholder', r'\$[a-zA-Z0-9_.\[\]]+'),
|
|
|
|
PatternRule('octal', r'\\[0-7]{3}'),
|
|
|
|
PatternRule('escaped', r'\\.'),
|
|
|
|
PatternRule('data', r'[^\$\\]+'),
|
2008-04-18 10:12:30 -04:00
|
|
|
]
|
|
|
|
|
2008-01-27 15:10:13 -05:00
|
|
|
class TagGrammar(Grammar):
|
|
|
|
rules = [
|
2009-03-29 20:50:27 -04:00
|
|
|
PatternRule('cheetah_placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'),
|
|
|
|
PatternRule('cheetah_placeholder', r'\$[a-zA-Z0-9_.\[\]]+'),
|
|
|
|
RegionRule('string', '"', StringGrammar, '"'),
|
|
|
|
RegionRule('string', "'", StringGrammar, "'"),
|
|
|
|
PatternRule('namespace', '[a-zA-Z_]+:'),
|
|
|
|
PatternRule('attrname', r'[^ =>\n]+(?==)'),
|
|
|
|
PatternRule('name', r'[^\[\] =>\n]+'),
|
2008-01-27 15:10:13 -05:00
|
|
|
]
|
|
|
|
|
|
|
|
class TemplateGrammar(Grammar):
|
|
|
|
rules = [
|
2009-03-29 20:50:27 -04:00
|
|
|
RegionRule('comment', r'#\*', Grammar, r'\*#'),
|
|
|
|
PatternRule('comment', r'##.*\n'),
|
|
|
|
PatternRule('cheetah_placeholder', r'\${[a-zA-Z0-9_.\[\]]+}'),
|
|
|
|
PatternRule('cheetah_placeholder', r'\$[a-zA-Z0-9_.\[\]]+'),
|
|
|
|
PatternRule('cheetah_directive', r'#.*?[#\n]'),
|
|
|
|
RegionRule('cheetah_tag', '</?', TagGrammar, '/?>'),
|
2008-01-27 15:10:13 -05:00
|
|
|
]
|
|
|
|
|
2009-03-29 20:50:27 -04:00
|
|
|
class Template(Fundamental):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'Cheetah'
|
2008-01-27 15:10:13 -05:00
|
|
|
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
|