39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import color, mode
|
|
from lex import Grammar, PatternRule, RegionRule
|
|
|
|
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]+'),
|
|
]
|
|
|
|
class XMLGrammar(Grammar):
|
|
rules = [
|
|
# TODO: how does cdata work again?
|
|
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
|
|
RegionRule(r'xml_tag', r'<', TagGrammar, r'/?>'),
|
|
]
|
|
|
|
class XML(mode.Fundamental):
|
|
modename = 'XML'
|
|
extensions = ['.xml', '.xml.in']
|
|
grammar = XMLGrammar
|
|
colors = {
|
|
#'comment.start': ('red', 'default'),
|
|
#'comment.null': ('red', 'default'),
|
|
#'comment.end': ('red', 'default'),
|
|
'xml_tag.start': ('default', 'default'),
|
|
'xml_tag.namespace': ('magenta', 'default'),
|
|
'xml_tag.name': ('blue', 'default'),
|
|
'xml_tag.attrname': ('cyan', 'default'),
|
|
'xml_tag.string.start': ('green', 'default'),
|
|
'xml_tag.string.null': ('green', 'default'),
|
|
'xml_tag.string.end': ('green', 'default'),
|
|
'xml_tag.end': ('default', 'default'),
|
|
}
|
|
|
|
install = XML.install
|