-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Bass grammar and queries #6547
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
(list) | ||
(scope) | ||
(cons) | ||
] @fold |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,75 +1,58 @@ | ||||||
; GENERATED VIA https://github.com/vito/tree-sitter-bass | ||||||
;; Includes | ||||||
|
||||||
;;; comments | ||||||
((symbol) @keyword.control.import | ||||||
(#match? @keyword.control.import "^(use|import|load)$")) | ||||||
|
||||||
(comment) @comment.line | ||||||
;; Keywords | ||||||
|
||||||
;;; punctuation | ||||||
((symbol) @keyword | ||||||
(#match? @keyword "^(do|doc)$")) | ||||||
|
||||||
["(" ")" "[" "]" "{" "}"] @punctuation.bracket | ||||||
|
||||||
;;; constants | ||||||
|
||||||
[(ignore) (null)] @constant.builtin | ||||||
|
||||||
(bool) @constant.builtin.boolean | ||||||
|
||||||
(int) @constant.numeric.integer | ||||||
|
||||||
;;; strings | ||||||
|
||||||
;; string literals | ||||||
|
||||||
(string) @string | ||||||
(string (string_escape) @constant.character.escape) | ||||||
|
||||||
;; keywords (symbol literals) | ||||||
; Keywords construct a symbol | ||||||
|
||||||
(keyword) @string.special.symbol | ||||||
|
||||||
;; paths | ||||||
;; Operators | ||||||
|
||||||
(dot) @string.special.path | ||||||
(dotdot) @string.special.path | ||||||
(command) @string.special.path | ||||||
(subpath (symbol) @string.special.path) | ||||||
; TODO: classify | ||||||
((symbol) @operator (#match? @operator "^(&|\\*|\\+|-|<|<=|=|>|>=)$")) | ||||||
|
||||||
; slashes in a path denote a combiner call | ||||||
(subpath (slash) @function) | ||||||
;; Defining | ||||||
|
||||||
((list | ||||||
. (symbol) @label | ||||||
. (symbol) @function | ||||||
(symbol)? @parameter) | ||||||
(#match? @label "^(def|defop|defn)$")) | ||||||
|
||||||
((cons | ||||||
. (symbol) @label | ||||||
. (symbol) @function | ||||||
(symbol)? @parameter) | ||||||
(#match? @label "^(def|defop|defn)$")) | ||||||
|
||||||
;;; specific highlighting for builtins & special forms | ||||||
((symbol) @label | ||||||
(#match? @label "^(def|defop|defn)$")) | ||||||
|
||||||
;; symbol classification based highlighting | ||||||
;; Builtins | ||||||
|
||||||
(list . (symbol) @keyword.control.conditional (#match? @keyword.control.conditional "^(if|case|cond|when)$")) | ||||||
(cons . (symbol) @keyword.control.conditional (#match? @keyword.control.conditional "^(if|case|cond|when)$")) | ||||||
((symbol) @function.builtin | ||||||
(#match? @function.builtin "^(dump|mkfs|json|log|error|now|cons|wrap|unwrap|eval|make-scope|bind|meta|with-meta|null\\?|ignore\\?|boolean\\?|number\\?|string\\?|symbol\\?|scope\\?|sink\\?|source\\?|list\\?|pair\\?|applicative\\?|operative\\?|combiner\\?|path\\?|empty\\?|thunk\\?|\\+|\\*|quot|-|max|min|=|>|>=|<|<=|list->source|across|emit|next|reduce-kv|assoc|symbol->string|string->symbol|str|substring|trim|scope->list|string->fs-path|string->cmd-path|string->dir|subpath|path-name|path-stem|with-image|with-dir|with-cmd|with-args|with-entrypoint|with-default-args|with-entrypoint-args|with-stdin|with-env|with-insecure|with-label|with-port|with-tls|with-mount|thunk-cmd|thunk-args|resolve|start|addr|wait|read|cache-dir|binds\\?|write|publish|export|only-globs|except-globs|recall-memo|store-memo|mask|list|list\\*|first|rest|length|second|third|map|map-pairs|foldr|foldl|concat|append|filter|conj|list->scope|merge|apply|id|always|vals|keys|memo|succeeds\\?|run|last|take|collect|take-all|insecure!|from|cd|wrap-cmd|docker-build|oci-load|mkfile|path-base|not)$")) | ||||||
|
||||||
(list . (symbol) @keyword.control.repeat (#match? @keyword.control.repeat "^(each)$")) | ||||||
(cons . (symbol) @keyword.control.repeat (#match? @keyword.control.repeat "^(each)$")) | ||||||
((symbol) @function.macro | ||||||
(#match? @function.macro "^(op|fn|current-scope|quote|let|provide|module|or|and|->|curryfn|assert|refute|for|\\$|\\$\\$|linux|glob)$")) | ||||||
|
||||||
(list . (symbol) @label (#match? @label "^(def|defop|defn)$")) | ||||||
(cons . (symbol) @label (#match? @label "^(def|defop|defn)$")) | ||||||
;; Conditionals | ||||||
|
||||||
(list . (symbol) @function.builtin (#match? @function.builtin "^(dump|mkfs|json|log|error|now|cons|wrap|unwrap|eval|make-scope|bind|meta|with-meta|null\\?|ignore\\?|boolean\\?|number\\?|string\\?|symbol\\?|scope\\?|sink\\?|source\\?|list\\?|pair\\?|applicative\\?|operative\\?|combiner\\?|path\\?|empty\\?|thunk\\?|\\+|\\*|quot|-|max|min|=|>|>=|<|<=|list->source|across|emit|next|reduce-kv|assoc|symbol->string|string->symbol|str|substring|trim|scope->list|string->fs-path|string->cmd-path|string->dir|subpath|path-name|path-stem|with-image|with-dir|with-args|with-cmd|with-stdin|with-env|with-insecure|with-label|with-port|with-tls|with-mount|thunk-cmd|thunk-args|resolve|start|addr|wait|read|cache-dir|binds\\?|recall-memo|store-memo|mask|list|list\\*|first|rest|length|second|third|map|map-pairs|foldr|foldl|append|filter|conj|list->scope|merge|apply|id|always|vals|keys|memo|succeeds\\?|run|last|take|take-all|insecure!|from|cd|wrap-cmd|mkfile|path-base|not)$")) | ||||||
(cons . (symbol) @function.builtin (#match? @function.builtin "^(dump|mkfs|json|log|error|now|cons|wrap|unwrap|eval|make-scope|bind|meta|with-meta|null\\?|ignore\\?|boolean\\?|number\\?|string\\?|symbol\\?|scope\\?|sink\\?|source\\?|list\\?|pair\\?|applicative\\?|operative\\?|combiner\\?|path\\?|empty\\?|thunk\\?|\\+|\\*|quot|-|max|min|=|>|>=|<|<=|list->source|across|emit|next|reduce-kv|assoc|symbol->string|string->symbol|str|substring|trim|scope->list|string->fs-path|string->cmd-path|string->dir|subpath|path-name|path-stem|with-image|with-dir|with-args|with-cmd|with-stdin|with-env|with-insecure|with-label|with-port|with-tls|with-mount|thunk-cmd|thunk-args|resolve|start|addr|wait|read|cache-dir|binds\\?|recall-memo|store-memo|mask|list|list\\*|first|rest|length|second|third|map|map-pairs|foldr|foldl|append|filter|conj|list->scope|merge|apply|id|always|vals|keys|memo|succeeds\\?|run|last|take|take-all|insecure!|from|cd|wrap-cmd|mkfile|path-base|not)$")) | ||||||
((symbol) @keyword.control.conditional | ||||||
(#match? @keyword.control.conditional "^(if|case|cond|when)$")) | ||||||
|
||||||
(list . (symbol) @function.macro (#match? @function.macro "^(op|fn|current-scope|quote|let|provide|module|or|and|->|curryfn|for|\\$|linux)$")) | ||||||
(cons . (symbol) @function.macro (#match? @function.macro "^(op|fn|current-scope|quote|let|provide|module|or|and|->|curryfn|for|\\$|linux)$")) | ||||||
;; Repeats | ||||||
|
||||||
(list . (symbol) @keyword.builtin (#match? @keyword.builtin "^(do|doc)$")) | ||||||
(cons . (symbol) @keyword.builtin (#match? @keyword.builtin "^(do|doc)$")) | ||||||
((symbol) @keyword.control.repeat | ||||||
(#match? @keyword.control.repeat "^(each)$")) | ||||||
|
||||||
(list . (symbol) @keyword.control.import (#match? @keyword.control.import "^(use|import|load)$")) | ||||||
(cons . (symbol) @keyword.control.import (#match? @keyword.control.import "^(use|import|load)$")) | ||||||
|
||||||
|
||||||
;; special cases | ||||||
|
||||||
; [a & b] highlights & as operator rather than a regular symbol | ||||||
(list (symbol) @operator (#match? @operator "&")) | ||||||
(cons (symbol) @operator (#match? @operator "&")) | ||||||
;; Special forms | ||||||
|
||||||
; (-> x y z) highlights first x as var, y z as function | ||||||
(list | ||||||
|
@@ -89,13 +72,60 @@ | |||||
(_) | ||||||
(symbol) @function) | ||||||
|
||||||
;;; generic highlighting for all forms | ||||||
;; Functions | ||||||
|
||||||
(list | ||||||
. (symbol) @function) | ||||||
|
||||||
; first symbol in a list form is a combiner call | ||||||
(list . (symbol) @function) | ||||||
;; Variables | ||||||
|
||||||
(list (symbol) @variable) | ||||||
|
||||||
; highlight symbols as vars only when they're clearly vars | ||||||
(cons (symbol) @variable) | ||||||
|
||||||
(scope (symbol) @variable) | ||||||
(path form: (symbol) @variable) | ||||||
(symbind form: (symbol) @variable) | ||||||
|
||||||
(symbind (symbol) @variable) | ||||||
|
||||||
;; Namespaces | ||||||
|
||||||
(symbind | ||||||
(symbol) @namespace | ||||||
. (keyword)) | ||||||
|
||||||
;; Punctuation | ||||||
|
||||||
[ "(" ")" ] @punctuation.bracket | ||||||
|
||||||
[ "{" "}" ] @punctuation.bracket | ||||||
|
||||||
[ "[" "]" ] @punctuation.bracket | ||||||
|
||||||
((symbol) @punctuation.delimiter | ||||||
(#eq? @punctuation.delimiter "->")) | ||||||
|
||||||
;; Literals | ||||||
|
||||||
(string) @string | ||||||
|
||||||
(escape_sequence) @constant.character.escape | ||||||
|
||||||
(path) @string.special.path | ||||||
(command) @string.special.path | ||||||
|
||||||
(number) @constant.numeric.integer | ||||||
|
||||||
(boolean) @constant.builtin.boolean | ||||||
|
||||||
[ | ||||||
(ignore) | ||||||
(null) | ||||||
] @constant.builtin | ||||||
|
||||||
[ | ||||||
"^" | ||||||
] @character.special | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
;; Comments | ||||||
|
||||||
(comment) @comment.line @spell | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like these are in the neovim format. We use different captures for indentation queries: https://docs.helix-editor.com/master/guides/indent.html |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
[ | ||
(list) | ||
(scope) | ||
(cons) | ||
] @indent | ||
|
||
[ | ||
")" | ||
"}" | ||
"]" | ||
] @indent_end | ||
|
||
[ "(" ")" ] @branch | ||
|
||
[ "{" "}" ] @branch | ||
|
||
[ "[" "]" ] @branch | ||
|
||
[ | ||
(ERROR) | ||
(comment) | ||
] @auto |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1 @@ | ||||||||
(comment) @comment | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar here about injections
Suggested change
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We follow tree-sitter for locals captures but these are in nvim's format. See https://tree-sitter.github.io/tree-sitter/syntax-highlighting#local-variables
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
; Scopes | ||
|
||
[ | ||
(list) | ||
(scope) | ||
] @scope | ||
|
||
; References | ||
|
||
(symbol) @reference | ||
|
||
; Definitions | ||
|
||
((list | ||
. (symbol) @_fnkw | ||
. (symbol) @definition.function | ||
(symbol)? @definition.parameter) | ||
(#match? @_fnkw "^(def|defop|defn)$")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
number
capture integers and floats?@constant.numeric
would be more appropriate if it is both but the current capture is good if it's just integers