2009-03-31 10:57:14 -04:00
|
|
|
import os
|
2009-03-20 15:41:56 -04:00
|
|
|
import regex
|
2009-03-31 10:57:14 -04:00
|
|
|
from method import Method
|
|
|
|
from method.shell import Interact
|
2009-03-20 15:41:56 -04:00
|
|
|
from mode import Fundamental
|
|
|
|
from tab import StackTabber
|
|
|
|
from lex import Grammar, PatternRule, RegionRule
|
2008-10-01 16:58:43 -04:00
|
|
|
from mode.python import StringGrammar2
|
2007-08-03 18:19:16 -04:00
|
|
|
|
|
|
|
class LispGrammar(Grammar):
|
|
|
|
rules = [
|
2009-03-31 10:57:14 -04:00
|
|
|
PatternRule('comment', ';.*$'),
|
|
|
|
PatternRule('delimiter', "[()']"),
|
|
|
|
PatternRule('keyword', r'(?:or|not|list|let\*|let|lambda|if|cons|c[ad]+r|apply|and)(?![^\"\' \t()])'),
|
|
|
|
PatternRule('lisp_word', r"[^\"' \t()]+"),
|
|
|
|
RegionRule('string', '"', StringGrammar2, '"'),
|
|
|
|
PatternRule('spaces', ' +'),
|
|
|
|
PatternRule('eol', r'\n'),
|
2007-08-03 18:19:16 -04:00
|
|
|
]
|
|
|
|
|
2009-03-20 15:41:56 -04:00
|
|
|
class LispTabber(StackTabber):
|
2007-08-15 18:37:49 -04:00
|
|
|
wsre = regex.whitespace
|
|
|
|
wst = ('spaces', 'null', 'eol',)
|
|
|
|
sre = regex.space
|
|
|
|
st = ('spaces', 'null',)
|
2007-08-06 11:36:49 -04:00
|
|
|
def _handle_open_token(self, currlvl, y, i):
|
2007-08-15 18:37:49 -04:00
|
|
|
token = self.get_token(y, i)
|
|
|
|
rtoken = self.get_next_right_token(y, i)
|
|
|
|
if rtoken is None:
|
2007-08-16 10:21:37 -04:00
|
|
|
level = self.get_curr_level() + self.mode.tabwidth
|
2008-07-19 16:00:11 -04:00
|
|
|
elif rtoken.string not in ('(', 'define', 'lambda'):
|
|
|
|
rtoken = self.get_next_right_token(y, i + 1)
|
|
|
|
if rtoken is None or rtoken.string != '(':
|
|
|
|
level = self.get_curr_level() + self.mode.tabwidth
|
|
|
|
else:
|
|
|
|
level = rtoken.x
|
2007-08-15 18:37:49 -04:00
|
|
|
else:
|
2008-07-19 16:00:11 -04:00
|
|
|
level = self.get_curr_level() + self.mode.tabwidth
|
2007-08-15 18:37:49 -04:00
|
|
|
self._append(token.string, level)
|
2007-08-06 11:36:49 -04:00
|
|
|
return currlvl
|
2007-08-03 18:19:16 -04:00
|
|
|
|
2009-03-31 10:57:14 -04:00
|
|
|
class ClispStart(Interact):
|
|
|
|
args = []
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
Interact._execute(self, w, bname='*Clisp*', cmd='clisp')
|
|
|
|
class ClispLoadFile(Interact):
|
|
|
|
args = []
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
Interact._execute(self, w, bname='*Clisp*', cmd='clisp')
|
|
|
|
b = w.application.get_buffer_by_name('*Clisp*')
|
|
|
|
path = os.path.realpath(w.buffer.path)
|
|
|
|
b.pipe_write('(load "%s")\n' % path)
|
|
|
|
|
2009-03-20 15:41:56 -04:00
|
|
|
class Lisp(Fundamental):
|
2009-03-17 15:24:10 -04:00
|
|
|
name = 'Lisp'
|
2009-03-31 10:57:14 -04:00
|
|
|
extensions = ['.lisp']
|
2007-08-16 10:21:37 -04:00
|
|
|
tabwidth = 2
|
2007-08-03 18:19:16 -04:00
|
|
|
tabbercls = LispTabber
|
|
|
|
grammar = LispGrammar
|
2009-03-20 15:41:56 -04:00
|
|
|
commentc = ';'
|
2007-08-03 18:19:16 -04:00
|
|
|
opentokens = ('delimiter',)
|
2007-08-06 11:36:49 -04:00
|
|
|
opentags = {'(': ')'}
|
2007-08-03 18:19:16 -04:00
|
|
|
closetokens = ('delimiter',)
|
2007-08-06 11:36:49 -04:00
|
|
|
closetags = {')': '('}
|
2009-03-31 10:57:14 -04:00
|
|
|
actions = [ClispStart, ClispLoadFile]
|
2009-02-15 12:06:35 -05:00
|
|
|
_bindings = {
|
2009-03-31 10:57:14 -04:00
|
|
|
'close-paren': (')',),
|
2009-02-15 12:06:35 -05:00
|
|
|
}
|
|
|
|
commentc = ';'
|
2007-10-19 02:41:33 -04:00
|
|
|
|
|
|
|
install = Lisp.install
|