pmacs3/mode/tt.py

72 lines
3.4 KiB
Python
Raw Normal View History

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
from mode.perl import StringGrammar, PerlGrammar
class PerlDirectiveGrammar(Grammar):
rules = [PatternRule(r'tt.perl', r'(?:PERL|RAWPERL|END)(?![A-Z_])')]
2007-07-21 11:40:53 -04:00
class DirectiveGrammar(Grammar):
rules = [
PatternRule(r'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_])'),
2009-02-23 19:07:38 -05:00
PatternRule(r'attribute', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *=)'),
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'tt.directive', r'\[\%', DirectiveGrammar, r'%%\]'),
2007-07-21 11:40:53 -04:00
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'comment', r'\[\%#', Grammar, r'%%\]'),
PatternRule(r'tt.data', r'[^\[<&]+'),
RegionRule(r'tt.directive', r'\[\%(?= *PERL)', PerlDirectiveGrammar,
r'%%\]', PerlGrammar, r'\[%%', PerlDirectiveGrammar, '%%\]'),
RegionRule(r'tt.directive', r'\[\%', DirectiveGrammar, r'%%\]'),
2009-05-01 17:26:29 -04:00
RegionRule(r'tt.tag', r'</?(?=[a-zA-Z_])', TagGrammar, r'/?>'),
2007-07-21 11:40:53 -04:00
]
2007-10-21 20:55:29 -04:00
class Template(mode.Fundamental):
name = 'Template'
2007-10-18 17:07:35 -04:00
extensions = ['.tt']
grammar = TemplateGrammar
colors = {
'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'),
'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'),
'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