pmacs3/mode_bds.py

66 lines
3.3 KiB
Python
Raw Normal View History

import color, lex2, mode2
2007-06-26 15:35:17 -04:00
from lex2 import Grammar, PatternRule, RegionRule
class StringGrammar(Grammar):
rules = [
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
2007-06-26 15:35:17 -04:00
]
lex2.add('xml-string', StringGrammar)
2007-06-26 15:35:17 -04:00
class BDSGrammar(Grammar):
rules = [
RegionRule(r'comment', r'<!--', lex2.get('null'), r'-->'),
RegionRule(r'opentag', r'<', lex2.get('xml-opentag'), r'/?>'),
PatternRule(r'closetag', r'< */ *[ =>\n]+ *>'),
PatternRule(r'delimiter', r'[\[\]\{\}\(\),\?:]'),
PatternRule(r'derived', r'(?:FM|CD|FS|FM|TA)[0-9]{3}-[0-9]{3}-[0-9]{3}'),
PatternRule(r'question', r'GQ[0-9]{3}-[0-9]{3}-[0-9]{3}:MQ[0-9]{3}-[0-9]{3}-[0-9]{3}'),
PatternRule(r'bdsfunc', r'[A-Z_][A-Z0-9_]+(?= *\()'),
PatternRule(r'perlfunc', r'[a-zA-Z_][a-zA-Z0-9_]+(?= *\()'),
PatternRule(r'misquoted', 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(r'misquoted', 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(r'string', '"', lex2.get('perl-string'), '"'),
RegionRule(r'string', "'", lex2.get('null'), "'"),
PatternRule(r'operator', r'(?:&gt;=|&lt;=|&gt;|&lt;|==|&amp;&amp;|\|\||eq|ne)'),
2007-06-26 15:35:17 -04:00
]
lex2.add('bds', BDSGrammar)
2007-06-26 15:35:17 -04:00
class BDS(mode2.Fundamental):
grammar = lex2.get('bds')
2007-06-26 15:35:17 -04:00
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"