pmacs3/mode/tt.py

91 lines
4.4 KiB
Python
Raw Permalink 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
import mode.xml
import mode.html
import mode.javascript
import mode.css
from mode.perl import StrictStringGrammar, StringGrammar, PerlGrammar
class PerlDirectiveGrammar(Grammar):
rules = [PatternRule('tt.perl', '(?:PERL|RAWPERL|END)(?![A-Z_])')]
2007-07-21 11:40:53 -04:00
class DirectiveGrammar(Grammar):
rules = [
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', "'", StrictStringGrammar, "'"),
2007-07-21 11:40:53 -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):
rules = [crule, prule, drule] + mode.html.TagGrammar.rules
class JavascriptGrammar(Grammar):
rules = [crule, prule, drule] + mode.javascript.JavascriptGrammar.rules
class CSSGrammar(Grammar):
rules = [crule, prule, drule] + mode.css.CSSGrammar.rules
class CommentGrammar(Grammar):
rules = [crule, prule, drule] + mode.html.CommentGrammar.rules
class CDataGrammar(Grammar):
rules = [crule, prule, drule] + mode.html.CDataGrammar.rules
class MetadataGrammar(Grammar):
rules = [crule, prule, drule] + mode.html.MetadataGrammar.rules
class DoctypeGrammar(Grammar):
rules = [crule, prule, drule] + mode.html.DoctypeGrammar.rules
2007-07-21 11:40:53 -04:00
class TemplateGrammar(Grammar):
rules = [crule, prule, drule] + [
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):
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'),
'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'),
'tt.perl': ('cyan', '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