63 lines
2.6 KiB
Python
63 lines
2.6 KiB
Python
|
import color, mode2
|
||
|
from lex3 import Grammar, PatternRule, RegionRule, Grammar
|
||
|
from mode.perl import PerlGrammar
|
||
|
from mode.xml import TagGrammar
|
||
|
from mode.perl import StringGrammar
|
||
|
|
||
|
class BDSGrammar(Grammar):
|
||
|
rules = [
|
||
|
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
|
||
|
RegionRule(r'tag', r'< */?', TagGrammar, r'/?>'),
|
||
|
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', '"', StringGrammar, '"'),
|
||
|
RegionRule(r'string', "'", Grammar, "'"),
|
||
|
PatternRule(r'operator', r'(?:>=|<=|>|<|==|&&|\|\||eq|ne)'),
|
||
|
]
|
||
|
|
||
|
class BDS(mode2.Fundamental):
|
||
|
grammar = BDSGrammar
|
||
|
opentokens = ('delimiter',)
|
||
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
||
|
closetokens = ('delimiter',)
|
||
|
closetags = {')': '(', ']': '[', '}': '{'}
|
||
|
colors = {
|
||
|
'comment.start': ('red', 'default'),
|
||
|
'comment.null': ('red', 'default'),
|
||
|
'comment.end': ('red', 'default'),
|
||
|
|
||
|
'tag.start': ('default', 'default'),
|
||
|
'tag.namespace': ('magenta', 'default'),
|
||
|
'tag.name': ('blue', 'default'),
|
||
|
'tag.attrname': ('blue', 'default'),
|
||
|
'tag.string.start': ('cyan', 'default'),
|
||
|
'tag.string.null': ('cyan', 'default'),
|
||
|
'tag.string.end': ('cyan', 'default'),
|
||
|
'tag.end': ('default', 'default'),
|
||
|
|
||
|
'string.start': ('green', 'default'),
|
||
|
'string.octal': ('magenta', 'default'),
|
||
|
'string.escaped': ('magenta', 'default'),
|
||
|
'string.null': ('green', 'default'),
|
||
|
'string.end': ('green', 'default'),
|
||
|
|
||
|
'derived': ('yellow', 'default'),
|
||
|
'question': ('yellow', 'default'),
|
||
|
'misquoted': ('yellow', 'red'),
|
||
|
'bdsfunc': ('magenta', 'default'),
|
||
|
'perlfunc': ('magenta', 'default'),
|
||
|
'operator': ('magenta', 'default'),
|
||
|
}
|
||
|
def __init__(self, w):
|
||
|
mode2.Fundamental.__init__(self, w)
|
||
|
self.add_bindings('close-paren', (')',))
|
||
|
self.add_bindings('close-brace', ('}',))
|
||
|
self.add_bindings('close-bracket', (']',))
|
||
|
def name(self):
|
||
|
return "BDS"
|