2007-10-21 20:55:29 -04:00
|
|
|
import color, mode
|
2007-10-21 20:52:48 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule
|
2007-07-21 11:40:53 -04:00
|
|
|
from mode.perl import StringGrammar
|
|
|
|
|
|
|
|
class DirectiveGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'comment', r'#(?:[^%]|%(?!\]))*'),
|
2009-02-02 11:56:26 -05:00
|
|
|
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)(?![A-Z_])'),
|
2007-07-21 11:40:53 -04:00
|
|
|
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 = [
|
2009-02-20 01:21:51 -05:00
|
|
|
PatternRule(r'escaped', r'&[^;]+;'),
|
2007-07-21 11:40:53 -04:00
|
|
|
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
|
|
|
|
RegionRule(r'directive', r'\[\%', DirectiveGrammar, r'%%\]'),
|
2008-03-16 01:23:14 -04:00
|
|
|
RegionRule(r'tt_tag', r'</?', TagGrammar, r'/?>'),
|
2007-07-21 11:40:53 -04:00
|
|
|
]
|
|
|
|
|
2007-10-21 20:55:29 -04:00
|
|
|
class Template(mode.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'Template'
|
|
|
|
extensions = ['.tt']
|
|
|
|
grammar = TemplateGrammar
|
|
|
|
colors = {
|
2008-05-03 13:31:30 -04:00
|
|
|
'directive.start': ('magenta', 'default', 'bold'),
|
|
|
|
'directive.comment': ('red', 'default', 'bold'),
|
|
|
|
'directive.keyword': ('cyan', 'default', 'bold'),
|
|
|
|
'directive.string.start': ('green', 'default', 'bold'),
|
|
|
|
'directive.string.escaped': ('magenta', 'default', 'bold'),
|
|
|
|
'directive.string.octal': ('magenta', 'default', 'bold'),
|
|
|
|
'directive.string.null': ('green', 'default', 'bold'),
|
|
|
|
'directive.string.end': ('green', 'default', 'bold'),
|
|
|
|
'directive.null': ('magenta', 'default', 'bold'),
|
|
|
|
'directive.end': ('magenta', 'default', 'bold'),
|
2007-07-21 11:40:53 -04:00
|
|
|
|
2008-05-03 13:31:30 -04:00
|
|
|
'tt_tag.start': ('default', 'default', 'bold'),
|
|
|
|
'tt_tag.namespace': ('magenta', 'default', 'bold'),
|
|
|
|
'tt_tag.name': ('blue', 'default', 'bold'),
|
|
|
|
'tt_tag.attrname': ('cyan', 'default', 'bold'),
|
|
|
|
'tt_tag.string.start': ('green', 'default', 'bold'),
|
|
|
|
'tt_tag.string.null': ('green', 'default', 'bold'),
|
|
|
|
'tt_tag.string.end': ('green', 'default', 'bold'),
|
|
|
|
'tt_tag.end': ('default', 'default', 'bold'),
|
2007-07-21 11:40:53 -04:00
|
|
|
}
|
2009-02-15 12:06:35 -05:00
|
|
|
_bindings = {
|
|
|
|
'close-paren': (')',),
|
|
|
|
'close-brace': ('}',),
|
|
|
|
'close-bracket': (']',),
|
|
|
|
}
|
2007-10-19 02:41:33 -04:00
|
|
|
install = Template.install
|