2007-08-04 16:16:30 -04:00
|
|
|
import commands, os.path, sets, string, sys, traceback
|
2007-10-21 20:55:29 -04:00
|
|
|
import color, completer, default, mode, method, regex, tab
|
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
|
2007-08-06 13:38:13 -04:00
|
|
|
import mode.lisp
|
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'[()]'),
|
2007-08-06 13:38:13 -04:00
|
|
|
RegionRule(r'string', r'"', mode.lisp.StringGrammar, 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
|
|
|
]
|
|
|
|
|
2007-10-21 20:55:29 -04:00
|
|
|
class Scheme(mode.Fundamental):
|
2007-10-18 17:07:35 -04:00
|
|
|
modename = 'Scheme'
|
|
|
|
extensions = ['.scm']
|
2007-08-16 10:21:37 -04:00
|
|
|
tabwidth = 2
|
2007-08-06 13:38:13 -04:00
|
|
|
tabbercls = mode.lisp.LispTabber
|
2007-08-04 16:16:30 -04:00
|
|
|
grammar = SchemeGrammar
|
|
|
|
opentokens = ('delimiter',)
|
2007-08-05 10:25:49 -04:00
|
|
|
opentags = {'(': ')'}
|
2007-08-04 16:16:30 -04:00
|
|
|
closetokens = ('delimiter',)
|
2007-08-05 10:25:49 -04:00
|
|
|
closetags = {')': '('}
|
2007-08-16 10:21:37 -04:00
|
|
|
colors = {
|
2008-03-16 01:23:14 -04:00
|
|
|
#'comment': ('red', 'default'),
|
2007-08-05 00:05:14 -04:00
|
|
|
|
2008-03-16 01:23:14 -04:00
|
|
|
'scheme_keyword': ('cyan', 'default'),
|
2007-08-05 00:05:14 -04:00
|
|
|
|
2008-03-16 01:23:14 -04:00
|
|
|
#'string.start': ('green', 'default'),
|
|
|
|
#'string.null': ('green', 'default'),
|
|
|
|
#'string.octal': ('magenta', 'default'),
|
|
|
|
#'string.escaped': ('magenta', 'default'),
|
|
|
|
#'string.end': ('green', 'default'),
|
|
|
|
'scheme_char': ('green', 'default'),
|
|
|
|
'scheme_boolean': ('magenta', 'default'),
|
|
|
|
'scheme_number': ('default', 'default'),
|
2007-08-04 16:16:30 -04:00
|
|
|
}
|
|
|
|
def __init__(self, w):
|
2007-10-21 20:55:29 -04:00
|
|
|
mode.Fundamental.__init__(self, w)
|
2007-08-04 16:16:30 -04:00
|
|
|
self.add_bindings('close-paren', (')',))
|
|
|
|
self.add_bindings('close-brace', ('}',))
|
|
|
|
self.add_bindings('close-bracket', (']',))
|
2008-01-29 13:07:13 -05:00
|
|
|
self.add_action_and_bindings(SchemeCheckSyntax(), ('C-c s',))
|
|
|
|
|
|
|
|
class SchemeCheckSyntax(method.Method):
|
|
|
|
'''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)
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = Scheme.install
|