feat(fennel)!: switch to maintained parser (#6132)

Change the Fennel parser to a simpler and more consistent one, along with updating all the queries.
This commit is contained in:
Alexei Mozaidze 2024-02-21 17:44:01 +04:00 committed by GitHub
parent 71ae32c187
commit 7d1bab6546
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 398 additions and 107 deletions

View file

@ -1,3 +1,6 @@
; Most primitive nodes
(shebang) @keyword.directive
(comment) @comment @spell
[
@ -9,18 +12,8 @@
"]"
] @punctuation.bracket
[
":"
":until"
"&"
"&as"
"?"
] @punctuation.special
(nil) @constant.builtin
(vararg) @punctuation.special
(boolean) @boolean
(number) @number
@ -33,11 +26,7 @@
(multi_symbol
"." @punctuation.delimiter
(symbol) @variable.member)
(multi_symbol_method
":" @punctuation.delimiter
(symbol) @function.method.call .)
member: (symbol_fragment) @variable.member)
(list
.
@ -46,80 +35,218 @@
(list
.
(multi_symbol
(symbol) @function.call .))
member: (symbol_fragment) @function.call .))
((symbol) @variable.builtin
(#lua-match? @variable.builtin "^[$]"))
(multi_symbol_method
":" @punctuation.delimiter
method: (symbol_fragment) @function.method.call .)
(binding) @string.special.symbol
; Just `&` is only used in destructuring
((symbol) @punctuation.special
(#eq? @punctuation.special "&"))
[
"fn"
"lambda"
"hashfn"
"#"
] @keyword.function
; BUG: $ arguments should only be valid inside hashfn of any depth, but
; it's impossible to express such query at the moment of writing.
; See tree-sitter/tree-sitter#880
((symbol) @variable.parameter
(#eq? @variable.parameter "$..."))
(fn
name:
[
(symbol) @function
(multi_symbol
(symbol) @function .)
])
((symbol) @variable.parameter
(#lua-match? @variable.parameter "^%$[1-9]$"))
(lambda
name:
[
(symbol) @function
(multi_symbol
(symbol) @function .)
])
((symbol) @operator
; format-ignore
(#any-of? @operator
; arithmetic
"+" "-" "*" "/" "//" "%" "^"
; comparison
">" "<" ">=" "<=" "=" "~="
; other
"#" "." "?." ".."))
[
"for"
"each"
] @keyword.repeat
((symbol) @keyword.operator
; format-ignore
(#any-of? @keyword.operator
; comparison
"not="
; boolean
"and" "or" "not"
; bitwise
"lshift" "rshift" "band" "bor" "bxor" "bnot"
; other
"length"))
(reader_macro
macro: "#" @keyword.function)
((symbol) @keyword.function
(#any-of? @keyword.function "fn" "lambda" "λ" "hashfn"))
((symbol) @keyword.repeat
(#any-of? @keyword.repeat "while"))
"match" @keyword.conditional
(#any-of? @keyword.repeat "for" "each" "while"))
((symbol) @keyword.conditional
(#any-of? @keyword.conditional "if" "when"))
[
"global"
"local"
"let"
"set"
"var"
"where"
"or"
] @keyword
(#any-of? @keyword.conditional "if" "when" "match" "case"))
((symbol) @keyword
(#any-of? @keyword "comment" "do" "doc" "eval-compiler" "lua" "macros" "quote" "tset" "values"))
; format-ignore
(#any-of? @keyword
"global"
"local"
"let"
"set"
"var"
"comment"
"do"
"doc"
"eval-compiler"
"lua"
"macros"
"unquote"
"quote"
"tset"
"values"
"tail!"))
((symbol) @keyword.import
(#any-of? @keyword.import "require" "require-macros" "import-macros" "include"))
[
"collect"
"icollect"
"accumulate"
] @function.macro
((symbol) @function.macro
(#any-of? @function.macro "->" "->>" "-?>" "-?>>" "?." "doto" "macro" "macrodebug" "partial" "pick-args" "pick-values" "with-open"))
; format-ignore
(#any-of? @function.macro
"collect"
"icollect"
"fcollect"
"accumulate"
"faccumulate"
"->"
"->>"
"-?>"
"-?>>"
"?."
"doto"
"macro"
"macrodebug"
"partial"
"pick-args"
"pick-values"
"with-open"))
; TODO: Highlight builtin methods (`table.unpack`, etc) as @function.builtin
([
(symbol) @module.builtin
(multi_symbol
base: (symbol_fragment) @module.builtin)
]
(#any-of? @module.builtin "vim" "_G" "debug" "io" "jit" "math" "os" "package" "string" "table" "utf8"))
([
(symbol) @variable.builtin
(multi_symbol
.
(symbol_fragment) @variable.builtin)
]
(#eq? @variable.builtin "arg"))
((symbol) @variable.builtin
(#eq? @variable.builtin "..."))
; Lua builtins
((symbol) @constant.builtin
(#any-of? @constant.builtin "arg" "_ENV" "_G" "_VERSION"))
(#eq? @constant.builtin "_VERSION"))
((symbol) @function.builtin
(#any-of? @function.builtin "assert" "collectgarbage" "dofile" "error" "getmetatable" "ipairs" "load" "loadfile" "next" "pairs" "pcall" "print" "rawequal" "rawget" "rawlen" "rawset" "require" "select" "setmetatable" "tonumber" "tostring" "type" "warn" "xpcall"))
; format-ignore
(#any-of? @function.builtin
"assert"
"collectgarbage"
"dofile"
"error"
"getmetatable"
"ipairs"
"load"
"loadfile"
"next"
"pairs"
"pcall"
"print"
"rawequal"
"rawget"
"rawlen"
"rawset"
"require"
"select"
"setmetatable"
"tonumber"
"tostring"
"type"
"warn"
"xpcall"
"module"
"setfenv"
"loadstring"
"unpack"))
((symbol) @function.builtin
(#any-of? @function.builtin "loadstring" "module" "setfenv" "unpack"))
(table
(table_pair
key: (symbol) @keyword.directive
(#eq? @keyword.directive "&as")))
(list
.
(symbol) @keyword.function
(#any-of? @keyword.function "fn" "lambda" "λ")
.
[
(symbol) @function
(multi_symbol
(symbol_fragment) @function .)
]
.
(sequence
((symbol) @variable.parameter
(#not-any-of? @variable.parameter "&" "..."))))
(list
.
(symbol) @function.macro
(#any-of? @function.macro "collect" "icollect" "fcollect")
.
(sequence
[
(symbol)
(string)
] @keyword.directive
(#any-of? @keyword.directive "&into" ":into")))
(list
.
(symbol) @function.macro
(#any-of? @function.macro "for" "each" "collect" "icollect" "fcollect" "accumulate" "faccumulate")
.
(sequence
[
(symbol)
(string)
] @keyword.directive
(#any-of? @keyword.directive "&until" ":until")))
(list
.
(symbol) @keyword.conditional
(#any-of? @keyword.conditional "match" "case")
.
(_)
.
((list
.
(symbol) @keyword
(#eq? @keyword "where"))
.
(_))*
.
(list
.
(symbol) @keyword
(#eq? @keyword "where"))
.
(_)? .)