from mode import Fundamental from lex import Grammar, PatternRule, RegionRule # this is a comment class StringGrammar1(Grammar): rules = [ PatternRule(r'data', r"[^\\']+"), PatternRule(r'escaped', r'\\.'), ] class StringGrammar2(Grammar): rules = [ PatternRule(r'data', r'[^\\"]+'), PatternRule(r'escaped', r'\\.'), ] tbbid = r'[A-Z]{2}\d{3}-\d{3}-\d{3}' class BDSGrammar(Grammar): rules = [ PatternRule(r'comment', r'#.*$'), PatternRule(r'bds.section', r'section(?= *\()'), PatternRule(r'bds.component', tbbid + r"(?= *\()"), PatternRule(r'bds.attr_name', r"[a-z_]+(?==)"), RegionRule(r'bds.attr_value', r"(?<=)'", StringGrammar1, r"'"), RegionRule(r'bds.attr_value', r'(?<=)"', StringGrammar2, r'"'), PatternRule(r'bds.num', r"-?(?:[0-9][0-9\.]*[0-9]|[0-9])"), PatternRule(r'bds.alias', r"[a-z0-9]+(?=:" + tbbid + ")"), PatternRule(r'bds.id', tbbid), PatternRule(r'bds.func', r"[a-zA-Z0-9_]+(?= *\()"), RegionRule(r'bds.string', r"'", StringGrammar1, r"'"), RegionRule(r'bds.string', r'"', StringGrammar2, r'"'), ] class BDS(Fundamental): name = 'bds' extensions = ['.bds'] grammar = BDSGrammar colors = { 'bds.section': ('blue', 'default', 'bold'), 'bds.component': ('magenta', 'default', 'bold'), 'bds.attr_name': ('blue', 'default', 'bold'), 'bds.attr_value.start': ('green', 'default', 'bold'), 'bds.attr_value.null': ('green', 'default', 'bold'), 'bds.attr_value.end': ('green', 'default', 'bold'), 'bds.num': ('red', 'default', 'bold'), 'bds.alias': ('magenta', 'default', 'bold'), 'bds.id': ('yellow', 'default', 'bold'), 'bds.func': ('cyan', 'default', 'bold'), 'bds.op': ('magenta', 'default', 'bold'), 'bds.string.start': ('red', 'default', 'bold'), 'bds.string.null': ('red', 'default', 'bold'), 'bds.string.end': ('red', 'default', 'bold'), } install = BDS.install