-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add Tree-sitter Query language #7243
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
Merged
lildude
merged 16 commits into
github-linguist:main
from
mkatychev:feat/tree-sitter-query
Mar 5, 2025
+477
−0
Merged
Changes from 4 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
84fef7a
added tree sitter query heuristics
mkatychev 7430ce5
added samples
mkatychev 9ed60cb
added test_heuristics case for scm
mkatychev c016e76
updated license
mkatychev 80419b9
partial cleanup of heuristic regex queries
mkatychev f7608c6
removed '\w heuristic match from scheme
mkatychev 91367fa
added vscode-tree-sitter-query license
mkatychev 546cc9c
added r6rs grammar
mkatychev fbfe049
tightened heuristics
mkatychev 740fcf0
rename scheme namespace -
mkatychev 15a6de3
added basic definitions
mkatychev 30362db
updated with r7rs repo implementation exmaples
mkatychev 38411c5
removed r6rs sample
mkatychev a12f29b
added aliases
mkatychev 87ebd80
removed redundant alias
mkatychev 8c36a6c
Update test_language.rb
mkatychev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ;; Variable bound to a number: | ||
| (define f 10) | ||
| f | ||
| ===> 10 | ||
| ;; Mutation (altering the bound value) | ||
| (set! f (+ f f 6)) | ||
| f | ||
| ===> 26 | ||
| ;; Assigning a procedure to the same variable: | ||
| (set! f (lambda (n) (+ n 12))) | ||
| (f 6) | ||
| ===> 18 | ||
| ;; Assigning the result of an expression to the same variable: | ||
| (set! f (f 1)) | ||
| f | ||
| ===> 13 | ||
| ;; functional programming: | ||
| (apply + '(1 2 3 4 5 6)) | ||
| ===> 21 | ||
| (set! f (lambda (n) (+ n 100))) | ||
| (map f '(1 2 3)) | ||
| ===> (101 102 103) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| ; Identifiers | ||
|
|
||
| (type_identifier) @type | ||
| (primitive_type) @type.builtin | ||
| (field_identifier) @property | ||
|
|
||
| ; Identifier conventions | ||
|
|
||
| ; Assume all-caps names are constants | ||
| ((identifier) @constant | ||
| (#match? @constant "^[A-Z][A-Z\\d_]+$'")) | ||
|
|
||
| ; Assume uppercase names are enum constructors | ||
| ((identifier) @constructor | ||
| (#match? @constructor "^[A-Z]")) | ||
|
|
||
| ; Assume that uppercase names in paths are types | ||
| ((scoped_identifier | ||
| path: (identifier) @type) | ||
| (#match? @type "^[A-Z]")) | ||
| ((scoped_identifier | ||
| path: (scoped_identifier | ||
| name: (identifier) @type)) | ||
| (#match? @type "^[A-Z]")) | ||
| ((scoped_type_identifier | ||
| path: (identifier) @type) | ||
| (#match? @type "^[A-Z]")) | ||
| ((scoped_type_identifier | ||
| path: (scoped_identifier | ||
| name: (identifier) @type)) | ||
| (#match? @type "^[A-Z]")) | ||
|
|
||
| ; Assume all qualified names in struct patterns are enum constructors. (They're | ||
| ; either that, or struct names; highlighting both as constructors seems to be | ||
| ; the less glaring choice of error, visually.) | ||
| (struct_pattern | ||
| type: (scoped_type_identifier | ||
| name: (type_identifier) @constructor)) | ||
|
|
||
| ; Function calls | ||
|
|
||
| (call_expression | ||
| function: (identifier) @function) | ||
| (call_expression | ||
| function: (field_expression | ||
| field: (field_identifier) @function.method)) | ||
| (call_expression | ||
| function: (scoped_identifier | ||
| "::" | ||
| name: (identifier) @function)) | ||
|
|
||
| (generic_function | ||
| function: (identifier) @function) | ||
| (generic_function | ||
| function: (scoped_identifier | ||
| name: (identifier) @function)) | ||
| (generic_function | ||
| function: (field_expression | ||
| field: (field_identifier) @function.method)) | ||
|
|
||
| (macro_invocation | ||
| macro: (identifier) @function.macro | ||
| "!" @function.macro) | ||
|
|
||
| ; Function definitions | ||
|
|
||
| (function_item (identifier) @function) | ||
| (function_signature_item (identifier) @function) | ||
|
|
||
| (line_comment) @comment | ||
| (block_comment) @comment | ||
|
|
||
| (line_comment (doc_comment)) @comment.documentation | ||
| (block_comment (doc_comment)) @comment.documentation | ||
|
|
||
| "(" @punctuation.bracket | ||
| ")" @punctuation.bracket | ||
| "[" @punctuation.bracket | ||
| "]" @punctuation.bracket | ||
| "{" @punctuation.bracket | ||
| "}" @punctuation.bracket | ||
|
|
||
| (type_arguments | ||
| "<" @punctuation.bracket | ||
| ">" @punctuation.bracket) | ||
| (type_parameters | ||
| "<" @punctuation.bracket | ||
| ">" @punctuation.bracket) | ||
|
|
||
| "::" @punctuation.delimiter | ||
| ":" @punctuation.delimiter | ||
| "." @punctuation.delimiter | ||
| "," @punctuation.delimiter | ||
| ";" @punctuation.delimiter | ||
|
|
||
| (parameter (identifier) @variable.parameter) | ||
|
|
||
| (lifetime (identifier) @label) | ||
|
|
||
| "as" @keyword | ||
| "async" @keyword | ||
| "await" @keyword | ||
| "break" @keyword | ||
| "const" @keyword | ||
| "continue" @keyword | ||
| "default" @keyword | ||
| "dyn" @keyword | ||
| "else" @keyword | ||
| "enum" @keyword | ||
| "extern" @keyword | ||
| "fn" @keyword | ||
| "for" @keyword | ||
| "gen" @keyword | ||
| "if" @keyword | ||
| "impl" @keyword | ||
| "in" @keyword | ||
| "let" @keyword | ||
| "loop" @keyword | ||
| "macro_rules!" @keyword | ||
| "match" @keyword | ||
| "mod" @keyword | ||
| "move" @keyword | ||
| "pub" @keyword | ||
| "raw" @keyword | ||
| "ref" @keyword | ||
| "return" @keyword | ||
| "static" @keyword | ||
| "struct" @keyword | ||
| "trait" @keyword | ||
| "type" @keyword | ||
| "union" @keyword | ||
| "unsafe" @keyword | ||
| "use" @keyword | ||
| "where" @keyword | ||
| "while" @keyword | ||
| "yield" @keyword | ||
| (crate) @keyword | ||
| (mutable_specifier) @keyword | ||
| (use_list (self) @keyword) | ||
| (scoped_use_list (self) @keyword) | ||
| (scoped_identifier (self) @keyword) | ||
| (super) @keyword | ||
|
|
||
| (self) @variable.builtin | ||
|
|
||
| (char_literal) @string | ||
| (string_literal) @string | ||
| (raw_string_literal) @string | ||
|
|
||
| (boolean_literal) @constant.builtin | ||
| (integer_literal) @constant.builtin | ||
| (float_literal) @constant.builtin | ||
|
|
||
| (escape_sequence) @escape | ||
|
|
||
| (attribute_item) @attribute | ||
| (inner_attribute_item) @attribute | ||
|
|
||
| "*" @operator | ||
| "&" @operator | ||
| "'" @operator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| ((macro_invocation | ||
| (token_tree) @injection.content) | ||
| (#set! injection.language "rust") | ||
| (#set! injection.include-children)) | ||
|
|
||
| ((macro_rule | ||
| (token_tree) @injection.content) | ||
| (#set! injection.language "rust") | ||
| (#set! injection.include-children)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| ; ADT definitions | ||
|
|
||
| (struct_item | ||
| name: (type_identifier) @name) @definition.class | ||
|
|
||
| (enum_item | ||
| name: (type_identifier) @name) @definition.class | ||
|
|
||
| (union_item | ||
| name: (type_identifier) @name) @definition.class | ||
|
|
||
| ; type aliases | ||
|
|
||
| (type_item | ||
| name: (type_identifier) @name) @definition.class | ||
|
|
||
| ; method definitions | ||
|
|
||
| (declaration_list | ||
| (function_item | ||
| name: (identifier) @name) @definition.method) | ||
|
|
||
| ; function definitions | ||
|
|
||
| (function_item | ||
| name: (identifier) @name) @definition.function | ||
|
|
||
| ; trait definitions | ||
| (trait_item | ||
| name: (type_identifier) @name) @definition.interface | ||
|
|
||
| ; module definitions | ||
| (mod_item | ||
| name: (identifier) @name) @definition.module | ||
|
|
||
| ; macro definitions | ||
|
|
||
| (macro_definition | ||
| name: (identifier) @name) @definition.macro | ||
|
|
||
| ; references | ||
|
|
||
| (call_expression | ||
| function: (identifier) @name) @reference.call | ||
|
|
||
| (call_expression | ||
| function: (field_expression | ||
| field: (field_identifier) @name)) @reference.call | ||
|
|
||
| (macro_invocation | ||
| macro: (identifier) @name) @reference.call | ||
|
|
||
| ; implementations | ||
|
|
||
| (impl_item | ||
| trait: (type_identifier) @name) @reference.implementation | ||
|
|
||
| (impl_item | ||
| type: (type_identifier) @name | ||
| !trait) @reference.implementation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule vscode-tree-sitter-query
added at
44c3c7
8 changes: 8 additions & 0 deletions
8
vendor/licenses/git_submodule/vscode-tree-sitter-query.dep.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| name: vscode-tree-sitter-query | ||
| version: d350239cb02d76c4e66720e7b1acb215ec636a18 | ||
| type: git_submodule | ||
| homepage: https://github.com/jrieken/vscode-tree-sitter-query.git | ||
| license: none | ||
| licenses: [] | ||
| notices: [] | ||
mkatychev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is vulnerable to ReDoS attack. Please fix it, and ensure the new regex runs linearly and is a Re2-style regex. See #7242 for other regexes we're slowly cleaning up.
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.
Are all the pattern entries joined by a
|or evaluated separately? Doespattern: ['a*', 'b*']becomepattern: '(a*|b*)'?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.
You can find the magic here.
My finding was based purely on testing the first regex in isolation 😉
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.