pmacs3/mode/bds.py

70 lines
2.6 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-04-06 15:21:30 -04:00
# this is a comment
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 = [
2009-04-24 14:52:32 -04:00
PatternRule('eol', r'\n'),
PatternRule('spaces', r' +'),
PatternRule('comment', r'#.*$'),
PatternRule('delimiter', r'(?:\|\||&&|[!<>=:\{\}\(\)\[\]])'),
PatternRule('bds.section', r'section(?= *\()'),
PatternRule('bds.component', tbbid + r"(?= *\()"),
PatternRule('bds.aname', r"[a-z_]+(?==)"),
RegionRule('bds.avalue', r"(?<=)'", StringGrammar1, r"'"),
RegionRule('bds.avalue', r'(?<=)"', StringGrammar2, r'"'),
2009-04-24 14:52:32 -04:00
PatternRule('bds.num', r"-?(?:[0-9][0-9\.]*[0-9]|[0-9])"),
PatternRule('bds.alias', r"[a-z0-9]+(?=:" + tbbid + ")"),
PatternRule('bds.id', tbbid),
PatternRule('bds.func', r"[a-zA-Z0-9_]+(?= *\()"),
RegionRule('bds.string', r"'", StringGrammar1, r"'"),
RegionRule('bds.string', r'"', StringGrammar2, r'"'),
PatternRule('bds.bareword', r'[a-zA-Z0-9_]+'),
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.aname': ('blue', 'default', 'bold'),
'bds.avalue.start': ('green', 'default', 'bold'),
'bds.avalue.data': ('green', 'default', 'bold'),
'bds.avalue.null': ('green', 'default', 'bold'),
'bds.avalue.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
}
2009-04-24 14:52:32 -04:00
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
2009-04-24 10:31:27 -04:00
_bindings = {
'close-paren': (')'),
'close-bracket': (']'),
'close-brace': ('}'),
}
2007-10-19 02:41:33 -04:00
install = BDS.install