Skip to content

Commit 5e7a25f

Browse files
author
jneen
committed
use the keywords api for common lisp
1 parent 4a3afd9 commit 5e7a25f

File tree

2 files changed

+212
-215
lines changed

2 files changed

+212
-215
lines changed

lib/rouge/lexers/common_lisp.rb

Lines changed: 10 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -12,202 +12,7 @@ class CommonLisp < RegexLexer
1212
filenames '*.cl', '*.lisp', '*.asd', '*.el' # used for Elisp too
1313
mimetypes 'text/x-common-lisp'
1414

15-
# 638 functions
16-
BUILTIN_FUNCTIONS = Set.new %w(
17-
< <= = > >= - / /= * + 1- 1+ abort abs acons acos acosh add-method
18-
adjoin adjustable-array-p adjust-array allocate-instance
19-
alpha-char-p alphanumericp append apply apropos apropos-list
20-
aref arithmetic-error-operands arithmetic-error-operation
21-
array-dimension array-dimensions array-displacement
22-
array-element-type array-has-fill-pointer-p array-in-bounds-p
23-
arrayp array-rank array-row-major-index array-total-size
24-
ash asin asinh assoc assoc-if assoc-if-not atan atanh atom
25-
bit bit-and bit-andc1 bit-andc2 bit-eqv bit-ior bit-nand
26-
bit-nor bit-not bit-orc1 bit-orc2 bit-vector-p bit-xor boole
27-
both-case-p boundp break broadcast-stream-streams butlast
28-
byte byte-position byte-size caaaar caaadr caaar caadar
29-
caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr
30-
cadr call-next-method car cdaaar cdaadr cdaar cdadar cdaddr
31-
cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr cddr cdr
32-
ceiling cell-error-name cerror change-class char char< char<=
33-
char= char> char>= char/= character characterp char-code
34-
char-downcase char-equal char-greaterp char-int char-lessp
35-
char-name char-not-equal char-not-greaterp char-not-lessp
36-
char-upcase cis class-name class-of clear-input clear-output
37-
close clrhash code-char coerce compile compiled-function-p
38-
compile-file compile-file-pathname compiler-macro-function
39-
complement complex complexp compute-applicable-methods
40-
compute-restarts concatenate concatenated-stream-streams conjugate
41-
cons consp constantly constantp continue copy-alist copy-list
42-
copy-pprint-dispatch copy-readtable copy-seq copy-structure
43-
copy-symbol copy-tree cos cosh count count-if count-if-not
44-
decode-float decode-universal-time delete delete-duplicates
45-
delete-file delete-if delete-if-not delete-package denominator
46-
deposit-field describe describe-object digit-char digit-char-p
47-
directory directory-namestring disassemble documentation dpb
48-
dribble echo-stream-input-stream echo-stream-output-stream
49-
ed eighth elt encode-universal-time endp enough-namestring
50-
ensure-directories-exist ensure-generic-function eq
51-
eql equal equalp error eval evenp every exp export expt
52-
fboundp fceiling fdefinition ffloor fifth file-author
53-
file-error-pathname file-length file-namestring file-position
54-
file-string-length file-write-date fill fill-pointer find
55-
find-all-symbols find-class find-if find-if-not find-method
56-
find-package find-restart find-symbol finish-output first
57-
float float-digits floatp float-precision float-radix
58-
float-sign floor fmakunbound force-output format fourth
59-
fresh-line fround ftruncate funcall function-keywords
60-
function-lambda-expression functionp gcd gensym gentemp get
61-
get-decoded-time get-dispatch-macro-character getf gethash
62-
get-internal-real-time get-internal-run-time get-macro-character
63-
get-output-stream-string get-properties get-setf-expansion
64-
get-universal-time graphic-char-p hash-table-count hash-table-p
65-
hash-table-rehash-size hash-table-rehash-threshold
66-
hash-table-size hash-table-test host-namestring identity
67-
imagpart import initialize-instance input-stream-p inspect
68-
integer-decode-float integer-length integerp interactive-stream-p
69-
intern intersection invalid-method-error invoke-debugger
70-
invoke-restart invoke-restart-interactively isqrt keywordp
71-
last lcm ldb ldb-test ldiff length lisp-implementation-type
72-
lisp-implementation-version list list* list-all-packages listen
73-
list-length listp load load-logical-pathname-translations
74-
log logand logandc1 logandc2 logbitp logcount logeqv
75-
logical-pathname logical-pathname-translations logior
76-
lognand lognor lognot logorc1 logorc2 logtest logxor
77-
long-site-name lower-case-p machine-instance machine-type
78-
machine-version macroexpand macroexpand-1 macro-function
79-
make-array make-broadcast-stream make-concatenated-stream
80-
make-condition make-dispatch-macro-character make-echo-stream
81-
make-hash-table make-instance make-instances-obsolete make-list
82-
make-load-form make-load-form-saving-slots make-package
83-
make-pathname make-random-state make-sequence make-string
84-
make-string-input-stream make-string-output-stream make-symbol
85-
make-synonym-stream make-two-way-stream makunbound map mapc
86-
mapcan mapcar mapcon maphash map-into mapl maplist mask-field
87-
max member member-if member-if-not merge merge-pathnames
88-
method-combination-error method-qualifiers min minusp mismatch mod
89-
muffle-warning name-char namestring nbutlast nconc next-method-p
90-
nintersection ninth no-applicable-method no-next-method not notany
91-
notevery nreconc nreverse nset-difference nset-exclusive-or
92-
nstring-capitalize nstring-downcase nstring-upcase nsublis
93-
nsubst nsubst-if nsubst-if-not nsubstitute nsubstitute-if
94-
nsubstitute-if-not nth nthcdr null numberp numerator nunion
95-
oddp open open-stream-p output-stream-p package-error-package
96-
package-name package-nicknames packagep package-shadowing-symbols
97-
package-used-by-list package-use-list pairlis parse-integer
98-
parse-namestring pathname pathname-device pathname-directory
99-
pathname-host pathname-match-p pathname-name pathnamep
100-
pathname-type pathname-version peek-char phase plusp
101-
position position-if position-if-not pprint pprint-dispatch
102-
pprint-fill pprint-indent pprint-linear pprint-newline pprint-tab
103-
pprint-tabular prin1 prin1-to-string princ princ-to-string print
104-
print-object probe-file proclaim provide random random-state-p
105-
rassoc rassoc-if rassoc-if-not rational rationalize rationalp
106-
read read-byte read-char read-char-no-hang read-delimited-list
107-
read-from-string read-line read-preserving-whitespace
108-
read-sequence readtable-case readtablep realp realpart
109-
reduce reinitialize-instance rem remhash remove
110-
remove-duplicates remove-if remove-if-not remove-method
111-
remprop rename-file rename-package replace require rest
112-
restart-name revappend reverse room round row-major-aref
113-
rplaca rplacd sbit scale-float schar search second set
114-
set-difference set-dispatch-macro-character set-exclusive-or
115-
set-macro-character set-pprint-dispatch set-syntax-from-char
116-
seventh shadow shadowing-import shared-initialize
117-
short-site-name signal signum simple-bit-vector-p
118-
simple-condition-format-arguments simple-condition-format-control
119-
simple-string-p simple-vector-p sin sinh sixth sleep slot-boundp
120-
slot-exists-p slot-makunbound slot-missing slot-unbound slot-value
121-
software-type software-version some sort special-operator-p
122-
sqrt stable-sort standard-char-p store-value stream-element-type
123-
stream-error-stream stream-external-format streamp string string<
124-
string<= string= string> string>= string/= string-capitalize
125-
string-downcase string-equal string-greaterp string-left-trim
126-
string-lessp string-not-equal string-not-greaterp string-not-lessp
127-
stringp string-right-trim string-trim string-upcase sublis subseq
128-
subsetp subst subst-if subst-if-not substitute substitute-if
129-
substitute-if-not subtypepsvref sxhash symbol-function
130-
symbol-name symbolp symbol-package symbol-plist symbol-value
131-
synonym-stream-symbol syntax: tailp tan tanh tenth terpri third
132-
translate-logical-pathname translate-pathname tree-equal truename
133-
truncate two-way-stream-input-stream two-way-stream-output-stream
134-
type-error-datum type-error-expected-type type-of
135-
typep unbound-slot-instance unexport unintern union
136-
unread-char unuse-package update-instance-for-different-class
137-
update-instance-for-redefined-class upgraded-array-element-type
138-
upgraded-complex-part-type upper-case-p use-package
139-
user-homedir-pathname use-value values values-list vector vectorp
140-
vector-pop vector-push vector-push-extend warn wild-pathname-p
141-
write write-byte write-char write-line write-sequence write-string
142-
write-to-string yes-or-no-p y-or-n-p zerop
143-
).freeze
144-
145-
SPECIAL_FORMS = Set.new %w(
146-
block catch declare eval-when flet function go if labels lambda
147-
let let* load-time-value locally macrolet multiple-value-call
148-
multiple-value-prog1 progn progv quote return-from setq
149-
symbol-macrolet tagbody the throw unwind-protect
150-
)
151-
152-
MACROS = Set.new %w(
153-
and assert call-method case ccase check-type cond ctypecase decf
154-
declaim defclass defconstant defgeneric define-compiler-macro
155-
define-condition define-method-combination define-modify-macro
156-
define-setf-expander define-symbol-macro defmacro defmethod
157-
defpackage defparameter defsetf defstruct defsystem deftype defun defvar
158-
destructuring-bind do do* do-all-symbols do-external-symbols
159-
dolist do-symbols dotimes ecase etypecase formatter
160-
handler-bind handler-case ignore-errors incf in-package
161-
lambda loop loop-finish make-method multiple-value-bind
162-
multiple-value-list multiple-value-setq nth-value or pop
163-
pprint-exit-if-list-exhausted pprint-logical-block pprint-pop
164-
print-unreadable-object prog prog* prog1 prog2 psetf psetq
165-
push pushnew remf restart-bind restart-case return rotatef
166-
setf shiftf step time trace typecase unless untrace when
167-
with-accessors with-compilation-unit with-condition-restarts
168-
with-hash-table-iterator with-input-from-string with-open-file
169-
with-open-stream with-output-to-string with-package-iterator
170-
with-simple-restart with-slots with-standard-io-syntax
171-
)
172-
173-
LAMBDA_LIST_KEYWORDS = Set.new %w(
174-
&allow-other-keys &aux &body &environment &key &optional &rest
175-
&whole
176-
)
177-
178-
DECLARATIONS = Set.new %w(
179-
dynamic-extent ignore optimize ftype inline special ignorable
180-
notinline type
181-
)
182-
183-
BUILTIN_TYPES = Set.new %w(
184-
atom boolean base-char base-string bignum bit compiled-function
185-
extended-char fixnum keyword nil signed-byte short-float
186-
single-float double-float long-float simple-array
187-
simple-base-string simple-bit-vector simple-string simple-vector
188-
standard-char unsigned-byte
189-
190-
arithmetic-error cell-error condition control-error
191-
division-by-zero end-of-file error file-error
192-
floating-point-inexact floating-point-overflow
193-
floating-point-underflow floating-point-invalid-operation
194-
parse-error package-error print-not-readable program-error
195-
reader-error serious-condition simple-condition simple-error
196-
simple-type-error simple-warning stream-error storage-condition
197-
style-warning type-error unbound-variable unbound-slot
198-
undefined-function warning
199-
)
200-
201-
BUILTIN_CLASSES = Set.new %w(
202-
array broadcast-stream bit-vector built-in-class character
203-
class complex concatenated-stream cons echo-stream file-stream
204-
float function generic-function hash-table integer list
205-
logical-pathname method-combination method null number package
206-
pathname ratio rational readtable real random-state restart
207-
sequence standard-class standard-generic-function standard-method
208-
standard-object string-stream stream string structure-class
209-
structure-object symbol synonym-stream t two-way-stream vector
210-
)
15+
lazy { require_relative 'common_lisp/builtins' }
21116

