pmacs3/mode/xml.py

44 lines
1.5 KiB
Python

import color, method, mode
from lex import Grammar, PatternRule, RegionRule
class TagGrammar(Grammar):
rules = [
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 XMLGrammar(Grammar):
rules = [
# TODO: how does cdata work again?
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
RegionRule(r'xml_tag', r'<', TagGrammar, r'/?>'),
]
class XmlValidate(method.shell.Exec):
'''Valid the buffer's contents as valid XML.'''
show_success = True
args = []
def _execute(self, w, **vargs):
self._doit(w, w.buffer.path, 'xmlwf %(path)r', cmdname='xml-validate')
class XML(mode.Fundamental):
modename = 'XML'
extensions = ['.xml', '.xml.in']
grammar = XMLGrammar
colors = {
'xml_tag.start': ('default', 'default', 'bold'),
'xml_tag.namespace': ('magenta', 'default', 'bold'),
'xml_tag.name': ('blue', 'default', 'bold'),
'xml_tag.attrname': ('cyan', 'default', 'bold'),
'xml_tag.string.start': ('green', 'default', 'bold'),
'xml_tag.string.null': ('green', 'default', 'bold'),
'xml_tag.string.end': ('green', 'default', 'bold'),
'xml_tag.end': ('default', 'default', 'bold'),
}
actions = [XmlValidate]
install = XML.install