pmacs3/mode/lisp.py

76 lines
4.0 KiB
Python
Raw Normal View History

2007-08-03 18:19:16 -04:00
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'\\.'),
]
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|unless|setq|require|mapcar|list|let|lambda|if|defvar|defalias|cons|cdr|car)(?![a-zA-Z0-9_])'),
PatternRule(r'symbol', 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"'''"),
RegionRule(r'string', r'"', StringGrammar, r'"'),
# RegionRule(r'string', r"'", StringGrammar, r"'"),
# PatternRule(r'continuation', r'\\\n$'),
# PatternRule(r'eol', r'\n$'),
]
class LispTabber(tab2.StackTabber):
pass
class Lisp(mode2.Fundamental):
tabbercls = LispTabber
grammar = LispGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
colors = {
'keyword': ('cyan', 'default'),
'reserved': ('blue', 'default'),
'symbol': ('magenta', '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"