65 lines
2.7 KiB
Python
65 lines
2.7 KiB
Python
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):
|
|
grammar = TemplateGrammar
|
|
colors = {
|
|
'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', (']',))
|
|
def name(self):
|
|
return "Template"
|