From c4705ef0792335ed5e33214efc489ddaf4d066d7 Mon Sep 17 00:00:00 2001 From: moculus Date: Sun, 27 Jan 2008 20:10:13 +0000 Subject: [PATCH] --HG-- branch : pmacs2 --- application.py | 2 +- mode/cheetah.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 mode/cheetah.py diff --git a/application.py b/application.py index da5074d..4e71ae9 100755 --- a/application.py +++ b/application.py @@ -86,7 +86,7 @@ class Application(object): 'dir', 'elisp', 'hex', 'html', 'java', 'javascript', 'lisp', 'make', 'mini', 'mutt', 'nasm', 'ocaml', 'perl', 'python', 'replace', 'rst', 'scheme', 'search', 'sh', 'sql', 'tt', - 'text', 'text2', 'which', 'xml') + 'text', 'text2', 'which', 'xml', 'cheetah') for name in names: exec("import mode.%s; mode.%s.install(self)" % (name, name)) diff --git a/mode/cheetah.py b/mode/cheetah.py new file mode 100644 index 0000000..14ddfef --- /dev/null +++ b/mode/cheetah.py @@ -0,0 +1,52 @@ +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 = [ + RegionRule(r'comment', r'#*', Grammar, r'*#'), + PatternRule(r'comment', r'##.*\n'), + PatternRule(r'placeholder', r'\$[a-zA-Z0-9_]+'), + PatternRule(r'directive', r'#.*?[#\n]'), + RegionRule(r'tag', r''), + ] + +class Template(mode.Fundamental): + modename = 'Cheetah' + extensions = ['.tmpl'] + grammar = TemplateGrammar + colors = { + 'comment': ('red', 'default'), + 'comment.start': ('red', 'default'), + 'comment.null': ('red', 'default'), + 'comment.end': ('red', 'default'), + + 'directive': ('magenta', 'default'), + 'placeholder': ('magenta', 'default'), + + 'tag.start': ('default', 'default'), + 'tag.namespace': ('magenta', 'default'), + 'tag.name': ('blue', 'default'), + 'tag.attrname': ('cyan', 'default'), + 'tag.string.start': ('green', 'default'), + 'tag.string.null': ('green', 'default'), + 'tag.string.end': ('green', 'default'), + 'tag.end': ('default', 'default'), + } + 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