-
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
Merged
Changes from all 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,88 @@ | ||
| ;; Calculation of Hofstadter's male and female sequences as a list of pairs | ||
|
|
||
| (define (hofstadter-male-female n) | ||
| (letrec ((female (lambda (n) | ||
| (if (= n 0) | ||
| 1 | ||
| (- n (male (female (- n 1))))))) | ||
| (male (lambda (n) | ||
| (if (= n 0) | ||
| 0 | ||
| (- n (female (male (- n 1)))))))) | ||
| (let loop ((i 0)) | ||
| (if (> i n) | ||
| '() | ||
| (cons (cons (female i) | ||
| (male i)) | ||
| (loop (+ i 1))))))) | ||
|
|
||
| (hofstadter-male-female 8) | ||
|
|
||
| ;; Building a list of squares from 0 to 9: | ||
| ;; Note: loop is simply an arbitrary symbol used as a label. Any symbol will do. | ||
|
|
||
| (define (list-of-squares n) | ||
| (let loop ((i n) (res '())) | ||
| (if (< i 0) | ||
| res | ||
| (loop (- i 1) (cons (* i i) res))))) | ||
|
|
||
| (list-of-squares 9) | ||
|
|
||
| (let loop ((n 1)) | ||
| (if (> n 10) | ||
| '() | ||
| (cons n | ||
| (loop (+ n 1))))) | ||
|
|
||
| (define (find-first func lst) | ||
| (call-with-current-continuation | ||
| (lambda (return-immediately) | ||
| (for-each (lambda (x) | ||
| (if (func x) | ||
| (return-immediately x))) | ||
| lst) | ||
| #f))) | ||
|
|
||
| (find-first integer? '(1/2 3/4 5.6 7 8/9 10 11)) | ||
|
|
||
|
|
||
| (set! + | ||
| (let ((original+ +)) | ||
| (lambda args | ||
| (apply (if (or (null? args) (string? (car args))) | ||
| string-append | ||
| original+) | ||
| args)))) | ||
| (+ 1 2 3) | ||
|
|
||
| ; create a hash-table, with keys :a and :b | ||
| (define my-hash (hash-table :a 1 :b 2) | ||
|
|
||
| (map | ||
| (lambda (x y) (list x y)) | ||
| (list :a :b :c) ; first collection | ||
| (list 1 2 3)) ; second collection6 | ||
|
|
||
| ;; example using break and continue with random, | ||
| ;; a construct we might use in a musical algorithm | ||
| (let ((count 0)) | ||
| ; execute a maxium of 8 times | ||
| (while (< count 8) | ||
| (post "count:" count) | ||
|
|
||
| ; a 1 in 4 chance we quit after each time | ||
| (if (= 0 (random 4)) | ||
| (begin (post "aborting!") (break))) | ||
|
|
||
| ; a 1 in 4 chance we stay on the same number | ||
| (if (= 0 (random 3)) | ||
| (begin (post "continuing!") (continue))) | ||
|
|
||
| (set! count (+ 1 count)))) | ||
|
|
||
| ; for-each will execute the functions, return #<unspecified> | ||
| (for-each | ||
| (lambda (x) (post "loop pass, x is:" x)) | ||
| (range 0 4)) | ||
|
|
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,36 @@ | ||
| ;string ports | ||
|
|
||
| (define *output-strings* '()) | ||
|
|
||
| (define open-output-string | ||
| (let ((n 0)) | ||
| (lambda () | ||
| (let ((f (string-append *jobname* "-Z-SC-" | ||
| (number->string n) ".scm"))) | ||
| (set! n (+ n 1)) | ||
| (if (file-exists? f) | ||
| ;try again | ||
| (open-output-string) | ||
| (let ((o (open-output-file f))) | ||
| (set! *output-strings* | ||
| (cons (cons o f) *output-strings*)) | ||
| o)))))) | ||
|
|
||
| (define get-output-string | ||
| (lambda (o) | ||
| (let ((o-f (assv o *output-strings*))) | ||
| (let ((o (car o-f)) | ||
| (f (cdr o-f))) | ||
| (close-output-port o) | ||
| (let ((s (call-with-input-file f | ||
| (lambda (o) | ||
| (let loop ((r '())) | ||
| (let ((c (read-char o))) | ||
| (if (eof-object? c) | ||
| (list->string (reverse! r)) | ||
| (loop (cons c r))))))))) | ||
| (delete-file f) | ||
| s))))) | ||
|
|
||
|
|
||
|
|
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,57 @@ | ||
| (assignment_expression | ||
| left: (member_expression | ||
| object: (call_expression))) | ||
|
|
||
| (class_declaration | ||
| name: (identifier) @class_name | ||
| !type_parameters) | ||
|
|
||
| (binary_expression | ||
| operator: "!=" | ||
| right: (null)) | ||
|
|
||
| (MISSING identifier) @missing-identifier | ||
| (MISSING ";") @missing-semicolon | ||
|
|
||
| (assignment_expression | ||
| left: (identifier) @the-function-name | ||
| right: (function)) | ||
|
|
||
| (comment)+ | ||
|
|
||
| [ | ||
| "break" | ||
| "delete" | ||
| "else" | ||
| "for" | ||
| "function" | ||
| "if" | ||
| "return" | ||
| "try" | ||
| "while" | ||
| ] @keyword | ||
|
|
||
| (body | ||
| [ | ||
| (identifier) | ||
| (function) | ||
| ]* | ||
| ) | ||
|
|
||
| (class_declaration | ||
| (decorator)* @the-decorator | ||
| name: (identifier) @the-name) | ||
|
|
||
| (call_expression | ||
| function: (identifier) @the-function | ||
| arguments: (arguments (string)? @the-string-arg)) | ||
|
|
||
| (dotted_name | ||
| (identifier) @prev-id | ||
| . | ||
| (identifier) @next-id) | ||
|
|
||
| ( | ||
| (number) | ||
| ("," (number))* | ||
| ) |
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,88 @@ | ||
| (string) @string | ||
|
|
||
| (escape_sequence) @string.escape | ||
|
|
||
| (capture | ||
| (identifier) @type) | ||
|
|
||
| (anonymous_node | ||
| (string) @string) | ||
|
|
||
| (predicate | ||
| name: (identifier) @function.call) | ||
|
|
||
| (named_node | ||
| name: (identifier) @variable) | ||
|
|
||
| (field_definition | ||
| name: (identifier) @property) | ||
|
|
||
| (negated_field | ||
| "!" @operator | ||
| (identifier) @property) | ||
|
|
||
| (comment) @comment @spell | ||
|
|
||
| (quantifier) @operator | ||
|
|
||
| (predicate_type) @punctuation.special | ||
|
|
||
| "." @operator | ||
|
|
||
| [ | ||
| "[" | ||
| "]" | ||
| "(" | ||
| ")" | ||
| ] @punctuation.bracket | ||
|
|
||
| ":" @punctuation.delimiter | ||
|
|
||
| [ | ||
| "@" | ||
| "#" | ||
| ] @punctuation.special | ||
|
|
||
| "_" @constant | ||
|
|
||
| ((parameters | ||
| (identifier) @number) | ||
| (#match? @number "^[-+]?[0-9]+(.[0-9]+)?$")) | ||
|
|
||
| ((program | ||
| . | ||
| (comment)* | ||
| . | ||
| (comment) @keyword.import) | ||
| (#lua-match? @keyword.import "^;+ *inherits *:")) | ||
|
|
||
| ((program | ||
| . | ||
| (comment)* | ||
| . | ||
| (comment) @keyword.directive) | ||
| (#lua-match? @keyword.directive "^;+ *extends *$")) | ||
|
|
||
| ((comment) @keyword.directive | ||
| (#lua-match? @keyword.directive "^;+%s*format%-ignore%s*$")) | ||
|
|
||
| ((predicate | ||
| name: (identifier) @_name | ||
| parameters: | ||
| (parameters | ||
| (string | ||
| "\"" @string | ||
| "\"" @string) @string.regexp)) | ||
| (#any-of? @_name "match" "not-match" "vim-match" "not-vim-match" "lua-match" "not-lua-match")) | ||
|
|
||
| ((predicate | ||
| name: (identifier) @_name | ||
| parameters: | ||
| (parameters | ||
| (string | ||
| "\"" @string | ||
| "\"" @string) @string.regexp | ||
| . | ||
| (string) .)) | ||
| (#any-of? @_name "gsub" "not-gsub")) | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.