import sets, sys import color, commands, default, lex2, method, mode, point, regex from lex2 import Grammar, ConstantRule, PatternRule, RegionRule, DualRegionRule class TagGrammar(Grammar): rules = [ RegionRule( name=r'string', start=r'(?P["\'])', 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]+', ), ] class XMLGrammar(Grammar): rules = [ RegionRule( name=r'comment', start=r'', ), RegionRule( name=r'opentag', start=r'<', grammar=TagGrammar(), end=r'/?>', ), PatternRule( name=r'closetag', pattern=r'< */ *[ =>\n]+ *>', ), ] class XML(mode.Fundamental): def __init__(self, w): mode.Fundamental.__init__(self, w) self.grammar = XMLGrammar() self.lexer = lex2.Lexer(self.name(), self.grammar) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) self.default_color = color.build('default', 'default') self.colors = { 'comment': color.build('red', '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): return "XML"