From a0f0de1bc3c830ccf0904751e46b2f207aaf688d Mon Sep 17 00:00:00 2001 From: moculus Date: Tue, 30 Sep 2008 21:04:35 +0000 Subject: [PATCH] xml efficiency --HG-- branch : pmacs2 --- mode/xml.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/mode/xml.py b/mode/xml.py index 9015d23..a9fcb29 100644 --- a/mode/xml.py +++ b/mode/xml.py @@ -1,21 +1,38 @@ import color, method, mode from lex import Grammar, PatternRule, RegionRule +class StringGrammar1(Grammar): + rules = [PatternRule(r'data', r'[^"]+')] +class StringGrammar2(Grammar): + rules = [PatternRule(r'data', r"[^']+")] + +class CommentGrammar(Grammar): + rules = [PatternRule(r'data', r'(?:[^-]|-(?!-)|--(?!>))+')] +class MetadataGrammar(Grammar): + rules = [PatternRule(r'data', r'(?:[^?]|\?(?!>))+')] + 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]+'), + 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'[/=]'), + RegionRule(r'string', r'"', StringGrammar1, r'"'), + RegionRule(r'string', r"'", StringGrammar2, r"'"), + PatternRule(r'spaces', r' +'), + PatternRule(r'eol', r'\n'), ] class XMLGrammar(Grammar): rules = [ # TODO: how does cdata work again? - RegionRule(r'comment', r''), + PatternRule(r'data', r'[^<& \n]+'), + PatternRule(r'spaces', r' +'), + RegionRule(r'comment', r''), RegionRule(r'xml_tag', r'<', TagGrammar, r'/?>'), - PatternRule(r'xml_entity', r'&.*?;'), + PatternRule(r'xml_entity', r'&[a-z]+;'), + PatternRule(r'eol', r'\n'), + RegionRule(r'metadata', r'<\?', MetadataGrammar, r'\?>'), ] class XmlValidate(method.shell.Exec):