parent
c40b3e0845
commit
a0f0de1bc3
31
mode/xml.py
31
mode/xml.py
|
@ -1,21 +1,38 @@
|
||||||
import color, method, mode
|
import color, method, mode
|
||||||
from lex import Grammar, PatternRule, RegionRule
|
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):
|
class TagGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
RegionRule(r'string', r'"', Grammar, r'"'),
|
PatternRule(r'attrname', r'[a-zA-Z_][a-zA-Z0-9_]+(?==)'),
|
||||||
RegionRule(r'string', r"'", Grammar, r"'"),
|
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'attrname', r'[^ =>\n]+(?==)'),
|
PatternRule(r'delimiter', r'[/=]'),
|
||||||
PatternRule(r'name', r'[^/\[\] =>\n]+'),
|
RegionRule(r'string', r'"', StringGrammar1, r'"'),
|
||||||
|
RegionRule(r'string', r"'", StringGrammar2, r"'"),
|
||||||
|
PatternRule(r'spaces', r' +'),
|
||||||
|
PatternRule(r'eol', r'\n'),
|
||||||
]
|
]
|
||||||
|
|
||||||
class XMLGrammar(Grammar):
|
class XMLGrammar(Grammar):
|
||||||
rules = [
|
rules = [
|
||||||
# TODO: how does cdata work again?
|
# 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'/?>'),
|
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):
|
class XmlValidate(method.shell.Exec):
|
||||||
|
|
Loading…
Reference in New Issue