import commands import color, mode from lex import Grammar, PatternRule, RegionRule, Grammar from method import Method from mode.perl import PerlGrammar from mode.xml import TagGrammar from mode.perl import StringGrammar class BDSGrammar(Grammar): rules = [ RegionRule(r'comment', r''), RegionRule(r'xml_tag', r'< */?', TagGrammar, r'/?>'), PatternRule(r'delimiter', r'[\[\]\{\}\(\),\?:]'), PatternRule(r'bds_derived', r'(?:FM|CD|FS|FM|TA)[0-9]{3}-[0-9]{3}-[0-9]{3}'), PatternRule(r'bds_question', r'GQ[0-9]{3}-[0-9]{3}-[0-9]{3}:MQ[0-9]{3}-[0-9]{3}-[0-9]{3}'), PatternRule(r'bds_function', r'[A-Z_][A-Z0-9_]+(?= *\()'), PatternRule(r'bds_perlfunc', r'[a-zA-Z_][a-zA-Z0-9_]+(?= *\()'), PatternRule(r'bds_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'bds_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'bds_operator', r'(?:>=|<=|>|<|==|&&|\|\||eq|ne)'), ] class BDSMakeInstall(Method): def _execute(self, w, **vargs): cmd = "perl Makefile.PL && make && make install" (status, output) = commands.getstatusoutput(cmd) if status == 0: w.set_error("make succeeded") else: w.application.data_buffer("*bds-make-install*", output, switch_to=True) w.set_error("make failed with %d" % status) class BDSCompileResources(Method): def _execute(self, w, **vargs): pass class BDSRestart(Method): def _execute(self, w, **vargs): pass class BDS(mode.Fundamental): modename = 'BDS' basenames = ['components.xml'] grammar = BDSGrammar opentokens = ('delimiter',) opentags = {'(': ')', '[': ']', '{': '}'} closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} colors = { 'bds_derived': ('yellow', 'default'), 'bds_question': ('yellow', 'default'), 'bds_misquoted': ('yellow', 'red'), 'bds_function': ('magenta', 'default'), 'bds_perlfunc': ('magenta', 'default'), 'bds_operator': ('magenta', 'default'), } actions = [BDSMakeInstall, BDSCompileResources, BDSRestart] def __init__(self, w): mode.Fundamental.__init__(self, w) self.add_bindings('close-paren', (')',)) self.add_bindings('close-brace', ('}',)) self.add_bindings('close-bracket', (']',)) install = BDS.install