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
|
2009-05-06 14:39:26 -04:00
|
|
|
import mode.xml
|
|
|
|
import mode.html
|
|
|
|
import mode.javascript
|
|
|
|
import mode.css
|
2009-04-08 00:21:29 -04:00
|
|
|
from mode.perl import StringGrammar, PerlGrammar
|
|
|
|
|
|
|
|
class PerlDirectiveGrammar(Grammar):
|
2009-05-06 14:39:26 -04:00
|
|
|
rules = [PatternRule('tt.perl', '(?:PERL|RAWPERL|END)(?![A-Z_])')]
|
2007-07-21 11:40:53 -04:00
|
|
|
|
|
|
|
class DirectiveGrammar(Grammar):
|
|
|
|
rules = [
|
2009-05-06 14:39:26 -04:00
|
|
|
PatternRule('tt.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_])'),
|
|
|
|
PatternRule('attribute', '[a-zA-Z_][a-zA-Z0-9_]*(?= *=)'),
|
|
|
|
RegionRule('string', '"', StringGrammar, '"'),
|
|
|
|
RegionRule('string', "'", StringGrammar, "'"),
|
2007-07-21 11:40:53 -04:00
|
|
|
]
|
|
|
|
|
2009-05-06 14:39:26 -04:00
|
|
|
crule = RegionRule('comment', r'\[\%#', Grammar, r'%%\]')
|
|
|
|
drule = RegionRule('tt.directive', r'\[\%', DirectiveGrammar, r'%%\]')
|
|
|
|
prule = RegionRule('tt.directive', r'\[\%(?= *PERL)', PerlDirectiveGrammar,
|
|
|
|
r'%%\]', PerlGrammar, r'\[%%', PerlDirectiveGrammar, '%%\]')
|
|
|
|
|
2007-07-21 11:40:53 -04:00
|
|
|
class TagGrammar(Grammar):
|
2009-05-06 14:39:26 -04:00
|
|
|
rules = [crule, drule, prule] + mode.html.TagGrammar.rules
|
|
|
|
class JavascriptGrammar(Grammar):
|
|
|
|
rules = [crule, drule, prule] + mode.javascript.JavascriptGrammar.rules
|
|
|
|
class CSSGrammar(Grammar):
|
|
|
|
rules = [crule, drule, prule] + mode.css.CSSGrammar.rules
|
|
|
|
class CommentGrammar(Grammar):
|
|
|
|
rules = [crule, drule, prule] + mode.html.CommentGrammar.rules
|
|
|
|
class CDataGrammar(Grammar):
|
|
|
|
rules = [crule, drule, prule] + mode.html.CDataGrammar.rules
|
|
|
|
class MetadataGrammar(Grammar):
|
|
|
|
rules = [crule, drule, prule] + mode.html.MetadataGrammar.rules
|
|
|
|
class DoctypeGrammar(Grammar):
|
2009-05-06 17:17:43 -04:00
|
|
|
rules = [crule, drule, prule] + mode.html.DoctypeGrammar.rules
|
2007-07-21 11:40:53 -04:00
|
|
|
|
|
|
|
class TemplateGrammar(Grammar):
|
|
|
|
rules = [
|
2009-05-06 14:39:26 -04:00
|
|
|
crule, drule, prule,
|
|
|
|
PatternRule('escaped', '&[^;]+;'),
|
|
|
|
PatternRule('html.data', r'[^\[&<]+'),
|
|
|
|
PatternRule('html.data', '[^&<]+'),
|
|
|
|
RegionRule('html.tag', '<(?=script[^a-zA-Z0-9_])', TagGrammar, '>',
|
|
|
|
JavascriptGrammar, '</(?=script>)', TagGrammar, '>'),
|
|
|
|
RegionRule('html.tag', '<(?=style[^a-zA-Z0-9_])', TagGrammar, '>',
|
|
|
|
CSSGrammar, '</(?=style>)', TagGrammar, '>'),
|
|
|
|
RegionRule('comment', '<!--', CommentGrammar, '-->'),
|
|
|
|
RegionRule('html.tag', r'<(?![\?!])', TagGrammar, '/?>'),
|
|
|
|
RegionRule('html.metadata', r'<\?', MetadataGrammar, r'\?>'),
|
|
|
|
RegionRule('html.doctype', '<!', DoctypeGrammar, '>'),
|
|
|
|
PatternRule('html.entity', '&[a-z]+;'),
|
|
|
|
RegionRule('html.cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
|
2007-07-21 11:40:53 -04:00
|
|
|
]
|
|
|
|
|
2007-10-21 20:55:29 -04:00
|
|
|
class Template(mode.Fundamental):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'Template'
|
2007-10-18 17:07:35 -04:00
|
|
|
extensions = ['.tt']
|
|
|
|
grammar = TemplateGrammar
|
|
|
|
colors = {
|
2009-04-08 00:21:29 -04:00
|
|
|
'tt.directive.start': ('magenta', 'default', 'bold'),
|
|
|
|
'tt.directive.comment': ('red', 'default', 'bold'),
|
|
|
|
'tt.directive.keyword': ('yellow', 'default', 'bold'),
|
|
|
|
'tt.directive.attribute': ('magenta', 'default', 'bold'),
|
|
|
|
'tt.directive.string.start': ('green', 'default', 'bold'),
|
|
|
|
'tt.directive.string.escaped': ('magenta', 'default', 'bold'),
|
|
|
|
'tt.directive.string.octal': ('magenta', 'default', 'bold'),
|
|
|
|
'tt.directive.string.null': ('green', 'default', 'bold'),
|
|
|
|
'tt.directive.string.end': ('green', 'default', 'bold'),
|
|
|
|
'tt.directive.null': ('magenta', 'default', 'bold'),
|
|
|
|
'tt.directive.middle0': ('magenta', 'default', 'bold'),
|
|
|
|
'tt.directive.middle1': ('magenta', 'default', 'bold'),
|
|
|
|
'tt.directive.end': ('magenta', 'default', 'bold'),
|
2009-05-06 14:39:26 -04:00
|
|
|
'tt.tag.start': ('default', 'default'),
|
2009-04-08 00:21:29 -04:00
|
|
|
'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'),
|
2009-05-06 14:39:26 -04:00
|
|
|
'tt.tag.end': ('default', 'default'),
|
2009-04-08 00:21:29 -04:00
|
|
|
'tt.perl': ('red', '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
|