pmacs3/mode/bds.py

68 lines
2.9 KiB
Python

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, StrictStringGrammar
class BDSGrammar(Grammar):
rules = [
RegionRule(r'comment', r'<!--', Grammar, r'-->'),
RegionRule(r'xml_tag', r'< */?', TagGrammar, r'/?>'),
PatternRule(r'delimiter', r'[\[\]\{\}\(\),\?:]'),
PatternRule(r'bds_alias', r'[a-z0-9]+(?=:)'),
PatternRule(r'keyword', r'if|else|elsif|unless'),
PatternRule(r'bds_derived', r'(?:CN|FM|CD|IS|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', "'", StrictStringGrammar, "'"),
PatternRule(r'bds_operator', r'(?:&gt;=|&lt;=|&gt;|&lt;|==|&amp;&amp;|\|\||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_alias': ('yellow', 'default', 'bold'),
'bds_derived': ('yellow', 'default', 'bold'),
'bds_question': ('yellow', 'default', 'bold'),
'bds_misquoted': ('yellow', 'red', 'bold'),
'bds_function': ('magenta', 'default', 'bold'),
'bds_perlfunc': ('magenta', 'default', 'bold'),
'bds_operator': ('magenta', 'default', 'bold'),
}
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