diff --git a/mode_tt.py b/mode_tt.py index a163928..84d5a32 100644 --- a/mode_tt.py +++ b/mode_tt.py @@ -1,19 +1,20 @@ import color, mode2 from lex3 import Grammar, PatternRule, RegionRule +from mode_xml import OpenTagGrammar +from mode_perl import StringGrammar -class TagGrammar(Grammar): +class DirectiveGrammar(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]+'), + PatternRule(r'keyword', r'BLOCK|CALL|CASE|CATCH|CLEAR|DEBUG|DEFAULT|FINAL|FILTER|FOREACH|ELSIF|ELSE|END|GET|IF|INCLUDE|INSERT|LAST|MACRO|META|NEXT|PERL|PROCESS|RAWPERL|RETURN|SET|STOP|SWITCH|TAGS|THROW|TRY|UNLESS|USE|WHILE|WRAPPER'), + RegionRule(r'string', r'"', StringGrammar, r'"'), + RegionRule(r'string', r"'", StringGrammar, r"'"), ] class TemplateGrammar(Grammar): rules = [ RegionRule(r'comment', r''), - RegionRule(r'template', r'\[\%', Grammar, r'%%\]'), - RegionRule(r'opentag', r'<', TagGrammar, r'/?>'), + RegionRule(r'directive', r'\[\%', DirectiveGrammar, r'%%\]'), + RegionRule(r'opentag', r'<', OpenTagGrammar, r'/?>'), PatternRule(r'closetag', pattern=r'< */ *[ =>\n]+ *>'), ] @@ -25,18 +26,26 @@ class Template(mode2.Fundamental): 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'), + 'comment': color.build('red', 'default'), + + 'directive.start': color.build('magenta', 'default'), + 'directive.keyword': color.build('cyan', 'default'), + 'directive.string.start': color.build('green', 'default'), + 'directive.string.escaped': color.build('magenta', 'default'), + 'directive.string.octal': color.build('magenta', 'default'), + 'directive.string.null': color.build('green', 'default'), + 'directive.string.end': color.build('green', 'default'), + 'directive.null': color.build('magenta', 'default'), + 'directive.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"