2007-07-21 11:40:53 -04:00
|
|
|
import color, mode2
|
|
|
|
from lex3 import Grammar, PatternRule, RegionRule
|
|
|
|
#from mode.xml import TagGrammar
|
|
|
|
from mode.perl import StringGrammar
|
|
|
|
|
|
|
|
class DirectiveGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'comment', r'#(?:[^%]|%(?!\]))*'),
|
|
|
|
PatternRule(r'keyword', r'BLOCK|CALL|CASE|CATCH|CLEAR|DEBUG|DEFAULT|FINAL|FILTER|FOREACH|ELSIF|ELSE|END|GET|IF|INCLUDE|INSERT|IN|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 TagGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
RegionRule(r'directive', r'\[\%', DirectiveGrammar, r'%%\]'),
|
|
|
|
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'-->'),
|
|
|
|
RegionRule(r'directive', r'\[\%', DirectiveGrammar, r'%%\]'),
|
|
|
|
RegionRule(r'tag', r'</?', TagGrammar, r'/?>'),
|
|
|
|
]
|
|
|
|
|
|
|
|
class Template(mode2.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'Template'
|
|
|
|
extensions = ['.tt']
|
|
|
|
grammar = TemplateGrammar
|
|
|
|
colors = {
|
2007-07-21 11:40:53 -04:00
|
|
|
'comment.start': ('red', 'default'),
|
|
|
|
'comment.null': ('red', 'default'),
|
|
|
|
'comment.end': ('red', 'default'),
|
|
|
|
|
|
|
|
'directive.start': ('magenta', 'default'),
|
|
|
|
'directive.comment': ('red', 'default'),
|
|
|
|
'directive.keyword': ('cyan', 'default'),
|
|
|
|
'directive.string.start': ('green', 'default'),
|
|
|
|
'directive.string.escaped': ('magenta', 'default'),
|
|
|
|
'directive.string.octal': ('magenta', 'default'),
|
|
|
|
'directive.string.null': ('green', 'default'),
|
|
|
|
'directive.string.end': ('green', 'default'),
|
|
|
|
'directive.null': ('magenta', 'default'),
|
|
|
|
'directive.end': ('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):
|
|
|
|
mode2.Fundamental.__init__(self, w)
|
|
|
|
self.add_bindings('close-paren', (')',))
|
|
|
|
self.add_bindings('close-brace', ('}',))
|
|
|
|
self.add_bindings('close-bracket', (']',))
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = Template.install
|