pmacs3/mode/elisp.py

50 lines
2.2 KiB
Python
Raw 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 = [
PatternRule(r'octal', r'\\[0-7]{3}'),
PatternRule(r'escaped', r'\\.'),
2008-10-20 19:22:53 -04:00
PatternRule(r'data', r'[^\\"]+'),
2007-08-04 16:16:30 -04:00
]
class ELispGrammar(Grammar):
rules = [
PatternRule(r'comment', r';.*$'),
PatternRule(r'delimiter', r'[()]'),
2009-03-20 15:41:56 -04:00
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()])'),
2008-03-16 11:39:17 -04:00
PatternRule(r'elisp_symbol', r"'[a-zA-Z_][a-zA-Z0-9-_]*"),
2009-03-20 15:41:56 -04:00
PatternRule(r'delimiter', r"'"),
2008-03-16 11:39:17 -04:00
PatternRule(r'elisp_type', r":[a-zA-Z_][a-zA-Z0-9-_]*"),
2007-08-04 16:16:30 -04:00
PatternRule(r'attribute', r"&[a-zA-Z_][a-zA-Z0-9-_]*"),
2008-03-16 11:39:17 -04:00
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_])"),
2007-08-04 16:16:30 -04:00
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_])"),
2009-03-20 15:41:56 -04:00
PatternRule(r'elisp_word', r"[^\"' \t()]+"),
2007-08-04 16:16:30 -04:00
RegionRule(r'string', r'"', StringGrammar, r'"'),
PatternRule(r'eol', r'\n$'),
]
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