2009-03-20 15:41:56 -04:00
|
|
|
from method import Method
|
|
|
|
from method.shell import Interact
|
2007-10-21 20:50:11 -04:00
|
|
|
from point import Point
|
2007-10-21 20:52:48 -04:00
|
|
|
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
|
2009-03-27 22:33:36 -04:00
|
|
|
from lex import PatternMatchRule
|
2009-03-20 15:41:56 -04:00
|
|
|
from mode.lisp import StringGrammar2, Lisp, LispTabber
|
2007-08-04 16:16:30 -04:00
|
|
|
|
|
|
|
class SchemeGrammar(Grammar):
|
|
|
|
rules = [
|
|
|
|
PatternRule(r'comment', r';.*$'),
|
2007-08-05 10:25:49 -04:00
|
|
|
PatternRule(r'delimiter', r'[()]'),
|
2009-03-20 15:41:56 -04:00
|
|
|
RegionRule(r'string', r'"', StringGrammar2, r'"'),
|
2007-08-04 16:16:30 -04:00
|
|
|
PatternRule(r'spaces', r' +'),
|
|
|
|
PatternRule(r'eol', r'\n'),
|
2007-08-05 00:05:14 -04:00
|
|
|
PatternRule(r'abbrev', r"'|`|,\@|,"),
|
2007-08-04 16:16:30 -04:00
|
|
|
|
2007-08-15 10:37:35 -04:00
|
|
|
# from r5rs
|
2008-03-16 01:23:14 -04:00
|
|
|
PatternRule(r'scheme_keyword', r'(?:=>|unquote-splicing|unquote|syntax-rules|set!|quote|quasiquote|or|map|loop|letrec-syntax|letrec|let-syntax|let\*|let|lambda|if|for-each|else|dynamic-wind|do|delay|define-syntax|define-macro|define|cond|case|call-with-output-file|call-with-input-file|call-with-current-continuation|begin|and)(?![^\n )])'),
|
2007-08-04 16:16:30 -04:00
|
|
|
|
2008-03-16 01:23:14 -04:00
|
|
|
PatternRule(r'scheme_boolean', r'#[tf]'),
|
|
|
|
PatternRule(r'scheme_char', r'#\\space|#\\newline|#\\.'),
|
|
|
|
PatternRule(r'scheme_number', '[+-]?[0-9][^ ()\n]+'),
|
|
|
|
PatternRule(r'scheme_number', '#[bodx][ie]?[^ ()\n]+'),
|
|
|
|
PatternRule(r'scheme_number', '#[ie][bodx]?[^ ()\n]+'),
|
2007-08-05 00:05:14 -04:00
|
|
|
|
2007-08-15 10:37:35 -04:00
|
|
|
PatternRule(r'variable', r'[a-zA-Z!$%&*/:<=>?\^_~][-a-zA-Z0-9!$%&*/:<=>?^_~+.@]*|\+|-|\.\.\.'),
|
2007-08-04 16:16:30 -04:00
|
|
|
]
|
|
|
|
|
2009-03-20 15:41:56 -04:00
|
|
|
class SchemeCheckSyntax(Method):
|
2008-04-18 23:32:08 -04:00
|
|
|
'''Check the syntax of a scheme file'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
app = w.application
|
|
|
|
cmd = "guile -s %r" % (w.buffer.path)
|
|
|
|
(status, output) = commands.getstatusoutput(cmd)
|
|
|
|
if status == 0:
|
|
|
|
app.set_error("Syntax OK")
|
|
|
|
app.data_buffer("*Scheme-Check-Syntax*", output, switch_to=False)
|
|
|
|
else:
|
|
|
|
app.data_buffer("*Scheme-Check-Syntax*", output)
|
|
|
|
|
2009-03-20 15:41:56 -04:00
|
|
|
class GuileStart(Interact):
|
2009-03-04 01:53:26 -05:00
|
|
|
args = []
|
2009-04-07 00:34:26 -04:00
|
|
|
reuse = True
|
2009-03-04 01:53:26 -05:00
|
|
|
def _execute(self, w, **vargs):
|
2009-03-20 15:41:56 -04:00
|
|
|
Interact._execute(self, w, bname='*Guile*', cmd='guile')
|
2009-03-04 01:53:26 -05:00
|
|
|
|
2009-03-20 15:41:56 -04:00
|
|
|
class GuileLoadFile(Interact):
|
2009-03-04 01:53:26 -05:00
|
|
|
args = []
|
2009-04-07 00:34:26 -04:00
|
|
|
reuse = True
|
2009-03-04 01:53:26 -05:00
|
|
|
def _execute(self, w, **vargs):
|
2009-03-20 15:41:56 -04:00
|
|
|
Interact._execute(self, w, bname='*Guile*', cmd='guile')
|
2009-03-04 01:53:26 -05:00
|
|
|
b = w.application.get_buffer_by_name('*Guile*')
|
|
|
|
path = os.path.realpath(w.buffer.path)
|
|
|
|
b.pipe_write('(load "%s")\n' % path)
|
|
|
|
|
2009-03-20 15:41:56 -04:00
|
|
|
class Scheme(Lisp):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'Scheme'
|
2007-10-18 17:07:35 -04:00
|
|
|
extensions = ['.scm']
|
2007-08-04 16:16:30 -04:00
|
|
|
grammar = SchemeGrammar
|
2007-08-16 10:21:37 -04:00
|
|
|
colors = {
|
2008-05-03 13:31:30 -04:00
|
|
|
'scheme_keyword': ('cyan', 'default', 'bold'),
|
|
|
|
'scheme_char': ('green', 'default', 'bold'),
|
|
|
|
'scheme_boolean': ('magenta', 'default', 'bold'),
|
|
|
|
'scheme_number': ('default', 'default', 'bold'),
|
2007-08-04 16:16:30 -04:00
|
|
|
}
|
2009-03-04 01:53:26 -05:00
|
|
|
actions = [SchemeCheckSyntax, GuileStart, GuileLoadFile]
|
2009-02-15 12:06:35 -05:00
|
|
|
_bindings = {
|
2009-03-04 01:53:26 -05:00
|
|
|
'close-paren': (')',),
|
|
|
|
'close-brace': ('}',),
|
|
|
|
'close-bracket': (']',),
|
2009-02-15 12:06:35 -05:00
|
|
|
'scheme-check-syntax': ('C-c s',),
|
|
|
|
}
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = Scheme.install
|