pmacs3/mode/elisp.py

56 lines
2.3 KiB
Python
Raw Permalink Normal View History

2009-03-20 15:41:56 -04:00
from mode import Fundamental
from point import Point
2007-10-21 20:52:48 -04:00
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
2009-03-20 15:41:56 -04:00
from mode.lisp import Lisp, LispTabber
2007-08-04 16:16:30 -04:00
class StringGrammar(Grammar):
rules = [
2009-03-29 20:50:27 -04:00
PatternRule('octal', r'\\[0-7]{3}'),
PatternRule('escaped', r'\\.'),
PatternRule('data', r'[^\\"]+'),
2007-08-04 16:16:30 -04:00
]
# TODO: a lot of these rules need fixing
2009-03-29 20:50:27 -04:00
chr1 = '[a-zA-Z_]'
chr2 = '[a-zA-Z0-9-_]'
symb = chr1 + chr2 + '*'
2007-08-04 16:16:30 -04:00
class ELispGrammar(Grammar):
rules = [
2009-03-29 20:50:27 -04:00
PatternRule('comment', ';.*$'),
PatternRule('delimiter', '[()]'),
PatternRule('spaces', ' +'),
PatternRule('eol', r'\n'),
PatternRule('elisp_reserved', r'(?:t|nil)(?![^\"\' \t()])'),
PatternRule('keyword', r'(?:while|when|unless|setq-default|setq|setcar|require|provide|or|not|mapcar|list|let\*|let|lambda|if|exists|equal|defvar|defun|defstruct|defface|defalias|count|cons|c[ad]+r|apply|and)(?![^\"\' \t()])'),
PatternRule('elisp_symbol', "'" + symb),
PatternRule('delimiter', r"'"),
PatternRule('elisp_type', ":" + symb),
PatternRule('char', r'\?(?:[^\\]|\\.)'),
2009-03-29 20:50:27 -04:00
PatternRule('attribute', "&" + symb),
PatternRule("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("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("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_])"),
PatternRule('elisp_word', r"[^\"' \t()]+"),
RegionRule('string', r'"', StringGrammar, r'"'),
PatternRule('eol', r'\n$'),
2007-08-04 16:16:30 -04:00
]
2009-03-20 15:41:56 -04:00
class ELisp(Lisp):
name = 'ELisp'
2007-10-18 17:07:35 -04:00
basenames = ['.emacs']
extensions = ['.el']
2007-08-04 16:16:30 -04:00
grammar = ELispGrammar
opentokens = ('delimiter',)
opentags = {'(': ')', '[': ']', '{': '}'}
closetokens = ('delimiter',)
closetags = {')': '(', ']': '[', '}': '{'}
2007-10-18 17:07:35 -04:00
colors = {
'elisp_reserved': ('blue', 'default', 'bold'),
'elisp_symbol': ('magenta', 'default', 'bold'),
'elisp_type': ('blue', 'default', 'bold'),
2009-03-20 15:41:56 -04:00
'elisp_word': ('default', 'default'),
2009-02-15 12:06:35 -05:00
}
2007-10-19 02:41:33 -04:00
install = ELisp.install