2008-04-19 11:10:15 -04:00
|
|
|
import color, method, mode
|
2007-10-21 20:52:48 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule
|
2007-07-21 11:40:53 -04:00
|
|
|
|
|
|
|
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]+(?==)'),
|
2008-05-21 17:54:34 -04:00
|
|
|
PatternRule(r'name', r'[^/\[\] =>\n]+'),
|
2007-07-21 11:40:53 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
class XMLGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
# TODO: how does cdata work again?
|
|
|
|
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
|
2008-03-16 01:23:14 -04:00
|
|
|
RegionRule(r'xml_tag', r'<', TagGrammar, r'/?>'),
|
2008-05-06 02:03:47 -04:00
|
|
|
PatternRule(r'xml_entity', r'&.*?;'),
|
2007-07-21 11:40:53 -04:00
|
|
|
]
|
|
|
|
|
2008-04-19 11:10:15 -04:00
|
|
|
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')
|
|
|
|
|
2008-05-06 01:23:58 -04:00
|
|
|
class XmlCreateTag(method.Method):
|
|
|
|
''''''
|
|
|
|
args = [method.Argument('tagname', prompt="Tag Name: ", help="Create an open/close tag pair")]
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
t = vargs['tagname']
|
|
|
|
w.insert_string_at_cursor("<%s>" % t)
|
|
|
|
p = w.logical_cursor()
|
|
|
|
w.insert_string_at_cursor("</%s>" % t)
|
|
|
|
w.goto(p)
|
|
|
|
|
2007-10-21 20:55:29 -04:00
|
|
|
class XML(mode.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'XML'
|
2008-05-21 17:54:34 -04:00
|
|
|
extensions = ['.xml', '.xml.in', '.xsl']
|
2007-10-18 17:07:35 -04:00
|
|
|
grammar = XMLGrammar
|
|
|
|
colors = {
|
2008-05-03 13:31:30 -04:00
|
|
|
'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'),
|
2008-05-06 02:03:47 -04:00
|
|
|
'xml_entity': ('magenta', 'default', 'bold'),
|
2007-07-21 11:40:53 -04:00
|
|
|
}
|
2008-05-06 01:23:58 -04:00
|
|
|
actions = [XmlValidate, XmlCreateTag]
|
|
|
|
def __init__(self, w):
|
|
|
|
mode.Fundamental.__init__(self, w)
|
|
|
|
self.add_bindings('xml-create-tag', ('M-t',))
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = XML.install
|