pmacs3/mode/xml.py

39 lines
1.3 KiB
Python

import color, mode2
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'tag', r'<', TagGrammar, r'/?>'),
]
class XML(mode2.Fundamental):
modename = 'XML'
extensions = ['.xml', '.xml.in']
grammar = XMLGrammar
colors = {
'comment.start': ('red', 'default'),
'comment.null': ('red', 'default'),
'comment.end': ('red', 'default'),
'tag.start': ('default', 'default'),
'tag.namespace': ('magenta', 'default'),
'tag.name': ('blue', 'default'),
'tag.attrname': ('cyan', 'default'),
'tag.string.start': ('green', 'default'),
'tag.string.null': ('green', 'default'),
'tag.string.end': ('green', 'default'),
'tag.end': ('default', 'default'),
}
install = XML.install