import color, mode2 from lex2 import Grammar, PatternRule, RegionRule class OpenTagGrammar(Grammar): rules = [ RegionRule(name=r'string', start=r'(?P["\'])', grammar=Grammar(), end=r'%(tag)s'), PatternRule(name=r'namespace', pattern=r'[a-zA-Z_]+:'), PatternRule(name=r'attrname', pattern=r'[^ =>\n]+(?==)'), PatternRule(name=r'name', pattern=r'[^ =>\n]+'), ] class StringGrammar(Grammar): rules = [ PatternRule(name=r'octal', pattern=r'\\[0-7]{3}'), PatternRule(name=r'escaped', pattern=r'\\.'), ] class BDSGrammar(Grammar): rules = [ RegionRule(name=r'comment', start=r''), RegionRule(name=r'opentag', start=r'<', grammar=OpenTagGrammar(), end=r'/?>'), PatternRule(name=r'closetag', pattern=r'< */ *[ =>\n]+ *>'), PatternRule(name=r'delimiter', pattern=r'[\[\]\{\}\(\),\?:]'), PatternRule(name=r'derived', pattern=r'(?:FM|CD|FS|FM|TA)[0-9]{3}-[0-9]{3}-[0-9]{3}'), PatternRule(name=r'question', pattern=r'GQ[0-9]{3}-[0-9]{3}-[0-9]{3}:MQ[0-9]{3}-[0-9]{3}-[0-9]{3}'), PatternRule(name=r'bdsfunc', pattern=r'[A-Z_][A-Z0-9_]+(?= *\()'), PatternRule(name=r'perlfunc', pattern=r'[a-zA-Z_][a-zA-Z0-9_]+(?= *\()'), PatternRule(name=r'misquoted', pattern=r"'[A-Z]{2}[0-9]{3}-[0-9]{3}-[0-9]{3}(?::[A-Z]{2}[0-9]{3}-[0-9]{3}-[0-9]{3})?'"), PatternRule(name=r'misquoted', pattern=r'"[A-Z]{2}[0-9]{3}-[0-9]{3}-[0-9]{3}(?::[A-Z]{2}[0-9]{3}-[0-9]{3}-[0-9]{3})?"'), RegionRule(name=r'string', start='"', grammar=StringGrammar(), end='"'), RegionRule(name=r'string', start="'", grammar=Grammar(), end="'"), PatternRule(name=r'operator', pattern=r'(?:>=|<=|>|<|==|&&|\|\||eq|ne)'), ] class BDS(mode2.Fundamental): grammar = BDSGrammar opentoken = 'delimiter' opentags = {'(': ')', '[': ']', '{': '}'} closetoken = 'delimiter' closetags = {')': '(', ']': '[', '}': '{'} def __init__(self, w): mode2.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) 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('blue', 'default'), 'opentag.string.start': color.build('cyan', 'default'), 'opentag.string.null': color.build('cyan', 'default'), 'opentag.string.end': color.build('cyan', 'default'), 'opentag.end': color.build('default', 'default'), 'string.start': color.build('green', 'default'), 'string.octal': color.build('magenta', 'default'), 'string.escaped': color.build('magenta', 'default'), 'string.null': color.build('green', 'default'), 'string.end': color.build('green', 'default'), 'derived': color.build('yellow', 'default'), 'question': color.build('yellow', 'default'), 'misquoted': color.build('yellow', 'red'), 'bdsfunc': color.build('magenta', 'default'), 'perlfunc': color.build('magenta', 'default'), 'operator': color.build('magenta', 'default'), } def name(self): return "BDS"