pmacs3/mode/bds.py

85 lines
3.4 KiB
Python
Raw Normal View History

import commands
2007-07-21 11:40:53 -04:00
import color, mode2
from lex3 import Grammar, PatternRule, RegionRule, Grammar
from method import Method
2007-07-21 11:40:53 -04:00
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'(?:&gt;=|&lt;=|&gt;|&lt;|==|&amp;&amp;|\|\||eq|ne)'),
]
class BDS(mode2.Fundamental):
grammar = BDSGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
# comments
2007-07-21 11:40:53 -04:00
'comment.start': ('red', 'default'),
'comment.null': ('red', 'default'),
'comment.end': ('red', 'default'),
# xml tag
2007-07-21 11:40:53 -04:00
'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'),
# strings
2007-07-21 11:40:53 -04:00
'string.start': ('green', 'default'),
'string.octal': ('magenta', 'default'),
'string.escaped': ('magenta', 'default'),
'string.null': ('green', 'default'),
'string.end': ('green', 'default'),
# keywords, etc
2007-07-21 11:40:53 -04:00
'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', (']',))
self.add_action(BDSMakeInstall())
self.add_action(BDSCompileResources())
self.add_action(BDSRestart())
2007-07-21 11:40:53 -04:00
def name(self):
return "BDS"
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