50 lines
2.2 KiB
Python
50 lines
2.2 KiB
Python
from mode import Fundamental
|
|
from point import Point
|
|
from lex import Grammar, PatternRule, RegionRule, OverridePatternRule
|
|
from mode.lisp import Lisp, LispTabber
|
|
|
|
class StringGrammar(Grammar):
|
|
rules = [
|
|
PatternRule(r'octal', r'\\[0-7]{3}'),
|
|
PatternRule(r'escaped', r'\\.'),
|
|
PatternRule(r'data', r'[^\\"]+'),
|
|
]
|
|
|
|
class ELispGrammar(Grammar):
|
|
rules = [
|
|
PatternRule(r'comment', r';.*$'),
|
|
PatternRule(r'delimiter', r'[()]'),
|
|
PatternRule(r'spaces', r' +'),
|
|
PatternRule(r'eol', r'\n'),
|
|
PatternRule(r'elisp_reserved', r'(?:t|nil)(?![^\"\' \t()])'),
|
|
PatternRule(r'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(r'elisp_symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"),
|
|
PatternRule(r'delimiter', r"'"),
|
|
PatternRule(r'elisp_type', r":[a-zA-Z_][a-zA-Z0-9-_]*"),
|
|
PatternRule(r'attribute', r"&[a-zA-Z_][a-zA-Z0-9-_]*"),
|
|
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_])"),
|
|
PatternRule(r'elisp_word', r"[^\"' \t()]+"),
|
|
RegionRule(r'string', r'"', StringGrammar, r'"'),
|
|
PatternRule(r'eol', r'\n$'),
|
|
]
|
|
|
|
class ELisp(Lisp):
|
|
name = 'ELisp'
|
|
basenames = ['.emacs']
|
|
extensions = ['.el']
|
|
grammar = ELispGrammar
|
|
opentokens = ('delimiter',)
|
|
opentags = {'(': ')', '[': ']', '{': '}'}
|
|
closetokens = ('delimiter',)
|
|
closetags = {')': '(', ']': '[', '}': '{'}
|
|
colors = {
|
|
'elisp_reserved': ('blue', 'default', 'bold'),
|
|
'elisp_symbol': ('magenta', 'default', 'bold'),
|
|
'elisp_type': ('blue', 'default', 'bold'),
|
|
'elisp_word': ('default', 'default'),
|
|
}
|
|
|
|
install = ELisp.install
|