pmacs3/mode_xml.py

37 lines
1.2 KiB
Python
Raw Normal View History

2007-07-14 10:21:22 -04:00
import color, mode2
from lex3 import Grammar, PatternRule, RegionRule
2007-06-18 15:09:00 -04:00
2007-07-18 07:22:12 -04:00
class TagGrammar(Grammar):
2007-06-18 15:09:00 -04:00
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]+(?==)'),
2007-07-18 07:22:12 -04:00
PatternRule(r'name', r'[^\[\] =>\n]+'),
2007-06-18 15:09:00 -04:00
]
class XMLGrammar(Grammar):
rules = [
2007-07-18 07:22:12 -04:00
# TODO: how does cdata work again?
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
2007-07-18 07:22:12 -04:00
RegionRule(r'tag', r'<', TagGrammar, r'/?>'),
2007-06-18 15:09:00 -04:00
]
2007-03-06 10:05:38 -05:00
class XML(mode2.Fundamental):
grammar = XMLGrammar
2007-07-18 07:22:12 -04:00
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'),
}
2007-03-06 10:05:38 -05:00
def name(self):
return "XML"