1 -- Copyright 2006-2016 Mitchell mitchell.att.foicica.com. See LICENSE.
4 local l
= require('lexer')
5 local token
, word_match
= l
.token
, l
.word_match
6 local P
, R
, S
= lpeg
.P
, lpeg
.R
, lpeg
.S
8 local M
= {_NAME
= 'lisp'}
11 local ws
= token(l
.WHITESPACE
, l
.space^
1)
14 local line_comment
= ';' * l
.nonnewline^
0
15 local block_comment
= '#|' * (l
.any
- '|#')^
0 * P('|#')^
-1
16 local comment
= token(l
.COMMENT
, line_comment
+ block_comment
)
18 local word
= l
.alpha
* (l
.alnum
+ '_' + '-')^
0
21 local literal
= "'" * word
22 local dq_str
= l
.delimited_range('"')
23 local string = token(l
.STRING
, literal
+ dq_str
)
26 local number = token(l
.NUMBER
, P('-')^
-1 * l
.digit^
1 * (S('./') * l
.digit^
1)^
-1)
29 local keyword
= token(l
.KEYWORD
, word_match({
30 'defclass', 'defconstant', 'defgeneric', 'define-compiler-macro',
31 'define-condition', 'define-method-combination', 'define-modify-macro',
32 'define-setf-expander', 'define-symbol-macro', 'defmacro', 'defmethod',
33 'defpackage', 'defparameter', 'defsetf', 'defstruct', 'deftype', 'defun',
35 'abort', 'assert', 'block', 'break', 'case', 'catch', 'ccase', 'cerror',
36 'cond', 'ctypecase', 'declaim', 'declare', 'do', 'do*', 'do-all-symbols',
37 'do-external-symbols', 'do-symbols', 'dolist', 'dotimes', 'ecase', 'error',
38 'etypecase', 'eval-when', 'flet', 'handler-bind', 'handler-case', 'if',
39 'ignore-errors', 'in-package', 'labels', 'lambda', 'let', 'let*', 'locally',
40 'loop', 'macrolet', 'multiple-value-bind', 'proclaim', 'prog', 'prog*',
41 'prog1', 'prog2', 'progn', 'progv', 'provide', 'require', 'restart-bind',
42 'restart-case', 'restart-name', 'return', 'return-from', 'signal',
43 'symbol-macrolet', 'tagbody', 'the', 'throw', 'typecase', 'unless',
44 'unwind-protect', 'when', 'with-accessors', 'with-compilation-unit',
45 'with-condition-restarts', 'with-hash-table-iterator',
46 'with-input-from-string', 'with-open-file', 'with-open-stream',
47 'with-output-to-string', 'with-package-iterator', 'with-simple-restart',
48 'with-slots', 'with-standard-io-syntax',
53 local identifier
= token(l
.IDENTIFIER
, word
)
56 local operator
= token(l
.OPERATOR
, S('<>=*/+-`@%()'))
59 local entity
= token('entity', '&' * word
)
64 {'identifier', identifier
},
68 {'operator', operator
},
73 entity
= l
.STYLE_VARIABLE
77 _patterns
= {'[%(%)%[%]{}]', '#|', '|#', ';'},
79 ['('] = 1, [')'] = -1, ['['] = 1, [']'] = -1, ['{'] = 1, ['}'] = -1
81 [l
.COMMENT
] = {['#|'] = 1, ['|#'] = -1, [';'] = l
.fold_line_comments(';')}