better TT

--HG--
branch : pmacs2
This commit is contained in:
moculus 2007-07-17 16:44:25 +00:00
parent 16c4448bac
commit 22b963c6cc
1 changed files with 28 additions and 19 deletions

View File

@ -1,19 +1,20 @@
import color, mode2 import color, mode2
from lex3 import Grammar, PatternRule, RegionRule from lex3 import Grammar, PatternRule, RegionRule
from mode_xml import OpenTagGrammar
from mode_perl import StringGrammar
class TagGrammar(Grammar): class DirectiveGrammar(Grammar):
rules = [ rules = [
RegionRule(r'string', r'(?P<tag>["\'])', Grammar, r'%(tag)s'), PatternRule(r'keyword', r'BLOCK|CALL|CASE|CATCH|CLEAR|DEBUG|DEFAULT|FINAL|FILTER|FOREACH|ELSIF|ELSE|END|GET|IF|INCLUDE|INSERT|LAST|MACRO|META|NEXT|PERL|PROCESS|RAWPERL|RETURN|SET|STOP|SWITCH|TAGS|THROW|TRY|UNLESS|USE|WHILE|WRAPPER'),
PatternRule(r'namespace', pattern=r'[a-zA-Z_]+:'), RegionRule(r'string', r'"', StringGrammar, r'"'),
PatternRule(r'attrname', pattern=r'[^ =>\n]+(?==)'), RegionRule(r'string', r"'", StringGrammar, r"'"),
PatternRule(r'name', pattern=r'[^ =>\n]+'),
] ]
class TemplateGrammar(Grammar): class TemplateGrammar(Grammar):
rules = [ rules = [
RegionRule(r'comment', r'<!--', Grammar, r'-->'), RegionRule(r'comment', r'<!--', Grammar, r'-->'),
RegionRule(r'template', r'\[\%', Grammar, r'%%\]'), RegionRule(r'directive', r'\[\%', DirectiveGrammar, r'%%\]'),
RegionRule(r'opentag', r'<', TagGrammar, r'/?>'), RegionRule(r'opentag', r'<', OpenTagGrammar, r'/?>'),
PatternRule(r'closetag', pattern=r'< */ *[ =>\n]+ *>'), PatternRule(r'closetag', pattern=r'< */ *[ =>\n]+ *>'),
] ]
@ -25,18 +26,26 @@ class Template(mode2.Fundamental):
self.add_bindings('close-brace', ('}',)) self.add_bindings('close-brace', ('}',))
self.add_bindings('close-bracket', (']',)) self.add_bindings('close-bracket', (']',))
self.colors = { self.colors = {
'comment': color.build('red', 'default'), 'comment': color.build('red', 'default'),
'template.start': color.build('magenta', 'default'),
'template.null': color.build('magenta', 'default'), 'directive.start': color.build('magenta', 'default'),
'template.end': color.build('magenta', 'default'), 'directive.keyword': color.build('cyan', 'default'),
'opentag.start': color.build('default', 'default'), 'directive.string.start': color.build('green', 'default'),
'opentag.namespace': color.build('magenta', 'default'), 'directive.string.escaped': color.build('magenta', 'default'),
'opentag.name': color.build('blue', 'default'), 'directive.string.octal': color.build('magenta', 'default'),
'opentag.attrname': color.build('cyan', 'default'), 'directive.string.null': color.build('green', 'default'),
'opentag.string.start': color.build('green', 'default'), 'directive.string.end': color.build('green', 'default'),
'opentag.string.null': color.build('green', 'default'), 'directive.null': color.build('magenta', 'default'),
'opentag.string.end': color.build('green', 'default'), 'directive.end': color.build('magenta', 'default'),
'opentag.end': color.build('default', 'default'),
'opentag.start': color.build('default', 'default'),
'opentag.namespace': color.build('magenta', 'default'),
'opentag.name': color.build('blue', 'default'),
'opentag.attrname': color.build('cyan', 'default'),
'opentag.string.start': color.build('green', 'default'),
'opentag.string.null': color.build('green', 'default'),
'opentag.string.end': color.build('green', 'default'),
'opentag.end': color.build('default', 'default'),
} }
def name(self): def name(self):
return "Template" return "Template"