small xml speedups

--HG--
branch : pmacs2
This commit is contained in:
moculus 2009-04-08 01:02:19 +00:00
parent d7870303a8
commit 68bb97e00e
1 changed files with 20 additions and 22 deletions

View File

@ -1,5 +1,5 @@
import color, method, mode
from lex import Grammar, Rule, PatternRule, RegionRule
from lex import Grammar, Rule, PatternRule, RegionRule, PatternMatchRule
class StringGrammar1(Grammar):
rules = [
@ -24,7 +24,7 @@ class TagGrammar(Grammar):
PatternRule(r'attrname', r'[a-zA-Z_][a-zA-Z0-9_]+(?==)'),
PatternRule(r'namespace', r'[a-zA-Z_]+(?=:)'),
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"'", StringGrammar2, r"'"),
PatternRule(r'spaces', r' +'),
@ -36,12 +36,12 @@ class XMLGrammar(Grammar):
# TODO: how does cdata work again?
PatternRule(r'data', r'[^<& \n]+'),
PatternRule(r'spaces', r' +'),
RegionRule(r'xml.tag', r'<(?![?!])', TagGrammar, r'/?>'),
RegionRule(r'comment', r'<!--', CommentGrammar, r'-->'),
RegionRule(r'xml_cdata', r'<!\[CDATA\[', CDataGrammar, r'\]\]>'),
RegionRule(r'xml_tag', r'<(?![?!])', TagGrammar, r'/?>'),
PatternRule(r'xml_entity', r'&[a-z]+;'),
PatternRule(r'xml.entity', r'&[a-z]+;'),
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):
@ -53,7 +53,8 @@ class XmlValidate(method.shell.Exec):
class XmlCreateTag(method.Method):
'''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):
t = vargs['tagname']
w.insert_string_at_cursor("<%s>" % t)
@ -82,21 +83,18 @@ class XML(mode.Fundamental):
extensions = ['.xml', '.xml.in', '.xsl', '.xsd']
grammar = XMLGrammar
colors = {
'xml_metadata.start': ('magenta', 'default', 'bold'),
'xml_metadata.data': ('magenta', 'default', 'bold'),
'xml_metadata.end': ('magenta', 'default', 'bold'),
'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'),
'xml_entity': ('magenta', 'default', 'bold'),
'xml_cdata.start': ('magenta', 'default', 'bold'),
'xml_cdata.data': ('green', 'default', 'bold'),
'xml_cdata.end': ('magenta', 'default', 'bold'),
'xml.metadata.start': ('magenta', 'default', 'bold'),
'xml.metadata.data': ('magenta', 'default', 'bold'),
'xml.metadata.end': ('magenta', 'default', 'bold'),
'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.end': ('default', 'default', 'bold'),
'xml.entity': ('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]
_bindings = {