2007-06-25 11:59:44 -04:00
|
|
|
import color, mode2
|
2007-07-15 09:44:20 -04:00
|
|
|
from lex3 import Grammar, PatternRule, RegionRule
|
2007-03-06 10:05:38 -05:00
|
|
|
|
2007-06-25 11:59:44 -04:00
|
|
|
class TagGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
RegionRule(name=r'string', start=r'(?P<tag>["\'])', grammar=Grammar(), end=r'%(tag)s'),
|
|
|
|
PatternRule(name=r'namespace', pattern=r'[a-zA-Z_]+:'),
|
|
|
|
PatternRule(name=r'attrname', pattern=r'[^ =>\n]+(?==)'),
|
|
|
|
PatternRule(name=r'name', pattern=r'[^ =>\n]+'),
|
|
|
|
]
|
2007-03-06 10:05:38 -05:00
|
|
|
|
2007-06-25 11:59:44 -04:00
|
|
|
class TemplateGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
RegionRule(name=r'comment', start=r'<!--', grammar=Grammar(), end=r'-->'),
|
|
|
|
RegionRule(name=r'template', start=r'\[\%', grammar=Grammar(), end=r'%%\]'),
|
|
|
|
RegionRule(name=r'opentag', start=r'<', grammar=TagGrammar(), end=r'/?>'),
|
|
|
|
PatternRule(name=r'closetag', pattern=r'< */ *[ =>\n]+ *>'),
|
|
|
|
]
|
2007-03-06 10:05:38 -05:00
|
|
|
|
2007-06-25 11:59:44 -04:00
|
|
|
class Template(mode2.Fundamental):
|
|
|
|
grammar = TemplateGrammar
|
|
|
|
def __init__(self, w):
|
|
|
|
mode2.Fundamental.__init__(self, w)
|
2007-03-06 10:05:38 -05:00
|
|
|
self.add_bindings('close-paren', (')',))
|
|
|
|
self.add_bindings('close-brace', ('}',))
|
|
|
|
self.add_bindings('close-bracket', (']',))
|
|
|
|
self.colors = {
|
2007-06-25 11:59:44 -04:00
|
|
|
'comment': color.build('red', 'default'),
|
|
|
|
'template.start': color.build('magenta', 'default'),
|
|
|
|
'template.null': color.build('magenta', 'default'),
|
|
|
|
'template.end': color.build('magenta', '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'),
|
2007-03-06 10:05:38 -05:00
|
|
|
}
|
|
|
|
def name(self):
|
2007-05-06 00:32:20 -04:00
|
|
|
return "Template"
|