2008-01-27 15:10:13 -05:00
|
|
|
import color, mode
|
|
|
|
from lex import Grammar, PatternRule, RegionRule
|
|
|
|
from mode.perl import StringGrammar
|
|
|
|
|
|
|
|
class TagGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'placeholder', r'\$[a-zA-Z0-9_]+'),
|
|
|
|
RegionRule(r'string', r'"', Grammar, r'"'),
|
|
|
|
RegionRule(r'string', r"'", Grammar, r"'"),
|
|
|
|
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'),
|
|
|
|
PatternRule(r'placeholder', r'\$[a-zA-Z0-9_]+'),
|
|
|
|
PatternRule(r'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
|
|
|
|
colors = {
|
2008-03-16 01:23:14 -04:00
|
|
|
#'comment': ('red', 'default'),
|
|
|
|
#'comment.start': ('red', 'default'),
|
|
|
|
#'comment.null': ('red', 'default'),
|
|
|
|
#'comment.end': ('red', 'default'),
|
2008-01-27 15:10:13 -05:00
|
|
|
|
|
|
|
'directive': ('magenta', 'default'),
|
|
|
|
'placeholder': ('magenta', 'default'),
|
|
|
|
|
2008-03-16 01:23:14 -04:00
|
|
|
'cheetah_tag.start': ('default', 'default'),
|
|
|
|
'cheetah_tag.namespace': ('magenta', 'default'),
|
|
|
|
'cheetah_tag.name': ('blue', 'default'),
|
|
|
|
'cheetah_tag.attrname': ('cyan', 'default'),
|
|
|
|
'cheetah_tag.string.start': ('green', 'default'),
|
|
|
|
'cheetah_tag.string.null': ('green', 'default'),
|
|
|
|
'cheetah_tag.string.end': ('green', 'default'),
|
|
|
|
'cheetah_tag.end': ('default', 'default'),
|
2008-01-27 15:10:13 -05:00
|
|
|
}
|
|
|
|
def __init__(self, w):
|
|
|
|
mode.Fundamental.__init__(self, w)
|
|
|
|
self.add_bindings('close-paren', (')',))
|
|
|
|
self.add_bindings('close-brace', ('}',))
|
|
|
|
self.add_bindings('close-bracket', (']',))
|
|
|
|
|
|
|
|
install = Template.install
|