From e2a093e85b3cb2fbe6e8cdd4bea52c2b9f25d470 Mon Sep 17 00:00:00 2001 From: moculus Date: Tue, 17 Jul 2007 16:44:34 +0000 Subject: [PATCH] HTML mode --HG-- branch : pmacs2 --- mode_html.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 mode_html.py diff --git a/mode_html.py b/mode_html.py new file mode 100644 index 0000000..a163928 --- /dev/null +++ b/mode_html.py @@ -0,0 +1,42 @@ +import color, mode2 +from lex3 import Grammar, PatternRule, RegionRule + +class TagGrammar(Grammar): + rules = [ + RegionRule(r'string', r'(?P["\'])', Grammar, r'%(tag)s'), + PatternRule(r'namespace', pattern=r'[a-zA-Z_]+:'), + PatternRule(r'attrname', pattern=r'[^ =>\n]+(?==)'), + PatternRule(r'name', pattern=r'[^ =>\n]+'), + ] + +class TemplateGrammar(Grammar): + rules = [ + RegionRule(r'comment', r''), + RegionRule(r'template', r'\[\%', Grammar, r'%%\]'), + RegionRule(r'opentag', r'<', TagGrammar, r'/?>'), + PatternRule(r'closetag', pattern=r'< */ *[ =>\n]+ *>'), + ] + +class Template(mode2.Fundamental): + grammar = TemplateGrammar + def __init__(self, w): + mode2.Fundamental.__init__(self, w) + self.add_bindings('close-paren', (')',)) + self.add_bindings('close-brace', ('}',)) + self.add_bindings('close-bracket', (']',)) + self.colors = { + 'comment': color.build('red', 'default'), + 'template.start': color.build('magenta', 'default'), + 'template.null': color.build('magenta', 'default'), + 'template.end': color.build('magenta', 'default'), + 'opentag.start': color.build('default', 'default'), + 'opentag.namespace': color.build('magenta', 'default'), + 'opentag.name': color.build('blue', 'default'), + 'opentag.attrname': color.build('cyan', 'default'), + 'opentag.string.start': color.build('green', 'default'), + 'opentag.string.null': color.build('green', 'default'), + 'opentag.string.end': color.build('green', 'default'), + 'opentag.end': color.build('default', 'default'), + } + def name(self): + return "Template"