parent
d7870303a8
commit
68bb97e00e
42
mode/xml.py
42
mode/xml.py
|
@ -1,5 +1,5 @@
|
||||||
import color, method, mode
|
import color, method, mode
|
||||||
from lex import Grammar, Rule, PatternRule, RegionRule
|
from lex import Grammar, Rule, PatternRule, RegionRule, PatternMatchRule
|
||||||
|
|
||||||
class StringGrammar1(Grammar):
|
class StringGrammar1(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
|
@ -24,7 +24,7 @@ class TagGrammar(Grammar):
|
||||||
PatternRule(r'attrname', r'[a-zA-Z_][a-zA-Z0-9_]+(?==)'),
|
PatternRule(r'attrname', r'[a-zA-Z_][a-zA-Z0-9_]+(?==)'),
|
||||||
PatternRule(r'namespace', r'[a-zA-Z_]+(?=:)'),
|
PatternRule(r'namespace', r'[a-zA-Z_]+(?=:)'),
|
||||||
PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
PatternRule(r'name', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||||
PatternRule(r'delimiter', r'[/=]'),
|
PatternRule(r'delimiter', r'[:/=]'),
|
||||||
RegionRule(r'string', r'"', StringGrammar1, r'"'),
|
RegionRule(r'string', r'"', StringGrammar1, r'"'),
|
||||||
RegionRule(r'string', r"'", StringGrammar2, r"'"),
|
RegionRule(r'string', r"'", StringGrammar2, r"'"),
|
||||||
PatternRule(r'spaces', r' +'),
|
PatternRule(r'spaces', r' +'),
|
||||||
|
@ -36,12 +36,12 @@ class XMLGrammar(Grammar):
|
||||||
# TODO: how does cdata work again?
|
# TODO: how does cdata work again?
|
||||||
PatternRule(r'data', r'[^<& \n]+'),
|
PatternRule(r'data', r'[^<& \n]+'),
|
||||||
PatternRule(r'spaces', r' +'),
|
PatternRule(r'spaces', r' +'),
|
||||||
|
RegionRule(r'xml.tag', r'<(?![?!])', TagGrammar, r'/?>'),
|
||||||
RegionRule(r'comment', r'<!--', CommentGrammar, r'-->'),
|
RegionRule(r'comment', r'<!--', CommentGrammar, r'-->'),
|
||||||
RegionRule(r'xml_cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
|
PatternRule(r'xml.entity', r'&[a-z]+;'),
|
||||||
RegionRule(r'xml_tag', r'<(?![?!])', TagGrammar, r'/?>'),
|
|
||||||
PatternRule(r'xml_entity', r'&[a-z]+;'),
|
|
||||||
PatternRule(r'eol', r'\n'),
|
PatternRule(r'eol', r'\n'),
|
||||||
RegionRule(r'xml_metadata', r'<\?', MetadataGrammar, r'\?>'),
|
RegionRule(r'xml.metadata', r'<\?', MetadataGrammar, r'\?>'),
|
||||||
|
RegionRule(r'xml.cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
|
||||||
]
|
]
|
||||||
|
|
||||||
class XmlValidate(method.shell.Exec):
|
class XmlValidate(method.shell.Exec):
|
||||||
|
@ -53,7 +53,8 @@ class XmlValidate(method.shell.Exec):
|
||||||
|
|
||||||
class XmlCreateTag(method.Method):
|
class XmlCreateTag(method.Method):
|
||||||
'''Create an opening and closing tag'''
|
'''Create an opening and closing tag'''
|
||||||
args = [method.Argument('tagname', prompt="Tag Name: ", help="Create an open/close tag pair")]
|
args = [method.Argument('tagname', prompt="Tag Name: ",
|
||||||
|
help="Create an open/close tag pair")]
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
t = vargs['tagname']
|
t = vargs['tagname']
|
||||||
w.insert_string_at_cursor("<%s>" % t)
|
w.insert_string_at_cursor("<%s>" % t)
|
||||||
|
@ -82,21 +83,18 @@ class XML(mode.Fundamental):
|
||||||
extensions = ['.xml', '.xml.in', '.xsl', '.xsd']
|
extensions = ['.xml', '.xml.in', '.xsl', '.xsd']
|
||||||
grammar = XMLGrammar
|
grammar = XMLGrammar
|
||||||
colors = {
|
colors = {
|
||||||
'xml_metadata.start': ('magenta', 'default', 'bold'),
|
'xml.metadata.start': ('magenta', 'default', 'bold'),
|
||||||
'xml_metadata.data': ('magenta', 'default', 'bold'),
|
'xml.metadata.data': ('magenta', 'default', 'bold'),
|
||||||
'xml_metadata.end': ('magenta', 'default', 'bold'),
|
'xml.metadata.end': ('magenta', 'default', 'bold'),
|
||||||
'xml_tag.start': ('default', 'default', 'bold'),
|
'xml.tag.start': ('default', 'default', 'bold'),
|
||||||
'xml_tag.namespace': ('magenta', 'default', 'bold'),
|
'xml.tag.namespace': ('magenta', 'default', 'bold'),
|
||||||
'xml_tag.name': ('blue', 'default', 'bold'),
|
'xml.tag.name': ('blue', 'default', 'bold'),
|
||||||
'xml_tag.attrname': ('cyan', 'default', 'bold'),
|
'xml.tag.attrname': ('cyan', 'default', 'bold'),
|
||||||
'xml_tag.string.start': ('green', 'default', 'bold'),
|
'xml.tag.end': ('default', 'default', 'bold'),
|
||||||
'xml_tag.string.null': ('green', 'default', 'bold'),
|
'xml.entity': ('magenta', 'default', 'bold'),
|
||||||
'xml_tag.string.end': ('green', 'default', 'bold'),
|
'xml.cdata.start': ('magenta', 'default', 'bold'),
|
||||||
'xml_tag.end': ('default', 'default', 'bold'),
|
'xml.cdata.data': ('green', 'default', 'bold'),
|
||||||
'xml_entity': ('magenta', 'default', 'bold'),
|
'xml.cdata.end': ('magenta', 'default', 'bold'),
|
||||||
'xml_cdata.start': ('magenta', 'default', 'bold'),
|
|
||||||
'xml_cdata.data': ('green', 'default', 'bold'),
|
|
||||||
'xml_cdata.end': ('magenta', 'default', 'bold'),
|
|
||||||
}
|
}
|
||||||
actions = [XmlValidate, XmlCreateTag, XmlCreateComment, XmlCreateCdata]
|
actions = [XmlValidate, XmlCreateTag, XmlCreateComment, XmlCreateCdata]
|
||||||
_bindings = {
|
_bindings = {
|
||||||
|
|
Loading…
Reference in New Issue