parent
57056968da
commit
55c55aeca9
57
mode/lisp.py
57
mode/lisp.py
|
@ -2,77 +2,42 @@ import commands, os.path, sets, string, sys, traceback
|
|||
import color, completer, default, mode2, method, regex, tab2
|
||||
from point2 import Point
|
||||
from lex3 import Grammar, PatternRule, RegionRule, OverridePatternRule
|
||||
|
||||
class StringGrammar(Grammar):
|
||||
rules = [
|
||||
PatternRule(r'octal', r'\\[0-7]{3}'),
|
||||
PatternRule(r'escaped', r'\\.'),
|
||||
]
|
||||
from mode.python import StringGrammar
|
||||
|
||||
class LispGrammar(Grammar):
|
||||
rules = [
|
||||
PatternRule(r'comment', r';.*$'),
|
||||
# PatternRule(r'functionname', r'(?<=def )[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||
# PatternRule(r'classname', r'(?<=class )[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||
PatternRule(r'reserved', r'(?:nil)(?![a-zA-Z0-9_])'),
|
||||
PatternRule(r'keyword', r'(?:while|when|unless|setq|require|or|not|mapcar|list|let|lambda|if|exists|equal|defvar|defun|defalias|count|cons|cdr|car|apply|and)(?![a-zA-Z0-9_])'),
|
||||
PatternRule(r'symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"),
|
||||
PatternRule(r'type', r":[a-zA-Z_][a-zA-Z0-9-_]*"),
|
||||
PatternRule(r'attribute', r"&[a-zA-Z_][a-zA-Z0-9-_]*"),
|
||||
# PatternRule(r"builtin", r'(?<!\.)(?:zip|xrange|vars|unicode|unichr|type|tuple|super|sum|str|staticmethod|sorted|slice|setattr|set|round|repr|reduce|raw_input|range|property|pow|ord|open|oct|object|max|min|map|long|locals|list|len|iter|issubclass|isinstance|int|input|id|hex|hash|hasattr|globals|getattr|frozenset|float|filter|file|execfile|eval|enumerate|divmod|dir|dict|delattr|complex|compile|coerce|cmp|classmethod|chr|callable|bool)(?![a-zA-Z0-9_])'),
|
||||
PatternRule(r'bareword', r"[a-zA-Z_][a-zA-Z0-9-_]*"),
|
||||
# PatternRule(r'methodcall', r'(?<=\. )[a-zA-Z_][a-zA-Z0-9_]*(?= *\()'),
|
||||
# PatternRule(r'functioncall', r'[a-zA-Z_][a-zA-Z0-9_]*(?= *\()'),
|
||||
# PatternRule(r'system_identifier', r'__[a-zA-Z0-9_]+__'),
|
||||
# PatternRule(r'private_identifier', r'__[a-zA-Z0-9_]*'),
|
||||
# PatternRule(r'hidden_identifier', r'_[a-zA-Z0-9_]*'),
|
||||
# PatternRule(r'identifier', r'[a-zA-Z_][a-zA-Z0-9_]*'),
|
||||
# PatternRule(r'delimiter', r'\(|\)|\[|\]|{|}|@|,|:|\.|`|=|;|\+=|-=|\*=|/=|//=|%=|&=|\|=|\^=|>>=|<<=|\*\*='),
|
||||
# PatternRule(r"operator", r"\+|<>|<<|<=|<|-|>>|>=|>|\*\*|&|\*|\||/|\^|==|//|~|!=|%"),
|
||||
PatternRule(r"integer", r"(?<![\.0-9a-zA-Z_])(?:0|[1-9][0-9]*|0[0-7]+|0[xX][0-9a-fA-F]+)[lL]?(?![\.0-9a-zA-Z_])"),
|
||||
PatternRule(r"float", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)(?![\.0-9a-zA-Z_])"),
|
||||
PatternRule(r"imaginary", r"(?<![\.0-9a-zA-Z_])(?:[0-9]+|(?:[0-9]+\.[0-9]*|\.[0-9]+|(?:[0-9]|[0-9]+\.[0-9]*|\.[0-9]+)[eE][\+-]?[0-9]+)[jJ])(?![\.0-9a-zA-Z_])"),
|
||||
# RegionRule(r'string', r'"""', StringGrammar, r'"""'),
|
||||
# RegionRule(r'string', r"'''", StringGrammar, r"'''"),
|
||||
PatternRule(r'delimiter', r'[()]'),
|
||||
RegionRule(r'string', r'"', StringGrammar, r'"'),
|
||||
# RegionRule(r'string', r"'", StringGrammar, r"'"),
|
||||
# PatternRule(r'continuation', r'\\\n$'),
|
||||
# PatternRule(r'eol', r'\n$'),
|
||||
PatternRule(r'spaces', r' +'),
|
||||
PatternRule(r'eol', r'\n'),
|
||||
]
|
||||
|
||||
class LispTabber(tab2.StackTabber):
|
||||
pass
|
||||
def _handle_open_token(self, currlvl, y, i):
|
||||
level = self.get_curr_level() + 4
|
||||
self._append(self.get_token(y, i).string, level)
|
||||
return currlvl
|
||||
|
||||
class Lisp(mode2.Fundamental):
|
||||
tabbercls = LispTabber
|
||||
grammar = LispGrammar
|
||||
opentokens = ('delimiter',)
|
||||
opentags = {'(': ')', '[': ']', '{': '}'}
|
||||
opentags = {'(': ')'}
|
||||
closetokens = ('delimiter',)
|
||||
closetags = {')': '(', ']': '[', '}': '{'}
|
||||
closetags = {')': '('}
|
||||
colors = {
|
||||
'keyword': ('cyan', 'default'),
|
||||
'reserved': ('blue', 'default'),
|
||||
'symbol': ('magenta', 'default'),
|
||||
'type': ('blue', 'default'),
|
||||
'comment': ('red', 'default'),
|
||||
'string.start': ('green', 'default'),
|
||||
'string.null': ('green', 'default'),
|
||||
'string.octal': ('magenta', 'default'),
|
||||
'string.escaped': ('magenta', 'default'),
|
||||
'string.format': ('yellow', 'default'),
|
||||
'string.end': ('green', 'default'),
|
||||
'integer': ('default', 'default'),
|
||||
'float': ('default', 'default'),
|
||||
'imaginary': ('default', 'default'),
|
||||
'comment': ('red', 'default'),
|
||||
}
|
||||
def __init__(self, w):
|
||||
mode2.Fundamental.__init__(self, w)
|
||||
# tag matching
|
||||
self.add_bindings('close-paren', (')',))
|
||||
self.add_bindings('close-brace', ('}',))
|
||||
self.add_bindings('close-bracket', (']',))
|
||||
## add lisp-specific methods
|
||||
#self.add_action_and_bindings(LispCheckSyntax(), ('C-c s',))
|
||||
def name(self):
|
||||
return "Lisp"
|
||||
|
|
Loading…
Reference in New Issue