xml efficiency

--HG--
branch : pmacs2
This commit is contained in:
moculus 2008-09-30 21:04:35 +00:00
parent c40b3e0845
commit a0f0de1bc3
1 changed files with 24 additions and 7 deletions

View File

@ -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'<!--', Grammar, r'-->'),
PatternRule(r'data', r'[^<& \n]+'),
PatternRule(r'spaces', r' +'),
RegionRule(r'comment', r'<!--', CommentGrammar, 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):