-
Notifications
You must be signed in to change notification settings - Fork 993
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
Modern D tree-sitter grammar and queries #2827
Open
gdamore
wants to merge
1
commit into
lapce:master
Choose a base branch
from
gdamore:gdamore/lapce_d
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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,234 @@ | ||
; highlights.scm | ||
panekj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; | ||
; Highlighting queries for D code for use by Tree-Sitter. | ||
; | ||
; Copyright 2023 Garrett D'Amore | ||
; | ||
; Distributed under the MIT License. | ||
; (See accompanying file LICENSE.txt or https://opensource.org/licenses/MIT) | ||
; SPDX-License-Identifier: MIT | ||
|
||
; these are listed first, because they override keyword queries | ||
(identity_expression (in) @operator) | ||
(identity_expression (is) @operator) | ||
|
||
(storage_class) @keyword.storage | ||
|
||
(function_declaration (identifier) @function) | ||
|
||
(call_expression (identifier) @function) | ||
(call_expression (type (identifier) @function)) | ||
|
||
(module_fqn) @namespace | ||
|
||
[ | ||
(abstract) | ||
(alias) | ||
(align) | ||
(asm) | ||
(assert) | ||
(auto) | ||
(cast) | ||
(const) | ||
(debug) | ||
(delete) | ||
(deprecated) | ||
(export) | ||
(extern) | ||
(final) | ||
(immutable) | ||
(in) | ||
(inout) | ||
(invariant) | ||
(is) | ||
(lazy) | ||
; "macro" - obsolete | ||
(mixin) | ||
(module) | ||
(new) | ||
(nothrow) | ||
(out) | ||
(override) | ||
(package) | ||
(pragma) | ||
(private) | ||
(protected) | ||
(public) | ||
(pure) | ||
(ref) | ||
(scope) | ||
(shared) | ||
(static) | ||
(super) | ||
(synchronized) | ||
(template) | ||
(this) | ||
(throw) | ||
(typeid) | ||
(typeof) | ||
(unittest) | ||
(version) | ||
(with) | ||
(gshared) | ||
(traits) | ||
(vector) | ||
(parameters_) | ||
] @keyword | ||
|
||
[ | ||
(class) | ||
(struct) | ||
(interface) | ||
(union) | ||
(enum) | ||
(function) | ||
(delegate) | ||
] @keyword.storage.type | ||
|
||
[ | ||
(break) | ||
(case) | ||
(catch) | ||
(continue) | ||
(do) | ||
(default) | ||
(finally) | ||
(else) | ||
(goto) | ||
(if) | ||
(switch) | ||
(try) | ||
] @keyword.control | ||
|
||
(return) @keyword.control.return | ||
|
||
(import) @keyword.control.import | ||
|
||
[ | ||
(for) | ||
(foreach) | ||
(foreach_reverse) | ||
(while) | ||
] @keyword.control.repeat | ||
|
||
[ | ||
(not_in) | ||
(not_is) | ||
"/=" | ||
"/" | ||
".." | ||
"..." | ||
"&" | ||
"&=" | ||
"&&" | ||
"|" | ||
"|=" | ||
"||" | ||
"-" | ||
"-=" | ||
"--" | ||
"+" | ||
"+=" | ||
"++" | ||
"<" | ||
"<=" | ||
"<<" | ||
"<<=" | ||
">" | ||
">=" | ||
">>=" | ||
">>>=" | ||
">>" | ||
">>>" | ||
"!" | ||
"!=" | ||
"?" | ||
"$" | ||
"=" | ||
"==" | ||
"*" | ||
"*=" | ||
"%" | ||
"%=" | ||
"^" | ||
"^=" | ||
"^^" | ||
"^^=" | ||
"~" | ||
"~=" | ||
"@" | ||
"=>" | ||
] @operator | ||
|
||
[ | ||
"(" | ||
")" | ||
"[" | ||
"]" | ||
"{" | ||
"}" | ||
] @punctuation.bracket | ||
|
||
[ | ||
";" | ||
"." | ||
":" | ||
"," | ||
] @punctuation.delimiter | ||
|
||
[ | ||
(true) | ||
(false) | ||
] @constant.builtin.boolean | ||
|
||
(null) @constant.builtin | ||
|
||
(special_keyword) @constant.builtin | ||
|
||
(directive) @keyword.directive | ||
(shebang) @keyword.directive | ||
|
||
(comment) @comment | ||
|
||
[ | ||
(void) | ||
(bool) | ||
(byte) | ||
(ubyte) | ||
(char) | ||
(short) | ||
(ushort) | ||
(wchar) | ||
(dchar) | ||
(int) | ||
(uint) | ||
(long) | ||
(ulong) | ||
(real) | ||
(double) | ||
(float) | ||
] @type.builtin | ||
|
||
[ | ||
(cent) | ||
(ucent) | ||
(ireal) | ||
(idouble) | ||
(ifloat) | ||
(creal) | ||
(double) | ||
(cfloat) | ||
] @warning ; these types are deprecated | ||
|
||
(label (identifier) @label) | ||
(goto_statement (goto) @keyword (identifier) @label) | ||
|
||
(string_literal) @string | ||
(int_literal) @constant.numeric.integer | ||
(float_literal) @constant.numeric.float | ||
(char_literal) @constant.character | ||
(identifier) @variable | ||
(at_attribute) @attribute | ||
|
||
; everything after __EOF_ is plain text | ||
(end_file) @ui.text |
This file contains 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,17 @@ | ||
[ | ||
(parameters) | ||
(template_parameters) | ||
(expression_statement) | ||
(aggregate_body) | ||
(function_body) | ||
(scope_statement) | ||
(block_statement) | ||
(case_statement) | ||
] @indent | ||
|
||
[ | ||
(case) | ||
(default) | ||
"}" | ||
"]" | ||
] @outdent |
This file contains 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,2 @@ | ||
((comment) @injection.content | ||
(#set! injection.language "comment")) |
This file contains 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 @@ | ||
(function_declaration (function_body) @function.inside) @function.around | ||
(comment) @comment.inside | ||
(comment)+ @comment.around | ||
(class_declaration (aggregate_body) @class.inside) @class.around | ||
(interface_declaration (aggregate_body) @class.inside) @class.around | ||
(struct_declaration (aggregate_body) @class.inside) @class.around | ||
(unittest_declaration (block_statement) @test.insid) @test.around | ||
(parameter) @parameter.inside | ||
(template_parameter) @parameter.inside |
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.
why was this added?
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.
I believe you need the actual tree-sitter grammar for D. I was literally following the pattern used elsewhere.
Note that the crate associated with tree-sitter-d was only created by me last night. But it is a crate now.
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.
It's already added to lapce, but we don't use crates and we don't add grammars directly
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.
Um. Ok. (Btw, if this was documented somewhere it would have helped me.)
What do I need to do to make lapce find my grammar if not this? (Note that this is a different grammar than the one gishadow added -- the grammar he used is older and has some flaws. I created my grammar about a year ago because of defects in the cybershadow grammar.)
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.
Also, the queries have to match the grammar! My queries are written against my grammar, and won't work with the other one.
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.
I'll try updating the submodule instead, now that I know about it. :-)