Skip to content

Tweaked tree-sitter query classification #7431

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -748,21 +748,23 @@ disambiguations:
pattern: '^#+\s+(NAME|SYNOPSIS|DESCRIPTION)'
- extensions: ['.scm']
rules:
- language: Scheme
pattern:
- '(?:''[\(\*#]|\w->\w|\.\.\.[\s\)]|\([+\-:<>\/=~\)]|~>|[#`]\(|#:\w)'
- '^\s*\((?:define\*?|import|library|lambda)'
negative_pattern:
- '\(#[\w-]+[!\?]'
- '[\)\]"_]\s*(?:[\*\+\?]|@\w)'
- language: Tree-sitter Query
pattern:
- '\(#[\w-]+[!\?]'
- '[\)\]"_]\s*(?:[\*\+\?]|@\w)'
- '(?:[\)\]]\s*[\*\+\?](?:\s|$))'
- '(?:^\s*\w+:\s*[\(\[\"])'
- '\(#(?:set!|(?:not-)?(?:any-of|match)\?)'
- '@[\w.-]+(?:\)\s|$)'
negative_pattern:
- '\([+\-:<>\/=~\)]'
- language: Scheme
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving TSQ above Scheme somehow increased classification hit-rate 🤷

pattern:
- '(?:''[\(\*#]|\w->\w|\.\.\.[\s\)]|\([+\-:<>\/=~\)]|~>|[#`]\(|#:\w)'
- '^\s*\((?:define\*?|import|library|lambda)'
negative_pattern:
- '\(#[\w-]+[!\?]'
- '(?:[\)\]]\s*[\*\+\?](?:\s|$))'
- '@[\w.-]+(?:\)\s|$)'
- extensions: ['.sol']
rules:
- language: Solidity
Expand Down
66 changes: 66 additions & 0 deletions samples/Tree-sitter Query/asm_highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
; General
(label
[
(ident)
(word)
] @label)

(reg) @variable.builtin

(meta
kind: (_) @function.builtin)

(instruction
kind: (_) @function.builtin)

(const
name: (word) @constant)

; Comments
[
(line_comment)
(block_comment)
] @comment @spell

; Literals
(int) @number

(float) @number.float

(string) @string

; Keywords
[
"byte"
"word"
"dword"
"qword"
"ptr"
"rel"
"label"
"const"
] @keyword

; Operators & Punctuation
[
"+"
"-"
"*"
"/"
"%"
"|"
"^"
"&"
] @operator

[
"("
")"
"["
"]"
] @punctuation.bracket

[
","
":"
] @punctuation.delimiter
5 changes: 5 additions & 0 deletions samples/Tree-sitter Query/asm_injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
([
(line_comment)
(block_comment)
] @injection.content
(#set! injection.language "comment"))
167 changes: 167 additions & 0 deletions samples/Tree-sitter Query/func_highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
; Include
"#include" @keyword.import

(include_path) @string

; Preproc
"#pragma" @keyword.directive

(pragma_directive
[
"version"
"not-version"
"test-version-set"
] @keyword.directive)

; Keywords
[
"asm"
"impure"
"inline"
"inline_ref"
"method_id"
"type"
] @keyword

"return" @keyword.return

; Conditionals
[
"if"
"ifnot"
"else"
"elseif"
"elseifnot"
"until"
] @keyword.conditional

; Exceptions
[
"try"
"catch"
] @keyword.exception

; Repeats
[
"do"
"forall"
"repeat"
"while"
] @keyword.repeat

; Qualifiers
[
"const"
"global"
(var)
] @keyword.modifier

; Variables
(identifier) @variable

; Constants
(const_var_declarations
name: (identifier) @constant)

; Functions/Methods
(function_definition
name: (function_name) @function)

(function_application
function: (identifier) @function)

(method_call
method_name: (identifier) @function.method.call)

; Parameters
(parameter) @variable.parameter

; Types
(type_identifier) @type

(primitive_type) @type.builtin

; Operators
[
"="
"+="
"-="
"*="
"/="
"~/="
"^/="
"%="
"~%="
"^%="
"<<="
">>="
"~>>="
"^>>="
"&="
"|="
"^="
"=="
"<"
">"
"<="
">="
"!="
"<=>"
"<<"
">>"
"~>>"
"^>>"
"-"
"+"
"|"
"^"
"*"
"/"
"%"
"~/"
"^/"
"~%"
"^%"
"/%"
"&"
"~"
] @operator

; Literals
[
(string)
(asm_instruction)
] @string

[
(string_type)
(underscore)
] @character.special

(number) @number

; Punctuation
[
"{"
"}"
] @punctuation.bracket

[
"("
")"
"()"
] @punctuation.bracket

[
"["
"]"
] @punctuation.bracket

[
";"
","
"->"
] @punctuation.delimiter

; Comments
(comment) @comment @spell
Loading