parent
c40b3e0845
commit
a0f0de1bc3
31
mode/xml.py
31
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'<!--', 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):
|
||||
|
|
Loading…
Reference in New Issue