pmacs3/mode/bds.py

55 lines
2.1 KiB
Python
Raw Normal View History

2009-03-29 20:50:27 -04:00
from mode import Fundamental
2008-09-09 18:43:22 -04:00
from lex import Grammar, PatternRule, RegionRule
2007-07-21 11:40:53 -04:00
2009-03-29 20:50:27 -04:00
class StringGrammar1(Grammar):
2007-07-21 11:40:53 -04:00
rules = [
2009-03-29 20:50:27 -04:00
PatternRule(r'data', r"[^\\']+"),
2008-09-09 18:43:22 -04:00
PatternRule(r'escaped', r'\\.'),
2007-07-21 11:40:53 -04:00
]
2009-03-29 20:50:27 -04:00
class StringGrammar2(Grammar):
rules = [
PatternRule(r'data', r'[^\\"]+'),
PatternRule(r'escaped', r'\\.'),
]
tbbid = r'[A-Z]{2}\d{3}-\d{3}-\d{3}'
2007-07-21 11:40:53 -04:00
2008-09-09 18:43:22 -04:00
class BDSGrammar(Grammar):
rules = [
PatternRule(r'comment', r'#.*$'),
PatternRule(r'bds_section', r'section(?= *\()'),
2009-03-29 20:50:27 -04:00
PatternRule(r'bds_component', tbbid + r"(?= *\()"),
2008-09-09 18:43:22 -04:00
PatternRule(r'bds_attr_name', r"[a-z_]+(?==)"),
2009-03-29 20:50:27 -04:00
RegionRule(r'bds_attr_value', r"(?<=)'", StringGrammar1, r"'"),
RegionRule(r'bds_attr_value', r'(?<=)"', StringGrammar2, r'"'),
2008-09-09 18:43:22 -04:00
PatternRule(r'bds_num', r"-?(?:[0-9][0-9\.]*[0-9]|[0-9])"),
2009-03-29 20:50:27 -04:00
PatternRule(r'bds_alias', r"[a-z0-9]+(?=:" + tbbid + ")"),
PatternRule(r'bds_id', tbbid),
2008-09-09 18:43:22 -04:00
PatternRule(r'bds_func', r"[a-zA-Z0-9_]+(?= *\()"),
2009-03-29 20:50:27 -04:00
RegionRule(r'bds_string', r"'", StringGrammar1, r"'"),
RegionRule(r'bds_string', r'"', StringGrammar2, r'"'),
2008-09-09 18:43:22 -04:00
]
2008-04-18 23:32:08 -04:00
2009-03-29 20:50:27 -04:00
class BDS(Fundamental):
name = 'bds'
2008-09-09 18:43:22 -04:00
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'),
2007-07-21 11:40:53 -04:00
}
2007-10-19 02:41:33 -04:00
install = BDS.install