21217
nonmacro = /\\.|[a-zA-Z0-9!$%&*+-\/<=>?@\[\]^_{}~]/
21318
constituent = /#{nonmacro}|[#.:]/
@@ -296,26 +101,16 @@ class complex concatenated-stream cons echo-stream file-stream
296101
# functions and variables
297102
# note that these get filtered through in stream_tokens
298103
rule %r/\*#{symbol}\*/, Name::Variable::Global
299-
rule symbol do |m|
300-
sym = m[0]
301104

302-
if BUILTIN_FUNCTIONS.include? sym
303-
token Name::Builtin
304-
elsif SPECIAL_FORMS.include? sym
305-
token Keyword
306-
elsif MACROS.include? sym
307-
token Name::Builtin
308-
elsif LAMBDA_LIST_KEYWORDS.include? sym
309-
token Keyword
310-
elsif DECLARATIONS.include? sym
311-
token Keyword
312-
elsif BUILTIN_TYPES.include? sym
313-
token Keyword::Type
314-
elsif BUILTIN_CLASSES.include? sym
315-
token Name::Class
316-
else
317-
token Name::Variable
318-
end
105+
keywords symbol do
106+
rule BUILTIN_FUNCTIONS, Name::Builtin
107+
rule SPECIAL_FORMS, Keyword
108+
rule MACROS, Name::Builtin
109+
rule LAMBDA_LIST_KEYWORDS, Keyword
110+
rule DECLARATIONS, Keyword
111+
rule BUILTIN_TYPES, Keyword
112+
rule BUILTIN_CLASSES, Keyword
113+
default Name
319114
end
320115

321116
rule %r/\(/, Punctuation, :root

0 commit comments

Comments
 (0)