pmacs3/mode/scheme.py

73 lines
4.3 KiB
Python
Raw Normal View History

2007-08-04 16:16:30 -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 SchemeGrammar(Grammar):
rules = [
PatternRule(r'comment', r';.*$'),
2007-08-05 00:05:14 -04:00
PatternRule(r'delimiter', r'\(|\)'),
2007-08-04 16:16:30 -04:00
RegionRule(r'string', r'"', StringGrammar, r'"'),
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-05 00:05:14 -04:00
PatternRule(r'keyword', r'define-syntax|define-macro|syntax-rules'),
PatternRule(r'keyword', r'quote|lambda|if|set\!|begin|cond|and|or|case|let\*|letrec|let|do|delay|quasiquote|else|=>|define|unquote-splicing|unquote|loop'),
2007-08-04 16:16:30 -04:00
2007-08-05 00:05:14 -04:00
# builtin predicates, mutators, and general procedures
PatternRule(r'builtin', r'(?:eqv|equal|eq|number|complex|real|rational|integer|exact|inexact|=|<=|>=|<|>|zero|positive|negative|odd|even|boolean|pair|null|list|symbol|char=|char<=|char>=|char<|char>|char-ci=|char-ci<=|char-ci>=|char-ci<|char-ci>|char-alphabetic|char-numeric|char-whitespace|char-upper-case|char-lower-case|char|string|string=|string-ci=|string<=|string>=|string<|string>|string-ci<=|string-ci>=|string-ci>|string-ci<|vector|procedure|input-port|output-port|port|eof-object|char-ready)\?'),
PatternRule(r'builtin', r'(?:set-car|set-cdr|string-set|string-fill|vector-set|vector-fill|set)\!'),
PatternRule(r'builtin', r'(?:max|min|\+|\*|-|/|abs|quotient|remainder|modulo|gcd|lcm|numerator|denominator|floor|ceiling|truncate|round|rationalize|exp|log|sin|cos|tan|asin|acos|atan|sqrt|expt|make-rectangular|make-polar|real-part|imag-part|magnitude|angle|exact->inexact|inexact->exact|number->string|string->number|not|cons|car|cdr|caar|cadr|cdar|cddr|caaar|caadr|cadar|cdaar|caddr|cdadr|cddar|cdddr|caaaar|caaadr|caadar|cadaar|cdaaar|caaddr|cadadr|caddar|cdadar|cddaar|cadddr|cdaddr|cddadr|cdddar|cddddr|list-tail|list-ref|length|append|reverse|memq|memv|member|assq|assv|assoc|symbol->string|string->symbol|char->integer|integer->char|char-upcase|char-downcase|make-string|string-length|string-ref|string-append|string->list|list->string|string-copy|substring|make-vector|vector-length|vector-ref|vector->list|list->vector|apply|map|for-each|force|call-with-current-continuation|values|call-with-values|dynamic-wind|eval|scheme-report-environment|null-environment|interaction-environment|call-with-input-file|call-with-output-file|current-input-port|current-output-port|with-input-from-file|with-output-to-file|open-input-file|open-output-file|close-input-port|close-output-port|read-char|peek-char|eof-object|read|write-char|write|display|newline|load|transcript-on|transcript-off|list|string|vector)(?![^ ()])'),
2007-08-04 16:16:30 -04:00
PatternRule(r'boolean', r'#[tf]'),
PatternRule(r'char', r'#\\space|#\\newline|#\\.'),
PatternRule(r'number', '[+-]?[0-9][^ \n]+'),
PatternRule(r'number', '#[bodx][ie]?[^ \n]+'),
PatternRule(r'number', '#[ie][bodx]?[^ \n]+'),
2007-08-05 00:05:14 -04:00
PatternRule(r'variable', r'[a-zA-Z!$%&*/:<=>?\^_~][a-zA-Z0-9!$%&*/:<=>?^_~+-.@]*|\+|-|...'),
2007-08-04 16:16:30 -04:00
]
class SchemeTabber(tab2.StackTabber):
pass
class Scheme(mode2.Fundamental):
tabbercls = SchemeTabber
grammar = SchemeGrammar
opentokens = ('delimiter',)
opentags = {'(': ')',},
closetokens = ('delimiter',)
closetags = {')': '(',},
colors = {
2007-08-05 00:05:14 -04:00
'comment': ('red', 'default'),
'keyword': ('cyan', 'default'),
'builtin': ('blue', 'default'),
2007-08-04 16:16:30 -04:00
'string.start': ('green', 'default'),
'string.null': ('green', 'default'),
'string.octal': ('magenta', 'default'),
'string.escaped': ('magenta', 'default'),
'string.end': ('green', 'default'),
2007-08-05 00:05:14 -04:00
'boolean': ('magenta', 'default'),
'number': ('default', 'default'),
2007-08-04 16:16:30 -04:00
}
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 scheme-specific methods
#self.add_action_and_bindings(SchemeCheckSyntax(), ('C-c s',))
def name(self):
return "Scheme"