39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
import color, mode2
|
|
from lex2 import Grammar, PatternRule, RegionRule
|
|
|
|
class OpenTagGrammar(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 = [
|
|
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
|
|
RegionRule(r'opentag', r'<', OpenTagGrammar, r'/?>'),
|
|
PatternRule(r'closetag', r'< */ *[ =>\n]+ *>'),
|
|
]
|
|
|
|
class XML(mode2.Fundamental):
|
|
grammar = XMLGrammar
|
|
def __init__(self, w):
|
|
mode2.Fundamental.__init__(self, w)
|
|
self.colors = {
|
|
'comment.start': color.build('red', 'default'),
|
|
'comment.null': color.build('red', 'default'),
|
|
'comment.end': color.build('red', 'default'),
|
|
'opentag.start': color.build('default', 'default'),
|
|
'opentag.namespace': color.build('magenta', 'default'),
|
|
'opentag.name': color.build('blue', 'default'),
|
|
'opentag.attrname': color.build('cyan', 'default'),
|
|
'opentag.string.start': color.build('green', 'default'),
|
|
'opentag.string.null': color.build('green', 'default'),
|
|
'opentag.string.end': color.build('green', 'default'),
|
|
'opentag.end': color.build('default', 'default'),
|
|
}
|
|
def name(self):
|
|
return "XML"
|