feat(fennel)!: update parser and queries (#6460)

This commit is contained in:
Alexei Mozaidze 2024-04-22 13:57:55 +04:00 committed by GitHub
parent 075b7594ca
commit 46f8778fbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 213 additions and 180 deletions

View file

@ -12,44 +12,97 @@
"]"
] @punctuation.bracket
(nil) @constant.builtin
[
(nil)
(nil_binding)
] @constant.builtin
(boolean) @boolean
[
(boolean)
(boolean_binding)
] @boolean
(number) @number
[
(number)
(number_binding)
] @number
(string) @string
[
(string)
(string_binding)
] @string
[
(symbol)
(symbol_binding)
] @variable
(symbol_option) @keyword.directive
(escape_sequence) @string.escape
(symbol) @variable
(multi_symbol
"." @punctuation.delimiter
member: (symbol_fragment) @variable.member)
(list
.
(symbol) @function.call)
call: (symbol) @function.call)
(list
.
(multi_symbol
call: (multi_symbol
member: (symbol_fragment) @function.call .))
(multi_symbol_method
":" @punctuation.delimiter
method: (symbol_fragment) @function.method.call .)
method: (symbol_fragment) @function.method.call)
; Just `&` is only used in destructuring
((symbol) @punctuation.special
(#eq? @punctuation.special "&"))
(quasi_quote_reader_macro
macro: _ @punctuation.special)
(quote_reader_macro
macro: _ @punctuation.special)
(unquote_reader_macro
macro: _ @punctuation.special)
(hashfn_reader_macro
macro: _ @keyword.function)
(sequence_arguments
(symbol_binding) @variable.parameter)
(sequence_arguments
(rest_binding
rhs: (symbol_binding) @variable.parameter))
(docstring) @string.documentation
(fn_form
name: [
(symbol) @function
(multi_symbol
member: (symbol_fragment) @function .)
])
(lambda_form
name: [
(symbol) @function
(multi_symbol
member: (symbol_fragment) @function .)
])
; NOTE: The macro name is highlighted as @variable because it
; gives a nicer contrast instead of everything being the same
; color. Rust queries use this workaround too for `macro_rules!`.
(macro_form
name: [
(symbol) @variable
(multi_symbol
member: (symbol_fragment) @variable .)
])
; 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 "$..."))
(#any-of? @variable.parameter "$" "$..."))
((symbol) @variable.parameter
(#lua-match? @variable.parameter "^%$[1-9]$"))
@ -74,8 +127,11 @@
; other
"length"))
(reader_macro
macro: "#" @keyword.function)
(case_guard
call: (_) @keyword.conditional)
(case_guard_or_special
call: (_) @keyword.conditional)
((symbol) @keyword.function
(#any-of? @keyword.function "fn" "lambda" "λ" "hashfn"))
@ -84,7 +140,7 @@
(#any-of? @keyword.repeat "for" "each" "while"))
((symbol) @keyword.conditional
(#any-of? @keyword.conditional "if" "when" "match" "case"))
(#any-of? @keyword.conditional "if" "when" "match" "case" "match-try" "case-try"))
((symbol) @keyword
(#any-of? @keyword
@ -92,13 +148,21 @@
"quote" "tset" "values" "tail!"))
((symbol) @keyword.import
(#any-of? @keyword.import "require" "require-macros" "import-macros" "include"))
(#any-of? @keyword.import "require-macros" "import-macros" "include"))
((symbol) @function.macro
(#any-of? @function.macro
"collect" "icollect" "fcollect" "accumulate" "faccumulate" "->" "->>" "-?>" "-?>>" "?." "doto"
"macro" "macrodebug" "partial" "pick-args" "pick-values" "with-open"))
(case_catch
call: (symbol) @keyword)
(import_macros_form
imports: (table_binding
(table_binding_pair
value: (symbol_binding) @function.macro)))
; TODO: Highlight builtin methods (`table.unpack`, etc) as @function.builtin
([
(symbol) @module.builtin
@ -127,68 +191,3 @@
"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"))
(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"))
.
(_)? .)