import color, mode from lex import Grammar, PatternRule, RegionRule class StringGrammar(Grammar): rules = [ PatternRule(r'escaped', r'\\.'), ] class BDSGrammar(Grammar): rules = [ PatternRule(r'comment', r'#.*$'), PatternRule(r'bds_section', r'section(?= *\()'), PatternRule(r'bds_component', r"[A-Z]{2}\d{3}-\d{3}-\d{3}(?= *\()"), PatternRule(r'bds_attr_name', r"[a-z_]+(?==)"), RegionRule(r'bds_attr_value', r'(?<=)"', StringGrammar, r'"'), RegionRule(r'bds_attr_value', r"(?<=)'", StringGrammar, r"'"), PatternRule(r'bds_num', r"-?(?:[0-9][0-9\.]*[0-9]|[0-9])"), PatternRule(r'bds_alias', r"[a-z0-9]+(?=:[A-Z]{2}\d{3}-\d{3}-\d{3})"), PatternRule(r'bds_id', r"[A-Z]{2}\d{3}-\d{3}-\d{3}"), PatternRule(r'bds_func', r"[a-zA-Z0-9_]+(?= *\()"), RegionRule(r'bds_string', r'"', StringGrammar, r'"'), RegionRule(r'bds_string', r"'", StringGrammar, r"'"), ] class BDS(mode.Fundamental): modename = '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