Add support for Common Lisp

This commit is contained in:
Stephan Seitz 2021-04-04 09:45:45 +02:00 committed by Stephan Seitz
parent 89d464744b
commit e197736061
5 changed files with 198 additions and 7 deletions

View file

@ -54,6 +54,15 @@ list.clojure = {
maintainers = {"@sogaiu"},
}
list.commonlisp = {
install_info = {
url = "~/projects/tree-sitter-commonlisp",
files = { "src/parser.c" },
},
filetype = 'lisp',
maintainers = {"@theHamsta"},
}
list.cpp = {
install_info = {
url = "https://github.com/tree-sitter/tree-sitter-cpp",

View file

@ -18,13 +18,13 @@
(meta_lit
marker: "^" @punctuation.special)
;;; parameter-related
((sym_lit) @parameter
(#match? @parameter "^[&]"))
;; dynamic variables
((sym_lit) @variable.builtin
(#match? @variable.builtin "^\\*.+\\*$"))
;; parameter-related
((sym_lit) @parameter
(#match? @parameter "^&.*$"))
(#match? @variable.builtin "^[*].+[*]$"))
;; gensym
((sym_lit) @variable
@ -44,8 +44,8 @@
(sym_lit) @function.macro
(#match? @function.macro "^(\\.|\\.\\.|\\->|\\->>|amap|and|areduce|as\\->|assert|binding|bound\\-fn|case|catch|comment|cond|cond\\->|cond\\->>|condp|delay|do|doseq|dosync|dotimes|doto|extend-protocol|extend-type|finally|fn|fn\\*|for|future|gen-class|gen-interface|if|if\\-let|if\\-not|if\\-some|import|io!|lazy\\-cat|lazy\\-seq|let|letfn|locking|loop|memfn|monitor\\-enter|monitor\\-exit|or|proxy|proxy-super|pvalues|quote|recur|refer\\-clojure|reify|set!|some\\->|some\\->>|sync|throw|time|try|unquote|unquote\\-splicing|var|vswap!|when|when\\-first|when\\-let|when\\-not|when\\-some|while|with\\-bindings|with\\-in\\-str|with\\-loading\\-context|with\\-local\\-vars|with\\-open|with\\-out\\-str|with\\-precision|with\\-redefs)$"))
;; clojure.core=> (cp/pprint (sort (keep (fn [[s v]] (when-not (:macro (meta v)) s)) (ns-publics *ns*))))
;; ...and then some manual filtering...
;;; clojure.core=> (cp/pprint (sort (keep (fn [[s v]] (when-not (:macro (meta v)) s)) (ns-publics *ns*))))
;;; ...and then some manual filtering...
(list_lit
.
(sym_lit) @function.builtin

View file

@ -0,0 +1 @@
(source (list_lit) @fold)

View file

@ -0,0 +1,133 @@
(dis_expr) @comment
(defun_keyword) @function.macro
(defun_header
function_name: (_) @function)
(defun_header
lambda_list: (list_lit (sym_lit) @parameter))
(defun_header
keyword: (defun_keyword "defmethod")
lambda_list: (list_lit (list_lit . (sym_lit) . (sym_lit) @type)))
(defun_header
lambda_list: (list_lit (list_lit . (sym_lit) @parameter . (_))))
[
(accumulation_verb)
"for"
"and"
"finally"
"thereis"
"always"
"when"
"if"
"unless"
"do"
"loop"
"below"
"in"
"from"
"across"
"being"
"into"
"with"
"as"
"while"
] @function.macro
"=" @operator
(include_reader_macro) @type
"#C" @number
(kwd_lit) @type
(str_lit) @string
(num_lit) @number
((sym_lit) @boolean (#eq? @boolean "t"))
(nil_lit) @constant.builtin
(comment) @comment
;; metadata experiment
(meta_lit
marker: "^" @punctuation.special)
;; dynamic variables
((sym_lit) @variable.builtin
(#match? @variable.builtin "^[*].+[*]$"))
;; gensym
((sym_lit) @variable
(#match? @variable "^.*#$"))
;; interop-ish
(list_lit
.
(sym_lit) @method
(#match? @method "^\\."))
;; other symbols with dots
((sym_lit) @variable
(#match? @variable "\\."))
;; quote
"'" @string.escape
(quoting_lit) @string.escape
;; syntax quote
"`" @string.escape
"," @string.escape
",@" @string.escape
(syn_quoting_lit) @string.escape
(unquoting_lit) @none
(unquote_splicing_lit) @none
["(" ")"] @punctuation.bracket
(block_comment) @comment
;; defun-like things
(list_lit
.
(sym_lit) @function.macro
.
(sym_lit) @function
(#eq? @function.macro "deftest"))
;; Macros
(list_lit
.
(sym_lit) @function.macro
(#match? @function.macro "^(let|progn|prog1|values|error|or|and|defvar|defparameter|loop|in-package|defpackage|[e]?(type)?case|defclass|if|if-let|when-let|when|unless|cond|switch|declaim|optimize)[*]?$"))
;; constant
((sym_lit) @constant
(#match? @constant "^[+].+[+]$"))
(var_quoting_lit
marker: "#'" @type
value: (_) @type)
"#" @type
;;; clojure.core=> (cp/pprint (sort (keep (fn [[s v]] (when-not (:macro (meta v)) s)) (ns-publics *ns*))))
;;; ...and then some manual filtering...
(list_lit
.
(sym_lit) @function.builtin
(#match? @function.builtin "^(mapcar|reduce|remove-if-not|cons|car|last|nth|equal[p]?|cdr|first|rest|decf|incf|format)$"))
(list_lit
.
(sym_lit) @operator
(#match? @operator "^([+*-+=<>]|<=|>=|/=)$"))
((sym_lit) @type
(#match? @type "^[&]"))
[(array_dimension) "#0A"] @number

View file

@ -0,0 +1,48 @@
(defun_header
function_name: (sym_lit) @definition.function (#set! definition.function.scope "parent"))
(defun_header
lambda_list: (list_lit (sym_lit) @definition.parameter))
(defun_header
keyword: (defun_keyword "defmethod")
lambda_list: (list_lit (list_lit . (sym_lit) . (sym_lit) @definition.type)))
(defun_header
lambda_list: (list_lit (list_lit . (sym_lit) @definition.parameter . (_))))
(sym_lit) @reference
(defun) @scope
((list_lit . (sym_lit) @_defvar . (sym_lit) @definition.var)
(#match? @_defvar "^(cl:)?(defvar|defparameter)$"))
(list_lit
.
(sym_lit) @_deftest
.
(sym_lit) @definition.function
(#match? @_deftest "^(deftest)$")) @scope
(list_lit
.
(sym_lit) @_deftest
.
(sym_lit) @definition.function
(#match? @_deftest "^(deftest)$")) @scope
(for_clause . (sym_lit) @definition.var)
(with_clause . (sym_lit) @definition.var)
(loop_macro) @scope
(list_lit
.
(sym_lit) @_let (#match? @_let "(cl:|cffi:)?(with-accessors|with-foreign-objects|let[*]?)")
.
(list_lit (list_lit . (sym_lit) @definition.var))) @scope
(list_lit
.
(sym_lit) @_let (#match? @_let "(cl:|alexandria)?(with-gensyms|dotimes|with-foreign-object)")
.
(list_lit . (sym_lit) @definition.var)) @scope